blob: d6c0e6c45234ba48b2752c2aa5d44ff09e9c0eaf [file] [log] [blame]
Simon Rothen0b5ad602014-08-30 13:15:53 +02001#ifndef _BMP_H_
2#define _BMP_H_
3
4
5/**************************************************************
6
7 QDBMP - Quick n' Dirty BMP
8
9 v1.0.0 - 2007-04-07
10 http://qdbmp.sourceforge.net
11
12
13 The library supports the following BMP variants:
14 1. Uncompressed 32 BPP (alpha values are ignored)
15 2. Uncompressed 24 BPP
16 3. Uncompressed 8 BPP (indexed color)
17
18 QDBMP is free and open source software, distributed
19 under the MIT licence.
20
21 Copyright (c) 2007 Chai Braudo (braudo@users.sourceforge.net)
22
23 Permission is hereby granted, free of charge, to any person obtaining a copy
24 of this software and associated documentation files (the "Software"), to deal
25 in the Software without restriction, including without limitation the rights
26 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 copies of the Software, and to permit persons to whom the Software is
28 furnished to do so, subject to the following conditions:
29
30 The above copyright notice and this permission notice shall be included in
31 all copies or substantial portions of the Software.
32
33 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 THE SOFTWARE.
40
41**************************************************************/
42
43#include <stdio.h>
44
45
46
47/* Type definitions */
48#ifndef UINT
49 #define UINT unsigned long int
50#endif
51
52#ifndef USHORT
53 #define USHORT unsigned short
54#endif
55
56#ifndef UCHAR
57 #define UCHAR unsigned char
58#endif
59
60
61/* Version */
62#define QDBMP_VERSION_MAJOR 1
63#define QDBMP_VERSION_MINOR 0
64#define QDBMP_VERSION_PATCH 1
65
66
67/* Error codes */
68typedef enum
69{
70 BMP_OK = 0, /* No error */
71 BMP_ERROR, /* General error */
72 BMP_OUT_OF_MEMORY, /* Could not allocate enough memory to complete the operation */
73 BMP_IO_ERROR, /* General input/output error */
74 BMP_FILE_NOT_FOUND, /* File not found */
75 BMP_FILE_NOT_SUPPORTED, /* File is not a supported BMP variant */
76 BMP_FILE_INVALID, /* File is not a BMP image or is an invalid BMP */
77 BMP_INVALID_ARGUMENT, /* An argument is invalid or out of range */
78 BMP_TYPE_MISMATCH, /* The requested action is not compatible with the BMP's type */
79 BMP_ERROR_NUM
80} BMP_STATUS;
81
82
83/* Bitmap image */
84typedef struct _BMP BMP;
85
86
87
88
89/*********************************** Public methods **********************************/
90
91
92/* Construction/destruction */
93BMP* BMP_Create ( UINT width, UINT height, USHORT depth );
94void BMP_Free ( BMP* bmp );
95
96
97/* I/O */
98BMP* BMP_ReadFile ( const char* filename );
99void BMP_WriteFile ( BMP* bmp, const char* filename );
100
101
102/* Meta info */
103UINT BMP_GetWidth ( BMP* bmp );
104UINT BMP_GetHeight ( BMP* bmp );
105USHORT BMP_GetDepth ( BMP* bmp );
106
107
108/* Pixel access */
109void BMP_GetPixelRGB ( BMP* bmp, UINT x, UINT y, UCHAR* r, UCHAR* g, UCHAR* b );
110void BMP_SetPixelRGB ( BMP* bmp, UINT x, UINT y, UCHAR r, UCHAR g, UCHAR b );
111void BMP_GetPixelIndex ( BMP* bmp, UINT x, UINT y, UCHAR* val );
112void BMP_SetPixelIndex ( BMP* bmp, UINT x, UINT y, UCHAR val );
113
114
115/* Palette handling */
116void BMP_GetPaletteColor ( BMP* bmp, UCHAR index, UCHAR* r, UCHAR* g, UCHAR* b );
117void BMP_SetPaletteColor ( BMP* bmp, UCHAR index, UCHAR r, UCHAR g, UCHAR b );
118
119
120/* Error handling */
121BMP_STATUS BMP_GetError ();
122const char* BMP_GetErrorDescription ();
123
124
125/* Useful macro that may be used after each BMP operation to check for an error */
126#define BMP_CHECK_ERROR( output_file, return_value ) \
127 if ( BMP_GetError() != BMP_OK ) \
128 { \
129 fprintf( ( output_file ), "BMP error: %s\n", BMP_GetErrorDescription() ); \
130 return( return_value ); \
131 } \
132
133#endif