From 460d23f1689f14f5812bfe4b322fd3f2a449905e Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Mon, 5 Apr 2010 08:46:26 +0200 Subject: [PATCH] Add new function `FT_Library_SetLcdFilterWeights'. This is based on code written by Lifter . It fixes FreeDesktop bug #27386. * src/base/ftlcdfil.c (FT_Library_SetLcdFilterWeights): New function. * include/freetype/ftlcdfil.h: Updated. * docs/CHANGES: Updated. --- ChangeLog | 15 +++++++++++++ docs/CHANGES | 13 ++++++++++- include/freetype/ftlcdfil.h | 43 ++++++++++++++++++++++++++++++++++++- src/base/ftlcdfil.c | 37 +++++++++++++++++++++++++------ 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c62e1699..a8fa18f81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-04-05 Werner Lemberg + + Add new function `FT_Library_SetLcdFilterWeights'. + + This is based on code written by Lifter + . It fixes + FreeDesktop bug #27386. + + * src/base/ftlcdfil.c (FT_Library_SetLcdFilterWeights): New + function. + + * include/freetype/ftlcdfil.h: Updated. + + * docs/CHANGES: Updated. + 2010-04-01 John Tytgat Fix Savannah bug #29404. diff --git a/docs/CHANGES b/docs/CHANGES index 018d16c57..761d92af2 100644 --- a/docs/CHANGES +++ b/docs/CHANGES @@ -1,3 +1,13 @@ +CHANGES BETWEEN 2.3.12 and 2.3.13 + + I. IMPORTANT CHANGES + + - A new function `FT_Library_SetLcdFilterWeights' is available to + adjust the filter weights set by `FT_Library_SetLcdFilter'. + + +====================================================================== + CHANGES BETWEEN 2.3.11 and 2.3.12 I. IMPORTANT CHANGES @@ -3378,7 +3388,8 @@ Extensions support: ------------------------------------------------------------------------ -Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by +Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 by David Turner, Robert Wilhelm, and Werner Lemberg. This file is part of the FreeType project, and may only be used, diff --git a/include/freetype/ftlcdfil.h b/include/freetype/ftlcdfil.h index c6201b38e..992a06412 100644 --- a/include/freetype/ftlcdfil.h +++ b/include/freetype/ftlcdfil.h @@ -5,7 +5,7 @@ /* FreeType API for color filtering of subpixel bitmap glyphs */ /* (specification). */ /* */ -/* Copyright 2006, 2007, 2008 by */ +/* Copyright 2006, 2007, 2008, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -161,6 +161,47 @@ FT_BEGIN_HEADER FT_Library_SetLcdFilter( FT_Library library, FT_LcdFilter filter ); + + /************************************************************************** + * + * @func: + * FT_Library_SetLcdFilterWeights + * + * @description: + * Use this function to override the filter weights selected by + * @FT_Library_SetLcdFilter. By default, FreeType uses the quintuple + * (0x00, 0x55, 0x56, 0x55, 0x00) for FT_LCD_FILTER_LIGHT, and (0x10, + * 0x40, 0x70, 0x40, 0x10) for FT_LCD_FILTER_DEFAULT and + * FT_LCD_FILTER_LEGACY. + * + * @input: + * library :: + * A handle to the target library instance. + * + * weights :: + * A pointer to an array; the function copies the first five bytes and + * uses them to specify the filter weights. + * + * @return: + * FreeType error code. 0~means success. + * + * @note: + * Due to *PATENTS* covering subpixel rendering, this function doesn't + * do anything except returning `FT_Err_Unimplemented_Feature' if the + * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not + * defined in your build of the library, which should correspond to all + * default builds of FreeType. + * + * This function must be called after @FT_Library_SetLcdFilter to have + * any effect. + * + * @since: + * 2.3.13 + */ + FT_EXPORT( FT_Error ) + FT_Library_SetLcdFilterWeights( FT_Library library, + unsigned char *weights ); + /* */ diff --git a/src/base/ftlcdfil.c b/src/base/ftlcdfil.c index 80640111c..0da4ba160 100644 --- a/src/base/ftlcdfil.c +++ b/src/base/ftlcdfil.c @@ -4,7 +4,7 @@ /* */ /* FreeType API for color filtering of subpixel bitmap glyphs (body). */ /* */ -/* Copyright 2006, 2008, 2009 by */ +/* Copyright 2006, 2008, 2009, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -267,18 +267,31 @@ FT_EXPORT_DEF( FT_Error ) - FT_Library_SetLcdFilter( FT_Library library, - FT_LcdFilter filter ) + FT_Library_SetLcdFilterWeights( FT_Library library, + unsigned char *weights ) + { + if ( !library || !weights ) + return FT_Err_Invalid_Argument; + + ft_memcpy( library->lcd_weights, weights, 5 ); + + return FT_Err_Ok; + } + + + FT_EXPORT_DEF( FT_Error ) + FT_Library_SetLcdFilter( FT_Library library, + FT_LcdFilter filter ) { static const FT_Byte light_filter[5] = - { 0, 85, 86, 85, 0 }; + { 0x00, 0x55, 0x56, 0x55, 0x00 }; /* the values here sum up to a value larger than 256, */ /* providing a cheap gamma correction */ static const FT_Byte default_filter[5] = { 0x10, 0x40, 0x70, 0x40, 0x10 }; - if ( library == NULL ) + if ( !library ) return FT_Err_Invalid_Argument; switch ( filter ) @@ -330,11 +343,23 @@ } library->lcd_filter = filter; - return 0; + + return FT_Err_Ok; } #else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ + FT_EXPORT_DEF( FT_Error ) + FT_Library_SetLcdFilterWeights( FT_Library library, + unsigned char *weights ) + { + FT_UNUSED( library ); + FT_UNUSED( weights ); + + return FT_Err_Unimplemented_Feature; + } + + FT_EXPORT_DEF( FT_Error ) FT_Library_SetLcdFilter( FT_Library library, FT_LcdFilter filter )