filters

kis_jpeg_export.cc

00001 /*
00002  *  Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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; // FIXME Cancel doesn't exist :(
00104     }
00105     KisJPEGOptions options;
00106     options.progressive = wdg->progressive->isChecked();
00107     options.quality = wdg->qualityLevel->value();
00108     
00109     delete kdb;
00110     // XXX: Add dialog about flattening layers here
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 
KDE Home | KDE Accessibility Home | Description of Access Keys