filters
kis_jpeg_export.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kis_jpeg_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_doc.h>
00032 #include <kis_image.h>
00033 #include <kis_group_layer.h>
00034 #include <kis_paint_layer.h>
00035 #include <kis_progress_display_interface.h>
00036 #include <kis_layer_visitor.h>
00037
00038 #include "kis_jpeg_converter.h"
00039 #include "kis_wdg_options_jpeg.h"
00040
00041
00042 class KisExifInfoVisitor : public KisLayerVisitor
00043 {
00044 public:
00045 KisExifInfoVisitor() :
00046 m_exifInfo(0),
00047 m_countPaintLayer(0)
00048 { };
00049 public:
00050 virtual bool visit(KisPaintLayer* layer) {
00051 m_countPaintLayer++;
00052 if( layer->paintDevice()->hasExifInfo())
00053 m_exifInfo = layer->paintDevice()->exifInfo();
00054 return true;
00055 };
00056 virtual bool visit(KisGroupLayer* layer)
00057 {
00058 kdDebug(41008) << "Visiting on grouplayer " << layer->name() << "\n";
00059 KisLayerSP child = layer->firstChild();
00060 while (child) {
00061 child->accept(*this);
00062 child = child->nextSibling();
00063 }
00064 return true;
00065 }
00066 virtual bool visit(KisPartLayer *) { return true; };
00067 virtual bool visit(KisAdjustmentLayer* ) { return true; };
00068 public:
00069 inline uint countPaintLayer() { return m_countPaintLayer; }
00070 inline KisExifInfo* exifInfo() {return m_exifInfo; }
00071 private:
00072 KisExifInfo* m_exifInfo;
00073 uint m_countPaintLayer;
00074 };
00075
00076
00077 typedef KGenericFactory<KisJPEGExport, KoFilter> KisJPEGExportFactory;
00078 K_EXPORT_COMPONENT_FACTORY(libkritajpegexport, KisJPEGExportFactory("kofficefilters"))
00079
00080 KisJPEGExport::KisJPEGExport(KoFilter *, const char *, const QStringList&) : KoFilter()
00081 {
00082 }
00083
00084 KisJPEGExport::~KisJPEGExport()
00085 {
00086 }
00087
00088 KoFilter::ConversionStatus KisJPEGExport::convert(const QCString& from, const QCString& to)
00089 {
00090 kdDebug(41008) << "JPEG export! From: " << from << ", To: " << to << "\n";
00091
00092 if (from != "application/x-krita")
00093 return KoFilter::NotImplemented;
00094
00095
00096 KDialogBase* kdb = new KDialogBase(0, "", false, i18n("JPEG Export Options"), KDialogBase::Ok | KDialogBase::Cancel);
00097
00098 KisWdgOptionsJPEG* wdg = new KisWdgOptionsJPEG(kdb);
00099 kdb->setMainWidget(wdg);
00100 kapp->restoreOverrideCursor();
00101 if(kdb->exec() == QDialog::Rejected)
00102 {
00103 return KoFilter::OK;
00104 }
00105 KisJPEGOptions options;
00106 options.progressive = wdg->progressive->isChecked();
00107 options.quality = wdg->qualityLevel->value();
00108
00109 delete kdb;
00110
00111
00112 KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
00113 QString filename = m_chain->outputFile();
00114
00115 if (!output)
00116 return KoFilter::CreationError;
00117
00118
00119 if (filename.isEmpty()) return KoFilter::FileNotFound;
00120
00121 KURL url;
00122 url.setPath(filename);
00123
00124 KisImageSP img = output->currentImage();
00125 Q_CHECK_PTR(img);
00126
00127 KisJPEGConverter kpc(output, output->undoAdapter());
00128
00129 KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
00130 KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
00131
00132 vKisAnnotationSP_it beginIt = img->beginAnnotations();
00133 vKisAnnotationSP_it endIt = img->endAnnotations();
00134 KisImageBuilder_Result res;
00135
00136 KisExifInfoVisitor eIV;
00137 eIV.visit( img->rootLayer() );
00138
00139 KisExifInfo* eI = 0;
00140 if(eIV.countPaintLayer() == 1)
00141 eI = eIV.exifInfo();
00142
00143 if ( (res = kpc.buildFile(url, l, beginIt, endIt, options, eI)) == KisImageBuilder_RESULT_OK) {
00144 kdDebug(41008) << "success !" << endl;
00145 return KoFilter::OK;
00146 }
00147 kdDebug(41008) << " Result = " << res << endl;
00148 return KoFilter::InternalError;
00149 }
00150
00151 #include <kis_jpeg_export.moc>
00152
|