freetype FT_PIXEL_MODE_LCD to rgba

Started by
41 comments, last by Brother Bob 10 years, 8 months ago

Darn I figured that since it didnt have rgb it couldnt be antialiased but I guess it can just not on subpixel level like you say.

Do I need to get rid of antialiasing all together?

I added a solid rgb and just changed the alhpa like this and it didnt look much different


data.append(3, (unsigned char)255);
data.append(1, (unsigned char)bitmap.buffer[(y*width) + x] );

Im not quite sure what you mean when blending to me blending and alpha testing sound the same and are you talking about when I make the images of the characters into one image?

Advertisement

Alpha blending and alpha testing are not the same thing. Alpha testing is a binary test that, using on some threshold of the alpha value, either fully draws a pixel or fully rejects it for further processing. Alpha blending is used when you have partially transparent pixels that has to blend gradually with the background. Take for example an edge pixel with a normalized alpha value of 0.25 (255*0.25=64 in 8-bit integer values); it means that is is 25% opaque and has to blend 25% with its own solid color and 75% with the background.

Ah I see what you mean I saved just one character to a png straight from freetype and it looks great so something is wrong with my blending of the images. I will get on that and figure out whats going on! The T in the images looks to have the top part better than in the complete image I wonder if it has something to do with the merging to. Thanks for your help!

Either you're cutting off the last top, or the top line just happens to be sharp. Fonts designed for rasterization, or if the library has a decent font hinting method, typically places the stems of the glyphs on pixel boundaries to eliminate the effect of antialiasing since there are no partial coverages in those cases. This is often desired, since antialiasing is meant to reduce the aliasing effects and the design/hinting strives to eliminate the aliasing in the first place. But I would double check that your code actually does copy all rows, if something missing it is probably the last row of the T, and one-off errors are not uncommon.

I made a little progress on getting them lined up properly and showing the whole characters im not sure whats wrong with the T but everything else looks ok aligned wise but im having an issue with my blending. Can you help get my blending sorted out please?

my varaibles are unsigned chars r,g,b,a,destr,destg,destb,desta

the rgba contain the new/top image that will be placed on the destrgba canvas

right not just to see what im doing im using

r = r * (a / 255);
g = g * (a / 255);
b = b * (a / 255);
a = 255;

My original code was

r = (r * a) + (destr * (255 - desta));
g = (g * a) + (destg * (255 - desta));
b = (b * a) + (destb * (255 - desta));
a = 255;

Neither of these seem to be correct and I just cant wrap my head on what to do can you help please?

Your second code is almost correct, but has to be scaled. It is correct for a normalized alpha channel, but since your alpha is scaled by 255, you also have to divide the result by 255 after multiplication to scale the product back to its actual range.

r = ((r * a) + (destr * (255 - desta))) / 255;
g = ((g * a) + (destg * (255 - desta))) / 255;
b = ((b * a) + (destb * (255 - desta))) / 255;
a = 255;

Hmm I added that but it looks pretty much the same it must be off somewhere before the merging ill have to find where its going bad.

Found the issue with the T I had it going x for height not y im really surprised the rest looked ok lol

Freetype will either give you a very nicely anti-aliased 8-bit glyph bitmap or a rather rough monochrome bitmap.

When I was playing around with Freetype, I set the alpha channel of my bitmap to the value of the corresponding pixel in the glyph bitmap. I then set the RGB components of my bitmap to whatever color I wanted and used the resulting bitmap as a texture with blending enabled. The best thing to do with a Freetype bitmap, 8-bit or 1-bit, is to use it as the alpha channel of your bitmap.

@MarkS I see but I think this is already covered and I know the output of the freetype is better than the string im getting as the characters are better

Just for show I changed the first character from T to lower case f because you can tell the alpha layer easily on it I attached the character and the string the character from freetype looks great the string doesnt and all the alpha data is the same so its definitely something in the merging that is causing issues.

This topic is closed to new replies.

Advertisement