| 24 | } |
| 25 | |
| 26 | void naive_row( |
| 27 | const uint8_t* src_y, const uint8_t* src_vu, uint8_t* rgb_buf, int width) { |
| 28 | #define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ |
| 29 | #define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ |
| 30 | |
| 31 | // U and V contributions to R,G,B. |
| 32 | #define UB -128 /* max(-128, round(-2.018 * 64)) */ |
| 33 | #define UG 25 /* round(0.391 * 64) */ |
| 34 | #define VG 52 /* round(0.813 * 64) */ |
| 35 | #define VR -102 /* round(-1.596 * 64) */ |
| 36 | |
| 37 | // Bias values to subtract 16 from Y and 128 from U and V. |
| 38 | #define BB (UB * 128 + YGB) |
| 39 | #define BG (UG * 128 + VG * 128 + YGB) |
| 40 | #define BR (VR * 128 + YGB) |
| 41 | |
| 42 | for (int x = 0; x < width - 1; x += 2) { |
| 43 | uint8_t y = src_y[0]; |
| 44 | uint8_t u = src_vu[1]; |
| 45 | uint8_t v = src_vu[0]; |
| 46 | uint32_t y1 = (uint32_t)(y * 0x0101 * YG) >> 16; |
| 47 | uint8_t B = Clamp((int32_t)(-(u * UB) + y1 + BB) >> 6); |
| 48 | uint8_t G = Clamp((int32_t)(-(u * UG + v * VG) + y1 + BG) >> 6); |
| 49 | uint8_t R = Clamp((int32_t)(-(v * VR) + y1 + BR) >> 6); |
| 50 | rgb_buf[0] = B; |
| 51 | rgb_buf[1] = G; |
| 52 | rgb_buf[2] = R; |
| 53 | |
| 54 | y = src_y[1]; |
| 55 | y1 = (uint32_t)(y * 0x0101 * YG) >> 16; |
| 56 | B = Clamp((int32_t)(-(u * UB) + y1 + BB) >> 6); |
| 57 | G = Clamp((int32_t)(-(u * UG + v * VG) + y1 + BG) >> 6); |
| 58 | R = Clamp((int32_t)(-(v * VR) + y1 + BR) >> 6); |
| 59 | rgb_buf[3] = B; |
| 60 | rgb_buf[4] = G; |
| 61 | rgb_buf[5] = R; |
| 62 | src_y += 2; |
| 63 | src_vu += 2; |
| 64 | rgb_buf += 6; // Advance 2 pixels. |
| 65 | } |
| 66 | #undef BB |
| 67 | #undef BG |
| 68 | #undef BR |
| 69 | #undef YGB |
| 70 | #undef UB |
| 71 | #undef UG |
| 72 | #undef VG |
| 73 | #undef VR |
| 74 | #undef YG |
| 75 | } |
| 76 | |
| 77 | //! refer to libyuv |
| 78 | //! https://github.com/lemenkov/libyuv/blob/7e936044d154b9fe159a67f9562e10b1ef1cb590/source/convert_argb.cc#L1079 |