OpenImageIO
|
#include <imagebuf.h>
Classes | |
class | ConstIterator |
class | Iterator |
class | IteratorBase |
Public Types | |
enum | WrapMode { WrapDefault, WrapBlack, WrapClamp, WrapPeriodic, WrapMirror, _WrapLast } |
Public Member Functions | |
ImageBuf () | |
ImageBuf (const std::string &name, ImageCache *imagecache=NULL) | |
ImageBuf (const std::string &name, const ImageSpec &spec) | |
ImageBuf (const std::string &name, const ImageSpec &spec, void *buffer) | |
ImageBuf (const ImageBuf &src) | |
~ImageBuf () | |
void | clear () |
void | reset (const std::string &name, ImageCache *imagecache=NULL) |
void | reset (const std::string &name, const ImageSpec &spec) |
void | alloc (const ImageSpec &spec) |
bool | initialized () const |
Is this ImageBuf object initialized? | |
bool | read (int subimage=0, int miplevel=0, bool force=false, TypeDesc convert=TypeDesc::UNKNOWN, ProgressCallback progress_callback=NULL, void *progress_callback_data=NULL) |
bool | init_spec (const std::string &filename, int subimage, int miplevel) |
bool | save (const std::string &filename=std::string(), const std::string &fileformat=std::string(), ProgressCallback progress_callback=NULL, void *progress_callback_data=NULL) const |
bool | write (ImageOutput *out, ProgressCallback progress_callback=NULL, void *progress_callback_data=NULL) const |
void | copy_metadata (const ImageBuf &src) |
bool | copy_pixels (const ImageBuf &src) |
bool | copy (const ImageBuf &src) |
void | swap (ImageBuf &other) |
Swap with another ImageBuf. | |
TINYFORMAT_WRAP_FORMAT (void, error, const, std::ostringstream msg;, msg, append_error(msg.str());) bool has_error(void) const | |
std::string | geterror (void) const |
const ImageSpec & | spec () const |
ImageSpec & | specmod () |
const ImageSpec & | nativespec () const |
const std::string & | name (void) const |
const std::string & | file_format_name (void) const |
int | subimage () const |
int | nsubimages () const |
int | miplevel () const |
int | nmiplevels () const |
int | nchannels () const |
float | getchannel (int x, int y, int z, int c, WrapMode wrap=WrapBlack) const |
void | getpixel (int x, int y, float *pixel, int maxchannels=1000) const |
void | getpixel (int x, int y, int z, float *pixel, int maxchannels=1000, WrapMode wrap=WrapBlack) const |
void | interppixel (float x, float y, float *pixel, WrapMode wrap=WrapBlack) const |
void | interppixel_NDC (float s, float t, float *pixel, WrapMode wrap=WrapBlack) const |
void | interppixel_NDC_full (float s, float t, float *pixel, WrapMode wrap=WrapBlack) const |
void | setpixel (int x, int y, const float *pixel, int maxchannels=1000) |
void | setpixel (int x, int y, int z, const float *pixel, int maxchannels=1000) |
void | setpixel (int i, const float *pixel, int maxchannels=1000) |
bool | get_pixel_channels (int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, int chbegin, int chend, TypeDesc format, void *result, stride_t xstride=AutoStride, stride_t ystride=AutoStride, stride_t zstride=AutoStride) const |
bool | get_pixels (int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, TypeDesc format, void *result, stride_t xstride=AutoStride, stride_t ystride=AutoStride, stride_t zstride=AutoStride) const |
template<typename T > | |
bool | get_pixel_channels (int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, int chbegin, int chend, T *result, stride_t xstride=AutoStride, stride_t ystride=AutoStride, stride_t zstride=AutoStride) const |
template<typename T > | |
bool | get_pixels (int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, T *result, stride_t xstride=AutoStride, stride_t ystride=AutoStride, stride_t zstride=AutoStride) const |
template<typename T > | |
bool | get_pixels (int xbegin_, int xend_, int ybegin_, int yend_, int zbegin_, int zend_, std::vector< T > &result) const |
int | orientation () const |
int | oriented_width () const |
int | oriented_height () const |
int | oriented_x () const |
int | oriented_y () const |
int | oriented_full_width () const |
int | oriented_full_height () const |
int | oriented_full_x () const |
int | oriented_full_y () const |
int | xbegin () const |
Return the beginning (minimum) x coordinate of the defined image. | |
int | xend () const |
Return the end (one past maximum) x coordinate of the defined image. | |
int | ybegin () const |
Return the beginning (minimum) y coordinate of the defined image. | |
int | yend () const |
Return the end (one past maximum) y coordinate of the defined image. | |
int | zbegin () const |
Return the beginning (minimum) z coordinate of the defined image. | |
int | zend () const |
Return the end (one past maximum) z coordinate of the defined image. | |
int | xmin () const |
Return the minimum x coordinate of the defined image. | |
int | xmax () const |
Return the maximum x coordinate of the defined image. | |
int | ymin () const |
Return the minimum y coordinate of the defined image. | |
int | ymax () const |
Return the maximum y coordinate of the defined image. | |
int | zmin () const |
Return the minimum z coordinate of the defined image. | |
int | zmax () const |
Return the maximum z coordinate of the defined image. | |
void | set_full (int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, const float *bordercolor=NULL) |
bool | pixels_valid (void) const |
TypeDesc | pixeltype () const |
void * | localpixels () |
const void * | localpixels () const |
bool | cachedpixels () const |
ImageCache * | imagecache () const |
const void * | pixeladdr (int x, int y, int z=0) const |
void * | pixeladdr (int x, int y) |
void * | pixeladdr (int x, int y, int z) |
bool | deep () const |
Does this ImageBuf store deep data? | |
int | deep_samples (int x, int y, int z=0) const |
const void * | deep_pixel_ptr (int x, int y, int z, int c) const |
float | deep_value (int x, int y, int z, int c, int s) const |
DeepData * | deepdata () |
Retrieve the "deep" data. | |
const DeepData * | deepdata () const |
Protected Member Functions | |
ImageBufImpl * | impl () |
const ImageBufImpl * | impl () const |
void | copy_from (const ImageBuf &src) |
const void * | retile (int x, int y, int z, ImageCache::Tile *&tile, int &tilexbegin, int &tileybegin, int &tilezbegin, int &tilexend, bool exists, WrapMode wrap=WrapDefault) const |
const void * | blackpixel () const |
void | do_wrap (int &x, int &y, int &z, WrapMode wrap) const |
const ImageBuf & | operator= (const ImageBuf &src) |
Private and unimplemented. | |
void | append_error (const std::string &message) const |
Add to the error message list for this IB. | |
Protected Attributes | |
ImageBufImpl * | m_impl |
Friends | |
class | IteratorBase |
An ImageBuf is a simple in-memory representation of a 2D image. It uses ImageInput and ImageOutput underneath for its file I/O, and has simple routines for setting and getting individual pixels, that hides most of the details of memory layout and data representation (translating to/from float automatically).
enum ImageBuf::WrapMode |
Wrap mode describes what happens when an iterator points to a value outside the usual data range of an image.
ImageBuf::ImageBuf | ( | ) |
ImageBuf::ImageBuf | ( | const std::string & | name, |
ImageCache * | imagecache = NULL |
||
) |
Construct an ImageBuf to read the named image – but don't actually read it yet! If a non-NULL imagecache is supplied, it will specifiy a custom ImageCache to use; if otherwise, the global/shared ImageCache will be used.
ImageBuf::ImageBuf | ( | const std::string & | name, |
const ImageSpec & | spec | ||
) |
Construct an Imagebuf given both a name and a proposed spec describing the image size and type, and allocate storage for the pixels of the image (whose values will be undefined).
ImageBuf::ImageBuf | ( | const std::string & | name, |
const ImageSpec & | spec, | ||
void * | buffer | ||
) |
Construct an ImageBuf that "wraps" a memory buffer owned by the calling application. It can write pixels to this buffer, but can't change its resolution or data type.
ImageBuf::~ImageBuf | ( | ) |
Destructor for an ImageBuf.
void ImageBuf::alloc | ( | const ImageSpec & | spec | ) |
Copy spec to *this, and then allocate enough space the right size for an image described by the format spec. If the ImageBuf already has allocated pixels, their values will not be preserved if the new spec does not describe an image of the same size and data type as it used to be.
|
protected |
Add to the error message list for this IB.
bool ImageBuf::cachedpixels | ( | ) | const |
Are the pixels backed by an ImageCache, rather than the whole image being in RAM somewhere?
void ImageBuf::clear | ( | ) |
Restore the ImageBuf to an uninitialized state.
bool ImageBuf::copy | ( | const ImageBuf & | src | ) |
Try to copy the pixels and metadata from src to *this, returning true upon success and false upon error/failure.
If the previous state of *this was uninitialized, owning its own local pixel memory, or referring to a read-only image backed by ImageCache, then local pixel memory will be allocated to hold the new pixels and the call always succeeds unless the memory cannot be allocated.
If *this previously referred to an app-owned memory buffer, the memory cannot be re-allocated, so the call will only succeed if the app-owned buffer is already the correct resolution and number of channels. The data type of the pixels will be converted automatically to the data type of the app buffer.
void ImageBuf::copy_metadata | ( | const ImageBuf & | src | ) |
Copy all the metadata from src to *this (except for pixel data resolution, channel information, and data format).
bool ImageBuf::copy_pixels | ( | const ImageBuf & | src | ) |
Copy the pixel data from src to *this, automatically converting to the existing data format of *this. It only copies pixels in the overlap regions (and channels) of the two images; pixel data in *this that do exist in src will be set to 0, and pixel data in src that do not exist in *this will not be copied.
bool ImageBuf::deep | ( | ) | const |
Does this ImageBuf store deep data?
const void* ImageBuf::deep_pixel_ptr | ( | int | x, |
int | y, | ||
int | z, | ||
int | c | ||
) | const |
Return a pointer to the raw array of deep data samples for channel c of pixel (x,y,z). Return NULL if the pixel coordinates or channel number are out of range, if the pixel/channel has no deep samples, or if the image is not deep.
int ImageBuf::deep_samples | ( | int | x, |
int | y, | ||
int | z = 0 |
||
) | const |
Retrieve the number of deep data samples corresponding to pixel (x,y,z). Return 0 if not a deep image or if the pixel is out of range or has no deep samples.
float ImageBuf::deep_value | ( | int | x, |
int | y, | ||
int | z, | ||
int | c, | ||
int | s | ||
) | const |
Return the value (as a float) of sample s of channel c of pixel (x,y,z). Return 0.0 if not a deep image or if the pixel coordinates or channel number are out of range or if it has no deep samples.
DeepData* ImageBuf::deepdata | ( | ) |
Retrieve the "deep" data.
const std::string& ImageBuf::file_format_name | ( | void | ) | const |
Return the name of the image file format of the disk file we read into this image. Returns an empty string if this image was not the result of a read().
bool ImageBuf::get_pixel_channels | ( | int | xbegin, |
int | xend, | ||
int | ybegin, | ||
int | yend, | ||
int | zbegin, | ||
int | zend, | ||
int | chbegin, | ||
int | chend, | ||
TypeDesc | format, | ||
void * | result, | ||
stride_t | xstride = AutoStride , |
||
stride_t | ystride = AutoStride , |
||
stride_t | zstride = AutoStride |
||
) | const |
Retrieve the rectangle of pixels spanning [xbegin..xend) X [ybegin..yend) X [zbegin..zend), channels [chbegin,chend) (all with exclusive 'end'), specified as integer pixel coordinates, at the current subimage and MIP-map level, storing the pixel values beginning at the address specified by result and with the given strides (by default, AutoStride means the usual contiguous packing of pixels) and converting into the data type described by 'format'. It is up to the caller to ensure that result points to an area of memory big enough to accommodate the requested rectangle. Return true if the operation could be completed, otherwise return false.
bool ImageBuf::get_pixel_channels | ( | int | xbegin, |
int | xend, | ||
int | ybegin, | ||
int | yend, | ||
int | zbegin, | ||
int | zend, | ||
int | chbegin, | ||
int | chend, | ||
T * | result, | ||
stride_t | xstride = AutoStride , |
||
stride_t | ystride = AutoStride , |
||
stride_t | zstride = AutoStride |
||
) | const |
Retrieve the rectangle of pixels spanning [xbegin..xend) X [ybegin..yend) (with exclusive 'end'), specified as integer pixel coordinates, at the current MIP-map level, storing the pixel values beginning at the address specified by result and with the given strides (by default, AutoStride means the usual contiguous packing of pixels), converting to the type <T> in the process. It is up to the caller to ensure that result points to an area of memory big enough to accommodate the requested rectangle. Return true if the operation could be completed, otherwise return false.
bool ImageBuf::get_pixels | ( | int | xbegin, |
int | xend, | ||
int | ybegin, | ||
int | yend, | ||
int | zbegin, | ||
int | zend, | ||
TypeDesc | format, | ||
void * | result, | ||
stride_t | xstride = AutoStride , |
||
stride_t | ystride = AutoStride , |
||
stride_t | zstride = AutoStride |
||
) | const |
Retrieve the rectangle of pixels spanning [xbegin..xend) X [ybegin..yend) X [zbegin..zend) (with exclusive 'end'), specified as integer pixel coordinates, at the current MIP-map level, storing the pixel values beginning at the address specified by result and with the given strides (by default, AutoStride means the usual contiguous packing of pixels) and converting into the data type described by 'format'. It is up to the caller to ensure that result points to an area of memory big enough to accommodate the requested rectangle. Return true if the operation could be completed, otherwise return false.
|
inline |
Even safer version of get_pixels: Retrieve the rectangle of pixels spanning [xbegin..xend) X [ybegin..yend) (with exclusive 'end'), specified as integer pixel coordinates, at the current MIP-map level, storing the pixel values in the 'result' vector (even allocating the right size). Return true if the operation could be completed, otherwise return false.
float ImageBuf::getchannel | ( | int | x, |
int | y, | ||
int | z, | ||
int | c, | ||
WrapMode | wrap = WrapBlack |
||
) | const |
Retrieve a single channel of one pixel.
std::string ImageBuf::geterror | ( | void | ) | const |
Return the text of all error messages issued since geterror() was called (or an empty string if no errors are pending). This also clears the error message for next time.
|
inline |
Retrieve the pixel value by x and y coordintes (on [0,res-1]), storing the floating point version in pixel[]. Retrieve at most maxchannels (will be clamped to the actual number of channels).
void ImageBuf::getpixel | ( | int | x, |
int | y, | ||
int | z, | ||
float * | pixel, | ||
int | maxchannels = 1000 , |
||
WrapMode | wrap = WrapBlack |
||
) | const |
Retrieve the pixel value by x, y, z coordintes (on [0,res-1]), storing the floating point version in pixel[]. Retrieve at most maxchannels (will be clamped to the actual number of channels).
bool ImageBuf::init_spec | ( | const std::string & | filename, |
int | subimage, | ||
int | miplevel | ||
) |
Initialize this ImageBuf with the named image file, and read its header to fill out the spec correctly. Return true if this succeeded, false if the file could not be read. But don't allocate or read the pixels.
bool ImageBuf::initialized | ( | ) | const |
Is this ImageBuf object initialized?
void ImageBuf::interppixel | ( | float | x, |
float | y, | ||
float * | pixel, | ||
WrapMode | wrap = WrapBlack |
||
) | const |
Linearly interpolate at pixel coordinates (x,y), where (0,0) is the upper left corner, (xres,yres) the lower right corner of the pixel data.
void ImageBuf::interppixel_NDC | ( | float | s, |
float | t, | ||
float * | pixel, | ||
WrapMode | wrap = WrapBlack |
||
) | const |
Linearly interpolate at image data NDC coordinates (s,t), where (0,0) is the upper left corner of the pixel data window, (1,1) the lower right corner of the pixel data. FIXME – lg thinks that this is stupid, and the only useful NDC space is the one used by interppixel_NDC_full. We should deprecate this in the future.
void ImageBuf::interppixel_NDC_full | ( | float | s, |
float | t, | ||
float * | pixel, | ||
WrapMode | wrap = WrapBlack |
||
) | const |
Linearly interpolate at space coordinates (s,t), where (0,0) is the upper left corner of the display window, (1,1) the lower right corner of the display window.
void* ImageBuf::localpixels | ( | ) |
A raw pointer to "local" pixel memory, if they are fully in RAM and not backed by an ImageCache, or NULL otherwise. You can also test it like a bool to find out if pixels are local.
int ImageBuf::miplevel | ( | ) | const |
Return the index of the miplevel are we currently viewing
const std::string& ImageBuf::name | ( | void | ) | const |
Return the name of this image.
const ImageSpec& ImageBuf::nativespec | ( | ) | const |
Return a read-only (const) reference to the "native" image spec (that describes the file, which may be slightly different than the spec of the ImageBuf, particularly if the IB is backed by an ImageCache that is imposing some particular data format or tile size).
int ImageBuf::nchannels | ( | ) | const |
Return the number of color channels in the image.
int ImageBuf::nmiplevels | ( | ) | const |
Return the number of miplevels of the current subimage.
int ImageBuf::nsubimages | ( | ) | const |
Return the number of subimages in the file.
const void* ImageBuf::pixeladdr | ( | int | x, |
int | y, | ||
int | z = 0 |
||
) | const |
Return the address where pixel (x,y,z) is stored in the image buffer. Use with extreme caution! Will return NULL if the pixel values aren't local.
|
inline |
Return the address where pixel (x,y) is stored in the image buffer. Use with extreme caution! Will return NULL if the pixel values aren't local.
void* ImageBuf::pixeladdr | ( | int | x, |
int | y, | ||
int | z | ||
) |
Return the address where pixel (x,y,z) is stored in the image buffer. Use with extreme caution! Will return NULL if the pixel values aren't local.
bool ImageBuf::read | ( | int | subimage = 0 , |
int | miplevel = 0 , |
||
bool | force = false , |
||
TypeDesc | convert = TypeDesc::UNKNOWN , |
||
ProgressCallback | progress_callback = NULL , |
||
void * | progress_callback_data = NULL |
||
) |
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found. Return value is true if all is ok, otherwise false.
void ImageBuf::reset | ( | const std::string & | name, |
ImageCache * | imagecache = NULL |
||
) |
Forget all previous info, reset this ImageBuf to a new image that is uninitialized (no pixel values, no size or spec).
void ImageBuf::reset | ( | const std::string & | name, |
const ImageSpec & | spec | ||
) |
Forget all previous info, reset this ImageBuf to a blank image of the given name and dimensions.
bool ImageBuf::save | ( | const std::string & | filename = std::string() , |
const std::string & | fileformat = std::string() , |
||
ProgressCallback | progress_callback = NULL , |
||
void * | progress_callback_data = NULL |
||
) | const |
Save the image to the named file ("" means use the original filename given when the ImageBuf was created or reset) and file format ("" means to infer the type from the filename extension). Return true if all went ok, false if there were errors writing.
void ImageBuf::set_full | ( | int | xbegin, |
int | xend, | ||
int | ybegin, | ||
int | yend, | ||
int | zbegin, | ||
int | zend, | ||
const float * | bordercolor = NULL |
||
) |
Set the "full" (a.k.a. display) window to [xbegin,xend) x [ybegin,yend) x [zbegin,zend). If bordercolor is not NULL, also set the spec's "oiio:bordercolor" attribute.
|
inline |
Set the pixel with coordinates (x,y,0) to have the values in pixel[0..n-1]. The number of channels copied, n, is the minimum of maxchannels and the actual number of channels in the image.
void ImageBuf::setpixel | ( | int | x, |
int | y, | ||
int | z, | ||
const float * | pixel, | ||
int | maxchannels = 1000 |
||
) |
Set the pixel with coordinates (x,y,z) to have the values in pixel[0..n-1]. The number of channels copied, n, is the minimum of maxchannels and the actual number of channels in the image.
void ImageBuf::setpixel | ( | int | i, |
const float * | pixel, | ||
int | maxchannels = 1000 |
||
) |
Set the i-th pixel value of the image (out of width*height*depth), from floating-point values in pixel[]. Set at most maxchannels (will be clamped to the actual number of channels).
const ImageSpec& ImageBuf::spec | ( | ) | const |
Return a read-only (const) reference to the image spec that describes the buffer.
ImageSpec& ImageBuf::specmod | ( | ) |
Return a writable reference to the image spec that describes the buffer. Use with extreme caution! If you use this for anything other than adding attribute metadata, you are really taking your chances!
int ImageBuf::subimage | ( | ) | const |
Return the index of the subimage are we currently viewing
ImageBuf::TINYFORMAT_WRAP_FORMAT | ( | void | , |
error | , | ||
const | , | ||
std::ostringstream msg; | , | ||
msg | , | ||
append_error(msg.str()); | |||
) | const |
Error reporting for ImageBuf: call this with printf-like arguments. Note however that this is fully typesafe! void error (const char *format, ...) Return true if the IB has had an error and has an error message to retrieve via geterror().
bool ImageBuf::write | ( | ImageOutput * | out, |
ProgressCallback | progress_callback = NULL , |
||
void * | progress_callback_data = NULL |
||
) | const |
Write the image to the open ImageOutput 'out'. Return true if all went ok, false if there were errors writing. It does NOT close the file when it's done (and so may be called in a loop to write a multi-image file).
int ImageBuf::xbegin | ( | ) | const |
Return the beginning (minimum) x coordinate of the defined image.
int ImageBuf::xend | ( | ) | const |
Return the end (one past maximum) x coordinate of the defined image.
int ImageBuf::xmax | ( | ) | const |
Return the maximum x coordinate of the defined image.
int ImageBuf::xmin | ( | ) | const |
Return the minimum x coordinate of the defined image.
int ImageBuf::ybegin | ( | ) | const |
Return the beginning (minimum) y coordinate of the defined image.
int ImageBuf::yend | ( | ) | const |
Return the end (one past maximum) y coordinate of the defined image.
int ImageBuf::ymax | ( | ) | const |
Return the maximum y coordinate of the defined image.
int ImageBuf::ymin | ( | ) | const |
Return the minimum y coordinate of the defined image.
int ImageBuf::zbegin | ( | ) | const |
Return the beginning (minimum) z coordinate of the defined image.
int ImageBuf::zend | ( | ) | const |
Return the end (one past maximum) z coordinate of the defined image.
int ImageBuf::zmax | ( | ) | const |
Return the maximum z coordinate of the defined image.
int ImageBuf::zmin | ( | ) | const |
Return the minimum z coordinate of the defined image.