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