This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.bitmaps.BaseBitmap – a bitmap class

The bitmap class can be used to load, read, draw and save bitmap pictures of various formats. The constructor of BaseBitmap allows you to create a Bitmap object that contains a reference to a Bitmap object.

Note

Bitmaps are organized so that x = y = 0 is the top left corner.

class c4d.bitmaps.BaseBitmap

Methods

BaseBitmap.__init__()
Return type:BaseBitmap
Returns:The new bitmap.
BaseBitmap.__getitem__(key)

THis is similar to GetPixel(). An example:

x, y, z = bmp[5, 5] #returns the color of a pixel at position x(5), y(5)
Raises IndexError:
 Raise this error when the pixel position is out of the bitmap.
Parameter:key (int) – The pixel position.
Return type:list of int
Returns:The color of a pixel. Range between 0-255.
BaseBitmap.__setitem__(key, value)

THis is similar to GetPixel(). An example:

bmp[5, 5] = (50, 255, 50) #returns the color of a pixel at position x(5), y(5)
Raises IndexError:
 

Raise this error when the pixel position is out of the bitmap.

Parameters:
  • key (int) – The pixel position.
  • value (list of int) – The color of the pixel. Range between 0-255.
BaseBitmap.SetPixel(x, y, r, g, b)

Sets the pixel at (x, y) to the color specified by (r,g,b) (0 <= r/g/b <= 255). Similar to the __setitem__()

Parameters:
  • x (int) – The X coordinate.
  • y (int) – The Y coordinate.
  • r (int) – The red component.
  • g (int) – The green component.
  • b (int) – The blue component.
Return type:

bool

Returns:

True if successful, otherwise False.

BaseBitmap.GetPixel(x, y)

Retrieves the color at (x,y) and assigns it to the passed pointers (r,g,b) (0 <= r/g/b <= 255). Similar to the __getitem__()

Parameters:
  • x (int) – The X coordinate.
  • y (int) – The Y coordinate.
  • r (int) – The red component.
  • g (int) – The green component.
  • b (int) – The blue component.
Return type:

list of int

Returns:

The color of the pixel. Range between 0-255.

BaseBitmap.GetAlphaPixel(channel, x, y)

Get the alpha value at (x,y) to val. The valid range of val is 0 to 255.

Parameters:
  • bmp (BaseBitmap) – The alpha channels to use. Has to be an alpha bitmap.
  • x (int) – X coordinate.
  • y (int) – Y coordinate.
Return type:

int

Returns:

The alpha value.

BaseBitmap.SetAlphaPixel(channel, x, y, val)

Sets the alpha value at (x,y) to val. The valid range of val is 0 to 255.

Parameters:
  • bmp (BaseBitmap) – The alpha channels to use. Has to be an alpha bitmap.
  • x (int) – X coordinate.
  • y (int) – Y coordinate.
  • val (int) – The alpha value.
BaseBitmap.Init(x, y, depth)

Note

The bitmap class only supports up to 4 channels. Also, most image loaders will only load one alpha channel.

Initializes the bitmap to the given dimensions and depth. Any previous data in the bitmap object is lost.

Parameters:
  • x (int) – The requested width in pixels. (Max 16000 pixels.).
  • y (int) – The requested width in pixels. (Max 16000 pixels.).
  • depth (int) – The requested bit depth. The possible values are {1,4,8,16,24,32}. On some platforms 32 bits will be used even if 24 is requested, to allow for padding.
Return type:

int

Returns:

The result:

IMAGE_OK

Image loaded/created.

IMAGE_NOTEXISTING

Image doesn`t exist.

IMAGE_WRONGTYPE

Image has the wrong type.

IMAGE_NOMEM

Not enough memory.

IMAGE_DISKERROR

Disk error.

IMAGE_FILESTRUCT

Invalid file structure.

BaseBitmap.InitWith(name[, frame=-1])

Note

The bitmap class only supports up to 4 channels. Also, most image loaders will only load one alpha channel.

Loads a file into the bitmap. The file can be either a movie or a picture. The file format is automatically detected:

result, ismovie = bmp.InitWith('example_path')
if result==bitmaps.IMAGE_OK: #int check
    # picture loaded
    if ismovie==True: #bool check
        pass # file is a movie
    else:
        pass # file is no movie
Parameters:
  • name (str) – The file path.
  • frame (int) – The frame number to load in a movie.
Return type:

list

Returns:

The result for first element:

IMAGE_OK

Image loaded/created.

IMAGE_NOTEXISTING

Image doesn`t exist.

IMAGE_WRONGTYPE

Image has the wrong type.

IMAGE_NOMEM

Not enough memory.

