Bitmap/Read a PPM file: Difference between revisions

Content added Content deleted
(→‎{{header|AutoHotkey}}: fixed error in pixel making loop)
Line 89: Line 89:
end;</lang>
end;</lang>
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with | AutoHotkey_L}}
<lang AutoHotkey>img := ppm_read("blue.ppm")
Only ppm3 ascii files supported.

<lang AutoHotkey>img := ppm_read("lena50.ppm") ;
x := img[4,4] ; get pixel(4,4)
x := img[4,4] ; get pixel(4,4)
msgbox % "img: 4,4,R,G,B, RGB: " x.R ", " x.G ", " x.B ", " x.rgb()
msgbox % "img: 4,4,R,G,B, RGB: " x.R ", " x.G ", " x.B ", " x.rgb()
img.write("bluecopy.ppm")
img.write("lena50copy.ppm")
return
return

ppm_read(filename)
ppm_read(filename, ppmo=0) ; only ppm3 files supported (ascii)
{
{
if !ppmo ; if image not already in memory, read from filename
fileread, ppmo, % filename, utf-8
fileread, ppmo, % filename, utf-8
loop, parse, ppmo, `n, `r
loop, parse, ppmo, `n, `r
Line 113: Line 117:
Break
Break
index ++
index ++
}
}

type := bitmap1
type := bitmap1
width := bitmap2
width := bitmap2
Line 121: Line 125:
maxcolor := bitmap4
maxcolor := bitmap4
bitmap := Bitmap(width, height, color(0,0,0))
bitmap := Bitmap(width, height, color(0,0,0))

index := 1
index := 1
width := 1
width := 1
height := 1
height := 1

while pos := regexmatch(ppm_nocomment, "\d+", pixel, pos)
while pos := regexmatch(ppm_nocomment, "\d+", pixel, pos)
{
{
pix%A_Index% := pixel
pix%index% := pixel
index++
index++
if (index > 3)
if (index > 3)
Line 143: Line 147:
width++
width++
}
}

pos := regexmatch(ppm_nocomment, "\s", x, pos)
pos := regexmatch(ppm_nocomment, "\s", x, pos)
}


}
return bitmap
return bitmap
}
}

#include bitmap_storage.ahk ; from http://rosettacode.org/wiki/Basic_bitmap_storage/AutoHotkey
#include bitmap_storage.ahk ; from http://rosettacode.org/wiki/Basic_bitmap_storage/AutoHotkey
</lang>
</lang>