CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::Bitmap Class Reference

32-bit RGBA raster image with drawing, compositing, scaling, BMP I/O and update-region tracking. More...

#include <Bitmap.h>

Collaboration diagram for cmlabs::Bitmap:
[legend]

Public Member Functions

 Bitmap ()
 Empty 0x0 bitmap.
 Bitmap (uint32 w, uint32 h)
 Allocate a w x h bitmap (uninitialized pixels).
 Bitmap (char *imgData, uint32 w, uint32 h, bool takeData=false)
 Wrap or copy existing RGBA data.
 Bitmap (const char *imgData, uint32 size, uint32 w, uint32 h, uint32 linestep)
 Copy from a buffer with per-row stride linestep bytes.
 Bitmap (const char *imgData, uint32 size, uint32 w, uint32 h, const char *encoding)
 Convert from another pixel encoding (e.g.
 Bitmap (const char *imgData, uint32 size, uint32 w, uint32 h, const char *encoding, uint32 linestep)
 Convert from another encoding with explicit stride.
 Bitmap (const char *filename)
 Load from a BMP file.
 Bitmap (BitmapUpdate *update)
 Reconstruct from a (full) BitmapUpdate.
 Bitmap (DataMessage *msg)
 Deserialize from a DataMessage produced by toMessage().
virtual ~Bitmap ()
bool init (uint32 w, uint32 h)
 (Re)allocate as w x h.
bool init (const char *imgData, uint32 size, uint32 w, uint32 h, const char *encoding, uint32 linestep)
 (Re)initialize from encoded data.
DataMessagetoMessage ()
 Serialize into a new DataMessage (caller owns).
BitmapUpdateoperator- (const Bitmap &bitmap) const
 Difference update transforming bitmap into this image.
bool updateBitmap (BitmapUpdate *update, bool takeData)
 Apply a full/RLE/diff update.
BitmapUpdaterunLengthEncode () const
 RLE-compress the full image.
BitmapUpdaterunLengthDestructiveEncode () const
 RLE-compress, allowed to modify this image's buffer for speed.
bool reset ()
 Release pixel data and return to the empty state.
bool mirror (bool horizontal, bool vertical)
 Flip in place along the requested axes.
bool setPixel (uint32 x, uint32 y, uint8 red, uint8 green, uint8 blue, uint8 alpha=0)
 Set the pixel at (x,y).
bool setPixel (uint32 pos, uint8 red, uint8 green, uint8 blue, uint8 alpha=0)
 Set the pixel at linear index pos.
bool setPixelXOR (uint32 x, uint32 y, uint8 red, uint8 green, uint8 blue, uint8 alpha=0)
 XOR the color into the pixel at (x,y) (reversible marker drawing).
bool setPixelXOR (uint32 pos, uint8 red, uint8 green, uint8 blue, uint8 alpha=0)
 XOR the color into the pixel at linear index pos.
Pixel getPixel (uint32 x, uint32 y)
 Get a Pixel referencing (x,y); value pointer is NULL when out of bounds.
bool getPixel (Pixel *pixel)
 Fill pixel->value from its x/y coordinates.
uint32 getPos (uint32 x, uint32 y)
 Linear pixel index of (x,y) = y*width+x.
double getDPos (double x, double y)
 Fractional linear index for sub-pixel coordinates.
Pixel getXY (uint32 pos)
 Inverse of getPos(): coordinates for a linear index.
Color getPixelColor (uint32 x, uint32 y)
 Pixel color at (x,y) as a Color value (black when out of bounds).
bool eraseBitmap ()
 Fill with black/zero.
bool eraseBitmap (uint8 r, uint8 g, uint8 b, uint8 a=0)
 Fill with the given RGBA color.
bool eraseBitmap (const Color &color)
 Fill with color.
bool replaceColor (const Color &oldColor, const Color &newColor)
 Replace every exact occurrence of oldColor with newColor.
bool fillBox (const Box &box, const Color &color)
 Fill a rectangle (clipped to the image).
bool fillBox (uint32 x, uint32 y, uint32 w, uint32 h, const Color &color)
 Fill a rectangle given by scalars.
bool putTransPixel (uint32 x, uint32 y, const Color &color, double weight)
 Alpha-blend color onto the pixel with fraction weight [0,1] (anti-aliasing helper).
bool drawLine (const Line &line, const Color &color)
 Draw a (possibly anti-aliased) line segment.
bool drawLine (const PolyLine &polyline, const Color &color)
 Draw every segment of a polyline.
bool drawBox (const Box &box, const Color &color)
 Draw a rectangle outline.
bool drawCircle (uint32 xCenter, uint32 yCenter, uint32 radius, const Color &color, double weight, double lineWidth, bool filled=false)
 Draw a circle.
bool putQuadPixel (uint32 xCenter, uint32 yCenter, uint32 x, uint32 y, const Color &color, double weight)
 Plot the 4 symmetric points of a circle octant (internal helper for drawCircle()).
bool drawBitmap (Bitmap *bitmap, uint32 x, uint32 y)
 Blit bitmap with its upper-left corner at (x,y).
bool drawBitmap (Bitmap *bitmap, uint32 x, uint32 y, uint32 w, uint32 h)
 Blit bitmap scaled/clipped into a w x h area at (x,y).
bool drawBitmap (Bitmap *bitmap, const Point &p)
 Blit at a Point.
bool drawBitmap (Bitmap *bitmap, const Box &box)
 Blit into a Box area.
bool drawBitmap (Bitmap *bitmap, uint32 srcx, uint32 srcy, uint32 dstx, uint32 dsty, uint32 w, uint32 h)
 Blit a w x h sub-region from (srcx,srcy) of bitmap to (dstx,dsty).
BitmapgetCopy (const Box &box)
 Extract a sub-image (caller owns).
bool canBeResizedTo (uint32 width, uint32 height)
 Check whether the integer-ratio resizer supports this target size.
BitmapgetResizedCopy (uint32 w, uint32 h, bool proportional)
 Resized copy (caller owns).
BitmapgetResizedCopy (double scale)
 Resized copy by uniform factor scale.
bool resizeTo (uint32 w, uint32 h, bool proportional)
 Resize in place.
bool copyDataFromBitmap (Bitmap *bitmap, bool shouldResize=false)
 Copy pixels from bitmap; optionally resize this image to fit.
bool takeDataFromBitmap (Bitmap *bitmap)
 Steal the pixel buffer from bitmap (which becomes empty); no copy.
double getBestResizeFactor (double factor)
 Snap factor to the nearest factor achievable by the fast integer resizers.
double getBestResizeFactors (double factor, int &scaleUp, int &scaleDown, int &scale66)
 Decompose factor into up/down/66% passes used by createResizedData().
char * createResizedData (uint32 newWidth, uint32 newHeight, int32 scaleUp, int32 scaleDown, int32 scale66)
 Produce a resized pixel buffer using the given pass counts (caller frees).
bool readFromMemory (const char *data, uint32 size)
 Parse a BMP file image from memory.
bool readFromFile (const char *filename)
 Load a BMP file.
bool saveToFile (const char *filename)
 Save as a BMP file.
BitmapUpdategetCompressedUpdate (bool destructive) const
 Full-frame update, RLE compressed.
char * getGrayScaleDataCopy (uint32 &len)
 8-bit grayscale copy of the image.
bool copyGrayScaleData (char *src, uint32 len)
 Fill this RGBA image from an 8-bit grayscale buffer of matching size.
bool resetBitmapUpdates ()
 Clear the dirty-region tracking.
bool setBitmapUpdated ()
 Mark the whole image as changed.
bool addBitmapUpdateRegion (const Box &updateBox)
 Grow the dirty region to include updateBox.
bool hasBitmapBeenUpdated ()
bool hasBitmapBeenTotallyChanged ()
int32 round (double d)
 Round to nearest integer (helper for pixel math).
char * toBitmapFileFormat (uint32 &len)
 Serialize this image as a complete BMP file in memory.

Static Public Member Functions

static bool convertBitmapFileData (const char *src, uint32 width, uint32 height, uint32 depth, char *dst, uint32 dstlen)
 Convert raw BMP pixel rows (bottom-up, padded) into the internal top-down RGBA layout.
static char * convertBitmapFileDataRunLength (const char *src, uint32 width, uint32 height, uint32 depth, uint32 &dstlen)
 As convertBitmapFileData() but RLE-compressing on the fly.
static char * differenceBitmapFileData (char *orig, char *src, uint32 width, uint32 height, uint32 depth, uint32 &dstlen)
 Encode the difference between two frames.
static char * differenceBitmapFileDataRunLength (char *orig, char *src, uint32 width, uint32 height, uint32 depth, uint32 &dstlen)
 Difference encoding + RLE compression.
static char * DataToBitmapFileFormat (const char *data, uint32 size, uint32 width, uint32 height, uint32 &len)
 Convert raw RGBA data into a BMP file image in memory.
static char * DataToBitmapFileFormat (const char *data, uint32 size, uint32 width, uint32 height, uint32 linestep, uint32 &len)
 As above, with an explicit source row stride linestep in bytes.
static char * DataToBitmapFileFormat (const char *data, uint32 size, uint32 width, uint32 height, const char *encoding, uint32 &len)
 Convert pixel data in another encoding (e.g.
static char * DataToBitmapFileFormat (const char *data, uint32 size, uint32 width, uint32 height, const char *encoding, uint32 linestep, uint32 &len)
 Encoded-source variant with an explicit row stride.
static char * DataToEncodingFormat (const char *data, uint32 size, uint32 width, uint32 height, const char *srcEncoding, uint32 linestep, const char *targetEncoding, uint32 &len)
 General pixel-format converter between named encodings.
static bool UnitTest ()
 Self test for Bitmap and BitmapUpdate.

Public Attributes

uint32 width
 Width in pixels.
uint32 height
 Height in pixels.
uint32 size
 Data buffer size in bytes (width*height*4).
char * data
 Pixel data, 32-bit RGBA, row-major top-down.
Box updateRegion
 Accumulated dirty region since the last resetBitmapUpdates().

Detailed Description

32-bit RGBA raster image with drawing, compositing, scaling, BMP I/O and update-region tracking.

Pixel layout: data holds width*height packed 32-bit pixels (size = width*height*4 bytes), row-major starting at the top-left corner with no per-row padding (stride is always width*4; constructors that take a linestep repack padded source rows during the copy). Within a pixel, byte order is R, G, B, A in increasing addresses, i.e. on a little-endian machine a pixel read as uint32 has R in the least significant byte — this is what the GET_*_FROM_RGBA macros assume. Note this is the opposite vertical order to a BMP file (bottom-up); the file routines flip rows on load/save via convertBitmapFileData().

Ownership: the Bitmap owns data and frees it in the destructor and in reset()/init(). The constructor taking takeData=true adopts the caller's malloc'd buffer instead of copying — the caller must not free it afterwards. takeDataFromBitmap() similarly transfers the buffer between Bitmap objects, leaving the source empty. Methods documented as returning "caller owns" allocate fresh buffers/objects the caller must delete/free.

Thread-safety: none — there is no internal locking; guard shared Bitmaps externally.

Most drawing methods clip against the image bounds and return false on invalid input. The updateRegion box accumulates dirty areas between resetBitmapUpdates() calls so consumers can send incremental refreshes.

Bitmap bmp(320, 240);
bmp.eraseBitmap(Color(255, 255, 255)); // white background
bmp.fillBox(10, 10, 100, 50, Color(255, 0, 0)); // red rectangle
bmp.drawCircle(160, 120, 40, Color(0, 0, 255), 1.0, 1.0, false);
bmp.saveToFile("out.bmp");
// Incremental remote refresh:
BitmapUpdate* full = bmp.getCompressedUpdate(false); // RLE full frame
Bitmap remote(full); // remote side decodes
delete full;
bmp.fillBox(0, 0, 32, 32, Color(0, 255, 0)); // change something
BitmapUpdate* diff = bmp - remote; // delta remote -> bmp
remote.updateBitmap(diff, false); // remote now matches
delete diff;
Bitmap()
Empty 0x0 bitmap.
Definition Bitmap.cpp:18
Transportable image update: either a full frame or a compressed (RLE and/or difference) delta against...
Definition Bitmap.h:318
24-bit RGB color with mixing, inversion, distance and palette-generation helpers.

Definition at line 139 of file Bitmap.h.

Constructor & Destructor Documentation

◆ Bitmap() [1/9]

cmlabs::Bitmap::Bitmap ( )

◆ Bitmap() [2/9]

cmlabs::Bitmap::Bitmap ( uint32 w,
uint32 h )

Allocate a w x h bitmap (uninitialized pixels).

Definition at line 29 of file Bitmap.cpp.

References init().

◆ Bitmap() [3/9]

cmlabs::Bitmap::Bitmap ( char * imgData,
uint32 w,
uint32 h,
bool takeData = false )

Wrap or copy existing RGBA data.

Parameters
imgDataRGBA pixel buffer.
w,hDimensions in pixels.
takeDataTake ownership instead of copying.

Definition at line 33 of file Bitmap.cpp.

References data, height, init(), setBitmapUpdated(), size, and width.

◆ Bitmap() [4/9]

cmlabs::Bitmap::Bitmap ( const char * imgData,
uint32 size,
uint32 w,
uint32 h,
uint32 linestep )

Copy from a buffer with per-row stride linestep bytes.

Definition at line 48 of file Bitmap.cpp.

References init(), and size.

◆ Bitmap() [5/9]

cmlabs::Bitmap::Bitmap ( const char * imgData,
uint32 size,
uint32 w,
uint32 h,
const char * encoding )

Convert from another pixel encoding (e.g.

"RGB", "GRAY", "YUV") into RGBA.

Definition at line 51 of file Bitmap.cpp.

References init(), and size.

◆ Bitmap() [6/9]

cmlabs::Bitmap::Bitmap ( const char * imgData,
uint32 size,
uint32 w,
uint32 h,
const char * encoding,
uint32 linestep )

Convert from another encoding with explicit stride.

Definition at line 54 of file Bitmap.cpp.

References init(), and size.

◆ Bitmap() [7/9]

cmlabs::Bitmap::Bitmap ( const char * filename)

Load from a BMP file.

Definition at line 22 of file Bitmap.cpp.

References init(), and readFromFile().

◆ Bitmap() [8/9]

cmlabs::Bitmap::Bitmap ( BitmapUpdate * update)

◆ Bitmap() [9/9]

cmlabs::Bitmap::Bitmap ( DataMessage * msg)

Deserialize from a DataMessage produced by toMessage().

Definition at line 283 of file Bitmap.cpp.

References data, cmlabs::DataMessage::getDataCopy(), cmlabs::DataMessage::getInt(), height, reset(), setBitmapUpdated(), size, and width.

◆ ~Bitmap()

cmlabs::Bitmap::~Bitmap ( )
virtual

Definition at line 256 of file Bitmap.cpp.

References reset().

Member Function Documentation

◆ addBitmapUpdateRegion()

bool cmlabs::Bitmap::addBitmapUpdateRegion ( const Box & updateBox)

Grow the dirty region to include updateBox.

Returns
true.

Definition at line 336 of file Bitmap.cpp.

References cmlabs::Box::getLeftX(), cmlabs::Box::getUpperY(), hasBitmapBeenTotallyChanged(), and updateRegion.

Referenced by drawBitmap(), drawBitmap(), drawBox(), and fillBox().

◆ canBeResizedTo()

bool cmlabs::Bitmap::canBeResizedTo ( uint32 width,
uint32 height )

Check whether the integer-ratio resizer supports this target size.

Definition at line 984 of file Bitmap.cpp.

References getBestResizeFactor(), height, and width.

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1canBeResizedTo().

◆ convertBitmapFileData()

bool cmlabs::Bitmap::convertBitmapFileData ( const char * src,
uint32 width,
uint32 height,
uint32 depth,
char * dst,
uint32 dstlen )
static

Convert raw BMP pixel rows (bottom-up, padded) into the internal top-down RGBA layout.

Returns
true on success.

Definition at line 2850 of file Bitmap.cpp.

References height, and width.

Referenced by _wrap_Bitmap_convertBitmapFileData(), _wrap_Bitmap_convertBitmapFileData(), Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1convertBitmapFileData(), cmlabs::BitmapUpdate::readFromFile(), and readFromMemory().

◆ convertBitmapFileDataRunLength()

char * cmlabs::Bitmap::convertBitmapFileDataRunLength ( const char * src,
uint32 width,
uint32 height,
uint32 depth,
uint32 & dstlen )
static

◆ copyDataFromBitmap()

bool cmlabs::Bitmap::copyDataFromBitmap ( Bitmap * bitmap,
bool shouldResize = false )

◆ copyGrayScaleData()

bool cmlabs::Bitmap::copyGrayScaleData ( char * src,
uint32 len )

Fill this RGBA image from an 8-bit grayscale buffer of matching size.

Returns
true on success.

Definition at line 418 of file Bitmap.cpp.

References data, GET_RGB_FROM_GRAY, height, and width.

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1copyGrayScaleData().

◆ createResizedData()

char * cmlabs::Bitmap::createResizedData ( uint32 newWidth,
uint32 newHeight,
int32 scaleUp,
int32 scaleDown,
int32 scale66 )

Produce a resized pixel buffer using the given pass counts (caller frees).

Definition at line 1137 of file Bitmap.cpp.

References data, height, cmlabs::ImageResizeDown(), cmlabs::ImageResizeDown66(), cmlabs::ImageResizeUp(), cmlabs::ImageResizeUp66(), and width.

Referenced by getResizedCopy(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1createResizedData().

◆ DataToBitmapFileFormat() [1/4]

char * cmlabs::Bitmap::DataToBitmapFileFormat ( const char * data,
uint32 size,
uint32 width,
uint32 height,
const char * encoding,
uint32 & len )
static

Convert pixel data in another encoding (e.g.

"RGB", "GRAY", "YUV") to a BMP file image.

Definition at line 2131 of file Bitmap.cpp.

References data, DataToBitmapFileFormat(), height, size, and width.

◆ DataToBitmapFileFormat() [2/4]

◆ DataToBitmapFileFormat() [3/4]

◆ DataToBitmapFileFormat() [4/4]

char * cmlabs::Bitmap::DataToBitmapFileFormat ( const char * data,
uint32 size,
uint32 width,
uint32 height,
uint32 linestep,
uint32 & len )
static

As above, with an explicit source row stride linestep in bytes.

Definition at line 2117 of file Bitmap.cpp.

References data, DataToBitmapFileFormat(), height, size, and width.

◆ DataToEncodingFormat()

char * cmlabs::Bitmap::DataToEncodingFormat ( const char * data,
uint32 size,
uint32 width,
uint32 height,
const char * srcEncoding,
uint32 linestep,
const char * targetEncoding,
uint32 & len )
static

General pixel-format converter between named encodings.

Parameters
dataSource pixels.
sizeSource size in bytes.
width,heightDimensions.
srcEncodingSource format name.
linestepSource row stride in bytes.
targetEncodingDestination format name.
[out]lenDestination size.
Returns
Allocated buffer (caller frees) or NULL when a conversion is unsupported.

Definition at line 2409 of file Bitmap.cpp.

References data, height, size, stricmp, and width.

Referenced by _wrap_Bitmap_DataToEncodingFormat(), _wrap_Bitmap_DataToEncodingFormat(), init(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1DataToEncodingFormat().

◆ differenceBitmapFileData()

char * cmlabs::Bitmap::differenceBitmapFileData ( char * orig,
char * src,
uint32 width,
uint32 height,
uint32 depth,
uint32 & dstlen )
static

Encode the difference between two frames.

Returns
Allocated diff buffer (caller frees).

Definition at line 3022 of file Bitmap.cpp.

References DATACTRL, DIFCTRL, height, and width.

Referenced by _wrap_Bitmap_differenceBitmapFileData(), _wrap_Bitmap_differenceBitmapFileData(), Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1differenceBitmapFileData(), and cmlabs::BitmapUpdate::readFromFileDiff().

◆ differenceBitmapFileDataRunLength()

char * cmlabs::Bitmap::differenceBitmapFileDataRunLength ( char * orig,
char * src,
uint32 width,
uint32 height,
uint32 depth,
uint32 & dstlen )
static

◆ drawBitmap() [1/5]

bool cmlabs::Bitmap::drawBitmap ( Bitmap * bitmap,
const Box & box )

◆ drawBitmap() [2/5]

bool cmlabs::Bitmap::drawBitmap ( Bitmap * bitmap,
const Point & p )

Blit at a Point.

Definition at line 1602 of file Bitmap.cpp.

References Bitmap(), drawBitmap(), cmlabs::Point::x, and cmlabs::Point::y.

◆ drawBitmap() [3/5]

bool cmlabs::Bitmap::drawBitmap ( Bitmap * bitmap,
uint32 srcx,
uint32 srcy,
uint32 dstx,
uint32 dsty,
uint32 w,
uint32 h )

Blit a w x h sub-region from (srcx,srcy) of bitmap to (dstx,dsty).

Definition at line 1497 of file Bitmap.cpp.

References addBitmapUpdateRegion(), Bitmap(), data, height, and width.

◆ drawBitmap() [4/5]

◆ drawBitmap() [5/5]

bool cmlabs::Bitmap::drawBitmap ( Bitmap * bitmap,
uint32 x,
uint32 y,
uint32 w,
uint32 h )

Blit bitmap scaled/clipped into a w x h area at (x,y).

Definition at line 1557 of file Bitmap.cpp.

References Bitmap(), data, and drawBitmap().

◆ drawBox()

bool cmlabs::Bitmap::drawBox ( const Box & box,
const Color & color )

◆ drawCircle()

bool cmlabs::Bitmap::drawCircle ( uint32 xCenter,
uint32 yCenter,
uint32 radius,
const Color & color,
double weight,
double lineWidth,
bool filled = false )

Draw a circle.

Parameters
xCenter,yCenterCenter in pixels.
radiusRadius in pixels.
colorStroke/fill color.
weightBlend fraction.
lineWidthStroke width.
filledFill the disc when true.

Definition at line 1373 of file Bitmap.cpp.

References D, drawCircle(), putQuadPixel(), and round().

Referenced by drawCircle().

◆ drawLine() [1/2]

bool cmlabs::Bitmap::drawLine ( const Line & line,
const Color & color )

Draw a (possibly anti-aliased) line segment.

Definition at line 886 of file Bitmap.cpp.

References clPI, cmlabs::Line::endPoint, cmlabs::Line::lineWidth, putTransPixel(), cmlabs::Line::startPoint, cmlabs::PointFloat::x, and cmlabs::PointFloat::y.

Referenced by drawBox(), and drawLine().

◆ drawLine() [2/2]

bool cmlabs::Bitmap::drawLine ( const PolyLine & polyline,
const Color & color )

Draw every segment of a polyline.

Definition at line 1337 of file Bitmap.cpp.

References drawLine(), cmlabs::PolyLine::getLine(), cmlabs::PolyLine::getLineCount(), and setBitmapUpdated().

◆ eraseBitmap() [1/3]

◆ eraseBitmap() [2/3]

bool cmlabs::Bitmap::eraseBitmap ( const Color & color)

Fill with color.

Definition at line 794 of file Bitmap.cpp.

References cmlabs::Color::b, eraseBitmap(), cmlabs::Color::g, and cmlabs::Color::r.

◆ eraseBitmap() [3/3]

bool cmlabs::Bitmap::eraseBitmap ( uint8 r,
uint8 g,
uint8 b,
uint8 a = 0 )

Fill with the given RGBA color.

Definition at line 763 of file Bitmap.cpp.

References data, setBitmapUpdated(), size, and width.

◆ fillBox() [1/2]

bool cmlabs::Bitmap::fillBox ( const Box & box,
const Color & color )

Fill a rectangle (clipped to the image).

Returns
true on success.

Definition at line 817 of file Bitmap.cpp.

References fillBox(), cmlabs::Box::getHeight(), cmlabs::Box::getLeftX(), cmlabs::Box::getUpperY(), and cmlabs::Box::getWidth().

Referenced by Bitmap(), fillBox(), and UnitTest().

◆ fillBox() [2/2]

bool cmlabs::Bitmap::fillBox ( uint32 x,
uint32 y,
uint32 w,
uint32 h,
const Color & color )

Fill a rectangle given by scalars.

Definition at line 821 of file Bitmap.cpp.

References addBitmapUpdateRegion(), cmlabs::Color::b, data, cmlabs::Color::g, height, cmlabs::Color::r, and width.

◆ getBestResizeFactor()

double cmlabs::Bitmap::getBestResizeFactor ( double factor)

Snap factor to the nearest factor achievable by the fast integer resizers.

Definition at line 1126 of file Bitmap.cpp.

References getBestResizeFactors().

Referenced by canBeResizedTo(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1getBestResizeFactor().

◆ getBestResizeFactors()

double cmlabs::Bitmap::getBestResizeFactors ( double factor,
int & scaleUp,
int & scaleDown,
int & scale66 )

Decompose factor into up/down/66% passes used by createResizedData().

Returns
Achieved factor.

Definition at line 1074 of file Bitmap.cpp.

Referenced by getBestResizeFactor(), getResizedCopy(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1getBestResizeFactors().

◆ getCompressedUpdate()

BitmapUpdate * cmlabs::Bitmap::getCompressedUpdate ( bool destructive) const

Full-frame update, RLE compressed.

Parameters
destructiveAllow modifying this bitmap's buffer for speed.
Returns
New update.

Definition at line 3271 of file Bitmap.cpp.

References runLengthDestructiveEncode(), and runLengthEncode().

Referenced by operator-().

◆ getCopy()

Bitmap * cmlabs::Bitmap::getCopy ( const Box & box)

◆ getDPos()

double cmlabs::Bitmap::getDPos ( double x,
double y )

Fractional linear index for sub-pixel coordinates.

Definition at line 733 of file Bitmap.cpp.

References height, and width.

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1getDPos().

◆ getGrayScaleDataCopy()

char * cmlabs::Bitmap::getGrayScaleDataCopy ( uint32 & len)

8-bit grayscale copy of the image.

Parameters
[out]lenBuffer size.
Returns
Allocated buffer (caller frees).

Definition at line 403 of file Bitmap.cpp.

References data, GET_GRAY_FROM_RGB, height, size, and width.

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1getGrayScaleDataCopy().

◆ getPixel() [1/2]

bool cmlabs::Bitmap::getPixel ( Pixel * pixel)

Fill pixel->value from its x/y coordinates.

Returns
false when out of bounds.

Definition at line 717 of file Bitmap.cpp.

References data, height, cmlabs::Pixel::value, width, cmlabs::Pixel::x, and cmlabs::Pixel::y.

◆ getPixel() [2/2]

Pixel cmlabs::Bitmap::getPixel ( uint32 x,
uint32 y )

Get a Pixel referencing (x,y); value pointer is NULL when out of bounds.

Definition at line 708 of file Bitmap.cpp.

References getPixel(), cmlabs::Pixel::value, cmlabs::Pixel::x, and cmlabs::Pixel::y.

Referenced by getPixel().

◆ getPixelColor()

Color cmlabs::Bitmap::getPixelColor ( uint32 x,
uint32 y )

Pixel color at (x,y) as a Color value (black when out of bounds).

Definition at line 862 of file Bitmap.cpp.

References cmlabs::Color::b, data, cmlabs::Color::g, getPos(), height, cmlabs::Color::r, and width.

Referenced by UnitTest().

◆ getPos()

uint32 cmlabs::Bitmap::getPos ( uint32 x,
uint32 y )

Linear pixel index of (x,y) = y*width+x.

Definition at line 727 of file Bitmap.cpp.

References height, and width.

Referenced by getPixelColor(), Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1getPos(), and UnitTest().

◆ getResizedCopy() [1/2]

Bitmap * cmlabs::Bitmap::getResizedCopy ( double scale)

Resized copy by uniform factor scale.

Definition at line 1024 of file Bitmap.cpp.

References Bitmap(), createResizedData(), getBestResizeFactors(), height, and width.

◆ getResizedCopy() [2/2]

Bitmap * cmlabs::Bitmap::getResizedCopy ( uint32 w,
uint32 h,
bool proportional )

◆ getXY()

Pixel cmlabs::Bitmap::getXY ( uint32 pos)

Inverse of getPos(): coordinates for a linear index.

Definition at line 739 of file Bitmap.cpp.

References data, cmlabs::Pixel::value, width, cmlabs::Pixel::x, and cmlabs::Pixel::y.

◆ hasBitmapBeenTotallyChanged()

bool cmlabs::Bitmap::hasBitmapBeenTotallyChanged ( )

◆ hasBitmapBeenUpdated()

bool cmlabs::Bitmap::hasBitmapBeenUpdated ( )
Returns
true when any region changed since the last reset.

Definition at line 364 of file Bitmap.cpp.

References updateRegion.

Referenced by _wrap_Bitmap_hasBitmapBeenUpdated(), _wrap_Bitmap_hasBitmapBeenUpdated(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1hasBitmapBeenUpdated().

◆ init() [1/2]

bool cmlabs::Bitmap::init ( const char * imgData,
uint32 size,
uint32 w,
uint32 h,
const char * encoding,
uint32 linestep )

(Re)initialize from encoded data.

Returns
true on success.

Definition at line 58 of file Bitmap.cpp.

References data, DataToEncodingFormat(), height, init(), setBitmapUpdated(), size, stricmp, and width.

◆ init() [2/2]

bool cmlabs::Bitmap::init ( uint32 w,
uint32 h )

◆ mirror()

bool cmlabs::Bitmap::mirror ( bool horizontal,
bool vertical )

Flip in place along the requested axes.

Returns
true on success.

Definition at line 1447 of file Bitmap.cpp.

References data, height, size, and width.

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1mirror().

◆ operator-()

BitmapUpdate * cmlabs::Bitmap::operator- ( const Bitmap & bitmap) const

Difference update transforming bitmap into this image.

Returns
New update (caller owns).

Definition at line 3279 of file Bitmap.cpp.

References Bitmap(), data, cmlabs::BitmapUpdate::data, DATACTRL, DIFCTRL, cmlabs::BitmapUpdate::DIFRUNLENGTH, getCompressedUpdate(), height, RLECTRL, cmlabs::BitmapUpdate::setUpdateType(), cmlabs::BitmapUpdate::size, and width.

◆ putQuadPixel()

bool cmlabs::Bitmap::putQuadPixel ( uint32 xCenter,
uint32 yCenter,
uint32 x,
uint32 y,
const Color & color,
double weight )

Plot the 4 symmetric points of a circle octant (internal helper for drawCircle()).

Definition at line 1360 of file Bitmap.cpp.

References putTransPixel().

Referenced by drawCircle().

◆ putTransPixel()

bool cmlabs::Bitmap::putTransPixel ( uint32 x,
uint32 y,
const Color & color,
double weight )

Alpha-blend color onto the pixel with fraction weight [0,1] (anti-aliasing helper).

Definition at line 876 of file Bitmap.cpp.

References cmlabs::Color::b, data, cmlabs::Color::g, height, cmlabs::Color::r, and width.

Referenced by drawLine(), and putQuadPixel().

◆ readFromFile()

bool cmlabs::Bitmap::readFromFile ( const char * filename)

Load a BMP file.

Returns
true on success.

Definition at line 1989 of file Bitmap.cpp.

References cmlabs::utils::ReadAFile(), and readFromMemory().

Referenced by Bitmap(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1readFromFile().

◆ readFromMemory()

◆ replaceColor()

bool cmlabs::Bitmap::replaceColor ( const Color & oldColor,
const Color & newColor )

Replace every exact occurrence of oldColor with newColor.

Definition at line 798 of file Bitmap.cpp.

References cmlabs::Color::b, data, cmlabs::Color::g, height, cmlabs::Color::r, and width.

Referenced by UnitTest().

◆ reset()

bool cmlabs::Bitmap::reset ( )

Release pixel data and return to the empty state.

Returns
true.

Definition at line 375 of file Bitmap.cpp.

References data.

Referenced by _wrap_Bitmap_reset(), _wrap_Bitmap_reset(), Bitmap(), Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1reset(), updateBitmap(), and ~Bitmap().

◆ resetBitmapUpdates()

bool cmlabs::Bitmap::resetBitmapUpdates ( )

Clear the dirty-region tracking.

Returns
true.

Definition at line 354 of file Bitmap.cpp.

References updateRegion.

Referenced by _wrap_Bitmap_resetBitmapUpdates(), _wrap_Bitmap_resetBitmapUpdates(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1resetBitmapUpdates().

◆ resizeTo()

bool cmlabs::Bitmap::resizeTo ( uint32 w,
uint32 h,
bool proportional )

Resize in place.

Returns
true on success.

Definition at line 1065 of file Bitmap.cpp.

References Bitmap(), getResizedCopy(), and takeDataFromBitmap().

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1resizeTo().

◆ round()

int cmlabs::Bitmap::round ( double d)

Round to nearest integer (helper for pixel math).

Definition at line 2775 of file Bitmap.cpp.

Referenced by drawCircle(), and Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1round().

◆ runLengthDestructiveEncode()

BitmapUpdate * cmlabs::Bitmap::runLengthDestructiveEncode ( ) const

RLE-compress, allowed to modify this image's buffer for speed.

Returns
New update.

Definition at line 3494 of file Bitmap.cpp.

References data, cmlabs::BitmapUpdate::data, DATACTRL, GET_DRGB_FROM_2RGBS, height, cmlabs::BitmapUpdate::RL16, RLECTRL, cmlabs::BitmapUpdate::setUpdateType(), cmlabs::BitmapUpdate::size, and width.

Referenced by getCompressedUpdate().

◆ runLengthEncode()

BitmapUpdate * cmlabs::Bitmap::runLengthEncode ( ) const

RLE-compress the full image.

Returns
New update (caller owns).

Definition at line 3413 of file Bitmap.cpp.

References data, cmlabs::BitmapUpdate::data, DATACTRL, height, RLECTRL, cmlabs::BitmapUpdate::RUNLENGTH, cmlabs::BitmapUpdate::setUpdateType(), cmlabs::BitmapUpdate::size, and width.

Referenced by getCompressedUpdate().

◆ saveToFile()

bool cmlabs::Bitmap::saveToFile ( const char * filename)

Save as a BMP file.

Returns
true on success.

Definition at line 2003 of file Bitmap.cpp.

References toBitmapFileFormat(), and cmlabs::utils::WriteAFile().

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1saveToFile().

◆ setBitmapUpdated()

bool cmlabs::Bitmap::setBitmapUpdated ( )

◆ setPixel() [1/2]

bool cmlabs::Bitmap::setPixel ( uint32 pos,
uint8 red,
uint8 green,
uint8 blue,
uint8 alpha = 0 )

Set the pixel at linear index pos.

Definition at line 670 of file Bitmap.cpp.

References data, setBitmapUpdated(), and size.

◆ setPixel() [2/2]

bool cmlabs::Bitmap::setPixel ( uint32 x,
uint32 y,
uint8 red,
uint8 green,
uint8 blue,
uint8 alpha = 0 )

◆ setPixelXOR() [1/2]

bool cmlabs::Bitmap::setPixelXOR ( uint32 pos,
uint8 red,
uint8 green,
uint8 blue,
uint8 alpha = 0 )

XOR the color into the pixel at linear index pos.

Definition at line 695 of file Bitmap.cpp.

References data, setBitmapUpdated(), and size.

◆ setPixelXOR() [2/2]

bool cmlabs::Bitmap::setPixelXOR ( uint32 x,
uint32 y,
uint8 red,
uint8 green,
uint8 blue,
uint8 alpha = 0 )

◆ takeDataFromBitmap()

bool cmlabs::Bitmap::takeDataFromBitmap ( Bitmap * bitmap)

Steal the pixel buffer from bitmap (which becomes empty); no copy.

Definition at line 1225 of file Bitmap.cpp.

References Bitmap(), data, height, size, and width.

Referenced by _wrap_Bitmap_takeDataFromBitmap(), _wrap_Bitmap_takeDataFromBitmap(), copyDataFromBitmap(), Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1takeDataFromBitmap(), and resizeTo().

◆ toBitmapFileFormat()

char * cmlabs::Bitmap::toBitmapFileFormat ( uint32 & len)

Serialize this image as a complete BMP file in memory.

Parameters
[out]lenFile size.
Returns
Allocated buffer (caller frees).

Definition at line 2109 of file Bitmap.cpp.

References data, DataToBitmapFileFormat(), height, size, and width.

Referenced by Java_com_cmlabs_cmsdk_cmsdkJNI_Bitmap_1toBitmapFileFormat(), and saveToFile().

◆ toMessage()

DataMessage * cmlabs::Bitmap::toMessage ( )

Serialize into a new DataMessage (caller owns).

Returns
Message or NULL.

Definition at line 294 of file Bitmap.cpp.

References data, height, cmlabs::DataMessage::setData(), cmlabs::DataMessage::setInt(), size, and width.

Referenced by UnitTest().

◆ UnitTest()

◆ updateBitmap()

bool cmlabs::Bitmap::updateBitmap ( BitmapUpdate * update,
bool takeData )

Member Data Documentation

◆ data

◆ height

◆ size

◆ updateRegion

Box cmlabs::Bitmap::updateRegion

Accumulated dirty region since the last resetBitmapUpdates().

Definition at line 252 of file Bitmap.h.

Referenced by addBitmapUpdateRegion(), hasBitmapBeenTotallyChanged(), hasBitmapBeenUpdated(), resetBitmapUpdates(), and setBitmapUpdated().

◆ width


The documentation for this class was generated from the following files:
  • /home/ubuntu/c/partner/psyclone2/CMSDK/include/Bitmap.h
  • /home/ubuntu/c/partner/psyclone2/CMSDK/src/Bitmap.cpp