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 ALIASES image classes see Images Manual. For MAXON API ALIASES 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:
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
@ OK
Image loaded/created.
void SetDirty()
Makes the bitmap dirty. Private.
Definition: c4d_basebitmap.h:846
static const ColorProfile * GetDefaultLinearRGB()
@ ALPHA
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:511
#define NewMemClear(T, cnt)
Definition: defaultallocator.h:204
void Arc(Int32 x, Int32 y, Float radius, Float angle_start, Float angle_end, Int32 subdiv=32)
Definition: c4d_basebitmap.h:670
Bool SetAlphaPixel(BaseBitmap *channel, Int32 x, Int32 y, Int32 val)
Definition: c4d_basebitmap.h:726
void SetInt32(Int32 id, Int32 l)
Definition: c4d_basecontainer.h:505
maxon::UInt32 UInt32
Definition: ge_sys_math.h:61
#define JPGSAVER_QUALITY
Quality of JPEG images. A value between 0 (lowest) and 100 (highest).
Definition: ge_prepass.h:237
maxon::Float Float
Definition: ge_sys_math.h:66
maxon::Float32 Float32
Definition: ge_sys_math.h:68
void Clear(Int32 r, Int32 g, Int32 b)
Manages file and path names.
Definition: c4d_file.h:93
return OK
Definition: apibase.h:2620
@ NONE
No check if file exists under case-sensitive drives.
#define iferr_return
Definition: resultbase.h:1465
UInt32 GetDirty() const
Definition: c4d_basebitmap.h:841
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
static void Free(BaseBitmap *&bm)
@ BFH_SCALEFIT
Scale fit. BFH_SCALE|BFH_FIT.
Definition: gui.h:315
#define BASEBITMAP_DATA_GUIPIXELRATIO
Float.
Definition: c4d_basebitmap.h:97
@ DOCUMENT_LINEARWORKFLOW
Definition: ddoc.h:62
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:86
Int32 GetLayerCount() const
Definition: c4d_basebitmap.h:988
maxon::UChar UChar
Definition: ge_sys_math.h:57
Int32 GetBw(void) const
Definition: c4d_basebitmap.h:554
BaseBitmap * AddChannel(Bool internal, Bool straight)
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
String GetString(void) const
@ BMP_APPLY_COLORPROFILE
Applies the color profile.
Definition: gui.h:176
Definition: c4d_string.h:38
void Line(Int32 x1, Int32 y1, Int32 x2, Int32 y2)
Definition: c4d_basebitmap.h:659
static String IntToString(Int32 v)
Definition: c4d_string.h:495
const BaseContainer & GetDataInstanceRef() const
Definition: c4d_baselist.h:2329
Bool SetPixel(Int32 x, Int32 y, Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:708
static const ColorProfile * GetDefaultSRGB()
Definition: c4d_basebitmap.h:943
COLORMODE
Definition: ge_prepass.h:447
void DeleteMem(T *&p)
Definition: defaultallocator.h:257
BaseBitmap * GetClonePart(Int32 x, Int32 y, Int32 w, Int32 h) const
Int32 GetBh(void) const
Definition: c4d_basebitmap.h:560
#define FILTER_PNG
PNG.
Definition: ge_prepass.h:196
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
Bool SetData(Int32 id, const GeData &data)
Bool ShowBitmap(const Filename &fn)
Bool GetBool(Int32 id, Bool preset=false) const
Definition: c4d_basecontainer.h:295
void SetPen(Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:625
@ RGBf
32-bit floating point RGB channels.
#define FILTER_JPG
JPEG.
Definition: ge_prepass.h:183
Definition: c4d_basebitmap.h:414
A simple BaseBitmap wrapper created from a filename or resource ID.
Definition: c4d_basebitmap.h:1505
Definition: ge_autoptr.h:36
Float32 PIX_F
32-bit float pixel type.
Definition: ge_math.h:34
Bool SetPixelCnt(Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE srcmode, PIXELCNT flags)
Definition: c4d_basebitmap.h:754
void GetPixelCnt(Int32 x, Int32 y, Int32 cnt, UChar *buffer, Int32 inc, COLORMODE dstmode, PIXELCNT flags, ColorProfileConvert *conversion=nullptr) const
Definition: c4d_basebitmap.h:741
Filename GeFilterSetSuffix(const Filename &name, Int32 id)
UChar PIX
8-bit integer pixel type.
Definition: ge_math.h:31
Bool CheckSuffix(const maxon::String &str) const
maxon::Bool Bool
Definition: ge_sys_math.h:55
Definition: c4d_tools.h:811
IMAGERESULT
Definition: ge_prepass.h:3730
IMAGERESULT Save(const Filename &name, Int32 format, BaseContainer *data, SAVEBIT savebits) const
COLORMODE GetColorMode(void) const
Int32 GetBt(void) const
Definition: c4d_basebitmap.h:566
Definition: c4d_basecontainer.h:46
Int32 GetBpz(void) const
Definition: c4d_basebitmap.h:572
Float32 DegToRad(Float32 r)
Definition: apibasemath.h:247
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())