RE: Combining HDR/EXR files into a single PSD
Posted: 2019-07-29T10:48:24-07:00
Hi there all,
I've been using Magick++ for a system which handles compositing image layers. The source images sent to Magick++ are in EXR format and contain 16bit linear colorspace data (these are coming from Unity and are HDR images) I'm currently facing two issues:
1 -The output PSD I create contains these layers correctly but it seems the data is clamped/incorrect. See the example pixel value in the source EXR and PSD file Magick++ outputs. I understand Photoshop handles 16bit a little strangely.
Original source EXR pixel value:
Magick++ output PSD pixel value:
Is this data clamped in the output file because I have built the 16 bit version of Magick++, and would it be expected to correctly hold the original pixel values if this was rebuilt with Magick++ set to 32bit quantum depth? Currently I have to switch mode to 32 bit in Photoshop when opening the output file in order to start making adjustments to layers, but my EXR's are captured using a half-precision 16bit per channel format.
2 -The file size of the output PSD's is larger than expected for the number of layers. Does anyone know of any further parameters/config to ease this? I'll put a snippet of my output function I've written below.
For reference, an output PSD containing 3 layers at 1920x1080 shows up at around 63.5Mb, resaving the file in Photoshop reduces the file size by almost half. When I resave these files in 32bit mode (as my adjustments need to be done in 32bit to function correctly with HDR data it seems) they are usually around the same size as the 16 bit output file Magick++ produced.
Thanks to anyone who reads this and can offer advice, really appreciate it as I've been working on this for a while and this roadblock is one of the final hurdles!
I've been using Magick++ for a system which handles compositing image layers. The source images sent to Magick++ are in EXR format and contain 16bit linear colorspace data (these are coming from Unity and are HDR images) I'm currently facing two issues:
1 -The output PSD I create contains these layers correctly but it seems the data is clamped/incorrect. See the example pixel value in the source EXR and PSD file Magick++ outputs. I understand Photoshop handles 16bit a little strangely.
Original source EXR pixel value:
Magick++ output PSD pixel value:
Is this data clamped in the output file because I have built the 16 bit version of Magick++, and would it be expected to correctly hold the original pixel values if this was rebuilt with Magick++ set to 32bit quantum depth? Currently I have to switch mode to 32 bit in Photoshop when opening the output file in order to start making adjustments to layers, but my EXR's are captured using a half-precision 16bit per channel format.
2 -The file size of the output PSD's is larger than expected for the number of layers. Does anyone know of any further parameters/config to ease this? I'll put a snippet of my output function I've written below.
Code: Select all
bool merge_images_layered_psd(string output_path)
{
bool completed = false;
try
{
list<Image> layersToFlatten;
for (pair<string,string> imageInfo : images_to_layer)
{
string extension = PathFindExtension(imageInfo.first.c_str());
Image image;
try
{
image.read(imageInfo.first);
}
catch (Magick::ErrorConfigure &error)
{
cerr << error.what() << endl;
}
image.label(imageInfo.second);
if (extension == ".exr")
{
image.colorSpaceType(ColorspaceType::RGBColorspace);
image.type(ImageType::TrueColorAlphaType);
}
image.colorSpaceType(ColorspaceType::RGBColorspace);
image.alphaChannel(AlphaChannelOption::SetAlphaChannel);
image.attribute("alpha", "Activate");
image.attribute("colorspace:auto-grayscale", "false");
layersToFlatten.push_back(image);
}
Image flattened;
flattenImages(&flattened, layersToFlatten.begin(), layersToFlatten.end());
flattened.label("CompositeLayer");
flattened.colorSpaceType(ColorspaceType::RGBColorspace);
flattened.alphaChannel(AlphaChannelOption::SetAlphaChannel);
flattened.attribute("alpha", "Activate");
flattened.attribute("colorspace:auto-grayscale", "false");
list<Image> layersForPsd;
layersForPsd.push_back(flattened);
for (auto img : layersToFlatten)
{
layersForPsd.push_back(img);
}
writeImages(layersForPsd.begin(), layersForPsd.end(), output_path, true);
completed = true;
}
catch (exception &error_)
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
images_to_layer.clear();
return completed;
}
For reference, an output PSD containing 3 layers at 1920x1080 shows up at around 63.5Mb, resaving the file in Photoshop reduces the file size by almost half. When I resave these files in 32bit mode (as my adjustments need to be done in 32bit to function correctly with HDR data it seems) they are usually around the same size as the 16 bit output file Magick++ produced.
Thanks to anyone who reads this and can offer advice, really appreciate it as I've been working on this for a while and this roadblock is one of the final hurdles!