SOURCES: cairo-1.2.4-lcd-filter-1.patch (NEW) - http://david.freet...

qrczak qrczak at pld-linux.org
Tue Feb 20 16:11:35 CET 2007


Author: qrczak                       Date: Tue Feb 20 15:11:35 2007 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- http://david.freetype.org/lcd/cairo-1.2.4-lcd-filter-1.patch:
  use freetype-2.3.0's LCD filtering
- Release 3

---- Files affected:
SOURCES:
   cairo-1.2.4-lcd-filter-1.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/cairo-1.2.4-lcd-filter-1.patch
diff -u /dev/null SOURCES/cairo-1.2.4-lcd-filter-1.patch:1.1
--- /dev/null	Tue Feb 20 16:11:35 2007
+++ SOURCES/cairo-1.2.4-lcd-filter-1.patch	Tue Feb 20 16:11:30 2007
@@ -0,0 +1,720 @@
+diff -urbN cairo-1.2.4-old/src/cairo-ft-font.c cairo-1.2.4/src/cairo-ft-font.c
+--- cairo-1.2.4-old/src/cairo-ft-font.c	2006-10-24 11:05:15.000000000 +0200
++++ cairo-1.2.4/src/cairo-ft-font.c	2006-10-24 11:06:45.000000000 +0200
+@@ -53,6 +53,8 @@
+ #include FT_SYNTHESIS_H
+ #endif
+ 
++#include FT_LCD_FILTER_H
++
+ #define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
+ #define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
+ #define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
+@@ -683,23 +685,300 @@
+     assert (error == 0);
+ }
+ 
+-/* Empirically-derived subpixel filtering values thanks to Keith
+- * Packard and libXft. */
+-static const int    filters[3][3] = {
+-    /* red */
+-#if 0
+-    {    65538*4/7,65538*2/7,65538*1/7 },
+-    /* green */
+-    {    65536*1/4, 65536*2/4, 65537*1/4 },
+-    /* blue */
+-    {    65538*1/7,65538*2/7,65538*4/7 },
++/* we sometimes need to convert the glyph bitmap in a FT_GlyphSlot
++ * into a different format. For example, we want to convert a
++ * FT_PIXEL_MODE_LCD or FT_PIXEL_MODE_LCD_V bitmap into a 32-bit
++ * ARGB or ABGR bitmap.
++ *
++ * this function prepares a target descriptor for this operation.
++ *
++ * input :: target bitmap descriptor. The function will set its
++ *          'width', 'rows' and 'pitch' fields, and only these
++ *
++ * slot  :: the glyph slot containing the source bitmap. this
++ *          function assumes that slot->format == FT_GLYPH_FORMAT_BITMAP
++ *
++ * mode  :: the requested final rendering mode. supported values are
++ *          MONO, NORMAL (i.e. gray), LCD and LCD_V
++ *
++ * the function returns the size in bytes of the corresponding buffer,
++ * it's up to the caller to allocate the corresponding memory block
++ * before calling _fill_xrender_bitmap
++ *
++ * it also returns -1 in case of error (e.g. incompatible arguments,
++ * like trying to convert a gray bitmap into a monochrome one)
++ */
++static int
++_compute_xrender_bitmap_size( FT_Bitmap*      target,
++                              FT_GlyphSlot    slot,
++                              FT_Render_Mode  mode )
++{
++    FT_Bitmap*  ftbit;
++    int         width, height, pitch;
++
++    if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
++        return -1;
++
++    // compute the size of the final bitmap
++    ftbit  = &slot->bitmap;
++
++    width  = ftbit->width;
++    height = ftbit->rows;
++    pitch  = (width+3) & ~3;
++
++    switch ( ftbit->pixel_mode )
++    {
++    case FT_PIXEL_MODE_MONO:
++        if ( mode == FT_RENDER_MODE_MONO )
++        {
++          pitch = (((width+31) & ~31) >> 3);
++          break;
++        }
++        /* fall-through */
++
++    case FT_PIXEL_MODE_GRAY:
++        if ( mode == FT_RENDER_MODE_LCD   ||
++            mode == FT_RENDER_MODE_LCD_V )
++        {
++            /* each pixel is replicated into a 32-bit ARGB value */
++            pitch = width*4;
++        }
++        break;
++
++    case FT_PIXEL_MODE_LCD:
++        if ( mode != FT_RENDER_MODE_LCD )
++            return -1;
++
++      /* horz pixel triplets are packed into 32-bit ARGB values */
++      width   /= 3;
++      pitch    = width*4;
++      break;
++
++    case FT_PIXEL_MODE_LCD_V:
++        if ( mode != FT_RENDER_MODE_LCD_V )
++            return -1;
++
++        /* vert pixel triplets are packed into 32-bit ARGB values */
++        height  /= 3;
++        pitch    = width*4;
++        break;
++
++    default:  /* unsupported source format */
++        return -1;
++    }
++
++    target->width  = width;
++    target->rows   = height;
++    target->pitch  = pitch;
++    target->buffer = NULL;
++
++    return pitch * height;
++}
++
++/* this functions converts the glyph bitmap found in a FT_GlyphSlot
++ * into a different format (see _compute_xrender_bitmap_size)
++ *
++ * you should call this function after _compute_xrender_bitmap_size
++ *
++ * target :: target bitmap descriptor. Note that its 'buffer' pointer
++ *           must point to memory allocated by the caller
++ *
++ * slot   :: the glyph slot containing the source bitmap
++ *
++ * mode   :: the requested final rendering mode
++ *
++ * bgr    :: boolean, set if BGR or VBGR pixel ordering is needed
++ */
++static void
++_fill_xrender_bitmap( FT_Bitmap*      target,
++                      FT_GlyphSlot    slot,
++                      FT_Render_Mode  mode,
++                      int             bgr )
++{
++    FT_Bitmap*   ftbit = &slot->bitmap;
++    unsigned char*   srcLine   = ftbit->buffer;
++    unsigned char*   dstLine   = target->buffer;
++    int              src_pitch = ftbit->pitch;
++    int              width     = target->width;
++    int              height    = target->rows;
++    int              pitch     = target->pitch;
++    int              subpixel;
++    int              h;
++
++    subpixel = ( mode == FT_RENDER_MODE_LCD ||
++        mode == FT_RENDER_MODE_LCD_V );
++
++    if ( src_pitch < 0 )
++      srcLine -= src_pitch*(ftbit->rows-1);
++
++    target->pixel_mode = ftbit->pixel_mode;
++
++    switch ( ftbit->pixel_mode )
++    {
++    case FT_PIXEL_MODE_MONO:
++        if ( subpixel )  /* convert mono to ARGB32 values */
++        {
++            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++            {
++                int  x;
++
++                for ( x = 0; x < width; x++ )
++                {
++                    if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
++                        ((unsigned int*)dstLine)[x] = 0xffffffffU;
++                }
++            }
++            target->pixel_mode = FT_PIXEL_MODE_LCD;
++        }
++        else if ( mode == FT_RENDER_MODE_NORMAL )  /* convert mono to 8-bit gray */
++        {
++            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++            {
++                int  x;
++
++                for ( x = 0; x < width; x++ )
++                {
++                    if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
++                        dstLine[x] = 0xff;
++                }
++            }
++            target->pixel_mode = FT_PIXEL_MODE_GRAY;
++        }
++        else  /* copy mono to mono */
++        {
++            int  bytes = (width+7) >> 3;
++
++            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++                memcpy( dstLine, srcLine, bytes );
++        }
++        break;
++
++    case FT_PIXEL_MODE_GRAY:
++        if ( subpixel )  /* convert gray to ARGB32 values */
++        {
++            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++            {
++                int            x;
++                unsigned int*  dst = (unsigned int*)dstLine;
++
++                for ( x = 0; x < width; x++ )
++                {
++                    unsigned int  pix = srcLine[x];
++
++                    pix |= (pix << 8);
++                    pix |= (pix << 16);
++
++                    dst[x] = pix;
++                }
++            }
++            target->pixel_mode = FT_PIXEL_MODE_LCD;
++        }
++        else  /* copy gray into gray */
++        {
++            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++                memcpy( dstLine, srcLine, width );
++        }
++        break;
++
++    case FT_PIXEL_MODE_LCD:
++        if ( !bgr )
++        {
++            /* convert horizontal RGB into ARGB32 */
++            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++            {
++                int            x;
++                unsigned char* src = srcLine;
++                unsigned int*  dst = (unsigned int*)dstLine;
++
++                for ( x = 0; x < width; x++, src += 3 )
++                {
++                    unsigned int  pix;
++
++                    pix = ((unsigned int)src[0] << 16) |
++                          ((unsigned int)src[1] <<  8) |
++                          ((unsigned int)src[2]      ) |
++                          ((unsigned int)src[1] << 24) ;
++
++                    dst[x] = pix;
++                }
++            }
++        }
++        else
++        {
++          /* convert horizontal BGR into ARGB32 */
++          for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
++          {
++              int            x;
++              unsigned char* src = srcLine;
++              unsigned int*  dst = (unsigned int*)dstLine;
++
++              for ( x = 0; x < width; x++, src += 3 )
++              {
++                  unsigned int  pix;
++
++                  pix = ((unsigned int)src[2] << 16) |
++                        ((unsigned int)src[1] <<  8) |
++                        ((unsigned int)src[0]      ) |
++                        ((unsigned int)src[1] << 24) ;
++
++                  dst[x] = pix;
++              }
++          }
++        }
++        break;
++
++    default:  /* FT_PIXEL_MODE_LCD_V */
++        /* convert vertical RGB into ARGB32 */
++        if ( !bgr )
++        {
++            for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
++            {
++                int            x;
++                unsigned char* src = srcLine;
++                unsigned int*  dst = (unsigned int*)dstLine;
++
++                for ( x = 0; x < width; x++, src += 1 )
++                {
++                    unsigned int  pix;
++#if 1
++                    pix = ((unsigned int)src[0]           << 16) |
++                          ((unsigned int)src[src_pitch]   <<  8) |
++                          ((unsigned int)src[src_pitch*2]      ) |
++                          0xFF000000 ;
++#else
++                    pix = ((unsigned int)src[0]           << 16) |
++                          ((unsigned int)src[src_pitch]   <<  8) |
++                          ((unsigned int)src[src_pitch*2]      ) |
++                          ((unsigned int)src[src_pitch]   << 24) ;
+ #endif
+-    {    65538*9/13,65538*3/13,65538*1/13 },
+-    /* green */
+-    {    65538*1/6, 65538*4/6, 65538*1/6 },
+-    /* blue */
+-    {    65538*1/13,65538*3/13,65538*9/13 },
+-};
++                    dst[x] = pix;
++                }
++            }
++        }
++        else
++        {
++            for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
++            {
++                int            x;
++                unsigned char* src = srcLine;
++                unsigned int*  dst = (unsigned int*)dstLine;
++
++                for ( x = 0; x < width; x++, src += 1 )
++                {
++                    unsigned int  pix;
++
++                    pix = ((unsigned int)src[src_pitch*2] << 16) |
++                        ((unsigned int)src[src_pitch]   <<  8) |
++                        ((unsigned int)src[0]                ) |
++                        ((unsigned int)src[src_pitch]   << 24) ;
++
++                    dst[x] = pix;
++                }
++            }
++        }
++    }
++}
++
+ 
+ /* Fills in val->image with an image surface created from @bitmap
+  */
+@@ -712,12 +991,14 @@
+     int width, height, stride;
+     unsigned char *data;
+     int format = CAIRO_FORMAT_A8;
+-    cairo_bool_t subpixel = FALSE;
++    cairo_image_surface_t  *image;
+ 
+     width = bitmap->width;
+     height = bitmap->rows;
+ 
+-    switch (bitmap->pixel_mode) {
++    {
++        switch (bitmap->pixel_mode)
++        {
+     case FT_PIXEL_MODE_MONO:
+ 	stride = (((width + 31) & ~31) >> 3);
+ 	if (own_buffer) {
+@@ -745,7 +1026,6 @@
+ 		}
+ 	    }
+ 	}
+-
+ #ifndef WORDS_BIGENDIAN
+ 	{
+ 	    unsigned char   *d = data;
+@@ -757,17 +1037,15 @@
+ 	    }
+ 	}
+ #endif
++
+ 	format = CAIRO_FORMAT_A1;
+ 	break;
+ 
+     case FT_PIXEL_MODE_LCD:
+     case FT_PIXEL_MODE_LCD_V:
+     case FT_PIXEL_MODE_GRAY:
+-	switch (font_options->antialias) {
+-	case CAIRO_ANTIALIAS_DEFAULT:
+-	case CAIRO_ANTIALIAS_GRAY:
+-	case CAIRO_ANTIALIAS_NONE:
+-	default:
++            if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL)
++            {
+ 	    stride = bitmap->pitch;
+ 	    if (own_buffer) {
+ 		data = bitmap->buffer;
+@@ -778,101 +1056,19 @@
+ 		memcpy (data, bitmap->buffer, stride * height);
+ 	    }
+ 	    format = CAIRO_FORMAT_A8;
+-	    break;
+-	case CAIRO_ANTIALIAS_SUBPIXEL: {
+-	    int		    x, y;
+-	    unsigned char   *in_line, *out_line, *in;
+-	    unsigned int    *out;
+-	    unsigned int    red, green, blue;
+-	    int		    rf, gf, bf;
+-	    int		    s;
+-	    int		    o, os;
+-	    unsigned char   *data_rgba;
+-	    unsigned int    width_rgba, stride_rgba;
+-	    int		    vmul = 1;
+-	    int		    hmul = 1;
++            } else {
++                // if we get there, the  data from the source bitmap
++                // really comes from _fill_xrender_bitmap, and is
++                // made of 32-bit ARGB or ABGR values
++                assert(own_buffer != 0);
++                assert(bitmap->pixel_mode != FT_PIXEL_MODE_GRAY);
+ 
+-	    switch (font_options->subpixel_order) {
+-	    case CAIRO_SUBPIXEL_ORDER_DEFAULT:
+-	    case CAIRO_SUBPIXEL_ORDER_RGB:
+-	    case CAIRO_SUBPIXEL_ORDER_BGR:
+-	    default:
+-		width /= 3;
+-		hmul = 3;
+-		break;
+-	    case CAIRO_SUBPIXEL_ORDER_VRGB:
+-	    case CAIRO_SUBPIXEL_ORDER_VBGR:
+-		vmul = 3;
+-		height /= 3;
+-		break;
+-	    }
+-	    /*
+-	     * Filter the glyph to soften the color fringes
+-	     */
+-	    width_rgba = width;
++                data   = bitmap->buffer;
+ 	    stride = bitmap->pitch;
+-	    stride_rgba = (width_rgba * 4 + 3) & ~3;
+-	    data_rgba = calloc (1, stride_rgba * height);
+-
+-	    os = 1;
+-	    switch (font_options->subpixel_order) {
+-	    case CAIRO_SUBPIXEL_ORDER_VRGB:
+-		os = stride;
+-	    case CAIRO_SUBPIXEL_ORDER_DEFAULT:
+-	    case CAIRO_SUBPIXEL_ORDER_RGB:
+-	    default:
+-		rf = 0;
+-		gf = 1;
+-		bf = 2;
+-		break;
+-	    case CAIRO_SUBPIXEL_ORDER_VBGR:
+-		os = stride;
+-	    case CAIRO_SUBPIXEL_ORDER_BGR:
+-		bf = 0;
+-		gf = 1;
+-		rf = 2;
+-		break;
+-	    }
+-	    in_line = bitmap->buffer;
+-	    out_line = data_rgba;
+-	    for (y = 0; y < height; y++)
+-	    {
+-		in = in_line;
+-		out = (unsigned int *) out_line;
+-		in_line += stride * vmul;
+-		out_line += stride_rgba;
+-		for (x = 0; x < width * hmul; x += hmul)
+-		{
+-		    red = green = blue = 0;
+-		    o = 0;
+-		    for (s = 0; s < 3; s++)
+-		    {
+-			red += filters[rf][s]*in[x+o];
+-			green += filters[gf][s]*in[x+o];
+-			blue += filters[bf][s]*in[x+o];
+-			o += os;
+-		    }
+-		    red = red / 65536;
+-		    green = green / 65536;
+-		    blue = blue / 65536;
+-		    *out++ = (green << 24) | (red << 16) | (green << 8) | blue;
+-		}
+-	    }
+-
+-	    /* Images here are stored in native format. The
+-	     * backend must convert to its own format as needed
+-	     */
+-
+-	    if (own_buffer)
+-		free (bitmap->buffer);
+-	    data = data_rgba;
+-	    stride = stride_rgba;
+ 	    format = CAIRO_FORMAT_ARGB32;
+-	    subpixel = TRUE;
+-	    break;
+-	}
+ 	}
+ 	break;
++
+     case FT_PIXEL_MODE_GRAY2:
+     case FT_PIXEL_MODE_GRAY4:
+ 	/* These could be triggered by very rare types of TrueType fonts */
+@@ -880,20 +1076,21 @@
+ 	return CAIRO_STATUS_NO_MEMORY;
+     }
+ 
+-    *surface = (cairo_image_surface_t *)
++        /* XXX */
++        *surface = image = (cairo_image_surface_t *)
+ 	cairo_image_surface_create_for_data (data,
+ 					     format,
+ 					     width, height, stride);
+-    if ((*surface)->base.status) {
++        if (image->base.status) {
+ 	free (data);
+ 	return CAIRO_STATUS_NO_MEMORY;
+     }
+ 
+-    if (subpixel)
+-	pixman_image_set_component_alpha ((*surface)->pixman_image, TRUE);
+-
+-    _cairo_image_surface_assume_ownership_of_data ((*surface));
++        if (font_options->antialias == CAIRO_ANTIALIAS_SUBPIXEL)
++            pixman_image_set_component_alpha (image->pixman_image, TRUE);
+ 
++        _cairo_image_surface_assume_ownership_of_data (image);
++    }
+     return CAIRO_STATUS_SUCCESS;
+ }
+ 
+@@ -917,16 +1114,44 @@
+ 		       cairo_font_options_t	 *font_options,
+ 		       cairo_image_surface_t	**surface)
+ {
++    int rgba = FC_RGBA_UNKNOWN;
+     FT_GlyphSlot glyphslot = face->glyph;
+     FT_Outline *outline = &glyphslot->outline;
+     FT_Bitmap bitmap;
+     FT_BBox cbox;
+-    FT_Matrix matrix;
+-    int hmul = 1;
+-    int vmul = 1;
+     unsigned int width, height, stride;
+-    cairo_bool_t subpixel = FALSE;
++    cairo_format_t format;
+     cairo_status_t status;
++    FT_Error  fterror;
++    FT_Library  library = glyphslot->library;
++    FT_Render_Mode  render_mode = FT_RENDER_MODE_NORMAL;
++
++    switch (font_options->antialias)
++    {
++    case CAIRO_ANTIALIAS_NONE:
++        render_mode = FT_RENDER_MODE_MONO;
++        break;
++
++    case CAIRO_ANTIALIAS_SUBPIXEL:
++        switch (font_options->subpixel_order)
++        {
++            case CAIRO_SUBPIXEL_ORDER_DEFAULT:
++            case CAIRO_SUBPIXEL_ORDER_RGB:
++            case CAIRO_SUBPIXEL_ORDER_BGR:
++                render_mode = FT_RENDER_MODE_LCD;
++                break;
++
++            case CAIRO_SUBPIXEL_ORDER_VRGB:
++            case CAIRO_SUBPIXEL_ORDER_VBGR:
++                render_mode = FT_RENDER_MODE_LCD_V;
++                break;
++        }
++        break;
++
++    case CAIRO_ANTIALIAS_DEFAULT:
++    case CAIRO_ANTIALIAS_GRAY:
++        render_mode = FT_RENDER_MODE_NORMAL;
++    }
+ 
+     FT_Outline_Get_CBox (outline, &cbox);
+ 
+@@ -937,98 +1162,90 @@
+ 
+     width = (unsigned int) ((cbox.xMax - cbox.xMin) >> 6);
+     height = (unsigned int) ((cbox.yMax - cbox.yMin) >> 6);
+-    stride = (width * hmul + 3) & ~3;
++    stride = (width + 3) & ~3;
+ 
+     if (width * height == 0) {
+-	cairo_format_t format;
+ 	/* Looks like fb handles zero-sized images just fine */
+-	switch (font_options->antialias) {
+-	case CAIRO_ANTIALIAS_NONE:
++        switch (render_mode)
++        {
++          case FT_RENDER_MODE_MONO:
+ 	    format = CAIRO_FORMAT_A1;
+ 	    break;
+-	case CAIRO_ANTIALIAS_SUBPIXEL:
+-	    format= CAIRO_FORMAT_ARGB32;
++          case FT_RENDER_MODE_LCD:
++          case FT_RENDER_MODE_LCD_V:
++            format = CAIRO_FORMAT_ARGB32;
+ 	    break;
+-	case CAIRO_ANTIALIAS_DEFAULT:
+-	case CAIRO_ANTIALIAS_GRAY:
+ 	default:
+ 	    format = CAIRO_FORMAT_A8;
+-	    break;
+ 	}
<<Diff was trimmed, longer than 597 lines>>


More information about the pld-cvs-commit mailing list