filters

kis_tiff_reader.cpp
1/*
2 * Copyright (c) 2005-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#include "kis_tiff_reader.h"
21
22#include <kdebug.h>
23
24#include <kis_iterators_pixel.h>
25#include <kis_paint_device.h>
26
27#include "kis_tiff_stream.h"
28
29 uint KisTIFFReaderTarget8bit::copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream)
30 {
31 KisHLineIterator it = paintDevice() -> createHLineIterator(x, y, dataWidth, true);
32 double coeff = TQ_UINT8_MAX / (double)( pow(2, sourceDepth() ) - 1 );
33// kdDebug(41008) << " depth expension coefficient : " << coeff << endl;
34 while (!it.isDone()) {
35 TQ_UINT8 *d = it.rawData();
36 TQ_UINT8 i;
37 for(i = 0; i < nbColorsSamples() ; i++)
38 {
39 d[poses()[i]] = (TQ_UINT8)( tiffstream->nextValue() * coeff );
40 }
41 postProcessor()->postProcess8bit( d);
42 if(transform()) cmsDoTransform(transform(), d, d, 1);
43 d[poses()[i]] = TQ_UINT8_MAX;
44 for(int k = 0; k < nbExtraSamples(); k++)
45 {
46 if(k == alphaPos())
47 d[poses()[i]] = (TQ_UINT32) ( tiffstream->nextValue() * coeff );
48 else
49 tiffstream->nextValue();
50 }
51 ++it;
52 }
53 return 1;
54 }
55 uint KisTIFFReaderTarget16bit::copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream)
56 {
57 KisHLineIterator it = paintDevice() -> createHLineIterator(x, y, dataWidth, true);
58 double coeff = TQ_UINT16_MAX / (double)( pow(2, sourceDepth() ) - 1 );
59// kdDebug(41008) << " depth expension coefficient : " << coeff << endl;
60 while (!it.isDone()) {
61 TQ_UINT16 *d = reinterpret_cast<TQ_UINT16 *>(it.rawData());
62 TQ_UINT8 i;
63 for(i = 0; i < nbColorsSamples(); i++)
64 {
65 d[poses()[i]] = (TQ_UINT16)( tiffstream->nextValue() * coeff );
66 }
67 postProcessor()->postProcess16bit( d);
68 if(transform()) cmsDoTransform(transform(), d, d, 1);
69 d[poses()[i]] = TQ_UINT16_MAX;
70 for(int k = 0; k < nbExtraSamples(); k++)
71 {
72 if(k == alphaPos())
73 d[poses()[i]] = (TQ_UINT16) ( tiffstream->nextValue() * coeff );
74 else
75 tiffstream->nextValue();
76 }
77 ++it;
78 }
79 return 1;
80 }
81
82 uint KisTIFFReaderTarget32bit::copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream)
83 {
84 KisHLineIterator it = paintDevice() -> createHLineIterator(x, y, dataWidth, true);
85 double coeff = TQ_UINT32_MAX / (double)( pow(2, sourceDepth() ) - 1 );
86// kdDebug(41008) << " depth expension coefficient : " << coeff << endl;
87 while (!it.isDone()) {
88 TQ_UINT32 *d = reinterpret_cast<TQ_UINT32 *>(it.rawData());
89 TQ_UINT8 i;
90 for(i = 0; i < nbColorsSamples(); i++)
91 {
92 d[poses()[i]] = (TQ_UINT32)( tiffstream->nextValue() * coeff );
93 }
94 postProcessor()->postProcess32bit( d);
95 if(transform()) cmsDoTransform(transform(), d, d, 1);
96 d[poses()[i]] = TQ_UINT32_MAX;
97 for(int k = 0; k < nbExtraSamples(); k++)
98 {
99 if(k == alphaPos())
100 d[poses()[i]] = (TQ_UINT32) ( tiffstream->nextValue() * coeff );
101 else
102 tiffstream->nextValue();
103 }
104 ++it;
105 }
106 return 1;
107 }
108 uint KisTIFFReaderFromPalette::copyDataToChannels(TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream)
109 {
110 KisHLineIterator it = paintDevice() -> createHLineIterator(x, y, dataWidth, true);
111 while (!it.isDone()) {
112 TQ_UINT16* d = reinterpret_cast<TQ_UINT16 *>(it.rawData());
113 uint32 index = tiffstream->nextValue();
114 d[2] = m_red[index];
115 d[1] = m_green[index];
116 d[0] = m_blue[index];
117 d[3] = TQ_UINT16_MAX;
118 ++it;
119 }
120 return 1;
121 }