Blame IlmImfUtil/ImfDeepImageLevel.h

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
#ifndef INCLUDED_IMF_DEEP_IMAGE_LEVEL_H
Packit 0d464f
#define INCLUDED_IMF_DEEP_IMAGE_LEVEL_H
Packit 0d464f
Packit 0d464f
//----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//      class DeepImageLevel
Packit 0d464f
//      class DeepImageLevel::Iterator
Packit 0d464f
//      class DeepImageLevel::ConstIterator
Packit 0d464f
//
Packit 0d464f
//      For an explanation of images, levels and channels,
Packit 0d464f
//      see the comments in header file Image.h.
Packit 0d464f
//
Packit 0d464f
//----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfDeepImageChannel.h"
Packit 0d464f
#include "ImfSampleCountChannel.h"
Packit 0d464f
#include "ImfImageLevel.h"
Packit 0d464f
#include "ImfExport.h"
Packit 0d464f
#include <string>
Packit 0d464f
#include <map>
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 0d464f
Packit 0d464f
class DeepImage;
Packit 0d464f
Packit 0d464f
class IMF_EXPORT DeepImageLevel : public ImageLevel
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Access to the image to which the level belongs.
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    DeepImage &                 deepImage ();
Packit 0d464f
    const DeepImage &           deepImage () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Access to deep channels by name:
Packit 0d464f
    //
Packit 0d464f
    // findChannel(n)           returns a pointer to the image channel with
Packit 0d464f
    //                          name n, or 0 if no such channel exists.
Packit 0d464f
    //
Packit 0d464f
    // channel(n)               returns a reference to the image channel with
Packit 0d464f
    //                          name n, or throws an Iex::ArgExc exception if
Packit 0d464f
    //                          no such channel exists.
Packit 0d464f
    //
Packit 0d464f
    // findTypedChannel<T>(n)   returns a pointer to the image channel with
Packit 0d464f
    //                          name n and type T, or 0 if no such channel
Packit 0d464f
    //                          exists.
Packit 0d464f
    //
Packit 0d464f
    // typedChannel(n)          returns a reference to the image channel with
Packit 0d464f
    //                          name n and type T, or throws an Iex::ArgExc
Packit 0d464f
    //                          exception if no such channel exists.
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
	
Packit 0d464f
    DeepImageChannel *          findChannel (const std::string& name);
Packit 0d464f
	const DeepImageChannel *    findChannel (const std::string& name) const;
Packit 0d464f
Packit 0d464f
    DeepImageChannel &          channel (const std::string& name);
Packit 0d464f
    const DeepImageChannel &    channel (const std::string& name) const;
Packit 0d464f
Packit 0d464f
    template <class T>
Packit 0d464f
    TypedDeepImageChannel<T> *       findTypedChannel
Packit 0d464f
                                        (const std::string& name);
Packit 0d464f
Packit 0d464f
    template <class T>
Packit 0d464f
    const TypedDeepImageChannel<T> * findTypedChannel
Packit 0d464f
                                        (const std::string& name) const;
Packit 0d464f
Packit 0d464f
    template <class T>
Packit 0d464f
    TypedDeepImageChannel<T> &       typedChannel
Packit 0d464f
                                        (const std::string& name);
Packit 0d464f
Packit 0d464f
    template <class T>
Packit 0d464f
    const TypedDeepImageChannel<T> & typedChannel
Packit 0d464f
                                        (const std::string& name) const;
Packit 0d464f
    
Packit 0d464f
    //
Packit 0d464f
    // Iterator-style access to deep channels
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    typedef std::map <std::string, DeepImageChannel *> ChannelMap;
Packit 0d464f
Packit 0d464f
	class Iterator;
Packit 0d464f
	class ConstIterator;
Packit 0d464f
Packit 0d464f
	Iterator        begin();
Packit 0d464f
	ConstIterator   begin() const;
Packit 0d464f
Packit 0d464f
	Iterator        end();
Packit 0d464f
	ConstIterator   end() const;
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Access to the sample count channel
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
	SampleCountChannel &            sampleCounts();
Packit 0d464f
	const SampleCountChannel &      sampleCounts() const;
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
    
Packit 0d464f
    friend class DeepImage;
