Mercurial > hg > forks > yadex
annotate src/rgbbmp.h @ 109:f05330267c66
Use stdint types.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Oct 2014 12:59:23 +0300 |
parents | a68786b9c74b |
children |
rev | line source |
---|---|
0 | 1 /* |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
2 * rgbbmp.h |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
3 * Rgbbmp - An RGB bitmap image class. |
0 | 4 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
5 * This is a simple bitmap where each pixel is an RGB |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
6 * triplet. Each component is coded as an 8-bit unsigned |
109 | 7 * integer (of type int8_t). |
0 | 8 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
9 * AYM 1999-06-06 |
0 | 10 */ |
11 | |
12 | |
13 /* | |
14 This file is part of Yadex. | |
15 | |
16 Yadex incorporates code from DEU 5.21 that was put in the public domain in | |
17 1994 by Raphaël Quinet and Brendon Wyber. | |
18 | |
19 The rest of Yadex is Copyright © 1997-2003 André Majorel and others. | |
20 | |
21 This program is free software; you can redistribute it and/or modify it under | |
22 the terms of the GNU General Public License as published by the Free Software | |
23 Foundation; either version 2 of the License, or (at your option) any later | |
24 version. | |
25 | |
26 This program is distributed in the hope that it will be useful, but WITHOUT | |
27 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
28 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
29 | |
30 You should have received a copy of the GNU General Public License along with | |
31 this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
32 Place, Suite 330, Boston, MA 02111-1307, USA. | |
33 */ | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
34 |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
35 |
0 | 36 #ifndef YH_RGBBMP |
37 #define YH_RGBBMP | |
38 | |
39 | |
40 typedef struct | |
41 { | |
109 | 42 uint8_t r; |
43 uint8_t g; | |
44 uint8_t b; | |
0 | 45 } Rgbbmp_pixel_t; |
46 | |
47 | |
48 class Rgbbmp | |
49 { | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 public:Rgbbmp() |
0 | 51 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
52 _width = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
53 _height = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
54 pixel = 0; |
0 | 55 } |
56 | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
57 void resize(int width, int height) // Must be defined before first use |
0 | 58 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
59 _width = width; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
60 _height = height; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
61 if (pixel) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
62 delete[]pixel; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
63 if (width * height > 0) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
64 pixel = new Rgbbmp_pixel_t[width * height]; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
65 else |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
66 pixel = 0; |
0 | 67 }; |
68 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 Rgbbmp(int width, int height) |
0 | 70 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
71 pixel = 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
72 resize(width, height); |
0 | 73 } |
74 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
75 ~Rgbbmp() |
0 | 76 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
77 if (pixel) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
78 delete[]pixel; |
0 | 79 } |
80 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
81 int width() const |
0 | 82 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
83 return _width; |
0 | 84 } |
85 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
86 int height() const |
0 | 87 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
88 return _height; |
0 | 89 } |
90 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
91 void clear() |
0 | 92 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
93 if (pixel) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
94 memset(pixel, 0, _width * _height * sizeof *pixel); |
0 | 95 } |
96 | |
109 | 97 void get(int x, int y, uint8_t & r, uint8_t & g, uint8_t & b) const |
0 | 98 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
99 r = pixel[y * _width + x].r; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
100 g = pixel[y * _width + x].g; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
101 b = pixel[y * _width + x].b; |
0 | 102 } |
103 | |
109 | 104 uint8_t get_r(int x, int y) const |
0 | 105 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
106 return pixel[y * _width + x].r; |
0 | 107 } |
108 | |
109 | 109 uint8_t get_g(int x, int y) const |
0 | 110 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
111 return pixel[y * _width + x].g; |
0 | 112 } |
113 | |
109 | 114 uint8_t get_b(int x, int y) const |
0 | 115 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
116 return pixel[y * _width + x].b; |
0 | 117 } |
118 | |
109 | 119 void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) |
0 | 120 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
121 pixel[y * _width + x].r = r; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
122 pixel[y * _width + x].g = g; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
123 pixel[y * _width + x].b = b; |
0 | 124 } |
125 | |
109 | 126 void set_r(int x, int y, uint8_t r) |
0 | 127 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
128 pixel[y * _width + x].r = r; |
0 | 129 } |
130 | |
109 | 131 void set_g(int x, int y, uint8_t g) |
0 | 132 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
133 pixel[y * _width + x].g = g; |
0 | 134 } |
135 | |
109 | 136 void set_b(int x, int y, uint8_t b) |
0 | 137 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
138 pixel[y * _width + x].b = b; |
0 | 139 } |
140 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
141 private: |
0 | 142 |
143 int _width; | |
144 int _height; | |
145 Rgbbmp_pixel_t *pixel; | |
146 }; | |
147 | |
148 | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
149 #endif /* DO NOT ADD ANYTHING AFTER THIS LINE */ |