ftlcdfil.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /***************************************************************************/
  2. /* */
  3. /* ftlcdfil.h */
  4. /* */
  5. /* FreeType API for color filtering of subpixel bitmap glyphs */
  6. /* (specification). */
  7. /* */
  8. /* Copyright 2006-2008, 2010, 2013 by */
  9. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  10. /* */
  11. /* This file is part of the FreeType project, and may only be used, */
  12. /* modified, and distributed under the terms of the FreeType project */
  13. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  14. /* this file you indicate that you have read the license and */
  15. /* understand and accept it fully. */
  16. /* */
  17. /***************************************************************************/
  18. #ifndef __FT_LCD_FILTER_H__
  19. #define __FT_LCD_FILTER_H__
  20. #include <ft2build.h>
  21. #include FT_FREETYPE_H
  22. #ifdef FREETYPE_H
  23. #error "freetype.h of FreeType 1 has been loaded!"
  24. #error "Please fix the directory search order for header files"
  25. #error "so that freetype.h of FreeType 2 is found first."
  26. #endif
  27. FT_BEGIN_HEADER
  28. /***************************************************************************
  29. *
  30. * @section:
  31. * lcd_filtering
  32. *
  33. * @title:
  34. * LCD Filtering
  35. *
  36. * @abstract:
  37. * Reduce color fringes of LCD-optimized bitmaps.
  38. *
  39. * @description:
  40. * The @FT_Library_SetLcdFilter API can be used to specify a low-pass
  41. * filter, which is then applied to LCD-optimized bitmaps generated
  42. * through @FT_Render_Glyph. This is useful to reduce color fringes
  43. * that would occur with unfiltered rendering.
  44. *
  45. * Note that no filter is active by default, and that this function is
  46. * *not* implemented in default builds of the library. You need to
  47. * #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING in your `ftoption.h' file
  48. * in order to activate it.
  49. *
  50. * FreeType generates alpha coverage maps, which are linear by nature.
  51. * For instance, the value 0x80 in bitmap representation means that
  52. * (within numerical precision) 0x80/0xff fraction of that pixel is
  53. * covered by the glyph's outline. The blending function for placing
  54. * text over a background is
  55. *
  56. * {
  57. * dst = alpha * src + (1 - alpha) * dst ,
  58. * }
  59. *
  60. * which is known as OVER. However, when calculating the output of the
  61. * OVER operator, the source colors should first be transformed to a
  62. * linear color space, then alpha blended in that space, and transformed
  63. * back to the output color space.
  64. *
  65. * When linear light blending is used, the default FIR5 filtering
  66. * weights (as given by FT_LCD_FILTER_DEFAULT) are no longer optimal, as
  67. * they have been designed for black on white rendering while lacking
  68. * gamma correction. To preserve color neutrality, weights for a FIR5
  69. * filter should be chosen according to two free parameters `a' and `c',
  70. * and the FIR weights should be
  71. *
  72. * {
  73. * [a - c, a + c, 2 * a, a + c, a - c] .
  74. * }
  75. *
  76. * This formula generates equal weights for all the color primaries
  77. * across the filter kernel, which makes it colorless. One suggested
  78. * set of weights is
  79. *
  80. * {
  81. * [0x10, 0x50, 0x60, 0x50, 0x10] ,
  82. * }
  83. *
  84. * where `a' has value 0x30 and `b' value 0x20. The weights in filter
  85. * may have a sum larger than 0x100, which increases coloration slightly
  86. * but also improves contrast.
  87. */
  88. /****************************************************************************
  89. *
  90. * @enum:
  91. * FT_LcdFilter
  92. *
  93. * @description:
  94. * A list of values to identify various types of LCD filters.
  95. *
  96. * @values:
  97. * FT_LCD_FILTER_NONE ::
  98. * Do not perform filtering. When used with subpixel rendering, this
  99. * results in sometimes severe color fringes.
  100. *
  101. * FT_LCD_FILTER_DEFAULT ::
  102. * The default filter reduces color fringes considerably, at the cost
  103. * of a slight blurriness in the output.
  104. *
  105. * FT_LCD_FILTER_LIGHT ::
  106. * The light filter is a variant that produces less blurriness at the
  107. * cost of slightly more color fringes than the default one. It might
  108. * be better, depending on taste, your monitor, or your personal vision.
  109. *
  110. * FT_LCD_FILTER_LEGACY ::
  111. * This filter corresponds to the original libXft color filter. It
  112. * provides high contrast output but can exhibit really bad color
  113. * fringes if glyphs are not extremely well hinted to the pixel grid.
  114. * In other words, it only works well if the TrueType bytecode
  115. * interpreter is enabled *and* high-quality hinted fonts are used.
  116. *
  117. * This filter is only provided for comparison purposes, and might be
  118. * disabled or stay unsupported in the future.
  119. *
  120. * @since:
  121. * 2.3.0
  122. */
  123. typedef enum FT_LcdFilter_
  124. {
  125. FT_LCD_FILTER_NONE = 0,
  126. FT_LCD_FILTER_DEFAULT = 1,
  127. FT_LCD_FILTER_LIGHT = 2,
  128. FT_LCD_FILTER_LEGACY = 16,
  129. FT_LCD_FILTER_MAX /* do not remove */
  130. } FT_LcdFilter;
  131. /**************************************************************************
  132. *
  133. * @func:
  134. * FT_Library_SetLcdFilter
  135. *
  136. * @description:
  137. * This function is used to apply color filtering to LCD decimated
  138. * bitmaps, like the ones used when calling @FT_Render_Glyph with
  139. * @FT_RENDER_MODE_LCD or @FT_RENDER_MODE_LCD_V.
  140. *
  141. * @input:
  142. * library ::
  143. * A handle to the target library instance.
  144. *
  145. * filter ::
  146. * The filter type.
  147. *
  148. * You can use @FT_LCD_FILTER_NONE here to disable this feature, or
  149. * @FT_LCD_FILTER_DEFAULT to use a default filter that should work
  150. * well on most LCD screens.
  151. *
  152. * @return:
  153. * FreeType error code. 0~means success.
  154. *
  155. * @note:
  156. * This feature is always disabled by default. Clients must make an
  157. * explicit call to this function with a `filter' value other than
  158. * @FT_LCD_FILTER_NONE in order to enable it.
  159. *
  160. * Due to *PATENTS* covering subpixel rendering, this function doesn't
  161. * do anything except returning `FT_Err_Unimplemented_Feature' if the
  162. * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not
  163. * defined in your build of the library, which should correspond to all
  164. * default builds of FreeType.
  165. *
  166. * The filter affects glyph bitmaps rendered through @FT_Render_Glyph,
  167. * @FT_Outline_Get_Bitmap, @FT_Load_Glyph, and @FT_Load_Char.
  168. *
  169. * It does _not_ affect the output of @FT_Outline_Render and
  170. * @FT_Outline_Get_Bitmap.
  171. *
  172. * If this feature is activated, the dimensions of LCD glyph bitmaps are
  173. * either larger or taller than the dimensions of the corresponding
  174. * outline with regards to the pixel grid. For example, for
  175. * @FT_RENDER_MODE_LCD, the filter adds up to 3~pixels to the left, and
  176. * up to 3~pixels to the right.
  177. *
  178. * The bitmap offset values are adjusted correctly, so clients shouldn't
  179. * need to modify their layout and glyph positioning code when enabling
  180. * the filter.
  181. *
  182. * @since:
  183. * 2.3.0
  184. */
  185. FT_EXPORT( FT_Error )
  186. FT_Library_SetLcdFilter( FT_Library library,
  187. FT_LcdFilter filter );
  188. /**************************************************************************
  189. *
  190. * @func:
  191. * FT_Library_SetLcdFilterWeights
  192. *
  193. * @description:
  194. * Use this function to override the filter weights selected by
  195. * @FT_Library_SetLcdFilter. By default, FreeType uses the quintuple
  196. * (0x00, 0x55, 0x56, 0x55, 0x00) for FT_LCD_FILTER_LIGHT, and (0x10,
  197. * 0x40, 0x70, 0x40, 0x10) for FT_LCD_FILTER_DEFAULT and
  198. * FT_LCD_FILTER_LEGACY.
  199. *
  200. * @input:
  201. * library ::
  202. * A handle to the target library instance.
  203. *
  204. * weights ::
  205. * A pointer to an array; the function copies the first five bytes and
  206. * uses them to specify the filter weights.
  207. *
  208. * @return:
  209. * FreeType error code. 0~means success.
  210. *
  211. * @note:
  212. * Due to *PATENTS* covering subpixel rendering, this function doesn't
  213. * do anything except returning `FT_Err_Unimplemented_Feature' if the
  214. * configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not
  215. * defined in your build of the library, which should correspond to all
  216. * default builds of FreeType.
  217. *
  218. * This function must be called after @FT_Library_SetLcdFilter to have
  219. * any effect.
  220. *
  221. * @since:
  222. * 2.4.0
  223. */
  224. FT_EXPORT( FT_Error )
  225. FT_Library_SetLcdFilterWeights( FT_Library library,
  226. unsigned char *weights );
  227. /* */
  228. FT_END_HEADER
  229. #endif /* __FT_LCD_FILTER_H__ */
  230. /* END */