开发者

OpenEXR image loading

开发者 https://www.devze.com 2022-12-22 23:24 出处:网络
I\'ve started to load EXR images using OpenEXR. I have to get the RGB pixels using floating point type.

I've started to load EXR images using OpenEXR. I have to get the RGB pixels using floating point type.

For RGB images, there was no problem on loading, using this code:

ImfInputFile *iFile = ImfOpenInputFile(filename);
        FrameBuffer fb;
        const Header &iHeader = iFile.header();
        bool hasRed = false, hasGreen = false, hasBlue = false;
        bool hasY = false;
        Box2i dw = iHeader.dataWindow();
        int width = dw.max.x-dw.min.x+1;
        int height = dw.max.y-dw.min.y+1;

        for (ChannelList::ConstIterator it = iHeader.channels().begin(), ite = iHeader.channels().end(); it != ite; it++) {
            if ((strcmp(it.name(), "R") == 0)) { hasRed = true; }
            if ((strcmp(it.name(), "G") == 0)) { hasGreen = true; }
            if ((strcmp(it.name(), "B") == 0)) { hasBlue = true; }
            if (it.channel().type != HALF) {
                HDR_LOG("Unable to open EXR file \"%s\" (unsupported data type %s)", filename, it.channel().type);
                return (IEFileCantOpen);
            }
        }

        if ((hasRed == true) || (hasGreen == true) || (hasBlue == true)) {
            fb.insert("R", Slice(
                Imf::FLOAT, (char*)((char*)image->data + (sizeof(float) * 0)),
                sizeof(float) * 3,
                sizeof(float) * width * 3,
                1, 1,
                0.0
                )
            );
            fb.insert("G", Slice(
                Imf::FLOAT, (char*)((char*)image->data + (sizeof(float) * 1)),
  开发者_运维知识库              sizeof(float) * 3,
                sizeof(float) * width * 3,
                1, 1,
                0.0
                )
            );

            fb.insert("B", Slice(
                Imf::FLOAT, (char*)((char*)image->data + (sizeof(float) * 2)),
                sizeof(float) * 3,
                sizeof(float) * width * 3,
                1, 1,
                0.0
                )
            );

            iFile.setFrameBuffer(fb);

            if (ReadImage(filename, iFile, dw.min.y, dw.max.y) == IEFileReadError) {
                HDR_LOG("There was a generic error on loading the EXR image \"%s\". Image could be corrupted.", filename);
                return (IEFileReadError);
            }

            image->unproc = 1;

            return (IENoError);
        } else {
            char sChannels[2048] = { '\0' };

            for (ChannelList::ConstIterator it = iHeader.channels().begin(), ite = iHeader.channels().end(); it != ite; it++) {
                strcat(sChannels, it.name());
                strcat(sChannels, " ");
            }

            HDR_LOG("Unable to open EXR file (unknown channels set: %s)", sChannels);
            return (IEFileReadError);
        }
    }

But I wonder how this library could decode/transform Y-RY-GY images (luminance + chroma channels) and get floating point RGB pixel data.


Take a look at the Technical Introduction. There is a section about Luminance/Chroma Images.

It seems that there are three Channels: Y (Luminance, used either alone, for gray-scale images, or in combination with RY and BY for color images.), RY, BY (Chroma for luminance/chroma).

Something like

 fb.insert("Y" /* <- channel name */, Slice(...)

should work out.

0

精彩评论

暂无评论...
验证码 换一张
取 消