Kōtuku
  • Gallery
  • API
  • Wiki
  • GitHub
    • Audio
    • Config
    • Core
    • Display
    • Document
    • Font
    • HTTP
    • Network
    • Regex
    • SVG
    • Tiri
    • Vector
    • XML
    • XQuery
    • XRandR
      • Audio
      • MP3
      • Sound
      • File
      • MetaClass
      • Module
      • StorageDevice
      • Task
      • Thread
      • Time
      • Compression
      • CompressedStream
      • Config
      • LZMAStream
      • Script
      • Tiri
      • XML
      • XQuery
      • Controller
      • BlurFX
      • ColourFX
      • CompositeFX
      • ConvolveFX
      • DisplacementFX
      • FilterEffect
      • FloodFX
      • ImageFX
      • LightingFX
      • MergeFX
      • MorphologyFX
      • OffsetFX
      • RemapFX
      • SourceFX
      • TurbulenceFX
      • WaveFunctionFX
      • Scintilla
      • Bitmap
      • Clipboard
      • Display
      • Document
      • Font
      • Image
      • Pointer
      • Surface
      • SVG
      • ClientSocket
      • HTTP
      • NetClient
      • NetLookup
      • NetServer
      • NetSocket
      • Proxy
      • Gradient
      • GradientConic
      • GradientContour
      • GradientDiamond
      • GradientDiffusion
      • GradientDistal
      • GradientGouraud
      • GradientLinear
      • GradientMesh
      • GradientRadial
      • GradientVoronoi
      • Vector
      • VectorClip
      • VectorColour
      • VectorEllipse
      • VectorFilter
      • VectorGradient
      • VectorGroup
      • VectorImage
      • VectorPath
      • VectorPattern
      • VectorPolygon
      • VectorRectangle
      • VectorScene
      • VectorShape
      • VectorSpiral
      • VectorText
      • VectorTransition
      • VectorViewport
      • VectorWave
      • Linux Builds
      • Windows Builds
      • Customising Your Build
      • Kōtuku Objects
      • Kōtuku In Depth
      • Kōtuku Design Patterns
      • Coding With AI
      • Regex Manual
      • XML Comparisons
      • Tiri Reference Manual
      • Config API
      • Defer Syntax
      • GUI API
      • HTTP Server API
      • I/O API
      • JSON API
      • OAuth API
      • Options API
      • Proxy Server API
      • Tempus API
      • URL API
      • VFX API
      • Widgets
      • RIPL Reference Manual
      • Origo
      • Flute / Unit Testing
      • Tuku
      • Embedded Document Format
      • TDL Reference Manual
      • TDL Tools
      • Action Reference Manual
      • System Error Codes

Bitmap Class

Represents a pixel buffer used for drawing, image transfer and display backing.

The Bitmap class describes a rectangular block of pixel data together with its dimensions, colour format, palette, clipping region and drawing state. Bitmaps are used directly by Display and Image objects and provide the low-level pixel storage behind much of Kōtuku's 2D graphics pipeline.

To create a bitmap, set Width and Height before initialisation. The pixel format can be selected explicitly with BitsPerPixel, BytesPerPixel, AmtColours and Type, or left for Query() and Init() to derive from the current display environment. MemType controls whether the bitmap uses regular CPU-accessible memory or a platform-specific video or texture resource where supported.

Direct CPU access is reliable for regular data bitmaps. Bitmaps backed by video or texture resources may require Lock() before reading or writing Data, and Unlock() after direct access is complete. Code that uses the drawing methods exposed by this class does not normally need to manage locking itself.

Bitmap methods are intentionally low-level and operate on immediate pixel data. Use the Vector module when retained scene graphs, paths, gradients, filters or higher-level drawing composition are required. Use Image when decoding or encoding image formats is the main concern.

Raw image bytes can be read and written with Read() and Write(). SaveImage() writes the clipped bitmap image as PCX data to a destination object that supports writing.

Structure

The Bitmap class consists of the following fields:

Access
NameTypeComment
 AmtColoursINTThe maximum number of colours represented by the bitmap format.

For indexed bitmaps, this is the size of the usable palette. For direct-colour bitmaps, it reflects the colour range implied by BitsPerPixel and the selected ColourFormat.

 BitsPerPixelINTThe number of bits used to represent each pixel.

This includes all bits used by the pixel format, including alpha bits where present.

 BkgdRGB8Background colour in RGB format.

The background colour is used by operations that need a default fill colour, such as Clear(), Draw() and some resize paths. The default background colour is black.

The BkgdIndex will be updated as a result of setting this field.

 BkgdIndexINTBackground colour as a packed pixel value or palette index.

