freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Devel] Freetype bitmap to Windows DIB?


From: Leonard Rosenthol
Subject: Re: [Devel] Freetype bitmap to Windows DIB?
Date: Wed, 13 Mar 2002 11:27:32 -0500

At 10:31 PM 3/11/2002 -0500, Ron Olson wrote:
Unfortuantly, working with the library has exposed a weakness in my
knowledge of graphics programming under Win32. I'm very familiar with
the DDB window format, GDI, DCs, etc. DIBs are something I've never
worked with before, and frankly, I'm stumped.

        No need to worry about DIB's...


I'm willing to post the laughably pathetic examples of what I've tried
to do so far, but I'm more hoping for "here's some sample code, now go
away".

Here are some snippets from some code that I use to render an FT_Glyph into an HBITMAP which is then easily copyable to a DC/DIB, etc.

        Hope it helps...


Leonard
___________________________________
HDC             glyphDC;        // DC to draw glyph into
HBITMAP         glyphBits;      // bitmap
TT_Glyph        glyph;
TT_Raster_Map   ras;

// make the bitmap
RECT            theBounds = { 0, 0, ras.width, ras.rows };
glyphBits = CreateCompatibleBitmap( engine->mDC, ras.width, ras.rows );

// make a DC for the bitmap & stick in it there
glyphDC = CreateCompatibleDC( engine->mDC );
SelectObject( glyphDC, glyphBits );

// clear it white, just in case
HBRUSH  whiteBrush = CreateSolidBrush( RGB( 255, 255, 255 ) );
FillRect( glyphDC, &theBounds, whiteBrush );
DeleteObject( whiteBrush );


// I only want 4 levels of color (not the full 256)
colors[4].red = r;      colors[4].green = g;    colors[4].blue = b;
colors[3].red = (3*r + 0xFF) / 4;
colors[3].green = (3*g + 0xFF) / 4;
colors[3].blue = (3*b + 0xFF) / 4;
colors[2].red = (r + 0xFF) / 2;
colors[2].green = (g + 0xFF) / 2;
colors[2].blue = (b + 0xFF) / 2;
colors[1].red = (r + (3*0xFF)) / 4;
colors[1].green = (g + (3*0xFF)) / 4;
colors[1].blue = (b + (3*0xFF)) / 4;
colors[0].red = colors[0].green = colors[0].blue = 0xFF;

// stuff the glyph pixmap into the image
p = (TT_Byte *)ras.bitmap;
for (yy = 0; yy < ras.rows; ++yy) {
        for (xx = 0; xx < ras.width; ++xx) {
                pix = *p++;
                if (true /* pix > 0 */) {
                        if (pix > 4) {
                                pix = 4;
                        }

SetPixelV(glyphDC, xx, yy, RGB(colors[pix].red, colors[pix].green, colors[pix].blue));
                }
        }
}

---------------------------------------------------------------------------
Leonard Rosenthol                            <mailto:address@hidden>
Lazerware                                     <http://www.lazerware.com>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]