packed record TBitmapChar

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TBitmapChar = packed record

Description

TBitmapChar record defines the bitmap character. TBitmapChar will not be directly used as a type of some variable. Instead, we use it only to define PBitmapChar.

Sample character may look like this :

      CharX = record
        Info: TBitmapCharInfo
        Data: packed array[0..23]of byte;
      end =
      ( Info : ( Alignment : 2;
                 XOrig : 0; YOrig : 0;
                 XMove : 10; YMove : 0;
                 Width : 8; Height : 12 );
        Data : ($AA, $00,
                $BB, $00,
                ....
               );
      );
    

Notes about example above: The row has Width = 8 which means that we need only 8 bits (one byte) to store it. But since Alignment = 2, we need to use some multiply of 2 bytes to store a row, which means that each row actually uses 2 bytes (even though the contents of 2nd byte are always meaningless). E.g. if you will pass this data to OpenGL, you should appropriately use glPixelStorei, so that OpenGL knows that data is aligned to 2 bytes, and then 2nd byte of each row will indeed be ignored by OpenGL.

Sure, this is rather extreme example, since in this case we're wasting half memory just to get Alignment = 2. Well, this is only an example. Also, Alignment may sometimes give us better speed. E.g. for OpenGL's glBitmap (even though if you will use OpenGL's display list, it will not actually matter that much, since then OpenGL will probably internally convert to the best alignment anyway).

Summing the example, we have 2 bytes and 12 rows (Height = 2) so we need 24 bytes to store this character.

The precise formula to calculate how many bytes are used to store a character is

  • RoundUpToMultiple( (Char.Info.Width + 7) div 8, Char.Info.Alignment ) * Char.Info.Height

  • Or, more readable, BitmapCharRowByteLength(Char.Info.Width, Char.Info.Alignment) * Char.Info.Height

  • Or, even more readable, just BitmapCharRowByteLength(Char) * Char.Info.Height

Rows are specified in Data from lower to upper (just like OpenGL's glBitmap likes).

Note that this is packed record so I'm sure that

      SizeOf(record
        Info: TBitmapCharInfo;
        Data: packed array[0..n]of byte;
      ) = SizeOf(TBitmapCharInfo) + (n+1) * SizeOf(Byte)
    

I.e. there's no padding between Info and Data.

Overview

Fields

Info: TBitmapCharInfo;
Data: packed[0 .. MaxInt - 1 - SizeOf(TBitmapCharInfo)]of byte;

Description

Fields

Info: TBitmapCharInfo;
 
Data: packed[0 .. MaxInt - 1 - SizeOf(TBitmapCharInfo)]of byte;
 

Generated by PasDoc 0.12.1 on 2013-02-04 20:26:49