Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tiff_import.cc File Reference
#include "kis_tiff_import.h"
#include "KisImportExportErrorCode.h"
#include "kis_assert.h"
#include <QBuffer>
#include <QPair>
#include <QSharedPointer>
#include <QStack>
#include <array>
#include <exiv2/exiv2.hpp>
#include <kpluginfactory.h>
#include <tiffio.h>
#include <KisDocument.h>
#include <KisImportExportAdditionalChecks.h>
#include <KisViewManager.h>
#include <KoColorProfile.h>
#include <KoDocumentInfo.h>
#include <KoUnit.h>
#include <KisExiv2IODevice.h>
#include <kis_group_layer.h>
#include <kis_image.h>
#include <kis_meta_data_backend_registry.h>
#include <kis_meta_data_tags.h>
#include <kis_paint_layer.h>
#include <kis_transform_worker.h>
#include <kis_transparency_mask.h>
#include "kis_buffer_stream.h"
#include "kis_tiff_logger.h"
#include "kis_tiff_reader.h"
#include "kis_tiff_ycbcr_reader.h"
#include <kis_tiff_import.moc>

Go to the source code of this file.

Classes

struct  KisTiffBasicInfo
 

Enumerations

enum class  TiffResolution : quint8 { NONE = RESUNIT_NONE , INCH = RESUNIT_INCH , CM = RESUNIT_CENTIMETER }
 

Functions

QString getColorSpaceForColorType (uint16_t sampletype, uint16_t color_type, uint16_t color_nb_bits, TIFF *image, uint16_t &nbchannels, uint16_t &extrasamplescount, uint8_t &destDepth)
 
 K_PLUGIN_FACTORY_WITH_JSON (TIFFImportFactory, "krita_tiff_import.json", registerPlugin< KisTIFFImport >();) QPair< QString
 
template<typename T , typename Deleter >
auto make_unique_with_deleter (T *data, Deleter d)
 
template<template< typename > class T>
QSharedPointer< KisTIFFPostProcessormakePostProcessor (uint32_t nbsamples, const QPair< QString, QString > &id)
 

Enumeration Type Documentation

◆ TiffResolution

enum class TiffResolution : quint8
strong
Enumerator
NONE 
INCH 
CM 

Definition at line 60 of file kis_tiff_import.cc.

60 : quint8 {
61 NONE = RESUNIT_NONE,
62 INCH = RESUNIT_INCH,
63 CM = RESUNIT_CENTIMETER,
64};

Function Documentation

◆ getColorSpaceForColorType()

QString getColorSpaceForColorType ( uint16_t sampletype,
uint16_t color_type,
uint16_t color_nb_bits,
TIFF * image,
uint16_t & nbchannels,
uint16_t & extrasamplescount,
uint8_t & destDepth )