Packit 0d464f
    friend class SampleCountChannel;
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // The constructor and destructor are private.
Packit 0d464f
    // Deep image levels exist only as part of a deep image.
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
     DeepImageLevel (DeepImage& image,
Packit 0d464f
                     int xLevelNumber,
Packit 0d464f
                     int yLevelNumber,
Packit 0d464f
                     const IMATH_NAMESPACE::Box2i& dataWindow);
Packit 0d464f
Packit 0d464f
    ~DeepImageLevel ();
Packit 0d464f
Packit 0d464f
    void         setSamplesToZero (size_t i,
Packit 0d464f
                                   unsigned int oldNumSamples,
Packit 0d464f
                                   unsigned int newNumSamples);
Packit 0d464f
Packit 0d464f
    void         moveSampleList (size_t i,
Packit 0d464f
                                 unsigned int oldNumSamples,
Packit 0d464f
                                 unsigned int newNumSamples,
Packit 0d464f
                                 size_t newSampleListPosition);
Packit 0d464f
Packit 0d464f
    void         moveSamplesToNewBuffer (const unsigned int * oldNumSamples,
Packit 0d464f
                                         const unsigned int * newNumSamples,
Packit 0d464f
                                         const size_t * newSampleListPositions);
Packit 0d464f
Packit 0d464f
    void         initializeSampleLists ();
Packit 0d464f
Packit 0d464f
    virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
Packit 0d464f
Packit 0d464f
    virtual void shiftPixels (int dx, int dy);
Packit 0d464f
Packit 0d464f
    virtual void insertChannel (const std::string& name,
Packit 0d464f
                                PixelType type,
Packit 0d464f
                                int xSampling,
Packit 0d464f
                                int ySampling,
Packit 0d464f
                                bool pLinear);
Packit 0d464f
Packit 0d464f
    virtual void eraseChannel (const std::string& name);
Packit 0d464f
Packit 0d464f
    virtual void clearChannels ();
Packit 0d464f
Packit 0d464f
    virtual void renameChannel (const std::string &oldName,
Packit 0d464f
                                const std::string &newName);
Packit 0d464f
Packit 0d464f
    virtual void renameChannels (const RenamingMap &oldToNewNames);
Packit 0d464f
Packit 0d464f
    ChannelMap          _channels;
Packit 0d464f
    SampleCountChannel  _sampleCounts;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
class DeepImageLevel::Iterator
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    Iterator ();
Packit 0d464f
    Iterator (const DeepImageLevel::ChannelMap::iterator& i);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Advance the iterator
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    Iterator &              operator ++ ();
Packit 0d464f
    Iterator                operator ++ (int);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Access to the channel to which the iterator points,
Packit 0d464f
    // and to the name of that channel.
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    const std::string &     name () const;
Packit 0d464f
    DeepImageChannel &      channel () const;
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    friend class DeepImageLevel::ConstIterator;
Packit 0d464f
Packit 0d464f
    DeepImageLevel::ChannelMap::iterator _i;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
class DeepImageLevel::ConstIterator
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    ConstIterator ();
Packit 0d464f
    ConstIterator (const DeepImageLevel::ChannelMap::const_iterator& i);
Packit 0d464f
    ConstIterator (const DeepImageLevel::Iterator& other);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Advance the iterator
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    ConstIterator &             operator ++ ();
Packit 0d464f
    ConstIterator               operator ++ (int);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //
Packit 0d464f
    // Access to the channel to which the iterator points,
Packit 0d464f
    // and to the name of that channel.
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    const std::string &         name () const;
Packit 0d464f
    const DeepImageChannel &    channel () const;
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    friend bool operator ==
Packit 0d464f
        (const ConstIterator &, const ConstIterator &);
Packit 0d464f
Packit 0d464f
    friend bool operator !=
Packit 0d464f
        (const ConstIterator &, const ConstIterator &);
Packit 0d464f
Packit 0d464f
    DeepImageLevel::ChannelMap::const_iterator _i;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
