Take a look at the picture, all colors except hands are 'pure' colors.
{"name":"591971","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b8d1678789bd504182193c7391f1b202.png","w":320,"h":240,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b8d1678789bd504182193c7391f1b202"}
I need to replace each of these color by another one, but quickly.
What is the way , faster than getpixel, that I can use ?
Thanks
If you're using 8bit I would go for palette changes, but something tells me you are not...
Use palettes. Or prerender, either using a graphic editor (great opportunity to discuss in this thread why Gimp sucks/is great) or during game setup.
Use palettes, prerender, or use OpenGL.
[append]
Next person to post has to add something to the list!
Use palettes, prerender, or use OpenGL.
Or use getpixel to build an array and then use the array to putpixel back the colors with a given offset to change your colors, as long as your image doesn't...change.
There are gradients there... Ya good luck. Easier to redo the art.
Gradients can be overcome by converting to HSL and not using the lightness but there will be problems if any of the gradients fades to pure black. The human brain is pretty good at putting imaginary boundries in images.
As far as I can think, getpixel is the only way and it will be slow. I can think of a few ways to optimize but all sacrifice accuracy.
+1 for finding another way.
Matt.
Solder a switch to your monitor cable, which switches the r, g and b channels.
I win!
I made some tests, and it is working (as expected) with getpixel/putpixel.
I will perhaps try to use the "block data transfer" method.
Here is the result, the colors are random and take the gradient :
[img http://www.allegro.cc/files/attachment/591972]
And here is the code :
I only skimmed over the code but I didn't see any rgb2hsv and vice versa conversions so I'm guessing you're not doing it right. What you want to do is this:
For each pixel:
1. Read colour (RGB format)
2. Convert to HSV
3. Rotate H by a certain number of degrees.
4. Convert back to RGB.
5. Write colour back to image.
Thanks for your help, but there is no need for me to use any other conversion than makecol and getX :-)
The color value of the input picture is here for two reason: having the form to fill with a color, and picking the value as a percentage from 0 to 255.
The whole thing is working as expected, it just need some king of optimisation as it will cause some load time.
Here is the new version, where default replacement color is on screen for us to verify that it is using it correctly.
Before:

After:
{"name":"591975","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/e\/cefcd7e9c42f3ac91cf96ab1e48b02b6.jpg","w":806,"h":625,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/e\/cefcd7e9c42f3ac91cf96ab1e48b02b6"}
Executable + source (Win32) ( 7z archive )
I am waiting for give the cookies. Please post me the answer ;-) huhuhu
As requested, a post so you can hand out cookies.
;-p
Your pictures look like they contain a large ammount of dead space. If your checking every pixel in the large space perhaps you could divide and conquer. Only check every nth pixel (in both dimensions) if the nth pixel is one that needs to be changed then go back n/2 and check that pixel (and so on). You value for n would have to be one where you won't missed anything important so if your working on a picture with skinny lines it won't help but even at n=2 you'll save a lot of time. Basically trading precision for speed.
Matt.
What is the way , faster than getpixel, that I can use ?
_getpixel
If the colour-depth is known, you might want to use getr8, getr16, getr24, getr32 etc. instead of getr.
r1 = (r1 * it)/255 ;
If you don't mind the result being in the range 0-254 instead of 0-255, you can divide by using a shift. The code would then become.r1 = (r1 * it)>>8;. While not as accurate as the /255 method, it will be a lot faster.
Also, you might want to consider using 8-bit graphics and using colour-map tables and draw_lit_sprite().
AE.
Matt Weir: This is only a test picture extracted from an animation, the picture when in it final form is 'clipped' to the nearest non-masked pixel. Anyway thanks for the tip !
Andrei: I will try the _getpixel way. Also: the >>8 seems good too.
GIMP rules.
Yeah perhaps. But GIMP does not do real time painting in my code.