Definition at line 90 of file kis_tiff_import.cc.

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; // FIX the extrasamples count in case of
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 {}; // sanity check; no support for float of
123 // higher or lower bit depth
124 }
125 if (color_nb_bits <= 8) {
126 destDepth = 8;
128 } else /* if (color_nb_bits == bits16) */ {
129 destDepth = 16;
131 }
132
133 } else if (color_type == PHOTOMETRIC_RGB /*|| color_type == */) {
134 if (nbchannels == 0)
135 nbchannels = 3;
136 extrasamplescount =
137 nbchannels - 3; // FIX the extrasamples count in case of
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 {}; // sanity check; no support for float of
149 // higher or lower bit depth
150 } else {
151 if (color_nb_bits <= 8) {
152 destDepth = 8;
154 } else /* if (color_nb_bits == bits16) */ {
155 destDepth = 16;
157 }
158 }
159 } else if (color_type == PHOTOMETRIC_YCBCR) {
160 if (nbchannels == 0)
161 nbchannels = 3;
162 extrasamplescount =
163 nbchannels - 3; // FIX the extrasamples count in case of
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 {}; // sanity check; no support for float of
175 // higher or lower bit depth
176 } else {
177 if (color_nb_bits <= 8) {
178 destDepth = 8;
180 } else /* if (color_nb_bits == bits16) */ {
181 destDepth = 16;
182 return {YCbCrAColorModelID.id(),
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 {}; // sanity check; no support
194 // integers of higher bit depth
195 }
196 } else if (color_type == PHOTOMETRIC_SEPARATED) {
197 if (nbchannels == 0)
198 nbchannels = 4;
199 // SEPARATED is in general CMYK but not always, so we check
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) {
212 dbgFile << "Inks are :";
213 for (uint32_t i = 0; i < numberofinks; i++) {
214 dbgFile << ink_names[i];
215 }
216 } else {
217 dbgFile << "inknames are not defined !";
218 // To be able to read stupid adobe files, if there are no
219 // information about inks and four channels, then it's a CMYK
220 // file :
221 if (nbchannels - extrasamplescount != 4) {
222 return {};
223 }
224 // else - assume it's CMYK and proceed
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 {}; // sanity check; no support for float of
238 // higher or lower bit depth
239 }
240 if (color_nb_bits <= 8) {
241 destDepth = 8;
243 } else if (color_nb_bits == 16) {
244 destDepth = 16;
246 } else {
247 return {}; // no support for other bit depths
248 }
249 } else if (color_type == PHOTOMETRIC_CIELAB
250 || color_type == PHOTOMETRIC_ICCLAB) {
251 if (nbchannels == 0)
252 nbchannels = 3;
253 extrasamplescount = nbchannels - 3; // FIX the extrasamples count
254
255 switch (color_nb_bits) {
256 case bits32: {
257 destDepth = bits32;
258 if (sampletype == SAMPLEFORMAT_IEEEFP) {
260 } else {
261 return {}; // no support for other bit depths
262 }
263 }
264 case bits16: {
265 destDepth = bits16;
266 if (sampletype == SAMPLEFORMAT_IEEEFP) {
267#ifdef HAVE_OPENEXR
269#endif
270 } else {
272 }
273 return {}; // no support for other bit depths
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; // FIX the extrasamples count
288 // <-- we will convert the index image to RGBA16 as the palette is
289 // always on 16bits colors
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"))
QString id() const
Definition KoID.cpp:63
#define dbgFile
Definition kis_debug.h:53

References CMYKAColorModelID, dbgFile, Float16BitsColorDepthID, Float32BitsColorDepthID, GrayAColorModelID, KoID::id(), Integer16BitsColorDepthID, Integer8BitsColorDepthID, LABAColorModelID, RGBAColorModelID, and YCbCrAColorModelID.

◆ K_PLUGIN_FACTORY_WITH_JSON()

K_PLUGIN_FACTORY_WITH_JSON ( TIFFImportFactory ,
"krita_tiff_import.json" ,
registerPlugin< KisTIFFImport >();  )

◆ make_unique_with_deleter()

template<typename T , typename Deleter >
auto make_unique_with_deleter ( T * data,
Deleter d )

Definition at line 330 of file kis_tiff_import.cc.

331{
332 return std::unique_ptr<T, Deleter>(data, d);
333}

◆ makePostProcessor()

template<template< typename > class T>
QSharedPointer< KisTIFFPostProcessor > makePostProcessor ( uint32_t nbsamples,
const QPair< QString, QString > & id )

Definition at line 297 of file kis_tiff_import.cc.

298{
299 if (id.second == Integer8BitsColorDepthID.id()) {
300 return QSharedPointer<T<uint8_t>>::create(nbsamples);
301 } else if (id.second == Integer16BitsColorDepthID.id()) {
302 return QSharedPointer<T<uint16_t>>::create(nbsamples);
303#ifdef HAVE_OPENEXR
304 } else if (id.second == Float16BitsColorDepthID.id()) {
305 return QSharedPointer<T<half>>::create(nbsamples);
306#endif
307 } else if (id.second == Float32BitsColorDepthID.id()) {
308 return QSharedPointer<T<float>>::create(nbsamples);
309 } else {
310 KIS_ASSERT(false && "TIFF does not support this bit depth!");
311 return {};
312 }
313}
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References Float16BitsColorDepthID, Float32BitsColorDepthID, KoID::id(), Integer16BitsColorDepthID, Integer8BitsColorDepthID, and KIS_ASSERT.