Author: tkreuzer Date: Sat May 21 15:05:20 2011 New Revision: 51839
URL: http://svn.reactos.org/svn/reactos?rev=51839&view=rev Log: [GDI FONT DRIVER] - Implement support for different source and destination bit depth, which is neccessary for fonts that provide bitmaps for individual glyphs. These can be in 1bpp, while we still need to provide 4bpp. (In theory we could use a callback for the rasterizer to directly draw on the output bitmap, but its support in freetype doesn't yet cover all cases)
Added: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/copybits.c (with props) Modified: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/CMakeLists.txt branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/ftfd.h branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/glyph.c
Modified: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/GdiFontDriver/drivers/... ============================================================================== --- branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/CMakeLists.txt [iso-8859-1] (original) +++ branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/CMakeLists.txt [iso-8859-1] Sat May 21 15:05:20 2011 @@ -5,6 +5,7 @@
add_library(ftfd SHARED enable.c + copybits.c font.c glyph.c tttables.c
Added: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/copybits.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/GdiFontDriver/drivers/... ============================================================================== --- branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/copybits.c (added) +++ branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/copybits.c [iso-8859-1] Sat May 21 15:05:20 2011 @@ -1,0 +1,188 @@ +/* + * PROJECT: ReactOS win32 subsystem + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: GDI font driver based on freetype + * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + */ + +#include "ftfd.h" + + +static +VOID +FtfdCopyBits_S1D1( + BYTE *pjDest, + FT_Bitmap *ftbitmap) +{ + ULONG ulRows, ulDstDelta, ulSrcDelta; + PBYTE pjDstLine, pjSrcLine; + + pjDstLine = pjDest; + ulDstDelta = (ftbitmap->width + 7) / 8; + + pjSrcLine = ftbitmap->buffer; + ulSrcDelta = abs(ftbitmap->pitch); + + ulRows = ftbitmap->rows; + while (ulRows--) + { + /* Copy one line */ + memcpy(pjDstLine, pjSrcLine, ulDstDelta); + + /* Next ros */ + pjDstLine += ulDstDelta; + pjSrcLine += ulSrcDelta; + } +} + +static +VOID +FtfdCopyBits_S8D1( + BYTE *pjDest, + FT_Bitmap *ftbitmap) +{ + __debugbreak(); +} + + +static +VOID +FtfdCopyBits_S1D4( + BYTE *pjDest, + FT_Bitmap *ftbitmap) +{ + ULONG ulRows, ulSrcDelta; + PBYTE pjDstLine, pjSrcLine; + +//__debugbreak(); + + pjDstLine = pjDest; + + pjSrcLine = ftbitmap->buffer; + ulSrcDelta = abs(ftbitmap->pitch); + + ulRows = ftbitmap->rows; + while (ulRows--) + { + ULONG ulWidth = ftbitmap->width; + BYTE j, *pjSrc; + static USHORT ausExpand[] = + {0x0000, 0x000f, 0x00f0, 0x00ff, 0x0f00, 0x0f0f, 0x0ff0, 0x0fff, + 0xf000, 0xf00f, 0xf0f0, 0xf0ff, 0xff00, 0xff0f, 0xfff0, 0xffff}; + + pjSrc = pjSrcLine; + + /* Get 8 pixels */ + j = (*pjSrc++); + + while (ulWidth >= 8) + { + /* Set 8 pixels / 4 bytes */ + *pjDstLine++ = (BYTE)(ausExpand[j >> 4] >> 8); + *pjDstLine++ = (BYTE)ausExpand[j >> 4]; + *pjDstLine++ = (BYTE)(ausExpand[j & 0xf] >> 8); + *pjDstLine++ = (BYTE)ausExpand[j & 0xf]; + + /* Next 8 pixels */ + j = (*pjSrc++); + ulWidth -= 8; + } + + /* Set remaining pixels (max 7) */ + if (ulWidth > 0) *pjDstLine++ = (BYTE)(ausExpand[j >> 4] >> 8); + if (ulWidth > 2) *pjDstLine++ = (BYTE)ausExpand[j >> 4]; + if (ulWidth > 4) *pjDstLine++ = (BYTE)(ausExpand[j & 0xf] >> 8); + if (ulWidth > 6) *pjDstLine++ = (BYTE)ausExpand[j & 0xf]; + + /* Go to the next source line */ + pjSrcLine += ulSrcDelta; + } +} + +static +VOID +FtfdCopyBits_S8D4( + BYTE *pjDest, + FT_Bitmap *ftbitmap) +{ + ULONG ulRows, ulDstDelta, ulSrcDelta; + PBYTE pjDstLine, pjSrcLine; + + pjDstLine = pjDest; + ulDstDelta = (ftbitmap->width*4 + 7) / 8; + + pjSrcLine = ftbitmap->buffer; + ulSrcDelta = abs(ftbitmap->pitch); + + ulRows = ftbitmap->rows; + while (ulRows--) + { + ULONG ulWidth = ulDstDelta; + BYTE j, *pjSrc; + + pjSrc = pjSrcLine; + while (ulWidth--) + { + /* Get the 1st pixel */ + j = (*pjSrc++) & 0xf0; + + /* Get the 2nd pixel */ + if (ulWidth > 0 || !(ftbitmap->width & 1)) + j |= (*pjSrc++) >> 4; + *pjDstLine++ = j; + } + + /* Go to the next source line */ + pjSrcLine += ulSrcDelta; + } +} + +void +NTAPI +FtfdCopyBits( + BYTE jBppDst, + BYTE *pjDest, + FT_Bitmap *ftbitmap) +{ + + if (jBppDst == 1) + { + if (ftbitmap->pixel_mode == FT_PIXEL_MODE_MONO) + { + FtfdCopyBits_S1D1(pjDest, ftbitmap); + } + else if (ftbitmap->pixel_mode == FT_PIXEL_MODE_GRAY && + ftbitmap->num_grays == 256) + { + FtfdCopyBits_S8D1(pjDest, ftbitmap); + } + else + { + WARN("Unsupported pixel format\n"); + __debugbreak(); + } + + } + else if (jBppDst == 4) + { + if (ftbitmap->pixel_mode == FT_PIXEL_MODE_MONO) + { + FtfdCopyBits_S1D4(pjDest, ftbitmap); + } + else if (ftbitmap->pixel_mode == FT_PIXEL_MODE_GRAY && + ftbitmap->num_grays == 256) + { + FtfdCopyBits_S8D4(pjDest, ftbitmap); + } + else + { + WARN("Unsupported pixel format\n"); + __debugbreak(); + } + } + else + { + WARN("Bit depth %ld not implemented\n", jBppDst); + __debugbreak(); + } +}
Propchange: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/copybits.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/ftfd.h URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/GdiFontDriver/drivers/... ============================================================================== --- branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/ftfd.h [iso-8859-1] (original) +++ branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/ftfd.h [iso-8859-1] Sat May 21 15:05:20 2011 @@ -148,7 +148,6 @@ POINTEF ptefSide; SIZEL sizlScale; HGLYPH hgSelected; - ULONG cjSelected; UCHAR jBpp; } FTFD_FONT, *PFTFD_FONT;
@@ -340,3 +339,10 @@ NTAPI FtfdInitKerningPairs( PFTFD_FACE pface); + +VOID +NTAPI +FtfdCopyBits( + BYTE jBppDst, + BYTE *pjDest, + FT_Bitmap *ftbitmap);
Modified: branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/glyph.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/GdiFontDriver/drivers/... ============================================================================== --- branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/glyph.c [iso-8859-1] (original) +++ branches/GSoC_2011/GdiFontDriver/drivers/video/font/ftfd/glyph.c [iso-8859-1] Sat May 21 15:05:20 2011 @@ -97,6 +97,7 @@ pfont->iFace = pfo->iFace; pfont->pface = pface; pfont->hgSelected = -1; +
/* Create a freetype face */ fterror = FT_New_Memory_Face(gftlibrary, @@ -429,72 +430,6 @@ //__debugbreak(); }
-static -VOID -FtfdCopyBitmap1Bpp( - BYTE *pjDest, - FT_Bitmap *ftbitmap) -{ - ULONG ulRows, ulDstDelta, ulSrcDelta; - PBYTE pjDstLine, pjSrcLine; - - pjDstLine = pjDest; - ulDstDelta = (ftbitmap->width + 7) / 8; - - pjSrcLine = ftbitmap->buffer; - ulSrcDelta = abs(ftbitmap->pitch); - - ulRows = ftbitmap->rows; - while (ulRows--) - { - /* Copy one line */ - memcpy(pjDstLine, pjSrcLine, ulDstDelta); - - /* Next ros */ - pjDstLine += ulDstDelta; - pjSrcLine += ulSrcDelta; - } -} - -static -VOID -FtfdCopyBitmap4Bpp( - BYTE *pjDest, - FT_Bitmap *ftbitmap) -{ - ULONG ulRows, ulDstDelta, ulSrcDelta; - PBYTE pjDstLine, pjSrcLine; - - pjDstLine = pjDest; - ulDstDelta = (ftbitmap->width*4 + 7) / 8; - - pjSrcLine = ftbitmap->buffer; - ulSrcDelta = abs(ftbitmap->pitch); - - ulRows = ftbitmap->rows; - while (ulRows--) - { - ULONG ulWidth = ulDstDelta; - BYTE j, *pjSrc; - - pjSrc = pjSrcLine; - while (ulWidth--) - { - /* Get the 1st pixel */ - j = (*pjSrc++) & 0xf0; - - /* Get the 2nd pixel */ - if (ulWidth > 0 || !(ftbitmap->width & 1)) - j |= (*pjSrc++) >> 4; - *pjDstLine++ = j; - } - - /* Go to the next line */ - //pjDstLine += ulDstDelta; - pjSrcLine += ulSrcDelta; - } -} - VOID FtfdQueryGlyphBits( FONTOBJ *pfo, @@ -523,15 +458,11 @@ }
/* Copy the bitmap */ - if (pfont->jBpp == 4) - FtfdCopyBitmap4Bpp(pgb->aj, &ftglyph->bitmap); - else - FtfdCopyBitmap1Bpp(pgb->aj, &ftglyph->bitmap); + FtfdCopyBits(pfont->jBpp, pgb->aj, &ftglyph->bitmap);
//TRACE("QueryGlyphBits hg=%lx, (%ld,%ld) cjSize=%ld, need %ld\n", // hg, pgb->sizlBitmap.cx, pgb->sizlBitmap.cy, cjSize, // GLYPHBITS_SIZE(pgb->sizlBitmap.cx, pgb->sizlBitmap.cy, pfont->jBpp)); - }
VOID