I have discovered an apparent problem with SwapColor. And icons in general. And it is making it very difficult and frustrating to do some of the things I WANT to do and SHOULD be ABLE to do in BYOND. I have a function to take an icon and 2-tone it. Take all dark colors and make them like a dark grey, for example, and all lighter colors and make them a light grey. Basicaly here it is:
icon/proc
StoneIfyIcon()
var/icon/R
var/icon/G
var/icon/B
var/icon/Y
R = icon(src)
G = icon(src)
B = icon(src)
R.SetIntensity(1,0,0)
G.SetIntensity(0,1,0)
B.SetIntensity(0,0,1)
for (var/r = 0,r<=127,r++)
R.SwapColor(rgb(r,0,0),rgb(0,0,0))
for (var/r = 128,r<=255,r++)
R.SwapColor(rgb(r,0,0),rgb(255,0,0))
for (var/g = 0,g<=127,g++)
G.SwapColor(rgb(0,g,0),rgb(0,0,0))
for (var/g = 128,g<=255,g++)
G.SwapColor(rgb(0,g,0),rgb(0,255,0))
for (var/b = 0,b<=127,b++)
B.SwapColor(rgb(0,0,b),rgb(0,0,0))
for (var/b = 128,b<=255,b++)
B.SwapColor(rgb(0,0,b),rgb(0,0,255))
Y = icon(R)
Y.Blend(G,ICON_ADD)
Y.Blend(B,ICON_ADD)
Y.SwapColor(rgb(0,0,0),rgb(127,127,127))
Y.SwapColor(rgb(0,0,255),rgb(127,127,127))
Y.SwapColor(rgb(0,255,0),rgb(127,127,127))
Y.SwapColor(rgb(255,0,0),rgb(127,127,127))
Y.SwapColor(rgb(255,0,255),rgb(192,192,192))
Y.SwapColor(rgb(255,255,0),rgb(192,192,192))
Y.SwapColor(rgb(0,255,255),rgb(192,192,192))
Y.SwapColor(rgb(255,255,255),rgb(192,192,192))
return Y
For most icons, with simple colors, this works fine. But occasionaly, something goes terribly wrong....
Basically the code works like this. It creates 4 seperate icons (R,G,B, and Y). RG&B start as direct copies of the icon itself. Y is the final product. I filter out Green and blue in the R icon, with Setintensity, Red and Blue in G, and Red and Green out of B. This works fine. Now each icon is left with just the individual component. well use R as the example. R is left with just the red portions of the icon. I then loop through all 256 red possibilities, and set the darker ones to black and the lighter ones to bright red (rgb(255,0,0)). With some icons, it doesn't do the swap color. For instance, I have an icon that after masking out blue and green, i have rgb(4,0,0) left in the icon. When I do my loop, it never replaces the 4,0,0 with 0,0,0. its left as just 4,0,0. codewise, this SHOULD work. I have no idea why it doesn't work, either. It doesn't make sense. I finish by recombining the icons, and I should be left with only 0 and 255 possiblites for rg and b, and can then do a few more swapcolors and bam, your icon has been turned into a two-toned grey icon. But because some colors dont get swapcolored like they should, it doesnt always work.
But an interesting thing. If I put a manual
R.SwapColor(rgb(4,0,0),rgb(0,0,0))
in, it swaps the color properly. Is it having a problem with the loop maybe? Am I insane? Am I doing something wrong myself?
Also, if I throw in a second loop after the first one that just loops through 0-10, it swaps it fine. My final solution was to do all the swaps in a loop (i=0 to5), and that works. So why does it fail to do the swap with the longer version of the loop if I only do it once? Id be happy to host and bring someone on with some authority to demonstrate this for them. honestly, if I am just being stupid and its blidningly obvious right in front of my face, please, let me know.
-Lute