Bitmap/Read a PPM file: Difference between revisions
Content added Content deleted
(→{{header|AutoHotkey}}: fixed error in pixel making loop) |
(→{{header|AutoHotkey}}: read ppm6 instead of ppm3) |
||
Line 90:
=={{header|AutoHotkey}}==
{{works with | AutoHotkey_L}}
Only
<lang AutoHotkey>img := ppm_read("lena50.ppm") ;
x := img[4,4] ; get pixel(4,4)
y := img[24,24] ; get pixel(24,24)
msgbox % x.rgb() " " y.rgb()
img.write("lena50copy.ppm")
return
ppm_read(filename, ppmo=0) ; only
{
if !ppmo ; if image not already in memory, read from filename
fileread, ppmo, % filename
index := 1 ▼
pos := 1▼
loop, parse, ppmo, `n, `r
{
if (substr(A_LoopField, 1, 1) == "#")
continue
loop,
{
▲ index := 1
break
▲ pos := 1
▲ while pos := regexmatch(ppm_nocomment, "\d+", pixel, pos)
pos := regexmatch(ppm_nocomment, "\s", x, pos)▼
bitmap%A_Index% := pixel
if (index == 4)
Break
index ++
}▼
}
Line 125 ⟶ 128:
maxcolor := bitmap4
bitmap := Bitmap(width, height, color(0,0,0))
index := 1
bits := pos
loop % width * height
{
bitmap[i, j, "r"] := numget(ppmo, 3 * A_Index + bits, "uchar")
bitmap[i, j, "g"] := numget(ppmo, 3 * A_Index + bits + 1, "uchar")
bitmap[i, j, "b"] := numget(ppmo, 3 * A_Index + bits + 2, "uchar")
{
}
else
}
return bitmap ▼
}
#include bitmap_storage.ahk ; from http://rosettacode.org/wiki/Basic_bitmap_storage/AutoHotkey</lang>▼
▲ return bitmap
▲}
▲#include bitmap_storage.ahk ; from http://rosettacode.org/wiki/Basic_bitmap_storage/AutoHotkey
=={{header|C}}==
|