RosettaCodeData/Task/Bitmap-Write-a-PPM-file/XPL0/bitmap-write-a-ppm-file.xpl0

39 lines
1.2 KiB
Plaintext

include c:\cxpl\codes; \intrinsic 'code' declarations
def Width=180, Height=135, Color=$123456;
proc WriteImage; \Write screen image to a a PPM file
int X, Y, C;
[Text(3,"P6 "); IntOut(3,Width); ChOut(3,^ ); IntOut(3,Height); Text(3," 255
");
for Y:= 0 to Height-1 do
for X:= 0 to Width-1 do
[C:= ReadPix(X, Y);
ChOut(3, C>>16);
ChOut(3, C>>8);
ChOut(3, C);
];
];
proc OpenOutFile(FN); \Open for output the named file
char FN; \file name string
int H; \handle
[H:= FOpen(FN, 1);
FSet(H, ^o); \small buffer allows multiple files, and it is
OpenO(3); \ closed automatically when the program exits
];
proc MakeImage; \Make a bitmap image
int X, Y;
[for Y:= 0 to Height-1 do \fill area with Color
for X:= 0 to Width-1 do
Point(X, Y, Color);
Move(60, 60); HexOut(6, ReadPix(0,0)); \show hex value of color of pixel at 0,0
];
[SetVid($112); \set display for 640x480 graphics in 24-bit RGB color
MakeImage;
OpenOutFile("IMAGE.PPM");
WriteImage;
SetVid(3); \restore display to normal text mode
]