AcademySoftwareFoundation / AcademySoftwareFoundation/OpenImageIO

[BUG] CMYK is being saved as RGB on export

Open
#4,170 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.4k
Forks
698
Avg merge
3d 4h
Merged PRs (30d)
47

Description

**Describe the bug**

We employ the oiio library for reading and writing files before and after upscaling images. However, it saves CMYK images as RGB during export, although they appear correct before exporting.

**OpenImageIO version and dependencies**

OpenImageIO version 2.5.7.0-1 installed from ArchLinux repo

**To Reproduce**

We use the C++ API for using oiio in our code

The code to save is
```

std::unique_ptr in = ImageInput::open(imagepath.c_str());
if (!in)
{
std::cerr << "Could not open " << imagepath.c_str() << ", error = " << geterror() << "\n";
errorOccurred = true;
continue;
}

const ImageSpec &spec = in->spec();
w = spec.width;
h = spec.height;
c = spec.nchannels;

pixeldata = new unsigned char[w * h * c];
in->read_image(0, 0, 0, c, TypeDesc::UINT8, pixeldata);
in->close();
```

and the code to save image is:

```

std::unique_ptr out = ImageOutput::create(v.outpath.c_str());
if (!out)
{
std::cerr << "Could not create output image, error = " << geterror() << "\n";
continue;
}

std::unique_ptr in = ImageInput::open(v.inpath.c_str());
if (!in)
{
std::cerr << "Could not read input image, error = " << geterror() << "\n";
continue; // Handle error appropriately
}
const ImageSpec &inputImageSpec = in->spec();
in->close(); // Close the input image

ImageSpec spec(v.outimage.w, v.outimage.h, v.outimage.elempack, TypeDesc::UINT8);

spec.extra_attribs = inputImageSpec.extra_attribs;
spec.extra_attribs.attribute("XResolution", 300);
spec.extra_attribs.attribute("YResolution", 300);
spec.extra_attribs.attribute("Exif:PixelXDimension", v.outimage.w);
spec.extra_attribs.attribute("Exif:PixelYDimension", v.outimage.h);
std::cout << "\n\nNew Color Space: " << spec.extra_attribs.get_string("ICCProfile:color_space") << "\n\n";

success = out->open(v.outpath.c_str(), spec);
if (!success)
{
std::cerr << "Could not open output image, error = " << out->geterror() << "\n";
continue;
}
success = out->write_image(TypeDesc::UINT8, v.outimage.data);
if (!success)
{
std::cerr << "Could not write output image, error = " << out->geterror() << "\n";
continue;
}

out->close();
```

oiiotool code to replicate is

`oiiotool output/cmyk_original.jpg --resize 500x333 --metamerge -o cmyk1.jpg`

**Evidence**

The information is there before saving
![image](https://github.com/AcademySoftwareFoundation/OpenImageIO/assets/46394656/002add0d-5172-404b-beb5-59539f44fda9)

But after saving the image file
![image](https://github.com/AcademySoftwareFoundation/OpenImageIO/assets/46394656/34813f99-a363-4a74-ab08-ccdde7c9bcda)

The Original Photo
![cmyk_original](https://github.com/AcademySoftwareFoundation/OpenImageIO/assets/46394656/8a24c4a8-4ffe-4fa4-9abf-28fbf230c454)

The processed photo
![cmyk](https://github.com/AcademySoftwareFoundation/OpenImageIO/assets/46394656/aa2c5fc4-fee9-4a60-8d3d-24e1d5b41d34)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided oiiotool command and reviewing the C++ ImageInput/ImageOutput usage. Compare the channel count and color-space metadata before and after export; done means CMYK input remains CMYK after resizing and saving, with an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.