2 * This library is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published
4 * by the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 #include "bccmodels.h"
25 int BC_CModels::is_planar(int colormodel)
42 int BC_CModels::components(int colormodel)
82 // planar, compressed, transparent
86 int BC_CModels::calculate_pixelsize(int colormodel)
90 case BC_A16: return 2;
91 case BC_A_FLOAT: return 4;
92 case BC_TRANSPARENCY: return 1;
93 case BC_COMPRESSED: return 1;
94 case BC_RGB8: return 1;
95 case BC_RGB565: return 2;
96 case BC_BGR565: return 2;
97 case BC_BGR888: return 3;
98 case BC_BGR8888: return 4;
99 // Working bitmaps are packed to simplify processing
100 case BC_RGB888: return 3;
101 case BC_ARGB8888: return 4;
102 case BC_ABGR8888: return 4;
103 case BC_RGBA8888: return 4;
104 case BC_RGBX8888: return 4;
105 case BC_RGB161616: return 6;
106 case BC_RGBA16161616: return 8;
107 case BC_RGBX16161616: return 8;
108 case BC_YUV888: return 3;
109 case BC_YUVA8888: return 4;
110 case BC_YUVX8888: return 4;
111 case BC_YUV161616: return 6;
112 case BC_YUVA16161616: return 8;
113 case BC_YUVX16161616: return 8;
114 case BC_AYUV16161616: return 8;
115 case BC_YUV101010: return 4;
116 case BC_VYU888: return 3;
117 case BC_UYVA8888: return 4;
118 case BC_RGB_FLOAT: return 12;
119 case BC_RGBA_FLOAT: return 16;
120 case BC_RGBX_FLOAT: return 16;
121 case BC_GREY8: return 1;
122 case BC_GREY16: return 2;
124 case BC_YUV420P: return 1;
125 case BC_YUV420PI: return 1;
126 case BC_YUV422P: return 1;
127 case BC_YUV444P: return 1;
128 case BC_GBRP: return 1;
129 case BC_YUV422: return 2;
130 case BC_UVY422: return 2;
131 case BC_YUV411P: return 1;
132 case BC_YUV410P: return 1;
133 case BC_RGB_FLOATP: return 4;
134 case BC_RGBA_FLOATP: return 4;
139 int BC_CModels::calculate_max(int colormodel)
142 // Working bitmaps are packed to simplify processing
143 case BC_A8: return 0xff;
144 case BC_A16: return 0xffff;
145 case BC_A_FLOAT: return 1;
146 case BC_RGB888: return 0xff;
147 case BC_RGBA8888: return 0xff;
148 case BC_RGBX8888: return 0xff;
149 case BC_RGB161616: return 0xffff;
150 case BC_RGBA16161616: return 0xffff;
151 case BC_RGBX16161616: return 0xffff;
152 case BC_YUV888: return 0xff;
153 case BC_YUVA8888: return 0xff;
154 case BC_YUVX8888: return 0xff;
155 case BC_YUV161616: return 0xffff;
156 case BC_YUVA16161616: return 0xffff;
157 case BC_YUVX16161616: return 0xffff;
158 case BC_AYUV16161616: return 0xffff;
159 case BC_RGB_FLOAT: return 1;
160 case BC_RGBA_FLOAT: return 1;
161 case BC_RGBX_FLOAT: return 1;
162 case BC_RGB_FLOATP: return 1;
163 case BC_RGBA_FLOATP: return 1;
164 case BC_GREY8: return 0xff;
165 case BC_GREY16: return 0xffff;
166 case BC_GBRP: return 0xff;
171 int BC_CModels::calculate_datasize(int w, int h, int bytes_per_line, int color_model)
173 switch(color_model) {
174 case BC_YUV410P: return w * h + w * h / 8 + 4;
177 case BC_YUV411P: return w * h + w * h / 2 + 4;
178 case BC_YUV422P: return w * h * 2 + 4;
179 case BC_YUV444P: return w * h * 3 + 4;
180 case BC_GBRP: return w * h * 3 + 4;
181 case BC_RGB_FLOATP: return w * h * 3 * sizeof(float) + 4;
182 case BC_RGBA_FLOATP: return w * h * 4 * sizeof(float) + 4;
184 if( bytes_per_line < 0 )
185 bytes_per_line = w * calculate_pixelsize(color_model);
186 return h * bytes_per_line + BC_COLOR_ALIGN;
189 int BC_CModels::bc_to_x(int color_model)
191 switch(color_model) {
192 case BC_YUV420P: return FOURCC_YV12;
193 case BC_YUV422: return FOURCC_YUV2;
194 case BC_UVY422: return FOURCC_UYVY;
199 void BC_CModels::to_text(char *string, int cmodel)
202 case BC_RGB888: strcpy(string, "RGB-8 Bit"); break;
203 case BC_RGBA8888: strcpy(string, "RGBA-8 Bit"); break;
204 case BC_RGB161616: strcpy(string, "RGB-16 Bit"); break;
205 case BC_RGBA16161616: strcpy(string, "RGBA-16 Bit"); break;
206 case BC_YUV888: strcpy(string, "YUV-8 Bit"); break;
207 case BC_YUVA8888: strcpy(string, "YUVA-8 Bit"); break;
208 case BC_YUV161616: strcpy(string, "YUV-16 Bit"); break;
209 case BC_YUVA16161616: strcpy(string, "YUVA-16 Bit"); break;
210 case BC_AYUV16161616: strcpy(string, "AYUV-16 Bit"); break;
211 case BC_RGB_FLOAT: strcpy(string, "RGB-FLOAT"); break;
212 case BC_RGBA_FLOAT: strcpy(string, "RGBA-FLOAT"); break;
213 case BC_RGB_FLOATP: strcpy(string, "RGB-FLOATP"); break;
214 case BC_RGBA_FLOATP: strcpy(string, "RGBA-FLOATP"); break;
215 default: strcpy(string, "RGB-8 Bit"); break;
219 int BC_CModels::from_text(const char *text)
221 if(!strcasecmp(text, "RGB-8 Bit")) return BC_RGB888;
222 if(!strcasecmp(text, "RGBA-8 Bit")) return BC_RGBA8888;
223 if(!strcasecmp(text, "RGB-16 Bit")) return BC_RGB161616;
224 if(!strcasecmp(text, "RGBA-16 Bit")) return BC_RGBA16161616;
225 if(!strcasecmp(text, "RGB-FLOAT")) return BC_RGB_FLOAT;
226 if(!strcasecmp(text, "RGBA-FLOAT")) return BC_RGBA_FLOAT;
227 if(!strcasecmp(text, "RGB-FLOATP")) return BC_RGB_FLOATP;
228 if(!strcasecmp(text, "RGBA-FLOATP")) return BC_RGBA_FLOATP;
229 if(!strcasecmp(text, "YUV-8 Bit")) return BC_YUV888;
230 if(!strcasecmp(text, "YUVA-8 Bit")) return BC_YUVA8888;
231 if(!strcasecmp(text, "YUV-16 Bit")) return BC_YUV161616;
232 if(!strcasecmp(text, "YUVA-16 Bit")) return BC_YUVA16161616;
233 if(!strcasecmp(text, "AYUV-16 Bit")) return BC_AYUV16161616;
237 int BC_CModels::has_alpha(int colormodel)
244 case BC_RGBA16161616:
246 case BC_YUVA16161616:
255 int BC_CModels::is_float(int colormodel)
268 int BC_CModels::is_yuv(int colormodel)
276 case BC_YUVA16161616:
277 case BC_YUVX16161616:
278 case BC_AYUV16161616: