About
A BaseBitmap object stores raster graphics image data. It can support multiple alpha channels. The BaseBitmap class is used in many different application areas inside Cinema 4D . An extensions of this class is MultipassBitmap which also supports multiple layers (see MultipassBitmap Manual ).
Warning For MAXON API image classes see Images Manual . For MAXON API media input and output see Media Sessions Manual .
Allocation/Deallocation
A BaseBitmap can be created with the usual tools:
After the BaseBitmap was created it has to be initiated with BaseBitmap::Init() . This can be done by
defining the dimensions of the new BaseBitmap
or by defining the file name of an image file to load
Also a static version of BaseBitmap::Init() exists that loads a image defined by a Filename into a given BaseBitmap object.
if (bitmap == nullptr )
const Int32 width = 1920;
const Int32 height = 1080;
for (
Int32 x = 0; x < width; ++x)
{
for (
Int32 y = 0; y < height; ++y)
{
bitmap->
SetPixel (x, y, red, green, blue);
}
}
AutoBitmap can be used to create a BaseBitmap from an image file in the plugin resource path or a resource ID. This is typically used in a "Register" function, see Registration .
if (bitmap == nullptr )
if (localIcon == nullptr )
Copy
The content of a BaseBitmap can be copied and with these functions:
const Int32 width = sourceBitmap->GetBw();
const Int32 height = sourceBitmap->GetBh();
const Int32 leftHalfWidth = width / 2;
if (leftBitmap == nullptr )
const Int32 rightHalfWidth = width - leftHalfWidth;
if (rightBitmap == nullptr )
Read-Only Properties
The basic properties of a BaseBitmap are accessed with:
const Int32 bytesPerPixel = bitsPerPixel / 8;
for (
Int32 y = 0; y <= height; ++y)
{
InvertLineRGB(lineBuffer, width);
}
The used color profile is managed with:
See also ColorProfile and ColorProfileConvert .
if (linearWorkflow)
else
DrawBitmap(_bitmap, 0, 0, width, height, 0, 0, width, height, drawMode);
Functionality
Bitmap
The content of a BaseBitmap can be scaled into another BaseBitmap :
Warning MultipassBitmap overwrites these functions. The overwritten functions will scale the layers but not the alpha channels.
if (scaledBitmap == nullptr )
const Int32 originalWidth = sourceBitmap->GetBw();
const Int32 originalHeight = sourceBitmap->GetBh();
const Int32 scaledWidth = originalWidth * scale;
const Int32 scaledHeight = originalHeight * scale;
const Int32 defaultBrightness = 256;
sourceBitmap->ScaleIt(scaledBitmap, defaultBrightness, true , false );
One can perform basic drawing operations with these functions:
Note For more advanced drawing operations use a GeClipMap , see GeClipMap Manual .
bitmap->
Clear (255, 255, 255);
bitmap->
Line (100, 100, 300, 100);
bitmap->
Line (100, 200, 300, 200);
bitmap->
Arc (300, 150, 50.0, quarterCircle, -quarterCircle, 20);
bitmap->
Arc (100, 150, 50.0, quarterCircle, threeQuarterCircle, 20);
Properties
A BaseBitmap is used as the target buffer of a rendering process. Details of that rendering process are stored with the bitmap itself and are displayed by the Picture Viewer. So these settings are mostly only relevant to the rendering pipeline were the given VPBuffer can be cast into a BaseBitmap / MultipassBitmap .
The settings are:
if (bitmapButtonGUI)
{
if (bitmap)
{
const Float pixelRatio = GetPixelRatio();
if (pixelRatio == 1.0)
filename = "lowRes.png" ;
else
filename = "highRes.png" ;
const String fullFileName = GetFullFilename(filename);
{
bitmapButtonGUI->
SetImage (bitmap,
true ,
false );
}
}
}
Dirty
A BaseBitmap stores an incremental dirty state that is used in some scenarios to indicate that the BaseBitmap has changed.
bitmap->
Clear (255, 255, 255);
Pixel Data
The internally stored bitmap data of a BaseBitmap can be accessed with:
Typically used pixel formats can be defined with:
PIX : 8-bit integer pixel type.
PIX_C : 8-bit integer pixel type.
PIX_W : 16-bit integer pixel type.
PIX_F : 32-bit float pixel type.
See also COLORBYTES for macros defining bytes per pixel and ::COLORMODE for a definition of the color mode.
if (bitmap == nullptr )
const Int32 width = 1024;
const Int32 height = 1024;
const Int32 pixelBits = pixelBytes * 8;
const Int32 bufferSize = width * 3;
for (
Int32 y = 0; y <= height; ++y)
{
for (
Int32 x = 0; x < width; ++x)
{
lineBuffer[offset] = red;
lineBuffer[offset + 1] = green;
lineBuffer[offset + 2] = 0.0;
offset += 3;
}
}
Alpha Channels
A BaseBitmap can contain up to four alpha channels. They are represented also with BaseBitmap instances:
bitmap->
Clear (255, 255, 255);
if (alphaChannel)
for (
Int32 x = 0; x < width; ++x)
{
for (
Int32 y = 0; y < height; ++y)
{
const Int32 alphaValueInt =
Int32 (alphaValueFloat);
}
}
Convert
BaseBitmap is the base class of MultipassBitmap . If a pointer to a BaseBitmap is handed over one can check if it is actually a MultipassBitmap :
{
MultipassBitmap *
const multipassBitmap = static_cast<MultipassBitmap*>(bitmap);
}
else
{
}
A BaseBitmap also represents a maxon::ImageRef. This is obtained with:
Disc I/O
A BaseBitmap can read the content of an image file and save its content to an image file.
if (bitmap == nullptr )
{
Filename jpgFileName = selectedImageFile;
}
{
Filename pngFileName = selectedImageFile;
}
Note An alternative way of loading image files is to use SendPainterCommand() with PAINTER_LOADTEXTURE .
A BaseBitmap can also be stored in a HyperFile using:
Display
A BaseBitmap or MultipassBitmap can easily displayed in the Picture Viewer:
Further Reading
Bool IsMultipassBitmap(void) const
void SetDirty()
Makes the bitmap dirty. Private.
Definition: c4d_basebitmap.h:827
static const ColorProfile * GetDefaultLinearRGB()
Save the alpha channel(s) in the file. (For filter plugins, do not save an alpha channel if this is n...
static String UIntToString(UInt32 v)
Definition: c4d_string.h:509
#define NewMemClear(T, cnt)
Definition: defaultallocator.h:205
void Arc(Int32 x, Int32 y, Float radius, Float angle_start, Float angle_end, Int32 subdiv=32)
Definition: c4d_basebitmap.h:661
Bool SetAlphaPixel(BaseBitmap *channel, Int32 x, Int32 y, Int32 val)
Definition: c4d_basebitmap.h:707
void SetInt32(Int32 id, Int32 l)
Definition: c4d_basecontainer.h:501
maxon::UInt32 UInt32
Definition: ge_sys_math.h:46
#define JPGSAVER_QUALITY
Quality of JPEG images. A value between 0 (lowest) and 100 (highest).
Definition: ge_prepass.h:232
maxon::Float Float
Definition: ge_sys_math.h:51
Applies the color profile.
Definition: gui.h:169
maxon::Float32 Float32
Definition: ge_sys_math.h:53
void Clear(Int32 r, Int32 g, Int32 b)
Manages file and path names.
Definition: c4d_file.h:81
return OK
Definition: apibase.h:2462
No check if file exists under case-sensitive drives.
#define iferr_return
Definition: resultbase.h:1419
UInt32 GetDirty() const
Definition: c4d_basebitmap.h:822
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
static void Free(BaseBitmap *&bm)
#define BASEBITMAP_DATA_GUIPIXELRATIO
Float.
Definition: c4d_basebitmap.h:92
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)
#define COLORBYTES_RGBf
Floating point RGB.
Definition: c4d_basebitmap.h:81
Int32 GetLayerCount() const
Definition: c4d_basebitmap.h:959
maxon::UChar UChar
Definition: ge_sys_math.h:42
Int32 GetBw(void) const
Definition: c4d_basebitmap.h:545
BaseBitmap * AddChannel(Bool internal, Bool straight)
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
String GetString(void) const
Definition: c4d_string.h:36
void Line(Int32 x1, Int32 y1, Int32 x2, Int32 y2)
Definition: c4d_basebitmap.h:650
static String IntToString(Int32 v)
Definition: c4d_string.h:493
const BaseContainer & GetDataInstanceRef() const
Definition: c4d_baselist.h:2240
Bool SetPixel(Int32 x, Int32 y, Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:689
static const ColorProfile * GetDefaultSRGB()
Definition: c4d_basebitmap.h:914
COLORMODE
Definition: ge_prepass.h:435
void DeleteMem(T *&p)
Definition: defaultallocator.h:258
BaseBitmap * GetClonePart(Int32 x, Int32 y, Int32 w, Int32 h) const
Int32 GetBh(void) const
Definition: c4d_basebitmap.h:551
#define FILTER_PNG
PNG.
Definition: ge_prepass.h:191
Scale fit. BFH_SCALE|BFH_FIT.
Definition: gui.h:305
maxon::Int32 Int32
Definition: ge_sys_math.h:45
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:209
Bool SetData(Int32 id, const GeData &data)
Bool ShowBitmap(const Filename &fn)
Bool GetBool(Int32 id, Bool preset=false) const
Definition: c4d_basecontainer.h:291
void SetPen(Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:616
32-bit floating point RGB channels.
#define FILTER_JPG
JPEG.
Definition: ge_prepass.h:178
Definition: c4d_basebitmap.h:405
A simple BaseBitmap wrapper created from a filename or resource ID.
Definition: c4d_basebitmap.h:1476
Definition: ge_autoptr.h:32
Float32 PIX_F
32-bit float pixel type.
Definition: ge_math.h:19
Bool SetPixelCnt(Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE srcmode, PIXELCNT flags)
Definition: c4d_basebitmap.h:735
void GetPixelCnt(Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE dstmode, PIXELCNT flags, ColorProfileConvert *conversion=nullptr) const
Definition: c4d_basebitmap.h:722
Filename GeFilterSetSuffix(const Filename &name, Int32 id)
UChar PIX
8-bit integer pixel type.
Definition: ge_math.h:16
Bool CheckSuffix(const maxon::String &str) const
maxon::Bool Bool
Definition: ge_sys_math.h:40
Definition: c4d_tools.h:807
IMAGERESULT
Definition: ge_prepass.h:3550
IMAGERESULT Save(const Filename &name, Int32 format, BaseContainer *data, SAVEBIT savebits) const
COLORMODE GetColorMode(void) const
Int32 GetBt(void) const
Definition: c4d_basebitmap.h:557
Definition: c4d_basecontainer.h:42
Int32 GetBpz(void) const
Definition: c4d_basebitmap.h:563
Float32 DegToRad(Float32 r)
Definition: apibasemath.h:271
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())