GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_bmp.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2020 Cyril Hrubis <metan@ucw.cz>
4 */
5
6/*
7
8 Internal BMP loader functions, you shouldn't need to touch these unless you
9 need to parse file formats that embedds a BMP images with incomplete header
10 such as ICO file format.
11
12 */
13
14#ifndef GP_BMP_H
15#define GP_BMP_H
16
17/*
18 * Sometimes called a DIB header as well.
19 */
20struct gp_bmp_info_header {
21 /* Offset to image data */
22 uint32_t pixel_offset;
23
24 /* Offset to the start of the info header */
25 uint32_t header_offset;
26
27 /* Header size (palette is on offset header_size + 14) */
28 uint32_t header_size;
29
30 /*
31 * Image size in pixels.
32 *
33 * If h is negative image is top-down (bottom-up is default)
34 */
35 int32_t w;
36 int32_t h;
37
38 uint16_t bpp;
39 uint32_t compress_type;
40 /*
41 * if 0 image uses whole range (2^bpp colors)
42 */
43 uint32_t palette_colors;
44 /*
45 * RGBA masks for bitfields compression
46 */
47 uint32_t R_mask;
48 uint32_t G_mask;
49 uint32_t B_mask;
50 uint32_t A_mask;
51};
52
53enum gp_bmp_compress {
54 COMPRESS_RGB = 0, /* uncompressed */
55 COMPRESS_RLE8 = 1, /* run-length encoded bitmap */
56 COMPRESS_RLE4 = 2, /* run-length encoded bitmap */
57 COMPRESS_BITFIELDS = 3, /* bitfield for each channel */
58 COMPRESS_JPEG = 4, /* only for printers */
59 COMPRESS_PNG = 5, /* only for printers */
60 COMPRESS_ALPHABITFIELDS = 6,
61 COMPRESS_MAX = COMPRESS_ALPHABITFIELDS,
62};
63
64enum gp_bmp_info_header_size {
65 BITMAPCOREHEADER = 12, /* old OS/2 format + win 3.0 */
66 BITMAPCOREHEADER2 = 64, /* OS/2 */
67 BITMAPINFOHEADER = 40, /* most common */
68 BITMAPINFOHEADER2 = 52, /* Undocummented */
69 BITMAPINFOHEADER3 = 56, /* Undocummented */
70 BITMAPINFOHEADER4 = 108, /* adds color space + gamma - win 95/NT4 */
71 BITMAPINFOHEADER5 = 124, /* adds ICC color profiles win 98+ */
72};
73
74/*
75 * @brief Attempts to parse BMP info header at current offset in the file IO.
76 *
77 * Note that pixel_offset is not set by this function since the offset to the
78 * pixels is stored in the bitmap file header. This offset must be filled in by
79 * the called before the header is passed to gp_bmp_read_pixels() function.
80 *
81 * @io An io stream with an BMP info header at current offset.
82 * @header BMP info header to be filled in.
83 *
84 * @return Returns 0 on success and errno on a failure.
85 */
86int gp_bmp_read_info_header(gp_io *io, struct gp_bmp_info_header *header);
87
88/*
89 * @brief Returns a pixel type suitable for a BMP info header.
90 *
91 * Returns a pixel type suitable for an pixmap that could be later passed to
92 * the gp_bmp_read_pixels().
93 *
94 * @header BMP info header.
95 *
96 * @return A pixel type.
97 */
98gp_pixel_type gp_bmp_pixel_type(struct gp_bmp_info_header *header);
99
100/*
101 * @brief Returns palette size in bytes.
102 *
103 * @header BMP info header structure.
104 *
105 * @return Palette size in bytes.
106 */
107uint32_t gp_bmp_palette_size(struct gp_bmp_info_header *header);
108
109/*
110 * @brief Reads a pixel data.
111 *
112 * @io An io stream.
113 * @header BMP info header.
114 * @pixmap Pre-allocated pixmap of correct size and pixel type.
115 * @callback A progress callback.
116 *
117 * @return Returns 0 on success and errno on a failure.
118 */
119int gp_bmp_read_pixels(gp_io *io, struct gp_bmp_info_header *header,
120 gp_pixmap *pixmap, gp_progress_cb *callback);
121
122#endif /* GP_BMP_H */
gp_pixel_type
List of all pixel types.
A pixmap buffer.
Definition gp_pixmap.h:33
Progress callback.