General-purpose bitmap class with read and write support for several common file formats. More...
#include <mitsuba/core/bitmap.h>
Classes | |
struct | Layer |
Describes a sub-layer of a multilayer bitmap (e.g. OpenEXR) More... | |
Public Member Functions | |
std::string | toString () const |
Return some human-readable information about this bitmap. More... | |
virtual const Class * | getClass () const |
Retrieve this object's class. More... | |
Access to metadata associated with the bitmap | |
Float | getGamma () const |
Return the bitmap's gamma identifier (-1: sRGB) More... | |
void | setGamma (Float gamma) |
Set the bitmap's gamma identifier (-1: sRGB) More... | |
void | setMetadataString (const std::string &key, const std::string &value) |
Set a string-valued metadata field. More... | |
std::string | getMetadataString (const std::string &key) const |
Return a string-valued metadata field. More... | |
Properties & | getMetadata () |
Return a Properties object containing the image metadata. More... | |
const Properties & | getMetadata () const |
Return a Properties object containing the image metadata (const version) More... | |
void | setMetadata (const Properties &metadata) |
Set the a Properties object containing the image metadata. More... | |
void | setChannelNames (const std::vector< std::string > &names) |
Explicitly set the names of the image channels. More... | |
std::vector< std::string > & | getChannelNames () |
Return the names of the image channels if explicitly specified (empty by default) More... | |
const std::vector< std::string > & | getChannelNames () const |
Return the names of the image channels if explicitly specified (empty by default) More... | |
Bitmap raster data accessors | |
void * | getData () |
Access the underlying raster. More... | |
const void * | getData () const |
Access the underlying bit raster (const version) More... | |
uint8_t * | getUInt8Data () |
Access the underlying raster (for uint8 bitmaps) More... | |
const uint8_t * | getUInt8Data () const |
Access the underlying bit raster (for uint8 bitmaps, const version) More... | |
uint16_t * | getUInt16Data () |
Access the underlying raster data (for uint16 bitmaps) More... | |
const uint16_t * | getUInt16Data () const |
Access the underlying raster data (for uint16 bitmaps, const version) More... | |
uint32_t * | getUInt32Data () |
Access the underlying raster data (for uint32 bitmaps) More... | |
const uint32_t * | getUInt32Data () const |
Access the underlying raster data (for uint32 bitmaps, const version) More... | |
half * | getFloat16Data () |
Access the underlying raster data (for float16 bitmaps) More... | |
const half * | getFloat16Data () const |
Access the underlying raster data (for float16 bitmaps, const version) More... | |
float * | getFloat32Data () |
Access the underlying raster data (for float32 bitmaps) More... | |
const float * | getFloat32Data () const |
Access the underlying raster data (for float32 bitmaps, const version) More... | |
double * | getFloat64Data () |
Access the underlying raster data (for float64 bitmaps) More... | |
const double * | getFloat64Data () const |
Access the underlying raster data (for float64 bitmaps, const version) More... | |
Float * | getFloatData () |
Access the underlying raster data (for float32/float64 bitmaps) More... | |
const Float * | getFloatData () const |
Access the underlying raster data (for float/float64 bitmaps, const version) More... | |
Public Member Functions inherited from Object | |
Object () | |
Construct a new object. More... | |
int | getRefCount () const |
Return the current reference count. More... | |
void | incRef () const |
Increase the reference count of the object by one. More... | |
void | decRef (bool autoDeallocate=true) const |
Decrease the reference count of the object and possibly deallocate it. More... | |
Static Public Member Functions | |
static void | staticInitialization () |
Run static initialization code (sets up OpenEXR for multithreading) More... | |
static void | staticShutdown () |
Release any resources allocated in staticInitialization. More... | |
Static Public Member Functions inherited from Object | |
static void | staticInitialization () |
Initializes the built-in reference count debugger (if enabled) More... | |
static void | staticShutdown () |
Free the memory taken by staticInitialization() More... | |
Static Public Attributes | |
static Class * | m_theClass |
Static Public Attributes inherited from Object | |
static Class * | m_theClass |
Pointer to the object's class descriptor. More... | |
Protected Member Functions | |
virtual | ~Bitmap () |
Virtual destructor. More... | |
void | readPNG (Stream *stream) |
Read a file stored using the PNG file format. More... | |
void | writePNG (Stream *stream, int compression) const |
Write a file using the PNG file format. More... | |
void | readJPEG (Stream *stream) |
Read a file stored using the JPEG file format. More... | |
void | writeJPEG (Stream *stream, int quality=100) const |
Save a file using the JPEG file format. More... | |
void | readRGBE (Stream *stream) |
Read a file stored using the RGBE file format. More... | |
void | writeRGBE (Stream *stream) const |
Write a file using the RGBE file format. More... | |
void | readOpenEXR (Stream *stream, const std::string &prefix) |
Read a file stored using the OpenEXR file format. More... | |
void | writeOpenEXR (Stream *stream) const |
Write a file using the OpenEXR file format. More... | |
void | readPFM (Stream *stream) |
Read a file stored using the PFM file format. More... | |
void | writePFM (Stream *stream) const |
Write a file using the PFM file format. More... | |
void | readPPM (Stream *stream) |
Read a file stored using the PPM file format. More... | |
void | writePPM (Stream *stream) const |
Write a file using the PPM file format. More... | |
void | readTGA (Stream *stream) |
Read a file stored using the TGA file format. More... | |
void | readBMP (Stream *stream) |
Read a file stored using the BMP file format. More... | |
void | updateChannelCount () |
Update the internally cached channel count. More... | |
void | readStream (EFileFormat format, Stream *stream, const std::string &prefix) |
Delegate for stream loading operations. More... | |
Protected Member Functions inherited from Object | |
virtual | ~Object () |
Virtual private deconstructor. (Will only be called by ref) More... | |
Protected Attributes | |
EPixelFormat | m_pixelFormat |
EComponentFormat | m_componentFormat |
Vector2i | m_size |
uint8_t * | m_data |
Float | m_gamma |
uint8_t | m_channelCount |
bool | m_ownsData |
Properties | m_metadata |
std::vector< std::string > | m_channelNames |
Constructors and Enumerations | |
enum | EPixelFormat { ELuminance = 0x00, ELuminanceAlpha = 0x01, ERGB = 0x02, ERGBA = 0x03, EXYZ = 0x04, EXYZA = 0x05, ESpectrum = 0x06, ESpectrumAlpha = 0x07, ESpectrumAlphaWeight = 0x08, EMultiSpectrumAlphaWeight = 0x09, EMultiChannel = 0x10 } |
enum | EComponentFormat { EBitmask = 0, EUInt8, EUInt16, EUInt32, EFloat16, EFloat32, EFloat64, EInvalid, EFloat = EFloat64 } |
Supported per-component data formats. More... | |
enum | EFileFormat { EPNG = 0, EOpenEXR, ERGBE, EPFM, EPPM, EJPEG, ETGA, EBMP, EAuto } |
Supported file formats. More... | |
enum | ERotateFlipType { ERotateNoneFlipNone = 0, ERotate180FlipXY = ERotateNoneFlipNone, ERotate90FlipNone = 1, ERotate270FlipXY = ERotate90FlipNone, ERotate180FlipNone = 2, ERotateNoneFlipXY = ERotate180FlipNone, ERotate270FlipNone = 3, ERotate90FlipXY = ERotate270FlipNone, ERotateNoneFlipX = 4, ERotate180FlipY = ERotateNoneFlipX, ERotate90FlipX = 5, ERotate270FlipY = ERotate90FlipX, ERotate180FlipX = 6, ERotateNoneFlipY = ERotate180FlipX, ERotate270FlipX = 7, ERotate90FlipY = ERotate270FlipX } |
List of different rotation/flip types that can be passed to rotateFlip() More... | |
enum | EArithmeticOperation { EAddition = 0, ESubtraction, EMultiplication, EDivision } |
The four basic arithmetic operations for use with arithmeticOperation() More... | |
Bitmap (EPixelFormat pFmt, EComponentFormat cFmt, const Vector2i &size, uint8_t channelCount=0, uint8_t *data=NULL) | |
Create a bitmap of the specified type and allocate the necessary amount of memory. More... | |
Bitmap (EFileFormat format, Stream *stream, const std::string &prefix="") | |
Load a bitmap from an arbitrary stream data source. More... | |
Bitmap (const fs::path &path, const std::string &prefix="") | |
Load a bitmap from a file on disk. More... | |
Miscellaneous | |
EPixelFormat | getPixelFormat () const |
Return the pixel format of this bitmap. More... | |
EComponentFormat | getComponentFormat () const |
Return the component format of this bitmap. More... | |
const Vector2i & | getSize () const |
Return the bitmap's resolution in pixels. More... | |
size_t | getPixelCount () const |
Return the total number of pixels. More... | |
int | getWidth () const |
Return the bitmap's width in pixels. More... | |
int | getHeight () const |
Return the bitmap's height in pixels. More... | |
int | getChannelCount () const |
Return the number of channels used by this bitmap. More... | |
bool | isSquare () const |
Return whether this image has matching width and height. More... | |
std::string | getChannelName (int channelIndex) const |
Return a string representation of the name of a channel. More... | |
bool | hasAlpha () const |
Return whether this image has an alpha channel. More... | |
bool | hasWeight () const |
Return whether this image has a weight channel. More... | |
bool | isMultiChannel () const |
Return whether this is a generic multi-channel image. More... | |
int | getBitsPerComponent () const |
Return the number bits per component. More... | |
int | getBytesPerComponent () const |
Return the number bytes per component. More... | |
int | getBytesPerPixel () const |
Return the number of bytes per pixel. More... | |
size_t | getBufferSize () const |
Return the bitmap size in bytes. More... | |
Spectrum | getPixel (const Point2i &pos) const |
Return the spectral color value associated with a given pixel. More... | |
void | setPixel (const Point2i &pos, const Spectrum &value) |
Set the spectral color value associated with a given pixel. More... | |
void | drawHLine (int y, int x1, int x2, const Spectrum &value) |
Draw a horizontal line at the specified position. More... | |
void | drawVLine (int x, int y1, int y2, const Spectrum &value) |
Draw a vertical line at the specified position. More... | |
void | drawRect (const Point2i &offset, const Vector2i &size, const Spectrum &value) |
Draw a rectangle with the specified position and size. More... | |
void | fillRect (Point2i offset, Vector2i size, const Spectrum &value) |
Draw a filled rectangle with the specified position and size. More... | |
void | drawWorkUnit (const Point2i &offset, const Vector2i &size, int worker) |
Convenience function to visually indicate that a thread is working on a certain part of an image. More... | |
bool | operator== (const Bitmap &bitmap) const |
Bitmap equality operator (useful for unit-tests etc.) More... | |
bool | operator!= (const Bitmap &bitmap) const |
Bitmap inequality operator (useful for unit-tests etc.) More... | |
ref< Bitmap > | clone () const |
Create an identical copy. More... | |
void | clear () |
Clear the bitmap to zero. More... | |
void | write (EFileFormat format, Stream *stream, int compression=-1) const |
void | write (EFileFormat format, const fs::path &filename, int compression=-1) const |
void | write (const fs::path &filename, int compression=-1) const |
template<typename T > | |
static EComponentFormat | componentFormat () |
Return the bitmap component format for a specified type. More... | |
Conversions and transformations | |
void | convert (Bitmap *target, Float multiplier=1.0f, Spectrum::EConversionIntent intent=Spectrum::EReflectance) const |
Convert the bitmap into another pixel and/or component format. More... | |
ref< Bitmap > | convert (EPixelFormat pixelFormat, EComponentFormat componentFormat, Float gamma=1.0f, Float multiplier=1.0f, Spectrum::EConversionIntent intent=Spectrum::EReflectance) |
Convert the bitmap into another pixel and/or component format. More... | |
void | convert (void *target, EPixelFormat pixelFormat, EComponentFormat componentFormat, Float gamma=1.0f, Float multiplier=1.0f, Spectrum::EConversionIntent intent=Spectrum::EReflectance) const |
Convert the bitmap into another pixel and/or component format. More... | |
ref< Bitmap > | convertMultiSpectrumAlphaWeight (const std::vector< EPixelFormat > &pixelFormats, EComponentFormat componentFormat, const std::vector< std::string > &channelNames) const |
Specialized conversion method for multi-channel HDR images. More... | |
void | tonemapReinhard (Float &logAvgLuminance, Float &maxLuminance, Float key, Float burn) |
Apply Reinhard et al's tonemapper in chromaticity space. More... | |
ref< Bitmap > | expand () |
Expand bitmask images. More... | |
ref< Bitmap > | extractChannel (int channelIndex) const |
Extract one of the color channels in the bitmap and return it as a separate luminance bitmap. More... | |
ref< Bitmap > | extractChannels (Bitmap::EPixelFormat fmt, const std::vector< int > &channels) const |
Extract several color channels of a multi-channel bitmap and return them as a bitmap with the given pixel format. More... | |
std::vector< Layer > | getLayers () const |
Extracts layer information from the bitmap. More... | |
std::map< std::string, Bitmap * > | split () const |
Split an multi-channel image buffer (e.g. from an OpenEXR image with lots of AOVs) into its constituent layers. More... | |
ref< Bitmap > | crop (const Point2i &offset, const Vector2i &size) const |
Crop the bitmap to the specified rectangle. More... | |
void | flipVertically () |
Vertically flip the image contents. More... | |
Spectrum | average () const |
Compute the average value of the bitmap. More... | |
ref< Bitmap > | rotateFlip (ERotateFlipType type) const |
Perform the specified rotatation & flip operation. More... | |
void | scale (Float value) |
Scale the entire image by a certain value. More... | |
void | pow (Float value) |
Raise the entire image to a certain value. More... | |
void | colorBalance (Float r, Float g, Float b) |
Color balancing: apply the given scale factors to the red, green, and blue channels of the image. More... | |
void | applyMatrix (Float matrix[3][3]) |
void | copyFrom (const Bitmap *bitmap, Point2i sourceOffset, Point2i targetOffset, Vector2i size) |
Copy the contents of another bitmap into the region with the specified offset. More... | |
void | copyFrom (const Bitmap *bitmap, Point2i targetOffset) |
Copy the contents of another bitmap into the region with the specified offset. More... | |
void | copyFrom (const Bitmap *bitmap) |
Copy the contents of another bitmap into the region with the specified offset. More... | |
void | accumulate (const Bitmap *bitmap, Point2i sourceOffset, Point2i targetOffset, Vector2i size) |
Accumulate the contents of another bitmap into the region with the specified offset. More... | |
void | accumulate (const Bitmap *bitmap, Point2i targetOffset) |
Accumulate the contents of another bitmap into the region with the specified offset. More... | |
void | accumulate (const Bitmap *bitmap) |
Accumulate the contents of another bitmap into the region with the specified offset. More... | |
void | convolve (const Bitmap *kernel) |
Convolve the image with a (centered) convolution kernel. More... | |
void | resample (const ReconstructionFilter *rfilter, ReconstructionFilter::EBoundaryCondition bch, ReconstructionFilter::EBoundaryCondition bcv, Bitmap *target, Bitmap *temp=NULL, Float minValue=0.0f, Float maxValue=1.0f) const |
Up- or down-sample this image to a different resolution. More... | |
ref< Bitmap > | resample (const ReconstructionFilter *rfilter, ReconstructionFilter::EBoundaryCondition bch, ReconstructionFilter::EBoundaryCondition bcv, const Vector2i &size, Float minValue=0.0f, Float maxValue=1.0f) const |
Up- or down-sample this image to a different resolution. More... | |
void | filter (const ReconstructionFilter *rfilter, ReconstructionFilter::EBoundaryCondition bch, ReconstructionFilter::EBoundaryCondition bcv, Bitmap *target, Bitmap *temp=NULL, Float minValue=0.0f, Float maxValue=1.0f) const |
Apply a separable convolution filter to the image. More... | |
ref< Bitmap > | filter (const ReconstructionFilter *rfilter, ReconstructionFilter::EBoundaryCondition bch, ReconstructionFilter::EBoundaryCondition bcv, Float minValue=0.0f, Float maxValue=1.0f) const |
Apply a separable convolution filter to the image. More... | |
static void | convertMultiSpectrumAlphaWeight (const Bitmap *source, const uint8_t *sourcePtr, const Bitmap *target, uint8_t *targetPtr, const std::vector< EPixelFormat > &pixelFormats, EComponentFormat componentFormat, size_t count) |
Similar to the above, but writes to an already existing image. More... | |
static ref< Bitmap > | join (EPixelFormat fmt, const std::vector< Bitmap * > &sourceBitmaps) |
Merges multiple bitmaps of the same type and resolution into one with a larger number of channels. More... | |
static ref< Bitmap > | arithmeticOperation (EArithmeticOperation operation, const Bitmap *bitmap1, const Bitmap *bitmap2) |
Perform an arithmetic operation using two images. More... | |
General-purpose bitmap class with read and write support for several common file formats.
This class handles loading of PNG, JPEG, BMP, TGA, as well as OpenEXR files, and it supports writing of PNG, JPEG and OpenEXR files.
PNG and OpenEXR files are optionally annotated with string-valued metadata, and the gamma setting can be stored as well. Please see the class methods and enumerations for further detail.
The Python version of this API contains thee additional member functions: fromByteArray
and toByteArray
copy image data between the Bitmap instance and a Python bytearray
. The function buffer
returns a memoryview
-compatible buffer object that can also interoperate with numpy
's ndarray
.
The four basic arithmetic operations for use with arithmeticOperation()
Enumerator | |
---|---|
EAddition | |
ESubtraction | |
EMultiplication | |
EDivision |
Supported per-component data formats.
Enumerator | |
---|---|
EBitmask |
1-bit (mask) component encoding. Note that you can use this class to load, save, and access bitmasks – however, many of the manipulation operations (i.e. crop(), accumulate(), etc.) do not currently handle them. Default gamma value: linear (1.0) |
EUInt8 |
8-bit unsigned integer ( Default gamma value: sRGB (approx. 2.2) |
EUInt16 |
16-bit unsigned integer ( Default gamma value: linear (1.0) |
EUInt32 |
32-bit unsigned integer ( Default gamma value: linear (1.0) |
EFloat16 |
16-bit floating point ( Default gamma value: linear (1.0) |
EFloat32 |
32-bit floating point ( Default gamma value: linear (1.0) |
EFloat64 |
64-bit floating point ( Default gamma value: linear (1.0) |
EInvalid |
Invalid component format (used to report error conditions) |
EFloat |
Floating point ( Default gamma value: linear (1.0) |
Supported file formats.
Enumerator | |
---|---|
EPNG |
Portable network graphics. The following is supported:
|
EOpenEXR |
OpenEXR high dynamic range file format developed by Industrial Light & Magic (ILM) The following is supported:
The following is not supported:
|
ERGBE |
RGBE image format by Greg Ward. The following is supported
|
EPFM |
PFM (Portable Float Map) image format. The following is supported
|
EPPM |
PPM (Portable Pixel Map) image format. The following is supported |
EJPEG |
Joint Photographic Experts Group file format. The following is supported:
|
ETGA |
Truevision Advanced Raster Graphics Array file format. The following is supported:
|
EBMP |
Windows Bitmap file format. The following is supported:
|
EAuto |
Automatically detect the file format. Note: this flag only applies when loading a file. In this case, the source stream must support the |
This enumeration lists all pixel format types supported by the Bitmap class. This both determines the number of channels, and how they should be interpreted
Enumerator | |
---|---|
ELuminance |
Single-channel luminance bitmap. |
ELuminanceAlpha |
Two-channel luminance + alpha bitmap. |
ERGB |
RGB bitmap. |
ERGBA |
RGB bitmap + alpha channel. |
EXYZ |
XYZ tristimulus bitmap. |
EXYZA |
XYZ tristimulus + alpha channel. |
ESpectrum |
Spectrum bitmap. |
ESpectrumAlpha |
Spectrum bitmap + alpha channel. |
ESpectrumAlphaWeight |
Spectrum bitmap + alpha + weight channel (Mitsuba's internal render bucket representation) |
EMultiSpectrumAlphaWeight |
Bitmap with multiple spectra + alpha + weight channel (render buckets used by the 'multichannel' plugin) |
EMultiChannel |
Arbitrary multi-channel bitmap without a fixed interpretation. |
List of different rotation/flip types that can be passed to rotateFlip()
mitsuba::Bitmap::Bitmap | ( | EPixelFormat | pFmt, |
EComponentFormat | cFmt, | ||
const Vector2i & | size, | ||
uint8_t | channelCount = 0 , |
||
uint8_t * | data = NULL |
||
) |
Create a bitmap of the specified type and allocate the necessary amount of memory.
pFmt | Specifies the pixel format (e.g. RGBA or Luminance-only) |
cFmt | Specifies how the per-pixel components are encoded (e.g. unsigned 8 bit integers or 32-bit floating point values) |
size | Specifies the horizontal and vertical bitmap size in pixels |
channelCount | Channel count of the image. This parameter is only required when pFmt = EMultiChannel or EMultiSpectrumAlphaWeight |
data | External pointer to the image data. If set to NULL , the implementation will allocate memory itself. |
mitsuba::Bitmap::Bitmap | ( | EFileFormat | format, |
Stream * | stream, | ||
const std::string & | prefix = "" |
||
) |
Load a bitmap from an arbitrary stream data source.
format | File format to be read (PNG/EXR/Auto-detect ...) |
stream | Pointer to an arbitrary stream data source |
prefix | Only consider image layers whose identifier begins with prefix . This is currently only supported by the OpenEXR format loader. |
mitsuba::Bitmap::Bitmap | ( | const fs::path & | path, |
const std::string & | prefix = "" |
||
) |
Load a bitmap from a file on disk.
path | Path to a bitmap file (format will be auto-detected) |
prefix | Only consider image layers whose identifier begins with prefix . This is currently only supported by the OpenEXR format loader. |
|
protectedvirtual |
Virtual destructor.
void mitsuba::Bitmap::accumulate | ( | const Bitmap * | bitmap, |
Point2i | sourceOffset, | ||
Point2i | targetOffset, | ||
Vector2i | size | ||
) |
Accumulate the contents of another bitmap into the region with the specified offset.
Out-of-bounds regions are ignored. It is assumed that bitmap != this
.
Accumulate the contents of another bitmap into the region with the specified offset.
This convenience function calls the main accumulate()
implementation with size
set to bitmap->getSize()
and sourceOffset
set to zero. Out-of-bounds regions are ignored. It is assumed that bitmap != this
.
|
inline |
Accumulate the contents of another bitmap into the region with the specified offset.
This convenience function calls the main accumulate()
implementation with size
set to bitmap->getSize()
and sourceOffset
and targetOffset
tt> set to zero. Out-of-bounds regions are ignored. It is assumed that bitmap != this
.
void mitsuba::Bitmap::applyMatrix | ( | Float | matrix[3][3] | ) |
Apply a color transformation matrix to the contents of the bitmap
The implementation assumes that the contents have the RGB, RGBA, XYZ, or XYZA pixel format and a floating point component format.
|
static |
Perform an arithmetic operation using two images.
This function can add, subtract, multiply, or divide arbitrary images. If the input images have different sizes or component and pixel formats, the implementation first resamples and converts them into the most "expressive" format that subsumes both input images (at the cost of some temporary dynamic memory allocations).
To keep the implementation simple, there is currently no special treatment of integer over/underflows if the component format is EUInt8, EUInt16, or EUInt32.
Spectrum mitsuba::Bitmap::average | ( | ) | const |
Compute the average value of the bitmap.
void mitsuba::Bitmap::clear | ( | ) |
Clear the bitmap to zero.
Color balancing: apply the given scale factors to the red, green, and blue channels of the image.
When the image is not an EFloat16
, EFloat32
, or EFloat64-based
RGB/RGBA image, the function throws an exception
|
inlinestatic |
Return the bitmap component format for a specified type.
void mitsuba::Bitmap::convert | ( | Bitmap * | target, |
Float | multiplier = 1.0f , |
||
Spectrum::EConversionIntent | intent = Spectrum::EReflectance |
||
) | const |
Convert the bitmap into another pixel and/or component format.
This helper function can be used to efficiently convert a bitmap between different underlying representations. For instance, it can translate a 24-bit sRGB bitmap to a linear spectrum-valued representation based on half-, single- or double-precision floating point-backed storage.
This function roughly does the following:
targetGamma
is applied The clamped gamma-corrected value is then written to the new bitmap
If the pixel formats differ, this function will also perform basic conversions (e.g. spectrum to rgb, luminance to uniform spectrum values, etc.)
Note that the alpha channel is assumed to be linear in both the source and target bitmap, hence it won't be affected by any gamma-related transformations.
convert()
variant takes a pointer to an existing bitmap, which must have a matching size. It then copies all data, while performing the necessary pixel/component format and gamma conversions.target Pointer to the target bitmap, which should be of the same size. multiplier An optional multiplicative factor that can be applied to all color/luminance values in linear space (alpha will not be affected). intent When converting from RGB to spectral color values, this flag specifies how ambiguities in this highly under-constrained problem should be resolved.
ref<Bitmap> mitsuba::Bitmap::convert | ( | EPixelFormat | pixelFormat, |
EComponentFormat | componentFormat, | ||
Float | gamma = 1.0f , |
||
Float | multiplier = 1.0f , |
||
Spectrum::EConversionIntent | intent = Spectrum::EReflectance |
||
) |
Convert the bitmap into another pixel and/or component format.
This helper function can be used to efficiently convert a bitmap between different underlying representations. For instance, it can translate a 24-bit sRGB bitmap to a linear spectrum-valued representation based on half-, single- or double-precision floating point-backed storage.
This function roughly does the following:
targetGamma
is applied The clamped gamma-corrected value is then written to the new bitmap
If the pixel formats differ, this function will also perform basic conversions (e.g. spectrum to rgb, luminance to uniform spectrum values, etc.)
Note that the alpha channel is assumed to be linear in both the source and target bitmap, hence it won't be affected by any gamma-related transformations.
convert()
variant usually returns a new bitmap instance. When the conversion would just involve copying the original bitmap, the function becomes a no-op and returns the current instance.pixelFormat Specifies the desired pixel format componentFormat Specifies the desired component format gamma Specifies the desired gamma value. Special values: 1.0
denotes a linear space, and -1.0
corresponds to sRGB. multiplier An optional multiplicative factor that can be applied to all color/luminance values in linear space (alpha will not be affected). intent When converting from RGB to spectral color values, this flag specifies how ambiguities in this highly under-constrained problem should be resolved.
void mitsuba::Bitmap::convert | ( | void * | target, |
EPixelFormat | pixelFormat, | ||
EComponentFormat | componentFormat, | ||
Float | gamma = 1.0f , |
||
Float | multiplier = 1.0f , |
||
Spectrum::EConversionIntent | intent = Spectrum::EReflectance |
||
) | const |
Convert the bitmap into another pixel and/or component format.
This helper function can be used to efficiently convert a bitmap between different underlying representations. For instance, it can translate a 24-bit sRGB bitmap to a linear spectrum-valued representation based on half-, single- or double-precision floating point-backed storage.
This function roughly does the following:
targetGamma
is applied The clamped gamma-corrected value is then written to the new bitmap
If the pixel formats differ, this function will also perform basic conversions (e.g. spectrum to rgb, luminance to uniform spectrum values, etc.)
Note that the alpha channel is assumed to be linear in both the source and target bitmap, hence it won't be affected by any gamma-related transformations.
convert()
variant writes to a raw bitmap buffer provided as a pointer.target A pointer to a "raw" image pixel buffer pixelFormat Specifies the desired pixel format componentFormat Specifies the desired component format gamma Specifies the desired gamma value. Special values: 1.0
denotes a linear space, and -1.0
corresponds to sRGB. multiplier An optional multiplicative factor that can be applied to all color/luminance values in linear space (alpha will not be affected). intent When converting from RGB to spectral color values, this flag specifies how ambiguities in this highly under-constrained problem should be resolved.
ref<Bitmap> mitsuba::Bitmap::convertMultiSpectrumAlphaWeight | ( | const std::vector< EPixelFormat > & | pixelFormats, |
EComponentFormat | componentFormat, | ||
const std::vector< std::string > & | channelNames | ||
) | const |
Specialized conversion method for multi-channel HDR images.
The bitmap class pixel format EMultiSpectrumAlphaWeight is used by the 'multichannel' plugin to render multiple related images at the same time. This function implements a conversion function analogous to convert() that adjusts each of the sub-images so that it has a desired pixel format. The returned bitmap has the combined pixel format EMultiChannel and the specified component format. Names for each of the resulting channels should be provided via the channelNames
parameters.
This feature is currently used by the hdrfilm
and tiledhdrfilm
plugins.
|
static |
Similar to the above, but writes to an already existing image.
void mitsuba::Bitmap::convolve | ( | const Bitmap * | kernel | ) |
Convolve the image with a (centered) convolution kernel.
When compiled with FFTW, Mitsuba will do the convolution in frequency space using three FFT operations. Otherwise, it falls back to a brute force method with quadratic complexity.
The image can have any resolution; the kernel should be square and of odd resolution. Both images must be of the same floating point-valued component format. The kernel can either have one color channel or as many color channels as the image to be convolved.
The convolution is always performed in double precision. irrespective of the precision of the underlying data.
void mitsuba::Bitmap::copyFrom | ( | const Bitmap * | bitmap, |
Point2i | sourceOffset, | ||
Point2i | targetOffset, | ||
Vector2i | size | ||
) |
Copy the contents of another bitmap into the region with the specified offset.
Out-of-bounds regions are ignored. It is assumed that bitmap != this
.
Copy the contents of another bitmap into the region with the specified offset.
This convenience function calls the main copyFrom()
implementation with size
set to bitmap->getSize()
and sourceOffset
set to zero. Out-of-bounds regions are ignored. It is assumed that bitmap != this
.
|
inline |
Copy the contents of another bitmap into the region with the specified offset.
This convenience function calls the main copyFrom()
implementation with size
set to bitmap->getSize()
and sourceOffset
and targetOffset
tt> set to zero. Out-of-bounds regions are ignored. It is assumed that bitmap != this
.
Crop the bitmap to the specified rectangle.
void mitsuba::Bitmap::drawHLine | ( | int | y, |
int | x1, | ||
int | x2, | ||
const Spectrum & | value | ||
) |
Draw a horizontal line at the specified position.
Draws from x1<x2 up to and including x2.
void mitsuba::Bitmap::drawRect | ( | const Point2i & | offset, |
const Vector2i & | size, | ||
const Spectrum & | value | ||
) |
Draw a rectangle with the specified position and size.
void mitsuba::Bitmap::drawVLine | ( | int | x, |
int | y1, | ||
int | y2, | ||
const Spectrum & | value | ||
) |
Draw a vertical line at the specified position.
Draws from y1<y2 up to and including y2.
Convenience function to visually indicate that a thread is working on a certain part of an image.
Expand bitmask images.
When this image is a bitmask, the implementation returns an expanded version in EUInt8 format. Otherwise, it returns a pointer to the current instance.
Extract one of the color channels in the bitmap and return it as a separate luminance bitmap.
When this is already a single-channel bitmap, the function returns a pointer to the current instance.
ref<Bitmap> mitsuba::Bitmap::extractChannels | ( | Bitmap::EPixelFormat | fmt, |
const std::vector< int > & | channels | ||
) | const |
Extract several color channels of a multi-channel bitmap and return them as a bitmap with the given pixel format.
Draw a filled rectangle with the specified position and size.
void mitsuba::Bitmap::filter | ( | const ReconstructionFilter * | rfilter, |
ReconstructionFilter::EBoundaryCondition | bch, | ||
ReconstructionFilter::EBoundaryCondition | bcv, | ||
Bitmap * | target, | ||
Bitmap * | temp = NULL , |
||
Float | minValue = 0.0f , |
||
Float | maxValue = 1.0f |
||
) | const |
Apply a separable convolution filter to the image.
Applies the provided filter while observing the specified horizontal and vertical boundary conditions when looking up data outside of the input domain.
In comparison to convolve(), this function operates in the primal domain.
A maximum and maximum image value can be specified to prevent to prevent out-of-range values that are created by the filtering process.
The optional 'temp' parameter can be used to pass an image of the same dimensions as the source and target image.
ref<Bitmap> mitsuba::Bitmap::filter | ( | const ReconstructionFilter * | rfilter, |
ReconstructionFilter::EBoundaryCondition | bch, | ||
ReconstructionFilter::EBoundaryCondition | bcv, | ||
Float | minValue = 0.0f , |
||
Float | maxValue = 1.0f |
||
) | const |
Apply a separable convolution filter to the image.
Applies the provided filter while observing the specified horizontal and vertical boundary conditions when looking up data outside of the input domain.
In comparison to convolve(), this function operates in the primal domain.
A maximum and maximum image value can be specified to prevent to prevent out-of-range values that are created by the filtering process.
This function allocates a new output image and returns it.
void mitsuba::Bitmap::flipVertically | ( | ) |
Vertically flip the image contents.
int mitsuba::Bitmap::getBitsPerComponent | ( | ) | const |
Return the number bits per component.
When the component format is set to EBitmask
, this function returns 1; EUInt8
maps to 8, etc.
size_t mitsuba::Bitmap::getBufferSize | ( | ) | const |
Return the bitmap size in bytes.
int mitsuba::Bitmap::getBytesPerComponent | ( | ) | const |
Return the number bytes per component.
When the component format is set to EBitmask
, this function throws an exception.
|
inline |
Return the number of bytes per pixel.
When the component format is set to EBitmask
, this function throws an exception.
|
inline |
Return the number of channels used by this bitmap.
std::string mitsuba::Bitmap::getChannelName | ( | int | channelIndex | ) | const |
Return a string representation of the name of a channel.
|
inline |
Return the names of the image channels if explicitly specified (empty by default)
|
inline |
Return the names of the image channels if explicitly specified (empty by default)
|
virtual |
Retrieve this object's class.
Reimplemented from Object.
|
inline |
Return the component format of this bitmap.
|
inline |
Access the underlying raster.
|
inline |
Access the underlying bit raster (const version)
|
inline |
Access the underlying raster data (for float16 bitmaps)
|
inline |
Access the underlying raster data (for float16 bitmaps, const version)
|
inline |
Access the underlying raster data (for float32 bitmaps)
|
inline |
Access the underlying raster data (for float32 bitmaps, const version)
|
inline |
Access the underlying raster data (for float64 bitmaps)
|
inline |
Access the underlying raster data (for float64 bitmaps, const version)
|
inline |
Access the underlying raster data (for float32/float64 bitmaps)
|
inline |
Access the underlying raster data (for float/float64 bitmaps, const version)
|
inline |
Return the bitmap's gamma identifier (-1: sRGB)
|
inline |
Return the bitmap's height in pixels.
std::vector<Layer> mitsuba::Bitmap::getLayers | ( | ) | const |
Extracts layer information from the bitmap.
This is a convenience function which analyzes the bitmap's channel names and extracts groups matching a name convention specified by the OpenEXR standard.
A series of channel names referred to as 'diffuse.R', 'diffuse.B', and 'diffuse.G' will be identified as a single layer. This works for RGB[A]/XYZ[A], and Luminance[A] images
|
inline |
Return a Properties object containing the image metadata.
|
inline |
Return a Properties object containing the image metadata (const version)
|
inline |
Return a string-valued metadata field.
Return the spectral color value associated with a given pixel.
When this is not a spectrum image, conversions are applied as appropriate.
|
inline |
Return the total number of pixels.
|
inline |
Return the pixel format of this bitmap.
|
inline |
Return the bitmap's resolution in pixels.
|
inline |
Access the underlying raster data (for uint16 bitmaps)
|
inline |
Access the underlying raster data (for uint16 bitmaps, const version)
|
inline |
Access the underlying raster data (for uint32 bitmaps)
|
inline |
Access the underlying raster data (for uint32 bitmaps, const version)
|
inline |
Access the underlying raster (for uint8 bitmaps)
|
inline |
Access the underlying bit raster (for uint8 bitmaps, const version)
|
inline |
Return the bitmap's width in pixels.
|
inline |
Return whether this image has an alpha channel.
|
inline |
Return whether this image has a weight channel.
|
inline |
Return whether this is a generic multi-channel image.
|
inline |
Return whether this image has matching width and height.
|
static |
Merges multiple bitmaps of the same type and resolution into one with a larger number of channels.
fmt | The desired pixel format of the combined bitmap |
sourceBitmaps | An array containing the input bitmaps They must all be of the same size and component format. |
Bitmap inequality operator (useful for unit-tests etc.)
Bitmap equality operator (useful for unit-tests etc.)
void mitsuba::Bitmap::pow | ( | Float | value | ) |
Raise the entire image to a certain value.
Skips the image's alpha channel, if it has one. When the image uses a fixed point representation and a pixel value overflows during the scale operation, it is clamped to the representable range.
|
protected |
Read a file stored using the BMP file format.
|
protected |
Read a file stored using the JPEG file format.
|
protected |
Read a file stored using the OpenEXR file format.
|
protected |
Read a file stored using the PFM file format.
|
protected |
Read a file stored using the PNG file format.
|
protected |
Read a file stored using the PPM file format.
|
protected |
Read a file stored using the RGBE file format.
|
protected |
Delegate for stream loading operations.
|
protected |
Read a file stored using the TGA file format.
void mitsuba::Bitmap::resample | ( | const ReconstructionFilter * | rfilter, |
ReconstructionFilter::EBoundaryCondition | bch, | ||
ReconstructionFilter::EBoundaryCondition | bcv, | ||
Bitmap * | target, | ||
Bitmap * | temp = NULL , |
||
Float | minValue = 0.0f , |
||
Float | maxValue = 1.0f |
||
) | const |
Up- or down-sample this image to a different resolution.
Uses the provided reconstruction filter and observes the specified horizontal and vertical boundary conditions when looking up data outside of the input domain.
A maximum and maximum image value can be specified to prevent to prevent out-of-range values that are created by the resampling process.
The optional 'temp' parameter can be used to pass an image of resolution Vector2i(target->getWidth(), this->getHeight())
to avoid intermediate memory allocations.
ref<Bitmap> mitsuba::Bitmap::resample | ( | const ReconstructionFilter * | rfilter, |
ReconstructionFilter::EBoundaryCondition | bch, | ||
ReconstructionFilter::EBoundaryCondition | bcv, | ||
const Vector2i & | size, | ||
Float | minValue = 0.0f , |
||
Float | maxValue = 1.0f |
||
) | const |
Up- or down-sample this image to a different resolution.
Uses the provided reconstruction filter and observes the specified horizontal and vertical boundary conditions when looking up data outside of the input domain.
A maximum and maximum image value can be specified to prevent to prevent out-of-range values that are created by the resampling process.
This function allocates a new output image and returns it.
ref<Bitmap> mitsuba::Bitmap::rotateFlip | ( | ERotateFlipType | type | ) | const |
Perform the specified rotatation & flip operation.
void mitsuba::Bitmap::scale | ( | Float | value | ) |
Scale the entire image by a certain value.
Skips the image's alpha channel, if it has one. When the image uses a fixed point representation and a pixel value overflows during the scale operation, it is clamped to the representable range.
void mitsuba::Bitmap::setChannelNames | ( | const std::vector< std::string > & | names | ) |
Explicitly set the names of the image channels.
The main use of this feature is when writing EMultiChannel images to OpenEXR files. In other cases, the names are ignored.
|
inline |
Set the bitmap's gamma identifier (-1: sRGB)
|
inline |
Set the a Properties object containing the image metadata.
|
inline |
Set a string-valued metadata field.
Set the spectral color value associated with a given pixel.
When this is not a spectrum image, conversions are applied as appropriate.
std::map<std::string, Bitmap *> mitsuba::Bitmap::split | ( | ) | const |
Split an multi-channel image buffer (e.g. from an OpenEXR image with lots of AOVs) into its constituent layers.
This operation internally calls getLayers() to extract bitmap layers followed by one or more calls to extractChannels()
|
static |
Run static initialization code (sets up OpenEXR for multithreading)
|
static |
Release any resources allocated in staticInitialization.
void mitsuba::Bitmap::tonemapReinhard | ( | Float & | logAvgLuminance, |
Float & | maxLuminance, | ||
Float | key, | ||
Float | burn | ||
) |
Apply Reinhard et al's tonemapper in chromaticity space.
This function
Computes and stores the maximum and log-average luminance of the image If the logAvgLuminace
and maxLuminance
parameters are nonzero, it is assumed that these have already been computed, and this step is omitted. Explicitly specifying them can be useful to prevent flickering when tonemapping multiple frames of an animation.
The key
parameter specifies whether a low-key or high-key image is desired. The value must be in the interval [0,1]
. A good starting point is a middle-grey, i.e. key=0.18
.
When burn=0
, the entire image is re-mapped into the displayable range. This may not always be desireable – for instance, one might choose to let a highlight burn out, and this is achieved by choosing burn in (0, 1].
For reference, see "Photographic Tone Reproduction for Digital Images" by Erik Reinhard, Michael Stark, Peter Shirley, and James Fewerda, in ACM Transactions on Graphics 2002, Vol. 21, 3
gamma=1
, and that it uses a EFloat16/EFloat32/EFloat64 component format. The conversion process is destructive in the sense that it overwrites the original image.(logAvgLuminance, maxLuminance) = tonemapReinhard(logAvgLuminance, maxLuminance, key, burn)
|
virtual |
Return some human-readable information about this bitmap.
Reimplemented from Object.
|
protected |
Update the internally cached channel count.
void mitsuba::Bitmap::write | ( | EFileFormat | format, |
Stream * | stream, | ||
int | compression = -1 |
||
) | const |
Write an encoded form of the bitmap to a stream using the specified file format
format | Target file format (EOpenEXR, EPNG, or EOpenEXR) |
stream | Target stream that will receive the encoded output |
compression | For PNG images, this parameter can be used to control how strongly libpng will try to compress the output (with 1 being the lowest and 9 denoting the highest compression). Note that saving files with the highest compression will be very slow. For JPEG files, this denotes the desired quality (between 0 and 100, the latter being best). The default argument (-1) uses compression 5 for PNG and 100 for JPEG files. |
void mitsuba::Bitmap::write | ( | EFileFormat | format, |
const fs::path & | filename, | ||
int | compression = -1 |
||
) | const |
Write an encoded form of the bitmap to a file using the specified file format
format | Target file format (EOpenEXR, EPNG, or EOpenEXR) |
stream | Target stream that will receive the encoded output |
compression | For PNG images, this parameter can be used to control how strongly libpng will try to compress the output (with 1 being the lowest and 9 denoting the highest compression). Note that saving files with the highest compression will be very slow. For JPEG files, this denotes the desired quality (between 0 and 100, the latter being best). The default argument (-1) uses compression 5 for PNG and 100 for JPEG files. |
void mitsuba::Bitmap::write | ( | const fs::path & | filename, |
int | compression = -1 |
||
) | const |
Write an encoded form of the bitmap to a file (auto-detecting the file format)
stream | Target stream that will receive the encoded output |
compression | For PNG images, this parameter can be used to control how strongly libpng will try to compress the output (with 1 being the lowest and 9 denoting the highest compression). Note that saving files with the highest compression will be very slow. For JPEG files, this denotes the desired quality (between 0 and 100, the latter being best). The default argument (-1) uses compression 5 for PNG and 100 for JPEG files. |
|
protected |
Save a file using the JPEG file format.
|
protected |
Write a file using the OpenEXR file format.
|
protected |
Write a file using the PFM file format.
|
protected |
Write a file using the PNG file format.
|
protected |
Write a file using the PPM file format.
|
protected |
Write a file using the RGBE file format.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
static |