1 #ifndef MUPDF_FITZ_BITMAP_H
2 #define MUPDF_FITZ_BITMAP_H
3 
4 #include "mupdf/fitz/system.h"
5 #include "mupdf/fitz/context.h"
6 #include "mupdf/fitz/pixmap.h"
7 
8 /**
9 	Bitmaps have 1 bit per component. Only used for creating
10 	halftoned versions of contone buffers, and saving out. Samples
11 	are stored msb first, akin to pbms.
12 
13 	The internals of this struct are considered implementation
14 	details and subject to change. Where possible, accessor
15 	functions should be used in preference.
16 */
17 typedef struct
18 {
19 	int refs;
20 	int w, h, stride, n;
21 	int xres, yres;
22 	unsigned char *samples;
23 } fz_bitmap;
24 
25 /**
26 	Take an additional reference to the bitmap. The same pointer
27 	is returned.
28 
29 	Never throws exceptions.
30 */
31 fz_bitmap *fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit);
32 
33 /**
34 	Drop a reference to the bitmap. When the reference count reaches
35 	zero, the bitmap will be destroyed.
36 
37 	Never throws exceptions.
38 */
39 void fz_drop_bitmap(fz_context *ctx, fz_bitmap *bit);
40 
41 /**
42 	A halftone is a set of threshold tiles, one per component. Each
43 	threshold tile is a pixmap, possibly of varying sizes and
44 	phases. Currently, we only provide one 'default' halftone tile
45 	for operating on 1 component plus alpha pixmaps (where the alpha
46 	is ignored). This is signified by a fz_halftone pointer to NULL.
47 */
48 typedef struct fz_halftone fz_halftone;
49 
50 /**
51 	Make a bitmap from a pixmap and a halftone.
52 
53 	pix: The pixmap to generate from. Currently must be a single
54 	color component with no alpha.
55 
56 	ht: The halftone to use. NULL implies the default halftone.
57 
58 	Returns the resultant bitmap. Throws exceptions in the case of
59 	failure to allocate.
60 */
61 fz_bitmap *fz_new_bitmap_from_pixmap(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht);
62 
63 /**
64 	Make a bitmap from a pixmap and a
65 	halftone, allowing for the position of the pixmap within an
66 	overall banded rendering.
67 
68 	pix: The pixmap to generate from. Currently must be a single
69 	color component with no alpha.
70 
71 	ht: The halftone to use. NULL implies the default halftone.
72 
73 	band_start: Vertical offset within the overall banded rendering
74 	(in pixels)
75 
76 	Returns the resultant bitmap. Throws exceptions in the case of
77 	failure to allocate.
78 */
79 fz_bitmap *fz_new_bitmap_from_pixmap_band(fz_context *ctx, fz_pixmap *pix, fz_halftone *ht, int band_start);
80 
81 /**
82 	Create a new bitmap.
83 
84 	w, h: Width and Height for the bitmap
85 
86 	n: Number of color components (assumed to be a divisor of 8)
87 
88 	xres, yres: X and Y resolutions (in pixels per inch).
89 
90 	Returns pointer to created bitmap structure. The bitmap
91 	data is uninitialised.
92 */
93 fz_bitmap *fz_new_bitmap(fz_context *ctx, int w, int h, int n, int xres, int yres);
94 
95 /**
96 	Retrieve details of a given bitmap.
97 
98 	bitmap: The bitmap to query.
99 
100 	w: Pointer to storage to retrieve width (or NULL).
101 
102 	h: Pointer to storage to retrieve height (or NULL).
103 
104 	n: Pointer to storage to retrieve number of color components (or
105 	NULL).
106 
107 	stride: Pointer to storage to retrieve bitmap stride (or NULL).
108 */
109 void fz_bitmap_details(fz_bitmap *bitmap, int *w, int *h, int *n, int *stride);
110 
111 /**
112 	Set the entire bitmap to 0.
113 
114 	Never throws exceptions.
115 */
116 void fz_clear_bitmap(fz_context *ctx, fz_bitmap *bit);
117 
118 /**
119 	Create a 'default' halftone structure
120 	for the given number of components.
121 
122 	num_comps: The number of components to use.
123 
124 	Returns a simple default halftone. The default halftone uses
125 	the same halftone tile for each plane, which may not be ideal
126 	for all purposes.
127 */
128 fz_halftone *fz_default_halftone(fz_context *ctx, int num_comps);
129 
130 /**
131 	Take an additional reference to the halftone. The same pointer
132 	is returned.
133 
134 	Never throws exceptions.
135 */
136 fz_halftone *fz_keep_halftone(fz_context *ctx, fz_halftone *half);
137 
138 /**
139 	Drop a reference to the halftone. When the reference count
140 	reaches zero, the halftone is destroyed.
141 
142 	Never throws exceptions.
143 */
144 void fz_drop_halftone(fz_context *ctx, fz_halftone *ht);
145 
146 #endif
147