Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bitmap.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000, Matias Atria
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 #ifndef _BITMAP_H
19 #define _BITMAP_H 1
20 
21 #include "sysdeps.h"
22 
23 /* Structures and functions to manipulate bitmaps */
24 
25 /* bitmap unit (as in X's docs) */
26 typedef Uint32 BmUnit;
27 
28 /* size (in bytes) of a bitmap atom */
29 #define BITMAP_BYTES 4
30 
31 /* size (in bits) of a bitmap atom */
32 #define BITMAP_BITS (BITMAP_BYTES << 3)
33 
34 typedef struct {
35  int width;
36  int height;
37  int stride;
39 } BITMAP;
40 
41 #define BM_BYTES_PER_LINE(b) \
42  (ROUND((b)->width, BITMAP_BITS) * BITMAP_BYTES)
43 #define BM_WIDTH(b) (((BITMAP *)(b))->width)
44 #define BM_HEIGHT(b) (((BITMAP *)(b))->height)
45 
46 #define BMBIT(n) ((BmUnit)1 << (n))
47 
48 /* Macros to manipulate individual pixels in a bitmap
49  * (they are slow, don't use them)
50  */
51 
52 #define bm_offset(b,o) (BmUnit *)((Uchar *)(b) + (o))
53 
54 #define __bm_unit_ptr(b,x,y) \
55  bm_offset((b)->data, (y) * (b)->stride + \
56  ((x) / BITMAP_BITS) * BITMAP_BYTES)
57 
58 #define __bm_unit(b,x,y) __bm_unit_ptr((b), (x), (y))[0]
59 
60 #define BM_GETPIXEL(b,x,y) __bm_unit((b), (x), (y))
61 #define BM_SETPIXEL(b,x,y) (__bm_unit((b), (x), (y)) |= FIRSTMASKAT(x))
62 #define BM_CLRPIXEL(b,x,y) (__bm_unit((b), (x), (y)) &= ~FIRSTMASKAT(x))
63 
64 /*
65  * These macros are used to access pixels in a bitmap. They are supposed
66  * to be used like this:
67  */
68 #if 0
69  BmUnit *row, mask;
70 
71  mask = FIRSTMASK;
72 
73  /* position `unit' at coordinates (column_number, row_number) */
74  unit = (BmUnit *)((char *)bitmap->data + row_number * bitmap->stride
75  + (column_number / BITMAP_BITS);
76  /* loop over all pixels IN THE SAME ROW */
77  for(i = 0; i < number_of_pixels; i++) {
78  /* to test if a pixel is set */
79  if(*unit & mask) {
80  /* yes, it is, do something with it */
81  }
82  /* to set/clear a pixel */
83  if(painting)
84  *unit |= mask; /* now you see it */
85  else
86  *unit &= ~mask; /* now you don't */
87  /* move to next pixel */
88  if(mask == LASTMASK) {
89  unit++;
90  UPDATEMASK(mask);
91  }
92  }
93 /* end of sample code */
94 #endif
95 
96 /* bitmaps are stored in native byte order */
97 #ifdef WORD_BIG_ENDIAN
98 #define FIRSTSHIFT (BITMAP_BITS - 1)
99 #define LASTSHIFT 0
100 #define NEXTMASK(m) ((m) >>= 1)
101 #define PREVMASK(m) ((m) <<= 1)
102 #define FIRSTSHIFTAT(c) (BITMAP_BITS - ((c) % BITMAP_BITS) - 1)
103 #else
104 #define FIRSTSHIFT 0
105 #define LASTSHIFT (BITMAP_BITS - 1)
106 #define NEXTMASK(m) ((m) <<= 1)
107 #define PREVMASK(m) ((m) >>= 1)
108 #define FIRSTSHIFTAT(c) ((c) % BITMAP_BITS)
109 #endif
110 
111 #define FIRSTMASK BMBIT(FIRSTSHIFT)
112 #define FIRSTMASKAT(c) BMBIT(FIRSTSHIFTAT(c))
113 #define LASTMASK BMBIT(LASTSHIFT)
114 
115 extern BITMAP *bitmap_alloc __PROTO((int, int));
116 extern BITMAP *bitmap_alloc_raw __PROTO((int, int));
117 extern void bitmap_destroy __PROTO((BITMAP *));
118 
119 /*
120  * set_row(bm, row, col, count, state):
121  * sets `count' pixels to state `onoff', starting from pixel
122  * at position (col, row). All pixels must lie in the same
123  * row.
124  */
125 extern void bitmap_set_col __PROTO((BITMAP *, int, int, int, int));
126 extern void bitmap_set_row __PROTO((BITMAP *, int, int, int, int));
127 
128 extern void bitmap_paint_bits __PROTO((BmUnit *, int, int));
129 extern void bitmap_clear_bits __PROTO((BmUnit *, int, int));
130 
131 extern BITMAP *bitmap_copy __PROTO((BITMAP *));
132 extern void bitmap_flip_horizontally __PROTO((BITMAP *));
133 extern void bitmap_flip_vertically __PROTO((BITMAP *));
134 extern void bitmap_flip_diagonally __PROTO((BITMAP *));
135 extern void bitmap_rotate_clockwise __PROTO((BITMAP *));
139 extern BITMAP *bitmap_convert_lsb8 __PROTO((Uchar *, int, int, int));
140 extern BITMAP *bitmap_convert_msb8 __PROTO((Uchar *, int, int, int));
141 
142 #include <stdio.h>
143 extern void bitmap_print __PROTO((FILE *, BITMAP *));
144 
145 #endif /* _BITMAP_H */