Commit d0c5d769 authored by Agata Cacko's avatar Agata Cacko

Add support for more color spaces in tiff impex

This commit adds support for following color spaces/bit depths:
Export:
- laba i8, f32
- graya f16, f32
- cmykaf32
Import:
- cmyka f32
- laba f32, f16, i8

CCBUG:408177
BUG:391987
parent 2a510033
......@@ -57,6 +57,10 @@ namespace
QPair<QString, QString> getColorSpaceForColorType(uint16 sampletype, uint16 color_type, uint16 color_nb_bits, TIFF *image, uint16 &nbchannels, uint16 &extrasamplescount, uint8 &destDepth)
{
const int bits32 = 32;
const int bits16 = 16;
const int bits8 = 8;
if (color_type == PHOTOMETRIC_MINISWHITE || color_type == PHOTOMETRIC_MINISBLACK) {
if (nbchannels == 0) nbchannels = 1;
extrasamplescount = nbchannels - 1; // FIX the extrasamples count in case of
......@@ -74,7 +78,7 @@ QPair<QString, QString> getColorSpaceForColorType(uint16 sampletype, uint16 colo
destDepth = 8;
return QPair<QString, QString>(GrayAColorModelID.id(), Integer8BitsColorDepthID.id());
}
else {
else /* if (color_nb_bits == bits16) */ {
destDepth = 16;
return QPair<QString, QString>(GrayAColorModelID.id(), Integer16BitsColorDepthID.id());
}
......@@ -91,14 +95,13 @@ QPair<QString, QString> getColorSpaceForColorType(uint16 sampletype, uint16 colo
destDepth = 32;
return QPair<QString, QString>(RGBAColorModelID.id(), Float32BitsColorDepthID.id());
}
return QPair<QString, QString>();
return QPair<QString, QString>(); // sanity check; no support for float of higher or lower bit depth
}
else {
if (color_nb_bits <= 8) {
destDepth = 8;
return QPair<QString, QString>(RGBAColorModelID.id(), Integer8BitsColorDepthID.id());
}
else {
} else /* if (color_nb_bits == bits16) */ {
destDepth = 16;
return QPair<QString, QString>(RGBAColorModelID.id(), Integer16BitsColorDepthID.id());
}
......@@ -106,13 +109,18 @@ QPair<QString, QString> getColorSpaceForColorType(uint16 sampletype, uint16 colo
} else if (color_type == PHOTOMETRIC_YCBCR) {
if (nbchannels == 0) nbchannels = 3;
extrasamplescount = nbchannels - 3; // FIX the extrasamples count in case of
if (sampletype == SAMPLEFORMAT_IEEEFP) {
return QPair<QString, QString>(); // sanity check; no support for float
}
if (color_nb_bits <= 8) {
destDepth = 8;
return QPair<QString, QString>(YCbCrAColorModelID.id(), Integer8BitsColorDepthID.id());
}
else {
else if (color_nb_bits == bits16) {
destDepth = 16;
return QPair<QString, QString>(YCbCrAColorModelID.id(), Integer16BitsColorDepthID.id());
} else {
return QPair<QString, QString>(); // sanity check; no support integers of higher bit depth
}
}
else if (color_type == PHOTOMETRIC_SEPARATED) {
......@@ -139,22 +147,48 @@ QPair<QString, QString> getColorSpaceForColorType(uint16 sampletype, uint16 colo
if (nbchannels - extrasamplescount != 4) {
return QPair<QString, QString>();
}
// else - assume it's CMYK and proceed
}
}
if (color_nb_bits <= 8) {
destDepth = 8;
return QPair<QString, QString>(CMYKAColorModelID.id(), Integer8BitsColorDepthID.id());
}
else {
} else if (color_nb_bits == 16) {
destDepth = 16;
return QPair<QString, QString>(CMYKAColorModelID.id(), Integer16BitsColorDepthID.id());
} else if (sampletype == SAMPLEFORMAT_IEEEFP) {
destDepth = bits32;
return QPair<QString, QString>(CMYKAColorModelID.id(), Float32BitsColorDepthID.id());
} else {
return QPair<QString, QString>(); // no support for other bit depths
}
}
else if (color_type == PHOTOMETRIC_CIELAB || color_type == PHOTOMETRIC_ICCLAB) {
destDepth = 16;
if (nbchannels == 0) nbchannels = 3;
extrasamplescount = nbchannels - 3; // FIX the extrasamples count
return QPair<QString, QString>(LABAColorModelID.id(), Integer16BitsColorDepthID.id());
switch(color_nb_bits) {
case bits32: {
destDepth = bits32;
return QPair<QString, QString>(LABAColorModelID.id(), Float32BitsColorDepthID.id());
}
case bits16: {
destDepth = bits16;
if (sampletype == SAMPLEFORMAT_IEEEFP) {
return QPair<QString, QString>(LABAColorModelID.id(), Float16BitsColorDepthID.id());
}
else {
return QPair<QString, QString>(LABAColorModelID.id(), Integer16BitsColorDepthID.id());
}
}
case bits8: {
destDepth = bits8;
return QPair<QString, QString>(LABAColorModelID.id(), Integer8BitsColorDepthID.id());
}
default: {
return QPair<QString, QString>();
}
}
}
else if (color_type == PHOTOMETRIC_PALETTE) {
destDepth = 16;
......
......@@ -58,27 +58,35 @@ namespace
color_type = PHOTOMETRIC_SEPARATED;
TIFFSetField(image, TIFFTAG_INKSET, INKSET_CMYK);
if (isBitDepthFloat(depth)) {
destColorSpace = KoColorSpaceRegistry::instance()->colorSpace(CMYKAColorModelID.id(), Integer16BitsColorDepthID.id(), cs->profile());
if (depth == "F16") {
sample_format = SAMPLEFORMAT_IEEEFP;
destColorSpace = KoColorSpaceRegistry::instance()->colorSpace(CMYKAColorModelID.id(), Float32BitsColorDepthID.id(), cs->profile());
return false;
}
if (isBitDepthFloat(depth)) {
sample_format = SAMPLEFORMAT_IEEEFP;
}
return true;
} else if (id.contains("LABA")) {
color_type = PHOTOMETRIC_ICCLAB;
if (depth != "U16") {
destColorSpace = KoColorSpaceRegistry::instance()->colorSpace(LABAColorModelID.id(), Integer16BitsColorDepthID.id(), cs->profile());
if (depth == "F16") {
sample_format = SAMPLEFORMAT_IEEEFP;
destColorSpace = KoColorSpaceRegistry::instance()->colorSpace(LABAColorModelID.id(), Float32BitsColorDepthID.id(), cs->profile());
return false;
}
if (isBitDepthFloat(depth)) {
sample_format = SAMPLEFORMAT_IEEEFP;
}
return true;
} else if (id.contains("GRAYA")) {
color_type = PHOTOMETRIC_MINISBLACK;
QList<QString> possibleDepths;
possibleDepths << "U16" << "U8";
if (!possibleDepths.contains(depth)) {
destColorSpace = KoColorSpaceRegistry::instance()->colorSpace(GrayAColorModelID.id(), Integer16BitsColorDepthID.id(), cs->profile());
return false;
if (isBitDepthFloat(depth)) {
sample_format = SAMPLEFORMAT_IEEEFP;
}
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment