[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Freetype] FreeType newbie
From: |
Bruce Mitchener |
Subject: |
Re: [Freetype] FreeType newbie |
Date: |
Sat, 19 Jun 2004 08:05:39 -0600 |
User-agent: |
Mozilla Thunderbird 0.7 (Windows/20040616) |
Marco,
I use FreeType with Qt as well. In our application, I just render the
text directly onto a QPixmap with a bit of code for MacOS X and Windows
(we don't ship on Unix or embedded platforms).
We use a blending macro derived from some of the FreeType samples:
#define BLEND_COLOR(source, alpha, text) (unsigned char)((alpha *
(int)(text - source) + 127) / 255);
and on Windows, it looks like this:
QRgb pixelColor;
HDC hDC = (HDC)dstPaintDevice.handle();
const int bitmapRows = bitmap->rows;
const int bitmapWidth = bitmap->width;
unsigned char * p = bitmap->buffer;
for (int yy = 0; yy < bitmapRows; ++yy) {
for (int xx = 0; xx < bitmapWidth; ++xx) {
unsigned char pix = *p++;
if (pix == 255) {
pixelColor = qRgba(qRed(color), qGreen(color),
qBlue(color), 0);
} else {
QRgb sourceColor = GetPixel(hDC, left + xx, top + yy);
unsigned char red, green, blue;
red = qRed(sourceColor);
red += BLEND_COLOR(red, pix, qRed(color));
green = qGreen(sourceColor);
green += BLEND_COLOR(green, pix, qGreen(color));
blue = qBlue(sourceColor);
blue += BLEND_COLOR(blue, pix, qBlue(color));
pixelColor = qRgba(red, green, blue, 0);
}
SetPixelV(hDC, left + xx, top + yy, pixelColor);
}
}
on OS X, we differ a bit because we use the Carbon API (GetGWorldPixMap,
GetPixBaseAddr, GetPixRowBytes, along with LockPixels, UnlockPixels).
This code could probably be faster on Windows, but we render a fair bit
of text and it hasn't yet been a performance issue for us.
We use FreeType 2.18, hand-patched to make the cache system work.
Does this help?
- Bruce
Marco Mussini wrote:
Hi all,
I'm trying to put an antialiased freetype rendered text into QT graphics
library. To do this I have an object (called QImage) with 8-bpp depth and
gray scale color map in which I have copied pixel per pixel the freetype
rendered bitmap. Also in this QImage object I set white background color to
be transparent so that it can be overlapped with other objects.
But there is of course a problem now:
if image is displayed into a widget with white background it appear fine. But
if background is different from white or has many colors (above all dark
colors), gray scale pixels that regards antialiasing appears badly.
For example if my background is dark blue and text is black, image's pixel
that regards antialiasing are much more visible and they form a contour for
any character of the text.
How to handle this problem??
I think that a solution could be to set a partial transparency on all
image's pixel that regard antialiasing, that is all pixels with colors that
are not black or white.
I don't know how to do that.
Does someone knows better techniques to handle this problem??