1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* Copyright 2006 Richard Wilson <info@tinct.net>
* Copyright 2008 Sean Fox <dyntryx@gmail.com>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* BMP file decoding (interface).
*/
#ifndef _NETSURF_IMAGE_BMPREAD_H_
#define _NETSURF_IMAGE_BMPREAD_H_
#include <stdbool.h>
/* bmp flags */
#define BMP_NEW 0
#define BMP_OPAQUE (1 << 0) /** image is opaque */
#define BMP_CLEAR_MEMORY (1 << 1) /** memory should be wiped */
/* error return values */
typedef enum {
BMP_OK = 0,
BMP_INSUFFICIENT_MEMORY = 1,
BMP_INSUFFICIENT_DATA = 2,
BMP_DATA_ERROR = 3
} bmp_result;
/* encoding types */
typedef enum {
BMP_ENCODING_RGB = 0,
BMP_ENCODING_RLE8 = 1,
BMP_ENCODING_RLE4 = 2,
BMP_ENCODING_BITFIELDS = 3
} bmp_encoding;
/* API for Bitmap callbacks
*/
typedef void* (*bitmap_cb_create)(int width, int height, unsigned int state);
typedef void (*bitmap_cb_destroy)(void *bitmap);
typedef void (*bitmap_cb_set_suspendable)(void *bitmap, void *private_word,
void (*invalidate)(void *bitmap, void *private_word));
typedef char* (*bitmap_cb_get_buffer)(void *bitmap);
typedef size_t (*bitmap_cb_get_rowstride)(void *bitmap);
/* The Bitmap callbacks function table
*/
typedef struct bmp_bitmap_callback_vt_s {
bitmap_cb_create bitmap_create; /**< Create a bitmap. */
bitmap_cb_destroy bitmap_destroy; /**< Free a bitmap. */
bitmap_cb_set_suspendable bitmap_set_suspendable; /**< The bitmap image can be suspended. */
bitmap_cb_get_buffer bitmap_get_buffer; /**< Return a pointer to the pixel data in a bitmap. */
bitmap_cb_get_rowstride bitmap_get_rowstride; /**< Find the width of a pixel row in bytes. */
} bmp_bitmap_callback_vt;
struct bmp_image {
unsigned char *bmp_data; /** pointer to BMP data */
unsigned int buffer_size; /** total number of bytes of BMP data available */
unsigned int width; /** width of BMP (valid after _analyse) */
unsigned int height; /** heigth of BMP (valid after _analyse) */
bmp_encoding encoding; /** pixel encoding type */
unsigned int bitmap_offset; /** offset of bitmap data */
unsigned int bpp; /** bits per pixel */
unsigned int colours; /** number of colours */
unsigned int *colour_table; /** colour table */
bool reversed; /** scanlines are top to bottom */
bool decoded; /** whether the image has been decoded */
bool ico; /** image is part of an ICO, mask follows */
unsigned int mask[4]; /** four bitwise mask */
int shift[4]; /** four bitwise shifts */
void *bitmap; /** decoded image */
};
struct ico_image {
struct bmp_image bmp;
struct ico_image *next;
};
struct ico_collection {
unsigned char *ico_data; /** pointer to ICO data */
unsigned int buffer_size; /** total number of bytes of ICO data available */
unsigned int width; /** width of largest BMP */
unsigned int height; /** heigth of largest BMP */
struct ico_image *first;
};
bmp_result bmp_analyse(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
bmp_result bmp_decode(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
void bmp_finalise(struct bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
bmp_result ico_analyse(struct ico_collection *ico, bmp_bitmap_callback_vt *bitmap_callbacks);
struct bmp_image *ico_find(struct ico_collection *ico, int width, int height);
void ico_finalise(struct ico_collection *ico, bmp_bitmap_callback_vt *bitmap_callbacks);
#endif
|