20#include "kis_png_export.h"
22#include <tqcheckbox.h>
25#include <tdeapplication.h>
26#include <kdialogbase.h>
27#include <kgenericfactory.h>
29#include <KoFilterChain.h>
31#include <kis_colorspace.h>
34#include <kis_iterators_pixel.h>
35#include <kis_paint_layer.h>
36#include <kis_progress_display_interface.h>
38#include "kis_png_converter.h"
39#include "kis_wdg_options_png.h"
41typedef KGenericFactory<KisPNGExport, KoFilter> KisPNGExportFactory;
42K_EXPORT_COMPONENT_FACTORY(libchalkpngexport, KisPNGExportFactory(
"kofficefilters"))
44KisPNGExport::KisPNGExport(KoFilter *, const
char *, const TQStringList&) : KoFilter()
48KisPNGExport::~KisPNGExport()
52KoFilter::ConversionStatus KisPNGExport::convert(
const TQCString& from,
const TQCString& to)
54 kdDebug(41008) <<
"Png export! From: " << from <<
", To: " << to <<
"\n";
56 KisDoc *output =
dynamic_cast<KisDoc*
>(m_chain->inputDocument());
57 TQString filename = m_chain->outputFile();
60 return KoFilter::CreationError;
63 if (filename.isEmpty())
return KoFilter::FileNotFound;
65 if (from !=
"application/x-chalk")
66 return KoFilter::NotImplemented;
69 KDialogBase* kdb =
new KDialogBase(0,
"",
false, i18n(
"PNG Export Options"), KDialogBase::Ok | KDialogBase::Cancel);
71 KisImageSP img = output->currentImage();
72 KisPaintDeviceSP pd =
new KisPaintDevice(*img->projection());
73 KisPaintLayerSP l =
new KisPaintLayer(img,
"projection", OPACITY_OPAQUE, pd);
75 KisRectIteratorPixel it = l->paintDevice()->createRectIterator(0,0, img->width(), img->height(),
false);
76 KisColorSpace* cs = l->paintDevice()->colorSpace();
77 bool isThereAlpha =
false;
80 if(cs->getAlpha( it.rawData() ) != 255)
88 KisWdgOptionsPNG* wdg =
new KisWdgOptionsPNG(kdb);
89 wdg->alpha->setChecked(isThereAlpha);
90 wdg->alpha->setEnabled(isThereAlpha);
91 kdb->setMainWidget(wdg);
92 kapp->restoreOverrideCursor();
93 if(kdb->exec() == TQDialog::Rejected)
98 bool alpha = wdg->alpha->isChecked();
99 bool interlace = wdg->interlacing->isChecked();
100 int compression = wdg->compressionLevel->value();
106 url.setPath(filename);
108 KisPNGConverter kpc(output, output->undoAdapter());
110 vKisAnnotationSP_it beginIt = img->beginAnnotations();
111 vKisAnnotationSP_it endIt = img->endAnnotations();
112 KisImageBuilder_Result res;
115 if ( (res = kpc.buildFile(url, l, beginIt, endIt, compression, interlace, alpha)) == KisImageBuilder_RESULT_OK) {
116 kdDebug(41008) <<
"success !" << endl;
119 kdDebug(41008) <<
" Result = " << res << endl;
120 return KoFilter::InternalError;
123#include <kis_png_export.moc>