filters

kis_tiff_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_tiff_export.h"
21
22#include <tqcheckbox.h>
23#include <tqslider.h>
24
25#include <tdeapplication.h>
26#include <kcombobox.h>
27#include <kdialogbase.h>
28#include <kgenericfactory.h>
29
30#include <KoFilterChain.h>
31
32#include <kis_doc.h>
33#include <kis_group_layer.h>
34#include <kis_image.h>
35#include <kis_paint_layer.h>
36#include <kis_progress_display_interface.h>
37
38#include "kis_tiff_converter.h"
39#include "kis_dlg_options_tiff.h"
40#include "kis_wdg_options_tiff.h"
41
42typedef KGenericFactory<KisTIFFExport, KoFilter> KisTIFFExportFactory;
43K_EXPORT_COMPONENT_FACTORY(libchalktiffexport, KisTIFFExportFactory("kofficefilters"))
44
45KisTIFFExport::KisTIFFExport(KoFilter *, const char *, const TQStringList&) : KoFilter()
46{
47}
48
49KisTIFFExport::~KisTIFFExport()
50{
51}
52
53KoFilter::ConversionStatus KisTIFFExport::convert(const TQCString& from, const TQCString& to)
54{
55 kdDebug(41008) << "Tiff export! From: " << from << ", To: " << to << "\n";
56
57 if (from != "application/x-chalk")
58 return KoFilter::NotImplemented;
59
60
61 KisDlgOptionsTIFF* kdb = new KisDlgOptionsTIFF(0, "options dialog for tiff");
62
63 KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
64
65 KisColorSpace* cs = output->currentImage()->colorSpace();
66 KisChannelInfo::enumChannelValueType type = cs->channels()[0]->channelValueType();
67 if( type == KisChannelInfo::FLOAT16 || type == KisChannelInfo::FLOAT32)
68 {
69 kdb->optionswdg->kComboBoxPredictor->removeItem(1);
70 } else {
71 kdb->optionswdg->kComboBoxPredictor->removeItem(2);
72 }
73
74 if(kdb->exec() == TQDialog::Rejected)
75 {
76 return KoFilter::OK; // FIXME Cancel doesn't exist :(
77 }
78
79 KisTIFFOptions options = kdb->options();
80
81 if( ( type == KisChannelInfo::FLOAT16 || type == KisChannelInfo::FLOAT32) && options.predictor == 2 )
82 { // FIXME THIS IS AN HACK FIX THAT IN 2.0 !!
83 options.predictor = 3;
84 }
85 delete kdb;
86
87 TQString filename = m_chain->outputFile();
88
89 if (!output)
90 return KoFilter::CreationError;
91
92 if (filename.isEmpty()) return KoFilter::FileNotFound;
93
94 KURL url;
95 url.setPath(filename);
96
97 KisImageSP img;
98
99 if(options.flatten)
100 {
101 img = new KisImage(0, output->currentImage()->width(), output->currentImage()->height(), output->currentImage()->colorSpace(), "");
102 KisPaintDeviceSP pd = new KisPaintDevice(*output->currentImage()->projection());
103 KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
104 img->addLayer(l.data(), img->rootLayer(), 0);
105 } else {
106 img = output->currentImage();
107 }
108
109
110 KisTIFFConverter ktc(output, output->undoAdapter());
111/* vKisAnnotationSP_it beginIt = img->beginAnnotations();
112 vKisAnnotationSP_it endIt = img->endAnnotations();*/
113 KisImageBuilder_Result res;
114 if ( (res = ktc.buildFile(url, img, options)) == KisImageBuilder_RESULT_OK) {
115 kdDebug(41008) << "success !" << endl;
116 return KoFilter::OK;
117 }
118 kdDebug(41008) << " Result = " << res << endl;
119 return KoFilter::InternalError;
120}
121
122#include <kis_tiff_export.moc>
123