AcademySoftwareFoundation / OpenImageIO

Reading, writing, and processing images in a wide variety of file formats, using a format-agnostic API, aimed at VFX applications.

Home Page:https://openimageio.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Photoshop files currently dont load 16- and 32- bit files' image data

EmilDohne opened this issue · comments

Describe the bug

When loading 16- or 32-bit Photoshop files (psd and psb) they will only extract the merged image data but not the data from the individual layers

Related issues and link to discussion with more information:

#3900, #3910 (reply in thread)

To Reproduce

  1. Create a 8- and 16-/32- bit file
  2. Run this code uncommenting the relevant files:
#include "OpenImageIO/imageio.h"

int main()
{
   //std::filesystem::path filePath = "File_16bit.psd";
   std::filesystem::path filePath = "File_8bit.psd";

    auto inp = OIIO::ImageInput::open(filePath.string());
    int subimage = 0;
    while (inp->seek_subimage(subimage, 0)) {
        const OIIO::ImageSpec& spec = inp->spec();
        int npixels = spec.width * spec.height;
        int nchannels = spec.nchannels;
        auto pixels = std::vector<unsigned char>(npixels * nchannels, 0);
        inp->read_image(subimage, 0, 0, nchannels, OIIO::TypeDesc::UINT8, pixels.data());

        std::cout << subimage << std::endl;
        ++subimage;
    }
}
  1. Even if the files are exactly identical with only bit-depth being the difference running the result for the 16-/32- bit files will always be that it only reads the first subimage (merged image section) but not the layers

Potential Fixes

This issue requires two fixes:

The first is extending the code to actually recognize layer data from 16- and 32-bit files by reading the 'Lr16' and 'Lr32' tagged blocks and extracting the layer info from there

The second one would require implementation of the Zip and ZipPrediction compression codecs as well as storage of the full decompressed image buffer on call to PSDInput::read_native_scanline() as these compression codecs do not allow for random access scanline reads and instead require the whole buffer to be decompressed.

For more information on this I have created this reply to a discussion #3910 (reply in thread)

@EmilDohne Is this issue fully solved by #4208? Can this one be closed?

@igritz yes, this is now fixed!