// Implementation of inline functions
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
TypedDeepImageChannel<T> *
Packit 0d464f
DeepImageLevel::findTypedChannel (const std::string& name)
Packit 0d464f
{
Packit 0d464f
    return dynamic_cast <TypedDeepImageChannel<T>*> (findChannel (name));
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
const TypedDeepImageChannel<T> *
Packit 0d464f
DeepImageLevel::findTypedChannel (const std::string& name) const
Packit 0d464f
{
Packit 0d464f
    return dynamic_cast <const TypedDeepImageChannel<T>*> (findChannel (name));
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
TypedDeepImageChannel<T> &
Packit 0d464f
DeepImageLevel::typedChannel (const std::string& name)
Packit 0d464f
{
Packit 0d464f
    TypedDeepImageChannel<T> * ptr = findTypedChannel<T> (name);
Packit 0d464f
Packit 0d464f
    if (ptr == 0)
Packit 0d464f
        throwBadChannelNameOrType (name);
Packit 0d464f
Packit 0d464f
    return *ptr;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
template <class T>
Packit 0d464f
const TypedDeepImageChannel<T> &
Packit 0d464f
DeepImageLevel::typedChannel (const std::string& name) const
Packit 0d464f
{
Packit 0d464f
    const TypedDeepImageChannel<T> * ptr = findTypedChannel<T> (name);
Packit 0d464f
Packit 0d464f
    if (ptr == 0)
Packit 0d464f
        throwBadChannelNameOrType (name);
Packit 0d464f
Packit 0d464f
    return *ptr;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline SampleCountChannel &
Packit 0d464f
DeepImageLevel::sampleCounts ()
Packit 0d464f
{
Packit 0d464f
    return _sampleCounts;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline const SampleCountChannel &
Packit 0d464f
DeepImageLevel::sampleCounts () const
Packit 0d464f
{
Packit 0d464f
    return _sampleCounts;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
DeepImageLevel::Iterator::Iterator (): _i()
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
DeepImageLevel::Iterator::Iterator
Packit 0d464f
    (const DeepImageLevel::ChannelMap::iterator& i)
Packit 0d464f
:
Packit 0d464f
    _i (i)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline DeepImageLevel::Iterator &                
Packit 0d464f
DeepImageLevel::Iterator::operator ++ ()
Packit 0d464f
{
Packit 0d464f
    ++_i;
Packit 0d464f
    return *this;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline DeepImageLevel::Iterator  
Packit 0d464f
DeepImageLevel::Iterator::operator ++ (int)
Packit 0d464f
{
Packit 0d464f
    Iterator tmp = *this;
Packit 0d464f
    ++_i;
Packit 0d464f
    return tmp;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline const std::string &
Packit 0d464f
DeepImageLevel::Iterator::name () const
Packit 0d464f
{
Packit 0d464f
    return _i->first;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline DeepImageChannel &        
Packit 0d464f
DeepImageLevel::Iterator::channel () const
Packit 0d464f
{
Packit 0d464f
    return *_i->second;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
DeepImageLevel::ConstIterator::ConstIterator (): _i()
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
DeepImageLevel::ConstIterator::ConstIterator
Packit 0d464f
    (const DeepImageLevel::ChannelMap::const_iterator& i): _i (i)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline
Packit 0d464f
DeepImageLevel::ConstIterator::ConstIterator
Packit 0d464f
    (const DeepImageLevel::Iterator& other): _i (other._i)
Packit 0d464f
{
Packit 0d464f
    // empty
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
inline DeepImageLevel::ConstIterator &
Packit 0d464f
DeepImageLevel::ConstIterator::operator ++ ()
Packit 0d464f
{
Packit 0d464f
    ++_i;
Packit 0d464f
    return *this;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline DeepImageLevel::ConstIterator             
Packit 0d464f
DeepImageLevel::ConstIterator::operator ++ (int)
Packit 0d464f
{
Packit 0d464f
    ConstIterator tmp = *this;
Packit 0d464f
    ++_i;
Packit 0d464f
    return tmp;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline const std::string &
Packit 0d464f
DeepImageLevel::ConstIterator::name () const
Packit 0d464f
{
Packit 0d464f
    return _i->first;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
inline const DeepImageChannel &  
Packit 0d464f
DeepImageLevel::ConstIterator::channel () const
Packit 0d464f
{
Packit 0d464f
    return *_i->second;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline bool
Packit 0d464f
operator == (const DeepImageLevel::ConstIterator& x,
Packit 0d464f
             const DeepImageLevel::ConstIterator& y)
Packit 0d464f
{
Packit 0d464f
    return x._i == y._i;
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
Packit 0d464f
inline bool
Packit 0d464f
operator != (const DeepImageLevel::ConstIterator& x,
Packit 0d464f
             const DeepImageLevel::ConstIterator& y)
Packit 0d464f
{
Packit 0d464f
    return !(x == y);
Packit 0d464f
}
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 0d464f
Packit 0d464f
#endif