JasPer: bmp_cod.h Source File

JasPer 2.0.24 |

bmp_cod.h
1 /*
2 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
3 * British Columbia.
4 * Copyright (c) 2001-2002 Michael David Adams.
5 * All rights reserved.
6 */
7
8 /* __START_OF_JASPER_LICENSE__
9 *
10 * JasPer License Version 2.0
11 *
12 * Copyright (c) 2001-2006 Michael David Adams
13 * Copyright (c) 1999-2000 Image Power, Inc.
14 * Copyright (c) 1999-2000 The University of British Columbia
15 *
16 * All rights reserved.
17 *
18 * Permission is hereby granted, free of charge, to any person (the
19 * "User") obtaining a copy of this software and associated documentation
20 * files (the "Software"), to deal in the Software without restriction,
21 * including without limitation the rights to use, copy, modify, merge,
22 * publish, distribute, and/or sell copies of the Software, and to permit
23 * persons to whom the Software is furnished to do so, subject to the
24 * following conditions:
25 *
26 * 1. The above copyright notices and this permission notice (which
27 * includes the disclaimer below) shall be included in all copies or
28 * substantial portions of the Software.
29 *
30 * 2. The name of a copyright holder shall not be used to endorse or
31 * promote products derived from the Software without specific prior
32 * written permission.
33 *
34 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
35 * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
36 * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
37 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
40 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
41 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
42 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
45 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
46 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
47 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
48 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
49 * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
50 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
51 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
52 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
53 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
54 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
55 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
56 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
57 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
58 * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
59 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
60 *
61 * __END_OF_JASPER_LICENSE__
62 */
63
64 /*
65 * Windows Bitmap File Library
66 *
67 * $Id$
68 */
69
70 #ifndef BMP_COD_H
71 #define BMP_COD_H
72
73 /******************************************************************************\
74 * Includes.
75 \******************************************************************************/
76
77 #include "jasper/jas_types.h"
78
79 /******************************************************************************\
80 * Constants and macros.
81 \******************************************************************************/
82
83 #define BMP_MAGIC 0x4d42
84 /* The signature for a BMP file. */
85
86 #define BMP_HDRLEN 14
87 /* The nominal header length. */
88
89 #define BMP_INFOLEN 40
90 /* The nominal info length. */
91
92 #define BMP_PALLEN(info) ((info)->numcolors * 4)
93 /* The length of the palette. */
94
95 #define BMP_HASPAL(info) ((info)->numcolors > 0)
96 /* Is this a palettized image? */
97
98 /* Encoding types. */
99 #define BMP_ENC_RGB 0 /* No special encoding. */
100 #define BMP_ENC_RLE8 1 /* Run length encoding. */
101 #define BMP_ENC_RLE4 2 /* Run length encoding. */
102
103 /******************************************************************************\
104 * Types.
105 \******************************************************************************/
106
107 /* BMP header. */
108 typedef struct {
109
110 int_fast16_t magic;
111 /* The signature (a.k.a. the magic number). */
112
113 int_fast32_t siz;
114 /* The size of the file in 32-bit words. */
115
116 int_fast16_t reserved1;
117 /* Ask Bill Gates what this is all about. */
118
119 int_fast16_t reserved2;
120 /* Ditto. */
121
122 int_fast32_t off;
123 /* The offset of the bitmap data from the bitmap file header in bytes. */
124
125 } bmp_hdr_t;
126
127 /* Palette entry. */
128 typedef struct {
129
130 int_fast16_t red;
131 /* The red component. */
132
133 int_fast16_t grn;
134 /* The green component. */
135
136 int_fast16_t blu;
137 /* The blue component. */
138
139 int_fast16_t res;
140 /* Reserved. */
141
142 } bmp_palent_t;
143
144 /* BMP info. */
145 typedef struct {
146
147 int_fast32_t len;
148 /* The length of the bitmap information header in bytes. */
149
150 int_fast32_t width;
151 /* The width of the bitmap in pixels. */
152
153 int_fast32_t height;
154 /* The height of the bitmap in pixels. */
155
156 int_fast8_t topdown;
157 /* The bitmap data is specified in top-down order. */
158
159 int_fast16_t numplanes;
160 /* The number of planes. This must be set to a value of one. */
161
162 int_fast16_t depth;
163 /* The number of bits per pixel. */
164
165 int_fast32_t enctype;
166 /* The type of compression used. */
167
168 int_fast32_t siz;
169 /* The size of the image in bytes. */
170
171 int_fast32_t hres;
172 /* The horizontal resolution in pixels/metre. */
173
174 int_fast32_t vres;
175 /* The vertical resolution in pixels/metre. */
176
177 int_fast32_t numcolors;
178 /* The number of color indices used by the bitmap. */
179
180 int_fast32_t mincolors;
181 /* The number of color indices important for displaying the bitmap. */
182
183 bmp_palent_t *palents;
184 /* The colors should be listed in order of importance. */
185
186 } bmp_info_t;
187
188 /******************************************************************************\
189 * Functions and macros.
190 \******************************************************************************/
191
192 #define bmp_issupported(hdr, info) \
193 ((hdr)->magic == BMP_MAGIC && !(hdr)->reserved1 && \
194 !(hdr)->reserved2 && (info)->numplanes == 1 && \
195 ((info)->depth == 8 || (info)->depth == 24) && \
196 (info)->enctype == BMP_ENC_RGB)
197 /* Is this type of BMP file supported? */
198
199 #define bmp_haspal(info) \
200 ((info)->depth == 8)
201 /* Is there a palette? */
202
203 int bmp_numcmpts(bmp_info_t *info);
204 /* Get the number of components. */
205
206 bmp_info_t *bmp_info_create(void);
207 /* Create BMP information. */
208
209 void bmp_info_destroy(bmp_info_t *info);
210 /* Destroy BMP information. */
211
212 int bmp_isgrayscalepal(bmp_palent_t *palents, int numpalents);
213 /* Does the specified palette correspond to a grayscale image? */
214
215 #endif
jas_types.h
Primitive Types.