Blame IlmImfUtil/ImfDeepImageChannel.h

Packit Service 6754ca
///////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
//
Packit Service 6754ca
// Copyright (c) 2014, Industrial Light & Magic, a division of Lucas
Packit Service 6754ca
// Digital Ltd. LLC
Packit Service 6754ca
// 
Packit Service 6754ca
// All rights reserved.
Packit Service 6754ca
// 
Packit Service 6754ca
// Redistribution and use in source and binary forms, with or without
Packit Service 6754ca
// modification, are permitted provided that the following conditions are
Packit Service 6754ca
// met:
Packit Service 6754ca
// *       Redistributions of source code must retain the above copyright
Packit Service 6754ca
// notice, this list of conditions and the following disclaimer.
Packit Service 6754ca
// *       Redistributions in binary form must reproduce the above
Packit Service 6754ca
// copyright notice, this list of conditions and the following disclaimer
Packit Service 6754ca
// in the documentation and/or other materials provided with the
Packit Service 6754ca
// distribution.
Packit Service 6754ca
// *       Neither the name of Industrial Light & Magic nor the names of
Packit Service 6754ca
// its contributors may be used to endorse or promote products derived
Packit Service 6754ca
// from this software without specific prior written permission. 
Packit Service 6754ca
// 
Packit Service 6754ca
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 6754ca
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 6754ca
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit Service 6754ca
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit Service 6754ca
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit Service 6754ca
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service 6754ca
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 6754ca
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 6754ca
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 6754ca
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 6754ca
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 6754ca
//
Packit Service 6754ca
///////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
Packit Service 6754ca
#ifndef INCLUDED_IMF_DEEP_IMAGE_CHANNEL_H
Packit Service 6754ca
#define INCLUDED_IMF_DEEP_IMAGE_CHANNEL_H
Packit Service 6754ca
Packit Service 6754ca
//----------------------------------------------------------------------------
Packit Service 6754ca
//
Packit Service 6754ca
//      class DeepImageChannel,
Packit Service 6754ca
//      template class TypedDeepImageChannel<T>
Packit Service 6754ca
//
Packit Service 6754ca
//      For an explanation of images, levels and channels,
Packit Service 6754ca
//      see the comments in header file Image.h.
Packit Service 6754ca
//
Packit Service 6754ca
//----------------------------------------------------------------------------
Packit Service 6754ca
Packit Service 6754ca
#include "ImfImageChannel.h"
Packit Service 6754ca
#include <ImfDeepFrameBuffer.h>
Packit Service 6754ca
#include "ImfExport.h"
Packit Service 6754ca
Packit Service 6754ca
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit Service 6754ca
Packit Service 6754ca
class DeepImageLevel;
Packit Service 6754ca
class SampleCountChannel;
Packit Service 6754ca
Packit Service 6754ca
//
Packit Service 6754ca
// Image channels:
Packit Service 6754ca
//
Packit Service 6754ca
// A TypedDeepImageChannel<T> holds the pixel data for a single channel
Packit Service 6754ca
// of one level of a deep image.  Each pixel in the channel contains an
Packit Service 6754ca
// array of n samples of type T, where T is either half, float or
Packit Service 6754ca
// unsigned int, and n is stored in a separate sample count channel.
Packit Service 6754ca
// Sample storage is allocated only for pixels within the data window
Packit Service 6754ca
// of the level.
Packit Service 6754ca
//
Packit Service 6754ca
Packit Service 6754ca
class DeepImageChannel: public ImageChannel
Packit Service 6754ca
{
Packit Service 6754ca
  public:
Packit Service 6754ca
Packit Service 6754ca
    //
Packit Service 6754ca
    // Construct an OpenEXR frame buffer slice for this channel.
Packit Service 6754ca
    // This function is needed reading an image from an OpenEXR
Packit Service 6754ca
    // file and for saving an image in an OpenEXR file.
Packit Service 6754ca
    // 
Packit Service 6754ca
Packit Service 6754ca
    virtual DeepSlice           slice () const = 0;
Packit Service 6754ca
Packit Service 6754ca
    //
Packit Service 6754ca
    // Access to the image level to which this channel belongs.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
	IMF_EXPORT DeepImageLevel &            deepLevel();
Packit Service 6754ca
	IMF_EXPORT const DeepImageLevel &      deepLevel() const;
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
    //
Packit Service 6754ca
    // Access to the sample count channel for this deep channel.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
	IMF_EXPORT SampleCountChannel &        sampleCounts();
Packit Service 6754ca
	IMF_EXPORT const SampleCountChannel &  sampleCounts() const;
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
  protected:
Packit Service 6754ca
Packit Service 6754ca
    friend class DeepImageLevel;
Packit Service 6754ca
Packit Service 6754ca
    DeepImageChannel (DeepImageLevel &level, bool pLinear);
Packit Service 6754ca
    virtual ~DeepImageChannel();
Packit Service 6754ca
Packit Service 6754ca
    virtual void setSamplesToZero
Packit Service 6754ca
                        (size_t i,
Packit Service 6754ca
                         unsigned int oldNumSamples,
Packit Service 6754ca
                         unsigned int newNumSamples) = 0;
Packit Service 6754ca
Packit Service 6754ca
    virtual void moveSampleList
Packit Service 6754ca
                        (size_t i,
Packit Service 6754ca
                         unsigned int oldNumSamples,
Packit Service 6754ca
                         unsigned int newNumSamples,
Packit Service 6754ca
                         size_t newSampleListPosition) = 0;
Packit Service 6754ca
Packit Service 6754ca
    virtual void moveSamplesToNewBuffer
Packit Service 6754ca
                        (const unsigned int * oldNumSamples,
Packit Service 6754ca
                         const unsigned int * newNumSamples,
Packit Service 6754ca
                         const size_t * newSampleListPositions) = 0;
Packit Service 6754ca
Packit Service 6754ca
    virtual void initializeSampleLists () = 0;
Packit Service 6754ca
Packit Service 6754ca
    virtual void resize ();
Packit Service 6754ca
Packit Service 6754ca
    virtual void resetBasePointer () = 0;
Packit Service 6754ca
};
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
class TypedDeepImageChannel: public DeepImageChannel
Packit Service 6754ca
{
Packit Service 6754ca
  public:
Packit Service 6754ca
    
Packit Service 6754ca
    //
Packit Service 6754ca
    // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    virtual PixelType   pixelType () const;
Packit Service 6754ca
Packit Service 6754ca
    
Packit Service 6754ca
    //
Packit Service 6754ca
    // Construct an OpenEXR frame buffer slice for this channel.
Packit Service 6754ca
    // This function is needed reading an image from an OpenEXR
Packit Service 6754ca
    // file and for saving an image in an OpenEXR file.
Packit Service 6754ca
    // 
Packit Service 6754ca
Packit Service 6754ca
    virtual DeepSlice   slice () const;
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
    //
Packit Service 6754ca
    // Access to the pixel at pixel space location (x, y), without bounds
Packit Service 6754ca
    // checking.  Accessing a location outside the data window of the image
Packit Service 6754ca
    // level results in undefined behavior.
Packit Service 6754ca
    //
Packit Service 6754ca
    // The pixel contains a pointer to an array of samples to type T.  The
Packit Service 6754ca
    // number of samples in this array is sampleCounts().at(x,y).
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    T *                 operator () (int x, int y);
Packit Service 6754ca
    const T *           operator () (int x, int y) const;
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
    //
Packit Service 6754ca
    // Access to the pixel at pixel space location (x, y), with bounds
Packit Service 6754ca
    // checking.  Accessing a location outside the data window of the
Packit Service 6754ca
    // image level throws an Iex::ArgExc exception.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    T *                 at (int x, int y);
Packit Service 6754ca
    const T *           at (int x, int y) const;
Packit Service 6754ca
Packit Service 6754ca
    //
Packit Service 6754ca
    // Faster access to all pixels in a single horizontal row of the
Packit Service 6754ca
    // channel.  Access is not bounds checked; accessing out of bounds
Packit Service 6754ca
    // rows or pixels results in undefined behavior.
Packit Service 6754ca
    //
Packit Service 6754ca
    // Rows are numbered from 0 to pixelsPerColumn()-1, and each row
Packit Service 6754ca
    // contains pixelsPerRow() values.  The number of samples in
Packit Service 6754ca
    // row(r)[i] is sampleCounts().row(r)[i].
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    T * const *         row (int r);
Packit Service 6754ca
    const T * const *   row (int r) const;
Packit Service 6754ca
Packit Service 6754ca
  private:
Packit Service 6754ca
    
Packit Service 6754ca
    friend class DeepImageLevel;
Packit Service 6754ca
Packit Service 6754ca
    TypedDeepImageChannel (DeepImageLevel &level, bool pLinear);
Packit Service 6754ca
    virtual ~TypedDeepImageChannel ();
Packit Service 6754ca
Packit Service 6754ca
    virtual void setSamplesToZero
Packit Service 6754ca
                            (size_t i,
Packit Service 6754ca
                             unsigned int oldNumSamples,
Packit Service 6754ca
                             unsigned int newNumSamples);
Packit Service 6754ca
Packit Service 6754ca
    virtual void moveSampleList
Packit Service 6754ca
                            (size_t i,
Packit Service 6754ca
                             unsigned int oldNumSamples,
Packit Service 6754ca
                             unsigned int newNumSamples,
Packit Service 6754ca
                             size_t newSampleListPosition);
Packit Service 6754ca
Packit Service 6754ca
    virtual void moveSamplesToNewBuffer
Packit Service 6754ca
                            (const unsigned int * oldNumSamples,
Packit Service 6754ca
                             const unsigned int * newNumSamples,
Packit Service 6754ca
                             const size_t * newSampleListPositions);
Packit Service 6754ca
Packit Service 6754ca
    virtual void initializeSampleLists ();
Packit Service 6754ca
Packit Service 6754ca
    virtual void resize ();
Packit Service 6754ca
Packit Service 6754ca
    virtual void resetBasePointer ();
Packit Service 6754ca
Packit Service 6754ca
    T **    _sampleListPointers;    // Array of pointers to per-pixel
Packit Service 6754ca
                                    //sample lists
Packit Service 6754ca
Packit Service 6754ca
    T **    _base;                  // Base pointer for faster access
Packit Service 6754ca
                                    // to entries in _sampleListPointers
Packit Service 6754ca
Packit Service 6754ca
    T *     _sampleBuffer;          // Contiguous memory block that
Packit Service 6754ca
                                    // contains all sample lists for
Packit Service 6754ca
                                    // this channel
Packit Service 6754ca
};
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
//
Packit Service 6754ca
// Channel typedefs for the pixel data types supported by OpenEXR.
Packit Service 6754ca
//
Packit Service 6754ca
Packit Service 6754ca
typedef TypedDeepImageChannel<half>         DeepHalfChannel;
Packit Service 6754ca
typedef TypedDeepImageChannel<float>        DeepFloatChannel;
Packit Service 6754ca
typedef TypedDeepImageChannel<unsigned int> DeepUIntChannel;
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
//-----------------------------------------------------------------------------
Packit Service 6754ca
// Implementation of templates and inline functions
Packit Service 6754ca
//-----------------------------------------------------------------------------
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
TypedDeepImageChannel<T>::TypedDeepImageChannel
Packit Service 6754ca
    (DeepImageLevel &level,
Packit Service 6754ca
     bool pLinear)
