jiayouxjh / grafx2

Automatically exported from code.google.com/p/grafx2
0 stars 0 forks source link

Alpha drawing mode #348

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In addition to the 3 transparency modes already implemented (transparent,
additive, subtractive), I would propose a new one, called for example alpha.
The behavior on RGB components would be:

new_color = foreground_color*brush_color + old_color*(255-brush_color)

Basically, it allows you to use antialiased brushes that paste the current
FG color with a varying level of opacity. : White pixels of the brush
bitmap render full opacity, black is skipped, grey is 50% translucent.

I had this idea when experimenting with Text tool. AA from FG to BG is
perfect if you paint on a solid background, but if you need to AA over a
varied background, you're on your own. It's especially problematic if you
wanted to use some italic text in a small font, where AA really helps
readability. With this mode, you would render the font with FG white and BG
black, you get white text with greyscale edges. Then you would choose the
real FG color you want to use (black, white, red, blue...) and paste the
brush anywhere; the AA would be performed perfectly, no matter where you
paste it.

Note that the efficiency of this system depends on the availablity of a
greyscale range in your palette: If you have a 16-color range it should be
near perfect (perfect is when your whole palette is a 256-color grey
scale), but with only 4 or 5 greys, it would be much less accurate.
Arguably, if you have few colors, you wouldn't use transparency anyway.

Feedback and criticisms are welcome.

Original issue reported on code.google.com by yrizoud on 26 May 2010 at 3:37

GoogleCodeExporter commented 9 years ago
There is code for that in vgapaint 386 (it's called antialias+blend). I'm all 
for it, 
particularly for text.

Original comment by pulkoma...@gmail.com on 26 May 2010 at 4:48

GoogleCodeExporter commented 9 years ago
Implemented in r1512.
See attached image (Painted on a screen of Agony by Frank Sauer, a 44-color 
image with custom palette)

After a bit of thought, I set the opacity level depending on the brush's 
perceived lighness, a classic "0.3*R + 0.59*G + 0.11*B" formula : My original 
formula was affecting each channel independantly, but if a perfect greyscale 
wasn't available in the palette, it would shift colors.

I think it works perfect with AA text (just remember to turn off effects after 
using it: shift-E). I've also made some tests with 'brushes of varying 
opacity', it looks promising. In any case, feedback is welcome.

Original comment by yrizoud on 17 Jun 2010 at 6:36

Attachments:

GoogleCodeExporter commented 9 years ago
Done.

Original comment by pulkoma...@gmail.com on 5 Aug 2010 at 6:08

GoogleCodeExporter commented 9 years ago
Woops, I had forgotten, display bug : in the Transparency setting window, 
choosing another mode (other than Alpha) leaves the visual indicators on Alpha 
anyway.
I go fix.

Original comment by yrizoud on 5 Aug 2010 at 6:52

GoogleCodeExporter commented 9 years ago
Fixed in r1561

Original comment by yrizoud on 7 Aug 2010 at 7:24