type rgb byte r,g,b
type rgba byte r,g,b,a
string tab=chr(9),cr=chr(13)+chr(10)
'
'
'==============
class RawObject
'==============
'
'handling raw RGB raster data
'----------------------------
'
string s,t
sys mx,my,ot
'
method readfile(n as string)
s=getfile n
end method
'
method setXY(sys px,py)
mx=px : my=py
end method
'
method getpixel(sys x,y) as sys
let p=(y*mx + x)*sizeof rgb + *s
return *p or 0xff000000 'set alpha channel to max 0xff
end method
'
method splitpixel(sys pix, byte*r, byte*g, byte*b, byte*a)
'rgba c at @pix
rgba * c : @c=@pix
r=c.r
g=c.g
b=c.b
a=c.a
end method
'
method cleartext()
ot=0 : t=""
end method
'
method addtext(string li)
sys le=len li
if ot+le>len t then t+=space 1000
mid t,ot+1,li
ot+=le
end method
'
method listpixels(sys px,py,nx,ny)
sys x,y,p
byte r,g,b,a
for y=1 to ny
addtext cr cr "y=" hex(y) cr cr
for x=1 to nx
p=getpixel px+x,py+y
splitpixel p,r,g,b,a
addtext hex(x) tab r tab g tab b tab a cr
next
next
end method
'
method mapcolor(sys px,py,nx,ny,c)
'
sys x,y,p,ch
byte r,g,b,a
string b=space(nx), co=" "
'
addtext cr cr "color channel=" c cr cr
'
for y=1 to ny
for x=1 to nx
p=getpixel px+x,py+y
splitpixel p,r,g,b,a
select c
case 1 : ch=r
case 2 : ch=g
case 3 : ch=b
case 4 : ch=a
end select
if r>0 then co=chr(65+(ch>>4)) else co=" " 'supports 16 color bands
mid b,x,co
next
addtext tab b cr
next
end method
'
end class
'#recordof RawObject
'TEST
'====
'
RawObject rw
rw.readfile "bulb32x.raw"
if not len rw.s then print "File problem!"
rw.setXY 32,32
sys p=rw.getpixel(30,30)
'print hex p
byte r,g,b,a
'rw.splitpixel 0x04030201, r, g, b, a
rw.splitpixel p, r, g, b, a
'print "red: " r " green: " g " blue: " b
rw.cleartext
'
'rw.listpixels 0,0,32,32
'
rw.mapcolor 0,0,32,32,1 'red
rw.mapcolor 0,0,32,32,2 'green
rw.mapcolor 0,0,32,32,3 'blue
'
putfile "t.txt", rw.t