Use Bkgd for most updates. Set BkgdIndex directly only when the caller has already calculated the target bitmap's native pixel value or palette index.

 BlendModeBLMDefines the blending algorithm to use when rendering transparent pixels.

The default value is BLM::AUTO, which selects the preferred blending path for the current bitmap and graphics backend.

NameDescription
BLM::AUTOUse the most suitable of the available algorithms.
BLM::GAMMAUse gamma correct blending. This algorithm is slow but produces a high quality result.
BLM::LINEARUse linear blending. Applicable if the bitmap is in linear colour space.
BLM::NONENever blend transparent pixels, just copy as-is.
BLM::SRGBUse sRGB linear blending. This algorithm is extremely efficient but produces poor quality results.
 ByteWidthINTThe width of the bitmap, in bytes.

ByteWidth is calculated from Width, Type and BytesPerPixel. It describes the meaningful pixel bytes in a row and does not include alignment padding.

The formulas used to calculate the value of this field are:

Planar      = Width/8
Chunky/8    = Width
Chunky/15   = Width * 2
Chunky/16   = Width * 2
Chunky/24   = Width * 3
Chunky/32   = Width * 4

To learn the total byte-width per line including any additional padded bytes, refer to the LineWidth field.

 BytesPerPixelINTThe number of bytes per pixel.

This field reflects the byte count used by one chunky pixel. Values normally range from 1 to 4. For planar bitmaps, BitsPerPixel is the more useful format indicator.

 Clipstruct ClipRectangleDefines the bitmap's clipping region.

Clip is a shorthand reference for ClipLeft, ClipTop, ClipRight and ClipBottom, returning all four values as a single ClipRectangle structure.

 ClipBottomINTThe exclusive bottom edge of the bitmap clipping region.

The default clipping region matches the bitmap dimensions. Drawing operations are limited to the active clipping region.

 ClipLeftINTThe left-most edge of a bitmap's clipping region.

The default clipping region matches the bitmap dimensions. Drawing operations are limited to the active clipping region.

 ClipRightINTThe exclusive right edge of the bitmap clipping region.

The default clipping region matches the bitmap dimensions. Drawing operations are limited to the active clipping region.

 ClipTopINTThe top-most edge of a bitmap's clipping region.

The default clipping region matches the bitmap dimensions. Drawing operations are limited to the active clipping region.

 ColourFormatstruct ColourFormat *Describes the colour format used to construct each bitmap pixel.

ColourFormat points to the structure that describes how packed pixel values map to red, green, blue and alpha channels. It is relevant for direct-colour bitmaps, normally those with two or more bytes per pixel.

FieldTypeDescription
RedShiftUINT8Right shift value for red (15/16 bit formats only)
GreenShiftUINT8Right shift value for green
BlueShiftUINT8Right shift value for blue
AlphaShiftUINT8Right shift value for alpha
RedMaskUINT8Unshifted mask value for red (ranges from 0x00 to 0xff)
GreenMaskUINT8Unshifted mask value for green
BlueMaskUINT8Unshifted mask value for blue
AlphaMaskUINT8Unshifted mask value for alpha
RedPosUINT8Left shift/positional value for red
GreenPosUINT8Left shift/positional value for green
BluePosUINT8Left shift/positional value for blue
AlphaPosUINT8Left shift/positional value for alpha
BitsPerPixelUINT8Number of bits per pixel for this format.

The following C++ helper methods can be called on a bitmap to build packed colour values from channel components:

packPixel(Red, Green, Blue)
packPixel(Red, Green, Blue, Alpha)
packAlpha(Alpha)
packPixelRGB(RGB8 &RGB)
packPixelRGBA(RGB8 &RGB)

The following C macros are optimised forms for 24 and 32-bit bitmaps:

PackPixelWB(Red, Green, Blue)
PackPixelWBA(Red, Green, Blue, Alpha)

The following C++ helper methods unpack individual colour components from a packed colour value:

unpackRed(Colour)
unpackGreen(Colour)
unpackBlue(Colour)
unpackAlpha(Colour)
 ColourSpaceCSDefines the colour space for RGB values.
NameDescription
CS::CIE_LABCartesian L*a*b* colour space defined by CIE 15.
CS::CIE_LCHPolar L*CHab colour space defined by CIE 15.
CS::LINEAR_RGBLinear RGB is used to improve colour balance in blending operations.
CS::SRGBThe default colour-space is sRGB.
 DataUINT8[]Provides direct access to the bitmap's data area.

Data points to the first byte of the bitmap's pixel buffer when CPU-visible memory is available. Caller-supplied memory can be used for data-backed bitmaps, but most callers should let Init() allocate the correctly sized buffer.

For video or texture-backed bitmaps, Data may be unavailable until Lock() succeeds.

 DrawUCPixelFUNCTION *Points to a C function that draws pixels to the bitmap using colour indexes.

DrawUCPixel points to the active low-level pixel writer for packed colour or palette-index values. It is intended for C callers that need direct pixel access. No clipping or bounds checks are performed.

The prototype of the DrawUCPixel function is Function(*Bitmap, LONG X, LONG Y, UINT Colour).

The new pixel value is supplied in the Colour parameter.

 DrawUCRIndexFUNCTION *Points to a C function that draws pixels to the bitmap in RGB format.

DrawUCRIndex points to the active low-level RGB pixel writer for a caller-supplied address inside Data. It is intended for C callers that need direct pixel access. No clipping, bounds or address validation is performed.

The prototype of the DrawUCRIndex function is Function(*Bitmap, BYTE *Data, RGB8 *RGB).

The Data parameter must point to a location within the Bitmap's graphical address space. The new pixel value must be defined in the RGB parameter.

There is no colour-index equivalent because callers can write indexed pixel bytes directly through Data.

 DrawUCRPixelFUNCTION *Points to a C function that draws pixels to the bitmap in RGB format.

DrawUCRPixel points to the active low-level RGB pixel writer for X, Y coordinates. It is intended for C callers that need direct pixel access. No clipping or bounds checks are performed.

The prototype of the DrawUCRPixel function is Function(*Bitmap, LONG X, LONG Y, RGB8 *RGB).

The new pixel value must be defined in the RGB parameter.

 FlagsBMFOptional flags.
NameDescription
BMF::ACCELERATED_2D2D video acceleration is available.
BMF::ACCELERATED_3D3D video acceleration is available.
BMF::ALPHA_CHANNELFor 32-bit images, indicates that an alpha channel is present.
BMF::BLANK_PALETTEForces a blank/black palette on initialisation.
BMF::CLEARClear graphics on initialisation and when resizing.
BMF::COMPRESSEDThe bitmap data is compressed.
BMF::FIXED_DEPTHPrevent changing of bitmap depth after initialisation (e.g. via Resize()).
BMF::INVERSE_ALPHAIndicates reverse alpha blending, higher values are transparent.
BMF::MASKDeclare the Bitmap as a 1 or 8 bit mask. Must be set in conjunction with the Bitmap⇒BitsPerPixel field on initialisation.
BMF::NEVER_SHRINKIgnore resize requests that would shrink the size of the bitmap.
BMF::NO_DATADo not allocate memory in the Data field on initialisation.
BMF::PREMULThe RGB values are premultiplied (32-bit only).
BMF::QUERIEDAutomatically set after a Query() on the bitmap.
BMF::TRANSPARENTIndicates that the bitmap utilises a transparent colour. This is automatically set if the Bitmap⇒TransIndex or Bitmap⇒TransColour is defined, and support exists in functions such as CopyArea().
BMF::USERThis user flag can be used to tag bitmaps with special meaning. Not used internally.
 HandleAPTRPlatform-dependent field for referencing video memory.
 HeightINTThe height of the bitmap, in pixels.
 LineWidthINTThe length of each bitmap line in bytes, including alignment.

LineWidth includes any row padding required by the active bitmap type or platform backend. Use ByteWidth for the number of meaningful pixel bytes in a row.

 MemTypeBMTDefines the memory type used to host a bitmap's data area.

MemType controls the kind of backing storage requested during initialisation. The available values are BMT::DATA, BMT::VIDEO and BMT::TEXTURE.

Video or texture-backed bitmaps can be faster for some drawing paths, but direct CPU access is platform dependent. Use Lock() before reading or writing Data directly when the bitmap is not a regular data bitmap.

NameDescription
BMT::DATAThe default type, indicates a standard memory allocation from system RAM.
BMT::TEXTUREIdentifies non-displayable video memory, e.g. texture graphics.
BMT::VIDEOIdentifies video memory, such as the frame buffer.
 OpacityINTDetermines the translucency setting to use in drawing operations.

Opacity is an 8-bit alpha multiplier used by drawing operations that support translucent bitmap copies. A value of 255 is fully opaque and disables additional translucency. Lower values make copied pixels more transparent.

This value is separate from any per-pixel alpha channel stored in the bitmap.

 Palettestruct RGBPalette *Points to a bitmap's colour palette.

Palette points to the bitmap's colour table. Indexed bitmaps use this table to map pixel values to RGB colours, and some conversion paths use it even when the bitmap itself is direct-colour.

The structure starts with the palette header and colour count, followed by colour entries in index order. There is no terminating entry.

The following example is for a 32 colour palette:

RGBPalette Palette = {
  ID_PALETTE, VER_PALETTE, 32,
  {{ 0x00,0x00,0x00 }, { 0x10,0x10,0x10 }, { 0x17,0x17,0x17 }, { 0x20,0x20,0x20 },
   { 0x27,0x27,0x27 }, { 0x30,0x30,0x30 }, { 0x37,0x37,0x37 }, { 0x40,0x40,0x40 },
   { 0x47,0x47,0x47 }, { 0x50,0x50,0x50 }, { 0x57,0x57,0x57 }, { 0x60,0x60,0x60 },
   { 0x67,0x67,0x67 }, { 0x70,0x70,0x70 }, { 0x77,0x77,0x77 }, { 0x80,0x80,0x80 },
   { 0x87,0x87,0x87 }, { 0x90,0x90,0x90 }, { 0x97,0x97,0x97 }, { 0xa0,0xa0,0xa0 },
   { 0xa7,0xa7,0xa7 }, { 0xb0,0xb0,0xb0 }, { 0xb7,0xb7,0xb7 }, { 0xc0,0xc0,0xc0 },
   { 0xc7,0xc7,0xc7 }, { 0xd0,0xd0,0xd0 }, { 0xd7,0xd7,0xd7 }, { 0xe0,0xe0,0xe0 },
   { 0xe0,0xe0,0xe0 }, { 0xf0,0xf0,0xf0 }, { 0xf7,0xf7,0xf7 }, { 0xff,0xff,0xff }
   }
};

Palettes are created for all bitmap types, including RGB bitmaps above 8-bit colour, because several drawing functions use a palette table when converting between bitmap formats.

Parent objects such as Display may need to be updated separately before palette changes are reflected by the visible display.

 PlaneModINTThe differential between each bitmap plane.

PlaneMod specifies the byte distance between each bitplane in planar bitmaps. For chunky bitmaps, it reflects the total size of the bitmap buffer.

 PositionINTThe current read/write data position.

Position is the byte offset used by Read() and Write(). Use Seek() to change it.

 ReadUCPixelFUNCTION *Points to a C function that reads pixels from the bitmap in colour index format.

ReadUCPixel points to the active low-level pixel reader for packed colour or palette-index values. It is intended for C callers that need direct pixel access. No clipping or bounds checks are performed.

The prototype of the ReadUCPixel function is Function(*Bitmap, LONG X, LONG Y, LONG *Index).

The pixel value will be returned in the Index parameter.

 ReadUCRIndexFUNCTION *Points to a C function that reads pixels from the bitmap in RGB format.

ReadUCRIndex points to the active low-level RGB pixel reader for a caller-supplied address inside Data. It is intended for C callers that need direct pixel access. No clipping, bounds or address validation is performed.

The prototype of the ReadUCRIndex function is Function(*Bitmap, BYTE *Data, RGB8 *RGB).

The Data parameter must point to a location within the Bitmap's graphical address space. The pixel value will be returned in the RGB parameter.

There is no colour-index equivalent because callers can read indexed pixel bytes directly through Data.

 ReadUCRPixelFUNCTION *Points to a C function that reads pixels from the bitmap in RGB format.

ReadUCRPixel points to the active low-level RGB pixel reader for X, Y coordinates. It is intended for C callers that need direct pixel access. No clipping or bounds checks are performed.

The prototype of the ReadUCRPixel function is Function(*Bitmap, LONG X, LONG Y, RGB8 *RGB).

The pixel value is returned in the RGB parameter. Because this function expands the pixel value to RGB components, ReadUCPixel or ReadUCRIndex may be faster when RGB decomposition is not required.

 SizeINTThe total size of the bitmap, in bytes.
 TransColourRGB8The transparent colour of the bitmap, in RGB format.

Pixels matching this colour are skipped by drawing operations that honour colour-key transparency.

Do not use colour-key transparency on bitmaps that use alpha transparency.

 TransIndexINTThe transparent colour of the bitmap, represented as an index.

TransIndex stores the transparent colour as a packed pixel value or palette index. Pixels matching this value are skipped by drawing operations that honour colour-key transparency.

Use TransColour for most updates. Set TransIndex directly only when the caller has already calculated the target bitmap's native pixel value or palette index. Do not use colour-key transparency on bitmaps that use alpha transparency.

 TypeBMPDefines the data type of the bitmap.

Type defines the bitmap layout, either BMP::PLANAR for planar bitmaps or BMP::CHUNKY for interleaved pixel data. Chunky is the default.

NameDescription
BMP::CHUNKYChunky pixel mode (default).
BMP::PLANARPlanar pixel mode separates pixel bits across multiple planes. Commonly used for single bit bitmap masks.
 WidthINTThe width of the bitmap, in pixels.

Width must be set before Query() or Init() can derive the bitmap layout.

Actions

The following actions are currently supported:

ClearClears the bitmap image to BkgdIndex.
ERR acClear(*Object)

Clear fills the full bitmap with the current background colour. The colour used by the operation is BkgdIndex, which is derived from Bkgd when the background colour is set through the RGB field.

To clear a bitmap to a different colour without changing the background fields, call DrawRectangle() with BAF::FILL. For alpha-capable bitmaps, setting BkgdIndex to zero is an efficient way to clear the image to transparent black.

Error Codes
OkayOperation successful.
LockFailedFailed to lock a required resource
CopyDataCopies bitmap image data to other bitmaps with colour remapping enabled.
ERR acCopyData(*Object, OBJECTID Dest)
ParameterDescription
DestThe unique ID of the destination object.

CopyData copies this bitmap into another initialised Bitmap object. Other destination classes are not supported.

The copy is clipped to the destination dimensions. If the destination is wider or taller than the source, the exposed area is cleared to the destination bitmap's background colour.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function
NullArgsFunction call missing argument value(s)
DrawClears the bitmap image to BkgdIndex.
ERR acDraw(*Object, DOUBLE X, DOUBLE Y, DOUBLE Width, DOUBLE Height)
ParameterDescription
XThe X position of the region to be drawn.
YThe Y position of the region to be drawn.
WidthThe width of the region to be drawn.
HeightThe height of the region to be drawn.

Draw fills the full bitmap with the current background colour. It is equivalent to drawing a filled rectangle over the entire bitmap with BkgdIndex.

FlushFlushes pending graphics operations and returns when the accelerator is idle.
ERR acFlush(*Object)

Flush synchronises pending graphics operations with the active graphics backend. Synchronisation is required before direct CPU access to accelerator-managed bitmap memory.

Clients do not need to call this function if solely using the graphics methods provided in the Bitmap class.

InitInitialises a bitmap.
ERR InitObject(*Object)

Init prepares a queried bitmap for use. It validates the calculated bitmap state, allocates Data when required, configures platform-specific backing resources and selects the pixel access routines used by drawing operations.

If Data has already been supplied, Init uses the caller-provided memory. Otherwise allocation is controlled by MemType and Flags. Width and Height must be set before this action is called.

Error Codes
OkayOperation successful.
NoSupportOperation not supported
QueryAttempt to Query() failed
FieldNotSetA required field value is undefined
AllocMemoryFailed to create a new memory block
SystemCallA call to the host system has failed
LockLocks the bitmap surface for direct read/write access.
ERR acLock(*Object)

Lock makes bitmap memory available through Data for direct CPU access. It is mainly required for bitmaps backed by a video or platform drawable resource; data-backed bitmaps are already CPU-accessible.

Call Unlock() when direct access is complete so platform resources can be released or synchronised.

Error Codes
OkayOperation successful.
NoDataNo data is available for use
LockFailedFailed to lock a required resource
NoSupportOperation not supported
FieldNotSetA required field value is undefined
AllocMemoryFailed to create a new memory block
SystemCallA call to the host system has failed
CreateResourceFailed to create a new resource
QueryPopulates a bitmap with pre-initialised/default values prior to initialisation.
ERR acQuery(*Object)

Query calculates the bitmap's derived fields without allocating image memory. It resolves values such as Type, BytesPerPixel, BitsPerPixel, AmtColours, ByteWidth, LineWidth, PlaneMod and Size from the fields already set by the caller.

At minimum, Width and Height must be positive. If format fields are incomplete, Query derives a compatible format where possible; for example, BytesPerPixel set to 2 implies a 16-bit bitmap.

Error Codes
OkayOperation successful.
InvalidDimensionA dimension specification is invalid
ReadReads raw image data from a bitmap object.
ERR acRead(*Object, std::span<int8_t> Buffer, INT *Result)
ParameterDescription
BufferA mutable buffer that will receive the data.
ResultThe Read action will write this parameter with the total number of bytes read into the Buffer.

Read copies bytes from Data into the supplied output buffer, starting at Position. Position is advanced by the number of bytes copied and the result count is returned in the action arguments.

If the requested length would pass the end of the bitmap data, Read truncates the transfer to the remaining byte count.

Error Codes
OkayOperation successful.
NoDataNo data is available for use
OutOfRangeA value is outside of the valid range
NullArgsFunction call missing argument value(s)
ResizeResizes a bitmap object's dimensions.
ERR acResize(*Object, DOUBLE Width, DOUBLE Height, DOUBLE Depth)
ParameterDescription
WidthThe new width of the object.
HeightThe new height of the object.
DepthThe new depth of the object.

Resize changes Width, Height and, unless BMF::FIXED_DEPTH is set, BitsPerPixel. Existing image content is not preserved.

If BMF::NEVER_SHRINK is set, requested dimensions smaller than the current bitmap are raised to the current size. If BMF::CLEAR is set, the resized bitmap is cleared to Bkgd.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function
NoSupportOperation not supported
UndefinedFieldA required field value is undefined
AllocMemoryFailed to create a new memory block
NullArgsFunction call missing argument value(s)
NotifiedUnknown error code.
SaveImageSaves the bitmap image to a writable object in PCX format.
ERR acSaveImage(*Object, OBJECTID Dest, CLASSID ClassID)
ParameterDescription
DestRefers to an object that will receive the encoded image data.
ClassIDThe Image class to use for encoding the image data.

SaveImage writes the current clipping region to Dest as PCX image data. Paletted bitmaps are written with a palette; true-colour bitmaps are written as three colour planes. If ColourSpace is CS::LINEAR_RGB, RGB values are converted to sRGB while the image is written.

Errors returned by the destination object's Write action are propagated to the caller.

Error Codes
OkayOperation successful.
NoSupportThe bitmap surface cannot be read by the CPU.
AllocMemoryThe read buffer for a host drawable could not be allocated.
BufferOverflowA buffer overflow has occurred
NullArgsFunction call missing argument value(s)
SeekChanges the current byte position for read/write operations.
ERR acSeek(*Object, DOUBLE Offset, INT Position)
ParameterDescription
OffsetThe desired offset to seek to, relative to the Position parameter.
PositionThe position that defines the starting point for Offset.

Seek sets Position from the supplied byte offset and origin. Positions before the start of the bitmap are clamped to zero, and positions beyond Size are clamped to Size.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function
NullArgsFunction call missing argument value(s)
UnlockUnlocks the bitmap surface once direct access is no longer required.
ERR acUnlock(*Object)

Unlock releases or synchronises any platform resources held for direct CPU access after Lock().

Error Codes
OkayOperation successful.
WriteWrites raw image data to a bitmap object.
ERR acWrite(*Object, std::span<const int8_t> Buffer, INT *Result)
ParameterDescription
BufferA buffer containing the data that will be written to the object.
ResultThis parameter with be updated with the total number of bytes written from the Buffer.

Write copies bytes from the supplied input buffer into Data, starting at Position. Position is advanced by the number of bytes written and the result count is returned in the action arguments.

The write must fit within the bitmap's allocated Size. Use Seek() to change the target position before writing.

Error Codes
OkayOperation successful.
NoDataNo data is available for use
OutOfSpaceOut of space. There is no available room to complete the request
NullArgsFunction call missing argument value(s)

Methods

The following methods are currently supported:

ConvertToLinearConverts a bitmap's colour space to linear RGB.
ERR bmp::ConvertToLinear(OBJECTPTR Object)

ConvertToLinear() converts the bitmap's clipped region from sRGB to linear RGB. If BMF::ALPHA_CHANNEL is set, pixels with an alpha value of zero are left unchanged.

ColourSpace is set to CS::LINEAR_RGB on completion. The method returns ERR::NothingDone if the bitmap is already marked as linear RGB.

This method currently requires a 32-bit bitmap.

Error Codes
OkayOperation successful.
NothingDoneThe Bitmap's content is already in linear RGB format.
InvalidDimensionThe clipping region is invalid.
InvalidStateThe Bitmap is not in the expected state.
ConvertToRGBConverts a bitmap's colour space to standard RGB.
ERR bmp::ConvertToRGB(OBJECTPTR Object)

ConvertToRGB() converts the bitmap's clipped region from linear RGB to sRGB. If BMF::ALPHA_CHANNEL is set, pixels with an alpha value of zero are left unchanged.

ColourSpace is set to CS::SRGB on completion. The method returns ERR::NothingDone if the bitmap is already marked as sRGB.

This method currently requires a 32-bit bitmap.

