Blame IlmImfUtil/ImfImageChannel.cpp

Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
//
Packit 0d464f
// Copyright (c) 2014, Industrial Light & Magic, a division of Lucas
Packit 0d464f
// Digital Ltd. LLC
Packit 0d464f
// 
Packit 0d464f
// All rights reserved.
Packit 0d464f
// 
Packit 0d464f
// Redistribution and use in source and binary forms, with or without
Packit 0d464f
// modification, are permitted provided that the following conditions are
Packit 0d464f
// met:
Packit 0d464f
// *       Redistributions of source code must retain the above copyright
Packit 0d464f
// notice, this list of conditions and the following disclaimer.
Packit 0d464f
// *       Redistributions in binary form must reproduce the above
Packit 0d464f
// copyright notice, this list of conditions and the following disclaimer
Packit 0d464f
// in the documentation and/or other materials provided with the
Packit 0d464f
// distribution.
Packit 0d464f
// *       Neither the name of Industrial Light & Magic nor the names of
Packit 0d464f
// its contributors may be used to endorse or promote products derived
Packit 0d464f
// from this software without specific prior written permission. 
Packit 0d464f
// 
Packit 0d464f
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 0d464f
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 0d464f
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 0d464f
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 0d464f
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 0d464f
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 0d464f
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 0d464f
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 0d464f
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 0d464f
//
Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
Packit 0d464f
//----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//      class ImageChannel
Packit 0d464f
//
Packit 0d464f
//----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfImageChannel.h"
Packit 0d464f
#include "ImfImageLevel.h"
Packit 0d464f
#include <Iex.h>
Packit 0d464f
Packit 0d464f
using namespace IMATH_NAMESPACE;
Packit 0d464f
using namespace IEX_NAMESPACE;
Packit 0d464f
using namespace std;
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
Packit 0d464f
Packit 0d464f
Packit 0d464f
ImageChannel::ImageChannel
Packit 0d464f
    (ImageLevel &level,
Packit 0d464f
     int xSampling,
Packit 0d464f
     int ySampling,
Packit 0d464f
     bool pLinear)
Packit 0d464f
:
Packit 0d464f
    _level (level),
Packit 0d464f
    _xSampling (xSampling),
Packit 0d464f
    _ySampling (ySampling),
Packit 0d464f
    _pLinear (pLinear),
Packit 0d464f
    _pixelsPerRow (0),
Packit 0d464f
    _pixelsPerColumn (0),
Packit 0d464f
    _numPixels (0)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
ImageChannel::~ImageChannel ()
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
Channel
Packit 0d464f
ImageChannel::channel () const
Packit 0d464f
{
Packit 0d464f
    return Channel (pixelType(), xSampling(), ySampling(), pLinear());
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
void
Packit 0d464f
ImageChannel::resize ()
Packit 0d464f
{
Packit 0d464f
    const Box2i& dataWindow = level().dataWindow();
Packit 0d464f
Packit 0d464f
    if (dataWindow.min.x % _xSampling || dataWindow.min.y % _ySampling)
Packit 0d464f
    {
Packit 0d464f
        throw ArgExc ("The minimum x and y coordinates of the data window "
Packit 0d464f
                      "of an image level must be multiples of the x and y "
Packit 0d464f
                      "subsampling factors of all channels in the image.");
Packit 0d464f
    }
Packit 0d464f
Packit 0d464f
    int width =  dataWindow.max.x - dataWindow.min.x + 1;
Packit 0d464f
    int height = dataWindow.max.y - dataWindow.min.y + 1;
Packit 0d464f
Packit 0d464f
    if (width % _xSampling || height % _ySampling)
Packit 0d464f
    {
Packit 0d464f
        throw ArgExc ("The width and height of the data window of an image "
Packit 0d464f
                      "level must be multiples of the x and y subsampling "
Packit 0d464f
                      "factors of all channels in the image.");
Packit 0d464f
    }
Packit 0d464f
Packit 0d464f
    _pixelsPerRow =    width  / _xSampling;
Packit 0d464f
    _pixelsPerColumn = height / _ySampling;
Packit 0d464f
    _numPixels = _pixelsPerRow * _pixelsPerColumn;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
void
Packit 0d464f
ImageChannel::boundsCheck (int x, int y) const
Packit 0d464f
{
Packit 0d464f
    const Box2i &dataWindow = level().dataWindow();
Packit 0d464f
Packit 0d464f
    if (x < dataWindow.min.x || x > dataWindow.max.x ||
Packit 0d464f
        y < dataWindow.min.y || y > dataWindow.max.y)
Packit 0d464f
    {
Packit 0d464f
        THROW (ArgExc,
Packit 0d464f
               "Attempt to access a pixel at location "
Packit 0d464f
               "(" << x << ", " << y << ") in an image whose data window is "
Packit 0d464f
               "(" << dataWindow.min.x << ", " << dataWindow.min.y << ") - "
Packit 0d464f
               "(" << dataWindow.max.x << ", " << dataWindow.max.y << ").");
Packit 0d464f
    }
Packit 0d464f
Packit 0d464f
    if (x % _xSampling || y % _ySampling)
Packit 0d464f
    {
Packit 0d464f
        THROW (ArgExc,
Packit 0d464f
               "Attempt to access a pixel at location "
Packit 0d464f
               "(" << x << ", " << y << ") in a channel whose x and y sampling "
Packit 0d464f
               "rates are " << _xSampling << " and " << _ySampling << ".  The "
Packit 0d464f
               "pixel coordinates are not divisible by the sampling rates.");
Packit 0d464f
    }
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT