filters

kis_tiff_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_tiff_export.h"
00021 
00022 #include <qcheckbox.h>
00023 #include <qslider.h>
00024 
00025 #include <kapplication.h>
00026 #include <kcombobox.h>
00027 #include <kdialogbase.h>
00028 #include <kgenericfactory.h>
00029 
00030 #include <KoFilterChain.h>
00031 
00032 #include <kis_doc.h>
00033 #include <kis_group_layer.h>
00034 #include <kis_image.h>
00035 #include <kis_paint_layer.h>
00036 #include <kis_progress_display_interface.h>
00037 
00038 #include "kis_tiff_converter.h"
00039 #include "kis_dlg_options_tiff.h"
00040 #include "kis_wdg_options_tiff.h"
00041 
00042 typedef KGenericFactory<KisTIFFExport, KoFilter> KisTIFFExportFactory;
00043 K_EXPORT_COMPONENT_FACTORY(libkritatiffexport, KisTIFFExportFactory("kofficefilters"))
00044 
00045 KisTIFFExport::KisTIFFExport(KoFilter *, const char *, const QStringList&) : KoFilter()
00046 {
00047 }
00048 
00049 KisTIFFExport::~KisTIFFExport()
00050 {
00051 }
00052 
00053 KoFilter::ConversionStatus KisTIFFExport::convert(const QCString& from, const QCString& to)
00054 {
00055     kdDebug(41008) << "Tiff export! From: " << from << ", To: " << to << "\n";
00056     
00057     if (from != "application/x-krita")
00058         return KoFilter::NotImplemented;
00059 
00060     
00061     KisDlgOptionsTIFF* kdb = new KisDlgOptionsTIFF(0, "options dialog for tiff");
00062  
00063     KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
00064     
00065     KisColorSpace* cs = output->currentImage()->colorSpace();
00066     KisChannelInfo::enumChannelValueType type = cs->channels()[0]->channelValueType();
00067     if( type == KisChannelInfo::FLOAT16 || type == KisChannelInfo::FLOAT32)
00068     {
00069       kdb->optionswdg->kComboBoxPredictor->removeItem(1);
00070     } else {
00071       kdb->optionswdg->kComboBoxPredictor->removeItem(2);
00072     }
00073     
00074     if(kdb->exec() == QDialog::Rejected)
00075     {
00076         return KoFilter::OK; // FIXME Cancel doesn't exist :(
00077     }
00078     
00079     KisTIFFOptions options = kdb->options();
00080 
00081     if( ( type == KisChannelInfo::FLOAT16 || type == KisChannelInfo::FLOAT32) && options.predictor == 2  )
00082     { // FIXME THIS IS AN HACK FIX THAT IN 2.0 !!
00083       options.predictor = 3;
00084     }
00085     delete kdb;
00086     
00087     QString filename = m_chain->outputFile();
00088     
00089     if (!output)
00090         return KoFilter::CreationError;
00091     
00092     if (filename.isEmpty()) return KoFilter::FileNotFound;
00093 
00094     KURL url;
00095     url.setPath(filename);
00096 
00097     KisImageSP img;
00098     
00099     if(options.flatten)
00100     {
00101         img = new KisImage(0, output->currentImage()->width(), output->currentImage()->height(), output->currentImage()->colorSpace(), "");
00102         KisPaintDeviceSP pd = new KisPaintDevice(*output->currentImage()->projection());
00103         KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
00104         img->addLayer(l.data(), img->rootLayer(), 0);
00105     } else {
00106         img = output->currentImage();
00107     }
00108     
00109 
00110     KisTIFFConverter ktc(output, output->undoAdapter());
00111 /*    vKisAnnotationSP_it beginIt = img->beginAnnotations();
00112     vKisAnnotationSP_it endIt = img->endAnnotations();*/
00113     KisImageBuilder_Result res;
00114     if ( (res = ktc.buildFile(url, img, options)) == KisImageBuilder_RESULT_OK) {
00115         kdDebug(41008) << "success !" << endl;
00116         return KoFilter::OK;
00117     }
00118     kdDebug(41008) << " Result = " << res << endl;
00119     return KoFilter::InternalError;
00120 }
00121 
00122 #include <kis_tiff_export.moc>
00123 
KDE Home | KDE Accessibility Home | Description of Access Keys