Ejemplo n.º 1
0
bool
OpenEXRInput::read_native_deep_scanlines (int ybegin, int yend, int z,
                                          int firstchan, int nchans,
                                          DeepData &deepdata)
{
    if (m_deep_scanline_input_part == NULL) {
        error ("called OpenEXRInput::read_native_deep_scanlines without an open file");
        return false;
    }

#ifdef USE_OPENEXR_VERSION2
    try {
        const PartInfo &part (m_parts[m_subimage]);
        size_t npixels = (yend - ybegin) * m_spec.width;

        // Set up the count and pointers arrays and the Imf framebuffer
        std::vector<TypeDesc> channeltypes;
        m_spec.get_channelformats (channeltypes);
        deepdata.init (npixels, nchans, &channeltypes[firstchan],
                       &channeltypes[firstchan+nchans]);
        Imf::DeepFrameBuffer frameBuffer;
        Imf::Slice countslice (Imf::UINT,
                               (char *)(&deepdata.nsamples[0]
                                        - m_spec.x
                                        - ybegin*m_spec.width),
                               sizeof(unsigned int),
                               sizeof(unsigned int) * m_spec.width);
        frameBuffer.insertSampleCountSlice (countslice);
        for (int c = 0;  c < nchans;  ++c) {
            Imf::DeepSlice slice (part.pixeltype[c+firstchan],
                                  (char *)(&deepdata.pointers[c]
                                           - m_spec.x * nchans
                                           - ybegin*m_spec.width*nchans),
                                  sizeof(void*) * nchans, // xstride of pointer array
                                  sizeof(void*) * nchans*m_spec.width, // ystride of pointer array
                                  part.chanbytes[c+firstchan]); // stride of data sample
            frameBuffer.insert (m_spec.channelnames[c+firstchan].c_str(), slice);
        }
        m_deep_scanline_input_part->setFrameBuffer (frameBuffer);

        // Get the sample counts for each pixel and compute the total
        // number of samples and resize the data area appropriately.
        m_deep_scanline_input_part->readPixelSampleCounts (ybegin, yend-1);
        deepdata.alloc ();

        // Read the pixels
        m_deep_scanline_input_part->readPixels (ybegin, yend-1);
    }
    catch (const std::exception &e) {
        error ("Failed OpenEXR read: %s", e.what());
        return false;
    }

    return true;

#else
    return false;
#endif
}
Ejemplo n.º 2
0
bool
OpenEXRInput::read_native_deep_tiles (int xbegin, int xend,
                                      int ybegin, int yend,
                                      int zbegin, int zend,
                                      int chbegin, int chend,
                                      DeepData &deepdata)
{
    if (m_deep_tiled_input_part == NULL) {
        error ("called OpenEXRInput::read_native_deep_tiles without an open file");
        return false;
    }

#ifdef USE_OPENEXR_VERSION2
    try {
        const PartInfo &part (m_parts[m_subimage]);
        size_t width = (xend - xbegin);
        size_t npixels = width * (yend - ybegin) * (zend - zbegin);
        chend = clamp (chend, chbegin+1, m_spec.nchannels);
        int nchans = chend - chbegin;

        // Set up the count and pointers arrays and the Imf framebuffer
        std::vector<TypeDesc> channeltypes;
        m_spec.get_channelformats (channeltypes);
        deepdata.init (npixels, nchans, &channeltypes[chbegin],
                       &channeltypes[chend]);
        Imf::DeepFrameBuffer frameBuffer;
        Imf::Slice countslice (Imf::UINT,
                               (char *)(&deepdata.nsamples[0]
                                        - xbegin
                                        - ybegin*width),
                               sizeof(unsigned int),
                               sizeof(unsigned int) * width);
        frameBuffer.insertSampleCountSlice (countslice);
        for (int c = chbegin;  c < chend;  ++c) {
            Imf::DeepSlice slice (part.pixeltype[c],
                                  (char *)(&deepdata.pointers[c-chbegin]
                                           - xbegin*nchans
                                           - ybegin*width*nchans),
                                  sizeof(void*) * nchans, // xstride of pointer array
                                  sizeof(void*) * nchans*width, // ystride of pointer array
                                  part.chanbytes[c]); // stride of data sample
            frameBuffer.insert (m_spec.channelnames[c].c_str(), slice);
        }
        m_deep_tiled_input_part->setFrameBuffer (frameBuffer);

        int xtiles = round_to_multiple (xend-xbegin, m_spec.tile_width) / m_spec.tile_width;
        int ytiles = round_to_multiple (yend-ybegin, m_spec.tile_height) / m_spec.tile_height;

        // Get the sample counts for each pixel and compute the total
        // number of samples and resize the data area appropriately.
        m_deep_tiled_input_part->readPixelSampleCounts (0, xtiles-1, 0, ytiles-1);
        deepdata.alloc ();

        // Read the pixels
        m_deep_tiled_input_part->readTiles (0, xtiles-1, 0, ytiles-1,
                                            m_miplevel, m_miplevel);
    }
    catch (const std::exception &e) {
        error ("Failed OpenEXR read: %s", e.what());
        return false;
    }

    return true;

#else
    return false;
#endif
}