| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/base/yuv_convert.h" | |
| 6 #include "media/base/yuv_convert_internal.h" | |
| 7 | |
| 8 namespace media { | |
| 9 | |
| 10 static int clip_byte(int x) { | |
| 11 if (x > 255) | |
| 12 return 255; | |
| 13 else if (x < 0) | |
| 14 return 0; | |
| 15 else | |
| 16 return x; | |
| 17 } | |
| 18 | |
| 19 void ConvertRGB32ToYUV_C(const uint8* rgbframe, | |
| 20 uint8* yplane, | |
| 21 uint8* uplane, | |
| 22 uint8* vplane, | |
| 23 int width, | |
| 24 int height, | |
| 25 int rgbstride, | |
| 26 int ystride, | |
| 27 int uvstride) { | |
| 28 for (int i = 0; i < height; ++i) { | |
| 29 for (int j = 0; j < width; ++j) { | |
| 30 // Since the input pixel format is RGB32, there are 4 bytes per pixel. | |
| 31 const uint8* pixel = rgbframe + 4 * j; | |
| 32 yplane[j] = clip_byte(((pixel[2] * 66 + pixel[1] * 129 + | |
| 33 pixel[0] * 25 + 128) >> 8) + 16); | |
| 34 if (i % 2 == 0 && j % 2 == 0) { | |
| 35 uplane[j / 2] = clip_byte(((pixel[2] * -38 + pixel[1] * -74 + | |
| 36 pixel[0] * 112 + 128) >> 8) + 128); | |
| 37 vplane[j / 2] = clip_byte(((pixel[2] * 112 + pixel[1] * -94 + | |
| 38 pixel[0] * -18 + 128) >> 8) + 128); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 rgbframe += rgbstride; | |
| 43 yplane += ystride; | |
| 44 if (i % 2 == 0) { | |
| 45 uplane += uvstride; | |
| 46 vplane += uvstride; | |
| 47 } | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void ConvertRGB24ToYUV_C(const uint8* rgbframe, | |
| 52 uint8* yplane, | |
| 53 uint8* uplane, | |
| 54 uint8* vplane, | |
| 55 int width, | |
| 56 int height, | |
| 57 int rgbstride, | |
| 58 int ystride, | |
| 59 int uvstride) { | |
| 60 for (int i = 0; i < height; ++i) { | |
| 61 for (int j = 0; j < width; ++j) { | |
| 62 // Since the input pixel format is RGB24, there are 3 bytes per pixel. | |
| 63 const uint8* pixel = rgbframe + 3 * j; | |
| 64 yplane[j] = clip_byte(((pixel[2] * 66 + pixel[1] * 129 + | |
| 65 pixel[0] * 25 + 128) >> 8) + 16); | |
| 66 if (i % 2 == 0 && j % 2 == 0) { | |
| 67 uplane[j / 2] = clip_byte(((pixel[2] * -38 + pixel[1] * -74 + | |
| 68 pixel[0] * 112 + 128) >> 8) + 128); | |
| 69 vplane[j / 2] = clip_byte(((pixel[2] * 112 + pixel[1] * -94 + | |
| 70 pixel[0] * -18 + 128) >> 8) + 128); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 rgbframe += rgbstride; | |
| 75 yplane += ystride; | |
| 76 if (i % 2 == 0) { | |
| 77 uplane += uvstride; | |
| 78 vplane += uvstride; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 void ConvertYUY2ToYUV_C(const uint8* src, | |
| 84 uint8* yplane, | |
| 85 uint8* uplane, | |
| 86 uint8* vplane, | |
| 87 int width, | |
| 88 int height) { | |
| 89 for (int i = 0; i < height / 2; ++i) { | |
| 90 for (int j = 0; j < (width / 2); ++j) { | |
| 91 yplane[0] = src[0]; | |
| 92 *uplane = src[1]; | |
| 93 yplane[1] = src[2]; | |
| 94 *vplane = src[3]; | |
| 95 src += 4; | |
| 96 yplane += 2; | |
| 97 uplane++; | |
| 98 vplane++; | |
| 99 } | |
| 100 for (int j = 0; j < (width / 2); ++j) { | |
| 101 yplane[0] = src[0]; | |
| 102 yplane[1] = src[2]; | |
| 103 src += 4; | |
| 104 yplane += 2; | |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 } // namespace media | |
| OLD | NEW |