#include <c4d_basebitmap.h>
The bitmap class can be used to load, read, draw and save bitmap pictures of various formats.
Bitmaps are organized so that the 2D point [0,0] is the top left corner. Be sure to call Init() before you attempt to use a newly allocated bitmap.
- Note
- Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.
- Warning
- Though BaseBitmap can work with other bit depths than 24 and 32, note that only these function support other bit depths:
GetBw(), GetBh(), GetBt(), GetBpz(), Init(), GetLine(), SetLine(), GetPixelCnt(), SetPixelCnt(), SetCMAP(),
AddChannel(), RemoveChannel(), GetAlphaPixel(), SetAlphaPixel(), GetInternalChannel(), GetChannelCount(), GetChannelNum()
To use higher bit depths or multiple channels, see MultipassBitmap.
|
static IMAGERESULT | Init (BaseBitmap *&res, const Filename &name, Int32 frame=-1, Bool *ismovie=nullptr, BitmapLoaderPlugin **loaderplugin=nullptr, const maxon::Delegate< void(Float progress)> &progressCallback=nullptr) |
|
IMAGERESULT | Init (const Filename &name, Int32 frame=-1, Bool *ismovie=nullptr) |
|
IMAGERESULT | Init (Int32 x, Int32 y, Int32 depth=24, INITBITMAPFLAGS flags=INITBITMAPFLAGS::NONE) |
|
|
void | ScaleIt (BaseBitmap *dst, Int32 intens, Bool sample, Bool nprop) const |
|
void | ScaleBicubic (BaseBitmap *dst, Int32 src_xmin, Int32 src_ymin, Int32 src_xmax, Int32 src_ymax, Int32 dst_xmin, Int32 dst_ymin, Int32 dst_xmax, Int32 dst_ymax) const |
|
|
void | SetPen (Int32 r, Int32 g, Int32 b) |
|
void | Clear (Int32 r, Int32 g, Int32 b) |
|
void | Clear (Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 r, Int32 g, Int32 b) |
|
void | Line (Int32 x1, Int32 y1, Int32 x2, Int32 y2) |
|
void | Arc (Int32 x, Int32 y, Float radius, Float angle_start, Float angle_end, Int32 subdiv=32) |
|
|
void | GetPixel (Int32 x, Int32 y, UInt16 *r, UInt16 *g, UInt16 *b) const |
|
Vector32 | GetPixelDirect (Int32 x, Int32 y) const |
|
Bool | SetPixel (Int32 x, Int32 y, Int32 r, Int32 g, Int32 b) |
|
void | GetAlphaPixel (BaseBitmap *channel, Int32 x, Int32 y, UInt16 *val) const |
|
Bool | SetAlphaPixel (BaseBitmap *channel, Int32 x, Int32 y, Int32 val) |
|
void | GetPixelCnt (Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE dstmode, PIXELCNT flags, ColorProfileConvert *conversion=nullptr) const |
|
Bool | SetPixelCnt (Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE srcmode, PIXELCNT flags) |
|
◆ BaseBitmap()
◆ ~BaseBitmap()
◆ Alloc()
Allocates a bitmap. Destroy the allocated bitmap with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.
- Returns
- The allocated bitmap, or nullptr if the allocation failed.
◆ Free()
Destructs bitmaps allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.
- Parameters
-
[in,out] | bm | The bitmap to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards. |
◆ Init() [1/3]
Loads a bitmap file. The format is automatically detected.
- Note
- The bitmap class only supports up to 4 channels. Also, most image loaders will only load one alpha channel.
- Parameters
-
[out] | res | Assigned a pointer to a bitmap. The caller owns the pointed bitmap. |
[in] | name | A valid filename that can either refer a movie or a picture. |
[in] | frame | The frame number to load in a movie. |
[in] | ismovie | If not nullptr this pointer is assigned true if the loaded picture is a movie, otherwise false. |
[in] | loaderplugin | If not nullptr this pointer is assigned a bitmap loader plugin instance of the same type as the loaded bitmap. The caller owns the pointed bitmap loader. |
[in] | progressCallback | Callback which is triggered if the loader supports progress reporting. Since R19. |
- Returns
- The image result: IMAGERESULT
◆ Init() [2/3]
Loads a file into the bitmap. The file format is automatically detected.
- Warning
- Any previous data in the bitmap object is lost.
- Note
- The bitmap class only supports up to 4 channels. Also, most image loaders will only load one alpha channel.
- Parameters
-
[in] | name | A valid filename that can either refer a movie or a picture. |
[in] | frame | The frame number to load in a movie. |
[in] | ismovie | If not nullptr this pointer is assigned true if the loaded picture is a movie, otherwise false. |
- Returns
- The image result: IMAGERESULT
◆ Init() [3/3]
Initializes the bitmap to the given [x,y] dimensions and depth.
- Warning
- Any previous data in the bitmap object is lost.
- Parameters
-
[in] | x | The requested width in pixels (Maximum 16 000 pixels). |
[in] | y | The requested height in pixels (Max. 16000 pixels). |
[in] | depth | The requested bit depth. The possible values are (1, 4, 8, 16, 24, 32, 64, 96). On some platforms 32-bit will be used even if 24 is requested, to allow for padding. In this case GetBt() will return 32. |
[in] | flags | The initialization flags: INITBITMAPFLAGS |
- Returns
- The image result: IMAGERESULT
◆ FlushAll()
Resets the bitmap to its initial state and frees allocated memory. Requires a call to Init() before the bitmap can be used again.
◆ Save()
Saves the bitmap to a file.
- Parameters
-
[in] | name | A valid filename that can either refer a movie or a picture. |
[in] | format | The image format: FILTER |
[in] | data | The additional settings for some formats. MISCSAVER
Can be nullptr, which means the same as an empty container. The caller owns the pointed container. |
[in] | savebits | A combination of the following flags: SAVEBIT |
- Returns
- The image result: IMAGERESULT
◆ GetClone()
Copies the bitmap.
- Warning
- Do not use GetClone() in a NodeData::CopyTo method. This will cause memory leaks. Use CopyTo() instead.
- Returns
- The cloned bitmap, or nullptr if an error occured. The caller owns the pointed bitmap.
◆ GetClonePart()
Copies a part of the bitmap, specified by the rectangle [x,y] to [x+w,y+h].
- Parameters
-
[in] | x | The upper left X coordinate of the rectangle. |
[in] | y | The upper left Y coordinate of the rectangle. |
[in] | w | The width of the rectangle. |
[in] | h | The height of the rectangle. |
- Returns
- The cloned part of the bitmap, or nullptr if an error occured. The caller owns the pointed bitmap.
◆ CopyTo()
Copies the bitmap from *this
to *dst.
- Parameters
-
[out] | dst | The bitmap to copy this bitmap to. The caller owns the pointed bitmap. |
- Returns
- true if the bitmap was successfully copied, otherwise false.
◆ CopyPartTo()
Copies a part of the bitmap from *this
to *dst.
- Parameters
-
[out] | dst | The bitmap to copy this bitmap to. The caller owns the pointed bitmap. |
[in] | x | The X position of the part to be copied from *this . |
[in] | y | The Y position of the part to be copied from *this . |
[in] | w | The width of the part to be copied. |
[in] | h | The height of the part to be copied. |
- Returns
- true if the bitmap part was successfully copied, otherwise false.
◆ GetBw()
Gets the width of the bitmap in pixels. If the bitmap has not been initialized the return value is 0.
- Note
- Calling this method is the only way to see if a bitmap passed by Cinema 4D or some other source has been initialized.
- Returns
- The bitmap width in pixels, or 0 if the bitmap is not initialized.
◆ GetBh()
Gets the height of the bitmap in pixels.
- Returns
- The bitmap height in pixels.
◆ GetBt()
Gets the number of bits per pixel.
- Returns
- The number of bits per pixel.
◆ GetBpz()
Gets the number of bytes per line.
- Returns
- The number of bytes per line.
◆ GetColorMode()
Gets the color mode of the bitmap.
- Returns
- The color mode: COLORMODE
◆ ScaleIt()
Scales the bitmap to fit in the destination bitmap and copies it there.
The destination bitmap dst needs to be initialized with the destination size before calling this function.
- Parameters
-
[out] | dst | The destination bitmap. The caller owns the pointed bitmap. |
[in] | intens | Lets you change brightness of the image (128 = 50% brightness, 256 = unchanged). |
[in] | sample | If true a better scaling algorithm is used, which results in a better quality but a bit slower. |
[in] | nprop | Must be true if non-proportional scaling is wanted. |
◆ ScaleBicubic()
Scales the bitmap rectangle [src_xmin,src_ymin,src_xmax,src_ymax] to fit in the destination bitmap rectangle [dst_xmin,dst_ymin,dst_xmax,dst_ymax] and copies it there.
The scaling, if necessary, is done using Bicubic interpolation.
The destination bitmap dst needs to be initialized before calling this function.
- Note
- This function can currently only scale down, i.e. the destination needs to be smaller to the source in size.
- Parameters
-
[out] | dst | The destination bitmap. The caller owns the pointed bitmap. |
[in] | src_xmin | The source top left X coordinate. |
[in] | src_ymin | The source top left Y coordinate. |
[in] | src_xmax | The source bottom right X coordinate. |
[in] | src_ymax | The source bottom right Y coordinate. |
[in] | dst_xmin | The destination top left X coordinate. |
[in] | dst_ymin | The destination top left Y coordinate. |
[in] | dst_xmax | The destination bottom right X coordinate. |
[in] | dst_ymax | The destination bottom right Y coordinate. |
◆ SetPen()
Sets the color for the following drawing operations.
The range of the parameters is 0 to 255, where (255,255,255) is white, regardless of the bit depth of the image.
- Note
- This method only works with bit depth 24 and 32.
- Parameters
-
[in] | r | The red component. |
[in] | g | The green component. |
[in] | b | The blue component. |
◆ Clear() [1/2]
Sets all pixels in the bitmap to the color specified by (r,g,b).
The range of the parameters is 0 to 255, where (255,255,255) is white, regardless of the bit depth of the image.
- Note
- This method only works with bit depth 24 and 32.
- Parameters
-
[in] | r | The red component. |
[in] | g | The green component. |
[in] | b | The blue component. |
◆ Clear() [2/2]
Sets all pixels within the rectangle specified by [x1,y1] and [x2,y2] to the color specified by (r,g,b).
The range of the parameters is 0 to 255, where (255,255,255) is white, regardless of the bit depth of the image.
- Note
- This method only works with bit depth 24 and 32.
- Parameters
-
[in] | x1 | The top left X coordinate of the rectangle. |
[in] | y1 | The top left Y coordinate of the rectangle. |
[in] | x2 | The bottom right X coordinate of the rectangle. |
[in] | y2 | The bottom right Y coordinate of the rectangle. |
[in] | r | The red component. |
[in] | g | The green component. |
[in] | b | The blue component. |
◆ Line()
Draws a line with the current pen color between (x1,y1) and (x2,y2).
- Note
- This method only works with bit depth 24 and 32.
- Parameters
-
[in] | x1 | The start X coordinate. |
[in] | y1 | The start Y coordinate. |
[in] | x2 | The end X coordinate. |
[in] | y2 | The end Y coordinate. |
◆ Arc()
Draws an arc (section of a circle) with the current pen color at [x,y].
- Parameters
-
[in] | x | The X coordinate. |
[in] | y | The Y coordinate. |
[in] | radius | The radius of the ellipse. |
[in] | angle_start | The start of the angle in radians. |
[in] | angle_end | The end of the angle in radians. |
[in] | subdiv | The range between angle_start and angle_end is divided into subdiv line segments. |
◆ GetPixel()
Gets the color at [x,y] and assigns it to the passed (r,g,b) parameters.
The range of the assigned r, g and b parameters is 0 to 255, where (255,255,255) is white, regardless of the bit depth of the image.
- Parameters
-
[in] | x | The X coordinate. |
[in] | y | The Y coordinate. |
[out] | r | Assigned the red component. |
[out] | g | Assigned the green component. |
[out] | b | Assigned the blue component. |
◆ GetPixelDirect()
Gets the color at [x,y].
The range of the assigned parameters are 0.0 to 255.0, regardless of the bit depth of the image, where (255.0,255.0,255.0) is white. The range returns Float value, so 8, 16 and 32 bit precision is supported.
- Parameters
-
[in] | x | The X coordinate. |
[in] | y | The Y coordinate. |
- Returns
- Color as form of a 3D Vector.
◆ SetPixel()
Sets the pixel at [x,y] to the color specified by (r,g,b) (0 <= r/g/b <= 255).
The range of the r, g and b parameters is 0 to 255, where (255,255,255) is white, regardless of the bit depth of the image.
- Parameters
-
[in] | x | The X coordinate. |
[in] | y | The Y coordinate. |
[in] | r | The red component. |
[in] | g | The green component. |
[in] | b | The blue component. |
- Returns
- true if the pixel was successfully set, otherwise false.
◆ GetAlphaPixel()
Gets the alpha value at [x,y] and assigns it to the passed parameter val (0 <= val <= 255).
- Parameters
-
[in] | channel | The alpha channel to use. |
[in] | x | The X coordinate. |
[in] | y | The Y coordinate. |
[out] | val | Assigned the alpha value. |
◆ SetAlphaPixel()
Sets the alpha value at [x,y] to val.
- Parameters
-
[in] | channel | The alpha channel to use. |
[in] | x | The X coordinate. |
[in] | y | The Y coordinate. |
[in] | val | The alpha value. 0 <= val <= 255 |
◆ GetPixelCnt()
Reads cnt pixels from [x,y] in the bitmap to the buffer with the color mode dstmode, incrementing inc bytes for each pixel.
- Parameters
-
[in] | x | The X coordinate of the first pixel to get. |
[in] | y | The Y coordinate of the first pixel to get. |
[in] | cnt | The number of pixels to get. |
[out] | buffer | A pointer to a large enough memory buffer where the pixel data will be written. The caller owns the pointed buffer. |
[in] | inc | The byte increment per pixel in the buffer. |
[in] | dstmode | The destination color mode: COLORMODE |
[in] | flags | The flags: PIXELCNT |
[in] | conversion | This should be normally set to nullptr. Pass a color profile only if a conversion is wanted before retrieving the pixel data.
This only works if either the bitmap is 32-bit per component (so no 8/16-bit images) or the dstmode is 32-bit per component.
The conversion is done before color reduction (e.g. if dstmode is 16-bit the profile is first applied and then the data resampled to 16-bit). |
◆ SetPixelCnt()
Sets cnt pixels at [x,y] in the bitmap from buffer with color mode srcmode, incrementing inc bytes for each pixel.
- Parameters
-
[in] | x | The X coordinate of the first pixel to set. |
[in] | y | The Y coordinate of the first pixel to set. |
[in] | cnt | The number of pixels to set. |
[in] | buffer | A pointer to a large enough memory buffer containing the pixels to set. The caller owns the pointed buffer. |
[in] | inc | The byte increment per pixel in the buffer. |
[in] | srcmode | The source color mode: COLORMODE |
- Warning
- None of the alpha modes are supported.
- Parameters
-
- Returns
- true if successful, otherwise false.
◆ AddChannel()
Adds a new alpha channel to the bitmap.
- Note
- The bitmap class only supports up to 4 channels.
- Parameters
-
[in] | internal | Should only be true for the first alpha. The internal alpha will be stored within a bitmaps if its format supports alphas. |
[in] | straight | Should be true if the bitmap has to be interpreted as straight.
For information about straight alphas please take a look at the corresponding option in the render settings and the manual of Cinema 4D. |
- Returns
- The newly added channel if successful, otherwise nullptr.
◆ RemoveChannel()
Removes the specified channel from the bitmap.
- Parameters
-
[in] | channel | The alpha channel to remove. |
◆ GetInternalChannel() [1/2]
Gets the internal read-only alpha channel.
- Note
- The internal alpha channel is the one that is saved together with the picture, with those formats that support this.
- Returns
- The read-only internal alpha channel, or nullptr if no internal alpha is available. The bitmap owns the pointed channel.
◆ GetInternalChannel() [2/2]
Gets the internal alpha channel.
- Note
- The internal alpha channel is the one that is saved together with the picture, with those formats that support this.
- Returns
- The read-only internal alpha channel, or nullptr if no internal alpha is available. The bitmap owns the pointed channel.
◆ GetChannelCount()
Int32 GetChannelCount |
( |
| ) |
const |
Gets the number of alpha channels in the bitmap, including the internal channel.
- Returns
- The number of alpha channels.
◆ GetChannelNum() [1/2]
Gets the read-only alpha channel specified by num.
- Parameters
-
- Returns
- The requested read-only channel.
◆ GetChannelNum() [2/2]
Gets the alpha channel specified by num.
- Parameters
-
- Returns
- The requested channel.
◆ GetData()
Gets bitmap data. Private.
- Parameters
-
[in] | id | The data ID to Get: BASEBITMAP_DATA |
[in] | t_default | The default data to use. |
- Returns
- The retrieved data.
◆ SetData()
Sets bitmap data. Private.
- Parameters
-
- Returns
- true if the data could be set, otherwise false.
◆ GetDirty()
Gets the incremented dirty count when the bitmap changes. Private.
- Returns
- The dirty count.
◆ SetDirty()
Makes the bitmap dirty. Private.
◆ GetUpdateRegionBitmap() [1/2]
Gets the updated region of a bitmap (read-only).
- Returns
- The updated region.
◆ GetUpdateRegionBitmap() [2/2]
Gets the updated region of a bitmap.
- Returns
- The updated region.
◆ GetUpdateRegion()
Gets the update region for the bitmap and resets it if requested.
- Parameters
-
[out] | xMin | Left side of the update region. |
[out] | xMax | Right side of the update region. |
[out] | yMin | Top side of the update region. |
[out] | yMax | Bottom side of the update region. |
[in] | reset | True, if the update region should be reset. |
◆ SetColorProfile()
Sets the color profile for the bitmap.
- Parameters
-
[in] | profile | The new color profile. The caller owns the pointed color profile. |
[in] | index | Index of the colorprofile to set (COLORPROFILE_INDEX_*). |
- Returns
- true if the color profile was successfully set, otherwise false.
◆ GetColorProfile()
Gets the color profile of the bitmap.
- Parameters
-
[in] | index | Index of the colorprofile to retrieve (COLORPROFILE_INDEX_*). |
- Returns
- The color profile of the bitmap, or nullptr if not available.
◆ GetMemoryInfo()
Int GetMemoryInfo |
( |
| ) |
const |
Gets the size of the memory used by the bitmap.
- Returns
- The memory size of the bitmap.
◆ IsMultipassBitmap()
Bool IsMultipassBitmap |
( |
| ) |
const |
◆ SetCMAP()
If the image in the bitmap has 8-bit indexed color, this function can be used to set the palette entries.
- Note
- All four parameters must be between 0 and 255.
- Parameters
-
[in] | i | The index. 0 <= i <= 255 |
[in] | r | The red component. 0 <= r <= 255 |
[in] | g | The green component. 0 <= g <= 255 |
[in] | b | The blue component. 0 <= b <= 255 |
◆ GetImageRef()
Bool GetImageRef |
( |
SAVEBIT |
saveBit, |
|
|
Bool |
alpha, |
|
|
maxon::ImageRef & |
imageRef |
|
) |
| const |
Gets the ImageRef for a BaseBitmap. The reference is stored internally. For the same saveBit / alpha pair you will get the same reference.
- Parameters
-
[in] | saveBit | A combination of the following flags: SAVEBIT |
[in] | alpha | True, if you need the alpha image, false otherwise. |
[out] | imageRef | A reference that gets the imageRef assigned. |
- Returns
- true if the function succeeded, otherwise false.
◆ COLORPROFILE_INDEX_IMAGE
constexpr Int32 COLORPROFILE_INDEX_IMAGE |
|
staticconstexpr |
Index of the image color profile.
◆ COLORPROFILE_INDEX_RENDERSPACE
constexpr Int32 COLORPROFILE_INDEX_RENDERSPACE |
|
staticconstexpr |
Index of the renderspace color profile.
◆ COLORPROFILE_INDEX_VIEW_TRANSFORM
constexpr Int32 COLORPROFILE_INDEX_VIEW_TRANSFORM |
|
staticconstexpr |
Index of the view transform.
◆ COLORPROFILE_INDEX_DISPLAYSPACE
constexpr Int32 COLORPROFILE_INDEX_DISPLAYSPACE |
|
staticconstexpr |
Index of the displayspace color profile.