| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "libyuv/row.h" |
| 12 |
| 13 | #include <string.h> // For memcpy and memset. |
| 14 |
| 15 | #include "libyuv/basic_types.h" |
| 16 |
| 17 | #ifdef __cplusplus |
| 18 | namespace libyuv { |
| 19 | extern "C" { |
| 20 | #endif |
| 21 |
| 22 | // llvm x86 is poor at ternary operator, so use branchless min/max. |
| 23 |
| 24 | #define USE_BRANCHLESS 1 |
| 25 | #if USE_BRANCHLESS |
| 26 | static __inline int32 clamp0(int32 v) { |
| 27 | return ((-(v) >> 31) & (v)); |
| 28 | } |
| 29 |
| 30 | static __inline int32 clamp255(int32 v) { |
| 31 | return (((255 - (v)) >> 31) | (v)) & 255; |
| 32 | } |
| 33 |
| 34 | static __inline uint32 Clamp(int32 val) { |
| 35 | int v = clamp0(val); |
| 36 | return (uint32)(clamp255(v)); |
| 37 | } |
| 38 |
| 39 | static __inline uint32 Abs(int32 v) { |
| 40 | int m = v >> 31; |
| 41 | return (v + m) ^ m; |
| 42 | } |
| 43 | #else // USE_BRANCHLESS |
| 44 | static __inline int32 clamp0(int32 v) { |
| 45 | return (v < 0) ? 0 : v; |
| 46 | } |
| 47 |
| 48 | static __inline int32 clamp255(int32 v) { |
| 49 | return (v > 255) ? 255 : v; |
| 50 | } |
| 51 |
| 52 | static __inline uint32 Clamp(int32 val) { |
| 53 | int v = clamp0(val); |
| 54 | return (uint32)(clamp255(v)); |
| 55 | } |
| 56 |
| 57 | static __inline uint32 Abs(int32 v) { |
| 58 | return (v < 0) ? -v : v; |
| 59 | } |
| 60 | #endif // USE_BRANCHLESS |
| 61 |
| 62 | #ifdef LIBYUV_LITTLE_ENDIAN |
| 63 | #define WRITEWORD(p, v) *(uint32*)(p) = v |
| 64 | #else |
| 65 | static inline void WRITEWORD(uint8* p, uint32 v) { |
| 66 | p[0] = (uint8)(v & 255); |
| 67 | p[1] = (uint8)((v >> 8) & 255); |
| 68 | p[2] = (uint8)((v >> 16) & 255); |
| 69 | p[3] = (uint8)((v >> 24) & 255); |
| 70 | } |
| 71 | #endif |
| 72 |
| 73 | void RGB24ToARGBRow_C(const uint8* src_rgb24, uint8* dst_argb, int width) { |
| 74 | int x; |
| 75 | for (x = 0; x < width; ++x) { |
| 76 | uint8 b = src_rgb24[0]; |
| 77 | uint8 g = src_rgb24[1]; |
| 78 | uint8 r = src_rgb24[2]; |
| 79 | dst_argb[0] = b; |
| 80 | dst_argb[1] = g; |
| 81 | dst_argb[2] = r; |
| 82 | dst_argb[3] = 255u; |
| 83 | dst_argb += 4; |
| 84 | src_rgb24 += 3; |
| 85 | } |
| 86 | } |
| 87 |
| 88 | void RAWToARGBRow_C(const uint8* src_raw, uint8* dst_argb, int width) { |
| 89 | int x; |
| 90 | for (x = 0; x < width; ++x) { |
| 91 | uint8 r = src_raw[0]; |
| 92 | uint8 g = src_raw[1]; |
| 93 | uint8 b = src_raw[2]; |
| 94 | dst_argb[0] = b; |
| 95 | dst_argb[1] = g; |
| 96 | dst_argb[2] = r; |
| 97 | dst_argb[3] = 255u; |
| 98 | dst_argb += 4; |
| 99 | src_raw += 3; |
| 100 | } |
| 101 | } |
| 102 |
| 103 | void RAWToRGB24Row_C(const uint8* src_raw, uint8* dst_rgb24, int width) { |
| 104 | int x; |
| 105 | for (x = 0; x < width; ++x) { |
| 106 | uint8 r = src_raw[0]; |
| 107 | uint8 g = src_raw[1]; |
| 108 | uint8 b = src_raw[2]; |
| 109 | dst_rgb24[0] = b; |
| 110 | dst_rgb24[1] = g; |
| 111 | dst_rgb24[2] = r; |
| 112 | dst_rgb24 += 3; |
| 113 | src_raw += 3; |
| 114 | } |
| 115 | } |
| 116 |
| 117 | void RGB565ToARGBRow_C(const uint8* src_rgb565, uint8* dst_argb, int width) { |
| 118 | int x; |
| 119 | for (x = 0; x < width; ++x) { |
| 120 | uint8 b = src_rgb565[0] & 0x1f; |
| 121 | uint8 g = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); |
| 122 | uint8 r = src_rgb565[1] >> 3; |
| 123 | dst_argb[0] = (b << 3) | (b >> 2); |
| 124 | dst_argb[1] = (g << 2) | (g >> 4); |
| 125 | dst_argb[2] = (r << 3) | (r >> 2); |
| 126 | dst_argb[3] = 255u; |
| 127 | dst_argb += 4; |
| 128 | src_rgb565 += 2; |
| 129 | } |
| 130 | } |
| 131 |
| 132 | void ARGB1555ToARGBRow_C(const uint8* src_argb1555, uint8* dst_argb, |
| 133 | int width) { |
| 134 | int x; |
| 135 | for (x = 0; x < width; ++x) { |
| 136 | uint8 b = src_argb1555[0] & 0x1f; |
| 137 | uint8 g = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); |
| 138 | uint8 r = (src_argb1555[1] & 0x7c) >> 2; |
| 139 | uint8 a = src_argb1555[1] >> 7; |
| 140 | dst_argb[0] = (b << 3) | (b >> 2); |
| 141 | dst_argb[1] = (g << 3) | (g >> 2); |
| 142 | dst_argb[2] = (r << 3) | (r >> 2); |
| 143 | dst_argb[3] = -a; |
| 144 | dst_argb += 4; |
| 145 | src_argb1555 += 2; |
| 146 | } |
| 147 | } |
| 148 |
| 149 | void ARGB4444ToARGBRow_C(const uint8* src_argb4444, uint8* dst_argb, |
| 150 | int width) { |
| 151 | int x; |
| 152 | for (x = 0; x < width; ++x) { |
| 153 | uint8 b = src_argb4444[0] & 0x0f; |
| 154 | uint8 g = src_argb4444[0] >> 4; |
| 155 | uint8 r = src_argb4444[1] & 0x0f; |
| 156 | uint8 a = src_argb4444[1] >> 4; |
| 157 | dst_argb[0] = (b << 4) | b; |
| 158 | dst_argb[1] = (g << 4) | g; |
| 159 | dst_argb[2] = (r << 4) | r; |
| 160 | dst_argb[3] = (a << 4) | a; |
| 161 | dst_argb += 4; |
| 162 | src_argb4444 += 2; |
| 163 | } |
| 164 | } |
| 165 |
| 166 | void ARGBToRGB24Row_C(const uint8* src_argb, uint8* dst_rgb, int width) { |
| 167 | int x; |
| 168 | for (x = 0; x < width; ++x) { |
| 169 | uint8 b = src_argb[0]; |
| 170 | uint8 g = src_argb[1]; |
| 171 | uint8 r = src_argb[2]; |
| 172 | dst_rgb[0] = b; |
| 173 | dst_rgb[1] = g; |
| 174 | dst_rgb[2] = r; |
| 175 | dst_rgb += 3; |
| 176 | src_argb += 4; |
| 177 | } |
| 178 | } |
| 179 |
| 180 | void ARGBToRAWRow_C(const uint8* src_argb, uint8* dst_rgb, int width) { |
| 181 | int x; |
| 182 | for (x = 0; x < width; ++x) { |
| 183 | uint8 b = src_argb[0]; |
| 184 | uint8 g = src_argb[1]; |
| 185 | uint8 r = src_argb[2]; |
| 186 | dst_rgb[0] = r; |
| 187 | dst_rgb[1] = g; |
| 188 | dst_rgb[2] = b; |
| 189 | dst_rgb += 3; |
| 190 | src_argb += 4; |
| 191 | } |
| 192 | } |
| 193 |
| 194 | void ARGBToRGB565Row_C(const uint8* src_argb, uint8* dst_rgb, int width) { |
| 195 | int x; |
| 196 | for (x = 0; x < width - 1; x += 2) { |
| 197 | uint8 b0 = src_argb[0] >> 3; |
| 198 | uint8 g0 = src_argb[1] >> 2; |
| 199 | uint8 r0 = src_argb[2] >> 3; |
| 200 | uint8 b1 = src_argb[4] >> 3; |
| 201 | uint8 g1 = src_argb[5] >> 2; |
| 202 | uint8 r1 = src_argb[6] >> 3; |
| 203 | WRITEWORD(dst_rgb, b0 | (g0 << 5) | (r0 << 11) | |
| 204 | (b1 << 16) | (g1 << 21) | (r1 << 27)); |
| 205 | dst_rgb += 4; |
| 206 | src_argb += 8; |
| 207 | } |
| 208 | if (width & 1) { |
| 209 | uint8 b0 = src_argb[0] >> 3; |
| 210 | uint8 g0 = src_argb[1] >> 2; |
| 211 | uint8 r0 = src_argb[2] >> 3; |
| 212 | *(uint16*)(dst_rgb) = b0 | (g0 << 5) | (r0 << 11); |
| 213 | } |
| 214 | } |
| 215 |
| 216 | // dither4 is a row of 4 values from 4x4 dither matrix. |
| 217 | // The 4x4 matrix contains values to increase RGB. When converting to |
| 218 | // fewer bits (565) this provides an ordered dither. |
| 219 | // The order in the 4x4 matrix in first byte is upper left. |
| 220 | // The 4 values are passed as an int, then referenced as an array, so |
| 221 | // endian will not affect order of the original matrix. But the dither4 |
| 222 | // will containing the first pixel in the lower byte for little endian |
| 223 | // or the upper byte for big endian. |
| 224 | void ARGBToRGB565DitherRow_C(const uint8* src_argb, uint8* dst_rgb, |
| 225 | const uint32 dither4, int width) { |
| 226 | int x; |
| 227 | for (x = 0; x < width - 1; x += 2) { |
| 228 | int dither0 = ((const unsigned char*)(&dither4))[x & 3]; |
| 229 | int dither1 = ((const unsigned char*)(&dither4))[(x + 1) & 3]; |
| 230 | uint8 b0 = clamp255(src_argb[0] + dither0) >> 3; |
| 231 | uint8 g0 = clamp255(src_argb[1] + dither0) >> 2; |
| 232 | uint8 r0 = clamp255(src_argb[2] + dither0) >> 3; |
| 233 | uint8 b1 = clamp255(src_argb[4] + dither1) >> 3; |
| 234 | uint8 g1 = clamp255(src_argb[5] + dither1) >> 2; |
| 235 | uint8 r1 = clamp255(src_argb[6] + dither1) >> 3; |
| 236 | WRITEWORD(dst_rgb, b0 | (g0 << 5) | (r0 << 11) | |
| 237 | (b1 << 16) | (g1 << 21) | (r1 << 27)); |
| 238 | dst_rgb += 4; |
| 239 | src_argb += 8; |
| 240 | } |
| 241 | if (width & 1) { |
| 242 | int dither0 = ((const unsigned char*)(&dither4))[(width - 1) & 3]; |
| 243 | uint8 b0 = clamp255(src_argb[0] + dither0) >> 3; |
| 244 | uint8 g0 = clamp255(src_argb[1] + dither0) >> 2; |
| 245 | uint8 r0 = clamp255(src_argb[2] + dither0) >> 3; |
| 246 | *(uint16*)(dst_rgb) = b0 | (g0 << 5) | (r0 << 11); |
| 247 | } |
| 248 | } |
| 249 |
| 250 | void ARGBToARGB1555Row_C(const uint8* src_argb, uint8* dst_rgb, int width) { |
| 251 | int x; |
| 252 | for (x = 0; x < width - 1; x += 2) { |
| 253 | uint8 b0 = src_argb[0] >> 3; |
| 254 | uint8 g0 = src_argb[1] >> 3; |
| 255 | uint8 r0 = src_argb[2] >> 3; |
| 256 | uint8 a0 = src_argb[3] >> 7; |
| 257 | uint8 b1 = src_argb[4] >> 3; |
| 258 | uint8 g1 = src_argb[5] >> 3; |
| 259 | uint8 r1 = src_argb[6] >> 3; |
| 260 | uint8 a1 = src_argb[7] >> 7; |
| 261 | *(uint32*)(dst_rgb) = |
| 262 | b0 | (g0 << 5) | (r0 << 10) | (a0 << 15) | |
| 263 | (b1 << 16) | (g1 << 21) | (r1 << 26) | (a1 << 31); |
| 264 | dst_rgb += 4; |
| 265 | src_argb += 8; |
| 266 | } |
| 267 | if (width & 1) { |
| 268 | uint8 b0 = src_argb[0] >> 3; |
| 269 | uint8 g0 = src_argb[1] >> 3; |
| 270 | uint8 r0 = src_argb[2] >> 3; |
| 271 | uint8 a0 = src_argb[3] >> 7; |
| 272 | *(uint16*)(dst_rgb) = |
| 273 | b0 | (g0 << 5) | (r0 << 10) | (a0 << 15); |
| 274 | } |
| 275 | } |
| 276 |
| 277 | void ARGBToARGB4444Row_C(const uint8* src_argb, uint8* dst_rgb, int width) { |
| 278 | int x; |
| 279 | for (x = 0; x < width - 1; x += 2) { |
| 280 | uint8 b0 = src_argb[0] >> 4; |
| 281 | uint8 g0 = src_argb[1] >> 4; |
| 282 | uint8 r0 = src_argb[2] >> 4; |
| 283 | uint8 a0 = src_argb[3] >> 4; |
| 284 | uint8 b1 = src_argb[4] >> 4; |
| 285 | uint8 g1 = src_argb[5] >> 4; |
| 286 | uint8 r1 = src_argb[6] >> 4; |
| 287 | uint8 a1 = src_argb[7] >> 4; |
| 288 | *(uint32*)(dst_rgb) = |
| 289 | b0 | (g0 << 4) | (r0 << 8) | (a0 << 12) | |
| 290 | (b1 << 16) | (g1 << 20) | (r1 << 24) | (a1 << 28); |
| 291 | dst_rgb += 4; |
| 292 | src_argb += 8; |
| 293 | } |
| 294 | if (width & 1) { |
| 295 | uint8 b0 = src_argb[0] >> 4; |
| 296 | uint8 g0 = src_argb[1] >> 4; |
| 297 | uint8 r0 = src_argb[2] >> 4; |
| 298 | uint8 a0 = src_argb[3] >> 4; |
| 299 | *(uint16*)(dst_rgb) = |
| 300 | b0 | (g0 << 4) | (r0 << 8) | (a0 << 12); |
| 301 | } |
| 302 | } |
| 303 |
| 304 | static __inline int RGBToY(uint8 r, uint8 g, uint8 b) { |
| 305 | return (66 * r + 129 * g + 25 * b + 0x1080) >> 8; |
| 306 | } |
| 307 |
| 308 | static __inline int RGBToU(uint8 r, uint8 g, uint8 b) { |
| 309 | return (112 * b - 74 * g - 38 * r + 0x8080) >> 8; |
| 310 | } |
| 311 | static __inline int RGBToV(uint8 r, uint8 g, uint8 b) { |
| 312 | return (112 * r - 94 * g - 18 * b + 0x8080) >> 8; |
| 313 | } |
| 314 |
| 315 | #define MAKEROWY(NAME, R, G, B, BPP) \ |
| 316 | void NAME ## ToYRow_C(const uint8* src_argb0, uint8* dst_y, int width) { \ |
| 317 | int x; \ |
| 318 | for (x = 0; x < width; ++x) { \ |
| 319 | dst_y[0] = RGBToY(src_argb0[R], src_argb0[G], src_argb0[B]); \ |
| 320 | src_argb0 += BPP; \ |
| 321 | dst_y += 1; \ |
| 322 | } \ |
| 323 | } \ |
| 324 | void NAME ## ToUVRow_C(const uint8* src_rgb0, int src_stride_rgb, \ |
| 325 | uint8* dst_u, uint8* dst_v, int width) { \ |
| 326 | const uint8* src_rgb1 = src_rgb0 + src_stride_rgb; \ |
| 327 | int x; \ |
| 328 | for (x = 0; x < width - 1; x += 2) { \ |
| 329 | uint8 ab = (src_rgb0[B] + src_rgb0[B + BPP] + \ |
| 330 | src_rgb1[B] + src_rgb1[B + BPP]) >> 2; \ |
| 331 | uint8 ag = (src_rgb0[G] + src_rgb0[G + BPP] + \ |
| 332 | src_rgb1[G] + src_rgb1[G + BPP]) >> 2; \ |
| 333 | uint8 ar = (src_rgb0[R] + src_rgb0[R + BPP] + \ |
| 334 | src_rgb1[R] + src_rgb1[R + BPP]) >> 2; \ |
| 335 | dst_u[0] = RGBToU(ar, ag, ab); \ |
| 336 | dst_v[0] = RGBToV(ar, ag, ab); \ |
| 337 | src_rgb0 += BPP * 2; \ |
| 338 | src_rgb1 += BPP * 2; \ |
| 339 | dst_u += 1; \ |
| 340 | dst_v += 1; \ |
| 341 | } \ |
| 342 | if (width & 1) { \ |
| 343 | uint8 ab = (src_rgb0[B] + src_rgb1[B]) >> 1; \ |
| 344 | uint8 ag = (src_rgb0[G] + src_rgb1[G]) >> 1; \ |
| 345 | uint8 ar = (src_rgb0[R] + src_rgb1[R]) >> 1; \ |
| 346 | dst_u[0] = RGBToU(ar, ag, ab); \ |
| 347 | dst_v[0] = RGBToV(ar, ag, ab); \ |
| 348 | } \ |
| 349 | } |
| 350 |
| 351 | MAKEROWY(ARGB, 2, 1, 0, 4) |
| 352 | MAKEROWY(BGRA, 1, 2, 3, 4) |
| 353 | MAKEROWY(ABGR, 0, 1, 2, 4) |
| 354 | MAKEROWY(RGBA, 3, 2, 1, 4) |
| 355 | MAKEROWY(RGB24, 2, 1, 0, 3) |
| 356 | MAKEROWY(RAW, 0, 1, 2, 3) |
| 357 | #undef MAKEROWY |
| 358 |
| 359 | // JPeg uses a variation on BT.601-1 full range |
| 360 | // y = 0.29900 * r + 0.58700 * g + 0.11400 * b |
| 361 | // u = -0.16874 * r - 0.33126 * g + 0.50000 * b + center |
| 362 | // v = 0.50000 * r - 0.41869 * g - 0.08131 * b + center |
| 363 | // BT.601 Mpeg range uses: |
| 364 | // b 0.1016 * 255 = 25.908 = 25 |
| 365 | // g 0.5078 * 255 = 129.489 = 129 |
| 366 | // r 0.2578 * 255 = 65.739 = 66 |
| 367 | // JPeg 8 bit Y (not used): |
| 368 | // b 0.11400 * 256 = 29.184 = 29 |
| 369 | // g 0.58700 * 256 = 150.272 = 150 |
| 370 | // r 0.29900 * 256 = 76.544 = 77 |
| 371 | // JPeg 7 bit Y: |
| 372 | // b 0.11400 * 128 = 14.592 = 15 |
| 373 | // g 0.58700 * 128 = 75.136 = 75 |
| 374 | // r 0.29900 * 128 = 38.272 = 38 |
| 375 | // JPeg 8 bit U: |
| 376 | // b 0.50000 * 255 = 127.5 = 127 |
| 377 | // g -0.33126 * 255 = -84.4713 = -84 |
| 378 | // r -0.16874 * 255 = -43.0287 = -43 |
| 379 | // JPeg 8 bit V: |
| 380 | // b -0.08131 * 255 = -20.73405 = -20 |
| 381 | // g -0.41869 * 255 = -106.76595 = -107 |
| 382 | // r 0.50000 * 255 = 127.5 = 127 |
| 383 |
| 384 | static __inline int RGBToYJ(uint8 r, uint8 g, uint8 b) { |
| 385 | return (38 * r + 75 * g + 15 * b + 64) >> 7; |
| 386 | } |
| 387 |
| 388 | static __inline int RGBToUJ(uint8 r, uint8 g, uint8 b) { |
| 389 | return (127 * b - 84 * g - 43 * r + 0x8080) >> 8; |
| 390 | } |
| 391 | static __inline int RGBToVJ(uint8 r, uint8 g, uint8 b) { |
| 392 | return (127 * r - 107 * g - 20 * b + 0x8080) >> 8; |
| 393 | } |
| 394 |
| 395 | #define AVGB(a, b) (((a) + (b) + 1) >> 1) |
| 396 |
| 397 | #define MAKEROWYJ(NAME, R, G, B, BPP) \ |
| 398 | void NAME ## ToYJRow_C(const uint8* src_argb0, uint8* dst_y, int width) { \ |
| 399 | int x; \ |
| 400 | for (x = 0; x < width; ++x) { \ |
| 401 | dst_y[0] = RGBToYJ(src_argb0[R], src_argb0[G], src_argb0[B]); \ |
| 402 | src_argb0 += BPP; \ |
| 403 | dst_y += 1; \ |
| 404 | } \ |
| 405 | } \ |
| 406 | void NAME ## ToUVJRow_C(const uint8* src_rgb0, int src_stride_rgb, \ |
| 407 | uint8* dst_u, uint8* dst_v, int width) { \ |
| 408 | const uint8* src_rgb1 = src_rgb0 + src_stride_rgb; \ |
| 409 | int x; \ |
| 410 | for (x = 0; x < width - 1; x += 2) { \ |
| 411 | uint8 ab = AVGB(AVGB(src_rgb0[B], src_rgb1[B]), \ |
| 412 | AVGB(src_rgb0[B + BPP], src_rgb1[B + BPP])); \ |
| 413 | uint8 ag = AVGB(AVGB(src_rgb0[G], src_rgb1[G]), \ |
| 414 | AVGB(src_rgb0[G + BPP], src_rgb1[G + BPP])); \ |
| 415 | uint8 ar = AVGB(AVGB(src_rgb0[R], src_rgb1[R]), \ |
| 416 | AVGB(src_rgb0[R + BPP], src_rgb1[R + BPP])); \ |
| 417 | dst_u[0] = RGBToUJ(ar, ag, ab); \ |
| 418 | dst_v[0] = RGBToVJ(ar, ag, ab); \ |
| 419 | src_rgb0 += BPP * 2; \ |
| 420 | src_rgb1 += BPP * 2; \ |
| 421 | dst_u += 1; \ |
| 422 | dst_v += 1; \ |
| 423 | } \ |
| 424 | if (width & 1) { \ |
| 425 | uint8 ab = AVGB(src_rgb0[B], src_rgb1[B]); \ |
| 426 | uint8 ag = AVGB(src_rgb0[G], src_rgb1[G]); \ |
| 427 | uint8 ar = AVGB(src_rgb0[R], src_rgb1[R]); \ |
| 428 | dst_u[0] = RGBToUJ(ar, ag, ab); \ |
| 429 | dst_v[0] = RGBToVJ(ar, ag, ab); \ |
| 430 | } \ |
| 431 | } |
| 432 |
| 433 | MAKEROWYJ(ARGB, 2, 1, 0, 4) |
| 434 | #undef MAKEROWYJ |
| 435 |
| 436 | void ARGBToUVJ422Row_C(const uint8* src_argb, |
| 437 | uint8* dst_u, uint8* dst_v, int width) { |
| 438 | int x; |
| 439 | for (x = 0; x < width - 1; x += 2) { |
| 440 | uint8 ab = (src_argb[0] + src_argb[4]) >> 1; |
| 441 | uint8 ag = (src_argb[1] + src_argb[5]) >> 1; |
| 442 | uint8 ar = (src_argb[2] + src_argb[6]) >> 1; |
| 443 | dst_u[0] = RGBToUJ(ar, ag, ab); |
| 444 | dst_v[0] = RGBToVJ(ar, ag, ab); |
| 445 | src_argb += 8; |
| 446 | dst_u += 1; |
| 447 | dst_v += 1; |
| 448 | } |
| 449 | if (width & 1) { |
| 450 | uint8 ab = src_argb[0]; |
| 451 | uint8 ag = src_argb[1]; |
| 452 | uint8 ar = src_argb[2]; |
| 453 | dst_u[0] = RGBToUJ(ar, ag, ab); |
| 454 | dst_v[0] = RGBToVJ(ar, ag, ab); |
| 455 | } |
| 456 | } |
| 457 |
| 458 | void RGB565ToYRow_C(const uint8* src_rgb565, uint8* dst_y, int width) { |
| 459 | int x; |
| 460 | for (x = 0; x < width; ++x) { |
| 461 | uint8 b = src_rgb565[0] & 0x1f; |
| 462 | uint8 g = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); |
| 463 | uint8 r = src_rgb565[1] >> 3; |
| 464 | b = (b << 3) | (b >> 2); |
| 465 | g = (g << 2) | (g >> 4); |
| 466 | r = (r << 3) | (r >> 2); |
| 467 | dst_y[0] = RGBToY(r, g, b); |
| 468 | src_rgb565 += 2; |
| 469 | dst_y += 1; |
| 470 | } |
| 471 | } |
| 472 |
| 473 | void ARGB1555ToYRow_C(const uint8* src_argb1555, uint8* dst_y, int width) { |
| 474 | int x; |
| 475 | for (x = 0; x < width; ++x) { |
| 476 | uint8 b = src_argb1555[0] & 0x1f; |
| 477 | uint8 g = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); |
| 478 | uint8 r = (src_argb1555[1] & 0x7c) >> 2; |
| 479 | b = (b << 3) | (b >> 2); |
| 480 | g = (g << 3) | (g >> 2); |
| 481 | r = (r << 3) | (r >> 2); |
| 482 | dst_y[0] = RGBToY(r, g, b); |
| 483 | src_argb1555 += 2; |
| 484 | dst_y += 1; |
| 485 | } |
| 486 | } |
| 487 |
| 488 | void ARGB4444ToYRow_C(const uint8* src_argb4444, uint8* dst_y, int width) { |
| 489 | int x; |
| 490 | for (x = 0; x < width; ++x) { |
| 491 | uint8 b = src_argb4444[0] & 0x0f; |
| 492 | uint8 g = src_argb4444[0] >> 4; |
| 493 | uint8 r = src_argb4444[1] & 0x0f; |
| 494 | b = (b << 4) | b; |
| 495 | g = (g << 4) | g; |
| 496 | r = (r << 4) | r; |
| 497 | dst_y[0] = RGBToY(r, g, b); |
| 498 | src_argb4444 += 2; |
| 499 | dst_y += 1; |
| 500 | } |
| 501 | } |
| 502 |
| 503 | void RGB565ToUVRow_C(const uint8* src_rgb565, int src_stride_rgb565, |
| 504 | uint8* dst_u, uint8* dst_v, int width) { |
| 505 | const uint8* next_rgb565 = src_rgb565 + src_stride_rgb565; |
| 506 | int x; |
| 507 | for (x = 0; x < width - 1; x += 2) { |
| 508 | uint8 b0 = src_rgb565[0] & 0x1f; |
| 509 | uint8 g0 = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); |
| 510 | uint8 r0 = src_rgb565[1] >> 3; |
| 511 | uint8 b1 = src_rgb565[2] & 0x1f; |
| 512 | uint8 g1 = (src_rgb565[2] >> 5) | ((src_rgb565[3] & 0x07) << 3); |
| 513 | uint8 r1 = src_rgb565[3] >> 3; |
| 514 | uint8 b2 = next_rgb565[0] & 0x1f; |
| 515 | uint8 g2 = (next_rgb565[0] >> 5) | ((next_rgb565[1] & 0x07) << 3); |
| 516 | uint8 r2 = next_rgb565[1] >> 3; |
| 517 | uint8 b3 = next_rgb565[2] & 0x1f; |
| 518 | uint8 g3 = (next_rgb565[2] >> 5) | ((next_rgb565[3] & 0x07) << 3); |
| 519 | uint8 r3 = next_rgb565[3] >> 3; |
| 520 | uint8 b = (b0 + b1 + b2 + b3); // 565 * 4 = 787. |
| 521 | uint8 g = (g0 + g1 + g2 + g3); |
| 522 | uint8 r = (r0 + r1 + r2 + r3); |
| 523 | b = (b << 1) | (b >> 6); // 787 -> 888. |
| 524 | r = (r << 1) | (r >> 6); |
| 525 | dst_u[0] = RGBToU(r, g, b); |
| 526 | dst_v[0] = RGBToV(r, g, b); |
| 527 | src_rgb565 += 4; |
| 528 | next_rgb565 += 4; |
| 529 | dst_u += 1; |
| 530 | dst_v += 1; |
| 531 | } |
| 532 | if (width & 1) { |
| 533 | uint8 b0 = src_rgb565[0] & 0x1f; |
| 534 | uint8 g0 = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); |
| 535 | uint8 r0 = src_rgb565[1] >> 3; |
| 536 | uint8 b2 = next_rgb565[0] & 0x1f; |
| 537 | uint8 g2 = (next_rgb565[0] >> 5) | ((next_rgb565[1] & 0x07) << 3); |
| 538 | uint8 r2 = next_rgb565[1] >> 3; |
| 539 | uint8 b = (b0 + b2); // 565 * 2 = 676. |
| 540 | uint8 g = (g0 + g2); |
| 541 | uint8 r = (r0 + r2); |
| 542 | b = (b << 2) | (b >> 4); // 676 -> 888 |
| 543 | g = (g << 1) | (g >> 6); |
| 544 | r = (r << 2) | (r >> 4); |
| 545 | dst_u[0] = RGBToU(r, g, b); |
| 546 | dst_v[0] = RGBToV(r, g, b); |
| 547 | } |
| 548 | } |
| 549 |
| 550 | void ARGB1555ToUVRow_C(const uint8* src_argb1555, int src_stride_argb1555, |
| 551 | uint8* dst_u, uint8* dst_v, int width) { |
| 552 | const uint8* next_argb1555 = src_argb1555 + src_stride_argb1555; |
| 553 | int x; |
| 554 | for (x = 0; x < width - 1; x += 2) { |
| 555 | uint8 b0 = src_argb1555[0] & 0x1f; |
| 556 | uint8 g0 = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); |
| 557 | uint8 r0 = (src_argb1555[1] & 0x7c) >> 2; |
| 558 | uint8 b1 = src_argb1555[2] & 0x1f; |
| 559 | uint8 g1 = (src_argb1555[2] >> 5) | ((src_argb1555[3] & 0x03) << 3); |
| 560 | uint8 r1 = (src_argb1555[3] & 0x7c) >> 2; |
| 561 | uint8 b2 = next_argb1555[0] & 0x1f; |
| 562 | uint8 g2 = (next_argb1555[0] >> 5) | ((next_argb1555[1] & 0x03) << 3); |
| 563 | uint8 r2 = (next_argb1555[1] & 0x7c) >> 2; |
| 564 | uint8 b3 = next_argb1555[2] & 0x1f; |
| 565 | uint8 g3 = (next_argb1555[2] >> 5) | ((next_argb1555[3] & 0x03) << 3); |
| 566 | uint8 r3 = (next_argb1555[3] & 0x7c) >> 2; |
| 567 | uint8 b = (b0 + b1 + b2 + b3); // 555 * 4 = 777. |
| 568 | uint8 g = (g0 + g1 + g2 + g3); |
| 569 | uint8 r = (r0 + r1 + r2 + r3); |
| 570 | b = (b << 1) | (b >> 6); // 777 -> 888. |
| 571 | g = (g << 1) | (g >> 6); |
| 572 | r = (r << 1) | (r >> 6); |
| 573 | dst_u[0] = RGBToU(r, g, b); |
| 574 | dst_v[0] = RGBToV(r, g, b); |
| 575 | src_argb1555 += 4; |
| 576 | next_argb1555 += 4; |
| 577 | dst_u += 1; |
| 578 | dst_v += 1; |
| 579 | } |
| 580 | if (width & 1) { |
| 581 | uint8 b0 = src_argb1555[0] & 0x1f; |
| 582 | uint8 g0 = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); |
| 583 | uint8 r0 = (src_argb1555[1] & 0x7c) >> 2; |
| 584 | uint8 b2 = next_argb1555[0] & 0x1f; |
| 585 | uint8 g2 = (next_argb1555[0] >> 5) | ((next_argb1555[1] & 0x03) << 3); |
| 586 | uint8 r2 = next_argb1555[1] >> 3; |
| 587 | uint8 b = (b0 + b2); // 555 * 2 = 666. |
| 588 | uint8 g = (g0 + g2); |
| 589 | uint8 r = (r0 + r2); |
| 590 | b = (b << 2) | (b >> 4); // 666 -> 888. |
| 591 | g = (g << 2) | (g >> 4); |
| 592 | r = (r << 2) | (r >> 4); |
| 593 | dst_u[0] = RGBToU(r, g, b); |
| 594 | dst_v[0] = RGBToV(r, g, b); |
| 595 | } |
| 596 | } |
| 597 |
| 598 | void ARGB4444ToUVRow_C(const uint8* src_argb4444, int src_stride_argb4444, |
| 599 | uint8* dst_u, uint8* dst_v, int width) { |
| 600 | const uint8* next_argb4444 = src_argb4444 + src_stride_argb4444; |
| 601 | int x; |
| 602 | for (x = 0; x < width - 1; x += 2) { |
| 603 | uint8 b0 = src_argb4444[0] & 0x0f; |
| 604 | uint8 g0 = src_argb4444[0] >> 4; |
| 605 | uint8 r0 = src_argb4444[1] & 0x0f; |
| 606 | uint8 b1 = src_argb4444[2] & 0x0f; |
| 607 | uint8 g1 = src_argb4444[2] >> 4; |
| 608 | uint8 r1 = src_argb4444[3] & 0x0f; |
| 609 | uint8 b2 = next_argb4444[0] & 0x0f; |
| 610 | uint8 g2 = next_argb4444[0] >> 4; |
| 611 | uint8 r2 = next_argb4444[1] & 0x0f; |
| 612 | uint8 b3 = next_argb4444[2] & 0x0f; |
| 613 | uint8 g3 = next_argb4444[2] >> 4; |
| 614 | uint8 r3 = next_argb4444[3] & 0x0f; |
| 615 | uint8 b = (b0 + b1 + b2 + b3); // 444 * 4 = 666. |
| 616 | uint8 g = (g0 + g1 + g2 + g3); |
| 617 | uint8 r = (r0 + r1 + r2 + r3); |
| 618 | b = (b << 2) | (b >> 4); // 666 -> 888. |
| 619 | g = (g << 2) | (g >> 4); |
| 620 | r = (r << 2) | (r >> 4); |
| 621 | dst_u[0] = RGBToU(r, g, b); |
| 622 | dst_v[0] = RGBToV(r, g, b); |
| 623 | src_argb4444 += 4; |
| 624 | next_argb4444 += 4; |
| 625 | dst_u += 1; |
| 626 | dst_v += 1; |
| 627 | } |
| 628 | if (width & 1) { |
| 629 | uint8 b0 = src_argb4444[0] & 0x0f; |
| 630 | uint8 g0 = src_argb4444[0] >> 4; |
| 631 | uint8 r0 = src_argb4444[1] & 0x0f; |
| 632 | uint8 b2 = next_argb4444[0] & 0x0f; |
| 633 | uint8 g2 = next_argb4444[0] >> 4; |
| 634 | uint8 r2 = next_argb4444[1] & 0x0f; |
| 635 | uint8 b = (b0 + b2); // 444 * 2 = 555. |
| 636 | uint8 g = (g0 + g2); |
| 637 | uint8 r = (r0 + r2); |
| 638 | b = (b << 3) | (b >> 2); // 555 -> 888. |
| 639 | g = (g << 3) | (g >> 2); |
| 640 | r = (r << 3) | (r >> 2); |
| 641 | dst_u[0] = RGBToU(r, g, b); |
| 642 | dst_v[0] = RGBToV(r, g, b); |
| 643 | } |
| 644 | } |
| 645 |
| 646 | void ARGBToUV444Row_C(const uint8* src_argb, |
| 647 | uint8* dst_u, uint8* dst_v, int width) { |
| 648 | int x; |
| 649 | for (x = 0; x < width; ++x) { |
| 650 | uint8 ab = src_argb[0]; |
| 651 | uint8 ag = src_argb[1]; |
| 652 | uint8 ar = src_argb[2]; |
| 653 | dst_u[0] = RGBToU(ar, ag, ab); |
| 654 | dst_v[0] = RGBToV(ar, ag, ab); |
| 655 | src_argb += 4; |
| 656 | dst_u += 1; |
| 657 | dst_v += 1; |
| 658 | } |
| 659 | } |
| 660 |
| 661 | void ARGBToUV422Row_C(const uint8* src_argb, |
| 662 | uint8* dst_u, uint8* dst_v, int width) { |
| 663 | int x; |
| 664 | for (x = 0; x < width - 1; x += 2) { |
| 665 | uint8 ab = (src_argb[0] + src_argb[4]) >> 1; |
| 666 | uint8 ag = (src_argb[1] + src_argb[5]) >> 1; |
| 667 | uint8 ar = (src_argb[2] + src_argb[6]) >> 1; |
| 668 | dst_u[0] = RGBToU(ar, ag, ab); |
| 669 | dst_v[0] = RGBToV(ar, ag, ab); |
| 670 | src_argb += 8; |
| 671 | dst_u += 1; |
| 672 | dst_v += 1; |
| 673 | } |
| 674 | if (width & 1) { |
| 675 | uint8 ab = src_argb[0]; |
| 676 | uint8 ag = src_argb[1]; |
| 677 | uint8 ar = src_argb[2]; |
| 678 | dst_u[0] = RGBToU(ar, ag, ab); |
| 679 | dst_v[0] = RGBToV(ar, ag, ab); |
| 680 | } |
| 681 | } |
| 682 |
| 683 | void ARGBToUV411Row_C(const uint8* src_argb, |
| 684 | uint8* dst_u, uint8* dst_v, int width) { |
| 685 | int x; |
| 686 | for (x = 0; x < width - 3; x += 4) { |
| 687 | uint8 ab = (src_argb[0] + src_argb[4] + src_argb[8] + src_argb[12]) >> 2; |
| 688 | uint8 ag = (src_argb[1] + src_argb[5] + src_argb[9] + src_argb[13]) >> 2; |
| 689 | uint8 ar = (src_argb[2] + src_argb[6] + src_argb[10] + src_argb[14]) >> 2; |
| 690 | dst_u[0] = RGBToU(ar, ag, ab); |
| 691 | dst_v[0] = RGBToV(ar, ag, ab); |
| 692 | src_argb += 16; |
| 693 | dst_u += 1; |
| 694 | dst_v += 1; |
| 695 | } |
| 696 | // Odd width handling mimics 'any' function which replicates last pixel. |
| 697 | if ((width & 3) == 3) { |
| 698 | uint8 ab = (src_argb[0] + src_argb[4] + src_argb[8] + src_argb[8]) >> 2; |
| 699 | uint8 ag = (src_argb[1] + src_argb[5] + src_argb[9] + src_argb[9]) >> 2; |
| 700 | uint8 ar = (src_argb[2] + src_argb[6] + src_argb[10] + src_argb[10]) >> 2; |
| 701 | dst_u[0] = RGBToU(ar, ag, ab); |
| 702 | dst_v[0] = RGBToV(ar, ag, ab); |
| 703 | } else if ((width & 3) == 2) { |
| 704 | uint8 ab = (src_argb[0] + src_argb[4]) >> 1; |
| 705 | uint8 ag = (src_argb[1] + src_argb[5]) >> 1; |
| 706 | uint8 ar = (src_argb[2] + src_argb[6]) >> 1; |
| 707 | dst_u[0] = RGBToU(ar, ag, ab); |
| 708 | dst_v[0] = RGBToV(ar, ag, ab); |
| 709 | } else if ((width & 3) == 1) { |
| 710 | uint8 ab = src_argb[0]; |
| 711 | uint8 ag = src_argb[1]; |
| 712 | uint8 ar = src_argb[2]; |
| 713 | dst_u[0] = RGBToU(ar, ag, ab); |
| 714 | dst_v[0] = RGBToV(ar, ag, ab); |
| 715 | } |
| 716 | } |
| 717 |
| 718 | void ARGBGrayRow_C(const uint8* src_argb, uint8* dst_argb, int width) { |
| 719 | int x; |
| 720 | for (x = 0; x < width; ++x) { |
| 721 | uint8 y = RGBToYJ(src_argb[2], src_argb[1], src_argb[0]); |
| 722 | dst_argb[2] = dst_argb[1] = dst_argb[0] = y; |
| 723 | dst_argb[3] = src_argb[3]; |
| 724 | dst_argb += 4; |
| 725 | src_argb += 4; |
| 726 | } |
| 727 | } |
| 728 |
| 729 | // Convert a row of image to Sepia tone. |
| 730 | void ARGBSepiaRow_C(uint8* dst_argb, int width) { |
| 731 | int x; |
| 732 | for (x = 0; x < width; ++x) { |
| 733 | int b = dst_argb[0]; |
| 734 | int g = dst_argb[1]; |
| 735 | int r = dst_argb[2]; |
| 736 | int sb = (b * 17 + g * 68 + r * 35) >> 7; |
| 737 | int sg = (b * 22 + g * 88 + r * 45) >> 7; |
| 738 | int sr = (b * 24 + g * 98 + r * 50) >> 7; |
| 739 | // b does not over flow. a is preserved from original. |
| 740 | dst_argb[0] = sb; |
| 741 | dst_argb[1] = clamp255(sg); |
| 742 | dst_argb[2] = clamp255(sr); |
| 743 | dst_argb += 4; |
| 744 | } |
| 745 | } |
| 746 |
| 747 | // Apply color matrix to a row of image. Matrix is signed. |
| 748 | // TODO(fbarchard): Consider adding rounding (+32). |
| 749 | void ARGBColorMatrixRow_C(const uint8* src_argb, uint8* dst_argb, |
| 750 | const int8* matrix_argb, int width) { |
| 751 | int x; |
| 752 | for (x = 0; x < width; ++x) { |
| 753 | int b = src_argb[0]; |
| 754 | int g = src_argb[1]; |
| 755 | int r = src_argb[2]; |
| 756 | int a = src_argb[3]; |
| 757 | int sb = (b * matrix_argb[0] + g * matrix_argb[1] + |
| 758 | r * matrix_argb[2] + a * matrix_argb[3]) >> 6; |
| 759 | int sg = (b * matrix_argb[4] + g * matrix_argb[5] + |
| 760 | r * matrix_argb[6] + a * matrix_argb[7]) >> 6; |
| 761 | int sr = (b * matrix_argb[8] + g * matrix_argb[9] + |
| 762 | r * matrix_argb[10] + a * matrix_argb[11]) >> 6; |
| 763 | int sa = (b * matrix_argb[12] + g * matrix_argb[13] + |
| 764 | r * matrix_argb[14] + a * matrix_argb[15]) >> 6; |
| 765 | dst_argb[0] = Clamp(sb); |
| 766 | dst_argb[1] = Clamp(sg); |
| 767 | dst_argb[2] = Clamp(sr); |
| 768 | dst_argb[3] = Clamp(sa); |
| 769 | src_argb += 4; |
| 770 | dst_argb += 4; |
| 771 | } |
| 772 | } |
| 773 |
| 774 | // Apply color table to a row of image. |
| 775 | void ARGBColorTableRow_C(uint8* dst_argb, const uint8* table_argb, int width) { |
| 776 | int x; |
| 777 | for (x = 0; x < width; ++x) { |
| 778 | int b = dst_argb[0]; |
| 779 | int g = dst_argb[1]; |
| 780 | int r = dst_argb[2]; |
| 781 | int a = dst_argb[3]; |
| 782 | dst_argb[0] = table_argb[b * 4 + 0]; |
| 783 | dst_argb[1] = table_argb[g * 4 + 1]; |
| 784 | dst_argb[2] = table_argb[r * 4 + 2]; |
| 785 | dst_argb[3] = table_argb[a * 4 + 3]; |
| 786 | dst_argb += 4; |
| 787 | } |
| 788 | } |
| 789 |
| 790 | // Apply color table to a row of image. |
| 791 | void RGBColorTableRow_C(uint8* dst_argb, const uint8* table_argb, int width) { |
| 792 | int x; |
| 793 | for (x = 0; x < width; ++x) { |
| 794 | int b = dst_argb[0]; |
| 795 | int g = dst_argb[1]; |
| 796 | int r = dst_argb[2]; |
| 797 | dst_argb[0] = table_argb[b * 4 + 0]; |
| 798 | dst_argb[1] = table_argb[g * 4 + 1]; |
| 799 | dst_argb[2] = table_argb[r * 4 + 2]; |
| 800 | dst_argb += 4; |
| 801 | } |
| 802 | } |
| 803 |
| 804 | void ARGBQuantizeRow_C(uint8* dst_argb, int scale, int interval_size, |
| 805 | int interval_offset, int width) { |
| 806 | int x; |
| 807 | for (x = 0; x < width; ++x) { |
| 808 | int b = dst_argb[0]; |
| 809 | int g = dst_argb[1]; |
| 810 | int r = dst_argb[2]; |
| 811 | dst_argb[0] = (b * scale >> 16) * interval_size + interval_offset; |
| 812 | dst_argb[1] = (g * scale >> 16) * interval_size + interval_offset; |
| 813 | dst_argb[2] = (r * scale >> 16) * interval_size + interval_offset; |
| 814 | dst_argb += 4; |
| 815 | } |
| 816 | } |
| 817 |
| 818 | #define REPEAT8(v) (v) | ((v) << 8) |
| 819 | #define SHADE(f, v) v * f >> 24 |
| 820 |
| 821 | void ARGBShadeRow_C(const uint8* src_argb, uint8* dst_argb, int width, |
| 822 | uint32 value) { |
| 823 | const uint32 b_scale = REPEAT8(value & 0xff); |
| 824 | const uint32 g_scale = REPEAT8((value >> 8) & 0xff); |
| 825 | const uint32 r_scale = REPEAT8((value >> 16) & 0xff); |
| 826 | const uint32 a_scale = REPEAT8(value >> 24); |
| 827 |
| 828 | int i; |
| 829 | for (i = 0; i < width; ++i) { |
| 830 | const uint32 b = REPEAT8(src_argb[0]); |
| 831 | const uint32 g = REPEAT8(src_argb[1]); |
| 832 | const uint32 r = REPEAT8(src_argb[2]); |
| 833 | const uint32 a = REPEAT8(src_argb[3]); |
| 834 | dst_argb[0] = SHADE(b, b_scale); |
| 835 | dst_argb[1] = SHADE(g, g_scale); |
| 836 | dst_argb[2] = SHADE(r, r_scale); |
| 837 | dst_argb[3] = SHADE(a, a_scale); |
| 838 | src_argb += 4; |
| 839 | dst_argb += 4; |
| 840 | } |
| 841 | } |
| 842 | #undef REPEAT8 |
| 843 | #undef SHADE |
| 844 |
| 845 | #define REPEAT8(v) (v) | ((v) << 8) |
| 846 | #define SHADE(f, v) v * f >> 16 |
| 847 |
| 848 | void ARGBMultiplyRow_C(const uint8* src_argb0, const uint8* src_argb1, |
| 849 | uint8* dst_argb, int width) { |
| 850 | int i; |
| 851 | for (i = 0; i < width; ++i) { |
| 852 | const uint32 b = REPEAT8(src_argb0[0]); |
| 853 | const uint32 g = REPEAT8(src_argb0[1]); |
| 854 | const uint32 r = REPEAT8(src_argb0[2]); |
| 855 | const uint32 a = REPEAT8(src_argb0[3]); |
| 856 | const uint32 b_scale = src_argb1[0]; |
| 857 | const uint32 g_scale = src_argb1[1]; |
| 858 | const uint32 r_scale = src_argb1[2]; |
| 859 | const uint32 a_scale = src_argb1[3]; |
| 860 | dst_argb[0] = SHADE(b, b_scale); |
| 861 | dst_argb[1] = SHADE(g, g_scale); |
| 862 | dst_argb[2] = SHADE(r, r_scale); |
| 863 | dst_argb[3] = SHADE(a, a_scale); |
| 864 | src_argb0 += 4; |
| 865 | src_argb1 += 4; |
| 866 | dst_argb += 4; |
| 867 | } |
| 868 | } |
| 869 | #undef REPEAT8 |
| 870 | #undef SHADE |
| 871 |
| 872 | #define SHADE(f, v) clamp255(v + f) |
| 873 |
| 874 | void ARGBAddRow_C(const uint8* src_argb0, const uint8* src_argb1, |
| 875 | uint8* dst_argb, int width) { |
| 876 | int i; |
| 877 | for (i = 0; i < width; ++i) { |
| 878 | const int b = src_argb0[0]; |
| 879 | const int g = src_argb0[1]; |
| 880 | const int r = src_argb0[2]; |
| 881 | const int a = src_argb0[3]; |
| 882 | const int b_add = src_argb1[0]; |
| 883 | const int g_add = src_argb1[1]; |
| 884 | const int r_add = src_argb1[2]; |
| 885 | const int a_add = src_argb1[3]; |
| 886 | dst_argb[0] = SHADE(b, b_add); |
| 887 | dst_argb[1] = SHADE(g, g_add); |
| 888 | dst_argb[2] = SHADE(r, r_add); |
| 889 | dst_argb[3] = SHADE(a, a_add); |
| 890 | src_argb0 += 4; |
| 891 | src_argb1 += 4; |
| 892 | dst_argb += 4; |
| 893 | } |
| 894 | } |
| 895 | #undef SHADE |
| 896 |
| 897 | #define SHADE(f, v) clamp0(f - v) |
| 898 |
| 899 | void ARGBSubtractRow_C(const uint8* src_argb0, const uint8* src_argb1, |
| 900 | uint8* dst_argb, int width) { |
| 901 | int i; |
| 902 | for (i = 0; i < width; ++i) { |
| 903 | const int b = src_argb0[0]; |
| 904 | const int g = src_argb0[1]; |
| 905 | const int r = src_argb0[2]; |
| 906 | const int a = src_argb0[3]; |
| 907 | const int b_sub = src_argb1[0]; |
| 908 | const int g_sub = src_argb1[1]; |
| 909 | const int r_sub = src_argb1[2]; |
| 910 | const int a_sub = src_argb1[3]; |
| 911 | dst_argb[0] = SHADE(b, b_sub); |
| 912 | dst_argb[1] = SHADE(g, g_sub); |
| 913 | dst_argb[2] = SHADE(r, r_sub); |
| 914 | dst_argb[3] = SHADE(a, a_sub); |
| 915 | src_argb0 += 4; |
| 916 | src_argb1 += 4; |
| 917 | dst_argb += 4; |
| 918 | } |
| 919 | } |
| 920 | #undef SHADE |
| 921 |
| 922 | // Sobel functions which mimics SSSE3. |
| 923 | void SobelXRow_C(const uint8* src_y0, const uint8* src_y1, const uint8* src_y2, |
| 924 | uint8* dst_sobelx, int width) { |
| 925 | int i; |
| 926 | for (i = 0; i < width; ++i) { |
| 927 | int a = src_y0[i]; |
| 928 | int b = src_y1[i]; |
| 929 | int c = src_y2[i]; |
| 930 | int a_sub = src_y0[i + 2]; |
| 931 | int b_sub = src_y1[i + 2]; |
| 932 | int c_sub = src_y2[i + 2]; |
| 933 | int a_diff = a - a_sub; |
| 934 | int b_diff = b - b_sub; |
| 935 | int c_diff = c - c_sub; |
| 936 | int sobel = Abs(a_diff + b_diff * 2 + c_diff); |
| 937 | dst_sobelx[i] = (uint8)(clamp255(sobel)); |
| 938 | } |
| 939 | } |
| 940 |
| 941 | void SobelYRow_C(const uint8* src_y0, const uint8* src_y1, |
| 942 | uint8* dst_sobely, int width) { |
| 943 | int i; |
| 944 | for (i = 0; i < width; ++i) { |
| 945 | int a = src_y0[i + 0]; |
| 946 | int b = src_y0[i + 1]; |
| 947 | int c = src_y0[i + 2]; |
| 948 | int a_sub = src_y1[i + 0]; |
| 949 | int b_sub = src_y1[i + 1]; |
| 950 | int c_sub = src_y1[i + 2]; |
| 951 | int a_diff = a - a_sub; |
| 952 | int b_diff = b - b_sub; |
| 953 | int c_diff = c - c_sub; |
| 954 | int sobel = Abs(a_diff + b_diff * 2 + c_diff); |
| 955 | dst_sobely[i] = (uint8)(clamp255(sobel)); |
| 956 | } |
| 957 | } |
| 958 |
| 959 | void SobelRow_C(const uint8* src_sobelx, const uint8* src_sobely, |
| 960 | uint8* dst_argb, int width) { |
| 961 | int i; |
| 962 | for (i = 0; i < width; ++i) { |
| 963 | int r = src_sobelx[i]; |
| 964 | int b = src_sobely[i]; |
| 965 | int s = clamp255(r + b); |
| 966 | dst_argb[0] = (uint8)(s); |
| 967 | dst_argb[1] = (uint8)(s); |
| 968 | dst_argb[2] = (uint8)(s); |
| 969 | dst_argb[3] = (uint8)(255u); |
| 970 | dst_argb += 4; |
| 971 | } |
| 972 | } |
| 973 |
| 974 | void SobelToPlaneRow_C(const uint8* src_sobelx, const uint8* src_sobely, |
| 975 | uint8* dst_y, int width) { |
| 976 | int i; |
| 977 | for (i = 0; i < width; ++i) { |
| 978 | int r = src_sobelx[i]; |
| 979 | int b = src_sobely[i]; |
| 980 | int s = clamp255(r + b); |
| 981 | dst_y[i] = (uint8)(s); |
| 982 | } |
| 983 | } |
| 984 |
| 985 | void SobelXYRow_C(const uint8* src_sobelx, const uint8* src_sobely, |
| 986 | uint8* dst_argb, int width) { |
| 987 | int i; |
| 988 | for (i = 0; i < width; ++i) { |
| 989 | int r = src_sobelx[i]; |
| 990 | int b = src_sobely[i]; |
| 991 | int g = clamp255(r + b); |
| 992 | dst_argb[0] = (uint8)(b); |
| 993 | dst_argb[1] = (uint8)(g); |
| 994 | dst_argb[2] = (uint8)(r); |
| 995 | dst_argb[3] = (uint8)(255u); |
| 996 | dst_argb += 4; |
| 997 | } |
| 998 | } |
| 999 |
| 1000 | void J400ToARGBRow_C(const uint8* src_y, uint8* dst_argb, int width) { |
| 1001 | // Copy a Y to RGB. |
| 1002 | int x; |
| 1003 | for (x = 0; x < width; ++x) { |
| 1004 | uint8 y = src_y[0]; |
| 1005 | dst_argb[2] = dst_argb[1] = dst_argb[0] = y; |
| 1006 | dst_argb[3] = 255u; |
| 1007 | dst_argb += 4; |
| 1008 | ++src_y; |
| 1009 | } |
| 1010 | } |
| 1011 |
| 1012 | // TODO(fbarchard): Unify these structures to be platform independent. |
| 1013 | // TODO(fbarchard): Generate SIMD structures from float matrix. |
| 1014 |
| 1015 | // BT.601 YUV to RGB reference |
| 1016 | // R = (Y - 16) * 1.164 - V * -1.596 |
| 1017 | // G = (Y - 16) * 1.164 - U * 0.391 - V * 0.813 |
| 1018 | // B = (Y - 16) * 1.164 - U * -2.018 |
| 1019 |
| 1020 | // Y contribution to R,G,B. Scale and bias. |
| 1021 | #define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ |
| 1022 | #define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ |
| 1023 |
| 1024 | // U and V contributions to R,G,B. |
| 1025 | #define UB -128 /* max(-128, round(-2.018 * 64)) */ |
| 1026 | #define UG 25 /* round(0.391 * 64) */ |
| 1027 | #define VG 52 /* round(0.813 * 64) */ |
| 1028 | #define VR -102 /* round(-1.596 * 64) */ |
| 1029 |
| 1030 | // Bias values to subtract 16 from Y and 128 from U and V. |
| 1031 | #define BB (UB * 128 + YGB) |
| 1032 | #define BG (UG * 128 + VG * 128 + YGB) |
| 1033 | #define BR (VR * 128 + YGB) |
| 1034 |
| 1035 | #if defined(__aarch64__) |
| 1036 | const YuvConstants SIMD_ALIGNED(kYuvI601Constants) = { |
| 1037 | { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
| 1038 | { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
| 1039 | { UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1040 | { UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1041 | { BB, BG, BR, 0, 0, 0, 0, 0 }, |
| 1042 | { 0x0101 * YG, 0, 0, 0 } |
| 1043 | }; |
| 1044 | const YuvConstants SIMD_ALIGNED(kYvuI601Constants) = { |
| 1045 | { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1046 | { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1047 | { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1048 | { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1049 | { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1050 | { 0x0101 * YG, 0, 0, 0 } |
| 1051 | }; |
| 1052 | #elif defined(__arm__) |
| 1053 | const YuvConstants SIMD_ALIGNED(kYuvI601Constants) = { |
| 1054 | { -UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1055 | { UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1056 | { BB, BG, BR, 0, 0, 0, 0, 0 }, |
| 1057 | { 0x0101 * YG, 0, 0, 0 } |
| 1058 | }; |
| 1059 | const YuvConstants SIMD_ALIGNED(kYvuI601Constants) = { |
| 1060 | { -VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1061 | { VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1062 | { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1063 | { 0x0101 * YG, 0, 0, 0 } |
| 1064 | }; |
| 1065 | #else |
| 1066 | const YuvConstants SIMD_ALIGNED(kYuvI601Constants) = { |
| 1067 | { UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, |
| 1068 | UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0 }, |
| 1069 | { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, |
| 1070 | UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1071 | { 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, |
| 1072 | 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR }, |
| 1073 | { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1074 | { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1075 | { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1076 | { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1077 | }; |
| 1078 | const YuvConstants SIMD_ALIGNED(kYvuI601Constants) = { |
| 1079 | { VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, |
| 1080 | VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0 }, |
| 1081 | { VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, |
| 1082 | VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1083 | { 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, |
| 1084 | 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB }, |
| 1085 | { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1086 | { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1087 | { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1088 | { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1089 | }; |
| 1090 | #endif |
| 1091 |
| 1092 | #undef BB |
| 1093 | #undef BG |
| 1094 | #undef BR |
| 1095 | #undef YGB |
| 1096 | #undef UB |
| 1097 | #undef UG |
| 1098 | #undef VG |
| 1099 | #undef VR |
| 1100 | #undef YG |
| 1101 |
| 1102 | // JPEG YUV to RGB reference |
| 1103 | // * R = Y - V * -1.40200 |
| 1104 | // * G = Y - U * 0.34414 - V * 0.71414 |
| 1105 | // * B = Y - U * -1.77200 |
| 1106 |
| 1107 | // Y contribution to R,G,B. Scale and bias. |
| 1108 | #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ |
| 1109 | #define YGB 32 /* 64 / 2 */ |
| 1110 |
| 1111 | // U and V contributions to R,G,B. |
| 1112 | #define UB -113 /* round(-1.77200 * 64) */ |
| 1113 | #define UG 22 /* round(0.34414 * 64) */ |
| 1114 | #define VG 46 /* round(0.71414 * 64) */ |
| 1115 | #define VR -90 /* round(-1.40200 * 64) */ |
| 1116 |
| 1117 | // Bias values to round, and subtract 128 from U and V. |
| 1118 | #define BB (UB * 128 + YGB) |
| 1119 | #define BG (UG * 128 + VG * 128 + YGB) |
| 1120 | #define BR (VR * 128 + YGB) |
| 1121 |
| 1122 | #if defined(__aarch64__) |
| 1123 | const YuvConstants SIMD_ALIGNED(kYuvJPEGConstants) = { |
| 1124 | { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
| 1125 | { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
| 1126 | { UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1127 | { UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1128 | { BB, BG, BR, 0, 0, 0, 0, 0 }, |
| 1129 | { 0x0101 * YG, 0, 0, 0 } |
| 1130 | }; |
| 1131 | const YuvConstants SIMD_ALIGNED(kYvuJPEGConstants) = { |
| 1132 | { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1133 | { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1134 | { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1135 | { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1136 | { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1137 | { 0x0101 * YG, 0, 0, 0 } |
| 1138 | }; |
| 1139 | #elif defined(__arm__) |
| 1140 | const YuvConstants SIMD_ALIGNED(kYuvJPEGConstants) = { |
| 1141 | { -UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1142 | { UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1143 | { BB, BG, BR, 0, 0, 0, 0, 0 }, |
| 1144 | { 0x0101 * YG, 0, 0, 0 } |
| 1145 | }; |
| 1146 | const YuvConstants SIMD_ALIGNED(kYvuJPEGConstants) = { |
| 1147 | { -VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1148 | { VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1149 | { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1150 | { 0x0101 * YG, 0, 0, 0 } |
| 1151 | }; |
| 1152 | #else |
| 1153 | const YuvConstants SIMD_ALIGNED(kYuvJPEGConstants) = { |
| 1154 | { UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, |
| 1155 | UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0 }, |
| 1156 | { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, |
| 1157 | UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1158 | { 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, |
| 1159 | 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR }, |
| 1160 | { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1161 | { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1162 | { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1163 | { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1164 | }; |
| 1165 | const YuvConstants SIMD_ALIGNED(kYvuJPEGConstants) = { |
| 1166 | { VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, |
| 1167 | VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0 }, |
| 1168 | { VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, |
| 1169 | VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1170 | { 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, |
| 1171 | 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB }, |
| 1172 | { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1173 | { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1174 | { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1175 | { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1176 | }; |
| 1177 | #endif |
| 1178 |
| 1179 | #undef BB |
| 1180 | #undef BG |
| 1181 | #undef BR |
| 1182 | #undef YGB |
| 1183 | #undef UB |
| 1184 | #undef UG |
| 1185 | #undef VG |
| 1186 | #undef VR |
| 1187 | #undef YG |
| 1188 |
| 1189 | // BT.709 YUV to RGB reference |
| 1190 | // * R = Y - V * -1.28033 |
| 1191 | // * G = Y - U * 0.21482 - V * 0.38059 |
| 1192 | // * B = Y - U * -2.12798 |
| 1193 |
| 1194 | // Y contribution to R,G,B. Scale and bias. |
| 1195 | #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ |
| 1196 | #define YGB 32 /* 64 / 2 */ |
| 1197 |
| 1198 | // TODO(fbarchard): Find way to express 2.12 instead of 2.0. |
| 1199 | // U and V contributions to R,G,B. |
| 1200 | #define UB -128 /* max(-128, round(-2.12798 * 64)) */ |
| 1201 | #define UG 14 /* round(0.21482 * 64) */ |
| 1202 | #define VG 24 /* round(0.38059 * 64) */ |
| 1203 | #define VR -82 /* round(-1.28033 * 64) */ |
| 1204 |
| 1205 | // Bias values to round, and subtract 128 from U and V. |
| 1206 | #define BB (UB * 128 + YGB) |
| 1207 | #define BG (UG * 128 + VG * 128 + YGB) |
| 1208 | #define BR (VR * 128 + YGB) |
| 1209 |
| 1210 | #if defined(__aarch64__) |
| 1211 | const YuvConstants SIMD_ALIGNED(kYuvH709Constants) = { |
| 1212 | { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
| 1213 | { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
| 1214 | { UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1215 | { UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1216 | { BB, BG, BR, 0, 0, 0, 0, 0 }, |
| 1217 | { 0x0101 * YG, 0, 0, 0 } |
| 1218 | }; |
| 1219 | const YuvConstants SIMD_ALIGNED(kYvuH709Constants) = { |
| 1220 | { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1221 | { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1222 | { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1223 | { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1224 | { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1225 | { 0x0101 * YG, 0, 0, 0 } |
| 1226 | }; |
| 1227 | #elif defined(__arm__) |
| 1228 | const YuvConstants SIMD_ALIGNED(kYuvH709Constants) = { |
| 1229 | { -UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1230 | { UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1231 | { BB, BG, BR, 0, 0, 0, 0, 0 }, |
| 1232 | { 0x0101 * YG, 0, 0, 0 } |
| 1233 | }; |
| 1234 | const YuvConstants SIMD_ALIGNED(kYvuH709Constants) = { |
| 1235 | { -VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1236 | { VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1237 | { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1238 | { 0x0101 * YG, 0, 0, 0 } |
| 1239 | }; |
| 1240 | #else |
| 1241 | const YuvConstants SIMD_ALIGNED(kYuvH709Constants) = { |
| 1242 | { UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, |
| 1243 | UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0 }, |
| 1244 | { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, |
| 1245 | UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG }, |
| 1246 | { 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, |
| 1247 | 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR }, |
| 1248 | { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1249 | { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1250 | { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1251 | { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1252 | }; |
| 1253 | const YuvConstants SIMD_ALIGNED(kYvuH709Constants) = { |
| 1254 | { VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, |
| 1255 | VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0 }, |
| 1256 | { VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, |
| 1257 | VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1258 | { 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, |
| 1259 | 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB }, |
| 1260 | { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1261 | { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1262 | { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1263 | { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1264 | }; |
| 1265 | #endif |
| 1266 |
| 1267 | #undef BB |
| 1268 | #undef BG |
| 1269 | #undef BR |
| 1270 | #undef YGB |
| 1271 | #undef UB |
| 1272 | #undef UG |
| 1273 | #undef VG |
| 1274 | #undef VR |
| 1275 | #undef YG |
| 1276 |
| 1277 | // C reference code that mimics the YUV assembly. |
| 1278 | static __inline void YuvPixel(uint8 y, uint8 u, uint8 v, |
| 1279 | uint8* b, uint8* g, uint8* r, |
| 1280 | const struct YuvConstants* yuvconstants) { |
| 1281 | #if defined(__aarch64__) |
| 1282 | int ub = -yuvconstants->kUVToRB[0]; |
| 1283 | int ug = yuvconstants->kUVToG[0]; |
| 1284 | int vg = yuvconstants->kUVToG[1]; |
| 1285 | int vr = -yuvconstants->kUVToRB[1]; |
| 1286 | int bb = yuvconstants->kUVBiasBGR[0]; |
| 1287 | int bg = yuvconstants->kUVBiasBGR[1]; |
| 1288 | int br = yuvconstants->kUVBiasBGR[2]; |
| 1289 | int yg = yuvconstants->kYToRgb[0] / 0x0101; |
| 1290 | #elif defined(__arm__) |
| 1291 | int ub = -yuvconstants->kUVToRB[0]; |
| 1292 | int ug = yuvconstants->kUVToG[0]; |
| 1293 | int vg = yuvconstants->kUVToG[4]; |
| 1294 | int vr = -yuvconstants->kUVToRB[4]; |
| 1295 | int bb = yuvconstants->kUVBiasBGR[0]; |
| 1296 | int bg = yuvconstants->kUVBiasBGR[1]; |
| 1297 | int br = yuvconstants->kUVBiasBGR[2]; |
| 1298 | int yg = yuvconstants->kYToRgb[0] / 0x0101; |
| 1299 | #else |
| 1300 | int ub = yuvconstants->kUVToB[0]; |
| 1301 | int ug = yuvconstants->kUVToG[0]; |
| 1302 | int vg = yuvconstants->kUVToG[1]; |
| 1303 | int vr = yuvconstants->kUVToR[1]; |
| 1304 | int bb = yuvconstants->kUVBiasB[0]; |
| 1305 | int bg = yuvconstants->kUVBiasG[0]; |
| 1306 | int br = yuvconstants->kUVBiasR[0]; |
| 1307 | int yg = yuvconstants->kYToRgb[0]; |
| 1308 | #endif |
| 1309 |
| 1310 | uint32 y1 = (uint32)(y * 0x0101 * yg) >> 16; |
| 1311 | *b = Clamp((int32)(-(u * ub ) + y1 + bb) >> 6); |
| 1312 | *g = Clamp((int32)(-(u * ug + v * vg) + y1 + bg) >> 6); |
| 1313 | *r = Clamp((int32)(-( v * vr) + y1 + br) >> 6); |
| 1314 | } |
| 1315 |
| 1316 | // Y contribution to R,G,B. Scale and bias. |
| 1317 | #define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ |
| 1318 | #define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ |
| 1319 |
| 1320 | // C reference code that mimics the YUV assembly. |
| 1321 | static __inline void YPixel(uint8 y, uint8* b, uint8* g, uint8* r) { |
| 1322 | uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16; |
| 1323 | *b = Clamp((int32)(y1 + YGB) >> 6); |
| 1324 | *g = Clamp((int32)(y1 + YGB) >> 6); |
| 1325 | *r = Clamp((int32)(y1 + YGB) >> 6); |
| 1326 | } |
| 1327 |
| 1328 | #undef YG |
| 1329 | #undef YGB |
| 1330 |
| 1331 | #if !defined(LIBYUV_DISABLE_NEON) && \ |
| 1332 | (defined(__ARM_NEON__) || defined(__aarch64__) || defined(LIBYUV_NEON)) |
| 1333 | // C mimic assembly. |
| 1334 | // TODO(fbarchard): Remove subsampling from Neon. |
| 1335 | void I444ToARGBRow_C(const uint8* src_y, |
| 1336 | const uint8* src_u, |
| 1337 | const uint8* src_v, |
| 1338 | uint8* rgb_buf, |
| 1339 | const struct YuvConstants* yuvconstants, |
| 1340 | int width) { |
| 1341 | int x; |
| 1342 | for (x = 0; x < width - 1; x += 2) { |
| 1343 | uint8 u = (src_u[0] + src_u[1] + 1) >> 1; |
| 1344 | uint8 v = (src_v[0] + src_v[1] + 1) >> 1; |
| 1345 | YuvPixel(src_y[0], u, v, rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, |
| 1346 | yuvconstants); |
| 1347 | rgb_buf[3] = 255; |
| 1348 | YuvPixel(src_y[1], u, v, rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, |
| 1349 | yuvconstants); |
| 1350 | rgb_buf[7] = 255; |
| 1351 | src_y += 2; |
| 1352 | src_u += 2; |
| 1353 | src_v += 2; |
| 1354 | rgb_buf += 8; // Advance 2 pixels. |
| 1355 | } |
| 1356 | if (width & 1) { |
| 1357 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1358 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1359 | rgb_buf[3] = 255; |
| 1360 | } |
| 1361 | } |
| 1362 | #else |
| 1363 | void I444ToARGBRow_C(const uint8* src_y, |
| 1364 | const uint8* src_u, |
| 1365 | const uint8* src_v, |
| 1366 | uint8* rgb_buf, |
| 1367 | const struct YuvConstants* yuvconstants, |
| 1368 | int width) { |
| 1369 | int x; |
| 1370 | for (x = 0; x < width; ++x) { |
| 1371 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1372 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1373 | rgb_buf[3] = 255; |
| 1374 | src_y += 1; |
| 1375 | src_u += 1; |
| 1376 | src_v += 1; |
| 1377 | rgb_buf += 4; // Advance 1 pixel. |
| 1378 | } |
| 1379 | } |
| 1380 | #endif |
| 1381 |
| 1382 | // Also used for 420 |
| 1383 | void I422ToARGBRow_C(const uint8* src_y, |
| 1384 | const uint8* src_u, |
| 1385 | const uint8* src_v, |
| 1386 | uint8* rgb_buf, |
| 1387 | const struct YuvConstants* yuvconstants, |
| 1388 | int width) { |
| 1389 | int x; |
| 1390 | for (x = 0; x < width - 1; x += 2) { |
| 1391 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1392 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1393 | rgb_buf[3] = 255; |
| 1394 | YuvPixel(src_y[1], src_u[0], src_v[0], |
| 1395 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1396 | rgb_buf[7] = 255; |
| 1397 | src_y += 2; |
| 1398 | src_u += 1; |
| 1399 | src_v += 1; |
| 1400 | rgb_buf += 8; // Advance 2 pixels. |
| 1401 | } |
| 1402 | if (width & 1) { |
| 1403 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1404 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1405 | rgb_buf[3] = 255; |
| 1406 | } |
| 1407 | } |
| 1408 |
| 1409 | void I422AlphaToARGBRow_C(const uint8* src_y, |
| 1410 | const uint8* src_u, |
| 1411 | const uint8* src_v, |
| 1412 | const uint8* src_a, |
| 1413 | uint8* rgb_buf, |
| 1414 | const struct YuvConstants* yuvconstants, |
| 1415 | int width) { |
| 1416 | int x; |
| 1417 | for (x = 0; x < width - 1; x += 2) { |
| 1418 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1419 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1420 | rgb_buf[3] = src_a[0]; |
| 1421 | YuvPixel(src_y[1], src_u[0], src_v[0], |
| 1422 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1423 | rgb_buf[7] = src_a[1]; |
| 1424 | src_y += 2; |
| 1425 | src_u += 1; |
| 1426 | src_v += 1; |
| 1427 | src_a += 2; |
| 1428 | rgb_buf += 8; // Advance 2 pixels. |
| 1429 | } |
| 1430 | if (width & 1) { |
| 1431 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1432 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1433 | rgb_buf[3] = src_a[0]; |
| 1434 | } |
| 1435 | } |
| 1436 |
| 1437 | void I422ToRGB24Row_C(const uint8* src_y, |
| 1438 | const uint8* src_u, |
| 1439 | const uint8* src_v, |
| 1440 | uint8* rgb_buf, |
| 1441 | const struct YuvConstants* yuvconstants, |
| 1442 | int width) { |
| 1443 | int x; |
| 1444 | for (x = 0; x < width - 1; x += 2) { |
| 1445 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1446 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1447 | YuvPixel(src_y[1], src_u[0], src_v[0], |
| 1448 | rgb_buf + 3, rgb_buf + 4, rgb_buf + 5, yuvconstants); |
| 1449 | src_y += 2; |
| 1450 | src_u += 1; |
| 1451 | src_v += 1; |
| 1452 | rgb_buf += 6; // Advance 2 pixels. |
| 1453 | } |
| 1454 | if (width & 1) { |
| 1455 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1456 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1457 | } |
| 1458 | } |
| 1459 |
| 1460 | void I422ToARGB4444Row_C(const uint8* src_y, |
| 1461 | const uint8* src_u, |
| 1462 | const uint8* src_v, |
| 1463 | uint8* dst_argb4444, |
| 1464 | const struct YuvConstants* yuvconstants, |
| 1465 | int width) { |
| 1466 | uint8 b0; |
| 1467 | uint8 g0; |
| 1468 | uint8 r0; |
| 1469 | uint8 b1; |
| 1470 | uint8 g1; |
| 1471 | uint8 r1; |
| 1472 | int x; |
| 1473 | for (x = 0; x < width - 1; x += 2) { |
| 1474 | YuvPixel(src_y[0], src_u[0], src_v[0], &b0, &g0, &r0, yuvconstants); |
| 1475 | YuvPixel(src_y[1], src_u[0], src_v[0], &b1, &g1, &r1, yuvconstants); |
| 1476 | b0 = b0 >> 4; |
| 1477 | g0 = g0 >> 4; |
| 1478 | r0 = r0 >> 4; |
| 1479 | b1 = b1 >> 4; |
| 1480 | g1 = g1 >> 4; |
| 1481 | r1 = r1 >> 4; |
| 1482 | *(uint32*)(dst_argb4444) = b0 | (g0 << 4) | (r0 << 8) | |
| 1483 | (b1 << 16) | (g1 << 20) | (r1 << 24) | 0xf000f000; |
| 1484 | src_y += 2; |
| 1485 | src_u += 1; |
| 1486 | src_v += 1; |
| 1487 | dst_argb4444 += 4; // Advance 2 pixels. |
| 1488 | } |
| 1489 | if (width & 1) { |
| 1490 | YuvPixel(src_y[0], src_u[0], src_v[0], &b0, &g0, &r0, yuvconstants); |
| 1491 | b0 = b0 >> 4; |
| 1492 | g0 = g0 >> 4; |
| 1493 | r0 = r0 >> 4; |
| 1494 | *(uint16*)(dst_argb4444) = b0 | (g0 << 4) | (r0 << 8) | |
| 1495 | 0xf000; |
| 1496 | } |
| 1497 | } |
| 1498 |
| 1499 | void I422ToARGB1555Row_C(const uint8* src_y, |
| 1500 | const uint8* src_u, |
| 1501 | const uint8* src_v, |
| 1502 | uint8* dst_argb1555, |
| 1503 | const struct YuvConstants* yuvconstants, |
| 1504 | int width) { |
| 1505 | uint8 b0; |
| 1506 | uint8 g0; |
| 1507 | uint8 r0; |
| 1508 | uint8 b1; |
| 1509 | uint8 g1; |
| 1510 | uint8 r1; |
| 1511 | int x; |
| 1512 | for (x = 0; x < width - 1; x += 2) { |
| 1513 | YuvPixel(src_y[0], src_u[0], src_v[0], &b0, &g0, &r0, yuvconstants); |
| 1514 | YuvPixel(src_y[1], src_u[0], src_v[0], &b1, &g1, &r1, yuvconstants); |
| 1515 | b0 = b0 >> 3; |
| 1516 | g0 = g0 >> 3; |
| 1517 | r0 = r0 >> 3; |
| 1518 | b1 = b1 >> 3; |
| 1519 | g1 = g1 >> 3; |
| 1520 | r1 = r1 >> 3; |
| 1521 | *(uint32*)(dst_argb1555) = b0 | (g0 << 5) | (r0 << 10) | |
| 1522 | (b1 << 16) | (g1 << 21) | (r1 << 26) | 0x80008000; |
| 1523 | src_y += 2; |
| 1524 | src_u += 1; |
| 1525 | src_v += 1; |
| 1526 | dst_argb1555 += 4; // Advance 2 pixels. |
| 1527 | } |
| 1528 | if (width & 1) { |
| 1529 | YuvPixel(src_y[0], src_u[0], src_v[0], &b0, &g0, &r0, yuvconstants); |
| 1530 | b0 = b0 >> 3; |
| 1531 | g0 = g0 >> 3; |
| 1532 | r0 = r0 >> 3; |
| 1533 | *(uint16*)(dst_argb1555) = b0 | (g0 << 5) | (r0 << 10) | |
| 1534 | 0x8000; |
| 1535 | } |
| 1536 | } |
| 1537 |
| 1538 | void I422ToRGB565Row_C(const uint8* src_y, |
| 1539 | const uint8* src_u, |
| 1540 | const uint8* src_v, |
| 1541 | uint8* dst_rgb565, |
| 1542 | const struct YuvConstants* yuvconstants, |
| 1543 | int width) { |
| 1544 | uint8 b0; |
| 1545 | uint8 g0; |
| 1546 | uint8 r0; |
| 1547 | uint8 b1; |
| 1548 | uint8 g1; |
| 1549 | uint8 r1; |
| 1550 | int x; |
| 1551 | for (x = 0; x < width - 1; x += 2) { |
| 1552 | YuvPixel(src_y[0], src_u[0], src_v[0], &b0, &g0, &r0, yuvconstants); |
| 1553 | YuvPixel(src_y[1], src_u[0], src_v[0], &b1, &g1, &r1, yuvconstants); |
| 1554 | b0 = b0 >> 3; |
| 1555 | g0 = g0 >> 2; |
| 1556 | r0 = r0 >> 3; |
| 1557 | b1 = b1 >> 3; |
| 1558 | g1 = g1 >> 2; |
| 1559 | r1 = r1 >> 3; |
| 1560 | *(uint32*)(dst_rgb565) = b0 | (g0 << 5) | (r0 << 11) | |
| 1561 | (b1 << 16) | (g1 << 21) | (r1 << 27); |
| 1562 | src_y += 2; |
| 1563 | src_u += 1; |
| 1564 | src_v += 1; |
| 1565 | dst_rgb565 += 4; // Advance 2 pixels. |
| 1566 | } |
| 1567 | if (width & 1) { |
| 1568 | YuvPixel(src_y[0], src_u[0], src_v[0], &b0, &g0, &r0, yuvconstants); |
| 1569 | b0 = b0 >> 3; |
| 1570 | g0 = g0 >> 2; |
| 1571 | r0 = r0 >> 3; |
| 1572 | *(uint16*)(dst_rgb565) = b0 | (g0 << 5) | (r0 << 11); |
| 1573 | } |
| 1574 | } |
| 1575 |
| 1576 | void I411ToARGBRow_C(const uint8* src_y, |
| 1577 | const uint8* src_u, |
| 1578 | const uint8* src_v, |
| 1579 | uint8* rgb_buf, |
| 1580 | const struct YuvConstants* yuvconstants, |
| 1581 | int width) { |
| 1582 | int x; |
| 1583 | for (x = 0; x < width - 3; x += 4) { |
| 1584 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1585 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1586 | rgb_buf[3] = 255; |
| 1587 | YuvPixel(src_y[1], src_u[0], src_v[0], |
| 1588 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1589 | rgb_buf[7] = 255; |
| 1590 | YuvPixel(src_y[2], src_u[0], src_v[0], |
| 1591 | rgb_buf + 8, rgb_buf + 9, rgb_buf + 10, yuvconstants); |
| 1592 | rgb_buf[11] = 255; |
| 1593 | YuvPixel(src_y[3], src_u[0], src_v[0], |
| 1594 | rgb_buf + 12, rgb_buf + 13, rgb_buf + 14, yuvconstants); |
| 1595 | rgb_buf[15] = 255; |
| 1596 | src_y += 4; |
| 1597 | src_u += 1; |
| 1598 | src_v += 1; |
| 1599 | rgb_buf += 16; // Advance 4 pixels. |
| 1600 | } |
| 1601 | if (width & 2) { |
| 1602 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1603 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1604 | rgb_buf[3] = 255; |
| 1605 | YuvPixel(src_y[1], src_u[0], src_v[0], |
| 1606 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1607 | rgb_buf[7] = 255; |
| 1608 | src_y += 2; |
| 1609 | rgb_buf += 8; // Advance 2 pixels. |
| 1610 | } |
| 1611 | if (width & 1) { |
| 1612 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1613 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1614 | rgb_buf[3] = 255; |
| 1615 | } |
| 1616 | } |
| 1617 |
| 1618 | void NV12ToARGBRow_C(const uint8* src_y, |
| 1619 | const uint8* src_uv, |
| 1620 | uint8* rgb_buf, |
| 1621 | const struct YuvConstants* yuvconstants, |
| 1622 | int width) { |
| 1623 | int x; |
| 1624 | for (x = 0; x < width - 1; x += 2) { |
| 1625 | YuvPixel(src_y[0], src_uv[0], src_uv[1], |
| 1626 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1627 | rgb_buf[3] = 255; |
| 1628 | YuvPixel(src_y[1], src_uv[0], src_uv[1], |
| 1629 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1630 | rgb_buf[7] = 255; |
| 1631 | src_y += 2; |
| 1632 | src_uv += 2; |
| 1633 | rgb_buf += 8; // Advance 2 pixels. |
| 1634 | } |
| 1635 | if (width & 1) { |
| 1636 | YuvPixel(src_y[0], src_uv[0], src_uv[1], |
| 1637 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1638 | rgb_buf[3] = 255; |
| 1639 | } |
| 1640 | } |
| 1641 |
| 1642 | void NV21ToARGBRow_C(const uint8* src_y, |
| 1643 | const uint8* src_vu, |
| 1644 | uint8* rgb_buf, |
| 1645 | const struct YuvConstants* yuvconstants, |
| 1646 | int width) { |
| 1647 | int x; |
| 1648 | for (x = 0; x < width - 1; x += 2) { |
| 1649 | YuvPixel(src_y[0], src_vu[1], src_vu[0], |
| 1650 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1651 | rgb_buf[3] = 255; |
| 1652 | YuvPixel(src_y[1], src_vu[1], src_vu[0], |
| 1653 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1654 | rgb_buf[7] = 255; |
| 1655 | src_y += 2; |
| 1656 | src_vu += 2; |
| 1657 | rgb_buf += 8; // Advance 2 pixels. |
| 1658 | } |
| 1659 | if (width & 1) { |
| 1660 | YuvPixel(src_y[0], src_vu[1], src_vu[0], |
| 1661 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1662 | rgb_buf[3] = 255; |
| 1663 | } |
| 1664 | } |
| 1665 |
| 1666 | void NV12ToRGB565Row_C(const uint8* src_y, |
| 1667 | const uint8* src_uv, |
| 1668 | uint8* dst_rgb565, |
| 1669 | const struct YuvConstants* yuvconstants, |
| 1670 | int width) { |
| 1671 | uint8 b0; |
| 1672 | uint8 g0; |
| 1673 | uint8 r0; |
| 1674 | uint8 b1; |
| 1675 | uint8 g1; |
| 1676 | uint8 r1; |
| 1677 | int x; |
| 1678 | for (x = 0; x < width - 1; x += 2) { |
| 1679 | YuvPixel(src_y[0], src_uv[0], src_uv[1], &b0, &g0, &r0, yuvconstants); |
| 1680 | YuvPixel(src_y[1], src_uv[0], src_uv[1], &b1, &g1, &r1, yuvconstants); |
| 1681 | b0 = b0 >> 3; |
| 1682 | g0 = g0 >> 2; |
| 1683 | r0 = r0 >> 3; |
| 1684 | b1 = b1 >> 3; |
| 1685 | g1 = g1 >> 2; |
| 1686 | r1 = r1 >> 3; |
| 1687 | *(uint32*)(dst_rgb565) = b0 | (g0 << 5) | (r0 << 11) | |
| 1688 | (b1 << 16) | (g1 << 21) | (r1 << 27); |
| 1689 | src_y += 2; |
| 1690 | src_uv += 2; |
| 1691 | dst_rgb565 += 4; // Advance 2 pixels. |
| 1692 | } |
| 1693 | if (width & 1) { |
| 1694 | YuvPixel(src_y[0], src_uv[0], src_uv[1], &b0, &g0, &r0, yuvconstants); |
| 1695 | b0 = b0 >> 3; |
| 1696 | g0 = g0 >> 2; |
| 1697 | r0 = r0 >> 3; |
| 1698 | *(uint16*)(dst_rgb565) = b0 | (g0 << 5) | (r0 << 11); |
| 1699 | } |
| 1700 | } |
| 1701 |
| 1702 | void YUY2ToARGBRow_C(const uint8* src_yuy2, |
| 1703 | uint8* rgb_buf, |
| 1704 | const struct YuvConstants* yuvconstants, |
| 1705 | int width) { |
| 1706 | int x; |
| 1707 | for (x = 0; x < width - 1; x += 2) { |
| 1708 | YuvPixel(src_yuy2[0], src_yuy2[1], src_yuy2[3], |
| 1709 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1710 | rgb_buf[3] = 255; |
| 1711 | YuvPixel(src_yuy2[2], src_yuy2[1], src_yuy2[3], |
| 1712 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1713 | rgb_buf[7] = 255; |
| 1714 | src_yuy2 += 4; |
| 1715 | rgb_buf += 8; // Advance 2 pixels. |
| 1716 | } |
| 1717 | if (width & 1) { |
| 1718 | YuvPixel(src_yuy2[0], src_yuy2[1], src_yuy2[3], |
| 1719 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1720 | rgb_buf[3] = 255; |
| 1721 | } |
| 1722 | } |
| 1723 |
| 1724 | void UYVYToARGBRow_C(const uint8* src_uyvy, |
| 1725 | uint8* rgb_buf, |
| 1726 | const struct YuvConstants* yuvconstants, |
| 1727 | int width) { |
| 1728 | int x; |
| 1729 | for (x = 0; x < width - 1; x += 2) { |
| 1730 | YuvPixel(src_uyvy[1], src_uyvy[0], src_uyvy[2], |
| 1731 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1732 | rgb_buf[3] = 255; |
| 1733 | YuvPixel(src_uyvy[3], src_uyvy[0], src_uyvy[2], |
| 1734 | rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); |
| 1735 | rgb_buf[7] = 255; |
| 1736 | src_uyvy += 4; |
| 1737 | rgb_buf += 8; // Advance 2 pixels. |
| 1738 | } |
| 1739 | if (width & 1) { |
| 1740 | YuvPixel(src_uyvy[1], src_uyvy[0], src_uyvy[2], |
| 1741 | rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
| 1742 | rgb_buf[3] = 255; |
| 1743 | } |
| 1744 | } |
| 1745 |
| 1746 | void I422ToRGBARow_C(const uint8* src_y, |
| 1747 | const uint8* src_u, |
| 1748 | const uint8* src_v, |
| 1749 | uint8* rgb_buf, |
| 1750 | const struct YuvConstants* yuvconstants, |
| 1751 | int width) { |
| 1752 | int x; |
| 1753 | for (x = 0; x < width - 1; x += 2) { |
| 1754 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1755 | rgb_buf + 1, rgb_buf + 2, rgb_buf + 3, yuvconstants); |
| 1756 | rgb_buf[0] = 255; |
| 1757 | YuvPixel(src_y[1], src_u[0], src_v[0], |
| 1758 | rgb_buf + 5, rgb_buf + 6, rgb_buf + 7, yuvconstants); |
| 1759 | rgb_buf[4] = 255; |
| 1760 | src_y += 2; |
| 1761 | src_u += 1; |
| 1762 | src_v += 1; |
| 1763 | rgb_buf += 8; // Advance 2 pixels. |
| 1764 | } |
| 1765 | if (width & 1) { |
| 1766 | YuvPixel(src_y[0], src_u[0], src_v[0], |
| 1767 | rgb_buf + 1, rgb_buf + 2, rgb_buf + 3, yuvconstants); |
| 1768 | rgb_buf[0] = 255; |
| 1769 | } |
| 1770 | } |
| 1771 |
| 1772 | void I400ToARGBRow_C(const uint8* src_y, uint8* rgb_buf, int width) { |
| 1773 | int x; |
| 1774 | for (x = 0; x < width - 1; x += 2) { |
| 1775 | YPixel(src_y[0], rgb_buf + 0, rgb_buf + 1, rgb_buf + 2); |
| 1776 | rgb_buf[3] = 255; |
| 1777 | YPixel(src_y[1], rgb_buf + 4, rgb_buf + 5, rgb_buf + 6); |
| 1778 | rgb_buf[7] = 255; |
| 1779 | src_y += 2; |
| 1780 | rgb_buf += 8; // Advance 2 pixels. |
| 1781 | } |
| 1782 | if (width & 1) { |
| 1783 | YPixel(src_y[0], rgb_buf + 0, rgb_buf + 1, rgb_buf + 2); |
| 1784 | rgb_buf[3] = 255; |
| 1785 | } |
| 1786 | } |
| 1787 |
| 1788 | void MirrorRow_C(const uint8* src, uint8* dst, int width) { |
| 1789 | int x; |
| 1790 | src += width - 1; |
| 1791 | for (x = 0; x < width - 1; x += 2) { |
| 1792 | dst[x] = src[0]; |
| 1793 | dst[x + 1] = src[-1]; |
| 1794 | src -= 2; |
| 1795 | } |
| 1796 | if (width & 1) { |
| 1797 | dst[width - 1] = src[0]; |
| 1798 | } |
| 1799 | } |
| 1800 |
| 1801 | void MirrorUVRow_C(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int width) { |
| 1802 | int x; |
| 1803 | src_uv += (width - 1) << 1; |
| 1804 | for (x = 0; x < width - 1; x += 2) { |
| 1805 | dst_u[x] = src_uv[0]; |
| 1806 | dst_u[x + 1] = src_uv[-2]; |
| 1807 | dst_v[x] = src_uv[1]; |
| 1808 | dst_v[x + 1] = src_uv[-2 + 1]; |
| 1809 | src_uv -= 4; |
| 1810 | } |
| 1811 | if (width & 1) { |
| 1812 | dst_u[width - 1] = src_uv[0]; |
| 1813 | dst_v[width - 1] = src_uv[1]; |
| 1814 | } |
| 1815 | } |
| 1816 |
| 1817 | void ARGBMirrorRow_C(const uint8* src, uint8* dst, int width) { |
| 1818 | int x; |
| 1819 | const uint32* src32 = (const uint32*)(src); |
| 1820 | uint32* dst32 = (uint32*)(dst); |
| 1821 | src32 += width - 1; |
| 1822 | for (x = 0; x < width - 1; x += 2) { |
| 1823 | dst32[x] = src32[0]; |
| 1824 | dst32[x + 1] = src32[-1]; |
| 1825 | src32 -= 2; |
| 1826 | } |
| 1827 | if (width & 1) { |
| 1828 | dst32[width - 1] = src32[0]; |
| 1829 | } |
| 1830 | } |
| 1831 |
| 1832 | void SplitUVRow_C(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int width) { |
| 1833 | int x; |
| 1834 | for (x = 0; x < width - 1; x += 2) { |
| 1835 | dst_u[x] = src_uv[0]; |
| 1836 | dst_u[x + 1] = src_uv[2]; |
| 1837 | dst_v[x] = src_uv[1]; |
| 1838 | dst_v[x + 1] = src_uv[3]; |
| 1839 | src_uv += 4; |
| 1840 | } |
| 1841 | if (width & 1) { |
| 1842 | dst_u[width - 1] = src_uv[0]; |
| 1843 | dst_v[width - 1] = src_uv[1]; |
| 1844 | } |
| 1845 | } |
| 1846 |
| 1847 | void MergeUVRow_C(const uint8* src_u, const uint8* src_v, uint8* dst_uv, |
| 1848 | int width) { |
| 1849 | int x; |
| 1850 | for (x = 0; x < width - 1; x += 2) { |
| 1851 | dst_uv[0] = src_u[x]; |
| 1852 | dst_uv[1] = src_v[x]; |
| 1853 | dst_uv[2] = src_u[x + 1]; |
| 1854 | dst_uv[3] = src_v[x + 1]; |
| 1855 | dst_uv += 4; |
| 1856 | } |
| 1857 | if (width & 1) { |
| 1858 | dst_uv[0] = src_u[width - 1]; |
| 1859 | dst_uv[1] = src_v[width - 1]; |
| 1860 | } |
| 1861 | } |
| 1862 |
| 1863 | void CopyRow_C(const uint8* src, uint8* dst, int count) { |
| 1864 | memcpy(dst, src, count); |
| 1865 | } |
| 1866 |
| 1867 | void CopyRow_16_C(const uint16* src, uint16* dst, int count) { |
| 1868 | memcpy(dst, src, count * 2); |
| 1869 | } |
| 1870 |
| 1871 | void SetRow_C(uint8* dst, uint8 v8, int width) { |
| 1872 | memset(dst, v8, width); |
| 1873 | } |
| 1874 |
| 1875 | void ARGBSetRow_C(uint8* dst_argb, uint32 v32, int width) { |
| 1876 | uint32* d = (uint32*)(dst_argb); |
| 1877 | int x; |
| 1878 | for (x = 0; x < width; ++x) { |
| 1879 | d[x] = v32; |
| 1880 | } |
| 1881 | } |
| 1882 |
| 1883 | // Filter 2 rows of YUY2 UV's (422) into U and V (420). |
| 1884 | void YUY2ToUVRow_C(const uint8* src_yuy2, int src_stride_yuy2, |
| 1885 | uint8* dst_u, uint8* dst_v, int width) { |
| 1886 | // Output a row of UV values, filtering 2 rows of YUY2. |
| 1887 | int x; |
| 1888 | for (x = 0; x < width; x += 2) { |
| 1889 | dst_u[0] = (src_yuy2[1] + src_yuy2[src_stride_yuy2 + 1] + 1) >> 1; |
| 1890 | dst_v[0] = (src_yuy2[3] + src_yuy2[src_stride_yuy2 + 3] + 1) >> 1; |
| 1891 | src_yuy2 += 4; |
| 1892 | dst_u += 1; |
| 1893 | dst_v += 1; |
| 1894 | } |
| 1895 | } |
| 1896 |
| 1897 | // Copy row of YUY2 UV's (422) into U and V (422). |
| 1898 | void YUY2ToUV422Row_C(const uint8* src_yuy2, |
| 1899 | uint8* dst_u, uint8* dst_v, int width) { |
| 1900 | // Output a row of UV values. |
| 1901 | int x; |
| 1902 | for (x = 0; x < width; x += 2) { |
| 1903 | dst_u[0] = src_yuy2[1]; |
| 1904 | dst_v[0] = src_yuy2[3]; |
| 1905 | src_yuy2 += 4; |
| 1906 | dst_u += 1; |
| 1907 | dst_v += 1; |
| 1908 | } |
| 1909 | } |
| 1910 |
| 1911 | // Copy row of YUY2 Y's (422) into Y (420/422). |
| 1912 | void YUY2ToYRow_C(const uint8* src_yuy2, uint8* dst_y, int width) { |
| 1913 | // Output a row of Y values. |
| 1914 | int x; |
| 1915 | for (x = 0; x < width - 1; x += 2) { |
| 1916 | dst_y[x] = src_yuy2[0]; |
| 1917 | dst_y[x + 1] = src_yuy2[2]; |
| 1918 | src_yuy2 += 4; |
| 1919 | } |
| 1920 | if (width & 1) { |
| 1921 | dst_y[width - 1] = src_yuy2[0]; |
| 1922 | } |
| 1923 | } |
| 1924 |
| 1925 | // Filter 2 rows of UYVY UV's (422) into U and V (420). |
| 1926 | void UYVYToUVRow_C(const uint8* src_uyvy, int src_stride_uyvy, |
| 1927 | uint8* dst_u, uint8* dst_v, int width) { |
| 1928 | // Output a row of UV values. |
| 1929 | int x; |
| 1930 | for (x = 0; x < width; x += 2) { |
| 1931 | dst_u[0] = (src_uyvy[0] + src_uyvy[src_stride_uyvy + 0] + 1) >> 1; |
| 1932 | dst_v[0] = (src_uyvy[2] + src_uyvy[src_stride_uyvy + 2] + 1) >> 1; |
| 1933 | src_uyvy += 4; |
| 1934 | dst_u += 1; |
| 1935 | dst_v += 1; |
| 1936 | } |
| 1937 | } |
| 1938 |
| 1939 | // Copy row of UYVY UV's (422) into U and V (422). |
| 1940 | void UYVYToUV422Row_C(const uint8* src_uyvy, |
| 1941 | uint8* dst_u, uint8* dst_v, int width) { |
| 1942 | // Output a row of UV values. |
| 1943 | int x; |
| 1944 | for (x = 0; x < width; x += 2) { |
| 1945 | dst_u[0] = src_uyvy[0]; |
| 1946 | dst_v[0] = src_uyvy[2]; |
| 1947 | src_uyvy += 4; |
| 1948 | dst_u += 1; |
| 1949 | dst_v += 1; |
| 1950 | } |
| 1951 | } |
| 1952 |
| 1953 | // Copy row of UYVY Y's (422) into Y (420/422). |
| 1954 | void UYVYToYRow_C(const uint8* src_uyvy, uint8* dst_y, int width) { |
| 1955 | // Output a row of Y values. |
| 1956 | int x; |
| 1957 | for (x = 0; x < width - 1; x += 2) { |
| 1958 | dst_y[x] = src_uyvy[1]; |
| 1959 | dst_y[x + 1] = src_uyvy[3]; |
| 1960 | src_uyvy += 4; |
| 1961 | } |
| 1962 | if (width & 1) { |
| 1963 | dst_y[width - 1] = src_uyvy[1]; |
| 1964 | } |
| 1965 | } |
| 1966 |
| 1967 | #define BLEND(f, b, a) (((256 - a) * b) >> 8) + f |
| 1968 |
| 1969 | // Blend src_argb0 over src_argb1 and store to dst_argb. |
| 1970 | // dst_argb may be src_argb0 or src_argb1. |
| 1971 | // This code mimics the SSSE3 version for better testability. |
| 1972 | void ARGBBlendRow_C(const uint8* src_argb0, const uint8* src_argb1, |
| 1973 | uint8* dst_argb, int width) { |
| 1974 | int x; |
| 1975 | for (x = 0; x < width - 1; x += 2) { |
| 1976 | uint32 fb = src_argb0[0]; |
| 1977 | uint32 fg = src_argb0[1]; |
| 1978 | uint32 fr = src_argb0[2]; |
| 1979 | uint32 a = src_argb0[3]; |
| 1980 | uint32 bb = src_argb1[0]; |
| 1981 | uint32 bg = src_argb1[1]; |
| 1982 | uint32 br = src_argb1[2]; |
| 1983 | dst_argb[0] = BLEND(fb, bb, a); |
| 1984 | dst_argb[1] = BLEND(fg, bg, a); |
| 1985 | dst_argb[2] = BLEND(fr, br, a); |
| 1986 | dst_argb[3] = 255u; |
| 1987 |
| 1988 | fb = src_argb0[4 + 0]; |
| 1989 | fg = src_argb0[4 + 1]; |
| 1990 | fr = src_argb0[4 + 2]; |
| 1991 | a = src_argb0[4 + 3]; |
| 1992 | bb = src_argb1[4 + 0]; |
| 1993 | bg = src_argb1[4 + 1]; |
| 1994 | br = src_argb1[4 + 2]; |
| 1995 | dst_argb[4 + 0] = BLEND(fb, bb, a); |
| 1996 | dst_argb[4 + 1] = BLEND(fg, bg, a); |
| 1997 | dst_argb[4 + 2] = BLEND(fr, br, a); |
| 1998 | dst_argb[4 + 3] = 255u; |
| 1999 | src_argb0 += 8; |
| 2000 | src_argb1 += 8; |
| 2001 | dst_argb += 8; |
| 2002 | } |
| 2003 |
| 2004 | if (width & 1) { |
| 2005 | uint32 fb = src_argb0[0]; |
| 2006 | uint32 fg = src_argb0[1]; |
| 2007 | uint32 fr = src_argb0[2]; |
| 2008 | uint32 a = src_argb0[3]; |
| 2009 | uint32 bb = src_argb1[0]; |
| 2010 | uint32 bg = src_argb1[1]; |
| 2011 | uint32 br = src_argb1[2]; |
| 2012 | dst_argb[0] = BLEND(fb, bb, a); |
| 2013 | dst_argb[1] = BLEND(fg, bg, a); |
| 2014 | dst_argb[2] = BLEND(fr, br, a); |
| 2015 | dst_argb[3] = 255u; |
| 2016 | } |
| 2017 | } |
| 2018 | #undef BLEND |
| 2019 |
| 2020 | #define UBLEND(f, b, a) (((a) * f) + ((255 - a) * b) + 255) >> 8 |
| 2021 | void BlendPlaneRow_C(const uint8* src0, const uint8* src1, |
| 2022 | const uint8* alpha, uint8* dst, int width) { |
| 2023 | int x; |
| 2024 | for (x = 0; x < width - 1; x += 2) { |
| 2025 | dst[0] = UBLEND(src0[0], src1[0], alpha[0]); |
| 2026 | dst[1] = UBLEND(src0[1], src1[1], alpha[1]); |
| 2027 | src0 += 2; |
| 2028 | src1 += 2; |
| 2029 | alpha += 2; |
| 2030 | dst += 2; |
| 2031 | } |
| 2032 | if (width & 1) { |
| 2033 | dst[0] = UBLEND(src0[0], src1[0], alpha[0]); |
| 2034 | } |
| 2035 | } |
| 2036 | #undef UBLEND |
| 2037 |
| 2038 | #define ATTENUATE(f, a) (a | (a << 8)) * (f | (f << 8)) >> 24 |
| 2039 |
| 2040 | // Multiply source RGB by alpha and store to destination. |
| 2041 | // This code mimics the SSSE3 version for better testability. |
| 2042 | void ARGBAttenuateRow_C(const uint8* src_argb, uint8* dst_argb, int width) { |
| 2043 | int i; |
| 2044 | for (i = 0; i < width - 1; i += 2) { |
| 2045 | uint32 b = src_argb[0]; |
| 2046 | uint32 g = src_argb[1]; |
| 2047 | uint32 r = src_argb[2]; |
| 2048 | uint32 a = src_argb[3]; |
| 2049 | dst_argb[0] = ATTENUATE(b, a); |
| 2050 | dst_argb[1] = ATTENUATE(g, a); |
| 2051 | dst_argb[2] = ATTENUATE(r, a); |
| 2052 | dst_argb[3] = a; |
| 2053 | b = src_argb[4]; |
| 2054 | g = src_argb[5]; |
| 2055 | r = src_argb[6]; |
| 2056 | a = src_argb[7]; |
| 2057 | dst_argb[4] = ATTENUATE(b, a); |
| 2058 | dst_argb[5] = ATTENUATE(g, a); |
| 2059 | dst_argb[6] = ATTENUATE(r, a); |
| 2060 | dst_argb[7] = a; |
| 2061 | src_argb += 8; |
| 2062 | dst_argb += 8; |
| 2063 | } |
| 2064 |
| 2065 | if (width & 1) { |
| 2066 | const uint32 b = src_argb[0]; |
| 2067 | const uint32 g = src_argb[1]; |
| 2068 | const uint32 r = src_argb[2]; |
| 2069 | const uint32 a = src_argb[3]; |
| 2070 | dst_argb[0] = ATTENUATE(b, a); |
| 2071 | dst_argb[1] = ATTENUATE(g, a); |
| 2072 | dst_argb[2] = ATTENUATE(r, a); |
| 2073 | dst_argb[3] = a; |
| 2074 | } |
| 2075 | } |
| 2076 | #undef ATTENUATE |
| 2077 |
| 2078 | // Divide source RGB by alpha and store to destination. |
| 2079 | // b = (b * 255 + (a / 2)) / a; |
| 2080 | // g = (g * 255 + (a / 2)) / a; |
| 2081 | // r = (r * 255 + (a / 2)) / a; |
| 2082 | // Reciprocal method is off by 1 on some values. ie 125 |
| 2083 | // 8.8 fixed point inverse table with 1.0 in upper short and 1 / a in lower. |
| 2084 | #define T(a) 0x01000000 + (0x10000 / a) |
| 2085 | const uint32 fixed_invtbl8[256] = { |
| 2086 | 0x01000000, 0x0100ffff, T(0x02), T(0x03), T(0x04), T(0x05), T(0x06), T(0x07), |
| 2087 | T(0x08), T(0x09), T(0x0a), T(0x0b), T(0x0c), T(0x0d), T(0x0e), T(0x0f), |
| 2088 | T(0x10), T(0x11), T(0x12), T(0x13), T(0x14), T(0x15), T(0x16), T(0x17), |
| 2089 | T(0x18), T(0x19), T(0x1a), T(0x1b), T(0x1c), T(0x1d), T(0x1e), T(0x1f), |
| 2090 | T(0x20), T(0x21), T(0x22), T(0x23), T(0x24), T(0x25), T(0x26), T(0x27), |
| 2091 | T(0x28), T(0x29), T(0x2a), T(0x2b), T(0x2c), T(0x2d), T(0x2e), T(0x2f), |
| 2092 | T(0x30), T(0x31), T(0x32), T(0x33), T(0x34), T(0x35), T(0x36), T(0x37), |
| 2093 | T(0x38), T(0x39), T(0x3a), T(0x3b), T(0x3c), T(0x3d), T(0x3e), T(0x3f), |
| 2094 | T(0x40), T(0x41), T(0x42), T(0x43), T(0x44), T(0x45), T(0x46), T(0x47), |
| 2095 | T(0x48), T(0x49), T(0x4a), T(0x4b), T(0x4c), T(0x4d), T(0x4e), T(0x4f), |
| 2096 | T(0x50), T(0x51), T(0x52), T(0x53), T(0x54), T(0x55), T(0x56), T(0x57), |
| 2097 | T(0x58), T(0x59), T(0x5a), T(0x5b), T(0x5c), T(0x5d), T(0x5e), T(0x5f), |
| 2098 | T(0x60), T(0x61), T(0x62), T(0x63), T(0x64), T(0x65), T(0x66), T(0x67), |
| 2099 | T(0x68), T(0x69), T(0x6a), T(0x6b), T(0x6c), T(0x6d), T(0x6e), T(0x6f), |
| 2100 | T(0x70), T(0x71), T(0x72), T(0x73), T(0x74), T(0x75), T(0x76), T(0x77), |
| 2101 | T(0x78), T(0x79), T(0x7a), T(0x7b), T(0x7c), T(0x7d), T(0x7e), T(0x7f), |
| 2102 | T(0x80), T(0x81), T(0x82), T(0x83), T(0x84), T(0x85), T(0x86), T(0x87), |
| 2103 | T(0x88), T(0x89), T(0x8a), T(0x8b), T(0x8c), T(0x8d), T(0x8e), T(0x8f), |
| 2104 | T(0x90), T(0x91), T(0x92), T(0x93), T(0x94), T(0x95), T(0x96), T(0x97), |
| 2105 | T(0x98), T(0x99), T(0x9a), T(0x9b), T(0x9c), T(0x9d), T(0x9e), T(0x9f), |
| 2106 | T(0xa0), T(0xa1), T(0xa2), T(0xa3), T(0xa4), T(0xa5), T(0xa6), T(0xa7), |
| 2107 | T(0xa8), T(0xa9), T(0xaa), T(0xab), T(0xac), T(0xad), T(0xae), T(0xaf), |
| 2108 | T(0xb0), T(0xb1), T(0xb2), T(0xb3), T(0xb4), T(0xb5), T(0xb6), T(0xb7), |
| 2109 | T(0xb8), T(0xb9), T(0xba), T(0xbb), T(0xbc), T(0xbd), T(0xbe), T(0xbf), |
| 2110 | T(0xc0), T(0xc1), T(0xc2), T(0xc3), T(0xc4), T(0xc5), T(0xc6), T(0xc7), |
| 2111 | T(0xc8), T(0xc9), T(0xca), T(0xcb), T(0xcc), T(0xcd), T(0xce), T(0xcf), |
| 2112 | T(0xd0), T(0xd1), T(0xd2), T(0xd3), T(0xd4), T(0xd5), T(0xd6), T(0xd7), |
| 2113 | T(0xd8), T(0xd9), T(0xda), T(0xdb), T(0xdc), T(0xdd), T(0xde), T(0xdf), |
| 2114 | T(0xe0), T(0xe1), T(0xe2), T(0xe3), T(0xe4), T(0xe5), T(0xe6), T(0xe7), |
| 2115 | T(0xe8), T(0xe9), T(0xea), T(0xeb), T(0xec), T(0xed), T(0xee), T(0xef), |
| 2116 | T(0xf0), T(0xf1), T(0xf2), T(0xf3), T(0xf4), T(0xf5), T(0xf6), T(0xf7), |
| 2117 | T(0xf8), T(0xf9), T(0xfa), T(0xfb), T(0xfc), T(0xfd), T(0xfe), 0x01000100 }; |
| 2118 | #undef T |
| 2119 |
| 2120 | void ARGBUnattenuateRow_C(const uint8* src_argb, uint8* dst_argb, int width) { |
| 2121 | int i; |
| 2122 | for (i = 0; i < width; ++i) { |
| 2123 | uint32 b = src_argb[0]; |
| 2124 | uint32 g = src_argb[1]; |
| 2125 | uint32 r = src_argb[2]; |
| 2126 | const uint32 a = src_argb[3]; |
| 2127 | const uint32 ia = fixed_invtbl8[a] & 0xffff; // 8.8 fixed point |
| 2128 | b = (b * ia) >> 8; |
| 2129 | g = (g * ia) >> 8; |
| 2130 | r = (r * ia) >> 8; |
| 2131 | // Clamping should not be necessary but is free in assembly. |
| 2132 | dst_argb[0] = clamp255(b); |
| 2133 | dst_argb[1] = clamp255(g); |
| 2134 | dst_argb[2] = clamp255(r); |
| 2135 | dst_argb[3] = a; |
| 2136 | src_argb += 4; |
| 2137 | dst_argb += 4; |
| 2138 | } |
| 2139 | } |
| 2140 |
| 2141 | void ComputeCumulativeSumRow_C(const uint8* row, int32* cumsum, |
| 2142 | const int32* previous_cumsum, int width) { |
| 2143 | int32 row_sum[4] = {0, 0, 0, 0}; |
| 2144 | int x; |
| 2145 | for (x = 0; x < width; ++x) { |
| 2146 | row_sum[0] += row[x * 4 + 0]; |
| 2147 | row_sum[1] += row[x * 4 + 1]; |
| 2148 | row_sum[2] += row[x * 4 + 2]; |
| 2149 | row_sum[3] += row[x * 4 + 3]; |
| 2150 | cumsum[x * 4 + 0] = row_sum[0] + previous_cumsum[x * 4 + 0]; |
| 2151 | cumsum[x * 4 + 1] = row_sum[1] + previous_cumsum[x * 4 + 1]; |
| 2152 | cumsum[x * 4 + 2] = row_sum[2] + previous_cumsum[x * 4 + 2]; |
| 2153 | cumsum[x * 4 + 3] = row_sum[3] + previous_cumsum[x * 4 + 3]; |
| 2154 | } |
| 2155 | } |
| 2156 |
| 2157 | void CumulativeSumToAverageRow_C(const int32* tl, const int32* bl, |
| 2158 | int w, int area, uint8* dst, int count) { |
| 2159 | float ooa = 1.0f / area; |
| 2160 | int i; |
| 2161 | for (i = 0; i < count; ++i) { |
| 2162 | dst[0] = (uint8)((bl[w + 0] + tl[0] - bl[0] - tl[w + 0]) * ooa); |
| 2163 | dst[1] = (uint8)((bl[w + 1] + tl[1] - bl[1] - tl[w + 1]) * ooa); |
| 2164 | dst[2] = (uint8)((bl[w + 2] + tl[2] - bl[2] - tl[w + 2]) * ooa); |
| 2165 | dst[3] = (uint8)((bl[w + 3] + tl[3] - bl[3] - tl[w + 3]) * ooa); |
| 2166 | dst += 4; |
| 2167 | tl += 4; |
| 2168 | bl += 4; |
| 2169 | } |
| 2170 | } |
| 2171 |
| 2172 | // Copy pixels from rotated source to destination row with a slope. |
| 2173 | LIBYUV_API |
| 2174 | void ARGBAffineRow_C(const uint8* src_argb, int src_argb_stride, |
| 2175 | uint8* dst_argb, const float* uv_dudv, int width) { |
| 2176 | int i; |
| 2177 | // Render a row of pixels from source into a buffer. |
| 2178 | float uv[2]; |
| 2179 | uv[0] = uv_dudv[0]; |
| 2180 | uv[1] = uv_dudv[1]; |
| 2181 | for (i = 0; i < width; ++i) { |
| 2182 | int x = (int)(uv[0]); |
| 2183 | int y = (int)(uv[1]); |
| 2184 | *(uint32*)(dst_argb) = |
| 2185 | *(const uint32*)(src_argb + y * src_argb_stride + |
| 2186 | x * 4); |
| 2187 | dst_argb += 4; |
| 2188 | uv[0] += uv_dudv[2]; |
| 2189 | uv[1] += uv_dudv[3]; |
| 2190 | } |
| 2191 | } |
| 2192 |
| 2193 | // Blend 2 rows into 1. |
| 2194 | static void HalfRow_C(const uint8* src_uv, int src_uv_stride, |
| 2195 | uint8* dst_uv, int width) { |
| 2196 | int x; |
| 2197 | for (x = 0; x < width; ++x) { |
| 2198 | dst_uv[x] = (src_uv[x] + src_uv[src_uv_stride + x] + 1) >> 1; |
| 2199 | } |
| 2200 | } |
| 2201 |
| 2202 | static void HalfRow_16_C(const uint16* src_uv, int src_uv_stride, |
| 2203 | uint16* dst_uv, int width) { |
| 2204 | int x; |
| 2205 | for (x = 0; x < width; ++x) { |
| 2206 | dst_uv[x] = (src_uv[x] + src_uv[src_uv_stride + x] + 1) >> 1; |
| 2207 | } |
| 2208 | } |
| 2209 |
| 2210 | // C version 2x2 -> 2x1. |
| 2211 | void InterpolateRow_C(uint8* dst_ptr, const uint8* src_ptr, |
| 2212 | ptrdiff_t src_stride, |
| 2213 | int width, int source_y_fraction) { |
| 2214 | int y1_fraction = source_y_fraction ; |
| 2215 | int y0_fraction = 256 - y1_fraction; |
| 2216 | const uint8* src_ptr1 = src_ptr + src_stride; |
| 2217 | int x; |
| 2218 | if (y1_fraction == 0) { |
| 2219 | memcpy(dst_ptr, src_ptr, width); |
| 2220 | return; |
| 2221 | } |
| 2222 | if (y1_fraction == 128) { |
| 2223 | HalfRow_C(src_ptr, (int)(src_stride), dst_ptr, width); |
| 2224 | return; |
| 2225 | } |
| 2226 | for (x = 0; x < width - 1; x += 2) { |
| 2227 | dst_ptr[0] = |
| 2228 | (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction + 128) >> 8; |
| 2229 | dst_ptr[1] = |
| 2230 | (src_ptr[1] * y0_fraction + src_ptr1[1] * y1_fraction + 128) >> 8; |
| 2231 | src_ptr += 2; |
| 2232 | src_ptr1 += 2; |
| 2233 | dst_ptr += 2; |
| 2234 | } |
| 2235 | if (width & 1) { |
| 2236 | dst_ptr[0] = |
| 2237 | (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction + 128) >> 8; |
| 2238 | } |
| 2239 | } |
| 2240 |
| 2241 | void InterpolateRow_16_C(uint16* dst_ptr, const uint16* src_ptr, |
| 2242 | ptrdiff_t src_stride, |
| 2243 | int width, int source_y_fraction) { |
| 2244 | int y1_fraction = source_y_fraction; |
| 2245 | int y0_fraction = 256 - y1_fraction; |
| 2246 | const uint16* src_ptr1 = src_ptr + src_stride; |
| 2247 | int x; |
| 2248 | if (source_y_fraction == 0) { |
| 2249 | memcpy(dst_ptr, src_ptr, width * 2); |
| 2250 | return; |
| 2251 | } |
| 2252 | if (source_y_fraction == 128) { |
| 2253 | HalfRow_16_C(src_ptr, (int)(src_stride), dst_ptr, width); |
| 2254 | return; |
| 2255 | } |
| 2256 | for (x = 0; x < width - 1; x += 2) { |
| 2257 | dst_ptr[0] = (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction) >> 8; |
| 2258 | dst_ptr[1] = (src_ptr[1] * y0_fraction + src_ptr1[1] * y1_fraction) >> 8; |
| 2259 | src_ptr += 2; |
| 2260 | src_ptr1 += 2; |
| 2261 | dst_ptr += 2; |
| 2262 | } |
| 2263 | if (width & 1) { |
| 2264 | dst_ptr[0] = (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction) >> 8; |
| 2265 | } |
| 2266 | } |
| 2267 |
| 2268 | // Use first 4 shuffler values to reorder ARGB channels. |
| 2269 | void ARGBShuffleRow_C(const uint8* src_argb, uint8* dst_argb, |
| 2270 | const uint8* shuffler, int width) { |
| 2271 | int index0 = shuffler[0]; |
| 2272 | int index1 = shuffler[1]; |
| 2273 | int index2 = shuffler[2]; |
| 2274 | int index3 = shuffler[3]; |
| 2275 | // Shuffle a row of ARGB. |
| 2276 | int x; |
| 2277 | for (x = 0; x < width; ++x) { |
| 2278 | // To support in-place conversion. |
| 2279 | uint8 b = src_argb[index0]; |
| 2280 | uint8 g = src_argb[index1]; |
| 2281 | uint8 r = src_argb[index2]; |
| 2282 | uint8 a = src_argb[index3]; |
| 2283 | dst_argb[0] = b; |
| 2284 | dst_argb[1] = g; |
| 2285 | dst_argb[2] = r; |
| 2286 | dst_argb[3] = a; |
| 2287 | src_argb += 4; |
| 2288 | dst_argb += 4; |
| 2289 | } |
| 2290 | } |
| 2291 |
| 2292 | void I422ToYUY2Row_C(const uint8* src_y, |
| 2293 | const uint8* src_u, |
| 2294 | const uint8* src_v, |
| 2295 | uint8* dst_frame, int width) { |
| 2296 | int x; |
| 2297 | for (x = 0; x < width - 1; x += 2) { |
| 2298 | dst_frame[0] = src_y[0]; |
| 2299 | dst_frame[1] = src_u[0]; |
| 2300 | dst_frame[2] = src_y[1]; |
| 2301 | dst_frame[3] = src_v[0]; |
| 2302 | dst_frame += 4; |
| 2303 | src_y += 2; |
| 2304 | src_u += 1; |
| 2305 | src_v += 1; |
| 2306 | } |
| 2307 | if (width & 1) { |
| 2308 | dst_frame[0] = src_y[0]; |
| 2309 | dst_frame[1] = src_u[0]; |
| 2310 | dst_frame[2] = 0; |
| 2311 | dst_frame[3] = src_v[0]; |
| 2312 | } |
| 2313 | } |
| 2314 |
| 2315 | void I422ToUYVYRow_C(const uint8* src_y, |
| 2316 | const uint8* src_u, |
| 2317 | const uint8* src_v, |
| 2318 | uint8* dst_frame, int width) { |
| 2319 | int x; |
| 2320 | for (x = 0; x < width - 1; x += 2) { |
| 2321 | dst_frame[0] = src_u[0]; |
| 2322 | dst_frame[1] = src_y[0]; |
| 2323 | dst_frame[2] = src_v[0]; |
| 2324 | dst_frame[3] = src_y[1]; |
| 2325 | dst_frame += 4; |
| 2326 | src_y += 2; |
| 2327 | src_u += 1; |
| 2328 | src_v += 1; |
| 2329 | } |
| 2330 | if (width & 1) { |
| 2331 | dst_frame[0] = src_u[0]; |
| 2332 | dst_frame[1] = src_y[0]; |
| 2333 | dst_frame[2] = src_v[0]; |
| 2334 | dst_frame[3] = 0; |
| 2335 | } |
| 2336 | } |
| 2337 |
| 2338 |
| 2339 | void ARGBPolynomialRow_C(const uint8* src_argb, |
| 2340 | uint8* dst_argb, |
| 2341 | const float* poly, |
| 2342 | int width) { |
| 2343 | int i; |
| 2344 | for (i = 0; i < width; ++i) { |
| 2345 | float b = (float)(src_argb[0]); |
| 2346 | float g = (float)(src_argb[1]); |
| 2347 | float r = (float)(src_argb[2]); |
| 2348 | float a = (float)(src_argb[3]); |
| 2349 | float b2 = b * b; |
| 2350 | float g2 = g * g; |
| 2351 | float r2 = r * r; |
| 2352 | float a2 = a * a; |
| 2353 | float db = poly[0] + poly[4] * b; |
| 2354 | float dg = poly[1] + poly[5] * g; |
| 2355 | float dr = poly[2] + poly[6] * r; |
| 2356 | float da = poly[3] + poly[7] * a; |
| 2357 | float b3 = b2 * b; |
| 2358 | float g3 = g2 * g; |
| 2359 | float r3 = r2 * r; |
| 2360 | float a3 = a2 * a; |
| 2361 | db += poly[8] * b2; |
| 2362 | dg += poly[9] * g2; |
| 2363 | dr += poly[10] * r2; |
| 2364 | da += poly[11] * a2; |
| 2365 | db += poly[12] * b3; |
| 2366 | dg += poly[13] * g3; |
| 2367 | dr += poly[14] * r3; |
| 2368 | da += poly[15] * a3; |
| 2369 |
| 2370 | dst_argb[0] = Clamp((int32)(db)); |
| 2371 | dst_argb[1] = Clamp((int32)(dg)); |
| 2372 | dst_argb[2] = Clamp((int32)(dr)); |
| 2373 | dst_argb[3] = Clamp((int32)(da)); |
| 2374 | src_argb += 4; |
| 2375 | dst_argb += 4; |
| 2376 | } |
| 2377 | } |
| 2378 |
| 2379 | void ARGBLumaColorTableRow_C(const uint8* src_argb, uint8* dst_argb, int width, |
| 2380 | const uint8* luma, uint32 lumacoeff) { |
| 2381 | uint32 bc = lumacoeff & 0xff; |
| 2382 | uint32 gc = (lumacoeff >> 8) & 0xff; |
| 2383 | uint32 rc = (lumacoeff >> 16) & 0xff; |
| 2384 |
| 2385 | int i; |
| 2386 | for (i = 0; i < width - 1; i += 2) { |
| 2387 | // Luminance in rows, color values in columns. |
| 2388 | const uint8* luma0 = ((src_argb[0] * bc + src_argb[1] * gc + |
| 2389 | src_argb[2] * rc) & 0x7F00u) + luma; |
| 2390 | const uint8* luma1; |
| 2391 | dst_argb[0] = luma0[src_argb[0]]; |
| 2392 | dst_argb[1] = luma0[src_argb[1]]; |
| 2393 | dst_argb[2] = luma0[src_argb[2]]; |
| 2394 | dst_argb[3] = src_argb[3]; |
| 2395 | luma1 = ((src_argb[4] * bc + src_argb[5] * gc + |
| 2396 | src_argb[6] * rc) & 0x7F00u) + luma; |
| 2397 | dst_argb[4] = luma1[src_argb[4]]; |
| 2398 | dst_argb[5] = luma1[src_argb[5]]; |
| 2399 | dst_argb[6] = luma1[src_argb[6]]; |
| 2400 | dst_argb[7] = src_argb[7]; |
| 2401 | src_argb += 8; |
| 2402 | dst_argb += 8; |
| 2403 | } |
| 2404 | if (width & 1) { |
| 2405 | // Luminance in rows, color values in columns. |
| 2406 | const uint8* luma0 = ((src_argb[0] * bc + src_argb[1] * gc + |
| 2407 | src_argb[2] * rc) & 0x7F00u) + luma; |
| 2408 | dst_argb[0] = luma0[src_argb[0]]; |
| 2409 | dst_argb[1] = luma0[src_argb[1]]; |
| 2410 | dst_argb[2] = luma0[src_argb[2]]; |
| 2411 | dst_argb[3] = src_argb[3]; |
| 2412 | } |
| 2413 | } |
| 2414 |
| 2415 | void ARGBCopyAlphaRow_C(const uint8* src, uint8* dst, int width) { |
| 2416 | int i; |
| 2417 | for (i = 0; i < width - 1; i += 2) { |
| 2418 | dst[3] = src[3]; |
| 2419 | dst[7] = src[7]; |
| 2420 | dst += 8; |
| 2421 | src += 8; |
| 2422 | } |
| 2423 | if (width & 1) { |
| 2424 | dst[3] = src[3]; |
| 2425 | } |
| 2426 | } |
| 2427 |
| 2428 | void ARGBCopyYToAlphaRow_C(const uint8* src, uint8* dst, int width) { |
| 2429 | int i; |
| 2430 | for (i = 0; i < width - 1; i += 2) { |
| 2431 | dst[3] = src[0]; |
| 2432 | dst[7] = src[1]; |
| 2433 | dst += 8; |
| 2434 | src += 2; |
| 2435 | } |
| 2436 | if (width & 1) { |
| 2437 | dst[3] = src[0]; |
| 2438 | } |
| 2439 | } |
| 2440 |
| 2441 | // Maximum temporary width for wrappers to process at a time, in pixels. |
| 2442 | #define MAXTWIDTH 2048 |
| 2443 |
| 2444 | #if !(defined(_MSC_VER) && defined(_M_IX86)) && \ |
| 2445 | defined(HAS_I422TORGB565ROW_SSSE3) |
| 2446 | // row_win.cc has asm version, but GCC uses 2 step wrapper. |
| 2447 | void I422ToRGB565Row_SSSE3(const uint8* src_y, |
| 2448 | const uint8* src_u, |
| 2449 | const uint8* src_v, |
| 2450 | uint8* dst_rgb565, |
| 2451 | const struct YuvConstants* yuvconstants, |
| 2452 | int width) { |
| 2453 | SIMD_ALIGNED(uint8 row[MAXTWIDTH * 4]); |
| 2454 | while (width > 0) { |
| 2455 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2456 | I422ToARGBRow_SSSE3(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2457 | ARGBToRGB565Row_SSE2(row, dst_rgb565, twidth); |
| 2458 | src_y += twidth; |
| 2459 | src_u += twidth / 2; |
| 2460 | src_v += twidth / 2; |
| 2461 | dst_rgb565 += twidth * 2; |
| 2462 | width -= twidth; |
| 2463 | } |
| 2464 | } |
| 2465 | #endif |
| 2466 |
| 2467 | #if defined(HAS_I422TOARGB1555ROW_SSSE3) |
| 2468 | void I422ToARGB1555Row_SSSE3(const uint8* src_y, |
| 2469 | const uint8* src_u, |
| 2470 | const uint8* src_v, |
| 2471 | uint8* dst_argb1555, |
| 2472 | const struct YuvConstants* yuvconstants, |
| 2473 | int width) { |
| 2474 | // Row buffer for intermediate ARGB pixels. |
| 2475 | SIMD_ALIGNED(uint8 row[MAXTWIDTH * 4]); |
| 2476 | while (width > 0) { |
| 2477 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2478 | I422ToARGBRow_SSSE3(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2479 | ARGBToARGB1555Row_SSE2(row, dst_argb1555, twidth); |
| 2480 | src_y += twidth; |
| 2481 | src_u += twidth / 2; |
| 2482 | src_v += twidth / 2; |
| 2483 | dst_argb1555 += twidth * 2; |
| 2484 | width -= twidth; |
| 2485 | } |
| 2486 | } |
| 2487 | #endif |
| 2488 |
| 2489 | #if defined(HAS_I422TOARGB4444ROW_SSSE3) |
| 2490 | void I422ToARGB4444Row_SSSE3(const uint8* src_y, |
| 2491 | const uint8* src_u, |
| 2492 | const uint8* src_v, |
| 2493 | uint8* dst_argb4444, |
| 2494 | const struct YuvConstants* yuvconstants, |
| 2495 | int width) { |
| 2496 | // Row buffer for intermediate ARGB pixels. |
| 2497 | SIMD_ALIGNED(uint8 row[MAXTWIDTH * 4]); |
| 2498 | while (width > 0) { |
| 2499 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2500 | I422ToARGBRow_SSSE3(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2501 | ARGBToARGB4444Row_SSE2(row, dst_argb4444, twidth); |
| 2502 | src_y += twidth; |
| 2503 | src_u += twidth / 2; |
| 2504 | src_v += twidth / 2; |
| 2505 | dst_argb4444 += twidth * 2; |
| 2506 | width -= twidth; |
| 2507 | } |
| 2508 | } |
| 2509 | #endif |
| 2510 |
| 2511 | #if defined(HAS_NV12TORGB565ROW_SSSE3) |
| 2512 | void NV12ToRGB565Row_SSSE3(const uint8* src_y, |
| 2513 | const uint8* src_uv, |
| 2514 | uint8* dst_rgb565, |
| 2515 | const struct YuvConstants* yuvconstants, |
| 2516 | int width) { |
| 2517 | // Row buffer for intermediate ARGB pixels. |
| 2518 | SIMD_ALIGNED(uint8 row[MAXTWIDTH * 4]); |
| 2519 | while (width > 0) { |
| 2520 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2521 | NV12ToARGBRow_SSSE3(src_y, src_uv, row, yuvconstants, twidth); |
| 2522 | ARGBToRGB565Row_SSE2(row, dst_rgb565, twidth); |
| 2523 | src_y += twidth; |
| 2524 | src_uv += twidth; |
| 2525 | dst_rgb565 += twidth * 2; |
| 2526 | width -= twidth; |
| 2527 | } |
| 2528 | } |
| 2529 | #endif |
| 2530 |
| 2531 | #if defined(HAS_I422TORGB565ROW_AVX2) |
| 2532 | void I422ToRGB565Row_AVX2(const uint8* src_y, |
| 2533 | const uint8* src_u, |
| 2534 | const uint8* src_v, |
| 2535 | uint8* dst_rgb565, |
| 2536 | const struct YuvConstants* yuvconstants, |
| 2537 | int width) { |
| 2538 | SIMD_ALIGNED32(uint8 row[MAXTWIDTH * 4]); |
| 2539 | while (width > 0) { |
| 2540 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2541 | I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2542 | ARGBToRGB565Row_AVX2(row, dst_rgb565, twidth); |
| 2543 | src_y += twidth; |
| 2544 | src_u += twidth / 2; |
| 2545 | src_v += twidth / 2; |
| 2546 | dst_rgb565 += twidth * 2; |
| 2547 | width -= twidth; |
| 2548 | } |
| 2549 | } |
| 2550 | #endif |
| 2551 |
| 2552 | #if defined(HAS_I422TOARGB1555ROW_AVX2) |
| 2553 | void I422ToARGB1555Row_AVX2(const uint8* src_y, |
| 2554 | const uint8* src_u, |
| 2555 | const uint8* src_v, |
| 2556 | uint8* dst_argb1555, |
| 2557 | const struct YuvConstants* yuvconstants, |
| 2558 | int width) { |
| 2559 | // Row buffer for intermediate ARGB pixels. |
| 2560 | SIMD_ALIGNED32(uint8 row[MAXTWIDTH * 4]); |
| 2561 | while (width > 0) { |
| 2562 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2563 | I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2564 | ARGBToARGB1555Row_AVX2(row, dst_argb1555, twidth); |
| 2565 | src_y += twidth; |
| 2566 | src_u += twidth / 2; |
| 2567 | src_v += twidth / 2; |
| 2568 | dst_argb1555 += twidth * 2; |
| 2569 | width -= twidth; |
| 2570 | } |
| 2571 | } |
| 2572 | #endif |
| 2573 |
| 2574 | #if defined(HAS_I422TOARGB4444ROW_AVX2) |
| 2575 | void I422ToARGB4444Row_AVX2(const uint8* src_y, |
| 2576 | const uint8* src_u, |
| 2577 | const uint8* src_v, |
| 2578 | uint8* dst_argb4444, |
| 2579 | const struct YuvConstants* yuvconstants, |
| 2580 | int width) { |
| 2581 | // Row buffer for intermediate ARGB pixels. |
| 2582 | SIMD_ALIGNED32(uint8 row[MAXTWIDTH * 4]); |
| 2583 | while (width > 0) { |
| 2584 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2585 | I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2586 | ARGBToARGB4444Row_AVX2(row, dst_argb4444, twidth); |
| 2587 | src_y += twidth; |
| 2588 | src_u += twidth / 2; |
| 2589 | src_v += twidth / 2; |
| 2590 | dst_argb4444 += twidth * 2; |
| 2591 | width -= twidth; |
| 2592 | } |
| 2593 | } |
| 2594 | #endif |
| 2595 |
| 2596 | #if defined(HAS_I422TORGB24ROW_AVX2) |
| 2597 | void I422ToRGB24Row_AVX2(const uint8* src_y, |
| 2598 | const uint8* src_u, |
| 2599 | const uint8* src_v, |
| 2600 | uint8* dst_rgb24, |
| 2601 | const struct YuvConstants* yuvconstants, |
| 2602 | int width) { |
| 2603 | // Row buffer for intermediate ARGB pixels. |
| 2604 | SIMD_ALIGNED32(uint8 row[MAXTWIDTH * 4]); |
| 2605 | while (width > 0) { |
| 2606 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2607 | I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); |
| 2608 | // TODO(fbarchard): ARGBToRGB24Row_AVX2 |
| 2609 | ARGBToRGB24Row_SSSE3(row, dst_rgb24, twidth); |
| 2610 | src_y += twidth; |
| 2611 | src_u += twidth / 2; |
| 2612 | src_v += twidth / 2; |
| 2613 | dst_rgb24 += twidth * 3; |
| 2614 | width -= twidth; |
| 2615 | } |
| 2616 | } |
| 2617 | #endif |
| 2618 |
| 2619 | #if defined(HAS_NV12TORGB565ROW_AVX2) |
| 2620 | void NV12ToRGB565Row_AVX2(const uint8* src_y, |
| 2621 | const uint8* src_uv, |
| 2622 | uint8* dst_rgb565, |
| 2623 | const struct YuvConstants* yuvconstants, |
| 2624 | int width) { |
| 2625 | // Row buffer for intermediate ARGB pixels. |
| 2626 | SIMD_ALIGNED32(uint8 row[MAXTWIDTH * 4]); |
| 2627 | while (width > 0) { |
| 2628 | int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; |
| 2629 | NV12ToARGBRow_AVX2(src_y, src_uv, row, yuvconstants, twidth); |
| 2630 | ARGBToRGB565Row_AVX2(row, dst_rgb565, twidth); |
| 2631 | src_y += twidth; |
| 2632 | src_uv += twidth; |
| 2633 | dst_rgb565 += twidth * 2; |
| 2634 | width -= twidth; |
| 2635 | } |
| 2636 | } |
| 2637 | #endif |
| 2638 |
| 2639 | #ifdef __cplusplus |
| 2640 | } // extern "C" |
| 2641 | } // namespace libyuv |
| 2642 | #endif |
| 2643 |