How to resolve the algorithm Bitmap/Write a PPM file step by step in the Modula-3 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bitmap/Write a PPM file step by step in the Modula-3 programming language
Table of Contents
Problem Statement
Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 preferred). (Read the definition of PPM file on Wikipedia.)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bitmap/Write a PPM file step by step in the Modula-3 programming language
Source code in the modula-3 programming language
INTERFACE PPM;
IMPORT Bitmap, Pathname;
PROCEDURE Create(imgfile: Pathname.T; img: Bitmap.T);
END PPM.
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.
You may also check:How to resolve the algorithm Conditional structures step by step in the SSEM programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the AdvPL programming language
You may also check:How to resolve the algorithm User input/Text step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Deming's funnel step by step in the jq programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Rust programming language