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: | Line 90: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
{{works with | AutoHotkey_L}} |
{{works with | AutoHotkey_L}} |
||
Only |
Only ppm6 files supported. |
||
<lang AutoHotkey>img := ppm_read("lena50.ppm") ; |
<lang AutoHotkey>img := ppm_read("lena50.ppm") ; |
||
x := img[4,4] ; get pixel(4,4) |
x := img[4,4] ; get pixel(4,4) |
||
y := img[24,24] ; get pixel(24,24) |
|||
msgbox % "img: 4,4,R,G,B, RGB: " x.R ", " x.G ", " x.B ", " x.rgb() |
|||
msgbox % x.rgb() " " y.rgb() |
|||
img.write("lena50copy.ppm") |
img.write("lena50copy.ppm") |
||
return |
return |
||
ppm_read(filename, ppmo=0) ; only |
ppm_read(filename, ppmo=0) ; only ppm6 files supported |
||
{ |
{ |
||
if !ppmo ; if image not already in memory, read from filename |
if !ppmo ; if image not already in memory, read from filename |
||
fileread, ppmo, % filename |
fileread, ppmo, % filename |
||
⚫ | |||
⚫ | |||
loop, parse, ppmo, `n, `r |
loop, parse, ppmo, `n, `r |
||
{ |
{ |
||
if (substr(A_LoopField, 1, 1) == "#") |
if (substr(A_LoopField, 1, 1) == "#") |
||
continue |
continue |
||
loop, |
|||
ppm_nocomment .= A_LoopField "`n" |
|||
{ |
|||
⚫ | |||
⚫ | |||
break |
|||
⚫ | |||
⚫ | |||
{ |
|||
⚫ | |||
bitmap%A_Index% := pixel |
bitmap%A_Index% := pixel |
||
if (index == 4) |
if (index == 4) |
||
Break |
Break |
||
⚫ | |||
index ++ |
index ++ |
||
⚫ | |||
} |
} |
||
Line 125: | Line 128: | ||
maxcolor := bitmap4 |
maxcolor := bitmap4 |
||
bitmap := Bitmap(width, height, color(0,0,0)) |
bitmap := Bitmap(width, height, color(0,0,0)) |
||
index := 1 |
index := 1 |
||
i := 1 |
|||
j := 1 |
|||
bits := pos |
|||
loop % width * height |
|||
while pos := regexmatch(ppm_nocomment, "\d+", pixel, pos) |
|||
{ |
{ |
||
bitmap[i, j, "r"] := numget(ppmo, 3 * A_Index + bits, "uchar") |
|||
pix%index% := pixel |
|||
bitmap[i, j, "g"] := numget(ppmo, 3 * A_Index + bits + 1, "uchar") |
|||
index++ |
|||
bitmap[i, j, "b"] := numget(ppmo, 3 * A_Index + bits + 2, "uchar") |
|||
if (index > 3) |
|||
{ |
|||
if (j == width) |
|||
pixel := Color(pix1, pix2, pix3) |
|||
bitmap[height, width] := pixel |
|||
if (width == bitmap.width) |
|||
{ |
{ |
||
j := 1 |
|||
i += 1 |
|||
} |
} |
||
else |
else |
||
j++ |
|||
} |
} |
||
⚫ | |||
pos := regexmatch(ppm_nocomment, "\s", x, pos) |
|||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |