| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- //
- // SPDX-License-Identifier: BSD-3-Clause
- // Copyright (c) Contributors to the OpenEXR Project.
- //
- #ifndef INCLUDED_IMF_FLAT_IMAGE_CHANNEL_H
- #define INCLUDED_IMF_FLAT_IMAGE_CHANNEL_H
- //----------------------------------------------------------------------------
- //
- // class FlatImageChannel,
- // template class TypedFlatImageChannel<T>
- //
- // For an explanation of images, levels and channels,
- // see the comments in header file Image.h.
- //
- //----------------------------------------------------------------------------
- #include "ImfImageChannel.h"
- #include "ImfUtilExport.h"
- #include "ImfImageLevel.h"
- #include "ImfPixelType.h"
- #include "ImfFrameBuffer.h"
- #include <ImathBox.h>
- #include <half.h>
- OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
- class FlatImageLevel;
- //
- // Image channels:
- //
- // A TypedFlatImageChannel<T> holds the pixel data for a single channel
- // of one level of a flat image. The pixels in the channel are of type T,
- // where T is either half, float or unsigned int. Storage is allocated
- // only for pixels within the data window of the level.
- //
- class IMFUTIL_EXPORT_TYPE FlatImageChannel: public ImageChannel
- {
- public:
- //
- // Construct an OpenEXR frame buffer slice for this channel.
- // This function is needed reading an image from an OpenEXR
- // file and for saving an image in an OpenEXR file.
- //
- virtual Slice slice () const = 0;
- //
- // Access to the flat image level to which this channel belongs.
- //
- IMFUTIL_EXPORT FlatImageLevel & flatLevel ();
- IMFUTIL_EXPORT const FlatImageLevel & flatLevel () const;
- protected:
- friend class FlatImageLevel;
- IMFUTIL_EXPORT
- FlatImageChannel (FlatImageLevel &level,
- int xSampling,
- int ySampling,
- bool pLinear);
- IMFUTIL_EXPORT virtual ~FlatImageChannel();
- FlatImageChannel (const FlatImageChannel& other) = delete;
- FlatImageChannel& operator = (const FlatImageChannel& other) = delete;
- FlatImageChannel (FlatImageChannel&& other) = delete;
- FlatImageChannel& operator = (FlatImageChannel&& other) = delete;
- IMFUTIL_EXPORT
- virtual void resize ();
- virtual void resetBasePointer () = 0;
- };
- template <class T>
- class IMFUTIL_EXPORT_TEMPLATE_TYPE TypedFlatImageChannel: public FlatImageChannel
- {
- public:
-
- //
- // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
- //
- virtual PixelType pixelType () const;
-
- //
- // Construct an OpenEXR frame buffer slice for this channel.
- //
- virtual Slice slice () const;
- //
- // Access to the pixel at pixel space location (x, y), without
- // bounds checking. Accessing a location outside the data window
- // of the image level results in undefined behavior.
- //
- T & operator () (int x, int y);
- const T & operator () (int x, int y) const;
- //
- // Access to the pixel at pixel space location (x, y), with bounds
- // checking. Accessing a location outside the data window of the
- // image level throws an Iex::ArgExc exception.
- //
- T & at (int x, int y);
- const T & at (int x, int y) const;
- //
- // Faster access to all pixels in a single horizontal row of the
- // channel. Rows are numbered from 0 to pixelsPerColumn()-1, and
- // each row contains pixelsPerRow() values.
- // Access is not bounds checked; accessing out of bounds rows or
- // pixels results in undefined behavior.
- //
- T * row (int r);
- const T * row (int r) const;
- private:
-
- friend class FlatImageLevel;
- //
- // The constructor and destructor are not public because flat
- // image channels exist only as parts of a flat image level.
- //
- IMFUTIL_HIDDEN
- TypedFlatImageChannel (FlatImageLevel &level,
- int xSampling,
- int ySampling,
- bool pLinear);
- IMFUTIL_HIDDEN
- virtual ~TypedFlatImageChannel ();
- TypedFlatImageChannel (const TypedFlatImageChannel& other) = delete;
- TypedFlatImageChannel& operator = (const TypedFlatImageChannel& other) = delete;
- TypedFlatImageChannel (TypedFlatImageChannel&& other) = delete;
- TypedFlatImageChannel& operator = (TypedFlatImageChannel&& other) = delete;
- IMFUTIL_HIDDEN
- virtual void resize ();
- IMFUTIL_HIDDEN
- virtual void resetBasePointer ();
- T * _pixels; // Pointer to allocated storage
- T * _base; // Base pointer for faster pixel access
- };
- //
- // Channel typedefs for the pixel data types supported by OpenEXR.
- //
- typedef TypedFlatImageChannel<half> FlatHalfChannel;
- typedef TypedFlatImageChannel<float> FlatFloatChannel;
- typedef TypedFlatImageChannel<unsigned int> FlatUIntChannel;
- //-----------------------------------------------------------------------------
- // Implementation of templates and inline functions
- //-----------------------------------------------------------------------------
- template <class T>
- inline T &
- TypedFlatImageChannel<T>::operator () (int x, int y)
- {
- return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
- }
- template <class T>
- inline const T &
- TypedFlatImageChannel<T>::operator () (int x, int y) const
- {
- return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
- }
- template <class T>
- inline T &
- TypedFlatImageChannel<T>::at (int x, int y)
- {
- boundsCheck (x, y);
- return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
- }
- template <class T>
- inline const T &
- TypedFlatImageChannel<T>::at (int x, int y) const
- {
- boundsCheck (x, y);
- return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
- }
- template <class T>
- inline T *
- TypedFlatImageChannel<T>::row (int r)
- {
- return _base + r * pixelsPerRow();
- }
- template <class T>
- inline const T *
- TypedFlatImageChannel<T>::row (int n) const
- {
- return _base + n * pixelsPerRow();
- }
- #ifndef COMPILING_IMF_FLAT_IMAGE_CHANNEL
- extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel<half>;
- extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel<float>;
- extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedFlatImageChannel<unsigned int>;
- #endif
- OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
- #endif
|