NetSurf
bitmap.h
Go to the documentation of this file.
1/*
2 * Copyright 2004 James Bursa <bursa@users.sourceforge.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 * Generic bitmap handling interface.
22 *
23 * This interface wraps the native platform-specific image format.
24 *
25 * Bitmaps are required to be 32bpp with 8-bit components. The components are
26 * red, green, blue, and alpha, in client specified order.
27 *
28 * The component order may be set in the front ends by calling
29 * \ref bitmap_set_format().
30 */
31
32#ifndef _NETSURF_BITMAP_H_
33#define _NETSURF_BITMAP_H_
34
35/** Bitmap creation flags. */
38 BITMAP_OPAQUE = (1 << 0), /**< image is opaque */
39 BITMAP_CLEAR = (1 << 1), /**< memory should be wiped to 0 */
40};
41
42/**
43 * NetSurf bitmap pixel layout.
44 *
45 * All pixels are 32 bits per pixel (bpp). The different layouts allow control
46 * over the ordering of colour channels. All colour channels are 8 bits wide.
47 */
49 /** Bite-wise RGBA: Byte order: 0xRR, 0xGG, 0xBB, 0xAA. */
51
52 /** Bite-wise BGRA: Byte order: 0xBB, 0xGG, 0xRR, 0xAA. */
54
55 /** Bite-wise ARGB: Byte order: 0xAA, 0xRR, 0xGG, 0xBB. */
57
58 /** Bite-wise ABGR: Byte order: 0xAA, 0xBB, 0xGG, 0xRR. */
60
61 /**
62 * 32-bit RGBA (0xRRGGBBAA).
63 *
64 * * On little endian host, same as \ref BITMAP_LAYOUT_A8B8G8R8.
65 * * On big endian host, same as \ref BITMAP_LAYOUT_R8G8B8A8.
66 */
68
69 /**
70 * 32-bit BGRA (0xBBGGRRAA).
71 *
72 * * On little endian host, same as \ref BITMAP_LAYOUT_A8R8G8B8.
73 * * On big endian host, same as \ref BITMAP_LAYOUT_B8G8R8A8.
74 */
76
77 /**
78 * 32-bit ARGB (0xAARRGGBB).
79 *
80 * * On little endian host, same as \ref BITMAP_LAYOUT_B8G8R8A8.
81 * * On big endian host, same as \ref BITMAP_LAYOUT_A8R8G8B8.
82 */
84
85 /**
86 * 32-bit BGRA (0xAABBGGRR).
87 *
88 * * On little endian host, same as \ref BITMAP_LAYOUT_R8G8B8A8.
89 * * On big endian host, same as \ref BITMAP_LAYOUT_A8B8G8R8.
90 */
92};
93
94/** Bitmap format specifier. */
95typedef struct bitmap_fmt {
96 enum bitmap_layout layout; /**< Colour component layout. */
97 bool pma; /**< Premultiplied alpha. */
99
100struct content;
101struct bitmap;
102struct hlcache_handle;
103
104/**
105 * Set client bitmap format.
106 *
107 * Set this to ensure that the bitmaps decoded by the core are in the
108 * correct format for the front end.
109 *
110 * \param[in] bitmap_format The bitmap format specification to set.
111 */
112void bitmap_set_format(const bitmap_fmt_t *bitmap_format);
113
114/**
115 * Test whether a bitmap is completely opaque (no transparency).
116 *
117 * \param[in] bitmap The bitmap to test.
118 * \return Returns true if the bitmap is opaque, false otherwise.
119 */
120bool bitmap_test_opaque(void *bitmap);
121
122/**
123 * Bitmap operations.
124 */
126 /* Mandatory entries */
127
128 /**
129 * Create a new bitmap.
130 *
131 * \param width width of image in pixels
132 * \param height height of image in pixels
133 * \param flags flags for bitmap creation
134 * \return A bitmap structure or NULL on error.
135 */
136 void *(*create)(int width, int height, enum gui_bitmap_flags flags);
137
138 /**
139 * Destroy a bitmap.
140 *
141 * \param bitmap The bitmap to destroy.
142 */
143 void (*destroy)(void *bitmap);
144
145 /**
146 * Set the opacity of a bitmap.
147 *
148 * \param bitmap The bitmap to set opacity on.
149 * \param opaque The bitmap opacity to set.
150 */
151 void (*set_opaque)(void *bitmap, bool opaque);
152
153 /**
154 * Get the opacity of a bitmap.
155 *
156 * \param bitmap The bitmap to examine.
157 * \return The bitmap opacity.
158 */
159 bool (*get_opaque)(void *bitmap);
160
161 /**
162 * Get the image buffer from a bitmap
163 *
164 * Note that all pixels must be 4-byte aligned.
165 *
166 * \param bitmap The bitmap to get the buffer from.
167 * \return The image buffer or NULL if there is none.
168 */
169 unsigned char *(*get_buffer)(void *bitmap);
170
171 /**
172 * Get the number of bytes per row of the image
173 *
174 * \param bitmap The bitmap
175 * \return The number of bytes for a row of the bitmap.
176 */
177 size_t (*get_rowstride)(void *bitmap);
178
179 /**
180 * Get the bitmap width
181 *
182 * \param bitmap The bitmap
183 * \return The bitmap width in pixels.
184 */
185 int (*get_width)(void *bitmap);
186
187 /**
188 * Get the bitmap height
189 *
190 * \param bitmap The bitmap
191 * \return The bitmap height in pixels.
192 */
193 int (*get_height)(void *bitmap);
194
195 /**
196 * Marks a bitmap as modified.
197 *
198 * \param bitmap The bitmap set as modified.
199 */
200 void (*modified)(void *bitmap);
201
202 /**
203 * Render content into a bitmap.
204 *
205 * \param bitmap The bitmap to render into.
206 * \param content The content to render.
207 */
209};
210
211#endif
nserror
Enumeration of error codes.
Definition: errors.h:29
bool bitmap_test_opaque(void *bitmap)
Test whether a bitmap is completely opaque (no transparency).
Definition: bitmap.c:316
void bitmap_set_format(const bitmap_fmt_t *bitmap_format)
Set client bitmap format.
Definition: bitmap.c:118
struct bitmap_fmt bitmap_fmt_t
Bitmap format specifier.
gui_bitmap_flags
Bitmap creation flags.
Definition: bitmap.h:36
@ BITMAP_CLEAR
memory should be wiped to 0
Definition: bitmap.h:39
@ BITMAP_OPAQUE
image is opaque
Definition: bitmap.h:38
@ BITMAP_NONE
Definition: bitmap.h:37
bitmap_layout
NetSurf bitmap pixel layout.
Definition: bitmap.h:48
@ BITMAP_LAYOUT_ABGR8888
32-bit BGRA (0xAABBGGRR).
Definition: bitmap.h:91
@ BITMAP_LAYOUT_BGRA8888
32-bit BGRA (0xBBGGRRAA).
Definition: bitmap.h:75
@ BITMAP_LAYOUT_ARGB8888
32-bit ARGB (0xAARRGGBB).
Definition: bitmap.h:83
@ BITMAP_LAYOUT_B8G8R8A8
Bite-wise BGRA: Byte order: 0xBB, 0xGG, 0xRR, 0xAA.
Definition: bitmap.h:53
@ BITMAP_LAYOUT_R8G8B8A8
Bite-wise RGBA: Byte order: 0xRR, 0xGG, 0xBB, 0xAA.
Definition: bitmap.h:50
@ BITMAP_LAYOUT_A8B8G8R8
Bite-wise ABGR: Byte order: 0xAA, 0xBB, 0xGG, 0xRR.
Definition: bitmap.h:59
@ BITMAP_LAYOUT_A8R8G8B8
Bite-wise ARGB: Byte order: 0xAA, 0xRR, 0xGG, 0xBB.
Definition: bitmap.h:56
@ BITMAP_LAYOUT_RGBA8888
32-bit RGBA (0xRRGGBBAA).
Definition: bitmap.h:67
int width
Definition: gui.c:160
int height
Definition: gui.c:161
Bitmap format specifier.
Definition: bitmap.h:95
bool pma
Premultiplied alpha.
Definition: bitmap.h:97
enum bitmap_layout layout
Colour component layout.
Definition: bitmap.h:96
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
Content which corresponds to a single URL.
Bitmap operations.
Definition: bitmap.h:125
void(* set_opaque)(void *bitmap, bool opaque)
Set the opacity of a bitmap.
Definition: bitmap.h:151
int(* get_height)(void *bitmap)
Get the bitmap height.
Definition: bitmap.h:193
void(* destroy)(void *bitmap)
Destroy a bitmap.
Definition: bitmap.h:143
nserror(* render)(struct bitmap *bitmap, struct hlcache_handle *content)
Render content into a bitmap.
Definition: bitmap.h:208
int(* get_width)(void *bitmap)
Get the bitmap width.
Definition: bitmap.h:185
size_t(* get_rowstride)(void *bitmap)
Get the number of bytes per row of the image.
Definition: bitmap.h:177
bool(* get_opaque)(void *bitmap)
Get the opacity of a bitmap.
Definition: bitmap.h:159
void(* modified)(void *bitmap)
Marks a bitmap as modified.
Definition: bitmap.h:200
High-level cache handle.
Definition: hlcache.c:66
static nserror bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.
Definition: plot.c:857