icon
proc
GetPixelColor(px as num,py as num)
set background=1
var/list/result=list()
var/icon/pixel=src.GetPixel(px,py)
for(var/r=0,r<=255,r++)
for(var/g=0,g<=255,g++)
for(var/b=0,b<=255,b++)
var/icon/test=icon('trans.dmi')
test.DrawBox(rgb(r,g,b),1,1)//Draw a small 1x1 box in the southwest corner of test
test.Shift(NORTH,py-1)
test.Shift(EAST,px-1)
if(test==pixel)
result["red"]=r
result["green"]=g
result["blue"]=b
break
if(!result.len)
src << "<font color=red><tt>ERROR: No value found on GetPixelColor([px],[py])<br>src:[src]</tt></font color=red>"
return 0
else
return result
The problem? That's the most inneficient piece of code ever. In order to find a pixel color, it would have to create 256**3, or 16581375, dynamic icons. I think that Garthor, in Chatters, summed it up quite well, saying "Wizkidd, you're trying to find the product of 345 and 217 by looping through a million numbers and seeing which one is right".
Can anyone think of a way to make this more efficient? As it is now, it simply takes too long and causes too much overhead for me to even consider putting it in my library.
For those that care, GetPixel() returns a specific pixel of an icon at coordinates px,py of the icon, and px and py stand for pixel x and pixel y, respectively.
[edit]
Realized that I posted this in Design Philosophy instead of Code Problems. Moved it.
To mask out, you multiple the icon like this
pixelcopy *= rgb(255,0,0) for red
pixelcopy *= rgb(0,255,0) for green
pixelcopy *= rgb(0,0,255) for blue
leaving only the Red component in the pixelcopy icon. Then loop through 256 times testing only red at this time (since you already know green and blue are 0 in both icons) till the icons match. When they do, recopy pizel copy from scratch, mask out green, and test only green component. repeat for blue. this gives you the RGB components seperately and much faster. Make sense?
-Lutelian