IMAGE_DISKERROR

Disk error.

IMAGE_FILESTRUCT

Invalid file structure.

BaseBitmap.FlushAll()

Returns a bool if the object is empty. Requires a call to BaseBitmap.init() before the bitmap can be used again.

Return type:bool
Returns:True if BaseBitmap is not empty, otherwise False.
BaseBitmap.GetClone()

Clones the Bitmap and returns a new instance.

Return type:BaseBitmap
Returns:The clone.
BaseBitmap.GetClonePart(x, y, w, h)

Copies a part of the bitmap, specified by the rectangle (x,y) to (x+w,y+h).

Parameters:
  • x (int) – Upper left x coordinate of the rectangle.
  • y (int) – int
  • w (int.) – The width of the rectangle.
  • h (int) – The height of the rectangle.
Return type:

BaseBitmap or None

Returns:

The cloned bitmap, or None if an error occured.

BaseBitmap.Save(name, format[, savebits=0][, data])

Returns a bool if the object is empty. Requires a call to BaseBitmap.Init() before the bitmap can be used again:

FILTER_TIF TIF
FILTER_TGA TGA
FILTER_BMP BMP
FILTER_IFF IFF
FILTER_JPG JPG
FILTER_PICT PICT
FILTER_PSD PSD
FILTER_RLA RLA
FILTER_RPF RPF
FILTER_B3D Bodypaint
Parameters:
  • name (str) – A valid filename.
  • format (int) – The image format.
  • savebits (int) –

    Can be a combination of the following flags:

    SAVEBIT_ALPHA Save the alpha channel(s) in the file. (For filter plugins, don’t save an alpha channel if this isn’t set.)
    SAVEBIT_GREYSCALE Save in grayscale mode.
    SAVEBIT_MULTILAYER Save multiple layers.
    SAVEBIT_USESELECTEDLAYERS Use selected layers.
    SAVEBIT_16BITCHANNELS Use 16 bit channels.
    SAVEBIT_32BITCHANNELS Use 32 bit channels.
    SAVEBIT_SAVERENDERRESULT Private.
  • data (BaseContainer) – The data.
Return type:

int

Returns:

True if BaseBitmap is not empty, otherwise False.

IMAGE_OK

Image loaded/created.

IMAGE_NOTEXISTING

