with dithering
good for 24BPP pictures in 256 color modes.
give it an try.
Joshy
Code: Select all
dim shared as integer rtab(2,16) = { {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},{ 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}}
dim shared as integer gtab(2,16) = { { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},{-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}}
dim shared as integer btab(2,16) = { { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},{ 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5} }
declare sub Palette332()
declare sub rgb332 overload (byval x as single,byval y as single,byval col32 as integer)
declare sub rgb332 (byval x as single,byval y as single,byval r as integer,byval g as integer,byval b as integer)
declare sub rgb332 (byval x as single,byval y as single,byval r1 as single ,byval g1 as single ,byval b1 as single )
declare sub dither332 overload (byval x as single,byval y as single,byval col32 as integer)
declare sub dither332 (byval x as single,byval y as single,byval r as integer,byval g as integer,byval b as integer)
declare sub dither332 (byval x as single,byval y as single,byval r1 as single ,byval g1 as single ,byval b1 as single )
'create an RRGGBB Palette (rrrgggbb)
sub Palette332()
dim as integer i,r,g,b
for i = 0 to 255
r=(((i shr 5) and &H07) * 255) / 7
g=(((i shr 2) and &H07) * 255) / 7
b=((i and &H03) * 255) / 3
palette i,r,g,b
next
end sub
'rrrrrrrrggggggggbbbbbbbb to rrrgggbb
sub rgb332(byval x as integer,byval y as integer,byval col32 as integer)
dim as integer r,g,b
b = col32 and &HFF:col32 = col32 shr 8
g = col32 and &HFF:col32 = col32 shr 8
r = col32 and &HFF
r=r and &HE0
g=(g and &HE0) shr 3
b=(b and &HC0) shr 6
col32=g or b or r
pset(x,y),col32
end sub
'r,g,b to rrrgggbb
sub rgb332(byval x as single,byval y as single,byval r as integer,byval g as integer,byval b as integer)
if (r > 255) then
r=224 ' &HE0
elseif r>0 then
r=r and &HE0
else
r=0
end if
if (g > 255) then
g=28 ' &HE0 shr 3
elseif g>0 then
g=(g and &HE0) shr 3
else
g=0
end if
if (b > 255) then
b=3 ' &HC0 shr 6
elseif b>0 then
b=(b and &HC0) shr 6
else
b=0
end if
r=r or g or b
pset(x,y),r
end sub
'r,g,b to rrrgggbb
sub rgb332(byval x as single,byval y as single,byval r1 as single,byval g1 as single,byval b1 as single)
dim as integer r,g,b
r=int(255.0*r1):g=int(255.0*g1):b=int(255.0*b1)
if (r > 255) then
r=224 ' &HE0
elseif r>0 then
r=r and &HE0
else
r=0
end if
if (g > 255) then
g=28 ' &HE0 shr 3
elseif g>0 then
g=(g and &HE0) shr 3
else
g=0
end if
if (b > 255) then
b=3 ' &HC0 shr 6
elseif b>0 then
b=(b and &HC0) shr 6
else
b=0
end if
r=r or g or b
pset(x,y),r
end sub
'rrrrrrrrggggggggbbbbbbbb dithering to rrrgggbb
sub dither332(byval x as single,byval y as single,byval col32 as integer)
dim as integer i,j,r,g,b
i=int(x) mod 16:j=int(y) mod 2
b = col32 and &HFF:col32 = col32 shr 8
g = col32 and &HFF:col32 = col32 shr 8
r = col32 and &HFF
r+=rtab(j,i):g+=gtab(j,i):b+=btab(j,i)
if (r > 255) then
r=224 ' &HE0
elseif r>0 then
r=r and &HE0
else
r=0
end if
if (g > 255) then
g=28 ' &HE0 shr 3
elseif g>0 then
g=(g and &HE0) shr 3
else
g=0
end if
if (b > 255) then
b=3 ' &HC0 shr 6
elseif b>0 then
b=(b and &HC0) shr 6
else
b=0
end if
col32=r or g or b
pset (x,y),col32
end sub
'r,g,b dithering to rrrgggbb
sub dither332(byval x as single,byval y as single,byval r as integer,byval g as integer,byval b as integer)
dim as integer i,j
i=int(x) mod 16:j=int(y) mod 2
r+=rtab(j,i):g+=gtab(j,i):b+=btab(j,i)
if (r > 255) then
r=224 ' &HE0
elseif r>0 then
r=r and &HE0
else
r=0
end if
if (g > 255) then
g=28 ' &HE0 shr 3
elseif g>0 then
g=(g and &HE0) shr 3
else
g=0
end if
if (b > 255) then
b=3 ' &HC0 shr 6
elseif b>0 then
b=(b and &HC0) shr 6
else
b=0
end if
i=r or g or b
pset(x,y),i
end sub
'r,g,b dithering to rrrgggbb
sub dither332(byval x as single,byval y as single,byval r1 as single,byval g1 as single,byval b1 as single)
dim as integer i,j,r,g,b
r=int(255.0*r1):g=int(255.0*g1):b=int(255.0*b1)
i=int(x) mod 16:j=int(y) mod 2
r+=rtab(i,j):g+=gtab(j,i):b+=btab(j,i)
if (r > 255) then
r=224 ' &HE0
elseif r>0 then
r=r and &HE0
else
r=0
end if
if (g > 255) then
g=28 ' &HE0 shr 3
elseif g>0 then
g=(g and &HE0) shr 3
else
g=0
end if
if (b > 255) then
b=3 ' &HC0 shr 6
elseif b>0 then
b=(b and &HC0) shr 6
else
b=0
end if
i=r or g or b
pset(x,y),i
end sub
''' main
dim as integer x,y,z,col32,r,g,b
dim as single xs,ys
ScreenRes 640,480,8
windowtitle "press any key ..."
Palette332
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,0,0):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,0,0):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, 0,x,0):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, 0,x,0):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, 0,0,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, 0,0,x):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,x,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,x,x):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,x,0):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,x,0):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, 0,x,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, 0,x,x):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,0,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,0,x):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,x,255):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,x,255):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, 255,x,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, 255,x,x):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,255,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,255,x):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, x,255,255):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, x,255,255):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, 255,x,255):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, 255,x,255):next x,y
sleep
for y = 0 to 255:for x = 0 to 255:rgb332 (x ,y, 255,255,x):next x,y
for y = 0 to 255:for x = 0 to 255:dither332 (x+256,y, 255,255,x):next x,y
sleep
for z=0 to 255:y=0
for x=0 to 255:rgb332(x+z,y+z, x,y,z):next:x=0
for y=0 to 255:rgb332(x+z,y+z, x,y,z):next
next
for y=0 to 255:for x=0 to 255:rgb332(x+z,y+z, x,y,z):next:next
sleep
for z=0 to 255
y=0:for x=0 to 255:dither332(x+z,y+z, x,y,z):next
x=0:for y=0 to 255:dither332(x+z,y+z, x,y,z):next
next
for y=0 to 255:for x=0 to 255:dither332(x+z,y+z, x,y,z):next x,y
sleep
for z=0 to 255:y=0
for x=0 to 255:rgb332(x+z,y+z, z,x,y):next:x=0
for y=0 to 255:rgb332(x+z,y+z, z,x,y):next
next
for y=0 to 255:for x=0 to 255:rgb332(x+z,y+z, z,x,y):next:next
sleep
for z=0 to 255
y=0:for x=0 to 255:dither332(x+z,y+z, z,x,y):next
x=0:for y=0 to 255:dither332(x+z,y+z, z,x,y):next
next
for y=0 to 255:for x=0 to 255:dither332(x+z,y+z, z,x,y):next x,y
sleep
for z=0 to 255:y=0
for x=0 to 255:rgb332(x+z,y+z, y,z,x):next:x=0
for y=0 to 255:rgb332(x+z,y+z, y,z,x):next
next
for y=0 to 255:for x=0 to 255:rgb332(x+z,y+z, x,z,x):next:next
sleep
for z=0 to 255
y=0:for x=0 to 255:dither332(x+z,y+z, y,z,x):next
x=0:for y=0 to 255:dither332(x+z,y+z, y,z,x):next
next
for y=0 to 255:for x=0 to 255:dither332(x+z,y+z, y,z,x):next x,y
windowtitle "thats all ..."
sleep