Packit Service 6754ca
:
Packit Service 6754ca
    DeepImageChannel (level, pLinear),
Packit Service 6754ca
    _sampleListPointers (0),
Packit Service 6754ca
    _base (0),
Packit Service 6754ca
    _sampleBuffer (0)
Packit Service 6754ca
{
Packit Service 6754ca
    resize();
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
TypedDeepImageChannel<T>::~TypedDeepImageChannel ()
Packit Service 6754ca
{
Packit Service 6754ca
    delete [] _sampleListPointers;
Packit Service 6754ca
    delete [] _sampleBuffer;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <>
Packit Service 6754ca
inline PixelType
Packit Service 6754ca
DeepHalfChannel::pixelType () const
Packit Service 6754ca
{
Packit Service 6754ca
    return HALF;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <>
Packit Service 6754ca
inline PixelType
Packit Service 6754ca
DeepFloatChannel::pixelType () const
Packit Service 6754ca
{
Packit Service 6754ca
    return FLOAT;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <>
Packit Service 6754ca
inline PixelType
Packit Service 6754ca
DeepUIntChannel::pixelType () const
Packit Service 6754ca
{
Packit Service 6754ca
    return UINT;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
DeepSlice
Packit Service 6754ca
TypedDeepImageChannel<T>::slice () const
Packit Service 6754ca
{
Packit Service 6754ca
    return DeepSlice (pixelType(),                  // type
Packit Service 6754ca
                      (char *) _base,               // base
Packit Service 6754ca
                      sizeof (T*),                  // xStride
Packit Service 6754ca
                      pixelsPerRow() * sizeof (T*), // yStride
Packit Service 6754ca
                      sizeof (T),                   // sampleStride
Packit Service 6754ca
                      xSampling(),
Packit Service 6754ca
                      ySampling());
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
inline T *
Packit Service 6754ca
TypedDeepImageChannel<T>::operator () (int x, int y)
Packit Service 6754ca
{
Packit Service 6754ca
    return _base[y * pixelsPerRow() + x];
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
inline const T *
Packit Service 6754ca
TypedDeepImageChannel<T>::operator () (int x, int y) const
Packit Service 6754ca
{
Packit Service 6754ca
    return _base[y * pixelsPerRow() + x];
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
inline T *
Packit Service 6754ca
TypedDeepImageChannel<T>::at (int x, int y)
Packit Service 6754ca
{
Packit Service 6754ca
    boundsCheck (x, y);
Packit Service 6754ca
    return _base[y * pixelsPerRow() + x];
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
inline const T *
Packit Service 6754ca
TypedDeepImageChannel<T>::at (int x, int y) const
Packit Service 6754ca
{
Packit Service 6754ca
    boundsCheck (x, y);
Packit Service 6754ca
    return _base[y * pixelsPerRow() + x];
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
inline T * const *
Packit Service 6754ca
TypedDeepImageChannel<T>::row (int r)
Packit Service 6754ca
{
Packit Service 6754ca
    return _base + r * pixelsPerRow();
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
inline const T * const *
Packit Service 6754ca
TypedDeepImageChannel<T>::row (int r) const
Packit Service 6754ca
{
Packit Service 6754ca
    return _base + r * pixelsPerRow();
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
void
Packit Service 6754ca
TypedDeepImageChannel<T>::setSamplesToZero
Packit Service 6754ca
    (size_t i,
Packit Service 6754ca
     unsigned int oldNumSamples,
Packit Service 6754ca
     unsigned int newNumSamples)
Packit Service 6754ca
{
Packit Service 6754ca
    //
Packit Service 6754ca
    // Expand the size of a sample list for a single pixel and
Packit Service 6754ca
    // set the new samples in the list to 0.
Packit Service 6754ca
    //
Packit Service 6754ca
    // i                The position of the affected pixel in
Packit Service 6754ca
    //                  the channel's _sampleListPointers.
Packit Service 6754ca
    //
Packit Service 6754ca
    // oldNumSamples    Original number of samples in the sample list.
Packit Service 6754ca
    //
Packit Service 6754ca
    // newNumSamples    New number of samples in the sample list.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    for (int j = oldNumSamples; j < newNumSamples; ++j)
Packit Service 6754ca
        _sampleListPointers[i][j] = 0;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
void
Packit Service 6754ca
TypedDeepImageChannel<T>::moveSampleList
Packit Service 6754ca
    (size_t i,
Packit Service 6754ca
     unsigned int oldNumSamples,
Packit Service 6754ca
     unsigned int newNumSamples,
Packit Service 6754ca
     size_t newSampleListPosition)
Packit Service 6754ca
{
Packit Service 6754ca
    //
Packit Service 6754ca
    // Resize the sample list for a single pixel and move it to a new
Packit Service 6754ca
    // position in the sample buffer for this channel.
Packit Service 6754ca
    // 
Packit Service 6754ca
    // i                        The position of the affected pixel in
Packit Service 6754ca
    //                          the channel's _sampleListPointers.
Packit Service 6754ca
    //
Packit Service 6754ca
    // oldNumSamples            Original number of samples in sample list.
Packit Service 6754ca
    //
Packit Service 6754ca
    // newNumSamples            New number of samples in the sample list.
Packit Service 6754ca
    //                          If the new number of samples is larger than
Packit Service 6754ca
    //                          the old number of samples for a given sample
Packit Service 6754ca
    //                          list, then the end of the new sample list
Packit Service 6754ca
    //                          is filled with zeroes.  If the new number of
Packit Service 6754ca
    //                          samples is smaller than the old one, then
Packit Service 6754ca
    //                          samples at the end of the old sample list
Packit Service 6754ca
    //                          are discarded.
Packit Service 6754ca
    //
Packit Service 6754ca
    // newSampleListPosition    The new position of the sample list in the
Packit Service 6754ca
    //                          sample buffer.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    T * oldSampleList = _sampleListPointers[i];
Packit Service 6754ca
    T * newSampleList = _sampleBuffer + newSampleListPosition;
Packit Service 6754ca
Packit Service 6754ca
    if (oldNumSamples > newNumSamples)
Packit Service 6754ca
    {
Packit Service 6754ca
        for (int j = 0; j < newNumSamples; ++j)
Packit Service 6754ca
            newSampleList[j] = oldSampleList[j];
Packit Service 6754ca
    }
Packit Service 6754ca
    else
Packit Service 6754ca
    {
Packit Service 6754ca
        for (int j = 0; j < oldNumSamples; ++j)
Packit Service 6754ca
            newSampleList[j] = oldSampleList[j];
Packit Service 6754ca
Packit Service 6754ca
        for (int j = oldNumSamples; j < newNumSamples; ++j)
Packit Service 6754ca
            newSampleList[j] = 0;
Packit Service 6754ca
    }
Packit Service 6754ca
Packit Service 6754ca
    _sampleListPointers[i] = newSampleList;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
void
Packit Service 6754ca
TypedDeepImageChannel<T>::moveSamplesToNewBuffer
Packit Service 6754ca
    (const unsigned int * oldNumSamples,
Packit Service 6754ca
     const unsigned int * newNumSamples,
Packit Service 6754ca
     const size_t * newSampleListPositions)
Packit Service 6754ca
{
Packit Service 6754ca
    //
Packit Service 6754ca
    // Allocate a new sample buffer for this channel.
Packit Service 6754ca
    // Copy the sample lists for all pixels into the new buffer.
Packit Service 6754ca
    // Then delete the old sample buffer.
Packit Service 6754ca
    //
Packit Service 6754ca
    // oldNumSamples            Number of samples in each sample list in the
Packit Service 6754ca
    //                          old sample buffer.
Packit Service 6754ca
    //
Packit Service 6754ca
    // newNumSamples            Number of samples in each sample list in
Packit Service 6754ca
    //                          the new sample buffer.  If the new number
Packit Service 6754ca
    //                          of samples is larger than the old number of
Packit Service 6754ca
    //                          samples for a given sample list, then the
Packit Service 6754ca
    //                          end of the new sample list is filled with
Packit Service 6754ca
    //                          zeroes.  If the new number of samples is
Packit Service 6754ca
    //                          smaller than the old one, then samples at
Packit Service 6754ca
    //                          the end of the old sample list are discarded.
Packit Service 6754ca
    //
Packit Service 6754ca
    // newSampleListPositions   The positions of the new sample lists in the
Packit Service 6754ca
    //                          new sample buffer.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    T * oldSampleBuffer = _sampleBuffer;
Packit Service 6754ca
    _sampleBuffer = new T [sampleCounts().sampleBufferSize()];
Packit Service 6754ca
Packit Service 6754ca
    for (size_t i = 0; i < numPixels(); ++i)
Packit Service 6754ca
    {
Packit Service 6754ca
        T * oldSampleList = _sampleListPointers[i];
Packit Service 6754ca
        T * newSampleList = _sampleBuffer + newSampleListPositions[i];
Packit Service 6754ca
Packit Service 6754ca
        if (oldNumSamples[i] > newNumSamples[i])
Packit Service 6754ca
        {
Packit Service 6754ca
            for (int j = 0; j < newNumSamples[i]; ++j)
Packit Service 6754ca
                newSampleList[j] = oldSampleList[j];
Packit Service 6754ca
        }
Packit Service 6754ca
        else
Packit Service 6754ca
        {
Packit Service 6754ca
            for (int j = 0; j < oldNumSamples[i]; ++j)
Packit Service 6754ca
                newSampleList[j] = oldSampleList[j];
Packit Service 6754ca
Packit Service 6754ca
            for (int j = oldNumSamples[i]; j < newNumSamples[i]; ++j)
Packit Service 6754ca
                newSampleList[j] = 0;
Packit Service 6754ca
        }
Packit Service 6754ca
Packit Service 6754ca
        _sampleListPointers[i] = newSampleList;
Packit Service 6754ca
    }
Packit Service 6754ca
Packit Service 6754ca
    delete [] oldSampleBuffer;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
void
Packit Service 6754ca
TypedDeepImageChannel<T>::initializeSampleLists ()
Packit Service 6754ca
{
Packit Service 6754ca
    //
Packit Service 6754ca
    // Allocate a new set of sample lists for this channel, and
Packit Service 6754ca
    // construct zero-filled sample lists for the pixels.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    delete [] _sampleBuffer;
Packit Service 6754ca
Packit Service 6754ca
    _sampleBuffer = 0;          // set to 0 to prevent double deletion
Packit Service 6754ca
                                // in case of an exception
Packit Service 6754ca
Packit Service 6754ca
    const unsigned int * numSamples = sampleCounts().numSamples();
Packit Service 6754ca
    const size_t * sampleListPositions = sampleCounts().sampleListPositions();
Packit Service 6754ca
Packit Service 6754ca
    _sampleBuffer = new T [sampleCounts().sampleBufferSize()];
Packit Service 6754ca
    
Packit Service 6754ca
    resetBasePointer();
Packit Service 6754ca
Packit Service 6754ca
    for (size_t i = 0; i < numPixels(); ++i)
Packit Service 6754ca
    {
Packit Service 6754ca
        _sampleListPointers[i] = _sampleBuffer + sampleListPositions[i];
Packit Service 6754ca
Packit Service 6754ca
        for (unsigned int j = 0; j < numSamples[i]; ++j)
Packit Service 6754ca
            _sampleListPointers[i][j] = T (0);
Packit Service 6754ca
    }
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
void
Packit Service 6754ca
TypedDeepImageChannel<T>::resize ()
Packit Service 6754ca
{
Packit Service 6754ca
    DeepImageChannel::resize();
Packit Service 6754ca
Packit Service 6754ca
    delete [] _sampleListPointers;
Packit Service 6754ca
    _sampleListPointers = 0;
Packit Service 6754ca
    _sampleListPointers = new T * [numPixels()];
Packit Service 6754ca
    initializeSampleLists();
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
template <class T>
Packit Service 6754ca
void
Packit Service 6754ca
TypedDeepImageChannel<T>::resetBasePointer ()
Packit Service 6754ca
{
Packit Service 6754ca
    _base = _sampleListPointers -
Packit Service 6754ca
            level().dataWindow().min.y * pixelsPerRow() -
Packit Service 6754ca
            level().dataWindow().min.x;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit Service 6754ca
Packit Service 6754ca
#endif