10#if !defined(_BITMAP_H_)
19#define GET_RGB_FROM_RGBA(a) (a & 0x00ffffff)
29#define GET_R_FROM_RGBA(a) (unsigned char)(a & 0x000000ff)
30#define GET_G_FROM_RGBA(a) (unsigned char)((a & 0x0000ff00)>>8)
31#define GET_B_FROM_RGBA(a) (unsigned char)((a & 0x00ff0000)>>16)
32#define GET_RGB_FROM_GRAY(a) (unsigned int)(((unsigned int)a<<16) + ((unsigned int)a<<8) + (unsigned int)a)
33#define GET_RGB_FROM_COMP(r,g,b) (unsigned int)((((unsigned int)b)<<16) + (((unsigned int)g)<<8) + (unsigned int)r)
34#define GET_GRAY_FROM_RGB(a) (unsigned char)((GET_R_FROM_RGBA(a)+GET_G_FROM_RGBA(a)+GET_B_FROM_RGBA(a))/3)
37#define GET_DRGB_FROM_2RGBS(a,b) (((unsigned int)GET_R_FROM_RGBA(a)>>3)<<27) + (((unsigned int)GET_G_FROM_RGBA(a)>>2)<<21) + (((unsigned int)GET_B_FROM_RGBA(a)>>3)<<16) + (((unsigned int)GET_R_FROM_RGBA(b)>>3)<<11) + (((unsigned int)GET_G_FROM_RGBA(b)>>2)<<5) + (((unsigned int)GET_B_FROM_RGBA(b)>>3)<<0)
38#define GET_FIRSTRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)((a>>16)&0xF800)>>8)) | ((unsigned int)((unsigned short)((a>>16)&0xE000)>>13)) | ((unsigned int)((unsigned short)((a>>16)&0x07E0)<<5)) | ((unsigned int)((unsigned short)((a>>16)&0x0600))>>1) | ((unsigned int)((unsigned short)(a>>16)&0x001F)<<19) | (((unsigned int)(unsigned short)(a>>16)&0x001C)<<14)
39#define GET_SECONDRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)(a&0xF800)>>8)) | ((unsigned int)((unsigned short)(a&0xE000)>>13)) | ((unsigned int)((unsigned short)(a&0x07E0)<<5)) | ((unsigned int)((unsigned short)(a&0x0600))>>1) | ((unsigned int)((unsigned short)a&0x001F)<<19) | (((unsigned int)(unsigned short)a&0x001C)<<14)
143 Bitmap(uint32 w, uint32 h);
144 Bitmap(
char* imgData, uint32 w, uint32 h,
bool takeData =
false);
145 Bitmap(
const char* imgData, uint32
size, uint32 w, uint32 h, uint32 linestep);
146 Bitmap(
const char* imgData, uint32
size, uint32 w, uint32 h,
const char* encoding);
147 Bitmap(
const char* imgData, uint32
size, uint32 w, uint32 h,
const char* encoding, uint32 linestep);
148 Bitmap(
const char* filename);
152 bool init(uint32 w, uint32 h);
153 bool init(
const char* imgData, uint32
size, uint32 w, uint32 h,
const char* encoding, uint32 linestep);
164 bool mirror(
bool horizontal,
bool vertical);
167 bool setPixel(uint32 x, uint32 y, uint8 red, uint8 green, uint8 blue, uint8 alpha = 0);
168 bool setPixel(uint32 pos, uint8 red, uint8 green, uint8 blue, uint8 alpha = 0);
169 bool setPixelXOR(uint32 x, uint32 y, uint8 red, uint8 green, uint8 blue, uint8 alpha = 0);
170 bool setPixelXOR(uint32 pos, uint8 red, uint8 green, uint8 blue, uint8 alpha = 0);
175 uint32
getPos(uint32 x, uint32 y);
176 double getDPos(
double x,
double y);
183 bool eraseBitmap(uint8 r, uint8 g, uint8 b, uint8 a = 0);
188 bool fillBox(uint32 x, uint32 y, uint32 w, uint32 h,
const Color& color);
194 bool drawCircle(uint32 xCenter, uint32 yCenter, uint32 radius,
const Color& color,
double weight,
double lineWidth,
bool filled =
false);
195 bool putQuadPixel(uint32 xCenter, uint32 yCenter, uint32 x, uint32 y,
const Color& color,
double weight);
201 bool drawBitmap(
Bitmap* bitmap, uint32 srcx, uint32 srcy, uint32 dstx, uint32 dsty, uint32 w, uint32 h);
208 bool resizeTo(uint32 w, uint32 h,
bool proportional);
213 char*
createResizedData(uint32 newWidth, uint32 newHeight, int32 scaleUp, int32 scaleDown, int32 scale66);
269 int32
round(
double d);
275 uint32
height, uint32& len);
278 uint32
height, uint32 linestep, uint32& len);
281 uint32
height,
const char* encoding, uint32& len);
284 uint32
height,
const char* encoding, uint32 linestep, uint32& len);
291 uint32
height,
const char* srcEncoding, uint32 linestep,
const char* targetEncoding, uint32& len);
300char*
ImageResizeDown(
char* bytesource, uint32 &cols, uint32 &rows, uint32 factor);
304char*
ImageResizeUp(
char* bytesource, uint32 &cols, uint32 &rows, uint32 factor);
327 bool init(uint32 w, uint32 h);
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
Geometry and 2D/3D math value classes: Color, Size, Point, PointFloat, Line, PolyLine,...
32-bit RGBA raster image with drawing, compositing, scaling, BMP I/O and update-region tracking.
static char * convertBitmapFileDataRunLength(const char *src, uint32 width, uint32 height, uint32 depth, uint32 &dstlen)
As convertBitmapFileData() but RLE-compressing on the fly.
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 addBitmapUpdateRegion(const Box &updateBox)
Grow the dirty region to include updateBox.
bool init(uint32 w, uint32 h)
(Re)allocate as w x h.
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 hasBitmapBeenTotallyChanged()
bool fillBox(const Box &box, const Color &color)
Fill a rectangle (clipped to the image).
Bitmap * getCopy(const Box &box)
Extract a sub-image (caller owns).
double getBestResizeFactors(double factor, int &scaleUp, int &scaleDown, int &scale66)
Decompose factor into up/down/66% passes used by createResizedData().
bool copyGrayScaleData(char *src, uint32 len)
Fill this RGBA image from an 8-bit grayscale buffer of matching size.
bool drawCircle(uint32 xCenter, uint32 yCenter, uint32 radius, const Color &color, double weight, double lineWidth, bool filled=false)
Draw a circle.
Pixel getXY(uint32 pos)
Inverse of getPos(): coordinates for a linear index.
bool mirror(bool horizontal, bool vertical)
Flip in place along the requested axes.
bool drawLine(const Line &line, const Color &color)
Draw a (possibly anti-aliased) line segment.
bool hasBitmapBeenUpdated()
static bool UnitTest()
Self test for Bitmap and BitmapUpdate.
Color getPixelColor(uint32 x, uint32 y)
Pixel color at (x,y) as a Color value (black when out of bounds).
bool setPixel(uint32 x, uint32 y, uint8 red, uint8 green, uint8 blue, uint8 alpha=0)
Set the pixel at (x,y).
bool setBitmapUpdated()
Mark the whole image as changed.
uint32 height
Height in pixels.
uint32 width
Width in pixels.
BitmapUpdate * operator-(const Bitmap &bitmap) const
Difference update transforming bitmap into this image.
DataMessage * toMessage()
Serialize into a new DataMessage (caller owns).
BitmapUpdate * getCompressedUpdate(bool destructive) const
Full-frame update, RLE compressed.
bool resizeTo(uint32 w, uint32 h, bool proportional)
Resize in place.
bool takeDataFromBitmap(Bitmap *bitmap)
Steal the pixel buffer from bitmap (which becomes empty); no copy.
static char * differenceBitmapFileDataRunLength(char *orig, char *src, uint32 width, uint32 height, uint32 depth, uint32 &dstlen)
Difference encoding + RLE compression.
double getBestResizeFactor(double factor)
Snap factor to the nearest factor achievable by the fast integer resizers.
bool eraseBitmap()
Fill with black/zero.
Box updateRegion
Accumulated dirty region since the last resetBitmapUpdates().
BitmapUpdate * runLengthDestructiveEncode() const
RLE-compress, allowed to modify this image's buffer for speed.
bool copyDataFromBitmap(Bitmap *bitmap, bool shouldResize=false)
Copy pixels from bitmap; optionally resize this image to fit.
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 updateBitmap(BitmapUpdate *update, bool takeData)
Apply a full/RLE/diff update.
uint32 size
Data buffer size in bytes (width*height*4).
static char * differenceBitmapFileData(char *orig, char *src, uint32 width, uint32 height, uint32 depth, uint32 &dstlen)
Encode the difference between two frames.
Bitmap()
Empty 0x0 bitmap.
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 resetBitmapUpdates()
Clear the dirty-region tracking.
Bitmap * getResizedCopy(uint32 w, uint32 h, bool proportional)
Resized copy (caller owns).
bool readFromMemory(const char *data, uint32 size)
Parse a BMP file image from memory.
uint32 getPos(uint32 x, uint32 y)
Linear pixel index of (x,y) = y*width+x.
char * data
Pixel data, 32-bit RGBA, row-major top-down.
bool replaceColor(const Color &oldColor, const Color &newColor)
Replace every exact occurrence of oldColor with newColor.
int32 round(double d)
Round to nearest integer (helper for pixel math).
bool reset()
Release pixel data and return to the empty state.
bool canBeResizedTo(uint32 width, uint32 height)
Check whether the integer-ratio resizer supports this target size.
char * toBitmapFileFormat(uint32 &len)
Serialize this image as a complete BMP file in memory.
Pixel getPixel(uint32 x, uint32 y)
Get a Pixel referencing (x,y); value pointer is NULL when out of bounds.
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.
bool drawBitmap(Bitmap *bitmap, uint32 x, uint32 y)
Blit bitmap with its upper-left corner at (x,y).
char * getGrayScaleDataCopy(uint32 &len)
8-bit grayscale copy of the image.
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.
double getDPos(double x, double y)
Fractional linear index for sub-pixel coordinates.
bool saveToFile(const char *filename)
Save as a BMP file.
BitmapUpdate * runLengthEncode() const
RLE-compress the full image.
bool readFromFile(const char *filename)
Load a BMP file.
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.
bool drawBox(const Box &box, const Color &color)
Draw a rectangle outline.
Transportable image update: either a full frame or a compressed (RLE and/or difference) delta against...
uint32 size
Payload size in bytes.
BitmapUpdate::Type getUpdateType()
Bitmap * toBitmap()
Decode into a new full Bitmap (caller owns); requires a FULL-equivalent payload.
uint32 height
Frame height in pixels.
BitmapUpdate()
Empty update.
bool reset()
Release the payload.
uint32 width
Frame width in pixels.
bool update(BitmapUpdate *update)
Merge a newer update into this one.
char * data
Encoded payload (interpretation depends on type).
bool setUpdateType(BitmapUpdate::Type updateType)
Set the payload encoding tag.
bool readFromFile(const char *filename)
Load a BMP file as a FULL update.
bool setFullUpdate(Bitmap *bitmap)
Fill as an uncompressed full frame from bitmap.
bool init(uint32 w, uint32 h)
(Re)initialize for a w x h frame.
bool readFromFileRLEDiff(const char *filename, Bitmap *oldBitmap)
Load, difference against oldBitmap and RLE-compress.
bool readFromFileDiff(const char *filename, Bitmap *oldBitmap)
Load a BMP file and store the difference against oldBitmap.
bool readFromFileRLE(const char *filename)
Load a BMP file and RLE-compress it.
Type
Payload encoding: FULL raw frame, RUNLENGTH RLE frame, RL16 16-bit RLE, DIF raw difference,...
Axis-aligned rectangle defined by an upper-left corner and a Size, with overlap/containment math.
24-bit RGB color with mixing, inversion, distance and palette-generation helpers.
The central Psyclone data container: a self-contained binary message with typed, named user entries.
Line segment between two PointFloat endpoints with a drawing width.
Reference to one pixel: coordinates plus a pointer directly into the owning Bitmap's data (no copy).
Integer 3D point with an optional attached Size; interoperates with PointFloat and vectors.
Ordered collection of Line segments (not necessarily connected).
char * ImageResizeUp66(char *bytesource, uint32 &cols, uint32 &rows)
Enlarge an RGBA image to 3/2 size (2→3 pixel interpolation).
char * ImageResizeUp(char *bytesource, uint32 &cols, uint32 &rows, uint32 factor)
Enlarge an RGBA image by an integer factor (pixel replication).
struct cmlabs::tagBITMAPFILEHEADER_CM BITMAPFILEHEADER_CM
BMP file header (14 bytes), local packed definition so no windows.h dependency is needed.
char * ImageResizeDown66(char *bytesource, uint32 &cols, uint32 &rows)
Shrink an RGBA image to 2/3 size (3→2 pixel averaging).
struct cmlabs::tagRGBA valRGBA
One RGBA pixel value as separate byte components.
struct cmlabs::tagBITMAPINFOHEADER_CM BITMAPINFOHEADER_CM
BMP info header (40 bytes, BITMAPINFOHEADER equivalent), packed to 2-byte alignment for direct file m...
char * ImageResizeDown(char *bytesource, uint32 &cols, uint32 &rows, uint32 factor)
Shrink an RGBA image by an integer factor (box averaging).
BMP file header (14 bytes), local packed definition so no windows.h dependency is needed.
BMP info header (40 bytes, BITMAPINFOHEADER equivalent), packed to 2-byte alignment for direct file m...
One RGBA pixel value as separate byte components.