Bitmap/Read a PPM file: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
(5 intermediate revisions by 2 users not shown)
Line 1,670:
* doing formatted I/O with Fortran is a pain... And unformatted does not mean ''free''; Fortran2003 has ''streams'', but they are not implemented (yet) in GNU Fortran compiler. Here (as in the write part) I've tried to handle the PPM format through formatted I/O. The tests worked but I have not tried still everything.
* comments after the first line are not handled
 
=={{header|FreeBASIC}}==
{{trans|Yabasic}}
<syntaxhighlight lang="vbnet">Dim As String imagen = "Lena.ppm"
 
Sub readPPM (fs As String)
Dim As Integer x, y, ancho, alto
Dim As String t, kolor
Dim As Ubyte r, g, b
If Len(fs) = 0 Then Print "No PPM file name indicated.": Exit Sub
Dim As Long ff = Freefile
Open fs For Binary As #ff
If Err Then Print "File "; fs; " not found.": Exit Sub
Input #ff, t, ancho, alto, kolor
If t = "P6" Then
Screenres ancho, alto, 32
For y = 0 To alto - 1
For x = 0 To ancho - 1
Get #ff, , r
Get #ff, , g
Get #ff, , b
Pset (x, y), Rgb(r, g, b)
Next x
Next y
Close #ff
Else
Print "File is NOT PPM P6 type."
End If
End Sub
 
readPPM(imagen)
Sleep</syntaxhighlight>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package raster
Line 1,827 ⟶ 1,864:
 
public static void main(String[] aArgs) throws IOException {
// Using the file created in the Bitmap task
String filePath = "C:/Users/psnow/Desktop/output.ppm";
reader = new BufferedInputStream( new FileInputStream(filePath) );
Line 1,848 ⟶ 1,886:
// Remove any comments before reading data
reader.mark(1);
while ( reader.read() == START_OF_COMMENT ) {
while ( reader.read() != END_OF_LINE );
reader.mark(1);
Line 1,872 ⟶ 1,910:
// Convert to gray scale and save to a file
bitmap.convertToGrayscale();
File grayFile = new File("C:/Users/psnow/Desktop/outputGray.jpg");
ImageIO.write((RenderedImage) bitmap.getImage(), "jpg", grayFile);
}
Line 1,949 ⟶ 1,987:
}
</syntaxhighlight>
{{ out }}
[[Media:ColouredJava.png]] & [[Media:GrayscaleJava.png]]
 
=={{header|Julia}}==
Line 3,517 ⟶ 3,557:
{{libheader|DOME}}
This assumes that [https://rosettacode.org/wiki/File:Lenna100.jpg Lenna100.jpg], a 512 x 512 color image of the eponymous lady, has already been converted to Lenna100.ppm using a variation of the 'Write a PPM file' task.
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, ImageData, Color
import "dome" for Window, Process
import "io" for FileSystem
Line 3,543 ⟶ 3,583:
loadPPMFile(fileName) {
var ppm = FileSystem.load(fileName)
var count = ppm.count // ensure file is fully loaded before proceeding
if (ppm[0..1] != "P6") {
System.print("The loaded file is not a P6 file.")
Line 3,592 ⟶ 3,633:
 
var Game = Bitmap.new("Lenna100.ppm", "Lenna100_gs.jpg", 1048, 512)</syntaxhighlight>
 
=={{header|XPL0}}==
The simplicity of redirecting an input file on the command line doesn't
2,123

edits