File indexing completed on 2024-12-22 04:15:49
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ora_converter.h" 0008 0009 #include <QApplication> 0010 0011 #include <QFileInfo> 0012 0013 #include <KoStore.h> 0014 #include <KoStoreDevice.h> 0015 #include <KoColorSpaceRegistry.h> 0016 #include <KisDocument.h> 0017 #include <kis_group_layer.h> 0018 #include <kis_image.h> 0019 #include <kis_open_raster_stack_load_visitor.h> 0020 #include <kis_open_raster_stack_save_visitor.h> 0021 #include <kis_paint_layer.h> 0022 #include "kis_png_converter.h" 0023 #include "kis_open_raster_load_context.h" 0024 #include "kis_open_raster_save_context.h" 0025 0026 OraConverter::OraConverter(KisDocument *doc) 0027 : m_doc(doc) 0028 , m_stop(false) 0029 { 0030 } 0031 0032 OraConverter::~OraConverter() 0033 { 0034 } 0035 0036 KisImportExportErrorCode OraConverter::buildImage(QIODevice *io) 0037 { 0038 KoStore* store = KoStore::createStore(io, KoStore::Read, "image/openraster", KoStore::Zip); 0039 if (!store) { 0040 delete store; 0041 return ImportExportCodes::FileFormatIncorrect; 0042 } 0043 0044 KisOpenRasterLoadContext olc(store); 0045 KisOpenRasterStackLoadVisitor orslv(m_doc->createUndoStore(), &olc); 0046 orslv.loadImage(); 0047 m_image = orslv.image(); 0048 0049 qDebug() << "m_image" << m_image; 0050 0051 if (!m_image) { 0052 delete store; 0053 return ImportExportCodes::ErrorWhileReading; 0054 } 0055 0056 m_activeNodes = orslv.activeNodes(); 0057 delete store; 0058 0059 return ImportExportCodes::OK; 0060 } 0061 0062 KisImageSP OraConverter::image() 0063 { 0064 return m_image; 0065 } 0066 0067 vKisNodeSP OraConverter::activeNodes() 0068 { 0069 return m_activeNodes; 0070 } 0071 0072 KisImportExportErrorCode OraConverter::buildFile(QIODevice *io, KisImageSP image, vKisNodeSP activeNodes) 0073 { 0074 0075 // Open file for writing 0076 KoStore* store = KoStore::createStore(io, KoStore::Write, "image/openraster", KoStore::Zip); 0077 if (!store) { 0078 delete store; 0079 return ImportExportCodes::Failure; 0080 } 0081 0082 KisOpenRasterSaveContext osc(store); 0083 KisOpenRasterStackSaveVisitor orssv(&osc, activeNodes); 0084 0085 image->rootLayer()->accept(orssv); 0086 0087 if (store->open("Thumbnails/thumbnail.png")) { 0088 QSize previewSize = image->bounds().size(); 0089 previewSize.scale(QSize(256,256), Qt::KeepAspectRatio); 0090 0091 QImage preview = image->convertToQImage(previewSize, 0); 0092 0093 KoStoreDevice io(store); 0094 if (io.open(QIODevice::WriteOnly)) { 0095 preview.save(&io, "PNG"); 0096 } 0097 io.close(); 0098 store->close(); 0099 } 0100 0101 KisPaintDeviceSP dev = image->projection(); 0102 KisPNGConverter::saveDeviceToStore("mergedimage.png", image->bounds(), image->xRes(), image->yRes(), dev, store); 0103 0104 delete store; 0105 return ImportExportCodes::OK; 0106 } 0107 0108 0109 void OraConverter::cancel() 0110 { 0111 m_stop = true; 0112 } 0113 0114