How to resolve the algorithm Bitmap/Write a PPM file step by step in the Stata 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 Stata 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 Stata programming language

Source code in the stata programming language

mata
void writeppm(name, r, g, b) {
	n = rows(r)
	p = cols(r)
	f = fopen(name, "w")
	fput(f, "P3")
	fput(f, strofreal(p) + " " + strofreal(n) + " 255")
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= p; j++) {
			fput(f, strofreal(r[i,j]) + " " + strofreal(g[i,j]) + " " + strofreal(b[i,j]))
		}
	}
	fclose(f)
}

r = J(1, 6, (0::5) * 51)
g = J(6, 1, (0..5) * 51)
b = J(6, 6, 255)
writeppm("image.ppm", r, g, b)
end


  

You may also check:How to resolve the algorithm Top rank per group step by step in the Arturo programming language
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the COBOL programming language
You may also check:How to resolve the algorithm Binary digits step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Nautical bell step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Wortel programming language