1 /*
2  * Copyright 2010 Ole Loots <ole@monochrom.net>
3  *
4  * This file is part of NetSurf, http://www.netsurf-browser.org/
5  *
6  * NetSurf is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * NetSurf is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /**
20  * \file
21  * Atari bitmap handling implementation.
22  */
23 
24 #ifndef NS_ATARI_BITMAP_H
25 #define NS_ATARI_BITMAP_H
26 
27 #include <gem.h>
28 #include <Hermes/Hermes.h>
29 
30 #define NS_BMP_DEFAULT_BPP 4
31 
32 /* Flags for init_mfdb function: */
33 #define MFDB_FLAG_STAND	  0x01
34 #define MFDB_FLAG_ZEROMEM 0x02
35 #define MFDB_FLAG_NOALLOC 0x04
36 
37 #define BITMAP_SHRINK	  0
38 #define BITMAP_GROW	  1024 /* Don't realloc when bitmap size shrinks */
39 #define BITMAP_CLEAR	  2048 /* Zero bitmap memory                     */
40 
41 
42 /**
43  * Calculates MFDB compatible rowstride (in number of bits)
44  */
45 #define MFDB_STRIDE( w ) (((w & 15) != 0) ? (w | 15)+1 : w)
46 
47 
48 /**
49  * Calculate size of an mfdb,
50  *
51  * \param bpp Bits per pixel.
52  * \param stride Word aligned rowstride (width) as returned by MFDB_STRIDE,
53  * \param h Height in pixels.
54 */
55 #define MFDB_SIZE( bpp, stride, h ) ( ((stride >> 3) * h) * bpp )
56 
57 extern struct gui_bitmap_table *atari_bitmap_table;
58 
59 struct bitmap {
60 	int width;
61 	int height;
62 	uint8_t *pixdata;
63 	bool opaque;
64 	short bpp;				/* number of BYTES! per pixel */
65 	size_t rowstride;
66 	struct bitmap * resized;
67 	MFDB native;
68 	bool converted;
69 };
70 
71 
72 
73 /**
74  * setup an MFDB struct and allocate memory for it when it is needed.
75  *
76  * If bpp == 0, this function assumes that the MFDB shall point to the
77  *       screen and will not allocate any memory (mfdb.fd_addr == 0).
78  *
79  * \return 0 when the memory allocation fails (out of memory),
80  *         otherwise it returns the size of the mfdb.fd_addr as number
81  *         of bytes.
82  */
83 int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out );
84 
85 /**
86  * Create a bitmap.
87  *
88  * \param  w  width of image in pixels
89  * \param  h  width of image in pixels
90  * \param  state   a flag word indicating the initial state
91  * \return an opaque struct bitmap, or NULL on memory exhaustion
92  */
93 void *atari_bitmap_create(int w, int h, unsigned int state);
94 
95 /**
96  * Find the width of a pixel row in bytes.
97  *
98  * \param  bitmap  a bitmap, as returned by bitmap_create()
99  * \return width of a pixel row in the bitmap
100  */
101 size_t atari_bitmap_get_rowstride(void *bitmap);
102 
103 /**
104  * Free a bitmap.
105  *
106  * \param  bitmap a bitmap, as returned by bitmap_create()
107  */
108 void atari_bitmap_destroy(void *bitmap);
109 
110 /**
111  * Get bitmap width
112  *
113  * \param  bitmap a bitmap, as returned by bitmap_create()
114  */
115 int atari_bitmap_get_width(void *bitmap);
116 
117 /**
118  * Get bitmap height
119  *
120  * \param  bitmap a bitmap, as returned by bitmap_create()
121  */
122 int atari_bitmap_get_height(void *bitmap);
123 
124 /**
125  * Gets whether a bitmap should be plotted opaque
126  *
127  * \param  bitmap  a bitmap, as returned by bitmap_create()
128  */
129 bool atari_bitmap_get_opaque(void *bitmap);
130 
131 size_t atari_bitmap_buffer_size(void *bitmap);
132 
133 bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh);
134 
135 void *atari_bitmap_realloc( int w, int h, short bpp, int rowstride, unsigned int state, void * bmp );
136 
137 #endif
138