首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenEXR镜像加载

OpenEXR镜像加载
EN

Stack Overflow用户
提问于 2010-03-13 04:26:53
回答 1查看 2.8K关注 0票数 5

我已经开始使用OpenEXR加载EXR图像。我必须使用浮点类型来获取RGB像素。

对于RGB图像,使用以下代码加载时没有问题:

代码语言:javascript
复制
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);
        }
    }

但我想知道这个库如何解码/转换Y-RY-GY图像(亮度+色度通道)并获得浮点RGB像素数据。

EN

回答 1

Stack Overflow用户

发布于 2016-02-28 20:06:28

看一看Technical Introduction。有一个关于亮度/色度图像的部分。

似乎有三个通道:Y(亮度,单独使用,对于灰度图像,或者与RY和BY组合使用,用于彩色图像),RY,BY (亮度/色度的色度)。

就像这样

代码语言:javascript
复制
 fb.insert("Y" /* <- channel name */, Slice(...)

应该能行得通。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2435642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档