Bitmap/Read an image through a pipe: Difference between revisions

→‎{{header|AutoHotkey}}: changed from ppm3 to ppm6
(added autohotkey implementation)
(→‎{{header|AutoHotkey}}: changed from ppm3 to ppm6)
Line 7:
{{works with | AutoHotkey_L}}
Uses [http://www.autohotkey.com/forum/viewtopic.php?t=16823 StdoutTovar.ahk]
<lang AutoHotkey>ppm := Run("cmd.exe /c convert lena50.jpg -compress none ppm:-")
; pipe in from imagemagick
img := ppm_read("", ppm) ;
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("lena50lena50copy.ppm")
return
ppm_read(filename, ppmo=0) ; only ppm3ppm6 files supported (ascii)
{
if !ppmo ; if image not already in memory, read from filename
fileread, ppmo, % filename, utf-8
 
index := 1
pos := 1
 
loop, parse, ppmo, `n, `r
{
if (substr(A_LoopField, 1, 1) == "#")
continue
loop,
ppm_nocomment .= A_LoopField "`n"
{ }
if while !pos := regexmatch(ppm_nocommentppmo, "\d+", pixel, pos)
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
pos := regexmatch(ppm_nocommentppmo, "\s", x, pos)
index ++
}
Line 42 ⟶ 45:
maxcolor := bitmap4
bitmap := Bitmap(width, height, color(0,0,0))
index := 1
widthi := 1
heightj := 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)
 
{
indexif :(j == 1width)
pixel := Color(pix1, pix2, pix3)
bitmap[height, width] := pixel
if (width == bitmap.width)
{
widthj := 1
heighti += 1
}
else
widthj++
}
return bitmap
pos := regexmatch(ppm_nocomment, "\s", x, pos)
}
 
return bitmap
#include bitmap_storage.ahk ; from http://rosettacode.org/wiki/Basic_bitmap_storage/AutoHotkey
#include run.ahk ; http://www.autohotkey.com/forum/viewtopic.php?t=16823
Anonymous user