kis_tiff_reader.h
1/*
2 * Copyright (c) 2006 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#ifndef _KIS_TIFF_READER_H_
21#define _KIS_TIFF_READER_H_
22
23// On some platforms, tiffio.h #defines NULL in a bad
24// way for C++, as (void *)0 instead of using the correct
25// C++ value 0. Include stdio.h first to get the right one.
26#include <stdio.h>
27#include <tiffio.h>
28
29// #include <tqvaluevector.h>
30// #include <tdeio/job.h>
31// #include <kis_progress_subject.h>
32
33#include <kis_paint_device.h>
34
35#include "kis_types.h"
36#include "kis_global.h"
37// #include "kis_annotation.h"
38
39#include <kis_iterator.h>
40#include <kis_paint_device.h>
41
42#define TQ_UINT32_MAX 4294967295u
43
44class TIFFStreamBase;
45
46class KisTIFFPostProcessor {
47 public:
48 KisTIFFPostProcessor(uint8 nbcolorssamples) : m_nbcolorssamples(nbcolorssamples) { }
49 public:
50 virtual void postProcess8bit( TQ_UINT8* ) { };
51 virtual void postProcess16bit( TQ_UINT16* ) { };
52 virtual void postProcess32bit( TQ_UINT32* ) { };
53 protected:
54 inline uint8 nbColorsSamples() { return m_nbcolorssamples; }
55 private:
56 uint8 m_nbcolorssamples;
57};
58
59class KisTIFFPostProcessorInvert : public KisTIFFPostProcessor {
60 public:
61 KisTIFFPostProcessorInvert(uint8 nbcolorssamples) : KisTIFFPostProcessor(nbcolorssamples) {}
62 public:
63 virtual void postProcess8bit( TQ_UINT8* data )
64 {
65 for(int i = 0; i < nbColorsSamples(); i++)
66 {
67 data[i] = TQ_UINT8_MAX - data[i];
68 }
69 }
70 virtual void postProcess16bit( TQ_UINT16* data )
71 {
72 TQ_UINT16* d = (TQ_UINT16*) data;
73 for(int i = 0; i < nbColorsSamples(); i++)
74 {
75 d[i] = TQ_UINT16_MAX - d[i];
76 }
77 }
78 virtual void postProcess32bit( TQ_UINT32* data )
79 {
80 TQ_UINT32* d = (TQ_UINT32*) data;
81 for(int i = 0; i < nbColorsSamples(); i++)
82 {
83 d[i] = TQ_UINT32_MAX - d[i];
84 }
85 }
86};
87
88class KisTIFFPostProcessorICCLABtoCIELAB : public KisTIFFPostProcessor {
89 public:
90 KisTIFFPostProcessorICCLABtoCIELAB(uint8 nbcolorssamples) : KisTIFFPostProcessor(nbcolorssamples) {}
91 public:
92 void postProcess8bit(TQ_UINT8* data)
93 {
94 TQ_INT8* ds = (TQ_INT8*) data;
95 for(int i = 1; i < nbColorsSamples(); i++)
96 {
97 ds[i] = data[i] - TQ_UINT8_MAX/2;
98 }
99 }
100 void postProcess16bit(TQ_UINT16* data)
101 {
102 TQ_UINT16* d = (TQ_UINT16*) data;
103 TQ_INT16* ds = (TQ_INT16*) data;
104 for(int i = 1; i < nbColorsSamples(); i++)
105 {
106 ds[i] = d[i] - TQ_UINT16_MAX /2;
107 }
108 }
109 void postProcess32bit(TQ_UINT32* data)
110 {
111 TQ_UINT32* d = (TQ_UINT32*) data;
112 TQ_INT32* ds = (TQ_INT32*) data;
113 for(int i = 1; i < nbColorsSamples(); i++)
114 {
115 ds[i] = d[i] - TQ_UINT32_MAX /2;
116 }
117 }
118};
119
120
121class KisTIFFReaderBase {
122 public:
123 KisTIFFReaderBase( KisPaintDeviceSP device, TQ_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)
124 {
125
126 }
127 public:
137 virtual uint copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream) =0;
141 virtual void finalize() { };
142 protected:
143 inline KisPaintDeviceSP paintDevice() { return m_device; }
144 inline TQ_UINT8 alphaPos() { return m_alphapos; }
145 inline TQ_UINT8 sourceDepth() { return m_sourceDepth; }
146 inline TQ_UINT8 nbColorsSamples() { return m_nbcolorssamples; }
147 inline TQ_UINT8 nbExtraSamples() { return m_nbextrasamples; }
148 inline TQ_UINT8* poses() { return m_poses; }
149 inline cmsHTRANSFORM transform() { return m_transformProfile; }
150 inline KisTIFFPostProcessor* postProcessor() { return m_postprocess; }
151 private:
152 KisPaintDeviceSP m_device;
153 TQ_UINT8 m_alphapos;
154 TQ_UINT8 m_sourceDepth;
155 TQ_UINT8 m_nbcolorssamples;
156 TQ_UINT8 m_nbextrasamples;
157 TQ_UINT8* m_poses;
158 cmsHTRANSFORM m_transformProfile;
159 KisTIFFPostProcessor* m_postprocess;
160 TQ_UINT32 m_tiffDataWidth;
161};
162
163class KisTIFFReaderTarget8bit : public KisTIFFReaderBase {
164 public:
165 KisTIFFReaderTarget8bit( KisPaintDeviceSP device, TQ_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, nbcolorssamples, extrasamplescount, transformProfile, postprocessor )
166 {
167
168 }
169 public:
170 virtual uint copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream);
171};
172
173
174class KisTIFFReaderTarget16bit : public KisTIFFReaderBase {
175 public:
176 KisTIFFReaderTarget16bit( KisPaintDeviceSP device, TQ_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, nbcolorssamples, extrasamplescount, transformProfile, postprocessor )
177 {
178
179 }
180 public:
181 virtual uint copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream) ;
182};
183
184class KisTIFFReaderTarget32bit : public KisTIFFReaderBase {
185 public:
186 KisTIFFReaderTarget32bit( KisPaintDeviceSP device, TQ_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, nbcolorssamples, extrasamplescount, transformProfile, postprocessor )
187 {
188
189 }
190 public:
191 virtual uint copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream) ;
192};
193
194class KisTIFFReaderFromPalette : public KisTIFFReaderBase {
195 public:
196 KisTIFFReaderFromPalette( KisPaintDeviceSP device, uint16 *red, uint16 *green, uint16 *blue, TQ_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)
197 {
198
199 }
200 public:
201 virtual uint copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream) ;
202 private:
203 uint16 *m_red, *m_green, *m_blue;
204};
205
206#endif