Commit 280f4fd8 authored by mikhal@webrtc.org's avatar mikhal@webrtc.org

LibYuv: Updating convert file: 1. Adding RawToI420 2. Adding support for odd…

LibYuv: Updating convert file: 1. Adding RawToI420 2. Adding support for odd dimensions 3. Removing I420ToRGB565Android and updating I420ToRGB565 to support negative height as invert 4. Adding convert class 5. Removing YV12 functionality 6. Adding I420ToBGRA 7. Coding style updates
Review URL: http://webrtc-codereview.appspot.com/214006

git-svn-id: http://libyuv.googlecode.com/svn/trunk@20 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent ea0cff02
...@@ -16,154 +16,109 @@ ...@@ -16,154 +16,109 @@
namespace libyuv namespace libyuv
{ {
class Convert {
int public:
ConvertI420ToRGB24(const uint8* src_yplane, int src_ystride, static int
const uint8* src_uplane, int src_ustride, I420ToRGB24(const uint8* src_yplane, int src_ystride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride,
int src_width,
int src_height
);
int
ConvertI420ToARGB(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertI420ToARGB4444(const uint8* src_yplane, int src_ystride, I420ToARGB(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertI420ToRGB565(const uint8* src_yplane, int src_ystride, I420ToARGB4444(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertI420ToRGB565Android(const uint8* src_yplane, int src_ystride, I420ToRGB565(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride, I420ToARGB1555(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertYV12ToARGB(const uint8* src_yplane, int src_ystride, I420ToYUY2(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height static int
); I420ToUYVY(const uint8* src_yplane, int src_ystride,
int
ConvertYV12ToRGBA(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height static int
); UYVYToI420(const uint8* src_frame, int src_stride,
int
ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride,
int src_width,
int src_height
);
int
ConvertUYVYToI420(const uint8* src_frame, int src_stride,
uint8* dst_yplane, int dst_ystride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride, uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height);
int src_height);
int static int
ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride, RGB24ToARGB(const uint8* src_frame, int src_stride,
const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
);
int
ConvertI420ToYV12(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride,
int src_width,
int src_height
);
int
ConvertRGB24ToARGB(const uint8* src_frame, int src_stride,
uint8* dst_frame, int dst_stride,
int src_width, int src_height
);
int static int
ConvertRGB24ToI420(const uint8* src_frame, int src_stride, RGB24ToI420(const uint8* src_frame, int src_stride,
uint8* dst_yplane, int dst_ystride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride, uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertABGRToI420(const uint8* src_frame, int src_stride, RAWToI420(const uint8* src_frame, int src_stride,
uint8* dst_yplane, int dst_ystride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride, uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height);
int src_height
);
int static int
ConvertNv12ToRGB565(const uint8* src_yplane, int src_ystride, ABGRToI420(const uint8* src_frame, int src_stride,
const uint8* src_uvplane, int src_uvstride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride,
int src_width, int src_height);
static int
I420ToABGR(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height int
); I420ToBGRA(const uint8* src_yplane, int src_ystride,
int
ConvertI420ToABGR(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height);
int src_height
); static int
NV12ToRGB565(const uint8* src_yplane, int src_ystride,
const uint8* src_uvplane, int src_uvstride,
uint8* dst_frame, int dst_stride,
int src_width, int src_height);
DISALLOW_IMPLICIT_CONSTRUCTORS(Convert);
};
} // namespace libyuv } // namespace libyuv
#endif // LIBYUV_INCLUDE_CONVERT_H_ #endif // LIBYUV_INCLUDE_CONVERT_H_
...@@ -37,19 +37,15 @@ void *memcpy_8(void * dest, const void * src, size_t n); ...@@ -37,19 +37,15 @@ void *memcpy_8(void * dest, const void * src, size_t n);
int int
ConvertI420ToRGB24(const uint8* src_yplane, int src_ystride, Convert::I420ToRGB24(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL)
{
return -1; return -1;
}
// RGB orientation - bottom up // RGB orientation - bottom up
uint8* out = dst_frame + dst_stride * src_height * 3 - dst_stride * 3; uint8* out = dst_frame + dst_stride * src_height * 3 - dst_stride * 3;
...@@ -61,43 +57,37 @@ ConvertI420ToRGB24(const uint8* src_yplane, int src_ystride, ...@@ -61,43 +57,37 @@ ConvertI420ToRGB24(const uint8* src_yplane, int src_ystride,
y2 = y1 + src_ystride; y2 = y1 + src_ystride;
u = src_uplane; u = src_uplane;
v = src_vplane; v = src_vplane;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// 2 rows at a time, 2 y's at a time // 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{
// Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out[2] = Clip(tmpR);
out[1] = Clip(tmpG);
out[0] = Clip(tmpB); out[0] = Clip(tmpB);
out[1] = Clip(tmpG);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8); out[2] = Clip(tmpR);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[2] = Clip(tmpR);
out2[1] = Clip(tmpG);
out2[0] = Clip(tmpB);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[5] = Clip(tmpR);
out[4] = Clip(tmpG);
out[3] = Clip(tmpB); out[3] = Clip(tmpB);
out[4] = Clip(tmpG);
out[5] = Clip(tmpR);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = Clip(tmpB);
out2[1] = Clip(tmpG);
out2[2] = Clip(tmpR);
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[5] = Clip(tmpR);
out2[4] = Clip(tmpG);
out2[3] = Clip(tmpB); out2[3] = Clip(tmpB);
out2[4] = Clip(tmpG);
out2[5] = Clip(tmpR);
out += 6; out += 6;
out2 += 6; out2 += 6;
...@@ -108,28 +98,24 @@ ConvertI420ToRGB24(const uint8* src_yplane, int src_ystride, ...@@ -108,28 +98,24 @@ ConvertI420ToRGB24(const uint8* src_yplane, int src_ystride,
} }
y1 += src_ystride + src_ystride - src_width; y1 += src_ystride + src_ystride - src_width;
y2 += src_ystride + src_ystride - src_width; y2 += src_ystride + src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out -= dst_stride * 9; out -= dst_stride * 9;
out2 -= dst_stride * 9; out2 -= dst_stride * 9;
} // end height for } // end height for
return 0; return 0;
} }
int int
ConvertI420ToARGB(const uint8* src_yplane, int src_ystride, Convert::I420ToARGB(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
...@@ -143,47 +129,42 @@ ConvertI420ToARGB(const uint8* src_yplane, int src_ystride, ...@@ -143,47 +129,42 @@ ConvertI420ToARGB(const uint8* src_yplane, int src_ystride,
int h, w; int h, w;
int tmpR, tmpG, tmpB; int tmpR, tmpG, tmpB;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// Do 2 rows at the time // Do 2 rows at the time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{ // Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out1[3] = 0xff;
out1[2] = Clip(tmpR);
out1[1] = Clip(tmpG);
out1[0] = Clip(tmpB); out1[0] = Clip(tmpB);
out1[1] = Clip(tmpG);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8); out1[2] = Clip(tmpR);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] out1[3] = 0xff;
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[3] = 0xff;
out2[2] = Clip(tmpR);
out2[1] = Clip(tmpG);
out2[0] = Clip(tmpB);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out1[7] = 0xff;
out1[6] = Clip(tmpR);
out1[5] = Clip(tmpG);
out1[4] = Clip(tmpB); out1[4] = Clip(tmpB);
out1[5] = Clip(tmpG);
out1[6] = Clip(tmpR);
out1[7] = 0xff;
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = Clip(tmpB);
out2[1] = Clip(tmpG);
out2[2] = Clip(tmpR);
out2[3] = 0xff;
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[7] = 0xff;
out2[6] = Clip(tmpR);
out2[5] = Clip(tmpG);
out2[4] = Clip(tmpB); out2[4] = Clip(tmpB);
out2[5] = Clip(tmpG);
out2[6] = Clip(tmpR);
out2[7] = 0xff;
out1 += 8; out1 += 8;
out2 += 8; out2 += 8;
...@@ -194,8 +175,8 @@ ConvertI420ToARGB(const uint8* src_yplane, int src_ystride, ...@@ -194,8 +175,8 @@ ConvertI420ToARGB(const uint8* src_yplane, int src_ystride,
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out1 += (2 * dst_stride - src_width) * 4; out1 += (2 * dst_stride - src_width) * 4;
out2 += (2 * dst_stride - src_width) * 4; out2 += (2 * dst_stride - src_width) * 4;
} // end height for } // end height for
...@@ -204,106 +185,92 @@ ConvertI420ToARGB(const uint8* src_yplane, int src_ystride, ...@@ -204,106 +185,92 @@ ConvertI420ToARGB(const uint8* src_yplane, int src_ystride,
int int
ConvertYV12ToRGBA(const uint8* src_yplane, int src_ystride, Convert::I420ToBGRA(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
int32 diff = dst_stride - src_width; uint8* out1 = dst_frame;
uint8* out2 = out1 + dst_stride * 4;
uint8 * out = dst_frame;
uint8 * out2 = out + dst_stride * 4;
const uint8 *y1,*y2, *u, *v; const uint8 *y1,*y2, *u, *v;
int tmpG, tmpB, tmpR;
int h, w;
y1 = src_yplane; y1 = src_yplane;
y2 = y1 + src_ystride; y2 = src_yplane + src_ystride;
v = src_vplane;
u = src_uplane; u = src_uplane;
v = src_vplane;
int h, w;
int tmpR, tmpG, tmpB;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// Do 2 rows at the time // Do 2 rows at the time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{ // Vertical and horizontal sub-sampling
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128 ) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
+ 128) >> 8); tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128 ) >> 8); tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out[1] = Clip(tmpR); out1[0] = 0xff;
out[2] = Clip(tmpG); out1[1] = Clip(tmpR);
out[3] = Clip(tmpB); out1[2] = Clip(tmpG);
out1[3] = Clip(tmpB);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out1[4] = 0xff;
out1[5] = Clip(tmpR);
out1[6] = Clip(tmpG);
out1[7] = Clip(tmpB);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = 0xff;
out2[1] = Clip(tmpR); out2[1] = Clip(tmpR);
out2[2] = Clip(tmpG); out2[2] = Clip(tmpG);
out2[3] = Clip(tmpB); out2[3] = Clip(tmpB);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[5] = Clip(tmpR);
out[6] = Clip(tmpG);
out[7] = Clip(tmpB);
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[4] = 0xff;
out2[5] = Clip(tmpR); out2[5] = Clip(tmpR);
out2[6] = Clip(tmpG); out2[6] = Clip(tmpG);
out2[7] = Clip(tmpB); out2[7] = Clip(tmpB);
out[0] = 0xff; out1 += 8;
out[4] = 0xff;
out += 8;
out2[0] = 0xff;
out2[4] = 0xff;
out2 += 8; out2 += 8;
y1 += 2; y1 += 2;
y2 += 2; y2 += 2;
u++; u++;
v++; v++;
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out += (src_width + diff * 2) * 4; out1 += (2 * dst_stride - src_width) * 4;
out2 += (src_width + diff * 2) * 4; out2 += (2 * dst_stride - src_width) * 4;
} } // end height for
return 0; return 0;
} }
// Little Endian... // Little Endian...
int int
ConvertI420ToARGB4444(const uint8* src_yplane, int src_ystride, Convert::I420ToARGB4444(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
// RGB orientation - bottom up // RGB orientation - bottom up
...@@ -317,37 +284,31 @@ ConvertI420ToARGB4444(const uint8* src_yplane, int src_ystride, ...@@ -317,37 +284,31 @@ ConvertI420ToARGB4444(const uint8* src_yplane, int src_ystride,
v = src_vplane; v = src_vplane;
int h, w; int h, w;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// 2 rows at a time, 2 y's at a time // 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{
// Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
// Convert to RGB888 and re-scale to 4 bits // Convert to RGB888 and re-scale to 4 bits
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out[0] =(uint8)((Clip(tmpG) & 0xf0) + (Clip(tmpB) >> 4)); out[0] =(uint8)((Clip(tmpG) & 0xf0) + (Clip(tmpB) >> 4));
out[1] = (uint8)(0xf0 + (Clip(tmpR) >> 4)); out[1] = (uint8)(0xf0 + (Clip(tmpR) >> 4));
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = (uint8)((Clip(tmpG) & 0xf0 ) + (Clip(tmpB) >> 4));
out2[1] = (uint8) (0xf0 + (Clip(tmpR) >> 4));
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[2] = (uint8)((Clip(tmpG) & 0xf0 ) + (Clip(tmpB) >> 4)); out[2] = (uint8)((Clip(tmpG) & 0xf0 ) + (Clip(tmpB) >> 4));
out[3] = (uint8)(0xf0 + (Clip(tmpR) >> 4)); out[3] = (uint8)(0xf0 + (Clip(tmpR) >> 4));
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = (uint8)((Clip(tmpG) & 0xf0 ) + (Clip(tmpB) >> 4));
out2[1] = (uint8) (0xf0 + (Clip(tmpR) >> 4));
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[2] = (uint8)((Clip(tmpG) & 0xf0 ) + (Clip(tmpB) >> 4)); out2[2] = (uint8)((Clip(tmpG) & 0xf0 ) + (Clip(tmpB) >> 4));
out2[3] = (uint8)(0xf0 + (Clip(tmpR) >> 4)); out2[3] = (uint8)(0xf0 + (Clip(tmpR) >> 4));
...@@ -361,33 +322,40 @@ ConvertI420ToARGB4444(const uint8* src_yplane, int src_ystride, ...@@ -361,33 +322,40 @@ ConvertI420ToARGB4444(const uint8* src_yplane, int src_ystride,
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out -= (2 * dst_stride + src_width) * 2; out -= (2 * dst_stride + src_width) * 2;
out2 -= (2 * dst_stride + src_width) * 2; out2 -= (2 * dst_stride + src_width) * 2;
} // end height for } // end height for
return 0; return 0;
} }
int int
ConvertI420ToRGB565(const uint8* src_yplane, int src_ystride, Convert::I420ToRGB565(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
// Negative height means invert the image.
if (src_height < 0) {
src_height = -src_height;
src_yplane = src_yplane + (src_height - 1) * src_ystride;
src_uplane = src_uplane + (src_height - 1) * src_ustride;
src_vplane = src_vplane + (src_height - 1) * src_vstride;
src_ystride = -src_ystride;
src_ustride = -src_ustride;
src_vstride = -src_vstride;
}
uint16* out = (uint16*)(dst_frame) + dst_stride * (src_height - 1); uint16* out = (uint16*)(dst_frame) + dst_stride * (src_height - 1);
uint16* out2 = out - dst_stride; uint16* out2 = out - dst_stride;
int tmpR, tmpG, tmpB; int tmpR, tmpG, tmpB;
const uint8 *y1,*y2, *u, *v; const uint8 *y1,*y2, *u, *v;
y1 = src_yplane; y1 = src_yplane;
...@@ -396,121 +364,33 @@ ConvertI420ToRGB565(const uint8* src_yplane, int src_ystride, ...@@ -396,121 +364,33 @@ ConvertI420ToRGB565(const uint8* src_yplane, int src_ystride,
v = src_vplane; v = src_vplane;
int h, w; int h, w;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// 2 rows at a time, 2 y's at a time // 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{
// Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
// 1. Convert to RGB888 // 1. Convert to RGB888
// 2. Shift to adequate location (in the 16 bit word) - RGB 565 // 2. Shift to adequate location (in the 16 bit word) - RGB 565
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3); & 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB ) >> 3); & 0xfc) << 3) + (Clip(tmpB ) >> 3);
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3);
y1 += 2;
y2 += 2;
out += 2;
out2 += 2;
u++;
v++;
}
y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1);
v += src_vstride - (src_width >> 1);
out -= 2 * dst_stride + src_width;
out2 -= 2 * dst_stride + src_width;
} // end height for
return 0;
}
//Same as ConvertI420ToRGB565 but doesn't flip vertically.
int
ConvertI420ToRGB565Android(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride,
int src_width,
int src_height
)
{
if (src_width == 0 || src_height == 0 || src_ystride == 0 ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0)
{
return -1;
}
uint16* out = (uint16*)(dst_frame);
uint16* out2 = out + dst_stride;
int tmpR, tmpG, tmpB;
const uint8 *y1,*y2, *u, *v;
int h, w;
y1 = src_yplane;
y2 = y1 + src_ystride;
u = src_uplane;
v = src_vplane;
for (h = (src_height >> 1); h > 0; h--)
{
// 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++)
{
// Vertical and horizontal sub-sampling
// 1. Convert to RGB888
// 2. Shift to adequate location (in the 16 bit word) - RGB 565
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out2[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3); & 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB ) >> 3);
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out2[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3); & 0xfc) << 3) + (Clip(tmpB) >> 3);
...@@ -524,31 +404,26 @@ ConvertI420ToRGB565Android(const uint8* src_yplane, int src_ystride, ...@@ -524,31 +404,26 @@ ConvertI420ToRGB565Android(const uint8* src_yplane, int src_ystride,
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out += 2 * dst_stride - src_width; out -= 2 * dst_stride + src_width;
out2 += 2 * dst_stride - src_width; out2 -= 2 * dst_stride + src_width;
} // end height for } // end height for
return 0; return 0;
} }
int int
ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride, Convert::I420ToARGB1555(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
uint16* out = (uint16*)(dst_frame) + dst_stride * (src_height - 1); uint16* out = (uint16*)(dst_frame) + dst_stride * (src_height - 1);
uint16* out2 = out - dst_stride ; uint16* out2 = out - dst_stride ;
int32 tmpR, tmpG, tmpB; int32 tmpR, tmpG, tmpB;
...@@ -560,38 +435,33 @@ ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride, ...@@ -560,38 +435,33 @@ ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride,
u = src_uplane; u = src_uplane;
v = src_vplane; v = src_vplane;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{ // 2 rows at a time, 2 y's at a time // 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{
// Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
// 1. Convert to RGB888 // 1. Convert to RGB888
// 2. Shift to adequate location (in the 16 bit word) - RGB 555 // 2. Shift to adequate location (in the 16 bit word) - RGB 555
// 3. Add 1 for alpha value // 3. Add 1 for alpha value
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128) >> 8);
out[0] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) + out[0] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) +
((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3)); ((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3));
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) +
((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3));
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[1] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) + out[1] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) +
((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3)); ((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3));
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[0] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) +
((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3));
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] + 128) >> 8);
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8);
out2[1] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) + out2[1] = (uint16)(0x8000 + ((Clip(tmpR) & 0xf8) << 10) +
((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3)); ((Clip(tmpG) & 0xf8) << 3) + (Clip(tmpB) >> 3));
...@@ -605,8 +475,8 @@ ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride, ...@@ -605,8 +475,8 @@ ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride,
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out -= 2 * dst_stride + src_width; out -= 2 * dst_stride + src_width;
out2 -= 2 * dst_stride + src_width; out2 -= 2 * dst_stride + src_width;
} // end height for } // end height for
...@@ -615,17 +485,14 @@ ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride, ...@@ -615,17 +485,14 @@ ConvertI420ToARGB1555(const uint8* src_yplane, int src_ystride,
int int
ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride, Convert::I420ToYUY2(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
...@@ -640,10 +507,8 @@ ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride, ...@@ -640,10 +507,8 @@ ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride,
// YUY2 - Macro-pixel = 2 image pixels // YUY2 - Macro-pixel = 2 image pixels
// Y0U0Y1V0....Y2U2Y3V2...Y4U4Y5V4.... // Y0U0Y1V0....Y2U2Y3V2...Y4U4Y5V4....
#ifndef SCALEOPT #ifndef SCALEOPT
for (int i = 0; i < (src_height >> 1);i++) for (int i = 0; i < ((src_height + 1) >> 1); i++){
{ for (int j = 0; j < ((src_width + 1) >> 1); j++){
for (int j = 0; j < (src_width >> 1);j++)
{
out1[0] = in1[0]; out1[0] = in1[0];
out1[1] = *inU; out1[1] = *inU;
out1[2] = in1[1]; out1[2] = in1[1];
...@@ -662,13 +527,13 @@ ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride, ...@@ -662,13 +527,13 @@ ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride,
} }
in1 += 2 * src_ystride - src_width; in1 += 2 * src_ystride - src_width;
in2 += 2 * src_ystride - src_width; in2 += 2 * src_ystride - src_width;
inU += src_ustride - (src_width >> 1); inU += src_ustride - ((src_width + 1) >> 1);
inV += src_vstride - (src_width >> 1); inV += src_vstride - ((src_width + 1) >> 1);
out1 += 2 * dst_stride + 2 * (dst_stride - src_width); out1 += 2 * dst_stride + 2 * (dst_stride - src_width);
out2 += 2 * dst_stride + 2 * (dst_stride - src_width); out2 += 2 * dst_stride + 2 * (dst_stride - src_width);
} }
#else #else
for (WebRtc_UWord32 i = 0; i < (height >> 1);i++) for (WebRtc_UWord32 i = 0; i < ((height + 1) >> 1);i++)
{ {
int32 width__ = (width >> 4); int32 width__ = (width >> 4);
_asm _asm
...@@ -736,17 +601,14 @@ ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride, ...@@ -736,17 +601,14 @@ ConvertI420ToYUY2(const uint8* src_yplane, int src_ystride,
} }
int int
ConvertI420ToUYVY(const uint8* src_yplane, int src_ystride, Convert::I420ToUYVY(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
int i = 0; int i = 0;
...@@ -762,10 +624,8 @@ ConvertI420ToUYVY(const uint8* src_yplane, int src_ystride, ...@@ -762,10 +624,8 @@ ConvertI420ToUYVY(const uint8* src_yplane, int src_ystride,
// U0Y0V0Y1....U2Y2V2Y3...U4Y4V4Y5..... // U0Y0V0Y1....U2Y2V2Y3...U4Y4V4Y5.....
#ifndef SCALEOPT #ifndef SCALEOPT
for (; i < (src_height >> 1);i++) for (; i < ((src_height + 1) >> 1);i++){
{ for (int j = 0; j < ((src_width + 1) >> 1) ;j++){
for (int j = 0; j < (src_width >> 1) ;j++)
{
out1[0] = *u; out1[0] = *u;
out1[1] = y1[0]; out1[1] = y1[0];
out1[2] = *v; out1[2] = *v;
...@@ -784,8 +644,8 @@ ConvertI420ToUYVY(const uint8* src_yplane, int src_ystride, ...@@ -784,8 +644,8 @@ ConvertI420ToUYVY(const uint8* src_yplane, int src_ystride,
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out1 += 2 * (dst_stride + (dst_stride - src_width)); out1 += 2 * (dst_stride + (dst_stride - src_width));
out2 += 2 * (dst_stride + (dst_stride - src_width)); out2 += 2 * (dst_stride + (dst_stride - src_width));
} }
...@@ -855,72 +715,14 @@ loop0: ...@@ -855,72 +715,14 @@ loop0:
return 0; return 0;
} }
int
ConvertI420ToYV12(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride,
int src_width,
int src_height
)
{
if (src_width == 0 || src_height == 0 || src_ystride == 0 ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0)
{
return -1;
}
const uint8* inFrame = src_yplane;
uint8* outFrame = dst_frame;
// Copy Y
for (int i = 0; i < src_height; i++)
{
#ifndef SCALEOPT
memcpy(outFrame, inFrame, src_width);
#else
memcpy_16(outFrame, inFrame, src_width);
#endif
inFrame += src_ystride;
outFrame += dst_stride;
}
// Copy U
inFrame = src_uplane;
outFrame += (dst_stride >> 1) * src_height >> 1;
for (uint32 i = 0; i < src_height >>1; i++)
{
#ifndef SCALEOPT
memcpy(outFrame, inFrame, src_width >> 1);
#else
memcpy_8(outFrame, inFrame, src_width >> 1);
#endif
inFrame += src_ustride;
outFrame += dst_stride >> 1;
}
outFrame -= dst_stride * src_height >> 1;
// Copy V
for (uint32 i = 0; i < src_height >> 1; i++)
{
#ifndef SCALEOPT
memcpy(outFrame, inFrame, src_width >> 1);
#else
memcpy_8(outFrame, inFrame, width >> 1);
#endif
inFrame += src_vstride;
outFrame += dst_stride >> 1;
}
return 0;
}
int int
ConvertNv12ToRGB565(const uint8* src_yplane, int src_ystride, Convert::NV12ToRGB565(const uint8* src_yplane, int src_ystride,
const uint8* src_uvplane, int src_uvstride, const uint8* src_uvplane, int src_uvstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_height < 1 || src_height < 1 || src_ystride < 1 || src_uvstride < 1) if (src_yplane == NULL || src_uvplane == NULL || dst_frame == NULL){
{
return -1; return -1;
} }
...@@ -934,48 +736,39 @@ ConvertNv12ToRGB565(const uint8* src_yplane, int src_ystride, ...@@ -934,48 +736,39 @@ ConvertNv12ToRGB565(const uint8* src_yplane, int src_ystride,
y2 = y1 + src_ystride; y2 = y1 + src_ystride;
int h, w; int h, w;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// 2 rows at a time, 2 y's at a time // 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{
// Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
// 1. Convert to RGB888 // 1. Convert to RGB888
// 2. Shift to adequate location (in the 16 bit word) - RGB 565 // 2. Shift to adequate location (in the 16 bit word) - RGB 565
tmpR = (int32)((mapYc[y1[0]] + mapVcr[interlacedSrc[1]] tmpR = (int32)((mapYc[y1[0]] + mapVcr[interlacedSrc[1]] + 128) >> 8);
+ 128) >> 8);
tmpG = (int32)((mapYc[y1[0]] + mapUcg[interlacedSrc[0]] tmpG = (int32)((mapYc[y1[0]] + mapUcg[interlacedSrc[0]]
+ mapVcg[interlacedSrc[1]] + 128) >> 8); + mapVcg[interlacedSrc[1]] + 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[interlacedSrc[0]] tmpB = (int32)((mapYc[y1[0]] + mapUcb[interlacedSrc[0]] + 128) >> 8);
+ 128) >> 8);
out[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3); & 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[interlacedSrc[1]] tmpR = (int32)((mapYc[y1[1]] + mapVcr[interlacedSrc[1]] + 128) >> 8);
+ 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[interlacedSrc[0]]
+ mapVcg[interlacedSrc[1]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[interlacedSrc[0]]
+ 128) >> 8);
out2[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[interlacedSrc[1]]
+ 128) >> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[interlacedSrc[0]] tmpG = (int32)((mapYc[y1[1]] + mapUcg[interlacedSrc[0]]
+ mapVcg[interlacedSrc[1]] + 128) >> 8); + mapVcg[interlacedSrc[1]] + 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[interlacedSrc[0]] tmpB = (int32)((mapYc[y1[1]] + mapUcb[interlacedSrc[0]] + 128) >> 8);
+ 128) >> 8);
out[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB ) >> 3); & 0xfc) << 3) + (Clip(tmpB ) >> 3);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[interlacedSrc[1]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[interlacedSrc[0]]
+ mapVcg[interlacedSrc[1]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[interlacedSrc[0]] + 128) >> 8);
out2[0] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3);
tmpR = (int32)((mapYc[y2[1]] + mapVcr[interlacedSrc[1]] tmpR = (int32)((mapYc[y2[1]] + mapVcr[interlacedSrc[1]]
+ 128) >> 8); + 128) >> 8);
tmpG = (int32)((mapYc[y2[1]] + mapUcg[interlacedSrc[0]] tmpG = (int32)((mapYc[y2[1]] + mapUcg[interlacedSrc[0]]
+ mapVcg[interlacedSrc[1]] + 128) >> 8); + mapVcg[interlacedSrc[1]] + 128) >> 8);
tmpB = (int32)((mapYc[y2[1]] + mapUcb[interlacedSrc[0]] tmpB = (int32)((mapYc[y2[1]] + mapUcb[interlacedSrc[0]] + 128) >> 8);
+ 128) >> 8);
out2[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG) out2[1] = (uint16)((Clip(tmpR) & 0xf8) << 8) + ((Clip(tmpG)
& 0xfc) << 3) + (Clip(tmpB) >> 3); & 0xfc) << 3) + (Clip(tmpB) >> 3);
...@@ -987,26 +780,22 @@ ConvertNv12ToRGB565(const uint8* src_yplane, int src_ystride, ...@@ -987,26 +780,22 @@ ConvertNv12ToRGB565(const uint8* src_yplane, int src_ystride,
} }
y1 += 2 * src_ystride - src_width; y1 += 2 * src_ystride - src_width;
y2 += 2 * src_ystride - src_width; y2 += 2 * src_ystride - src_width;
interlacedSrc += src_uvstride - (src_width >> 1); interlacedSrc += src_uvstride - ((src_width + 1) >> 1);
out -= 3 * dst_stride + dst_stride - src_width; out -= 3 * dst_stride + dst_stride - src_width;
out2 -= 3 * dst_stride + dst_stride - src_width; out2 -= 3 * dst_stride + dst_stride - src_width;
} // end height for } // end height for
return 0; return 0;
} }
int int
ConvertI420ToABGR(const uint8* src_yplane, int src_ystride, Convert::I420ToABGR(const uint8* src_yplane, int src_ystride,
const uint8* src_uplane, int src_ustride, const uint8* src_uplane, int src_ustride,
const uint8* src_vplane, int src_vstride, const uint8* src_vplane, int src_vstride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_yplane == NULL || src_uplane == NULL || src_vplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_frame == NULL){
{
return -1; return -1;
} }
...@@ -1022,59 +811,49 @@ ConvertI420ToABGR(const uint8* src_yplane, int src_ystride, ...@@ -1022,59 +811,49 @@ ConvertI420ToABGR(const uint8* src_yplane, int src_ystride,
u = src_uplane; u = src_uplane;
v = src_vplane; v = src_vplane;
for (h = (src_height >> 1); h > 0; h--) for (h = ((src_height + 1) >> 1); h > 0; h--){
{
// 2 rows at a time, 2 y's at a time // 2 rows at a time, 2 y's at a time
for (w = 0; w < (src_width >> 1); w++) for (w = 0; w < ((src_width + 1) >> 1); w++){
{
// Vertical and horizontal sub-sampling // Vertical and horizontal sub-sampling
tmpR = (int32)((298 * (y1[0] - 16) + 409 * (v[0] - 128) tmpR = (int32)((298 * (y1[0] - 16) + 409 * (v[0] - 128) + 128) >> 8);
+ 128) >> 8);
tmpG = (int32)((298 * (y1[0] - 16) - 100 * (u[0] - 128) tmpG = (int32)((298 * (y1[0] - 16) - 100 * (u[0] - 128)
- 208 * (v[0] - 128) + 128 ) >> 8); - 208 * (v[0] - 128) + 128 ) >> 8);
tmpB = (int32)((298 * (y1[0] - 16) + 516 * (u[0] - 128) tmpB = (int32)((298 * (y1[0] - 16) + 516 * (u[0] - 128) + 128 ) >> 8);
+ 128 ) >> 8);
out[3] = 0xff;
out[0] = Clip(tmpR); out[0] = Clip(tmpR);
out[1] = Clip(tmpG); out[1] = Clip(tmpG);
out[2] = Clip(tmpB); out[2] = Clip(tmpB);
out[3] = 0xff;
tmpR = (int32)((298 * (y2[0] - 16) + 409 * (v[0] - 128) tmpR = (int32)((298 * (y1[1] - 16) + 409 * (v[0] - 128) + 128 ) >> 8);
+ 128) >> 8);
tmpG = (int32)((298 * (y2[0] - 16) - 100 * (u[0] - 128)
- 208 * (v[0] - 128) + 128) >> 8);
tmpB = (int32)((298 * (y2[0] - 16) + 516 * (u[0] - 128)
+ 128) >> 8);
out2[3] = 0xff;
out2[0] = Clip(tmpR);
out2[1] = Clip(tmpG);
out2[2] = Clip(tmpB);
tmpR = (int32)((298 * (y1[1] - 16) + 409 * (v[0] - 128)
+ 128 ) >> 8);
tmpG = (int32)((298 * (y1[1] - 16) - 100 * (u[0] - 128) tmpG = (int32)((298 * (y1[1] - 16) - 100 * (u[0] - 128)
- 208 * (v[0] - 128) + 128 ) >> 8); - 208 * (v[0] - 128) + 128 ) >> 8);
tmpB = (int32)((298 * (y1[1] - 16) + 516 * (u[0] - 128) tmpB = (int32)((298 * (y1[1] - 16) + 516 * (u[0] - 128) + 128) >> 8);
+ 128) >> 8);
out[7] = 0xff;
out[4] = Clip(tmpR); out[4] = Clip(tmpR);
out[5] = Clip(tmpG); out[5] = Clip(tmpG);
out[6] = Clip(tmpB); out[6] = Clip(tmpB);
out[7] = 0xff;
tmpR = (int32)((298 * (y2[1] - 16) + 409 * (v[0] - 128) tmpR = (int32)((298 * (y2[0] - 16) + 409 * (v[0] - 128) + 128) >> 8);
+ 128) >> 8); tmpG = (int32)((298 * (y2[0] - 16) - 100 * (u[0] - 128)
- 208 * (v[0] - 128) + 128) >> 8);
tmpB = (int32)((298 * (y2[0] - 16) + 516 * (u[0] - 128) + 128) >> 8);
out2[0] = Clip(tmpR);
out2[1] = Clip(tmpG);
out2[2] = Clip(tmpB);
out2[3] = 0xff;
tmpR = (int32)((298 * (y2[1] - 16) + 409 * (v[0] - 128) + 128) >> 8);
tmpG = (int32)((298 * (y2[1] - 16) - 100 * (u[0] - 128) tmpG = (int32)((298 * (y2[1] - 16) - 100 * (u[0] - 128)
- 208 * (v[0] - 128) + 128) >> 8); - 208 * (v[0] - 128) + 128) >> 8);
tmpB = (int32)((298 * (y2[1] - 16) + 516 * (u[0] - 128) tmpB = (int32)((298 * (y2[1] - 16) + 516 * (u[0] - 128) + 128 ) >> 8);
+ 128 ) >> 8);
out2[7] = 0xff;
out2[4] = Clip(tmpR); out2[4] = Clip(tmpR);
out2[5] = Clip(tmpG); out2[5] = Clip(tmpG);
out2[6] = Clip(tmpB); out2[6] = Clip(tmpB);
out2[7] = 0xff;
out += 8; out += 8;
out2 += 8; out2 += 8;
...@@ -1083,11 +862,10 @@ ConvertI420ToABGR(const uint8* src_yplane, int src_ystride, ...@@ -1083,11 +862,10 @@ ConvertI420ToABGR(const uint8* src_yplane, int src_ystride,
u++; u++;
v++; v++;
} }
y1 += src_ystride + src_ystride - src_width; y1 += src_ystride + src_ystride - src_width;
y2 += src_ystride + src_ystride - src_width; y2 += src_ystride + src_ystride - src_width;
u += src_ustride - (src_width >> 1); u += src_ustride - ((src_width + 1) >> 1);
v += src_vstride - (src_width >> 1); v += src_vstride - ((src_width + 1) >> 1);
out -= (2 * dst_stride + src_width) * 4; out -= (2 * dst_stride + src_width) * 4;
out2 -= (2 * dst_stride + src_width) * 4; out2 -= (2 * dst_stride + src_width) * 4;
} // end height for } // end height for
...@@ -1096,17 +874,14 @@ ConvertI420ToABGR(const uint8* src_yplane, int src_ystride, ...@@ -1096,17 +874,14 @@ ConvertI420ToABGR(const uint8* src_yplane, int src_ystride,
int int
ConvertUYVYToI420(const uint8* src_frame, int src_stride, Convert::UYVYToI420(const uint8* src_frame, int src_stride,
uint8* dst_yplane, int dst_ystride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride, uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || dst_ystride == 0 || if (dst_yplane == NULL || dst_uplane == NULL || dst_vplane == NULL ||
dst_ustride == 0 || dst_vstride == 0 || src_stride == 0) src_frame == NULL){
{
return -1; return -1;
} }
...@@ -1117,10 +892,8 @@ ConvertUYVYToI420(const uint8* src_frame, int src_stride, ...@@ -1117,10 +892,8 @@ ConvertUYVYToI420(const uint8* src_frame, int src_stride,
// U0Y0V0Y1..U2Y2V2Y3..... // U0Y0V0Y1..U2Y2V2Y3.....
for (i = 0; i < (src_height >> 1); i++) for (i = 0; i < ((src_height + 1) >> 1); i++){
{ for (j = 0; j < ((src_width + 1) >> 1); j++){
for (j = 0; j < (src_width >> 1); j++)
{
outI[0] = src_frame[1]; outI[0] = src_frame[1];
*outU = src_frame[0]; *outU = src_frame[0];
outI[1] = src_frame[3]; outI[1] = src_frame[3];
...@@ -1130,7 +903,7 @@ ConvertUYVYToI420(const uint8* src_frame, int src_stride, ...@@ -1130,7 +903,7 @@ ConvertUYVYToI420(const uint8* src_frame, int src_stride,
outU++; outU++;
outV++; outV++;
} }
for (j = 0; j < (src_width >> 1); j++) for (j = 0; j < ((src_width + 1) >> 1); j++)
{ {
outI[0] = src_frame[1]; outI[0] = src_frame[1];
outI[1] = src_frame[3]; outI[1] = src_frame[3];
...@@ -1138,21 +911,19 @@ ConvertUYVYToI420(const uint8* src_frame, int src_stride, ...@@ -1138,21 +911,19 @@ ConvertUYVYToI420(const uint8* src_frame, int src_stride,
outI += 2; outI += 2;
} }
outI += dst_ystride - src_width; outI += dst_ystride - src_width;
outU += dst_ustride - src_width << 1; outU += dst_ustride - ((src_width + 1) << 1);
outV += dst_vstride - src_width << 1; outV += dst_vstride - ((src_width + 1) << 1);
} }
return 0; return 0;
} }
int int
ConvertRGB24ToARGB(const uint8* src_frame, int src_stride, Convert::RGB24ToARGB(const uint8* src_frame, int src_stride,
uint8* dst_frame, int dst_stride, uint8* dst_frame, int dst_stride,
int src_width, int src_height int src_width, int src_height)
)
{ {
if (src_width < 1 || src_height < 1 || dst_stride < 1) if (src_frame == NULL || dst_frame == NULL){
{
return -1; return -1;
} }
...@@ -1180,19 +951,16 @@ ConvertRGB24ToARGB(const uint8* src_frame, int src_stride, ...@@ -1180,19 +951,16 @@ ConvertRGB24ToARGB(const uint8* src_frame, int src_stride,
int int
ConvertRGB24ToI420(const uint8* src_frame, int src_stride, Convert::RGB24ToI420(const uint8* src_frame, int src_stride,
uint8* dst_yplane, int dst_ystride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride, uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || dst_ystride == 0 || if (src_frame == NULL || dst_yplane == NULL ||
dst_ustride == 0 || dst_vstride == 0 || src_stride == 0) dst_vplane == NULL || dst_vplane == NULL)
{
return -1; return -1;
}
uint8* yStartPtr; uint8* yStartPtr;
uint8* yStartPtr2; uint8* yStartPtr2;
uint8* uStartPtr; uint8* uStartPtr;
...@@ -1205,14 +973,12 @@ ConvertRGB24ToI420(const uint8* src_frame, int src_stride, ...@@ -1205,14 +973,12 @@ ConvertRGB24ToI420(const uint8* src_frame, int src_stride,
yStartPtr = dst_yplane; yStartPtr = dst_yplane;
yStartPtr2 = yStartPtr + dst_ystride; yStartPtr2 = yStartPtr + dst_ystride;
uStartPtr = dst_uplane; uStartPtr = dst_uplane;
vStartPtr =dst_vplane; vStartPtr = dst_vplane;
inpPtr = src_frame + src_stride * src_height * 3 - 3 * src_height; inpPtr = src_frame + src_stride * src_height * 3 - 3 * src_height;
inpPtr2 = inpPtr - 3 * src_stride; inpPtr2 = inpPtr - 3 * src_stride;
for (h = 0; h < (src_height >> 1); h++ ) for (h = 0; h < ((src_height + 1) >> 1); h++ ){
{ for (w = 0; w < ((src_width + 1) >> 1); w++){
for (w = 0; w < (src_width >> 1); w++)
{
// Y // Y
yStartPtr[0] = (uint8)((66 * inpPtr[2] + 129 * inpPtr[1] yStartPtr[0] = (uint8)((66 * inpPtr[2] + 129 * inpPtr[1]
+ 25 * inpPtr[0] + 128) >> 8) + 16; + 25 * inpPtr[0] + 128) >> 8) + 16;
...@@ -1239,113 +1005,89 @@ ConvertRGB24ToI420(const uint8* src_frame, int src_stride, ...@@ -1239,113 +1005,89 @@ ConvertRGB24ToI420(const uint8* src_frame, int src_stride,
} // end for w } // end for w
yStartPtr += dst_ystride + dst_ystride - src_width; yStartPtr += dst_ystride + dst_ystride - src_width;
yStartPtr2 += dst_ystride + dst_ystride - src_width; yStartPtr2 += dst_ystride + dst_ystride - src_width;
uStartPtr += dst_ustride + dst_ustride - (src_width >> 1); uStartPtr += dst_ustride + dst_ustride - ((src_width + 1) >> 1);
vStartPtr += dst_vstride + dst_vstride - (src_width >> 1); vStartPtr += dst_vstride + dst_vstride - ((src_width + 1) >> 1);
inpPtr -= 3 * (2 * src_stride + src_width); inpPtr -= 3 * (2 * src_stride + src_width);
inpPtr2 -= 3 * (2 * src_stride + src_width); inpPtr2 -= 3 * (2 * src_stride + src_width);
} // end for h } // end for h
return 0; return 0;
} }
int int
ConvertYV12ToARGB(const uint8* src_yplane, int src_ystride, Convert::RAWToI420(const uint8* src_frame, int src_stride,
const uint8* src_uplane, int src_ustride, uint8* dst_yplane, int dst_ystride,
const uint8* src_vplane, int src_vstride, uint8* dst_uplane, int dst_ustride,
uint8* dst_frame, int dst_stride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || src_ystride == 0 || if (src_frame == NULL || dst_yplane == NULL ||
src_ustride == 0 || src_vstride == 0 || dst_stride == 0) dst_vplane == NULL || dst_vplane == NULL)
{
return -1; return -1;
}
int32 diff = dst_stride - src_width;
uint8* out = dst_frame;
uint8* out2 = out + dst_stride * 4;
const uint8 *y1,*y2, *u, *v;
int h, w;
y1 = src_yplane;
y2 = y1 + src_ystride;
v = src_vplane;
u = src_uplane;
int32 tmpG, tmpB, tmpR; uint8* yStartPtr;
for (h = (src_height >> 1); h > 0; h--) uint8* yStartPtr2;
{ uint8* uStartPtr;
// 2 rows at a time uint8* vStartPtr;
for (w = 0; w < (src_width >> 1); w++) const uint8* inpPtr;
{ const uint8* inpPtr2;
tmpR = (int32)((mapYc[y1[0]] + mapVcr[v[0]] + 128 )>> 8); int h, w;
tmpG = (int32)((mapYc[y1[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[0]] + mapUcb[u[0]] + 128 )>> 8);
out[2] = Clip(tmpR);
out[1] = Clip(tmpG);
out[0] = Clip(tmpB);
tmpR = (int32)((mapYc[y2[0]] + mapVcr[v[0]] + 128) >> 8);
tmpG = (int32)((mapYc[y2[0]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y2[0]] + mapUcb[u[0]] + 128) >> 8);
out2[2] = Clip(tmpR);
out2[1] = Clip(tmpG);
out2[0] = Clip(tmpB);
tmpR = (int32)((mapYc[y1[1]] + mapVcr[v[0]] + 128)>> 8);
tmpG = (int32)((mapYc[y1[1]] + mapUcg[u[0]] + mapVcg[v[0]]
+ 128) >> 8);
tmpB = (int32)((mapYc[y1[1]] + mapUcb[u[0]] + 128) >> 8);
out[6] = Clip(tmpR);
out[5] = Clip(tmpG);
out[4] = Clip(tmpB);
tmpR = (int32)((mapYc[y2[1]] + mapVcr[v[0]] + 128) >> 8); // Assuming RGB in a bottom up orientation.
tmpG = (int32)((mapYc[y2[1]] + mapUcg[u[0]] + mapVcg[v[0]] yStartPtr = dst_yplane;
+ 128) >> 8); yStartPtr2 = yStartPtr + dst_ystride;
tmpB = (int32)((mapYc[y2[1]] + mapUcb[u[0]] + 128) >> 8); uStartPtr = dst_uplane;
out2[6] = Clip(tmpR); vStartPtr = dst_vplane;
out2[5] = Clip(tmpG); inpPtr = src_frame + src_stride * src_height * 3 - 3 * src_height;
out2[4] = Clip(tmpB); inpPtr2 = inpPtr - 3 * src_stride;
out[3] = 0xff; // Same as RGB24 - reverse ordering
out[7] = 0xff;
out += 8;
out2[3] = 0xff;
out2[7] = 0xff;
out2 += 8;
y1 += 2;
y2 += 2;
u++;
v++;
}
y1 += 2 * src_ystride - src_width; for (h = 0; h < ((src_height + 1) >> 1); h++){
y2 += 2 * src_ystride - src_width; for (w = 0; w < ((src_width + 1) >> 1); w++){
u += src_ustride - (src_width >> 1); // Y
v += src_vstride - (src_width >> 1); yStartPtr[0] = (uint8)((66 * inpPtr[0] + 129 * inpPtr[1]
+ 25 * inpPtr[2] + 128) >> 8) + 16;
yStartPtr2[0] = (uint8)((66 * inpPtr2[2] + 129 * inpPtr2[1]
+ 25 * inpPtr2[0] + 128) >> 8) + 16;
// Moving to next column
yStartPtr[1] = (uint8)((66 * inpPtr[3] + 129 * inpPtr[4]
+ 25 * inpPtr[5] + 128) >> 8) + 16;
yStartPtr2[1] = (uint8)((66 * inpPtr2[3] + 129 * inpPtr2[4]
+ 25 * inpPtr2[5] + 128) >> 8 ) + 16;
// U
uStartPtr[0] = (uint8)((-38 * inpPtr[0] - 74 * inpPtr[1] +
112 * inpPtr[2] + 128) >> 8) + 128;
// V
vStartPtr[0] = (uint8)((112 * inpPtr[0] -94 * inpPtr[1] -
18 * inpPtr[2] + 128) >> 8) + 128;
out += 4 * (2 * dst_stride - src_width); yStartPtr += 2;
out2 += 4 * (2 * dst_stride - src_width); yStartPtr2 += 2;
} uStartPtr++;
vStartPtr++;
inpPtr += 6;
inpPtr2 += 6;
} // end for w
yStartPtr += dst_ystride + dst_ystride - src_width;
yStartPtr2 += dst_ystride + dst_ystride - src_width;
uStartPtr += dst_ustride + dst_ustride - ((src_width + 1) >> 1);
vStartPtr += dst_vstride + dst_vstride - ((src_width + 1) >> 1);
inpPtr -= 3 * (2 * src_stride + src_width);
inpPtr2 -= 3 * (2 * src_stride + src_width);
} // end for h
return 0; return 0;
} }
int int
ConvertABGRToI420(const uint8* src_frame, int src_stride, Convert::ABGRToI420(const uint8* src_frame, int src_stride,
uint8* dst_yplane, int dst_ystride, uint8* dst_yplane, int dst_ystride,
uint8* dst_uplane, int dst_ustride, uint8* dst_uplane, int dst_ustride,
uint8* dst_vplane, int dst_vstride, uint8* dst_vplane, int dst_vstride,
int src_width, int src_width, int src_height)
int src_height
)
{ {
if (src_width == 0 || src_height == 0 || dst_ystride == 0 || if (src_frame == NULL || dst_yplane == NULL ||
dst_ustride == 0 || dst_vstride == 0 || src_stride == 0) dst_vplane == NULL || dst_vplane == NULL){
{
return -1; return -1;
} }
...@@ -1363,10 +1105,8 @@ ConvertABGRToI420(const uint8* src_frame, int src_stride, ...@@ -1363,10 +1105,8 @@ ConvertABGRToI420(const uint8* src_frame, int src_stride,
inpPtr = src_frame; inpPtr = src_frame;
inpPtr2 = inpPtr + 4 * src_stride; inpPtr2 = inpPtr + 4 * src_stride;
int h, w; int h, w;
for (h = 0; h < (src_height >> 1); h++) for (h = 0; h < ((src_height + 1) >> 1); h++){
{ for (w = 0; w < ((src_width + 1) >> 1); w++){
for (w = 0; w < (src_height >> 1); w++)
{
// Y // Y
yStartPtr[0] = (uint8)((66 * inpPtr[1] + 129 * inpPtr[2] yStartPtr[0] = (uint8)((66 * inpPtr[1] + 129 * inpPtr[2]
+ 25 * inpPtr[3] + 128) >> 8) + 16; + 25 * inpPtr[3] + 128) >> 8) + 16;
...@@ -1394,8 +1134,8 @@ ConvertABGRToI420(const uint8* src_frame, int src_stride, ...@@ -1394,8 +1134,8 @@ ConvertABGRToI420(const uint8* src_frame, int src_stride,
yStartPtr += 2 * dst_ystride - src_width; yStartPtr += 2 * dst_ystride - src_width;
yStartPtr2 += 2 * dst_ystride - src_width; yStartPtr2 += 2 * dst_ystride - src_width;
uStartPtr += dst_ustride + dst_ustride - (src_width >> 1); uStartPtr += dst_ustride + dst_ustride - ((src_width + 1) >> 1);
vStartPtr += dst_vstride + dst_vstride - (src_width >> 1); vStartPtr += dst_vstride + dst_vstride - ((src_width + 1) >> 1);
inpPtr += 4 * (2 * src_stride - src_width); inpPtr += 4 * (2 * src_stride - src_width);
inpPtr2 += 4 * (2 * src_stride - src_width); inpPtr2 += 4 * (2 * src_stride - src_width);
} }
...@@ -1405,11 +1145,9 @@ ConvertABGRToI420(const uint8* src_frame, int src_stride, ...@@ -1405,11 +1145,9 @@ ConvertABGRToI420(const uint8* src_frame, int src_stride,
inline inline
uint8 Clip(int32 val) uint8 Clip(int32 val)
{ {
if (val < 0) if (val < 0){
{
return (uint8)0; return (uint8)0;
} else if (val > 255) } else if (val > 255){
{
return (uint8)255; return (uint8)255;
} }
return (uint8)val; return (uint8)val;
...@@ -1455,7 +1193,6 @@ void ...@@ -1455,7 +1193,6 @@ void
add ebx, 8 add ebx, 8
sub ecx, 8 sub ecx, 8
jg loop0 jg loop0
emms emms
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment