0

我正在尝试打开一个 .exr 文件,但程序在 xtree#275 处崩溃

在此处输入图像描述

我认为问题发生在 exrinput.cpp#804

for (auto ci = channels.begin(); ci != channels.end();  ++c, ++ci)

有关更多上下文,这是功能

bool
OpenEXRInput::PartInfo::query_channels (OpenEXRInput *in,
                                        const Imf::Header *header)
{
    ASSERT (! initialized);
    bool ok = true;
    spec.nchannels = 0;
    const Imf::ChannelList &channels (header->channels());
    std::vector<std::string> channelnames;  // Order of channels in file
    std::vector<ChanNameHolder> cnh;
    int c = 0;
    for (auto ci = channels.begin(); ci != channels.end();  ++c, ++ci)
        cnh.emplace_back (ci.name(), c, ci.channel());
    spec.nchannels = int(cnh.size());
    std::sort (cnh.begin(), cnh.end(), ChanNameHolder::compare_cnh);
    // Now we should have cnh sorted into the order that we want to present
    // to the OIIO client.
    spec.format = TypeDesc::UNKNOWN;
    bool all_one_format = true;
    for (int c = 0; c < spec.nchannels; ++c) {
        spec.channelnames.push_back (cnh[c].fullname);
        spec.channelformats.push_back (cnh[c].datatype);
        spec.format = TypeDesc(ImageBufAlgo::type_merge (TypeDesc::BASETYPE(spec.format.basetype),
                                                         TypeDesc::BASETYPE(cnh[c].datatype.basetype)));
        pixeltype.push_back (cnh[c].exr_data_type);
        chanbytes.push_back (cnh[c].datatype.size());
        all_one_format &= (cnh[c].datatype == cnh[0].datatype);
        if (spec.alpha_channel < 0 && (Strutil::iequals (cnh[c].suffix, "A") ||
                                       Strutil::iequals (cnh[c].suffix, "Alpha")))
            spec.alpha_channel = c;
        if (spec.z_channel < 0 && (Strutil::iequals (cnh[c].suffix, "Z") ||
                                   Strutil::iequals (cnh[c].suffix, "Depth")))
            spec.z_channel = c;
        if (cnh[c].xSampling != 1 || cnh[c].ySampling != 1) {
            ok = false;
            in->error ("Subsampled channels are not supported (channel \"%s\" has sampling %d,%d).",
                       cnh[c].fullname, cnh[c].xSampling, cnh[c].ySampling);
            // FIXME: Some day, we should handle channel subsampling.
        }
    }
    ASSERT ((int)spec.channelnames.size() == spec.nchannels);
    ASSERT (spec.format != TypeDesc::UNKNOWN);
    if (all_one_format)
        spec.channelformats.clear();
    return ok;
}

这是打开 .exr 文件的代码

#include "pch.h"
#include <iostream>
#include <string>

#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/imagebufalgo.h>

using namespace OpenImageIO_v1_8;

int main()
{
    /* Simple image read */
    const auto *FileName = "C:/HM.exr";
    int xres, yres, channels;
    unsigned char *pixels;

    ImageInput *FileImage = ImageInput::create(FileName);
    if (!FileImage)
    {
        std::cout << printf("ERROR: %s", geterror().c_str());
        return 1;
    }

    ImageSpec ImageSpecification;

    FileImage->open(FileName, ImageSpecification);
    xres = ImageSpecification.width;
    yres = ImageSpecification.height;
    channels = ImageSpecification.nchannels;
    pixels = new unsigned char[xres*yres*channels];

    FileImage->read_image(TypeDesc::UINT32, pixels);
    FileImage->close();
    delete FileImage;
}
4

0 回答 0