Bitmap/Write a PPM file: Difference between revisions
→Ada: Fixed tipo an better reference
(→Ada: Fixed tipo an better reference) Tags: Mobile edit Mobile web edit |
|||
(5 intermediate revisions by 4 users not shown) | |||
Line 76:
print(bitmap.writeppmp3())
File(‘tmp.ppm’,
{{out}}
Line 89:
0 0 0 255 255 255 0 0 0 0 0 0
</pre>
=={{header|Action!}}==
{{libheader|Action! Bitmap tools}}
Line 203 ⟶ 204:
<syntaxhighlight lang="ada">with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Bitmap_Store; use Bitmap_Store;
-- This package is defined in the Bitmap task.
procedure Put_PPM (File : File_Type; Picture : Image) is
Line 228 ⟶ 232:
end Put_PPM;</syntaxhighlight>
The solution writes the image into an opened file. The file format might fail to work on certain [[OS]]es, because output might mangle control characters like LF, CR, FF, HT, VT etc. The OS might also limit the line length of a text file. In general it is a bad idea to mix binary and text output in one file. This solution uses ''stream I/O'', which should be as portable as possible.
=={{header|Aime}}==
<syntaxhighlight lang="aime">integer i, h, j, w;
Line 269 ⟶ 274:
The static file provides templates for writing a PPM in either raw or plain format, regardless of what type you use to represent a pixel. The dynamic file, however, provides implementations ''only'' for the <code>rgb24</code> type defined in <code>bitmap_task.sats</code>.
===The ATS static file===
Line 357 ⟶ 360:
else
let
val @(r, g, b) = rgb24_values pix[x, y]
in
fprintln! (outf, r, " ", g, " ", b);
Line 379 ⟶ 382:
main0 () =
let
val bgcolor = rgb24_make (217u, 217u, 214u)
and fgcolor1 = rgb24_make (210, 0, 0)
and
stadef w = 300
Line 2,531 ⟶ 2,532:
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-str}}
<syntaxhighlight lang="
import "dome" for Window, Process
import "io" for FileSystem
import "./str" for Strs
class Bitmap {
Line 2,555 ⟶ 2,557:
init() {
// write bitmap to a PPM file
var ppm = ["P6\n%(_w) %(_h)\n255\n"]
for (y in 0..._h) {
for (x in 0..._w) {
var c = pget(x, y)
ppm
ppm
ppm
}
}
FileSystem.save("output.ppm", Strs.concat(ppm))
Process.exit(0)
}
Line 2,578 ⟶ 2,580:
var Game = Bitmap.new("Bitmap - write to PPM file", 320, 320)</syntaxhighlight>
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
|