Image doesn`t exist.

IMAGE_WRONGTYPE

Image has the wrong type.

IMAGE_NOMEM

Not enough memory.

IMAGE_DISKERROR

Disk error.

IMAGE_FILESTRUCT

Invalid file structure.

BaseBitmap.GetChannelCount()

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

Return type:int
Returns:Number of alpha channels.
BaseBitmap.Within(x, y)

Checks if a position is in the bitmap.

Parameters:
  • x (int) – The X Coordinate
  • y (int) – The Y Coordinate
Return type:

bool

Returns:

True if the coordinate is in the bitmap.

BaseBitmap.GetSize()

Returns the size of the bitmap in pixels. If the bitmap hasn’t been initialized the return values are 0. (This is the only way to see if a bitmap has been initialized.):

#bmp is a BaseBitmap instance
x, y = bmp.get_size()
Return type:list of int
Returns:Bitmap width and height in pixels, or 0 if the bitmap isn’t initialized.
BaseBitmap.GetBw()

Returns the width of the bitmap in pixels. If the bitmap hasn’t been initialized the return value is 0. (This is the only way to see if a bitmap has been initialized.)

Return type:int
Returns:Bitmap width in pixels, or 0 if the bitmap isn’t initialized.
BaseBitmap.GetBh()

Returns the height of the bitmap in pixels.

Return type:int
Returns:Bitmap height in pixels.
BaseBitmap.GetBt()

Returns the number of bits per pixel.

Return type:int
Returns:The number of bits.
BaseBitmap.SetCMAP(i, r, g, b)

If the image in the bitmap has 8 bit indexed color, this function can be used to set the palette entries. All four parameters must be between 0 and 255.

Parameters:
  • i (int) – The index.
  • r (int) – The red component.
  • g (int) – The green component.
  • b (int) – The blue component.
BaseBitmap.GetBpz()

Returns the number of bytes per line.

Return type:int
Returns:Number of bytes per line.
BaseBitmap.SetData(id, data)

Returns the height of the bitmap in pixels.

Parameters:
  • id (int) –

    The data to set:

    BASEBITMAP_DATA_GAMMA Gamma
    BASEBITMAP_DATA_EXPOSURE Exposure
    BASEBITMAP_DATA_TARGETGAMMA Target gamma
  • data (float) – The data
Return type:

bool

Returns:

True if the data could be set, otherwise False.

BaseBitmap.GetData(id, default)

Gets bitmap data.

Parameters:
  • id (int) –

    The data to get:

    BASEBITMAP_DATA_GAMMA Gamma
    BASEBITMAP_DATA_EXPOSURE Exposure
    BASEBITMAP_DATA_TARGETGAMMA Target gamma
  • default (any) – Returns default if value is not set.
Return type:

float or type(default)

Returns:

the retrieved data, or default.

BaseBitmap.ScaleBicubic(dest, src_xmin, src_ymin, src_xmax, src_ymax, dst_xmin, dst_ymin, dst_xmax, dst_ymax)

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 needs to be initialized before calling this function.

Note

This function can currently only scale down, i.e. the destination needs to be smaller or equal to the source in size.

Parameters:
  • dest (BaseBitmap) – The destination bitmap.
  • src_xmin (int) – Source top left X coordinate.
  • src_ymin (int) – Source top left Y coordinate.
  • src_xmax (int) – Source bottom right X coordinate.
  • src_ymax (int) – Source bottom right Y coordinate.
  • dst_xmin (int) – Destination top left X coordinate.
  • dst_ymin (int) – Destination top left Y coordinate.
  • dst_xmax (int) – Destination bottom right X coordinate.
  • dst_ymax (int) – Destination bottom right Y coordinate.
BaseBitmap.Scale(intens, sample, inprop)

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

../../../_images/scaleit.jpg
Parameters:
  • intens (int) – Lets you change brightness of the image (128 = 50% brightness, 256 = unchanged).
  • sample (bool) – If True a better scaling algorithm is used, which results in a better quality but is a bit slower.
  • inprop (bool) – Must be True if non-proportional scaling is wanted.
Return type:

BaseBitmap

Returns:

The scaled bitmap.

BaseBitmap.AddChannel(internal, straight)

Adds a new alpha channel to the image.

Parameters:
  • internal (bool) – Should only be True for the first alpha. The internal alpha will be stored within an image if the image format supports alphas.
  • straight (bool) – Should be True if the image has to be interpreted as straight. For information about straight alphas please take a look at the corresponding option in the render settings of CINEMA 4D and the CINEMA 4D manual.
Return type:

int

Returns:

The new channel.

BaseBitmap.RemoveChannel(channel)

Removes the specified channel from the bitmap.

Parameter:channel (BaseBitmap) – The alpha channels to use.
BaseBitmap.GetChannelNum(num)

Returns the channel ID from the channel index.

Parameters:
  • num (int) – A number between 0 and BaseBitmap.get_channel_count().
  • channel (BaseBitmap) – The requested channel.
BaseBitmap.GetDirty()

Private.

Return type:int
Returns:Dirty count, incremented when the bitmap changes.
BaseBitmap.SetDirty()
Makes the bitmap dirty.
BaseBitmap.IsMultipassBitmap()

Checks if the image is a MultipassBitmap.

Return type:bool
Returns:True if the image is a MultipassBitmap, otherwise False
BaseBitmap.GetColorMode()

Returns the color mode of the bitmap.

Return type:

int

Returns:

Color mode

MODE_ALPHA

Only 8-bit alpha channel.

MODE_GREY8

8-bit greyscale channel.

MODE_GREYA8

8-bit greyscale channel with 8-bit alpha.

MODE_RGB

8-bit RGB channels.

MODE_RGBA

8-bit RGB channels with 8-bit alpha.

MODE_CMYK

8-bit CMYK channel.

MODE_CMYKA

8-bit CMYK channel with 8-bit alpha.

MODE_MASK

8-bit greymap as mask.

MODE_GREYw

8-bit greymap as mask with 8-bit alpha.

MODE_GREYAw

16-bit greyscale channel with 16-bit alpha.

MODE_RGBw

16-bit RGB channels.

MODE_RGBAw

16-bit RGB channels with 16-bit alpha.

MODE_GREYf

Floating point greyscale channel.

MODE_GREYAf

Floating point greyscale channel with floating point alpha.

MODE_RGBf

Floating point RGB channels.

MODE_RGBAf

Floating point RGB channels with floating point alpha.

BaseBitmap.GetLine([mode=DEZ_MODE])

Returns a line of pixels.

Parameter:mode (int) – The mode. Currently only DEZ_MODE is avaible.
Return type:list of type Vector
Returns:The element count is equal to get_width
BaseBitmap.GetMemoryInfo()

Get the size of the memory used by the bitmap.

Return type:long
Returns:Memory size of the bitmap.
BaseBitmap.GetUpdateRegionBitmap()

Get the updated region of a bitmap.

Return type:BaseBitmap
Returns:The updated region.

Table Of Contents

This Page