filters

kis_tiff_reader.h

00001 /*
00002  *  Copyright (c) 2006 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 #ifndef _KIS_TIFF_READER_H_
00021 #define _KIS_TIFF_READER_H_
00022 
00023 #include <tiffio.h>
00024 
00025 /*#include <stdio.h>
00026 
00027 #include <qvaluevector.h>
00028 
00029 #include <kio/job.h>
00030 
00031 #include <kis_progress_subject.h> */
00032 
00033 #include <kis_paint_device.h>
00034 
00035 #include "kis_types.h"
00036 #include "kis_global.h"
00037 // #include "kis_annotation.h"
00038 
00039 #include <kis_iterator.h>
00040 #include <kis_paint_device.h>
00041 
00042 #define Q_UINT32_MAX 4294967295u
00043 
00044 class TIFFStreamBase;
00045 
00046 class KisTIFFPostProcessor {
00047     public:
00048         KisTIFFPostProcessor(uint8 nbcolorssamples) : m_nbcolorssamples(nbcolorssamples) { }
00049     public:
00050         virtual void postProcess8bit( Q_UINT8* ) { };
00051         virtual void postProcess16bit( Q_UINT16* ) { };
00052         virtual void postProcess32bit( Q_UINT32* ) { };
00053     protected:
00054         inline uint8 nbColorsSamples() { return m_nbcolorssamples; }
00055     private:
00056         uint8 m_nbcolorssamples;
00057 };
00058 
00059 class KisTIFFPostProcessorInvert : public KisTIFFPostProcessor {
00060     public:
00061         KisTIFFPostProcessorInvert(uint8 nbcolorssamples) : KisTIFFPostProcessor(nbcolorssamples) {}
00062     public:
00063         virtual void postProcess8bit( Q_UINT8* data )
00064         {
00065             for(int i = 0; i < nbColorsSamples(); i++)
00066             {
00067                 data[i] = Q_UINT8_MAX - data[i];
00068             }
00069         }
00070         virtual void postProcess16bit( Q_UINT16* data )
00071         {
00072             Q_UINT16* d = (Q_UINT16*) data;
00073             for(int i = 0; i < nbColorsSamples(); i++)
00074             {
00075                 d[i] = Q_UINT16_MAX - d[i];
00076             }
00077         }
00078         virtual void postProcess32bit( Q_UINT32* data )
00079         {
00080             Q_UINT32* d = (Q_UINT32*) data;
00081             for(int i = 0; i < nbColorsSamples(); i++)
00082             {
00083                 d[i] = Q_UINT32_MAX - d[i];
00084             }
00085         }
00086 };
00087 
00088 class KisTIFFPostProcessorICCLABtoCIELAB : public KisTIFFPostProcessor {
00089     public:
00090         KisTIFFPostProcessorICCLABtoCIELAB(uint8 nbcolorssamples) : KisTIFFPostProcessor(nbcolorssamples) {}
00091     public:
00092         void postProcess8bit(Q_UINT8* data)
00093         {
00094             Q_INT8* ds = (Q_INT8*) data;
00095             for(int i = 1; i < nbColorsSamples(); i++)
00096             {
00097                 ds[i] = data[i] - Q_UINT8_MAX/2;
00098             }
00099         }
00100         void postProcess16bit(Q_UINT16* data)
00101         {
00102             Q_UINT16* d = (Q_UINT16*) data;
00103             Q_INT16* ds = (Q_INT16*) data;
00104             for(int i = 1; i < nbColorsSamples(); i++)
00105             {
00106                 ds[i] = d[i] - Q_UINT16_MAX /2;
00107             }
00108         }
00109         void postProcess32bit(Q_UINT32* data)
00110         {
00111             Q_UINT32* d = (Q_UINT32*) data;
00112             Q_INT32* ds = (Q_INT32*) data;
00113             for(int i = 1; i < nbColorsSamples(); i++)
00114             {
00115                 ds[i] = d[i] - Q_UINT32_MAX /2;
00116             }
00117         }
00118 };
00119 
00120 
00121 class KisTIFFReaderBase {
00122     public:
00123         KisTIFFReaderBase( KisPaintDeviceSP device, Q_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : m_device(device), m_alphapos(alphapos), m_sourceDepth(sourceDepth), m_nbcolorssamples(nbcolorssamples), m_nbextrasamples(extrasamplescount), m_poses(poses), m_transformProfile(transformProfile), m_postprocess(postprocessor)
00124         {
00125             
00126         }
00127     public:
00137         virtual uint copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream) =0;
00141         virtual void finalize() { };
00142     protected:
00143         inline KisPaintDeviceSP paintDevice() { return m_device; }
00144         inline Q_UINT8 alphaPos() { return m_alphapos; }
00145         inline Q_UINT8 sourceDepth() { return m_sourceDepth; }
00146         inline Q_UINT8 nbColorsSamples() { return m_nbcolorssamples; }
00147         inline Q_UINT8 nbExtraSamples() { return m_nbextrasamples; }
00148         inline Q_UINT8* poses() { return m_poses; }
00149         inline cmsHTRANSFORM transform() { return m_transformProfile; }
00150         inline KisTIFFPostProcessor* postProcessor() { return m_postprocess; }
00151     private:
00152         KisPaintDeviceSP m_device;
00153         Q_UINT8 m_alphapos;
00154         Q_UINT8 m_sourceDepth;
00155         Q_UINT8 m_nbcolorssamples;
00156         Q_UINT8 m_nbextrasamples;
00157         Q_UINT8* m_poses;
00158         cmsHTRANSFORM m_transformProfile;
00159         KisTIFFPostProcessor* m_postprocess;
00160         Q_UINT32 m_tiffDataWidth;
00161 };
00162 
00163 class KisTIFFReaderTarget8bit : public KisTIFFReaderBase {
00164     public:
00165         KisTIFFReaderTarget8bit( KisPaintDeviceSP device, Q_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount,  cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth,  nbcolorssamples, extrasamplescount, transformProfile, postprocessor )
00166         {
00167             
00168         }
00169     public:
00170         virtual uint copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream);
00171 };
00172 
00173 
00174 class KisTIFFReaderTarget16bit : public KisTIFFReaderBase {
00175     public:
00176         KisTIFFReaderTarget16bit( KisPaintDeviceSP device, Q_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth,  nbcolorssamples, extrasamplescount, transformProfile, postprocessor )
00177         {
00178             
00179         }
00180     public:
00181         virtual uint copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream) ;
00182 };
00183 
00184 class KisTIFFReaderTarget32bit : public KisTIFFReaderBase {
00185     public:
00186         KisTIFFReaderTarget32bit( KisPaintDeviceSP device, Q_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth,  nbcolorssamples, extrasamplescount, transformProfile, postprocessor )
00187         {
00188             
00189         }
00190     public:
00191         virtual uint copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream) ;
00192 };
00193 
00194 class KisTIFFReaderFromPalette : public  KisTIFFReaderBase {
00195     public:
00196         KisTIFFReaderFromPalette( KisPaintDeviceSP device, uint16 *red, uint16 *green, uint16 *blue, Q_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth,  nbcolorssamples, extrasamplescount, transformProfile, postprocessor ), m_red(red), m_green(green), m_blue(blue)
00197         {
00198             
00199         }
00200     public:
00201         virtual uint copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream) ;
00202     private:
00203         uint16 *m_red,  *m_green, *m_blue;
00204 };
00205 
00206 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys