BaseBitmap Class Reference

#include <c4d_basebitmap.h>

Public Attributes

void * unknownBitmapData
 
Int unknownBitmapSize
 

Protected Member Functions

IMAGERESULT Init (void *mem, Int size)
 
void _Free ()
 
virtual IMAGERESULT _Init (Int32 x, Int32 y, Int32 t, DrawPortTypes type=DpRegular, void *data=nullptr)
 
Bool Check (const Vector &v) const
 
Bool Check (Int32 x1, Int32 y1) const
 
Bool Check (Int32 x1, Int32 y1, Int32 x2, Int32 y2) const
 

Protected Attributes

CHANNEL Channels [4]
 

Private Attributes

DrawPortdp
 
COLORMODE colormode
 

Friends

class HyperFile
 
class BaseMaterial
 
class SkyObjects
 
class iMatPreviewData
 
class JpgLoader
 
class BmpLoader
 

Constructor/Destructor

 BaseBitmap ()
 
virtual ~BaseBitmap ()
 

Alloc/Free

static BaseBitmapAlloc ()
 
static void Free (BaseBitmap *&bm)
 

Init/Load/Save

virtual IMAGERESULT Init (Int32 x, Int32 y, Int32 depth=24, INITBITMAPFLAGS flags=INITBITMAPFLAGS_0)
 
IMAGERESULT Load (const Filename &name, Int32 format, BaseContainer *data, Int32 frame)
 
IMAGERESULT Save (const Filename &name, Int32 format, BaseContainer *data, SAVEBIT savebits)
 

Bitmap Dimension/Information

Int32 GetBw () const
 
Int32 GetBh () const
 
Int32 GetBt () const
 
COLORMODE GetColorMode ()
 

Clone/Copy/Scale

Bool CloneIt (BaseBitmap *dest) const
 
BaseBitmapGetClone ()
 
Bool CopyPart (BaseBitmap *dest, Int32 x, Int32 y, Int32 w, Int32 h, Bool no_reallocation) const
 
void ScaleIt (BaseBitmap *dest, Int32 hell, Bool sample, Bool nprop=false, Bool disable_gamma=false) const
 

Set/Get Pixels

Bool SetPixel (Int32 x, Int32 y, Int32 red, Int32 green, Int32 blue, Int32 alpha=0)
 
void GetPixel (Int32 x, Int32 y, UInt16 *red, UInt16 *green, UInt16 *blue) const
 
Vector GetRGB (Int32 x, Int32 y)
 
virtual Bool SetAlphaPixel (BaseBitmap *channel, Int32 x, Int32 y, Int32 val)
 
virtual void GetAlphaPixel (BaseBitmap *channel, Int32 x, Int32 y, UInt16 *val) const
 
Bool SetPixelCnt (Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE srcmode, PIXELCNT flags)
 
virtual void GetPixelCnt (Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE dstmode, PIXELCNT flags, ColorProfileConvert *conversion=nullptr) const
 
virtual Bool SetAlphaPixelCnt (Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, BaseBitmap *channel)
 
virtual void GetAlphaPixelCnt (Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, BaseBitmap *channel) const
 
Bool SetLineDirect (Int32 y, void *data, Int32 depth)
 

Channel

virtual BaseBitmapAddChannel (Bool internal, Bool straight=false)
 
virtual void RemoveChannel (BaseBitmap *channel)
 
virtual BaseBitmapGetInternalChannel () const
 
virtual Int32 GetChannelCount () const
 
virtual BaseBitmapGetChannelNum (Int32 num) const
 

Detailed Description

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(Int32 x, Int32 y, Int32 depth = 24, INITBITMAPFLAGS flags = INITBITMAPFLAGS_0) before attempting to use a newly allocated bitmap.

Constructor & Destructor Documentation

◆ BaseBitmap()

Default constructor.

◆ ~BaseBitmap()

virtual ~BaseBitmap ( )
virtual

Default destructor.

Member Function Documentation

◆ Init() [1/2]

IMAGERESULT Init ( void *  mem,
Int  size 
)
protected

Private. Internal.

◆ _Free()

void _Free ( )
protected

Private. Internal.

◆ _Init()

virtual IMAGERESULT _Init ( Int32  x,
Int32  y,
Int32  t,
DrawPortTypes  type = DpRegular,
void *  data = nullptr 
)
protectedvirtual

Private. Internal.

◆ Check() [1/3]

Bool Check ( const Vector v) const
protected

Private. Internal.

◆ Check() [2/3]

Bool Check ( Int32  x1,
Int32  y1 
) const
protected

Private. Internal.

◆ Check() [3/3]

Bool Check ( Int32  x1,
Int32  y1,
Int32  x2,
Int32  y2 
) const
protected

Private. Internal.

◆ Alloc()

static BaseBitmap* Alloc ( )
static

Allocates a bitmap. Destroy the allocated bitmap with Free().

Since
R20
Returns
The allocated bitmap, or nullptr if the allocation failed.

◆ Free()

static void Free ( BaseBitmap *&  bm)
static

Destructs bitmaps allocated with Alloc().

Since
R20
Parameters
[in,out]bmThe bitmap to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ Init() [2/2]

virtual IMAGERESULT Init ( Int32  x,
Int32  y,
Int32  depth = 24,
INITBITMAPFLAGS  flags = INITBITMAPFLAGS_0 
)
virtual

Initializes the bitmap to the given [x,y] dimensions and depth.

Warning
Any previous data in the bitmap object is lost.
Parameters
[in]xThe requested width in pixels (Maximum 16 000 pixels).
[in]yThe requested height in pixels (Max. 16000 pixels).
[in]depthThe 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]flagsThe initialization flags.
Returns
The image result.

◆ Load()

IMAGERESULT Load ( const Filename name,
Int32  format,
BaseContainer data,
Int32  frame 
)

Loads the bitmap from a file.

Parameters
[in]nameA valid filename that can either refer a movie or a picture.
[in]formatThe image format.
[in]dataSome formats provide additional settings. Can be nullptr, which means the same as an empty container. The caller owns the pointed container.
[in]frameThe frame number to load in a movie.
Returns
The image result.

◆ Save()

IMAGERESULT Save ( const Filename name,
Int32  format,
BaseContainer data,
SAVEBIT  savebits 
)

Saves the bitmap to a file.

Parameters
[in]nameA valid filename that can either refer a movie or a picture.
[in]formatThe image format.
[in]dataSome formats provide additional settings. Can be nullptr, which means the same as an empty container. The caller owns the pointed container.
[in]savebitsA combination of the following flags.
Returns
The image result.

◆ GetBw()

Int32 GetBw ( ) const

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()

Int32 GetBh ( ) const

Gets the height of the bitmap in pixels.

Returns
The bitmap height in pixels.

◆ GetBt()

Int32 GetBt ( ) const

Gets the number of bits per pixel.

Returns
The number of bits per pixel.

◆ GetColorMode()

COLORMODE GetColorMode ( )

Gets the color mode of the bitmap.

Returns
The color mode: COLORMODE

◆ CloneIt()

Bool CloneIt ( BaseBitmap dest) const

Copies the bitmap.

Parameters
[out]destThe cloned bitmap, or nullptr if an error occurred. The caller owns the pointed bitmap.
Returns
true if the bitmap was successfully cloned and assigned to dest, otherwise false.

◆ GetClone()

BaseBitmap* GetClone ( )

Copies the bitmap.

Returns
The cloned bitmap, or nullptr if an error occurred. The caller owns the pointed bitmap.

◆ CopyPart()

Bool CopyPart ( BaseBitmap dest,
Int32  x,
Int32  y,
Int32  w,
Int32  h,
Bool  no_reallocation 
) const

Copies part of the bitmap to dest.

Parameters
[out]destThe bitmap to copy the bitmap to. The caller owns the pointed bitmap.
[in]xThe X position of the bitmap part to be copied.
[in]yThe Y position of the bitmap part to be copied.
[in]wThe width of the bitmap part to be copied.
[in]hThe height of the bitmap part to be copied.
[in]no_reallocationPass true if dest is an already initialized bitmap with width and height equal to w and h. Faster without initialization/allocation.
Returns
true if the bitmap part was successfully copied, otherwise false.

◆ ScaleIt()

void ScaleIt ( BaseBitmap dest,
Int32  hell,
Bool  sample,
Bool  nprop = false,
Bool  disable_gamma = false 
) const

Scales the bitmap to fit in the destination bitmap and copies it there.
The destination bitmap dest needs to be initialized with the destination size before calling this function.

Parameters
[out]destThe destination bitmap. The caller owns the pointed bitmap.
[in]hellLets you change brightness of the image (128 = 50% brightness, 256 = unchanged).
[in]sampleIf true a better scaling algorithm is used, which results in a better quality but a bit slower.
[in]npropMust be true if non-proportional scaling is wanted.
[in]disable_gammaPass true to disable gamma correction.

◆ SetPixel()

Bool SetPixel ( Int32  x,
Int32  y,
Int32  red,
Int32  green,
Int32  blue,
Int32  alpha = 0 
)

Sets the pixel at [x,y] to the color specified by (red,green,blue) (0 <= red/green/blue <= 255). The alpha value for the pixel can also be set.
The range of the red, green, blue and alpha parameters is 0 to 255, where (255,255,255) is white or opaque, regardless of the bit depth of the image.

Parameters
[in]xThe X coordinate.
[in]yThe Y coordinate.
[in]redThe red component.
[in]greenThe green component.
[in]blueThe blue component.
[in]alphaThe alpha.
Returns
true if the pixel was successfully set, otherwise false.

◆ GetPixel()

void GetPixel ( Int32  x,
Int32  y,
UInt16 red,
UInt16 green,
UInt16 blue 
) const

Gets the color at [x,y] and assigns it to the passed (red,green,blue) parameters.
The range of the assigned red, green and blue parameters is 0 to 255, where (255,255,255) is white, regardless of the bit depth of the image.

Parameters
[in]xThe X coordinate.
[in]yThe Y coordinate.
[out]redAssigned the red component.
[out]greenAssigned the green component.
[out]blueAssigned the blue component.

◆ GetRGB()

Vector GetRGB ( Int32  x,
Int32  y 
)

Gets the color at [x,y] as RGB Vector.

Parameters
[in]xThe X coordinate.
[in]yThe Y coordinate.

◆ SetAlphaPixel()

virtual Bool SetAlphaPixel ( BaseBitmap channel,
Int32  x,
Int32  y,
Int32  val 
)
virtual

Sets the alpha value at [x,y] to val.

Parameters
[in]channelThe alpha channel to use.
[in]xThe X coordinate.
[in]yThe Y coordinate.
[in]valThe alpha value. 0 <= val <= 255

◆ GetAlphaPixel()

virtual void GetAlphaPixel ( BaseBitmap channel,
Int32  x,
Int32  y,
UInt16 val 
) const
virtual

Gets the alpha value at [x,y] and assigns it to the passed parameter val (0 <= val <= 255).

Parameters
[in]channelThe alpha channel to use.
[in]xThe X coordinate.
[in]yThe Y coordinate.
[out]valAssigned the alpha value.

◆ SetPixelCnt()

Bool SetPixelCnt ( Int32  x,
Int32  y,
Int32  cnt,
UChar buffer,
Int32  inc,
COLORMODE  srcmode,
PIXELCNT  flags 
)

Sets cnt pixels at [x,y] in the bitmap from buffer with color mode srcmode, incrementing inc bytes for each pixel.

Parameters
[in]xThe X coordinate of the first pixel to set.
[in]yThe Y coordinate of the first pixel to set.
[in]cntThe number of pixels to set.
[in]bufferA pointer to a large enough memory buffer containing the pixels to set. The caller owns the pointed buffer.
[in]incThe byte increment per pixel in the buffer.
[in]srcmodeThe source color mode. Warning: None of the alpha modes are supported.
[in]flagsThe flags.
Returns
true if successful, otherwise false.

◆ GetPixelCnt()

virtual void GetPixelCnt ( Int32  x,
Int32  y,
Int32  cnt,
UChar buffer,
Int32  inc,
COLORMODE  dstmode,
PIXELCNT  flags,
ColorProfileConvert conversion = nullptr 
) const
virtual

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]xThe X coordinate of the first pixel to get.
[in]yThe Y coordinate of the first pixel to get.
[in]cntThe number of pixels to get.
[out]bufferA pointer to a large enough memory buffer where the pixel data will be written. The caller owns the pointed buffer.
[in]incThe byte increment per pixel in the buffer.
[in]dstmodeThe destination color mode.
[in]flagsThe flags.
[in]conversionThis 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).

