tiff-save: store as CMYK with ICC profile even if incoming RGB

This permits the following to work to convert an RGB image to
16bit integer tiff with the desired ICC profile:

gegl input.jpg -- convert-space path=FOGRA29L_uncoated.icc tiff-save path=output.tif bitdepth=16 fp=0

This will also work for a file loaded with a CMYK ICC profile that has been
"demoted" to RGB at some point in the chain.
parent 83601142
...@@ -377,6 +377,7 @@ export_tiff (GeglOperation *operation, ...@@ -377,6 +377,7 @@ export_tiff (GeglOperation *operation,
gshort color_space, compression = COMPRESSION_NONE; gshort color_space, compression = COMPRESSION_NONE;
gushort bits_per_sample, samples_per_pixel; gushort bits_per_sample, samples_per_pixel;
gboolean has_alpha, alpha_is_premultiplied = FALSE; gboolean has_alpha, alpha_is_premultiplied = FALSE;
BablModelFlag model_flags;
gushort sample_format, predictor = 0; gushort sample_format, predictor = 0;
gushort extra_types[1]; gushort extra_types[1];
glong rows_per_stripe = 1; glong rows_per_stripe = 1;
...@@ -397,6 +398,7 @@ export_tiff (GeglOperation *operation, ...@@ -397,6 +398,7 @@ export_tiff (GeglOperation *operation,
model = babl_format_get_model(format); model = babl_format_get_model(format);
space = babl_format_get_space (format); space = babl_format_get_space (format);
type = babl_format_get_type(format, 0); type = babl_format_get_type(format, 0);
model_flags = babl_get_model_flags (model);
{ {
int icc_len; int icc_len;
...@@ -406,6 +408,24 @@ export_tiff (GeglOperation *operation, ...@@ -406,6 +408,24 @@ export_tiff (GeglOperation *operation,
TIFFSetField (p->tiff, TIFFTAG_ICCPROFILE, icc_len, icc_profile); TIFFSetField (p->tiff, TIFFTAG_ICCPROFILE, icc_len, icc_profile);
} }
if (babl_space_is_cmyk (space))
{
color_space = PHOTOMETRIC_SEPARATED;
predictor = 2;
if (model_flags & BABL_MODEL_FLAG_ALPHA)
{
has_alpha = TRUE;
alpha_is_premultiplied = FALSE;
model = babl_model("CMYKA");
samples_per_pixel = 5;
}
else
{
has_alpha = FALSE;
model = babl_model("CMYK");
samples_per_pixel = 4;
}
}
if (babl_model_is (model, "Y") || babl_model_is (model, "Y'")) if (babl_model_is (model, "Y") || babl_model_is (model, "Y'"))
{ {
has_alpha = FALSE; has_alpha = FALSE;
...@@ -429,12 +449,17 @@ export_tiff (GeglOperation *operation, ...@@ -429,12 +449,17 @@ export_tiff (GeglOperation *operation,
model = babl_model("Y'aA"); model = babl_model("Y'aA");
samples_per_pixel = 2; samples_per_pixel = 2;
} }
else if (babl_model_is (model, "RGB") || babl_model_is (model, "R'G'B'")) else if (babl_model_is (model, "cmykA") ||
babl_model_is (model, "CMYKA") ||
babl_model_is (model, "camayakaA")||
babl_model_is (model, "CaMaYaKaA") ||
babl_space_is_cmyk (space))
{ {
has_alpha = FALSE; has_alpha = TRUE;
color_space = PHOTOMETRIC_RGB; alpha_is_premultiplied = FALSE;
model = babl_model("R'G'B'"); color_space = PHOTOMETRIC_SEPARATED;
samples_per_pixel = 3; model = babl_model("CMYKA");
samples_per_pixel = 5;
predictor = 2; predictor = 2;
} }
else if (babl_model_is (model, "cmyk") || else if (babl_model_is (model, "cmyk") ||
...@@ -446,16 +471,12 @@ export_tiff (GeglOperation *operation, ...@@ -446,16 +471,12 @@ export_tiff (GeglOperation *operation,
samples_per_pixel = 4; samples_per_pixel = 4;
predictor = 2; predictor = 2;
} }
else if (babl_model_is (model, "cmykA") || else if (babl_model_is (model, "RGB") || babl_model_is (model, "R'G'B'"))
babl_model_is (model, "CMYKA") ||
babl_model_is (model, "camayakaA")||
babl_model_is (model, "CaMaYaKaA"))
{ {
has_alpha = TRUE; has_alpha = FALSE;
alpha_is_premultiplied = FALSE; color_space = PHOTOMETRIC_RGB;
color_space = PHOTOMETRIC_SEPARATED; model = babl_model("R'G'B'");
model = babl_model("CMYKA"); samples_per_pixel = 3;
samples_per_pixel = 5;
predictor = 2; predictor = 2;
} }
#if 0 #if 0
......
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