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