2018-06-03 22:00:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftlcdfil.h
|
|
|
|
*
|
|
|
|
* FreeType API for color filtering of subpixel bitmap glyphs
|
|
|
|
* (specification).
|
|
|
|
*
|
|
|
|
* Copyright 2006-2018 by
|
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
2006-09-29 23:31:53 +02:00
|
|
|
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#ifndef FTLCDFIL_H_
|
|
|
|
#define FTLCDFIL_H_
|
2006-09-27 11:12:43 +02:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
2017-12-06 23:15:54 +01:00
|
|
|
#include FT_PARAMETER_TAGS_H
|
2006-09-27 11:12:43 +02:00
|
|
|
|
2008-09-12 18:27:48 +02:00
|
|
|
#ifdef FREETYPE_H
|
|
|
|
#error "freetype.h of FreeType 1 has been loaded!"
|
|
|
|
#error "Please fix the directory search order for header files"
|
|
|
|
#error "so that freetype.h of FreeType 2 is found first."
|
|
|
|
#endif
|
|
|
|
|
2006-09-29 23:31:53 +02:00
|
|
|
|
2006-09-27 11:12:43 +02:00
|
|
|
FT_BEGIN_HEADER
|
|
|
|
|
2007-01-12 10:28:44 +01:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* @section:
|
2018-06-07 08:48:48 +02:00
|
|
|
* lcd_rendering
|
2007-01-12 10:28:44 +01:00
|
|
|
*
|
|
|
|
* @title:
|
2018-06-07 08:48:48 +02:00
|
|
|
* Subpixel Rendering
|
2007-01-12 10:28:44 +01:00
|
|
|
*
|
|
|
|
* @abstract:
|
2018-06-07 08:48:48 +02:00
|
|
|
* API to control subpixel rendering.
|
2007-01-12 10:28:44 +01:00
|
|
|
*
|
|
|
|
* @description:
|
2018-06-07 08:48:48 +02:00
|
|
|
* FreeType provides two alternative subpixel rendering technologies.
|
2017-03-09 06:08:38 +01:00
|
|
|
* Should you #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your
|
2018-06-07 08:48:48 +02:00
|
|
|
* `ftoption.h', this enables patented ClearType-style rendering.
|
|
|
|
* Otherwise, Harmony LCD rendering is enabled. These technologies are
|
|
|
|
* controlled differently and API described below, although always
|
|
|
|
* available, performs its function when appropriate method is enabled
|
|
|
|
* and does nothing otherwise.
|
2017-03-09 06:08:38 +01:00
|
|
|
*
|
|
|
|
* ClearType-style LCD rendering exploits the color-striped structure of
|
|
|
|
* LCD pixels, increasing the available resolution in the direction of
|
2018-05-31 05:29:41 +02:00
|
|
|
* the stripe (usually horizontal RGB) by a factor of~3. Using the
|
|
|
|
* subpixels coverages unfiltered can create severe color fringes
|
|
|
|
* especially when rendering thin features. Indeed, to produce
|
2018-06-07 08:48:48 +02:00
|
|
|
* black-on-white text, the nearby color subpixels must be dimmed equally.
|
2007-01-12 10:28:44 +01:00
|
|
|
*
|
2018-05-31 05:29:41 +02:00
|
|
|
* A good 5-tap FIR filter should be applied to subpixel coverages
|
|
|
|
* regardless of pixel boundaries and should have these properties:
|
2015-11-28 12:04:28 +01:00
|
|
|
*
|
2018-05-31 05:29:41 +02:00
|
|
|
* 1) It should be symmetrical, like {~a, b, c, b, a~}, to avoid
|
|
|
|
* any shifts in appearance.
|
2015-11-28 12:04:28 +01:00
|
|
|
*
|
2018-05-31 05:29:41 +02:00
|
|
|
* 2) It should be color-balanced, meaning a~+ b~=~c, to reduce color
|
|
|
|
* fringes by distributing the computed coverage for one subpixel to
|
|
|
|
* all subpixels equally.
|
2015-11-28 12:04:28 +01:00
|
|
|
*
|
2018-05-31 05:29:41 +02:00
|
|
|
* 3) It should be normalized, meaning 2a~+ 2b~+ c~=~1.0 to maintain
|
|
|
|
* overall brightness.
|
2015-11-28 12:04:28 +01:00
|
|
|
*
|
2018-06-13 03:59:15 +02:00
|
|
|
* Boxy 3-tap filter {0, 1/3, 1/3, 1/3, 0} is sharper but is less
|
|
|
|
* forgiving of non-ideal gamma curves of a screen (and viewing angles),
|
2018-06-07 08:48:48 +02:00
|
|
|
* beveled filters are fuzzier but more tolerant.
|
|
|
|
*
|
|
|
|
* Use the @FT_Library_SetLcdFilter or @FT_Library_SetLcdFilterWeights
|
|
|
|
* API to specify a low-pass filter, which is then applied to
|
|
|
|
* subpixel-rendered bitmaps generated through @FT_Render_Glyph.
|
|
|
|
*
|
|
|
|
* Harmony LCD rendering is suitable to panels with any regular subpixel
|
|
|
|
* structure, not just monitors with 3 color striped subpixels, as long as
|
|
|
|
* the color subpixels have fixed positions relative to the pixel center.
|
|
|
|
* In this case, each color channel is then rendered separately after
|
|
|
|
* shifting the outline opposite to the subpixel shift so that the
|
|
|
|
* coverage maps are aligned. This method is immune to color fringes
|
|
|
|
* because the shifts do not change integral coverage.
|
|
|
|
*
|
|
|
|
* The subpixel geometry must be specified by xy-coordinates for each
|
|
|
|
* subpixel. By convention they may come in the RGB order:
|
2018-06-13 03:59:15 +02:00
|
|
|
* {{-1/3, 0}, {0, 0}, {1/3, 0}} for standard RGB striped panel or
|
2018-06-07 08:48:48 +02:00
|
|
|
* {{-1/6, 1/4}, {-1/6, -1/4}, {1/3, 0}} for a certain PenTile panel.
|
|
|
|
*
|
|
|
|
* Use the @FT_Library_SetLcdGeometry API to specify subpixel positions.
|
|
|
|
* If one follows the RGB order convention, the same order applies
|
|
|
|
* to the resulting @FT_PIXEL_MODE_LCD and @FT_PIXEL_MODE_LCD_V bitmaps.
|
|
|
|
* Note, however, that the coordinate frame for the latter must be rotated
|
|
|
|
* clockwise. Harmony with default LCD geometry is equivalent to
|
|
|
|
* ClearType with light filter.
|
|
|
|
*
|
|
|
|
* As a result of ClearType filtering or Harmony rendering, the dimensions
|
|
|
|
* of LCD bitmaps can be either wider or taller than the dimensions of
|
|
|
|
* the corresponding outline with regard to the pixel grid. For example,
|
|
|
|
* for @FT_RENDER_MODE_LCD, the filter adds 2~subpixels to the left, and
|
2018-05-31 05:29:41 +02:00
|
|
|
* 2~subpixels to the right. The bitmap offset values are adjusted
|
2016-01-20 04:54:59 +01:00
|
|
|
* accordingly, so clients shouldn't need to modify their layout and
|
|
|
|
* glyph positioning code when enabling the filter.
|
|
|
|
*
|
2018-06-07 08:48:48 +02:00
|
|
|
* The ClearType and Harmony rendering is applicable to glyph bitmaps
|
2018-06-13 03:59:15 +02:00
|
|
|
* rendered through @FT_Render_Glyph, @FT_Load_Glyph, @FT_Load_Char, and
|
|
|
|
* @FT_Glyph_To_Bitmap, when @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V
|
|
|
|
* is specified. This API does not control @FT_Outline_Render and
|
|
|
|
* @FT_Outline_Get_Bitmap.
|
|
|
|
*
|
|
|
|
* The described algorithms can completely remove color artefacts when
|
|
|
|
* combined with gamma-corrected alpha blending in linear space.
|
2018-06-07 08:48:48 +02:00
|
|
|
* Each of the 3~alpha values (subpixels) must by independently used to
|
|
|
|
* blend one color channel. That is, red alpha blends the red channel of
|
|
|
|
* the text color with the red channel of the background pixel.
|
2007-01-12 10:28:44 +01:00
|
|
|
*/
|
|
|
|
|
2006-09-29 23:31:53 +02:00
|
|
|
|
2006-11-14 11:37:10 +01:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
2010-07-18 18:41:47 +02:00
|
|
|
* @enum:
|
2006-11-14 11:37:10 +01:00
|
|
|
* FT_LcdFilter
|
|
|
|
*
|
|
|
|
* @description:
|
|
|
|
* A list of values to identify various types of LCD filters.
|
|
|
|
*
|
|
|
|
* @values:
|
|
|
|
* FT_LCD_FILTER_NONE ::
|
|
|
|
* Do not perform filtering. When used with subpixel rendering, this
|
|
|
|
* results in sometimes severe color fringes.
|
|
|
|
*
|
|
|
|
* FT_LCD_FILTER_DEFAULT ::
|
2018-05-31 05:29:41 +02:00
|
|
|
* This is a beveled, normalized, and color-balanced five-tap filter
|
|
|
|
* with weights of [0x08 0x4D 0x56 0x4D 0x08] in 1/256th units.
|
2015-11-28 12:04:28 +01:00
|
|
|
*
|
2006-11-14 11:37:10 +01:00
|
|
|
* FT_LCD_FILTER_LIGHT ::
|
2018-05-31 05:29:41 +02:00
|
|
|
* this is a boxy, normalized, and color-balanced three-tap filter
|
|
|
|
* with weights of [0x00 0x55 0x56 0x55 0x00] in 1/256th units.
|
2006-11-14 11:37:10 +01:00
|
|
|
*
|
|
|
|
* FT_LCD_FILTER_LEGACY ::
|
2018-05-31 05:29:41 +02:00
|
|
|
* FT_LCD_FILTER_LEGACY1 ::
|
2006-11-14 11:37:10 +01:00
|
|
|
* This filter corresponds to the original libXft color filter. It
|
|
|
|
* provides high contrast output but can exhibit really bad color
|
2007-01-16 07:11:27 +01:00
|
|
|
* fringes if glyphs are not extremely well hinted to the pixel grid.
|
2006-11-14 11:37:10 +01:00
|
|
|
* This filter is only provided for comparison purposes, and might be
|
2018-05-31 05:29:41 +02:00
|
|
|
* disabled or stay unsupported in the future. The second value is
|
|
|
|
* provided for compatibility with FontConfig, which historically
|
|
|
|
* used different enumeration, sometimes incorrectly forwarded to
|
|
|
|
* FreeType.
|
2015-11-20 16:03:09 +01:00
|
|
|
*
|
2007-01-12 10:28:44 +01:00
|
|
|
* @since:
|
2015-11-20 16:03:09 +01:00
|
|
|
* 2.3.0 (`FT_LCD_FILTER_LEGACY1' since 2.6.2)
|
2006-11-14 11:37:10 +01:00
|
|
|
*/
|
2008-05-29 00:17:28 +02:00
|
|
|
typedef enum FT_LcdFilter_
|
2006-11-10 17:49:42 +01:00
|
|
|
{
|
|
|
|
FT_LCD_FILTER_NONE = 0,
|
|
|
|
FT_LCD_FILTER_DEFAULT = 1,
|
|
|
|
FT_LCD_FILTER_LIGHT = 2,
|
2015-11-20 16:03:09 +01:00
|
|
|
FT_LCD_FILTER_LEGACY1 = 3,
|
2006-11-10 17:49:42 +01:00
|
|
|
FT_LCD_FILTER_LEGACY = 16,
|
|
|
|
|
|
|
|
FT_LCD_FILTER_MAX /* do not remove */
|
|
|
|
|
|
|
|
} FT_LcdFilter;
|
|
|
|
|
2006-09-29 23:31:53 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
2018-06-17 11:22:37 +02:00
|
|
|
* @function:
|
2006-09-29 23:31:53 +02:00
|
|
|
* FT_Library_SetLcdFilter
|
|
|
|
*
|
|
|
|
* @description:
|
|
|
|
* This function is used to apply color filtering to LCD decimated
|
|
|
|
* bitmaps, like the ones used when calling @FT_Render_Glyph with
|
|
|
|
* @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V.
|
|
|
|
*
|
|
|
|
* @input:
|
2006-11-14 11:37:10 +01:00
|
|
|
* library ::
|
|
|
|
* A handle to the target library instance.
|
2006-09-29 23:31:53 +02:00
|
|
|
*
|
2006-11-14 11:37:10 +01:00
|
|
|
* filter ::
|
|
|
|
* The filter type.
|
2006-09-29 23:31:53 +02:00
|
|
|
*
|
|
|
|
* You can use @FT_LCD_FILTER_NONE here to disable this feature, or
|
|
|
|
* @FT_LCD_FILTER_DEFAULT to use a default filter that should work
|
|
|
|
* well on most LCD screens.
|
|
|
|
*
|
|
|
|
* @return:
|
2008-06-26 21:56:51 +02:00
|
|
|
* FreeType error code. 0~means success.
|
2006-09-29 23:31:53 +02:00
|
|
|
*
|
|
|
|
* @note:
|
|
|
|
* This feature is always disabled by default. Clients must make an
|
2006-11-14 11:37:10 +01:00
|
|
|
* explicit call to this function with a `filter' value other than
|
|
|
|
* @FT_LCD_FILTER_NONE in order to enable it.
|
2006-09-29 23:31:53 +02:00
|
|
|
*
|
|
|
|
* Due to *PATENTS* covering subpixel rendering, this function doesn't
|
2006-12-01 09:20:47 +01:00
|
|
|
* do anything except returning `FT_Err_Unimplemented_Feature' if the
|
2006-09-29 23:31:53 +02:00
|
|
|
* configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not
|
|
|
|
* defined in your build of the library, which should correspond to all
|
2007-01-10 15:18:15 +01:00
|
|
|
* default builds of FreeType.
|
2006-09-29 23:31:53 +02:00
|
|
|
*
|
2007-01-12 10:28:44 +01:00
|
|
|
* @since:
|
|
|
|
* 2.3.0
|
2006-09-29 23:31:53 +02:00
|
|
|
*/
|
2006-09-27 11:12:43 +02:00
|
|
|
FT_EXPORT( FT_Error )
|
2006-11-10 17:49:42 +01:00
|
|
|
FT_Library_SetLcdFilter( FT_Library library,
|
|
|
|
FT_LcdFilter filter );
|
2006-09-29 23:31:53 +02:00
|
|
|
|
2010-04-05 08:46:26 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
2018-06-17 11:22:37 +02:00
|
|
|
* @function:
|
2010-04-05 08:46:26 +02:00
|
|
|
* FT_Library_SetLcdFilterWeights
|
|
|
|
*
|
|
|
|
* @description:
|
2016-01-15 05:31:08 +01:00
|
|
|
* This function can be used to enable LCD filter with custom weights,
|
|
|
|
* instead of using presets in @FT_Library_SetLcdFilter.
|
2010-04-05 08:46:26 +02:00
|
|
|
*
|
|
|
|
* @input:
|
|
|
|
* library ::
|
|
|
|
* A handle to the target library instance.
|
|
|
|
*
|
|
|
|
* weights ::
|
|
|
|
* A pointer to an array; the function copies the first five bytes and
|
2018-05-31 05:29:41 +02:00
|
|
|
* uses them to specify the filter weights in 1/256th units.
|
2010-04-05 08:46:26 +02:00
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*
|
2017-02-18 10:42:23 +01:00
|
|
|
* LCD filter weights can also be set per face using @FT_Face_Properties
|
|
|
|
* with @FT_PARAM_TAG_LCD_FILTER_WEIGHTS.
|
|
|
|
*
|
2010-04-05 08:46:26 +02:00
|
|
|
* @since:
|
2010-07-04 07:49:03 +02:00
|
|
|
* 2.4.0
|
2010-04-05 08:46:26 +02:00
|
|
|
*/
|
|
|
|
FT_EXPORT( FT_Error )
|
|
|
|
FT_Library_SetLcdFilterWeights( FT_Library library,
|
|
|
|
unsigned char *weights );
|
|
|
|
|
2017-02-16 20:45:45 +01:00
|
|
|
|
2018-06-03 22:00:42 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2017-02-16 20:45:45 +01:00
|
|
|
* @type:
|
|
|
|
* FT_LcdFiveTapFilter
|
|
|
|
*
|
|
|
|
* @description:
|
|
|
|
* A typedef for passing the five LCD filter weights to
|
|
|
|
* @FT_Face_Properties within an @FT_Parameter structure.
|
|
|
|
*
|
2017-09-21 14:56:58 +02:00
|
|
|
* @since:
|
|
|
|
* 2.8
|
|
|
|
*
|
2017-02-16 20:45:45 +01:00
|
|
|
*/
|
|
|
|
#define FT_LCD_FILTER_FIVE_TAPS 5
|
|
|
|
|
|
|
|
typedef FT_Byte FT_LcdFiveTapFilter[FT_LCD_FILTER_FIVE_TAPS];
|
|
|
|
|
2017-09-28 06:20:50 +02:00
|
|
|
|
2018-06-07 08:48:48 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2018-06-17 11:22:37 +02:00
|
|
|
* @function:
|
2018-06-07 08:48:48 +02:00
|
|
|
* FT_Library_SetLcdGeometry
|
|
|
|
*
|
|
|
|
* @description:
|
|
|
|
* This function can be used to modify default positions of color
|
|
|
|
* subpixels, which controls Harmony LCD rendering.
|
|
|
|
*
|
|
|
|
* @input:
|
|
|
|
* library ::
|
|
|
|
* A handle to the target library instance.
|
|
|
|
*
|
|
|
|
* sub ::
|
|
|
|
* A pointer to an array of 3 vectors in 26.6 fractional pixel format;
|
|
|
|
* the function modifies the default values, see the note below.
|
|
|
|
*
|
|
|
|
* @return:
|
|
|
|
* FreeType error code. 0~means success.
|
|
|
|
*
|
|
|
|
* @note:
|
|
|
|
* Subpixel geometry examples:
|
|
|
|
*
|
2018-06-13 03:59:15 +02:00
|
|
|
* - {{-21, 0}, {0, 0}, {21, 0}} is the default, corresponding to 3 color
|
2018-06-07 08:48:48 +02:00
|
|
|
* stripes shifted by a third of a pixel. This could be an RGB panel.
|
|
|
|
*
|
|
|
|
* - {{21, 0}, {0, 0}, {-21, 0}} looks the same as the default but
|
|
|
|
* can specify a BGR panel instead, while keeping the bitmap in the same
|
|
|
|
* RGB888 format.
|
|
|
|
*
|
|
|
|
* - {{0, 21}, {0, 0}, {0, -21}} is the vertical RGB, but the bitmap
|
|
|
|
* stays RGB888 as a result.
|
|
|
|
*
|
|
|
|
* - {{-11, 16}, {-11, -16}, {22, 0}} is a certain PenTile arrangement.
|
|
|
|
*
|
|
|
|
* This function does nothing and returns `FT_Err_Unimplemented_Feature'
|
|
|
|
* in the context of ClearType-style subpixel rendering when
|
|
|
|
* FT_CONFIG_OPTION_SUBPIXEL_RENDERING is defined in your build of the
|
|
|
|
* library.
|
|
|
|
*
|
|
|
|
* @since:
|
|
|
|
* 2.10.0
|
|
|
|
*/
|
|
|
|
FT_EXPORT( FT_Error )
|
|
|
|
FT_Library_SetLcdGeometry( FT_Library library,
|
|
|
|
FT_Vector sub[3] );
|
|
|
|
|
2006-09-29 23:31:53 +02:00
|
|
|
/* */
|
|
|
|
|
2006-09-27 11:12:43 +02:00
|
|
|
|
|
|
|
FT_END_HEADER
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#endif /* FTLCDFIL_H_ */
|
2006-09-29 23:31:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|