PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Question about GDBLTFAST_COLORIZE

I have an animated selection cursor (you know, a spinning box that shows what unit is selected) that has 2 colors - black and the basic color of the playerside.

I created the basic cursor using 2 colors - black and grey (128,128,128) with a transparent color of magenta, and figured I would use GDBLTFAST_COLORIZE to alter the color of grey to the current playerside color (white, yellow, orange, red, green, dark blue, light blue or remain grey), but I find that trying to colorize to white doesn't alter the cursor color at all, and colorizing to yellow simply presents a 'muddy' yellow color.

I tried adjusting the dwColorizeOpacity value, but I see no effect beyond a value of 128 (probably due to the value for my base color grey).

My guess is that the problem revolves around my selection of a base color (in this case grey (128, 128, 128), resulting in problems blending to colors lighter than that - white or yellow. I tried using a ligher base color, but found that darker colors were being washed out.

What base color should I be using for colorization? I thought the mid-range grey would be perfect for this, but it seems I was wrong. Is there some combination of base color/colorization opacity that gives the best results?

I'll keep playing with the combo to try and find something that works well with all colors, but if anyone knows offhand it would be greaty appreciated. :D
Well, here's what I ended up doing. I created 2 sets of selection cursor animations - one with the midlevel grey (128, 128, 128) as the base color, and another with near white (245, 245, 245) as the base color. The grey is used for colorizing to darker colors, while the near white is used for colorizing to the lighter colors.

Unless I'm missing something, it seems like the dwColorizeOpacity handling is bugged. It seems to me that a value of 255 should create an image that uses the dwColorizeColor at 100% opacity regardless of what the base color is, but it still appears to blend the colors at 50%.
Actually it's a feature.. :) I'll see if I can pack a "GDBLTFAST_COLOROVERLAY" into 2.02 before it's shipped...
Oops, you're right! They're always features =)

Do you think its an error in the blend code? I thought the idea of dwColorizeOpacity was to go from 0 (the original color fully) to 255 (the dwColorizeColor fully). Is that the intention?
Actually, the colorize function of GapiDraw is quite advanced and works in the HSV color space. I'll add some pictures to the documentation to show how they all work...

Image

Basically what's white will stay white when colorizing. If you want white to change color hue you want a color overlay filter, something GapiDraw does not support.
Yep, I understood that white and black will remain unchanged, but shouldn't the other colors blend according to the dwColorizeOpacity setting? Shouldn't 255 equal essentially no blend with the dwColorizeColor being blitted for everything other than white and black? I'm not seeing that - I'm seeing the blend get no stronger than 50% (at least with the colors I'm using).
I added a multiply pixel effect to 2.02 which will do exactly what you want.. :)
Thanks! :D
I have been playing around with photoshop effects for my new little side project.
Then I have been trying to do the same in Gapidraw. For Multiply and Colorize etc., they work fine.

But two effects I really miss in GapiDraw is Screen and Overlay, the screen effect does the opposite of multiply. Multiply darkens and screen brightens.

Overlay is multiply and screen and is great because it can both make your graphics darker and brighter. For 8-bit channels the effects can be calculated like this:

Multiply:
ab/255

Screen:
255-((255-a)(255-b)/255)

Overlay:
If b < 128 then 2ab/255
If b >= 128 then 255-2(255-a)(255-b)/255

The colorize effect may be cool and it does something like overlay, but it doesn’t really work the same.

I will implement a simple overlay algo for my purposes but I think they could be useful effects for GapiDraw. And probably 10 times faster if Johan writes it :)

/Okku
Hi,

Thanks for the algos.. The fx implementation in GapiDraw was remade in 2.04 so adding new effects will be quite easy. I'll give them a go in 2.10...

Thanks
Johan
I did a simple implementation of the overlay and it works nice. I will only use it to generate some new graphics at level loads so my implementation is not that time critical.

How about exposing a effects plugin interface? Or maybe a pixel class (with some overloaded operators), this code snippet would implement the screen effect:

pixel a = *pSrc;
pixel b = *pDest;
*dest = 255-((255-a)*(255-b))/255;

I don’t know how this fit in with pixel shaders, which seems to be something cool.

And I really don’t if it would be possible to make the performance good enough.
How about exposing a effects plugin interface?


I have been thinking of this, but do not want to implement something like PF that uses a virtual function call on every pixel (=slooow).

If you use GetBuffer / ReleaseBuffer and the color conversion routines in GapiDrawExtension.h it's actually quite easy to write pixel shaders yourself.
InexorableTash · 15 Nov 2003, 22:16 UTC
Johan wrote:
If you use GetBuffer / ReleaseBuffer and the color conversion routines in GapiDrawExtension.h it's actually quite easy to write pixel shaders yourself.


I'd be interesting to do a template (or macro)-based framework for this, taking some of the optimization ideas from the GD core. The goal would be to let other developers write the minimal code block for processing input/output pixels one at a time in either RGB or HSV space (with ROP-like variations, e.g. process two source and one dest pixel), and have the template take care of colorspace conversions and optimized reads/writes from the buffer. The external developer's code would be inlined by the template so it's optimized by the compiler and wouldn't have any function call overhead.