AcademySoftwareFoundation / AcademySoftwareFoundation/OpenImageIO
[BUG] CMYK is being saved as RGB on export
- 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

But after saving the image file

The Original Photo

The processed photo

Contributor 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