filters

kis_jpeg_export.cpp
1/*
2 * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "kis_jpeg_export.h"
21
22#include <tqcheckbox.h>
23#include <tqslider.h>
24
25#include <tdeapplication.h>
26#include <kdialogbase.h>
27#include <kgenericfactory.h>
28
29#include <KoFilterChain.h>
30
31#include <kis_doc.h>
32#include <kis_image.h>
33#include <kis_group_layer.h>
34#include <kis_paint_layer.h>
35#include <kis_progress_display_interface.h>
36#include <kis_layer_visitor.h>
37
38#include "kis_jpeg_converter.h"
39#include "kis_wdg_options_jpeg.h"
40
41
42class KisExifInfoVisitor : public KisLayerVisitor
43{
44 public:
45 KisExifInfoVisitor() :
46 m_exifInfo(0),
47 m_countPaintLayer(0)
48 { };
49 public:
50 virtual bool visit(KisPaintLayer* layer) {
51 m_countPaintLayer++;
52 if( layer->paintDevice()->hasExifInfo())
53 m_exifInfo = layer->paintDevice()->exifInfo();
54 return true;
55 };
56 virtual bool visit(KisGroupLayer* layer)
57 {
58 kdDebug(41008) << "Visiting on grouplayer " << layer->name() << "\n";
59 KisLayerSP child = layer->firstChild();
60 while (child) {
61 child->accept(*this);
62 child = child->nextSibling();
63 }
64 return true;
65 }
66 virtual bool visit(KisPartLayer *) { return true; };
67 virtual bool visit(KisAdjustmentLayer* ) { return true; };
68 public:
69 inline uint countPaintLayer() { return m_countPaintLayer; }
70 inline KisExifInfo* exifInfo() {return m_exifInfo; }
71 private:
72 KisExifInfo* m_exifInfo;
73 uint m_countPaintLayer;
74};
75
76
77typedef KGenericFactory<KisJPEGExport, KoFilter> KisJPEGExportFactory;
78K_EXPORT_COMPONENT_FACTORY(libchalkjpegexport, KisJPEGExportFactory("kofficefilters"))
79
80KisJPEGExport::KisJPEGExport(KoFilter *, const char *, const TQStringList&) : KoFilter()
81{
82}
83
84KisJPEGExport::~KisJPEGExport()
85{
86}
87
88KoFilter::ConversionStatus KisJPEGExport::convert(const TQCString& from, const TQCString& to)
89{
90 kdDebug(41008) << "JPEG export! From: " << from << ", To: " << to << "\n";
91
92 if (from != "application/x-chalk")
93 return KoFilter::NotImplemented;
94
95
96 KDialogBase* kdb = new KDialogBase(0, "", false, i18n("JPEG Export Options"), KDialogBase::Ok | KDialogBase::Cancel);
97
98 KisWdgOptionsJPEG* wdg = new KisWdgOptionsJPEG(kdb);
99 kdb->setMainWidget(wdg);
100 kapp->restoreOverrideCursor();
101 if(kdb->exec() == TQDialog::Rejected)
102 {
103 return KoFilter::OK; // FIXME Cancel doesn't exist :(
104 }
105 KisJPEGOptions options;
106 options.progressive = wdg->progressive->isChecked();
107 options.quality = wdg->qualityLevel->value();
108
109 delete kdb;
110 // XXX: Add dialog about flattening layers here
111
112 KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
113 TQString filename = m_chain->outputFile();
114
115 if (!output)
116 return KoFilter::CreationError;
117
118
119 if (filename.isEmpty()) return KoFilter::FileNotFound;
120
121 KURL url;
122 url.setPath(filename);
123
124 KisImageSP img = output->currentImage();
125 TQ_CHECK_PTR(img);
126
127 KisJPEGConverter kpc(output, output->undoAdapter());
128
129 KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
130 KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
131
132 vKisAnnotationSP_it beginIt = img->beginAnnotations();
133 vKisAnnotationSP_it endIt = img->endAnnotations();
134 KisImageBuilder_Result res;
135
136 KisExifInfoVisitor eIV;
137 eIV.visit( img->rootLayer() );
138
139 KisExifInfo* eI = 0;
140 if(eIV.countPaintLayer() == 1)
141 eI = eIV.exifInfo();
142
143 if ( (res = kpc.buildFile(url, l, beginIt, endIt, options, eI)) == KisImageBuilder_RESULT_OK) {
144 kdDebug(41008) << "success !" << endl;
145 return KoFilter::OK;
146 }
147 kdDebug(41008) << " Result = " << res << endl;
148 return KoFilter::InternalError;
149}
150
151#include <kis_jpeg_export.moc>
152