How to saturate just one colo (R, G, B)?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1417
Joined: Sun Feb 14, 2010 7:11 pm

How to saturate just one colo (R, G, B)?

Post by Bugala »

I am trying to achieve basically similar effect as Wizball Game has.

In Wizball you collected colors, and as you got them, the game started having more colors appearing.

I am trying to do something similar.

As in, first level starts all gray, and as level progresses, the RED color will start gradually coming back.

In second level, the image already has RED in place, but GREEN and BLUE are still Grey, and during the level GREEN starts coming back.

In third level, RED and GREEN are already in place, and during the level, BLUE starts gradually getting back.

Question is, how do I get this done?


My current thinking is that for the first level, I would basically need an image, which is image in such way that GREEN and BLUE are in gray color, and BLUE is there in the image already.

Then I would need some system, that could control making the BLUE completely gray at beginning, and then gradually lessening the emount of desaturation.


I see there are something like Channels in brushes. Can those be used somehow? Like is there RED, GREEN, BLUE channels, that I could use to turn them into grey?

Or is there perhaps a system, like if I want to have a darkness, then basically I can draw image, and on top of it I draw a black box, with transparency.

More transparency I put, less dark it is, and less transparency, more dark it is.

Does there happen to be an option where I could draw some sort of Desaturation box, that only affects the one of the RGB colors?
Flinx
Posts: 378
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: How to saturate just one colo (R, G, B)?

Post by Flinx »

Here’s something of a solution, but it needs a lot of memory for the tables and is slow. It might still be helpful, if no one knows a better way.
The operations in the loop could be combined into a single line, which would probably speed up the calculation a bit, but it’s easier to experiment this way.
In the example the blue color component is changed from 0 to 100%. If the color component is supposed to be gray rather than 0 (black), you would have to distribute the value for blue among the other colors. There are various algorithms for weighting the color components (search for “RGB to grayscale conversion”).

Code: Select all

bid1=LoadBrush(Nil, "test.jpg")
Local dwidth= GetAttribute(#DISPLAY, 1, #ATTRWIDTH)
Local dheight=GetAttribute(#DISPLAY, 1, #ATTRHEIGHT)
ScaleBrush(bid1, dwidth, dheight)
Local brwidth= GetAttribute(#BRUSH, bid1, #ATTRWIDTH)
Local brheight=GetAttribute(#BRUSH, bid1, #ATTRHEIGHT)

ARGBarray1 = BrushToRGBArray(bid1)
DisableLineHook()
ARGBarray2={}
For blueval=0 To 1 Step 0.05
	For pixel=0 To TableItems(ARGBarray1)-1
		Local r,g,b
		r=(ARGBarray1[pixel]&0xff0000)>>16
		g=(ARGBarray1[pixel]&0x00ff00)>>8
		b= ARGBarray1[pixel]&0x0000ff
		b=b*blueval
		ARGBarray2[pixel]=r<<16 | g<<8 | b
	Next
	bid2=RGBArrayToBrush(Nil, ARGBarray2, brwidth, brheight)
	DisplayBrush(bid2, #CENTER, #CENTER)
Next
EnableLineHook()
ARGBarray=Nil
ARGBarray2=Nil
Sleep(15000)
Bugala
Posts: 1417
Joined: Sun Feb 14, 2010 7:11 pm

Re: How to saturate just one colo (R, G, B)?

Post by Bugala »

I guess that will do the trick, indeed, but I guess might be bit slow, as it makes the change to every pixel independently.

If no one gives other solutions, I might give this a try, but my guess is that this would be too slow for Amigas, but then again, basically any effect is always done to every pixel, so who knows, maybe it isnt so slow after all.
Post Reply