ftbitmap.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /****************************************************************************
  2. *
  3. * ftbitmap.h
  4. *
  5. * FreeType utility functions for bitmaps (specification).
  6. *
  7. * Copyright (C) 2004-2023 by
  8. * David Turner, Robert Wilhelm, and Werner Lemberg.
  9. *
  10. * This file is part of the FreeType project, and may only be used,
  11. * modified, and distributed under the terms of the FreeType project
  12. * license, LICENSE.TXT. By continuing to use, modify, or distribute
  13. * this file you indicate that you have read the license and
  14. * understand and accept it fully.
  15. *
  16. */
  17. #ifndef FTBITMAP_H_
  18. #define FTBITMAP_H_
  19. #include <freetype/freetype.h>
  20. #include <freetype/ftcolor.h>
  21. #ifdef FREETYPE_H
  22. #error "freetype.h of FreeType 1 has been loaded!"
  23. #error "Please fix the directory search order for header files"
  24. #error "so that freetype.h of FreeType 2 is found first."
  25. #endif
  26. FT_BEGIN_HEADER
  27. /**************************************************************************
  28. *
  29. * @section:
  30. * bitmap_handling
  31. *
  32. * @title:
  33. * Bitmap Handling
  34. *
  35. * @abstract:
  36. * Handling FT_Bitmap objects.
  37. *
  38. * @description:
  39. * This section contains functions for handling @FT_Bitmap objects,
  40. * automatically adjusting the target's bitmap buffer size as needed.
  41. *
  42. * Note that none of the functions changes the bitmap's 'flow' (as
  43. * indicated by the sign of the `pitch` field in @FT_Bitmap).
  44. *
  45. * To set the flow, assign an appropriate positive or negative value to
  46. * the `pitch` field of the target @FT_Bitmap object after calling
  47. * @FT_Bitmap_Init but before calling any of the other functions
  48. * described here.
  49. */
  50. /**************************************************************************
  51. *
  52. * @function:
  53. * FT_Bitmap_Init
  54. *
  55. * @description:
  56. * Initialize a pointer to an @FT_Bitmap structure.
  57. *
  58. * @inout:
  59. * abitmap ::
  60. * A pointer to the bitmap structure.
  61. *
  62. * @note:
  63. * A deprecated name for the same function is `FT_Bitmap_New`.
  64. */
  65. FT_EXPORT( void )
  66. FT_Bitmap_Init( FT_Bitmap *abitmap );
  67. /* deprecated */
  68. FT_EXPORT( void )
  69. FT_Bitmap_New( FT_Bitmap *abitmap );
  70. /**************************************************************************
  71. *
  72. * @function:
  73. * FT_Bitmap_Copy
  74. *
  75. * @description:
  76. * Copy a bitmap into another one.
  77. *
  78. * @input:
  79. * library ::
  80. * A handle to a library object.
  81. *
  82. * source ::
  83. * A handle to the source bitmap.
  84. *
  85. * @output:
  86. * target ::
  87. * A handle to the target bitmap.
  88. *
  89. * @return:
  90. * FreeType error code. 0~means success.
  91. *
  92. * @note:
  93. * `source->buffer` and `target->buffer` must neither be equal nor
  94. * overlap.
  95. */
  96. FT_EXPORT( FT_Error )
  97. FT_Bitmap_Copy( FT_Library library,
  98. const FT_Bitmap *source,
  99. FT_Bitmap *target );
  100. /**************************************************************************
  101. *
  102. * @function:
  103. * FT_Bitmap_Embolden
  104. *
  105. * @description:
  106. * Embolden a bitmap. The new bitmap will be about `xStrength` pixels
  107. * wider and `yStrength` pixels higher. The left and bottom borders are
  108. * kept unchanged.
  109. *
  110. * @input:
  111. * library ::
  112. * A handle to a library object.
  113. *
  114. * xStrength ::
  115. * How strong the glyph is emboldened horizontally. Expressed in 26.6
  116. * pixel format.
  117. *
  118. * yStrength ::
  119. * How strong the glyph is emboldened vertically. Expressed in 26.6
  120. * pixel format.
  121. *
  122. * @inout:
  123. * bitmap ::
  124. * A handle to the target bitmap.
  125. *
  126. * @return:
  127. * FreeType error code. 0~means success.
  128. *
  129. * @note:
  130. * The current implementation restricts `xStrength` to be less than or
  131. * equal to~8 if bitmap is of pixel_mode @FT_PIXEL_MODE_MONO.
  132. *
  133. * If you want to embolden the bitmap owned by a @FT_GlyphSlotRec, you
  134. * should call @FT_GlyphSlot_Own_Bitmap on the slot first.
  135. *
  136. * Bitmaps in @FT_PIXEL_MODE_GRAY2 and @FT_PIXEL_MODE_GRAY@ format are
  137. * converted to @FT_PIXEL_MODE_GRAY format (i.e., 8bpp).
  138. */
  139. FT_EXPORT( FT_Error )
  140. FT_Bitmap_Embolden( FT_Library library,
  141. FT_Bitmap* bitmap,
  142. FT_Pos xStrength,
  143. FT_Pos yStrength );
  144. /**************************************************************************
  145. *
  146. * @function:
  147. * FT_Bitmap_Convert
  148. *
  149. * @description:
  150. * Convert a bitmap object with depth 1bpp, 2bpp, 4bpp, 8bpp or 32bpp to
  151. * a bitmap object with depth 8bpp, making the number of used bytes per
  152. * line (a.k.a. the 'pitch') a multiple of `alignment`.
  153. *
  154. * @input:
  155. * library ::
  156. * A handle to a library object.
  157. *
  158. * source ::
  159. * The source bitmap.
  160. *
  161. * alignment ::
  162. * The pitch of the bitmap is a multiple of this argument. Common
  163. * values are 1, 2, or 4.
  164. *
  165. * @output:
  166. * target ::
  167. * The target bitmap.
  168. *
  169. * @return:
  170. * FreeType error code. 0~means success.
  171. *
  172. * @note:
  173. * It is possible to call @FT_Bitmap_Convert multiple times without
  174. * calling @FT_Bitmap_Done (the memory is simply reallocated).
  175. *
  176. * Use @FT_Bitmap_Done to finally remove the bitmap object.
  177. *
  178. * The `library` argument is taken to have access to FreeType's memory
  179. * handling functions.
  180. *
  181. * `source->buffer` and `target->buffer` must neither be equal nor
  182. * overlap.
  183. */
  184. FT_EXPORT( FT_Error )
  185. FT_Bitmap_Convert( FT_Library library,
  186. const FT_Bitmap *source,
  187. FT_Bitmap *target,
  188. FT_Int alignment );
  189. /**************************************************************************
  190. *
  191. * @function:
  192. * FT_Bitmap_Blend
  193. *
  194. * @description:
  195. * Blend a bitmap onto another bitmap, using a given color.
  196. *
  197. * @input:
  198. * library ::
  199. * A handle to a library object.
  200. *
  201. * source ::
  202. * The source bitmap, which can have any @FT_Pixel_Mode format.
  203. *
  204. * source_offset ::
  205. * The offset vector to the upper left corner of the source bitmap in
  206. * 26.6 pixel format. It should represent an integer offset; the
  207. * function will set the lowest six bits to zero to enforce that.
  208. *
  209. * color ::
  210. * The color used to draw `source` onto `target`.
  211. *
  212. * @inout:
  213. * target ::
  214. * A handle to an `FT_Bitmap` object. It should be either initialized
  215. * as empty with a call to @FT_Bitmap_Init, or it should be of type
  216. * @FT_PIXEL_MODE_BGRA.
  217. *
  218. * atarget_offset ::
  219. * The offset vector to the upper left corner of the target bitmap in
  220. * 26.6 pixel format. It should represent an integer offset; the
  221. * function will set the lowest six bits to zero to enforce that.
  222. *
  223. * @return:
  224. * FreeType error code. 0~means success.
  225. *
  226. * @note:
  227. * This function doesn't perform clipping.
  228. *
  229. * The bitmap in `target` gets allocated or reallocated as needed; the
  230. * vector `atarget_offset` is updated accordingly.
  231. *
  232. * In case of allocation or reallocation, the bitmap's pitch is set to
  233. * `4 * width`. Both `source` and `target` must have the same bitmap
  234. * flow (as indicated by the sign of the `pitch` field).
  235. *
  236. * `source->buffer` and `target->buffer` must neither be equal nor
  237. * overlap.
  238. *
  239. * @since:
  240. * 2.10
  241. */
  242. FT_EXPORT( FT_Error )
  243. FT_Bitmap_Blend( FT_Library library,
  244. const FT_Bitmap* source,
  245. const FT_Vector source_offset,
  246. FT_Bitmap* target,
  247. FT_Vector *atarget_offset,
  248. FT_Color color );
  249. /**************************************************************************
  250. *
  251. * @function:
  252. * FT_GlyphSlot_Own_Bitmap
  253. *
  254. * @description:
  255. * Make sure that a glyph slot owns `slot->bitmap`.
  256. *
  257. * @input:
  258. * slot ::
  259. * The glyph slot.
  260. *
  261. * @return:
  262. * FreeType error code. 0~means success.
  263. *
  264. * @note:
  265. * This function is to be used in combination with @FT_Bitmap_Embolden.
  266. */
  267. FT_EXPORT( FT_Error )
  268. FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot );
  269. /**************************************************************************
  270. *
  271. * @function:
  272. * FT_Bitmap_Done
  273. *
  274. * @description:
  275. * Destroy a bitmap object initialized with @FT_Bitmap_Init.
  276. *
  277. * @input:
  278. * library ::
  279. * A handle to a library object.
  280. *
  281. * bitmap ::
  282. * The bitmap object to be freed.
  283. *
  284. * @return:
  285. * FreeType error code. 0~means success.
  286. *
  287. * @note:
  288. * The `library` argument is taken to have access to FreeType's memory
  289. * handling functions.
  290. */
  291. FT_EXPORT( FT_Error )
  292. FT_Bitmap_Done( FT_Library library,
  293. FT_Bitmap *bitmap );
  294. /* */
  295. FT_END_HEADER
  296. #endif /* FTBITMAP_H_ */
  297. /* END */