bitmap.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // Copyright (C) 2004-2025 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifndef MUPDF_FITZ_BITMAP_H
  23. #define MUPDF_FITZ_BITMAP_H
  24. #include "mupdf/fitz/system.h"
  25. #include "mupdf/fitz/context.h"
  26. #include "mupdf/fitz/pixmap.h"
  27. /**
  28. Bitmaps have 1 bit per component. Only used for creating
  29. halftoned versions of contone buffers, and saving out. Samples
  30. are stored msb first, akin to pbms.
  31. The internals of this struct are considered implementation
  32. details and subject to change. Where possible, accessor
  33. functions should be used in preference.
  34. */
  35. typedef struct
  36. {
  37. int refs;
  38. int w, h, stride, n;
  39. int xres, yres;
  40. unsigned char *samples;
  41. } fz_bitmap;
  42. /**
  43. Take an additional reference to the bitmap. The same pointer
  44. is returned.
  45. Never throws exceptions.
  46. */
  47. fz_bitmap *fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit);
  48. /**
  49. Drop a reference to the bitmap. When the reference count reaches
  50. zero, the bitmap will be destroyed.
  51. Never throws exceptions.
  52. */
  53. void fz_drop_bitmap(fz_context *ctx, fz_bitmap *bit);
  54. /**
  55. Invert bitmap.
  56. Never throws exceptions.
  57. */
  58. void fz_invert_bitmap(fz_context *ctx, fz_bitmap *bmp);
  59. /**
  60. A halftone is a set of threshold tiles, one per component. Each
  61. threshold tile is a pixmap, possibly of varying sizes and
  62. phases. Currently, we only provide one 'default' halftone tile
  63. for operating on 1 component plus alpha pixmaps (where the alpha
  64. is ignored). This is signified by a fz_halftone pointer to NULL.
  65. */
  66. typedef struct fz_halftone fz_halftone;
  67. /**
  68. Make a bitmap from a pixmap and a halftone.
  69. pix: The pixmap to generate from. Currently must be a single
  70. color component with no alpha.
  71. ht: The halftone to use. NULL implies the default halftone.
  72. Returns the resultant bitmap. Throws exceptions in the case of
  73. failure to allocate.
  74. */
  75. fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht);
  76. /**
  77. Make a bitmap from a pixmap and a halftone.
  78. img: The image to generate from. Currently must be a single
  79. color component with no alpha.
  80. ht: The halftone to use. NULL implies the default halftone.
  81. Returns the resultant bitmap. Throws exceptions in the case of
  82. failure to allocate.
  83. */
  84. fz_bitmap *fz_new_bitmap_from_image(fz_context *ctx, fz_image *img, fz_halftone *ht);
  85. /**
  86. Make a bitmap from a pixmap and a
  87. halftone, allowing for the position of the pixmap within an
  88. overall banded rendering.
  89. pix: The pixmap to generate from. Currently must be a single
  90. color component with no alpha.
  91. ht: The halftone to use. NULL implies the default halftone.
  92. band_start: Vertical offset within the overall banded rendering
  93. (in pixels)
  94. Returns the resultant bitmap. Throws exceptions in the case of
  95. failure to allocate.
  96. */
  97. fz_bitmap *fz_new_bitmap_from_pixmap_band(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht, int band_start);
  98. /**
  99. Create a new bitmap.
  100. w, h: Width and Height for the bitmap
  101. n: Number of color components (assumed to be a divisor of 8)
  102. xres, yres: X and Y resolutions (in pixels per inch).
  103. Returns pointer to created bitmap structure. The bitmap
  104. data is uninitialised.
  105. */
  106. fz_bitmap *fz_new_bitmap(fz_context *ctx, int w, int h, int n, int xres, int yres);
  107. /**
  108. Retrieve details of a given bitmap.
  109. bitmap: The bitmap to query.
  110. w: Pointer to storage to retrieve width (or NULL).
  111. h: Pointer to storage to retrieve height (or NULL).
  112. n: Pointer to storage to retrieve number of color components (or
  113. NULL).
  114. stride: Pointer to storage to retrieve bitmap stride (or NULL).
  115. */
  116. void fz_bitmap_details(fz_bitmap *bitmap, int *w, int *h, int *n, int *stride);
  117. /**
  118. Set the entire bitmap to 0.
  119. Never throws exceptions.
  120. */
  121. void fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit);
  122. /**
  123. Create a 'default' halftone structure
  124. for the given number of components.
  125. num_comps: The number of components to use.
  126. Returns a simple default halftone. The default halftone uses
  127. the same halftone tile for each plane, which may not be ideal
  128. for all purposes.
  129. */
  130. fz_halftone *fz_default_halftone(fz_context *ctx, int num_comps);
  131. /**
  132. Take an additional reference to the halftone. The same pointer
  133. is returned.
  134. Never throws exceptions.
  135. */
  136. fz_halftone *fz_keep_halftone(fz_context *ctx, fz_halftone *half);
  137. /**
  138. Drop a reference to the halftone. When the reference count
  139. reaches zero, the halftone is destroyed.
  140. Never throws exceptions.
  141. */
  142. void fz_drop_halftone(fz_context *ctx, fz_halftone *ht);
  143. #endif