mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
libyuv: Adding conversion functions
Review URL: http://webrtc-codereview.appspot.com/213005 git-svn-id: http://libyuv.googlecode.com/svn/trunk@21 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
280f4fd8bb
commit
abe14f80ba
@ -59,6 +59,7 @@ class Convert {
|
|||||||
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_height);
|
int src_width, int src_height);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
I420ToUYVY(const uint8* src_yplane, int src_ystride,
|
I420ToUYVY(const uint8* src_yplane, int src_ystride,
|
||||||
const uint8* src_uplane, int src_ustride,
|
const uint8* src_uplane, int src_ustride,
|
||||||
@ -97,19 +98,35 @@ class Convert {
|
|||||||
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_height);
|
int src_width, int src_height);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
I420ToABGR(const uint8* src_yplane, int src_ystride,
|
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_height);
|
int src_width, int src_height);
|
||||||
int
|
|
||||||
|
static int
|
||||||
I420ToBGRA(const uint8* src_yplane, int src_ystride,
|
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_height);
|
int src_width, int src_height);
|
||||||
|
|
||||||
|
static int`
|
||||||
|
BGRAToI420(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 static
|
||||||
|
ARGBToI420(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
|
static int
|
||||||
NV12ToRGB565(const uint8* src_yplane, int src_ystride,
|
NV12ToRGB565(const uint8* src_yplane, int src_ystride,
|
||||||
const uint8* src_uvplane, int src_uvstride,
|
const uint8* src_uvplane, int src_uvstride,
|
||||||
|
|||||||
@ -969,7 +969,6 @@ Convert::RGB24ToI420(const uint8* src_frame, int src_stride,
|
|||||||
const uint8* inpPtr2;
|
const uint8* inpPtr2;
|
||||||
int h, w;
|
int h, w;
|
||||||
|
|
||||||
// Assuming RGB in a bottom up orientation.
|
|
||||||
yStartPtr = dst_yplane;
|
yStartPtr = dst_yplane;
|
||||||
yStartPtr2 = yStartPtr + dst_ystride;
|
yStartPtr2 = yStartPtr + dst_ystride;
|
||||||
uStartPtr = dst_uplane;
|
uStartPtr = dst_uplane;
|
||||||
@ -1032,7 +1031,6 @@ Convert::RAWToI420(const uint8* src_frame, int src_stride,
|
|||||||
const uint8* inpPtr2;
|
const uint8* inpPtr2;
|
||||||
int h, w;
|
int h, w;
|
||||||
|
|
||||||
// Assuming RGB in a bottom up orientation.
|
|
||||||
yStartPtr = dst_yplane;
|
yStartPtr = dst_yplane;
|
||||||
yStartPtr2 = yStartPtr + dst_ystride;
|
yStartPtr2 = yStartPtr + dst_ystride;
|
||||||
uStartPtr = dst_uplane;
|
uStartPtr = dst_uplane;
|
||||||
@ -1079,6 +1077,133 @@ Convert::RAWToI420(const uint8* src_frame, int src_stride,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Convert::BGRAToI420(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_frame == NULL || dst_yplane == NULL ||
|
||||||
|
dst_vplane == NULL || dst_vplane == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
uint8* yStartPtr;
|
||||||
|
uint8* yStartPtr2;
|
||||||
|
uint8* uStartPtr;
|
||||||
|
uint8* vStartPtr;
|
||||||
|
const uint8* inpPtr;
|
||||||
|
const uint8* inpPtr2;
|
||||||
|
int h, w;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
yStartPtr2[0] = (uint8)((66 * inpPtr2[1] + 129 * inpPtr2[2]
|
||||||
|
+ 25 * inpPtr2[3] + 128) >> 8) + 16;
|
||||||
|
// Moving to next column
|
||||||
|
yStartPtr[1] = (uint8)((66 * inpPtr[5] + 129 * inpPtr[6]
|
||||||
|
+ 25 * inpPtr[7] + 128) >> 8) + 16;
|
||||||
|
yStartPtr2[1] = (uint8)((66 * inpPtr2[5] + 129 * inpPtr2[6]
|
||||||
|
+ 25 * inpPtr2[7] + 128) >> 8 ) + 16;
|
||||||
|
// U
|
||||||
|
uStartPtr[0] = (uint8)((-38 * inpPtr[1] - 74 * inpPtr[2] +
|
||||||
|
112 * inpPtr[3] + 128) >> 8) + 128;
|
||||||
|
// V
|
||||||
|
vStartPtr[0] = (uint8)((112 * inpPtr[1] -94 * inpPtr[2] -
|
||||||
|
18 * inpPtr[3] + 128) >> 8) + 128;
|
||||||
|
|
||||||
|
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
|
||||||
|
Convert::ARGBToI420(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_frame == NULL || dst_yplane == NULL ||
|
||||||
|
dst_vplane == NULL || dst_vplane == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
uint8* yStartPtr;
|
||||||
|
uint8* yStartPtr2;
|
||||||
|
uint8* uStartPtr;
|
||||||
|
uint8* vStartPtr;
|
||||||
|
const uint8* inpPtr;
|
||||||
|
const uint8* inpPtr2;
|
||||||
|
int h, w;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
yStartPtr2[0] = (uint8)((66 * inpPtr2[2] + 129 * inpPtr2[1]
|
||||||
|
+ 25 * inpPtr2[0] + 128) >> 8) + 16;
|
||||||
|
// Moving to next column
|
||||||
|
yStartPtr[1] = (uint8)((66 * inpPtr[6] + 129 * inpPtr[5]
|
||||||
|
+ 25 * inpPtr[4] + 128) >> 8) + 16;
|
||||||
|
yStartPtr2[1] = (uint8)((66 * inpPtr2[5] + 129 * inpPtr2[4]
|
||||||
|
+ 25 * inpPtr2[3] + 128) >> 8 ) + 16;
|
||||||
|
// U
|
||||||
|
uStartPtr[0] = (uint8)((-38 * inpPtr[2] - 74 * inpPtr[1] +
|
||||||
|
112 * inpPtr[0] + 128) >> 8) + 128;
|
||||||
|
// V
|
||||||
|
vStartPtr[0] = (uint8)((112 * inpPtr[2] -94 * inpPtr[1] -
|
||||||
|
18 * inpPtr[0] + 128) >> 8) + 128;
|
||||||
|
|
||||||
|
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
|
int
|
||||||
Convert::ABGRToI420(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,
|
||||||
@ -1105,24 +1230,26 @@ Convert::ABGRToI420(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;
|
||||||
|
|
||||||
|
// RGBA in memory
|
||||||
for (h = 0; h < ((src_height + 1) >> 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) >> 1); w++){
|
||||||
// Y
|
// Y
|
||||||
yStartPtr[0] = (uint8)((66 * inpPtr[1] + 129 * inpPtr[2]
|
yStartPtr[0] = (uint8)((66 * inpPtr[0] + 129 * inpPtr[1]
|
||||||
+ 25 * inpPtr[3] + 128) >> 8) + 16;
|
+ 25 * inpPtr[2] + 128) >> 8) + 16;
|
||||||
yStartPtr2[0] = (uint8)((66 * inpPtr2[1] + 129 * inpPtr2[2]
|
yStartPtr2[0] = (uint8)((66 * inpPtr2[0] + 129 * inpPtr2[1]
|
||||||
+ 25 * inpPtr2[3] + 128) >> 8) + 16;
|
+ 25 * inpPtr2[2] + 128) >> 8) + 16;
|
||||||
// Moving to next column
|
// Moving to next column
|
||||||
yStartPtr[1] = (uint8)((66 * inpPtr[5] + 129 * inpPtr[6]
|
yStartPtr[1] = (uint8)((66 * inpPtr[4] + 129 * inpPtr[5]
|
||||||
+ 25 * inpPtr[7] + 128) >> 8) + 16;
|
+ 25 * inpPtr[6] + 128) >> 8) + 16;
|
||||||
yStartPtr2[1] = (uint8)((66 * inpPtr2[5] + 129 * inpPtr2[6]
|
yStartPtr2[1] = (uint8)((66 * inpPtr2[4] + 129 * inpPtr2[5]
|
||||||
+ 25 * inpPtr2[7] + 128) >> 8) + 16;
|
+ 25 * inpPtr2[6] + 128) >> 8) + 16;
|
||||||
// U
|
// U
|
||||||
uStartPtr[0] = (uint8)((-38 * inpPtr[1] - 74 * inpPtr[2]
|
uStartPtr[0] = (uint8)((-38 * inpPtr[0] - 74 * inpPtr[1]
|
||||||
+ 112 * inpPtr[3] + 128) >> 8) + 128;
|
+ 112 * inpPtr[2] + 128) >> 8) + 128;
|
||||||
// V
|
// V
|
||||||
vStartPtr[0] = (uint8)((112 * inpPtr[1] - 94 * inpPtr[2]
|
vStartPtr[0] = (uint8)((112 * inpPtr[0] - 94 * inpPtr[1]
|
||||||
- 18 * inpPtr[3] + 128) >> 8) + 128;
|
- 18 * inpPtr[2] + 128) >> 8) + 128;
|
||||||
|
|
||||||
yStartPtr += 2;
|
yStartPtr += 2;
|
||||||
yStartPtr2 += 2;
|
yStartPtr2 += 2;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user