31 lines
730 B
Plaintext
31 lines
730 B
Plaintext
MODULE PPM;
|
|
|
|
IMPORT Bitmap, Wr, FileWr, Pathname;
|
|
FROM Fmt IMPORT F, Int;
|
|
|
|
<*FATAL ANY*>
|
|
|
|
VAR imgfilewr: FileWr.T;
|
|
|
|
PROCEDURE Create(imgfile: Pathname.T; img: Bitmap.T) =
|
|
VAR height := LAST(img^);
|
|
width := LAST(img[0]);
|
|
color: Bitmap.Pixel;
|
|
BEGIN
|
|
imgfilewr := FileWr.Open(imgfile);
|
|
Wr.PutText(imgfilewr, F("P6\n%s %s\n255\n", Int(height + 1), Int(width + 1)));
|
|
FOR i := 0 TO height DO
|
|
FOR j := 0 TO width DO
|
|
color := img[i,j];
|
|
Wr.PutChar(imgfilewr, VAL(color.R, CHAR));
|
|
Wr.PutChar(imgfilewr, VAL(color.G, CHAR));
|
|
Wr.PutChar(imgfilewr, VAL(color.B, CHAR));
|
|
END;
|
|
END;
|
|
Wr.PutChar(imgfilewr, '\n');
|
|
Wr.Flush(imgfilewr);
|
|
END Create;
|
|
|
|
BEGIN
|
|
END PPM.
|