20 #if !defined(__MITSUBA_CORE_BITMAP_H_)
21 #define __MITSUBA_CORE_BITMAP_H_
23 #include <mitsuba/mitsuba.h>
66 ELuminanceAlpha = 0x01,
84 ESpectrumAlpha = 0x07,
87 ESpectrumAlphaWeight = 0x08,
90 EMultiSpectrumAlphaWeight = 0x09,
162 #if defined(SINGLE_PRECISION)
274 ERotateNoneFlipNone = 0,
275 ERotate180FlipXY = ERotateNoneFlipNone,
276 ERotate90FlipNone = 1,
277 ERotate270FlipXY = ERotate90FlipNone,
278 ERotate180FlipNone = 2,
279 ERotateNoneFlipXY = ERotate180FlipNone,
280 ERotate270FlipNone = 3,
281 ERotate90FlipXY = ERotate270FlipNone,
282 ERotateNoneFlipX = 4,
283 ERotate180FlipY = ERotateNoneFlipX,
285 ERotate270FlipY = ERotate90FlipX,
287 ERotateNoneFlipY = ERotate180FlipX,
289 ERotate90FlipY = ERotate270FlipX
366 Bitmap(
const fs::path &path,
const std::string &prefix =
"");
388 inline size_t getPixelCount()
const {
return (
size_t) m_size.x * (size_t) m_size.y; }
400 inline bool isSquare()
const {
return m_size.x == m_size.y; }
403 std::string getChannelName(
int channelIndex)
const;
408 m_pixelFormat == ELuminanceAlpha ||
409 m_pixelFormat == ERGBA ||
410 m_pixelFormat == EXYZA ||
411 m_pixelFormat == ESpectrumAlpha;
416 return m_pixelFormat == ESpectrumAlphaWeight ||
417 m_pixelFormat == EMultiSpectrumAlphaWeight;
422 return m_pixelFormat == EMultiChannel ||
423 m_pixelFormat == EMultiSpectrumAlphaWeight;
432 int getBitsPerComponent()
const;
440 int getBytesPerComponent()
const;
449 return getBytesPerComponent() * getChannelCount(); }
452 size_t getBufferSize()
const;
487 void drawHLine(
int y,
int x1,
int x2,
const Spectrum &value);
494 void drawVLine(
int x,
int y1,
int y2,
const Spectrum &value);
506 void drawWorkUnit(
const Point2i &offset,
const Vector2i &size,
int worker);
509 bool operator==(
const Bitmap &bitmap)
const;
513 {
return !operator==(bitmap); }
539 void write(EFileFormat format,
Stream *stream,
int compression = -1)
const;
559 void write(EFileFormat format,
const fs::path &filename,
int compression = -1)
const;
576 void write(
const fs::path &filename,
int compression = -1)
const;
631 void convert(
Bitmap *target,
Float multiplier = 1.0f,
685 ref<Bitmap> convert(EPixelFormat pixelFormat, EComponentFormat componentFormat,
740 void convert(
void *target,
741 EPixelFormat pixelFormat, EComponentFormat componentFormat,
758 ref<Bitmap> convertMultiSpectrumAlphaWeight(
const std::vector<EPixelFormat> &pixelFormats,
759 EComponentFormat componentFormat,
const std::vector<std::string> &channelNames)
const;
762 static void convertMultiSpectrumAlphaWeight(
const Bitmap *source,
764 const std::vector<EPixelFormat> &pixelFormats,
765 EComponentFormat componentFormat,
size_t count);
805 void tonemapReinhard(
Float &logAvgLuminance,
Float &maxLuminance,
824 ref<Bitmap> extractChannel(
int channelIndex)
const;
844 std::vector<Layer> getLayers()
const;
853 std::map<std::string, Bitmap *> split()
const;
868 const std::vector<Bitmap *> &sourceBitmaps);
874 void flipVertically();
880 ref<Bitmap> rotateFlip(ERotateFlipType type)
const;
889 void scale(
Float value);
898 void pow(
Float value);
916 void applyMatrix(
Float matrix[3][3]);
1033 void convolve(
const Bitmap *kernel);
1049 static ref<Bitmap> arithmeticOperation(EArithmeticOperation operation,
1070 Float minValue = 0.0f,
Float maxValue = 1.0f)
const;
1088 Float maxValue = 1.0f)
const;
1110 Float minValue = 0.0f,
Float maxValue = 1.0f)
const;
1130 Float minValue = 0.0f,
Float maxValue = 1.0f)
const;
1147 m_metadata.setString(key, value);
1152 return m_metadata.getAsString(key);
1170 void setChannelNames(
const std::vector<std::string> &names);
1189 inline const void *
getData()
const {
return m_data; }
1201 inline const uint16_t *
getUInt16Data()
const {
return (
const uint16_t *) m_data; }
1251 void readPNG(
Stream *stream);
1254 void writePNG(
Stream *stream,
int compression) const;
1257 void readJPEG(
Stream *stream);
1260 void writeJPEG(
Stream *stream,
int quality = 100) const;
1263 void readRGBE(
Stream *stream);
1266 void writeRGBE(
Stream *stream) const;
1269 void readOpenEXR(
Stream *stream, const std::
string &prefix);
1272 void writeOpenEXR(
Stream *stream) const;
1275 void readPFM(
Stream *stream);
1278 void writePFM(
Stream *stream) const;
1281 void readPPM(
Stream *stream);
1284 void writePPM(
Stream *stream) const;
1287 void readTGA(
Stream *stream);
1290 void readBMP(
Stream *stream);
1293 void updateChannelCount();
1306 std::vector<std::
string> m_channelNames;
1383 virtual void convert(
1386 size_t count,
Float multiplier = 1.0f,
1388 int channelCount = -1)
const= 0;
1397 virtual Conversion getConversion()
const = 0;
1406 static const FormatConverter *getInstance(Conversion con);
1414 static ConverterMap m_converters;
1419 template <
typename T>
inline Bitmap::EComponentFormat cfmt() {
return Bitmap::EInvalid; }
1420 template <>
inline Bitmap::EComponentFormat cfmt<uint8_t>() {
return Bitmap::EUInt8; }
1421 template <>
inline Bitmap::EComponentFormat cfmt<uint16_t>() {
return Bitmap::EUInt16; }
1422 template <>
inline Bitmap::EComponentFormat cfmt<uint32_t>() {
return Bitmap::EUInt32; }
1423 template <>
inline Bitmap::EComponentFormat cfmt<half>() {
return Bitmap::EFloat16; }
1424 template <>
inline Bitmap::EComponentFormat cfmt<float>() {
return Bitmap::EFloat32; }
1425 template <>
inline Bitmap::EComponentFormat cfmt<double>() {
return Bitmap::EFloat64; }
1428 template <
typename T>
inline Bitmap::EComponentFormat Bitmap::componentFormat() {
1429 return detail::cfmt<T>();
Float * getFloatData()
Access the underlying raster data (for float32/float64 bitmaps)
Definition: bitmap.h:1228
EBoundaryCondition
When resampling data to a different resolution using Resampler::resample(), this enumeration specifie...
Definition: rfilter.h:53
uint16_t * getUInt16Data()
Access the underlying raster data (for uint16 bitmaps)
Definition: bitmap.h:1198
General-purpose bitmap class with read and write support for several common file formats.
Definition: bitmap.h:50
bool isSquare() const
Return whether this image has matching width and height.
Definition: bitmap.h:400
int getBytesPerPixel() const
Return the number of bytes per pixel.
Definition: bitmap.h:448
void setMetadataString(const std::string &key, const std::string &value)
Set a string-valued metadata field.
Definition: bitmap.h:1146
const std::vector< std::string > & getChannelNames() const
Return the names of the image channels if explicitly specified (empty by default) ...
Definition: bitmap.h:1176
EArithmeticOperation
The four basic arithmetic operations for use with arithmeticOperation()
Definition: bitmap.h:293
Properties & getMetadata()
Return a Properties object containing the image metadata.
Definition: bitmap.h:1156
static void staticInitialization()
Initializes the built-in reference count debugger (if enabled)
bool hasWeight() const
Return whether this image has a weight channel.
Definition: bitmap.h:415
bool operator!=(const Bitmap &bitmap) const
Bitmap inequality operator (useful for unit-tests etc.)
Definition: bitmap.h:512
const Vector2i & getSize() const
Return the bitmap's resolution in pixels.
Definition: bitmap.h:385
EPixelFormat
Definition: bitmap.h:61
#define MTS_EXPORT_CORE
Definition: getopt.h:29
std::string name
Descriptive name of the bitmap layer.
Definition: bitmap.h:309
Invalid component format (used to report error conditions)
Definition: bitmap.h:154
const void * getData() const
Access the underlying bit raster (const version)
Definition: bitmap.h:1189
32-bit unsigned integer (uint32_t) component encoding
Definition: bitmap.h:128
half * getFloat16Data()
Access the underlying raster data (for float16 bitmaps)
Definition: bitmap.h:1210
std::ostream & operator<<(std::ostream &out, const DScalar1< Scalar, VecType > &s)
Definition: autodiff.h:392
void copyFrom(const Bitmap *bitmap, Point2i targetOffset)
Copy the contents of another bitmap into the region with the specified offset.
Definition: bitmap.h:945
bool hasAlpha() const
Return whether this image has an alpha channel.
Definition: bitmap.h:406
ERotateFlipType
List of different rotation/flip types that can be passed to rotateFlip()
Definition: bitmap.h:273
Describes a sub-layer of a multilayer bitmap (e.g. OpenEXR)
Definition: bitmap.h:307
Generic interface to separable image reconstruction filters.
Definition: rfilter.h:44
float * getFloat32Data()
Access the underlying raster data (for float32 bitmaps)
Definition: bitmap.h:1216
EPixelFormat getPixelFormat() const
Return the pixel format of this bitmap.
Definition: bitmap.h:379
std::vector< std::string > & getChannelNames()
Return the names of the image channels if explicitly specified (empty by default) ...
Definition: bitmap.h:1173
int getChannelCount() const
Return the number of channels used by this bitmap.
Definition: bitmap.h:397
RGBE image format by Greg Ward.
Definition: bitmap.h:214
Truevision Advanced Raster Graphics Array file format.
Definition: bitmap.h:253
std::vector< int > channels
References to bitmap channels.
Definition: bitmap.h:313
OpenEXR high dynamic range file format developed by Industrial Light & Magic (ILM) ...
Definition: bitmap.h:204
size_t getPixelCount() const
Return the total number of pixels.
Definition: bitmap.h:388
EComponentFormat getComponentFormat() const
Return the component format of this bitmap.
Definition: bitmap.h:382
void accumulate(const Bitmap *bitmap)
Accumulate the contents of another bitmap into the region with the specified offset.
Definition: bitmap.h:1012
void setMetadata(const Properties &metadata)
Set the a Properties object containing the image metadata.
Definition: bitmap.h:1162
const half * getFloat16Data() const
Access the underlying raster data (for float16 bitmaps, const version)
Definition: bitmap.h:1213
void copyFrom(const Bitmap *bitmap)
Copy the contents of another bitmap into the region with the specified offset.
Definition: bitmap.h:963
const float * getFloat32Data() const
Access the underlying raster data (for float32 bitmaps, const version)
Definition: bitmap.h:1219
8-bit unsigned integer (uint8_t) component encoding
Definition: bitmap.h:114
void accumulate(const Bitmap *bitmap, Point2i targetOffset)
Accumulate the contents of another bitmap into the region with the specified offset.
Definition: bitmap.h:994
bool isMultiChannel() const
Return whether this is a generic multi-channel image.
Definition: bitmap.h:421
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
32-bit floating point (float) HDR component encoding
Definition: bitmap.h:142
Reference counting helper.
Definition: ref.h:40
EConversionIntent
When converting from RGB reflectance values to discretized color spectra, the following `intent' flag...
Definition: spectrum.h:673
const Float * getFloatData() const
Access the underlying raster data (for float/float64 bitmaps, const version)
Definition: bitmap.h:1231
Joint Photographic Experts Group file format.
Definition: bitmap.h:245
std::string getMetadataString(const std::string &key) const
Return a string-valued metadata field.
Definition: bitmap.h:1151
const Properties & getMetadata() const
Return a Properties object containing the image metadata (const version)
Definition: bitmap.h:1159
int getHeight() const
Return the bitmap's height in pixels.
Definition: bitmap.h:394
uint8_t * getUInt8Data()
Access the underlying raster (for uint8 bitmaps)
Definition: bitmap.h:1192
PPM (Portable Pixel Map) image format.
Definition: bitmap.h:234
int getWidth() const
Return the bitmap's width in pixels.
Definition: bitmap.h:391
EComponentFormat
Supported per-component data formats.
Definition: bitmap.h:97
EPixelFormat format
Pixel format that should be associated with underlying combination of bitmap channels.
Definition: bitmap.h:311
const uint16_t * getUInt16Data() const
Access the underlying raster data (for uint16 bitmaps, const version)
Definition: bitmap.h:1201
Associative parameter map for constructing subclasses of ConfigurableObject.
Definition: properties.h:46
PFM (Portable Float Map) image format.
Definition: bitmap.h:224
Parent of all Mitsuba classes.
Definition: object.h:38
16-bit unsigned integer (uint16_t) component encoding
Definition: bitmap.h:121
Windows Bitmap file format.
Definition: bitmap.h:261
const double * getFloat64Data() const
Access the underlying raster data (for float64 bitmaps, const version)
Definition: bitmap.h:1225
TPoint2< int > Point2i
Definition: fwd.h:131
Float getGamma() const
Return the bitmap's gamma identifier (-1: sRGB)
Definition: bitmap.h:1140
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
const uint32_t * getUInt32Data() const
Access the underlying raster data (for uint32 bitmaps, const version)
Definition: bitmap.h:1207
virtual std::string toString() const
Return a human-readable string representation of the object's contents.
const uint8_t * getUInt8Data() const
Access the underlying bit raster (for uint8 bitmaps, const version)
Definition: bitmap.h:1195
64-bit floating point (double) HDR component encoding
Definition: bitmap.h:149
static void staticShutdown()
Free the memory taken by staticInitialization()
EFileFormat
Supported file formats.
Definition: bitmap.h:170
void * getData()
Access the underlying raster.
Definition: bitmap.h:1186
void setGamma(Float gamma)
Set the bitmap's gamma identifier (-1: sRGB)
Definition: bitmap.h:1143
double * getFloat64Data()
Access the underlying raster data (for float64 bitmaps)
Definition: bitmap.h:1222
uint32_t * getUInt32Data()
Access the underlying raster data (for uint32 bitmaps)
Definition: bitmap.h:1204