filters
kis_png_export.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kis_png_export.h"
00021
00022 #include <qcheckbox.h>
00023 #include <qslider.h>
00024
00025 #include <kapplication.h>
00026 #include <kdialogbase.h>
00027 #include <kgenericfactory.h>
00028
00029 #include <KoFilterChain.h>
00030
00031 #include <kis_colorspace.h>
00032 #include <kis_doc.h>
00033 #include <kis_image.h>
00034 #include <kis_iterators_pixel.h>
00035 #include <kis_paint_layer.h>
00036 #include <kis_progress_display_interface.h>
00037
00038 #include "kis_png_converter.h"
00039 #include "kis_wdg_options_png.h"
00040
00041 typedef KGenericFactory<KisPNGExport, KoFilter> KisPNGExportFactory;
00042 K_EXPORT_COMPONENT_FACTORY(libkritapngexport, KisPNGExportFactory("kofficefilters"))
00043
00044 KisPNGExport::KisPNGExport(KoFilter *, const char *, const QStringList&) : KoFilter()
00045 {
00046 }
00047
00048 KisPNGExport::~KisPNGExport()
00049 {
00050 }
00051
00052 KoFilter::ConversionStatus KisPNGExport::convert(const QCString& from, const QCString& to)
00053 {
00054 kdDebug(41008) << "Png export! From: " << from << ", To: " << to << "\n";
00055
00056 KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
00057 QString filename = m_chain->outputFile();
00058
00059 if (!output)
00060 return KoFilter::CreationError;
00061
00062
00063 if (filename.isEmpty()) return KoFilter::FileNotFound;
00064
00065 if (from != "application/x-krita")
00066 return KoFilter::NotImplemented;
00067
00068
00069 KDialogBase* kdb = new KDialogBase(0, "", false, i18n("PNG Export Options"), KDialogBase::Ok | KDialogBase::Cancel);
00070
00071 KisImageSP img = output->currentImage();
00072 KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
00073 KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
00074
00075 KisRectIteratorPixel it = l->paintDevice()->createRectIterator(0,0, img->width(), img->height(), false);
00076 KisColorSpace* cs = l->paintDevice()->colorSpace();
00077 bool isThereAlpha = false;
00078 while( !it.isDone() )
00079 {
00080 if(cs->getAlpha( it.rawData() ) != 255)
00081 {
00082 isThereAlpha = true;
00083 break;
00084 }
00085 ++it;
00086 }
00087
00088 KisWdgOptionsPNG* wdg = new KisWdgOptionsPNG(kdb);
00089 wdg->alpha->setChecked(isThereAlpha);
00090 wdg->alpha->setEnabled(isThereAlpha);
00091 kdb->setMainWidget(wdg);
00092 kapp->restoreOverrideCursor();
00093 if(kdb->exec() == QDialog::Rejected)
00094 {
00095 return KoFilter::OK;
00096 }
00097
00098 bool alpha = wdg->alpha->isChecked();
00099 bool interlace = wdg->interlacing->isChecked();
00100 int compression = wdg->compressionLevel->value();
00101
00102 delete kdb;
00103
00104
00105 KURL url;
00106 url.setPath(filename);
00107
00108 KisPNGConverter kpc(output, output->undoAdapter());
00109
00110 vKisAnnotationSP_it beginIt = img->beginAnnotations();
00111 vKisAnnotationSP_it endIt = img->endAnnotations();
00112 KisImageBuilder_Result res;
00113
00114
00115 if ( (res = kpc.buildFile(url, l, beginIt, endIt, compression, interlace, alpha)) == KisImageBuilder_RESULT_OK) {
00116 kdDebug(41008) << "success !" << endl;
00117 return KoFilter::OK;
00118 }
00119 kdDebug(41008) << " Result = " << res << endl;
00120 return KoFilter::InternalError;
00121 }
00122
00123 #include <kis_png_export.moc>
00124
|