NetSurf
bitmap.h
Go to the documentation of this file.
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
58
59struct 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;
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 */
83int 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 */
93void *atari_bitmap_create(int w, int h, enum gui_bitmap_flags flags);
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 */
102
103/**
104 * Free a bitmap.
105 *
106 * \param bitmap a bitmap, as returned by bitmap_create()
107 */
108void atari_bitmap_destroy(void *bitmap);
109
110/**
111 * Get bitmap width
112 *
113 * \param bitmap a bitmap, as returned by bitmap_create()
114 */
116
117/**
118 * Get bitmap height
119 *
120 * \param bitmap a bitmap, as returned by bitmap_create()
121 */
123
124/**
125 * Gets whether a bitmap should be plotted opaque
126 *
127 * \param bitmap a bitmap, as returned by bitmap_create()
128 */
130
131size_t atari_bitmap_buffer_size(void *bitmap);
132
133bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh);
134
135void *atari_bitmap_realloc( int w, int h, short bpp, int rowstride, unsigned int state, void * bmp );
136
137#endif
bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh)
Definition: bitmap.c:313
size_t atari_bitmap_buffer_size(void *bitmap)
Definition: bitmap.c:208
size_t atari_bitmap_get_rowstride(void *bitmap)
Find the width of a pixel row in bytes.
Definition: bitmap.c:218
bool atari_bitmap_get_opaque(void *bitmap)
Gets whether a bitmap should be plotted opaque.
Definition: bitmap.c:273
void atari_bitmap_destroy(void *bitmap)
Free a bitmap.
Definition: bitmap.c:231
void * atari_bitmap_create(int w, int h, enum gui_bitmap_flags flags)
Create a bitmap.
Definition: bitmap.c:121
struct gui_bitmap_table * atari_bitmap_table
Definition: bitmap.c:391
int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB *out)
setup an MFDB struct and allocate memory for it when it is needed.
Definition: bitmap.c:41
int atari_bitmap_get_height(void *bitmap)
Get bitmap height.
Definition: bitmap.c:301
int atari_bitmap_get_width(void *bitmap)
Get bitmap width.
Definition: bitmap.c:287
void * atari_bitmap_realloc(int w, int h, short bpp, int rowstride, unsigned int state, void *bmp)
Definition: bitmap.c:149
gui_bitmap_flags
Bitmap creation flags.
Definition: bitmap.h:36
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
MFDB native
Definition: bitmap.h:67
int width
width of bitmap
Definition: bitmap.c:69
struct bitmap * resized
Definition: bitmap.h:66
int height
height of bitmap
Definition: bitmap.c:70
bool opaque
Whether the bitmap is opaque.
Definition: bitmap.c:74
short bpp
Definition: bitmap.h:64
size_t rowstride
Definition: bitmap.h:65
bool converted
Definition: bitmap.h:68
uint8_t * pixdata
Definition: bitmap.h:62
Bitmap operations.
Definition: bitmap.h:125