- 4.51.2.4.61. -
Table of Contents
4. Standard Units
4.51. ObjGfx40 - ObjectGraphics 4.0 Unit
4.51.2. ObjGfx40 Unit Object Types
4.51.2.4. ogSurface object
4.51.2.4.61. ogUnpackRGB()
4.51.2.4.61. ogUnpackRGB()
Targets: MS-DOS, Win32 console
ObjGfx40 Unit
Unpacks a pixel.
Declaration:
procedure ogUnpackRGB(colour:uInt32; var red, green, blue:uInt8);
Remarks:
Breaks a packed pixel apart based on the bitdepth and pixel format
of the surface. Performs a lookup in the palette array for 8BPP surfaces.
See also:
Sample code:
{ogUnpackRGB.pas}
uses
ObjGfx40, CRT;
var
buf:^ogSurface;
xx, yy, zz:uInt32;
r, g, b:uInt8;
begin
new(buf, ogInit);
{Create a buffer large enough for an RGB cube using the default
mac format, which is ARGB 4:4:4:4}
if not buf^.ogCreate(384, 384, OG_MAC_PIXFMT_16BPP) then
begin
writeln('Error allocating memory for buffer');
halt
end;
{Set up the screen}
if not screen^.ogCreate(1024, 768, OG_PIXFMT_32BPP) then
begin
writeln('Error setting video mode');
halt
end;
{Draw a standard RGB cube to Buf}
zz:=1;
repeat
with buf^ do
for yy:=0 to 255 do
for xx:=0 to 255 do
if (yy = 0) or (xx = 255) or (zz = 255) then
ogSetPixel(128+xx-(zz div 2), yy+(zz div 2),
ogRGB(xx, 255-yy, zz));
inc(zz,2);
until (keyPressed) or (zz > 255);
{Draw a standard RGB cube to the screen for reference}
zz:=1;
repeat
with screen^ do
for yy:=0 to 255 do
for xx:=0 to 255 do
if (yy = 0) or (xx = 255) or (zz = 255) then
ogSetPixel(512+128+xx-(zz div 2), yy+(zz div 2),
ogRGB(xx, 255-yy, zz));
inc(zz,2);
until (keyPressed) or (zz > 255);
{Now copy a buffer of one pixel format to another (buf to screen)}
for yy:=0 to Buf^.ogGetMaxX do
for xx:=0 to Buf^.ogGetMaxY do
begin
{Unpack the pixel at xx,yy to r, g, b}
buf^.ogUnpackRGB(buf^.ogGetPixel(xx, yy), r, g, b);
{Repack and draw the pixel to the screen}
screen^.ogSetPixel(xx, yy, screen^.ogRGB(r, g, b));
end;
readKey;
dispose(buf, ogDone);
end.
- 4.51.2.4.61. -