video conversion functions: switching from designated functions to a general one.
BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/686004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2517 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
7760963d04
commit
73db8dbfc2
@ -113,22 +113,6 @@ int ConvertFromYV12(const uint8_t* src_frame, int src_stride,
|
||||
// are not covered by the previous general functions.
|
||||
// Input and output descriptions mostly match the above descriptions, and are
|
||||
// therefore omitted.
|
||||
// Possible additional input value - dst_stride - stride of the dst frame.
|
||||
|
||||
int ConvertI420ToARGB4444(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width,
|
||||
int height,
|
||||
int dst_stride);
|
||||
int ConvertI420ToRGB565(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width,
|
||||
int height);
|
||||
int ConvertI420ToARGB1555(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width,
|
||||
int height,
|
||||
int dst_stride);
|
||||
int ConvertRGB24ToARGB(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height,
|
||||
@ -136,9 +120,6 @@ int ConvertRGB24ToARGB(const uint8_t* src_frame,
|
||||
int ConvertNV12ToRGB565(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height);
|
||||
int ConvertI420ToARGB8888(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height);
|
||||
|
||||
// Mirror functions
|
||||
// The following 2 functions perform mirroring on a given image
|
||||
|
@ -87,83 +87,6 @@ int CalcBufferSize(VideoType type, int width, int height) {
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
int ConvertI420ToARGB8888(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height) {
|
||||
int abs_height = (height < 0) ? -height : height;
|
||||
int half_width = (width + 1) >> 1;
|
||||
int half_height = (abs_height + 1) >> 1;
|
||||
const uint8_t* src_y = src_frame;
|
||||
const uint8_t* src_u = src_y + width * abs_height;
|
||||
const uint8_t* src_v = src_u + half_width * half_height;
|
||||
int src_stride_y = width;
|
||||
|
||||
return libyuv::I420ToARGB(src_y, src_stride_y,
|
||||
src_u, half_width,
|
||||
src_v, half_width,
|
||||
dst_frame, width * 4,
|
||||
width, height);
|
||||
}
|
||||
|
||||
int ConvertI420ToARGB4444(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height,
|
||||
int dst_stride) {
|
||||
if (dst_stride == 0 || dst_stride == width)
|
||||
dst_stride = 2 * width;
|
||||
int abs_height = (height < 0) ? -height : height;
|
||||
int half_width = (width + 1) >> 1;
|
||||
int half_height = (abs_height + 1) >> 1;
|
||||
const uint8_t* yplane = src_frame;
|
||||
const uint8_t* uplane = src_frame + width * abs_height;
|
||||
const uint8_t* vplane = uplane + half_width * half_height;
|
||||
|
||||
return libyuv::I420ToARGB4444(yplane, width,
|
||||
uplane, half_width,
|
||||
vplane, half_width,
|
||||
dst_frame, dst_stride,
|
||||
width, height);
|
||||
}
|
||||
|
||||
int ConvertI420ToRGB565(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height) {
|
||||
int abs_height = (height < 0) ? -height : height;
|
||||
int half_width = (width + 1) >> 1;
|
||||
int half_height = (abs_height + 1) >> 1;
|
||||
const uint8_t* yplane = src_frame;
|
||||
const uint8_t* uplane = yplane + width * abs_height;
|
||||
const uint8_t* vplane = uplane + half_width * half_height;
|
||||
|
||||
return libyuv::I420ToRGB565(yplane, width,
|
||||
uplane, half_width,
|
||||
vplane, half_width,
|
||||
dst_frame, width * 2,
|
||||
width, height);
|
||||
}
|
||||
|
||||
int ConvertI420ToARGB1555(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height,
|
||||
int dst_stride) {
|
||||
if (dst_stride == 0 || dst_stride == width)
|
||||
dst_stride = 2 * width;
|
||||
else if (dst_stride < 2 * width)
|
||||
return -1;
|
||||
int abs_height = (height < 0) ? -height : height;
|
||||
int half_width = (width + 1) >> 1;
|
||||
int half_height = (abs_height + 1) >> 1;
|
||||
const uint8_t* yplane = src_frame;
|
||||
const uint8_t* uplane = src_frame + width * abs_height;
|
||||
const uint8_t* vplane = uplane + half_width * half_height;
|
||||
|
||||
return libyuv::I420ToARGB1555(yplane, width,
|
||||
uplane, half_width,
|
||||
vplane, half_width,
|
||||
dst_frame, dst_stride,
|
||||
width, height);
|
||||
}
|
||||
|
||||
int ConvertNV12ToRGB565(const uint8_t* src_frame,
|
||||
uint8_t* dst_frame,
|
||||
int width, int height) {
|
||||
@ -216,11 +139,6 @@ int ConvertVideoType(VideoType video_type) {
|
||||
return libyuv::FOURCC_ABGR;
|
||||
case kRGB565:
|
||||
return libyuv::FOURCC_RGBP;
|
||||
case kARGB4444:
|
||||
case kARGB1555:
|
||||
// TODO(mikhal): Not supported;
|
||||
assert(false);
|
||||
return libyuv::FOURCC_ANY;
|
||||
case kYUY2:
|
||||
return libyuv::FOURCC_YUY2;
|
||||
case kUYVY:
|
||||
@ -235,6 +153,10 @@ int ConvertVideoType(VideoType video_type) {
|
||||
return libyuv::FOURCC_ARGB;
|
||||
case kBGRA:
|
||||
return libyuv::FOURCC_BGRA;
|
||||
case kARGB4444:
|
||||
return libyuv::FOURCC_R444;
|
||||
case kARGB1555:
|
||||
return libyuv::FOURCC_RGBO;
|
||||
}
|
||||
assert(false);
|
||||
return libyuv::FOURCC_ANY;
|
||||
|
@ -985,84 +985,22 @@ int DirectDrawChannel::DeliverFrame(unsigned char* buffer, int bufferSize,
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char* ptr = (unsigned char*) ddsd.lpSurface;
|
||||
// ddsd.lPitch; distance in bytes
|
||||
|
||||
|
||||
switch (_incomingVideoType)
|
||||
{
|
||||
case kI420:
|
||||
{
|
||||
switch (_blitVideoType)
|
||||
{
|
||||
case kYUY2:
|
||||
case kUYVY:
|
||||
case kIYUV: // same as kYV12
|
||||
case kYV12:
|
||||
ConvertFromI420(buffer, _width,
|
||||
_blitVideoType, 0,
|
||||
_width, _height,
|
||||
ptr);
|
||||
break;
|
||||
case kRGB24:
|
||||
{
|
||||
_tempRenderBuffer.VerifyAndAllocate(_width * _height * 3);
|
||||
unsigned char *ptrTempBuffer = _tempRenderBuffer.Buffer();
|
||||
ConvertFromI420(buffer, _width, kRGB24, 0, _width, _height,
|
||||
ptrTempBuffer);
|
||||
for (int i = 0; i < _height; i++)
|
||||
{
|
||||
memcpy(ptr, ptrTempBuffer, _width * 3);
|
||||
ptrTempBuffer += _width * 3;
|
||||
ptr += ddsd.lPitch;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kARGB:
|
||||
ConvertFromI420(buffer, ddsd.lPitch, kARGB, 0,
|
||||
_width, _height, ptr);
|
||||
break;
|
||||
case kARGB4444:
|
||||
ConvertI420ToARGB4444(buffer, ptr, _width, _height,
|
||||
(ddsd.lPitch >> 1) - _width);
|
||||
break;
|
||||
case kARGB1555:
|
||||
ConvertI420ToARGB1555(buffer, ptr, _width, _height,
|
||||
(ddsd.lPitch >> 1) - _width);
|
||||
break;
|
||||
case kRGB565:
|
||||
{
|
||||
_tempRenderBuffer.VerifyAndAllocate(_width * _height * 2);
|
||||
unsigned char *ptrTempBuffer = _tempRenderBuffer.Buffer();
|
||||
ConvertI420ToRGB565(buffer, ptrTempBuffer, _width, _height);
|
||||
ptr += ddsd.lPitch * (_height - 1);
|
||||
for (int i = 0; i < _height; i++)
|
||||
{
|
||||
memcpy(ptr, ptrTempBuffer, _width * 2);
|
||||
ptrTempBuffer += _width * 2;
|
||||
ptr -= ddsd.lPitch;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false &&
|
||||
"DirectDrawChannel::DeliverFrame unknown blitVideoType");
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, -1,
|
||||
"%s unknown blitVideoType %d",
|
||||
__FUNCTION__, _blitVideoType);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false &&
|
||||
"DirectDrawChannel::DeliverFrame wrong incomming video type");
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, -1,
|
||||
"%s wrong incomming video type:%d",
|
||||
__FUNCTION__, _incomingVideoType);
|
||||
int ret = 0;
|
||||
if (_incomingVideoType == kI420) {
|
||||
unsigned char* ptr = static_cast<unsigned char*>(ddsd.lpSurface);
|
||||
ret = ConvertFromI420(buffer, ddsd.lPitch, _blitVideoType, 0,
|
||||
_width, _height, ptr);
|
||||
} else {
|
||||
assert(false &&
|
||||
"DirectDrawChannel::DeliverFrame wrong incoming video type");
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, -1,
|
||||
"%s wrong incoming video type:%d",
|
||||
__FUNCTION__, _incomingVideoType);
|
||||
ret = -1;
|
||||
}
|
||||
_offScreenSurfaceUpdated = true;
|
||||
offScreenSurface->Unlock(NULL);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DirectDrawChannel::BlitFromOffscreenBufferToMixingBuffer(
|
||||
|
@ -187,6 +187,9 @@ WebRtc_Word32 ViEExternalRendererImpl::RenderFrame(
|
||||
case kVideoUYVY:
|
||||
case kVideoARGB:
|
||||
case kVideoRGB24:
|
||||
case kVideoRGB565:
|
||||
case kVideoARGB4444:
|
||||
case kVideoARGB1555 :
|
||||
{
|
||||
ConvertFromI420(video_frame.Buffer(), video_frame.Width(), type, 0,
|
||||
video_frame.Width(), video_frame.Height(),
|
||||
@ -196,18 +199,6 @@ WebRtc_Word32 ViEExternalRendererImpl::RenderFrame(
|
||||
case kVideoIYUV:
|
||||
// no conversion available
|
||||
break;
|
||||
case kVideoRGB565:
|
||||
ConvertI420ToRGB565(video_frame.Buffer(), converted_frame_->Buffer(),
|
||||
video_frame.Width(), video_frame.Height());
|
||||
break;
|
||||
case kVideoARGB4444:
|
||||
ConvertI420ToARGB4444(video_frame.Buffer(), converted_frame_->Buffer(),
|
||||
video_frame.Width(), video_frame.Height(), 0);
|
||||
break;
|
||||
case kVideoARGB1555 :
|
||||
ConvertI420ToARGB1555(video_frame.Buffer(), converted_frame_->Buffer(),
|
||||
video_frame.Width(), video_frame.Height(), 0);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
out_frame = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user