◆ SetAlphaPixelCnt()

virtual Bool SetAlphaPixelCnt ( Int32  x,
Int32  y,
Int32  cnt,
UChar buffer,
Int32  inc,
BaseBitmap channel 
)
virtual

Sets cnt alpha pixels at [x,y] in the bitmap channel from buffer incrementing inc bytes for each pixel.

Parameters
[in]xThe X coordinate of the first pixel to set.
[in]yThe Y coordinate of the first pixel to set.
[in]cntThe number of pixels to set.
[in]bufferA pointer to a large enough memory buffer containing the alpha values to set. The caller owns the pointed buffer.
[in]incThe byte increment per pixel in the buffer.
[in]channelThe channel to set the alpha values. The caller owns the pointed bitmap.
Returns
true if successful, otherwise false.

◆ GetAlphaPixelCnt()

virtual void GetAlphaPixelCnt ( Int32  x,
Int32  y,
Int32  cnt,
UChar buffer,
Int32  inc,
BaseBitmap channel 
) const
virtual

Reads cnt alpha pixels from [x,y] in the bitmap channel to the buffer incrementing inc bytes for each pixel.

Parameters
[in]xThe X coordinate of the first pixel to get.
[in]yThe Y coordinate of the first pixel to get.
[in]cntThe number of pixels to get.
[out]bufferA pointer to a large enough memory buffer where the pixel data will be written. The caller owns the pointed buffer.
[in]incThe byte increment per pixel in the buffer.
[in]channelThe channel to get the alpha values. The caller owns the pointed bitmap.

◆ SetLineDirect()

Bool SetLineDirect ( Int32  y,
void *  data,
Int32  depth 
)

Sets all line pixels at y in the bitmap from data.

Parameters
[in]yThe Y coordinate of the line to set.
[in]dataA pointer to a large enough memory buffer containing the pixels to set. The caller owns the pointed buffer.
[in]depthThe 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.
Returns
true if successful, otherwise false.

◆ AddChannel()

virtual BaseBitmap* AddChannel ( Bool  internal,
Bool  straight = false 
)
virtual

Adds a new alpha channel to the bitmap.

Note
The bitmap class only supports up to 4 channels.
Parameters
[in]internalShould only be true for the first alpha. The internal alpha will be stored within a bitmaps if its format supports alphas.
[in]straightShould 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()

virtual void RemoveChannel ( BaseBitmap channel)
virtual

Removes the specified channel from the bitmap.

Parameters
[in]channelThe alpha channel to remove.

◆ GetInternalChannel()

virtual BaseBitmap* GetInternalChannel ( ) const
virtual

Gets the internal read-only alpha channel.
The internal alpha channel is the one that is saved together with the picture, with those formats that support this. If no internal alpha is available, nullptr is returned.

Returns
The read-only internal alpha channel, or nullptr if no internal alpha is available. The bitmap owns the pointed channel.

◆ GetChannelCount()

virtual Int32 GetChannelCount ( ) const
virtual

Gets the number of alpha channels in the bitmap, including the internal channel.

Returns
The number of alpha channels.

◆ GetChannelNum()

virtual BaseBitmap* GetChannelNum ( Int32  num) const
virtual

Gets the alpha channel specified by num.

Parameters
[in]numAn alpha channel index between 0 and GetChannelCount().
Returns
The requested channel.

Friends And Related Function Documentation

◆ HyperFile

friend class HyperFile
friend

◆ BaseMaterial

friend class BaseMaterial
friend

◆ SkyObjects

friend class SkyObjects
friend

◆ iMatPreviewData

friend class iMatPreviewData
friend

◆ JpgLoader

friend class JpgLoader
friend

◆ BmpLoader

friend class BmpLoader
friend

Member Data Documentation

◆ dp

DrawPort* dp
private

Private. Internal.

◆ colormode

COLORMODE colormode
private

Private. Internal.

◆ Channels

CHANNEL Channels[4]
protected

Private. Internal.

◆ unknownBitmapData

void* unknownBitmapData

Private. Internal.

◆ unknownBitmapSize

Int unknownBitmapSize

Private. Internal.