97{
98 const int bits32 = 32;
99 const int bits16 = 16;
100 const int bits8 = 8;
101
102 if (sampletype == SAMPLEFORMAT_INT) {
103 dbgFile <<
"Detected signed TIFF image" << color_type << color_nb_bits;
104 }
105
106 if (color_type == PHOTOMETRIC_MINISWHITE
107 || color_type == PHOTOMETRIC_MINISBLACK) {
108 if (nbchannels == 0)
109 nbchannels = 1;
110 extrasamplescount =
111 nbchannels - 1;
112 if (sampletype == SAMPLEFORMAT_IEEEFP) {
113 if (color_nb_bits == 16) {
114#ifdef HAVE_OPENEXR
115 destDepth = 16;
117#endif
118 } else if (color_nb_bits == 32) {
119 destDepth = 32;
121 }
122 return {};
123
124 }
125 if (color_nb_bits <= 8) {
126 destDepth = 8;
128 } else {
129 destDepth = 16;
131 }
132
133 } else if (color_type == PHOTOMETRIC_RGB ) {
134 if (nbchannels == 0)
135 nbchannels = 3;
136 extrasamplescount =
137 nbchannels - 3;
138 if (sampletype == SAMPLEFORMAT_IEEEFP) {
139 if (color_nb_bits == 16) {
140#ifdef HAVE_OPENEXR
141 destDepth = 16;
143#endif
144 } else if (color_nb_bits == 32) {
145 destDepth = 32;
147 }
148 return {};
149
150 } else {
151 if (color_nb_bits <= 8) {
152 destDepth = 8;
154 } else {
155 destDepth = 16;
157 }
158 }
159 } else if (color_type == PHOTOMETRIC_YCBCR) {
160 if (nbchannels == 0)
161 nbchannels = 3;
162 extrasamplescount =
163 nbchannels - 3;
164 if (sampletype == SAMPLEFORMAT_IEEEFP) {
165 if (color_nb_bits == 16) {
166#ifdef HAVE_OPENEXR
167 destDepth = 16;
169#endif
170 } else if (color_nb_bits == 32) {
171 destDepth = 32;
173 }
174 return {};
175
176 } else {
177 if (color_nb_bits <= 8) {
178 destDepth = 8;
180 } else {
181 destDepth = 16;
184 }
185 }
186 if (color_nb_bits <= 8) {
187 destDepth = 8;
189 } else if (color_nb_bits == bits16) {
190 destDepth = 16;
192 } else {
193 return {};
194
195 }
196 } else if (color_type == PHOTOMETRIC_SEPARATED) {
197 if (nbchannels == 0)
198 nbchannels = 4;
199
200 uint16_t inkset = 0;
201 if ((TIFFGetField(image, TIFFTAG_INKSET, &inkset) == 0)) {
202 dbgFile <<
"Image does not define the inkset.";
203 inkset = 2;
204 }
205 if (inkset != INKSET_CMYK) {
206 dbgFile <<
"Unsupported inkset (right now, only CMYK is supported)";
207 char **ink_names = nullptr;
208 uint16_t numberofinks = 0;
209 if (TIFFGetField(image, TIFFTAG_INKNAMES, &ink_names) == 1
210 && TIFFGetField(image, TIFFTAG_NUMBEROFINKS, &numberofinks)
211 == 1) {
213 for (uint32_t i = 0; i < numberofinks; i++) {
215 }
216 } else {
217 dbgFile <<
"inknames are not defined !";
218
219
220
221 if (nbchannels - extrasamplescount != 4) {
222 return {};
223 }
224
225 }
226 }
227 if (sampletype == SAMPLEFORMAT_IEEEFP) {
228 if (color_nb_bits == 16) {
229#ifdef HAVE_OPENEXR
230 destDepth = 16;
232#endif
233 } else if (color_nb_bits == 32) {
234 destDepth = 32;
236 }
237 return {};
238
239 }
240 if (color_nb_bits <= 8) {
241 destDepth = 8;
243 } else if (color_nb_bits == 16) {
244 destDepth = 16;
246 } else {
247 return {};
248 }
249 } else if (color_type == PHOTOMETRIC_CIELAB
250 || color_type == PHOTOMETRIC_ICCLAB) {
251 if (nbchannels == 0)
252 nbchannels = 3;
253 extrasamplescount = nbchannels - 3;
254
255 switch (color_nb_bits) {
256 case bits32: {
257 destDepth = bits32;
258 if (sampletype == SAMPLEFORMAT_IEEEFP) {
260 } else {
261 return {};
262 }
263 }
264 case bits16: {
265 destDepth = bits16;
266 if (sampletype == SAMPLEFORMAT_IEEEFP) {
267#ifdef HAVE_OPENEXR
269#endif
270 } else {
272 }
273 return {};
274 }
275 case bits8: {
276 destDepth = bits8;
278 }
279 default: {
280 return {};
281 }
282 }
283 } else if (color_type == PHOTOMETRIC_PALETTE) {
284 destDepth = 16;
285 if (nbchannels == 0)
286 nbchannels = 2;
287 extrasamplescount = nbchannels - 2;
288
289
291 }
292 return {};
293}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID YCbCrAColorModelID("YCbCrA", ki18n("YCbCr/Alpha"))
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))