| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2026, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | #include "gate/graphics/colors.h" | ||
| 29 | #include "gate/strings.h" | ||
| 30 | #include "gate/mathematics.h" | ||
| 31 | |||
| 32 | 2 | void gate_color_set_opaque(gate_color_t* dest, gate_color_t const* src) | |
| 33 | { | ||
| 34 | 2 | dest->bits = src->bits; | |
| 35 | 2 | dest->a = 255; | |
| 36 | 2 | } | |
| 37 | 4401 | void gate_color_set_transparent(gate_color_t* dest, gate_color_t const* src) | |
| 38 | { | ||
| 39 | 4401 | dest->r = (gate_uint8_t)((((int)dest->r * (int)(255 - src->a) + (int)src->r * (int)src->a)) / (255 * 2)); | |
| 40 | 4401 | dest->g = (gate_uint8_t)((((int)dest->r * (int)(255 - src->a) + (int)src->r * (int)src->a)) / (255 * 2)); | |
| 41 | 4401 | dest->b = (gate_uint8_t)((((int)dest->r * (int)(255 - src->a) + (int)src->r * (int)src->a)) / (255 * 2)); | |
| 42 | 4401 | dest->a = (gate_uint8_t)(((int)dest->a + (int)src->a) / 2); | |
| 43 | 4401 | } | |
| 44 | |||
| 45 | 214 | gate_size_t gate_color_parse_hex(gate_char8_t const* text, gate_size_t textlen, gate_color_t* col) | |
| 46 | { | ||
| 47 | 214 | gate_size_t ret = 0; | |
| 48 | gate_uint8_t nibbles[8]; | ||
| 49 | gate_size_t cnt; | ||
| 50 | do | ||
| 51 | { | ||
| 52 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 214 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 214 times.
|
214 | if ((textlen == 0) || (text == NULL)) |
| 53 | { | ||
| 54 | break; | ||
| 55 | } | ||
| 56 | |||
| 57 |
2/2✓ Branch 0 taken 213 times.
✓ Branch 1 taken 1 times.
|
214 | if (text[0] == '#') |
| 58 | { | ||
| 59 | /* ignore hashtag */ | ||
| 60 | 213 | ++ret; | |
| 61 | 213 | ++text; | |
| 62 | 213 | --textlen; | |
| 63 | } | ||
| 64 | |||
| 65 |
4/4✓ Branch 0 taken 1494 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1281 times.
✓ Branch 3 taken 213 times.
|
1495 | for (cnt = 0; (cnt < 8) && (textlen != 0); ++cnt) |
| 66 | { | ||
| 67 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1281 times.
|
1281 | if (!gate_str_parse_hex_nibble(*text, &nibbles[cnt])) |
| 68 | { | ||
| 69 | ✗ | break; | |
| 70 | } | ||
| 71 | 1281 | ++ret; | |
| 72 | 1281 | ++text; | |
| 73 | 1281 | --textlen; | |
| 74 | } | ||
| 75 |
4/5✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 211 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
214 | switch (cnt) |
| 76 | { | ||
| 77 | 1 | case 3: | |
| 78 | { | ||
| 79 | 1 | col->r = nibbles[0] * 17; | |
| 80 | 1 | col->g = nibbles[1] * 17; | |
| 81 | 1 | col->b = nibbles[2] * 17; | |
| 82 | 1 | col->a = 255; | |
| 83 | 1 | break; | |
| 84 | } | ||
| 85 | 1 | case 4: | |
| 86 | { | ||
| 87 | 1 | col->r = nibbles[0] * 17; | |
| 88 | 1 | col->g = nibbles[1] * 17; | |
| 89 | 1 | col->b = nibbles[2] * 17; | |
| 90 | 1 | col->a = nibbles[3] * 17; | |
| 91 | 1 | break; | |
| 92 | } | ||
| 93 | 211 | case 6: | |
| 94 | { | ||
| 95 | 211 | col->r = nibbles[0] * 16 + nibbles[1]; | |
| 96 | 211 | col->g = nibbles[2] * 16 + nibbles[3]; | |
| 97 | 211 | col->b = nibbles[4] * 16 + nibbles[5]; | |
| 98 | 211 | col->a = 255; | |
| 99 | 211 | break; | |
| 100 | } | ||
| 101 | 1 | case 8: | |
| 102 | { | ||
| 103 | 1 | col->r = nibbles[0] * 16 + nibbles[1]; | |
| 104 | 1 | col->g = nibbles[2] * 16 + nibbles[3]; | |
| 105 | 1 | col->b = nibbles[4] * 16 + nibbles[5]; | |
| 106 | 1 | col->a = nibbles[6] * 16 + nibbles[7]; | |
| 107 | 1 | break; | |
| 108 | } | ||
| 109 | ✗ | default: | |
| 110 | { | ||
| 111 | ✗ | ret = 0; | |
| 112 | ✗ | break; | |
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | ✗ | } while (0); | |
| 117 | 214 | return ret; | |
| 118 | } | ||
| 119 | |||
| 120 | 4 | gate_size_t gate_color_palette_rgb4_create(gate_color_rgb_t palette[16]) | |
| 121 | { | ||
| 122 | 4 | gate_color_rgb_t* ptr = &palette[0]; | |
| 123 | |||
| 124 | /* VGA colors */ | ||
| 125 | 4 | ptr->r = 0x00; ptr->g = 0x00; ptr->b = 0x00; ++ptr; /* 00 black */ | |
| 126 | 4 | ptr->r = 0x00; ptr->g = 0x00; ptr->b = 0xaa; ++ptr; /* 01 blue */ | |
| 127 | 4 | ptr->r = 0x00; ptr->g = 0xaa; ptr->b = 0x00; ++ptr; /* 02 green */ | |
| 128 | 4 | ptr->r = 0x00; ptr->g = 0xaa; ptr->b = 0xaa; ++ptr; /* 03 cyan */ | |
| 129 | 4 | ptr->r = 0xaa; ptr->g = 0x00; ptr->b = 0x00; ++ptr; /* 04 red */ | |
| 130 | 4 | ptr->r = 0xaa; ptr->g = 0x00; ptr->b = 0xaa; ++ptr; /* 05 magenta*/ | |
| 131 | 4 | ptr->r = 0xaa; ptr->g = 0xaa; ptr->b = 0x00; ++ptr; /* 06 brown */ | |
| 132 | 4 | ptr->r = 0xaa; ptr->g = 0xaa; ptr->b = 0xaa; ++ptr; /* 07 light gray */ | |
| 133 | 4 | ptr->r = 0x55; ptr->g = 0x55; ptr->b = 0x55; ++ptr; /* 08 gray */ | |
| 134 | 4 | ptr->r = 0x55; ptr->g = 0x55; ptr->b = 0xff; ++ptr; /* 09 light blue */ | |
| 135 | 4 | ptr->r = 0x55; ptr->g = 0xff; ptr->b = 0x55; ++ptr; /* 10 light green */ | |
| 136 | 4 | ptr->r = 0x55; ptr->g = 0xff; ptr->b = 0xff; ++ptr; /* 11 light cyan */ | |
| 137 | 4 | ptr->r = 0xff; ptr->g = 0x55; ptr->b = 0x55; ++ptr; /* 12 light red */ | |
| 138 | 4 | ptr->r = 0xff; ptr->g = 0x55; ptr->b = 0xff; ++ptr; /* 13 light magenta */ | |
| 139 | 4 | ptr->r = 0xff; ptr->g = 0xff; ptr->b = 0x55; ++ptr; /* 14 yellow */ | |
| 140 | 4 | ptr->r = 0xff; ptr->g = 0xff; ptr->b = 0xff; /* ++ptr; */ /* 15 white */ | |
| 141 | 4 | return 16; | |
| 142 | } | ||
| 143 | |||
| 144 | static gate_uint8_t const bi_colors[] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff }; | ||
| 145 | |||
| 146 | static gate_color_rgb_t vga[16]; | ||
| 147 | static volatile gate_bool_t vga_palette_initialized = false; | ||
| 148 | |||
| 149 | |||
| 150 | 89349 | gate_uint8_t gate_color_palette_rgb8_index_from_color(gate_color_rgb_t col) | |
| 151 | { | ||
| 152 | unsigned ndx; | ||
| 153 | unsigned r, g, b; | ||
| 154 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 89347 times.
|
89349 | if (!vga_palette_initialized) |
| 155 | { | ||
| 156 | 2 | gate_color_palette_rgb4_create(vga); | |
| 157 | 2 | vga_palette_initialized = true; | |
| 158 | } | ||
| 159 | /* check vga color */ | ||
| 160 |
2/2✓ Branch 0 taken 1371834 times.
✓ Branch 1 taken 85283 times.
|
1457117 | for (ndx = 0; ndx < 16; ++ndx) |
| 161 | { | ||
| 162 |
6/6✓ Branch 0 taken 308802 times.
✓ Branch 1 taken 1063032 times.
✓ Branch 2 taken 146782 times.
✓ Branch 3 taken 162020 times.
✓ Branch 4 taken 4066 times.
✓ Branch 5 taken 142716 times.
|
1371834 | if ((vga[ndx].r == col.r) && (vga[ndx].g == col.g) && (vga[ndx].b == col.b)) |
| 163 | { | ||
| 164 | 4066 | return (gate_uint8_t)ndx; | |
| 165 | } | ||
| 166 | } | ||
| 167 | /* 6*6*6 */ | ||
| 168 | 85283 | r = ((unsigned)col.r + (unsigned)25) / (unsigned)51; | |
| 169 | 85283 | g = ((unsigned)col.g + (unsigned)25) / (unsigned)51; | |
| 170 | 85283 | b = ((unsigned)col.b + (unsigned)25) / (unsigned)51; | |
| 171 | 85283 | return (gate_uint8_t)(16 + r * 36 + g * 6 + b); | |
| 172 | } | ||
| 173 | |||
| 174 | |||
| 175 | 25091 | void gate_color_palette_rgb8_from_index(gate_uint8_t ndx, gate_color_rgb_t* col) | |
| 176 | { | ||
| 177 | unsigned pal_ndx; | ||
| 178 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 25072 times.
|
25091 | if (ndx <= 15) |
| 179 | { | ||
| 180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (!vga_palette_initialized) |
| 181 | { | ||
| 182 | ✗ | gate_color_palette_rgb4_create(vga); | |
| 183 | ✗ | vga_palette_initialized = true; | |
| 184 | } | ||
| 185 | 19 | *col = vga[ndx]; | |
| 186 | 19 | return; | |
| 187 | } | ||
| 188 | 25072 | pal_ndx = ndx - 16; | |
| 189 |
2/2✓ Branch 0 taken 25049 times.
✓ Branch 1 taken 23 times.
|
25072 | if (pal_ndx < 216) |
| 190 | { | ||
| 191 | 25049 | const gate_uint8_t r = (gate_uint8_t)(pal_ndx / 36); | |
| 192 | 25049 | const gate_uint8_t g = (gate_uint8_t)((pal_ndx % 36) / 6); | |
| 193 | 25049 | const gate_uint8_t b = (gate_uint8_t)(pal_ndx % 6); | |
| 194 | 25049 | col->r = bi_colors[r]; | |
| 195 | 25049 | col->g = bi_colors[g]; | |
| 196 | 25049 | col->b = bi_colors[b]; | |
| 197 | 25049 | return; | |
| 198 | } | ||
| 199 | 23 | pal_ndx -= 216; | |
| 200 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 7 times.
|
23 | if (pal_ndx < 16) |
| 201 | { | ||
| 202 | 16 | col->b = col->g = col->r = (gate_uint8_t)(pal_ndx * 0x11); | |
| 203 | 16 | return; | |
| 204 | } | ||
| 205 | 7 | col->r = 255; | |
| 206 | 7 | col->g = 255; | |
| 207 | 7 | col->b = 255; | |
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | 1 | gate_size_t gate_color_palette_rgb8_create(gate_color_rgb_t palette[256]) | |
| 212 | { | ||
| 213 | 1 | gate_size_t count = 0; | |
| 214 | unsigned r, g, b, i; | ||
| 215 | |||
| 216 | 1 | gate_color_rgb_t* ptr = &palette[0]; | |
| 217 | |||
| 218 | /* VGA colors */ | ||
| 219 | 1 | gate_color_palette_rgb4_create(ptr); | |
| 220 | 1 | ptr += 16; | |
| 221 | 1 | count += 16; | |
| 222 | |||
| 223 | /* browser-independent 216 colors:*/ | ||
| 224 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for (r = 0; r != sizeof(bi_colors); ++r) |
| 225 | { | ||
| 226 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 6 times.
|
42 | for (g = 0; g != sizeof(bi_colors); ++g) |
| 227 | { | ||
| 228 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 36 times.
|
252 | for (b = 0; b != sizeof(bi_colors); ++b) |
| 229 | { | ||
| 230 | 216 | ptr->r = bi_colors[r]; | |
| 231 | 216 | ptr->g = bi_colors[g]; | |
| 232 | 216 | ptr->b = bi_colors[b]; | |
| 233 | 216 | ++ptr; | |
| 234 | 216 | ++count; | |
| 235 | } | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
|
17 | for (i = 0; i != 16; ++i) |
| 240 | { | ||
| 241 | 16 | ptr->b = ptr->g = ptr->r = (gate_uint8_t)(i * 0x11); | |
| 242 | 16 | ++ptr; | |
| 243 | 16 | ++count; | |
| 244 | } | ||
| 245 | 1 | return count; | |
| 246 | } | ||
| 247 | |||
| 248 | 272 | static int gate_color_diff(gate_color_rgb_t const* col1, gate_color_rgb_t const* col2) | |
| 249 | { | ||
| 250 | 272 | gate_int16_t diff_r = gate_math_abs_i16((gate_int16_t)((gate_int16_t)col1->r - (gate_int16_t)col2->r)); | |
| 251 | 272 | gate_int16_t diff_g = gate_math_abs_i16((gate_int16_t)((gate_int16_t)col1->g - (gate_int16_t)col2->g)); | |
| 252 | 272 | gate_int16_t diff_b = gate_math_abs_i16((gate_int16_t)((gate_int16_t)col1->b - (gate_int16_t)col2->b)); | |
| 253 | 272 | return gate_math_max_i16(3, diff_r, diff_g, diff_b); | |
| 254 | } | ||
| 255 | |||
| 256 | |||
| 257 | 2 | gate_size_t gate_color_palette_rgb8_resolve(gate_color_rgb_t find_color, gate_color_rgb_t const* palette, gate_size_t palette_length) | |
| 258 | { | ||
| 259 | 2 | int max_diff = 255; | |
| 260 | 2 | gate_size_t best_match = 0; | |
| 261 | gate_size_t index; | ||
| 262 | |||
| 263 |
2/2✓ Branch 0 taken 272 times.
✓ Branch 1 taken 2 times.
|
274 | for (index = 0; index != palette_length; ++index) |
| 264 | { | ||
| 265 | 272 | int tmp = gate_color_diff(&find_color, &palette[index]); | |
| 266 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 267 times.
|
272 | if (tmp < max_diff) |
| 267 | { | ||
| 268 | 5 | best_match = index; | |
| 269 | 5 | max_diff = tmp; | |
| 270 | } | ||
| 271 | } | ||
| 272 | 2 | return best_match; | |
| 273 | } | ||
| 274 | |||
| 275 | 1 | gate_size_t gate_color_load_rgb_24(gate_color_t* dest, gate_size_t pixel_count, void const* source) | |
| 276 | { | ||
| 277 | 1 | gate_size_t cnt = 0; | |
| 278 | 1 | char const* ptr = (char const*)source; | |
| 279 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | while (pixel_count-- != 0) |
| 280 | { | ||
| 281 | 2 | dest->r = *ptr; | |
| 282 | 2 | ++ptr; | |
| 283 | 2 | dest->g = *ptr; | |
| 284 | 2 | ++ptr; | |
| 285 | 2 | dest->b = *ptr; | |
| 286 | 2 | ++ptr; | |
| 287 | 2 | dest->a = 255; | |
| 288 | |||
| 289 | 2 | ++dest; | |
| 290 | 2 | ++cnt; | |
| 291 | } | ||
| 292 | 1 | return cnt; | |
| 293 | } | ||
| 294 | 1 | gate_size_t gate_color_load_rgb_32(gate_color_t* dest, gate_size_t pixel_count, void const* source) | |
| 295 | { | ||
| 296 | 1 | gate_size_t cnt = 0; | |
| 297 | 1 | char const* ptr = (char const*)source; | |
| 298 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | while (pixel_count-- != 0) |
| 299 | { | ||
| 300 | 2 | dest->r = *ptr; | |
| 301 | 2 | ++ptr; | |
| 302 | 2 | dest->g = *ptr; | |
| 303 | 2 | ++ptr; | |
| 304 | 2 | dest->b = *ptr; | |
| 305 | 2 | ++ptr; | |
| 306 | 2 | dest->a = *ptr; | |
| 307 | 2 | ++ptr; | |
| 308 | |||
| 309 | 2 | ++dest; | |
| 310 | 2 | ++cnt; | |
| 311 | } | ||
| 312 | 1 | return cnt; | |
| 313 | } | ||
| 314 | |||
| 315 | 439698 | static gate_uint8_t convert_float(gate_real32_t f) | |
| 316 | { | ||
| 317 | 439698 | int num = (int)(f * 128.0f + 127.0f); | |
| 318 |
2/2✓ Branch 0 taken 53170 times.
✓ Branch 1 taken 386528 times.
|
439698 | if (num <= 0) return 0; |
| 319 |
2/2✓ Branch 0 taken 165353 times.
✓ Branch 1 taken 221175 times.
|
386528 | if (num >= 255) return 255; |
| 320 | 221175 | return (gate_uint8_t)num; | |
| 321 | } | ||
| 322 | |||
| 323 | 293392 | static gate_real32_t convert_byte(gate_uint8_t b) | |
| 324 | { | ||
| 325 | 293392 | return (((gate_real32_t)b) - 127.0f) / 128.0f; | |
| 326 | } | ||
| 327 | |||
| 328 | 65025 | gate_size_t gate_color_load_yuv2_16(gate_color_t* dest, gate_size_t pixel_count, void const* source) | |
| 329 | { | ||
| 330 | 65025 | gate_size_t cnt = 0; | |
| 331 | 65025 | char const* ptr = (char const*)source; | |
| 332 | gate_real32_t y1, u, y2, v; | ||
| 333 | gate_real32_t fb, fr, fg; | ||
| 334 | |||
| 335 |
2/2✓ Branch 0 taken 65025 times.
✓ Branch 1 taken 65025 times.
|
130050 | while (pixel_count-- != 0) |
| 336 | { | ||
| 337 | 65025 | y1 = convert_byte(ptr[0]); | |
| 338 | 65025 | u = convert_byte(ptr[1]); | |
| 339 | 65025 | y2 = convert_byte(ptr[2]); | |
| 340 | 65025 | v = convert_byte(ptr[3]); | |
| 341 | 65025 | ptr += 4; | |
| 342 | |||
| 343 | 65025 | fb = y1 + u / 0.493f; | |
| 344 | 65025 | fr = y1 + v / 0.877f; | |
| 345 | 65025 | fg = y1 - 0.39393f * u - 0.58081f * v; | |
| 346 | |||
| 347 | 65025 | dest->r = convert_float(fr); | |
| 348 | 65025 | dest->g = convert_float(fg); | |
| 349 | 65025 | dest->b = convert_float(fb); | |
| 350 | 65025 | dest->a = 255; | |
| 351 | 65025 | ++dest; | |
| 352 | 65025 | ++cnt; | |
| 353 | |||
| 354 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 65025 times.
|
65025 | if (pixel_count-- == 0) |
| 355 | { | ||
| 356 | ✗ | break; | |
| 357 | } | ||
| 358 | |||
| 359 | 65025 | fb = y2 + u / 0.493f; | |
| 360 | 65025 | fr = y2 + v / 0.877f; | |
| 361 | 65025 | fg = y2 - 0.39393f * u - 0.58081f * v; | |
| 362 | 65025 | dest->r = convert_float(fr); | |
| 363 | 65025 | dest->g = convert_float(fg); | |
| 364 | 65025 | dest->b = convert_float(fb); | |
| 365 | 65025 | dest->a = 255; | |
| 366 | 65025 | ++dest; | |
| 367 | 65025 | ++cnt; | |
| 368 | } | ||
| 369 | 65025 | return cnt; | |
| 370 | } | ||
| 371 | |||
| 372 | 4096 | gate_uint8_t gate_color_to_grayscale(gate_color_t const* src) | |
| 373 | { | ||
| 374 | 4096 | return (gate_uint8_t)((((int)src->r * 54) + ((int)src->g * 182) + ((int)src->b * 19)) / 255); | |
| 375 | } | ||
| 376 | |||
| 377 | 111 | gate_uint8_t gate_color_to_monochrome(gate_color_t const* src, gate_uint8_t threshold) | |
| 378 | { | ||
| 379 | gate_uint8_t gray; | ||
| 380 |
2/4✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 111 times.
✗ Branch 3 not taken.
|
111 | if ((src->r == src->g) && (src->r == src->b)) |
| 381 | { | ||
| 382 | 111 | gray = src->r; | |
| 383 | } | ||
| 384 | else | ||
| 385 | { | ||
| 386 | ✗ | gray = gate_color_to_grayscale(src); | |
| 387 | } | ||
| 388 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 60 times.
|
111 | return (gray < threshold) ? 0 : 255; |
| 389 | } | ||
| 390 | |||
| 391 | |||
| 392 | |||
| 393 | 513 | void gate_color_convert_rgba_from_bgra_32(gate_uint8_t* rgba, gate_uint8_t const* bgra, gate_size_t pixel_count) | |
| 394 | { | ||
| 395 |
2/2✓ Branch 0 taken 32769 times.
✓ Branch 1 taken 513 times.
|
33282 | while (pixel_count-- > 0) |
| 396 | { | ||
| 397 | 32769 | rgba[0] = bgra[2]; | |
| 398 | 32769 | rgba[1] = bgra[1]; | |
| 399 | 32769 | rgba[2] = bgra[0]; | |
| 400 | 32769 | rgba[3] = bgra[3]; | |
| 401 | 32769 | rgba += 4; | |
| 402 | 32769 | bgra += 4; | |
| 403 | } | ||
| 404 | 513 | } | |
| 405 | 257 | void gate_color_convert_rgba_from_bgr_24(gate_uint8_t* rgba, gate_uint8_t const* bgr24, gate_size_t pixel_count) | |
| 406 | { | ||
| 407 |
2/2✓ Branch 0 taken 16385 times.
✓ Branch 1 taken 257 times.
|
16642 | while (pixel_count-- > 0) |
| 408 | { | ||
| 409 | 16385 | rgba[0] = bgr24[2]; | |
| 410 | 16385 | rgba[1] = bgr24[1]; | |
| 411 | 16385 | rgba[2] = bgr24[0]; | |
| 412 | 16385 | rgba[3] = 255; | |
| 413 | 16385 | rgba += 4; | |
| 414 | 16385 | bgr24 += 3; | |
| 415 | } | ||
| 416 | 257 | } | |
| 417 | 417 | void gate_color_convert_rgba_from_rgb_24(gate_uint8_t* rgba, gate_uint8_t const* rgb24, gate_size_t pixel_count) | |
| 418 | { | ||
| 419 |
2/2✓ Branch 0 taken 26625 times.
✓ Branch 1 taken 417 times.
|
27042 | while (pixel_count-- > 0) |
| 420 | { | ||
| 421 | 26625 | rgba[0] = rgb24[0]; | |
| 422 | 26625 | rgba[1] = rgb24[1]; | |
| 423 | 26625 | rgba[2] = rgb24[2]; | |
| 424 | 26625 | rgba[3] = 255; | |
| 425 | 26625 | rgba += 4; | |
| 426 | 26625 | rgb24 += 3; | |
| 427 | } | ||
| 428 | 417 | } | |
| 429 | 257 | void gate_color_convert_rgba_from_rgb_16(gate_uint8_t* rgba, gate_uint8_t const* rgb565, gate_size_t pixel_count) | |
| 430 | { | ||
| 431 |
2/2✓ Branch 0 taken 16385 times.
✓ Branch 1 taken 257 times.
|
16642 | while (pixel_count-- > 0) |
| 432 | { | ||
| 433 | 16385 | const unsigned char b = (rgb565[0] & 0x1f); | |
| 434 | 16385 | const unsigned char g = ((rgb565[1] & 0x07) << 3) | ((rgb565[0] & 0xe0) >> 5); | |
| 435 | 16385 | const unsigned char r = (rgb565[1] & 0xf8) >> 3; | |
| 436 | 16385 | rgba[0] = (r << 3) | (r >> 2); | |
| 437 | 16385 | rgba[1] = (g << 2) | (g >> 4); | |
| 438 | 16385 | rgba[2] = (b << 3) | (b >> 2); | |
| 439 | 16385 | rgba[3] = 255; | |
| 440 | 16385 | rgba += 4; | |
| 441 | 16385 | rgb565 += 2; | |
| 442 | } | ||
| 443 | 257 | } | |
| 444 | 257 | void gate_color_convert_rgba_from_rgb_15(gate_uint8_t* rgba, gate_uint8_t const* rgb555, gate_size_t pixel_count) | |
| 445 | { | ||
| 446 |
2/2✓ Branch 0 taken 16385 times.
✓ Branch 1 taken 257 times.
|
16642 | while (pixel_count-- > 0) |
| 447 | { | ||
| 448 | 16385 | const unsigned char b = (rgb555[0] & 0x1f); | |
| 449 | 16385 | const unsigned char g = ((rgb555[1] & 0x03) << 3) | ((rgb555[0] & 0xe0) >> 5); | |
| 450 | 16385 | const unsigned char r = (rgb555[1] & 0x7c) >> 2; | |
| 451 | 16385 | rgba[0] = (r << 3) | (r >> 2); | |
| 452 | 16385 | rgba[1] = (g << 3) | (g >> 2); | |
| 453 | 16385 | rgba[2] = (b << 3) | (b >> 2); | |
| 454 | 16385 | rgba[3] = 255; | |
| 455 | 16385 | rgba += 4; | |
| 456 | 16385 | rgb555 += 2; | |
| 457 | } | ||
| 458 | 257 | } | |
| 459 | 257 | void gate_color_convert_rgba_from_argb_16(gate_uint8_t* rgba, gate_uint8_t const* rgba4444, gate_size_t pixel_count) | |
| 460 | { | ||
| 461 |
2/2✓ Branch 0 taken 16385 times.
✓ Branch 1 taken 257 times.
|
16642 | while (pixel_count-- > 0) |
| 462 | { | ||
| 463 | 16385 | const unsigned char b = (rgba4444[0] & 0x0f); | |
| 464 | 16385 | const unsigned char g = (rgba4444[0] & 0xf0) >> 4; | |
| 465 | 16385 | const unsigned char r = (rgba4444[1] & 0x0f); | |
| 466 | 16385 | const unsigned char a = (rgba4444[1] & 0xf0) >> 4; | |
| 467 | 16385 | rgba[0] = (r << 4) | r; | |
| 468 | 16385 | rgba[1] = (g << 4) | g; | |
| 469 | 16385 | rgba[2] = (b << 4) | b; | |
| 470 | 16385 | rgba[3] = (a << 4) | a; | |
| 471 | 16385 | rgba += 4; | |
| 472 | 16385 | rgba4444 += 2; | |
| 473 | } | ||
| 474 | 257 | } | |
| 475 | 257 | void gate_color_convert_rgba_from_yuv2_16(gate_uint8_t* rgba, gate_uint8_t const* yuv2, gate_size_t pixel_count) | |
| 476 | { | ||
| 477 | gate_real32_t y1, u, y2, v; | ||
| 478 | gate_real32_t fb, fr, fg; | ||
| 479 | |||
| 480 |
2/2✓ Branch 0 taken 8193 times.
✓ Branch 1 taken 257 times.
|
8450 | for (; pixel_count >= 2; pixel_count -= 2) |
| 481 | { | ||
| 482 | 8193 | y1 = convert_byte(yuv2[0]); | |
| 483 | 8193 | u = convert_byte(yuv2[1]); | |
| 484 | 8193 | y2 = convert_byte(yuv2[2]); | |
| 485 | 8193 | v = convert_byte(yuv2[3]); | |
| 486 | 8193 | yuv2 += 4; | |
| 487 | |||
| 488 | 8193 | fb = y1 + u / 0.493f; | |
| 489 | 8193 | fr = y1 + v / 0.877f; | |
| 490 | 8193 | fg = y1 - 0.39393f * u - 0.58081f * v; | |
| 491 | |||
| 492 | 8193 | rgba[0] = convert_float(fr); | |
| 493 | 8193 | rgba[1] = convert_float(fg); | |
| 494 | 8193 | rgba[2] = convert_float(fb); | |
| 495 | 8193 | rgba[3] = 255; | |
| 496 | 8193 | rgba += 4; | |
| 497 | |||
| 498 | 8193 | fb = y2 + u / 0.493f; | |
| 499 | 8193 | fr = y2 + v / 0.877f; | |
| 500 | 8193 | fg = y2 - 0.39393f * u - 0.58081f * v; | |
| 501 | |||
| 502 | 8193 | rgba[0] = convert_float(fr); | |
| 503 | 8193 | rgba[1] = convert_float(fg); | |
| 504 | 8193 | rgba[2] = convert_float(fb); | |
| 505 | 8193 | rgba[3] = 255; | |
| 506 | 8193 | rgba += 4; | |
| 507 | } | ||
| 508 | 257 | } | |
| 509 | 257 | void gate_color_convert_rgba_from_pal_8(gate_uint8_t* rgba, gate_uint8_t const* pal8, gate_size_t pixel_count) | |
| 510 | { | ||
| 511 | gate_color_rgb_t rgb; | ||
| 512 |
2/2✓ Branch 0 taken 16385 times.
✓ Branch 1 taken 257 times.
|
16642 | while (pixel_count-- > 0) |
| 513 | { | ||
| 514 | 16385 | const unsigned char c = *pal8; | |
| 515 | 16385 | gate_color_palette_rgb8_from_index(c, &rgb); | |
| 516 | 16385 | rgba[0] = rgb.r; | |
| 517 | 16385 | rgba[1] = rgb.g; | |
| 518 | 16385 | rgba[2] = rgb.b; | |
| 519 | 16385 | rgba[3] = 255; | |
| 520 | 16385 | rgba += 4; | |
| 521 | 16385 | ++pal8; | |
| 522 | } | ||
| 523 | 257 | } | |
| 524 | 257 | void gate_color_convert_rgba_from_gray_8(gate_uint8_t* rgba, gate_uint8_t const* gray8, gate_size_t pixel_count) | |
| 525 | { | ||
| 526 |
2/2✓ Branch 0 taken 16385 times.
✓ Branch 1 taken 257 times.
|
16642 | while (pixel_count-- > 0) |
| 527 | { | ||
| 528 | 16385 | const unsigned char g = *gray8; | |
| 529 | 16385 | rgba[0] = g; | |
| 530 | 16385 | rgba[1] = g; | |
| 531 | 16385 | rgba[2] = g; | |
| 532 | 16385 | rgba[3] = 255; | |
| 533 | 16385 | rgba += 4; | |
| 534 | 16385 | ++gray8; | |
| 535 | } | ||
| 536 | 257 | } | |
| 537 | |||
| 538 | |||
| 539 | /**********************************************/ | ||
| 540 | |||
| 541 | 385 | void gate_color_convert_rgb_from_rgba_32(gate_uint8_t* rgb, gate_uint8_t const* rgba, gate_size_t pixel_count) | |
| 542 | { | ||
| 543 |
2/2✓ Branch 0 taken 40961 times.
✓ Branch 1 taken 385 times.
|
41346 | while (pixel_count-- > 0) |
| 544 | { | ||
| 545 | 40961 | rgb[0] = rgba[0]; | |
| 546 | 40961 | rgb[1] = rgba[1]; | |
| 547 | 40961 | rgb[2] = rgba[2]; | |
| 548 | 40961 | rgb += 3; | |
| 549 | 40961 | rgba += 4; | |
| 550 | } | ||
| 551 | 385 | } | |
| 552 | |||
| 553 | 129 | void gate_color_convert_rgb_from_bgra_32(gate_uint8_t* rgb, gate_uint8_t const* bgra, gate_size_t pixel_count) | |
| 554 | { | ||
| 555 |
2/2✓ Branch 0 taken 8193 times.
✓ Branch 1 taken 129 times.
|
8322 | while (pixel_count-- > 0) |
| 556 | { | ||
| 557 | 8193 | rgb[0] = bgra[2]; | |
| 558 | 8193 | rgb[1] = bgra[1]; | |
| 559 | 8193 | rgb[2] = bgra[0]; | |
| 560 | 8193 | rgb += 3; | |
| 561 | 8193 | bgra += 4; | |
| 562 | } | ||
| 563 | 129 | } | |
| 564 | 65 | void gate_color_convert_rgb_from_bgr_24(gate_uint8_t* rgb, gate_uint8_t const* rgb24, gate_size_t pixel_count) | |
| 565 | { | ||
| 566 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 567 | { | ||
| 568 | 4097 | rgb[0] = rgb24[2]; | |
| 569 | 4097 | rgb[1] = rgb24[1]; | |
| 570 | 4097 | rgb[2] = rgb24[0]; | |
| 571 | 4097 | rgb += 3; | |
| 572 | 4097 | rgb24 += 3; | |
| 573 | } | ||
| 574 | 65 | } | |
| 575 | 96 | void gate_color_convert_rgb_from_rgb_24(gate_uint8_t* rgb, gate_uint8_t const* rgb24, gate_size_t pixel_count) | |
| 576 | { | ||
| 577 |
2/2✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 96 times.
|
6240 | while (pixel_count-- > 0) |
| 578 | { | ||
| 579 | 6144 | rgb[0] = rgb24[0]; | |
| 580 | 6144 | rgb[1] = rgb24[1]; | |
| 581 | 6144 | rgb[2] = rgb24[2]; | |
| 582 | 6144 | rgb += 3; | |
| 583 | 6144 | rgb24 += 3; | |
| 584 | } | ||
| 585 | 96 | } | |
| 586 | 65 | void gate_color_convert_rgb_from_rgb_16(gate_uint8_t* rgb, gate_uint8_t const* rgb565, gate_size_t pixel_count) | |
| 587 | { | ||
| 588 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 589 | { | ||
| 590 | 4097 | const unsigned char b = (rgb565[0] & 0x1f); | |
| 591 | 4097 | const unsigned char g = ((rgb565[1] & 0x07) << 3) | ((rgb565[0] & 0xe0) >> 5); | |
| 592 | 4097 | const unsigned char r = (rgb565[1] & 0xf8) >> 3; | |
| 593 | 4097 | rgb[0] = (r << 3) | (r >> 2); | |
| 594 | 4097 | rgb[1] = (g << 2) | (g >> 4); | |
| 595 | 4097 | rgb[2] = (b << 3) | (b >> 2); | |
| 596 | 4097 | rgb += 3; | |
| 597 | 4097 | rgb565 += 2; | |
| 598 | } | ||
| 599 | 65 | } | |
| 600 | 65 | void gate_color_convert_rgb_from_rgb_15(gate_uint8_t* rgb, gate_uint8_t const* rgb555, gate_size_t pixel_count) | |
| 601 | { | ||
| 602 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 603 | { | ||
| 604 | 4097 | const unsigned char b = (rgb555[0] & 0x1f); | |
| 605 | 4097 | const unsigned char g = ((rgb555[1] & 0x03) << 3) | ((rgb555[0] & 0xe0) >> 5); | |
| 606 | 4097 | const unsigned char r = (rgb555[1] & 0x7c) >> 2; | |
| 607 | 4097 | rgb[0] = (r << 3) | (r >> 2); | |
| 608 | 4097 | rgb[1] = (g << 3) | (g >> 2); | |
| 609 | 4097 | rgb[2] = (b << 3) | (b >> 2); | |
| 610 | 4097 | rgb += 3; | |
| 611 | 4097 | rgb555 += 2; | |
| 612 | } | ||
| 613 | 65 | } | |
| 614 | 65 | void gate_color_convert_rgb_from_argb_16(gate_uint8_t* rgb, gate_uint8_t const* rgba4444, gate_size_t pixel_count) | |
| 615 | { | ||
| 616 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 617 | { | ||
| 618 | 4097 | const unsigned char b = (rgba4444[0] & 0x0f); | |
| 619 | 4097 | const unsigned char g = (rgba4444[0] & 0xf0) >> 4; | |
| 620 | 4097 | const unsigned char r = (rgba4444[1] & 0x0f); | |
| 621 | /*const unsigned char a = (rgba4444[1] & 0xf0) >> 4;*/ | ||
| 622 | 4097 | rgb[0] = (r << 4) | r; | |
| 623 | 4097 | rgb[1] = (g << 4) | g; | |
| 624 | 4097 | rgb[2] = (b << 4) | b; | |
| 625 | 4097 | rgb += 3; | |
| 626 | 4097 | rgba4444 += 2; | |
| 627 | } | ||
| 628 | 65 | } | |
| 629 | 65 | void gate_color_convert_rgb_from_yuv2_16(gate_uint8_t* rgb, gate_uint8_t const* yuv2, gate_size_t pixel_count) | |
| 630 | { | ||
| 631 | gate_real32_t y1, u, y2, v; | ||
| 632 | gate_real32_t fb, fr, fg; | ||
| 633 | |||
| 634 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
65 | for (; pixel_count >= 2; pixel_count -= 2) |
| 635 | { | ||
| 636 | 65 | y1 = convert_byte(yuv2[0]); | |
| 637 | 65 | u = convert_byte(yuv2[1]); | |
| 638 | 65 | y2 = convert_byte(yuv2[2]); | |
| 639 | 65 | v = convert_byte(yuv2[3]); | |
| 640 | 65 | yuv2 += 4; | |
| 641 | |||
| 642 | 65 | fb = y1 + u / 0.493f; | |
| 643 | 65 | fr = y1 + v / 0.877f; | |
| 644 | 65 | fg = y1 - 0.39393f * u - 0.58081f * v; | |
| 645 | |||
| 646 | 65 | rgb[0] = convert_float(fr); | |
| 647 | 65 | rgb[1] = convert_float(fg); | |
| 648 | 65 | rgb[2] = convert_float(fb); | |
| 649 | 65 | rgb += 3; | |
| 650 | |||
| 651 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
65 | if (pixel_count-- != 0) |
| 652 | { | ||
| 653 | 65 | break; | |
| 654 | } | ||
| 655 | |||
| 656 | ✗ | fb = y2 + u / 0.493f; | |
| 657 | ✗ | fr = y2 + v / 0.877f; | |
| 658 | ✗ | fg = y2 - 0.39393f * u - 0.58081f * v; | |
| 659 | |||
| 660 | ✗ | rgb[0] = convert_float(fr); | |
| 661 | ✗ | rgb[1] = convert_float(fg); | |
| 662 | ✗ | rgb[2] = convert_float(fb); | |
| 663 | ✗ | rgb += 3; | |
| 664 | } | ||
| 665 | 65 | } | |
| 666 | 65 | void gate_color_convert_rgb_from_pal_8(gate_uint8_t* rgb, gate_uint8_t const* pal8, gate_size_t pixel_count) | |
| 667 | { | ||
| 668 | gate_color_rgb_t src_rgb; | ||
| 669 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 670 | { | ||
| 671 | 4097 | const unsigned char c = *pal8; | |
| 672 | 4097 | gate_color_palette_rgb8_from_index(c, &src_rgb); | |
| 673 | 4097 | rgb[0] = src_rgb.r; | |
| 674 | 4097 | rgb[1] = src_rgb.g; | |
| 675 | 4097 | rgb[2] = src_rgb.b; | |
| 676 | 4097 | rgb += 3; | |
| 677 | 4097 | ++pal8; | |
| 678 | } | ||
| 679 | 65 | } | |
| 680 | 65 | void gate_color_convert_rgb_from_gray_8(gate_uint8_t* rgb, gate_uint8_t const* gray8, gate_size_t pixel_count) | |
| 681 | { | ||
| 682 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 683 | { | ||
| 684 | 4097 | const unsigned char g = *gray8; | |
| 685 | 4097 | rgb[0] = g; | |
| 686 | 4097 | rgb[1] = g; | |
| 687 | 4097 | rgb[2] = g; | |
| 688 | 4097 | rgb += 3; | |
| 689 | 4097 | ++gray8; | |
| 690 | } | ||
| 691 | 65 | } | |
| 692 | |||
| 693 | |||
| 694 | /**********************************************/ | ||
| 695 | |||
| 696 | |||
| 697 | 513 | void gate_color_convert_bgra_from_rgba_32(gate_uint8_t* bgra, gate_uint8_t const* rgba32, gate_size_t pixel_count) | |
| 698 | { | ||
| 699 |
2/2✓ Branch 0 taken 57345 times.
✓ Branch 1 taken 513 times.
|
57858 | while (pixel_count-- > 0) |
| 700 | { | ||
| 701 | 57345 | bgra[0] = rgba32[2]; | |
| 702 | 57345 | bgra[1] = rgba32[1]; | |
| 703 | 57345 | bgra[2] = rgba32[0]; | |
| 704 | 57345 | bgra[3] = rgba32[3]; | |
| 705 | 57345 | bgra += 4; | |
| 706 | 57345 | rgba32 += 4; | |
| 707 | } | ||
| 708 | 513 | } | |
| 709 | 65 | void gate_color_convert_bgra_from_bgr_24(gate_uint8_t* bgra, gate_uint8_t const* bgr24, gate_size_t pixel_count) | |
| 710 | { | ||
| 711 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 712 | { | ||
| 713 | 4097 | bgra[0] = bgr24[0]; | |
| 714 | 4097 | bgra[1] = bgr24[1]; | |
| 715 | 4097 | bgra[2] = bgr24[2]; | |
| 716 | 4097 | bgra[3] = 255; | |
| 717 | 4097 | bgra += 4; | |
| 718 | 4097 | bgr24 += 3; | |
| 719 | } | ||
| 720 | 65 | } | |
| 721 | 97 | void gate_color_convert_bgra_from_rgb_24(gate_uint8_t* bgra, gate_uint8_t const* rgb24, gate_size_t pixel_count) | |
| 722 | { | ||
| 723 |
2/2✓ Branch 0 taken 6145 times.
✓ Branch 1 taken 97 times.
|
6242 | while (pixel_count-- > 0) |
| 724 | { | ||
| 725 | 6145 | bgra[0] = rgb24[2]; | |
| 726 | 6145 | bgra[1] = rgb24[1]; | |
| 727 | 6145 | bgra[2] = rgb24[0]; | |
| 728 | 6145 | bgra[3] = 255; | |
| 729 | 6145 | bgra += 4; | |
| 730 | 6145 | rgb24 += 3; | |
| 731 | } | ||
| 732 | 97 | } | |
| 733 | 65 | void gate_color_convert_bgra_from_rgb_16(gate_uint8_t* bgra, gate_uint8_t const* rgb565, gate_size_t pixel_count) | |
| 734 | { | ||
| 735 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 736 | { | ||
| 737 | /* rrrrrggg gggbbbbb */ | ||
| 738 | 4097 | const unsigned char b = (rgb565[0] & 0x1f); | |
| 739 | 4097 | const unsigned char g = ((rgb565[1] & 0x07) << 3) | ((rgb565[0] & 0xe0) >> 5); | |
| 740 | 4097 | const unsigned char r = (rgb565[1] & 0xf8) >> 3; | |
| 741 | 4097 | bgra[0] = (b << 3) | (b >> 2); | |
| 742 | 4097 | bgra[1] = (g << 2) | (g >> 4); | |
| 743 | 4097 | bgra[2] = (r << 3) | (r >> 2); | |
| 744 | 4097 | bgra[3] = 255; | |
| 745 | 4097 | bgra += 4; | |
| 746 | 4097 | rgb565 += 2; | |
| 747 | } | ||
| 748 | 65 | } | |
| 749 | 65 | void gate_color_convert_bgra_from_rgb_15(gate_uint8_t* bgra, gate_uint8_t const* rgb555, gate_size_t pixel_count) | |
| 750 | { | ||
| 751 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 752 | { | ||
| 753 | /* 0rrrrrgg gggbbbbb */ | ||
| 754 | 4097 | const unsigned char b = (rgb555[0] & 0x1f); | |
| 755 | 4097 | const unsigned char g = ((rgb555[1] & 0x03) << 3) | ((rgb555[0] & 0xe0) >> 5); | |
| 756 | 4097 | const unsigned char r = (rgb555[1] & 0x7c) >> 2; | |
| 757 | 4097 | bgra[0] = (b << 3) | (b >> 2); | |
| 758 | 4097 | bgra[1] = (g << 3) | (g >> 2); | |
| 759 | 4097 | bgra[2] = (r << 3) | (r >> 2); | |
| 760 | 4097 | bgra[3] = 255; | |
| 761 | 4097 | bgra += 4; | |
| 762 | 4097 | rgb555 += 2; | |
| 763 | } | ||
| 764 | 65 | } | |
| 765 | 65 | void gate_color_convert_bgra_from_argb_16(gate_uint8_t* bgra, gate_uint8_t const* rgba4444, gate_size_t pixel_count) | |
| 766 | { | ||
| 767 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 768 | { | ||
| 769 | /* aaaarrrrggggbbbb */ | ||
| 770 | 4097 | const unsigned char b = (rgba4444[0] & 0x0f); | |
| 771 | 4097 | const unsigned char g = (rgba4444[0] & 0xf0) >> 4; | |
| 772 | 4097 | const unsigned char r = (rgba4444[1] & 0x0f); | |
| 773 | 4097 | const unsigned char a = (rgba4444[1] & 0xf0) >> 4; | |
| 774 | 4097 | bgra[0] = (b << 4) | b; | |
| 775 | 4097 | bgra[1] = (g << 4) | g; | |
| 776 | 4097 | bgra[2] = (r << 4) | r; | |
| 777 | 4097 | bgra[3] = (a << 4) | a; | |
| 778 | 4097 | bgra += 4; | |
| 779 | 4097 | rgba4444 += 2; | |
| 780 | } | ||
| 781 | 65 | } | |
| 782 | 65 | void gate_color_convert_bgra_from_yuv2_16(gate_uint8_t* bgra, gate_uint8_t const* yuv2, gate_size_t pixel_count) | |
| 783 | { | ||
| 784 | gate_real32_t y1, u, y2, v; | ||
| 785 | gate_real32_t fb, fr, fg; | ||
| 786 | |||
| 787 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
65 | for (; pixel_count >= 2; pixel_count -= 2) |
| 788 | { | ||
| 789 | 65 | y1 = convert_byte(yuv2[0]); | |
| 790 | 65 | u = convert_byte(yuv2[1]); | |
| 791 | 65 | y2 = convert_byte(yuv2[2]); | |
| 792 | 65 | v = convert_byte(yuv2[3]); | |
| 793 | 65 | yuv2 += 4; | |
| 794 | |||
| 795 | 65 | fb = y1 + u / 0.493f; | |
| 796 | 65 | fr = y1 + v / 0.877f; | |
| 797 | 65 | fg = y1 - 0.39393f * u - 0.58081f * v; | |
| 798 | |||
| 799 | 65 | bgra[0] = convert_float(fb); | |
| 800 | 65 | bgra[1] = convert_float(fg); | |
| 801 | 65 | bgra[2] = convert_float(fr); | |
| 802 | 65 | bgra[3] = 255; | |
| 803 | 65 | bgra += 4; | |
| 804 | |||
| 805 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
65 | if (pixel_count-- != 0) |
| 806 | { | ||
| 807 | 65 | break; | |
| 808 | } | ||
| 809 | |||
| 810 | ✗ | fb = y2 + u / 0.493f; | |
| 811 | ✗ | fr = y2 + v / 0.877f; | |
| 812 | ✗ | fg = y2 - 0.39393f * u - 0.58081f * v; | |
| 813 | |||
| 814 | ✗ | bgra[0] = convert_float(fb); | |
| 815 | ✗ | bgra[1] = convert_float(fg); | |
| 816 | ✗ | bgra[2] = convert_float(fr); | |
| 817 | ✗ | bgra[3] = 255; | |
| 818 | ✗ | bgra += 4; | |
| 819 | } | ||
| 820 | 65 | } | |
| 821 | 65 | void gate_color_convert_bgra_from_pal_8(gate_uint8_t* bgra, gate_uint8_t const* pal8, gate_size_t pixel_count) | |
| 822 | { | ||
| 823 | gate_color_rgb_t rgb; | ||
| 824 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 825 | { | ||
| 826 | 4097 | const unsigned char c = *pal8; | |
| 827 | 4097 | gate_color_palette_rgb8_from_index(c, &rgb); | |
| 828 | 4097 | bgra[0] = rgb.b; | |
| 829 | 4097 | bgra[1] = rgb.g; | |
| 830 | 4097 | bgra[2] = rgb.r; | |
| 831 | 4097 | bgra[3] = 255; | |
| 832 | 4097 | bgra += 4; | |
| 833 | 4097 | ++pal8; | |
| 834 | } | ||
| 835 | 65 | } | |
| 836 | 65 | void gate_color_convert_bgra_from_gray_8(gate_uint8_t* bgra, gate_uint8_t const* gray8, gate_size_t pixel_count) | |
| 837 | { | ||
| 838 |
2/2✓ Branch 0 taken 4097 times.
✓ Branch 1 taken 65 times.
|
4162 | while (pixel_count-- > 0) |
| 839 | { | ||
| 840 | 4097 | const unsigned char g = *gray8; | |
| 841 | 4097 | bgra[0] = g; | |
| 842 | 4097 | bgra[1] = g; | |
| 843 | 4097 | bgra[2] = g; | |
| 844 | 4097 | bgra[3] = 255; | |
| 845 | 4097 | bgra += 4; | |
| 846 | 4097 | ++gray8; | |
| 847 | } | ||
| 848 | 65 | } | |
| 849 |