Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] CMYK is being saved as RGB on export #4170

Open
TGS963 opened this issue Mar 2, 2024 · 0 comments
Open

[BUG] CMYK is being saved as RGB on export #4170

TGS963 opened this issue Mar 2, 2024 · 0 comments

Comments

@TGS963
Copy link

TGS963 commented Mar 2, 2024

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<ImageInput> 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<ImageOutput> out = ImageOutput::create(v.outpath.c_str());
if (!out)
{
    std::cerr << "Could not create output image, error = " << geterror() << "\n";
    continue;
}

std::unique_ptr<ImageInput> 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

But after saving the image file
image

The Original Photo
cmyk_original

The processed photo
cmyk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant