ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:packing

This is an old revision of the document!


Value packing

All ACS integers are 32-bit. Value packing functions let you store four 8-bit integers or two 16-bit integers in one 32-bit int variable. This can be useful, for example, to store RGBA colors in a single variable. Or to store big arrays using less memory.

Packing 8-bit integers

int PackBytes(int b1, int b2, int b3, int b4) returns a 32-bit integer containing 4 bytes. Byte values must be in [0, 255] range.

  • int UnpackByte1(int packed) – returns the first packed byte.
  • int UnpackByte2(int packed) – returns the second packed byte.
  • int UnpackByte3(int packed) – returns the third packed byte.
  • int UnpackByte4(int packed) – returns the fourth packed byte.

Example:

int color = PackBytes(255, 128, 0, 255); // Orange

int r = UnpackByte1(color); // 255
int g = UnpackByte2(color); // 128
int b = UnpackByte3(color); // 0
int alpha = UnpackByte4(color); // 255
new/packing.1518895217.txt.gz · Last modified: 2018/02/17 21:20 by korshun