Error Codes
OkayOperation successful.
NothingDoneThe bitmap's content is already in sRGB format.
InvalidDimensionThe clipping region is invalid.
InvalidStateThe bitmap is not in the expected state.
CopyAreaCopies a rectangular area from one bitmap to another.
ERR bmp::CopyArea(OBJECTPTR Object, objBitmap * DestBitmap, BAF Flags, INT X, INT Y, INT Width, INT Height, INT XDest, INT YDest)
ParameterDescription
DestBitmapThe target bitmap.
FlagsOptional flags.
XThe horizontal position of the area to be copied.
YThe vertical position of the area to be copied.
WidthThe width of the area.
HeightThe height of the area.
XDestThe horizontal position to copy the area to.
YDestThe vertical position to copy the area to.

CopyArea() copies a rectangular region from this bitmap to DestBitmap. The source rectangle starts at X, Y and has the supplied Width and Height; the destination position is XDest, YDest.

The operation is implemented by CopyArea() and supports the same BAF options.

Error Codes
OkayOperation successful.
MismatchThe target bitmap is not a close enough match to the source bitmap in order to perform the operation.
NullArgsFunction call missing argument value(s)
DemultiplyReverses the conversion process performed by Premultiply().
ERR bmp::Demultiply(OBJECTPTR Object)

Demultiply() restores straight RGB channel values after Premultiply() has converted them to premultiplied alpha. The method returns ERR::NothingDone if BMF::PREMUL is not set in Flags.

This method operates only on 32-bit bitmaps that have an alpha channel, and it processes only the current clipping region.

Error Codes
OkayOperation successful.
NothingDoneThe content is already normalised.
AllocMemoryFailed to create a new memory block
InvalidDimensionThe clipping region is invalid.
InvalidStateThe Bitmap is not in the expected state (32-bit with an alpha channel).
DrawRectangleDraws rectangles, both filled and unfilled.
ERR bmp::DrawRectangle(OBJECTPTR Object, INT X, INT Y, INT Width, INT Height, UINT Colour, BAF Flags)
ParameterDescription
XThe left-most coordinate of the rectangle.
YThe top-most coordinate of the rectangle.
WidthThe width of the rectangle.
HeightThe height of the rectangle.
ColourThe colour index to use for the rectangle.
FlagsSupports FILL and BLEND.

This method draws both filled and unfilled rectangles. The rectangle is drawn to the target bitmap at position (X, Y) with dimensions determined by the specified Width and Height. If the Flags parameter sets the FILL flag then the rectangle will be filled, otherwise the rectangle's outline will be drawn. The colour of the rectangle is determined by the pixel value in the Colour parameter.

The draw operation is clipped to the bitmap's current clipping region.

Error Codes
OkayOperation successful.
NullArgsFunction call missing argument value(s)
GetColourConverts Red, Green, Blue components into a single colour value.
ERR bmp::GetColour(OBJECTPTR Object, INT Red, INT Green, INT Blue, INT Alpha, UINT * Colour)
ParameterDescription
RedRed component from 0 - 255.
GreenGreen component from 0 - 255.
BlueBlue component value from 0 - 255.
AlphaAlpha component value from 0 - 255.
ColourThe resulting colour value will be returned here.

The GetColour() method is used to convert Red, Green, Blue and Alpha colour components into a single colour index that can be used for directly writing colours to the bitmap. The result is returned in the Colour parameter.

Error Codes
OkayOperation successful.
NullArgsFunction call missing argument value(s)
PremultiplyPremultiplies RGB channel values by the alpha channel.
ERR bmp::Premultiply(OBJECTPTR Object)

Premultiply() converts RGB values in the current clipping region to premultiplied-alpha form. The formula applied to each colour channel is (Colour * Alpha + 0xff)>>8. The alpha channel is not changed.

This method operates only on 32-bit bitmaps that have an alpha channel. If the bitmap is already marked as premultiplied, the method returns ERR::NothingDone.

The process can be reversed with a call to Demultiply().

Error Codes
OkayOperation successful.
NothingDoneThe content is already premultiplied.
InvalidDimensionThe clipping region is invalid.
InvalidStateThe Bitmap is not in the expected state (32-bit with an alpha channel)
SetClipRegionSets a clipping region for a bitmap object.
ERR bmp::SetClipRegion(OBJECTPTR Object, INT Left, INT Top, INT Right, INT Bottom)
ParameterDescription
LeftThe horizontal start of the clip region.
TopThe vertical start of the clip region.
RightThe exclusive right edge of the clip region.
BottomThe exclusive bottom edge of the clip region.

SetClipRegion() updates the bitmap's clipping region. Drawing operations are restricted to the combined region.

This method is implemented by SetClipRegion().

Error Codes
OkayOperation successful.
NullArgsFunction call missing argument value(s)
Bitmap class documentation © Paul Manias © 2003-2026

BAF Type

Instructions for basic graphics operations.

NameDescription
BAF::BLENDEnable alpha blending to the destination if the source supports an alpha channel.
BAF::COPYSpecial CopyArea() option that avoids blending when the destination pixel is empty.
BAF::DITHERPerform dithering if the colour formats differ between the source and destination.
BAF::FILLFor primitive operations such as DrawRectangle(), this will fill the shape with a solid colour or texture.
BAF::LINEARUse linear interpolation to improve the quality of alpha blending.
Bitmap module documentation © Paul Manias © 2003-2026

BLM Type

Defines the blending algorithm to use when transparent pixels are rendered to the bitmap.

NameDescription
BLM::AUTOUse the most suitable of the available algorithms.
BLM::GAMMAUse gamma correct blending. This algorithm is slow but produces a high quality result.
BLM::LINEARUse linear blending. Applicable if the bitmap is in linear colour space.
BLM::NONENever blend transparent pixels, just copy as-is.
BLM::SRGBUse sRGB linear blending. This algorithm is extremely efficient but produces poor quality results.
Bitmap module documentation © Paul Manias © 2003-2026

BMF Type

Bitmap flags

NameDescription
BMF::ACCELERATED_2D2D video acceleration is available.
BMF::ACCELERATED_3D3D video acceleration is available.
BMF::ALPHA_CHANNELFor 32-bit images, indicates that an alpha channel is present.
BMF::BLANK_PALETTEForces a blank/black palette on initialisation.
BMF::CLEARClear graphics on initialisation and when resizing.
BMF::COMPRESSEDThe bitmap data is compressed.
BMF::FIXED_DEPTHPrevent changing of bitmap depth after initialisation (e.g. via Resize()).
BMF::INVERSE_ALPHAIndicates reverse alpha blending, higher values are transparent.
BMF::MASKDeclare the Bitmap as a 1 or 8 bit mask. Must be set in conjunction with the Bitmap⇒BitsPerPixel field on initialisation.
BMF::NEVER_SHRINKIgnore resize requests that would shrink the size of the bitmap.
BMF::NO_DATADo not allocate memory in the Data field on initialisation.
BMF::PREMULThe RGB values are premultiplied (32-bit only).
BMF::QUERIEDAutomatically set after a Query() on the bitmap.
BMF::TRANSPARENTIndicates that the bitmap utilises a transparent colour. This is automatically set if the Bitmap⇒TransIndex or Bitmap⇒TransColour is defined, and support exists in functions such as CopyArea().
BMF::USERThis user flag can be used to tag bitmaps with special meaning. Not used internally.
Bitmap module documentation © Paul Manias © 2003-2026

BMP Type

Bitmap types

NameDescription
BMP::CHUNKYChunky pixel mode (default).
BMP::PLANARPlanar pixel mode separates pixel bits across multiple planes. Commonly used for single bit bitmap masks.
Bitmap module documentation © Paul Manias © 2003-2026

BMT Type

Bitmap memory type.

NameDescription
BMT::DATAThe default type, indicates a standard memory allocation from system RAM.
BMT::TEXTUREIdentifies non-displayable video memory, e.g. texture graphics.
BMT::VIDEOIdentifies video memory, such as the frame buffer.
Bitmap module documentation © Paul Manias © 2003-2026

CS Type

Colour space options.

NameDescription
CS::CIE_LABCartesian L*a*b* colour space defined by CIE 15.
CS::CIE_LCHPolar L*CHab colour space defined by CIE 15.
CS::LINEAR_RGBLinear RGB is used to improve colour balance in blending operations.
CS::SRGBThe default colour-space is sRGB.
Bitmap module documentation © Paul Manias © 2003-2026

ColourFormat Structure

FieldTypeDescription
RedShiftUINT8Right shift value for red (15/16 bit formats only)
GreenShiftUINT8Right shift value for green
BlueShiftUINT8Right shift value for blue
AlphaShiftUINT8Right shift value for alpha
RedMaskUINT8Unshifted mask value for red (ranges from 0x00 to 0xff)
GreenMaskUINT8Unshifted mask value for green
BlueMaskUINT8Unshifted mask value for blue
AlphaMaskUINT8Unshifted mask value for alpha
RedPosUINT8Left shift/positional value for red
GreenPosUINT8Left shift/positional value for green
BluePosUINT8Left shift/positional value for blue
AlphaPosUINT8Left shift/positional value for alpha
BitsPerPixelUINT8Number of bits per pixel for this format.
Bitmap class documentation © Paul Manias © 2003-2026