Commit 392cc2c4 authored by fbarchard@google.com's avatar fbarchard@google.com

MJPGToI420

BUG=none
TEST=none
Review URL: https://webrtc-codereview.appspot.com/396014

git-svn-id: http://libyuv.googlecode.com/svn/trunk@181 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 8536b2f3
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 180 Version: 181
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -20,6 +20,8 @@ struct jpeg_source_mgr; ...@@ -20,6 +20,8 @@ struct jpeg_source_mgr;
namespace libyuv { namespace libyuv {
static const uint32 kUnknownDataSize = 0xFFFFFFFF;
enum JpegSubsamplingType { enum JpegSubsamplingType {
kJpegYuv420, kJpegYuv420,
kJpegYuv422, kJpegYuv422,
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ #ifndef INCLUDE_LIBYUV_VERSION_H_
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 180 #define LIBYUV_VERSION 181
#endif // INCLUDE_LIBYUV_VERSION_H_ #endif // INCLUDE_LIBYUV_VERSION_H_
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include "libyuv/basic_types.h" #include "libyuv/basic_types.h"
#include "libyuv/cpu_id.h" #include "libyuv/cpu_id.h"
#include "libyuv/format_conversion.h" #include "libyuv/format_conversion.h"
#ifdef HAVE_JPEG
#include "libyuv/mjpeg_decoder.h"
#endif
#include "libyuv/planar_functions.h" #include "libyuv/planar_functions.h"
#include "libyuv/rotate.h" #include "libyuv/rotate.h"
#include "libyuv/video_common.h" #include "libyuv/video_common.h"
...@@ -1363,12 +1366,202 @@ int ARGB4444ToI420(const uint8* src_argb4444, int src_stride_argb4444, ...@@ -1363,12 +1366,202 @@ int ARGB4444ToI420(const uint8* src_argb4444, int src_stride_argb4444,
return 0; return 0;
} }
#ifdef HAVE_JPEG
struct I420Buffers {
uint8* y;
int y_stride;
uint8* u;
int u_stride;
uint8* v;
int v_stride;
int w;
int h;
};
static void JpegCopyI420(void* opaque,
const uint8* const* data,
const int* strides,
int rows) {
I420Buffers* dest = static_cast<I420Buffers*>(opaque);
I420Copy(data[0], strides[0],
data[1], strides[1],
data[2], strides[2],
dest->y, dest->y_stride,
dest->u, dest->u_stride,
dest->v, dest->v_stride,
dest->w, rows);
dest->y += rows * dest->y_stride;
dest->u += ((rows + 1) >> 1) * dest->u_stride;
dest->v += ((rows + 1) >> 1) * dest->v_stride;
dest->h -= rows;
}
static void JpegI422ToI420(void* opaque,
const uint8* const* data,
const int* strides,
int rows) {
I420Buffers* dest = static_cast<I420Buffers*>(opaque);
I422ToI420(data[0], strides[0],
data[1], strides[1],
data[2], strides[2],
dest->y, dest->y_stride,
dest->u, dest->u_stride,
dest->v, dest->v_stride,
dest->w, rows);
dest->y += rows * dest->y_stride;
dest->u += ((rows + 1) >> 1) * dest->u_stride;
dest->v += ((rows + 1) >> 1) * dest->v_stride;
dest->h -= rows;
}
static void JpegI444ToI420(void* opaque,
const uint8* const* data,
const int* strides,
int rows) {
I420Buffers* dest = static_cast<I420Buffers*>(opaque);
I444ToI420(data[0], strides[0],
data[1], strides[1],
data[2], strides[2],
dest->y, dest->y_stride,
dest->u, dest->u_stride,
dest->v, dest->v_stride,
dest->w, rows);
dest->y += rows * dest->y_stride;
dest->u += ((rows + 1) >> 1) * dest->u_stride;
dest->v += ((rows + 1) >> 1) * dest->v_stride;
dest->h -= rows;
}
static void JpegI411ToI420(void* opaque,
const uint8* const* data,
const int* strides,
int rows) {
I420Buffers* dest = static_cast<I420Buffers*>(opaque);
I411ToI420(data[0], strides[0],
data[1], strides[1],
data[2], strides[2],
dest->y, dest->y_stride,
dest->u, dest->u_stride,
dest->v, dest->v_stride,
dest->w, rows);
dest->y += rows * dest->y_stride;
dest->u += ((rows + 1) >> 1) * dest->u_stride;
dest->v += ((rows + 1) >> 1) * dest->v_stride;
dest->h -= rows;
}
static void JpegI400ToI420(void* opaque,
const uint8* const* data,
const int* strides,
int rows) {
I420Buffers* dest = static_cast<I420Buffers*>(opaque);
I400ToI420(data[0], strides[0],
dest->y, dest->y_stride,
dest->u, dest->u_stride,
dest->v, dest->v_stride,
dest->w, rows);
dest->y += rows * dest->y_stride;
dest->u += ((rows + 1) >> 1) * dest->u_stride;
dest->v += ((rows + 1) >> 1) * dest->v_stride;
dest->h -= rows;
}
// MJPG (Motion JPeg) to I420
// TODO(fbarchard): review w and h requirement. dw and dh may be enough.
int MJPGToI420(const uint8* sample,
size_t sample_size,
uint8* y, int y_stride,
uint8* u, int u_stride,
uint8* v, int v_stride,
int w, int h,
int dw, int dh) {
if (sample_size == kUnknownDataSize) {
// ERROR: MJPEG frame size unknown
return -1;
}
// TODO(fbarchard): Port to C
MJpegDecoder* mjpeg_decoder = new MJpegDecoder();
bool ret = mjpeg_decoder->LoadFrame(sample, sample_size);
if (ret && (mjpeg_decoder->GetWidth() != w ||
mjpeg_decoder->GetHeight() != h)) {
// ERROR: MJPEG frame has unexpected dimensions
mjpeg_decoder->UnloadFrame();
delete mjpeg_decoder;
return 1; // runtime failure
}
if (ret) {
I420Buffers bufs = { y, y_stride, u, u_stride, v, v_stride, dw, dh };
// YUV420
if (mjpeg_decoder->GetColorSpace() ==
MJpegDecoder::kColorSpaceYCbCr &&
mjpeg_decoder->GetNumComponents() == 3 &&
mjpeg_decoder->GetVertSampFactor(0) == 2 &&
mjpeg_decoder->GetHorizSampFactor(0) == 2 &&
mjpeg_decoder->GetVertSampFactor(1) == 1 &&
mjpeg_decoder->GetHorizSampFactor(1) == 1 &&
mjpeg_decoder->GetVertSampFactor(2) == 1 &&
mjpeg_decoder->GetHorizSampFactor(2) == 1) {
ret = mjpeg_decoder->DecodeToCallback(&JpegCopyI420, &bufs, dw, dh);
// YUV422
} else if (mjpeg_decoder->GetColorSpace() ==
MJpegDecoder::kColorSpaceYCbCr &&
mjpeg_decoder->GetNumComponents() == 3 &&
mjpeg_decoder->GetVertSampFactor(0) == 1 &&
mjpeg_decoder->GetHorizSampFactor(0) == 2 &&
mjpeg_decoder->GetVertSampFactor(1) == 1 &&
mjpeg_decoder->GetHorizSampFactor(1) == 1 &&
mjpeg_decoder->GetVertSampFactor(2) == 1 &&
mjpeg_decoder->GetHorizSampFactor(2) == 1) {
ret = mjpeg_decoder->DecodeToCallback(&JpegI422ToI420, &bufs, dw, dh);
// YUV444
} else if (mjpeg_decoder->GetColorSpace() ==
MJpegDecoder::kColorSpaceYCbCr &&
mjpeg_decoder->GetNumComponents() == 3 &&
mjpeg_decoder->GetVertSampFactor(0) == 1 &&
mjpeg_decoder->GetHorizSampFactor(0) == 1 &&
mjpeg_decoder->GetVertSampFactor(1) == 1 &&
mjpeg_decoder->GetHorizSampFactor(1) == 1 &&
mjpeg_decoder->GetVertSampFactor(2) == 1 &&
mjpeg_decoder->GetHorizSampFactor(2) == 1) {
ret = mjpeg_decoder->DecodeToCallback(&JpegI444ToI420, &bufs, dw, dh);
// YUV411
} else if (mjpeg_decoder->GetColorSpace() ==
MJpegDecoder::kColorSpaceYCbCr &&
mjpeg_decoder->GetNumComponents() == 3 &&
mjpeg_decoder->GetVertSampFactor(0) == 1 &&
mjpeg_decoder->GetHorizSampFactor(0) == 4 &&
mjpeg_decoder->GetVertSampFactor(1) == 1 &&
mjpeg_decoder->GetHorizSampFactor(1) == 1 &&
mjpeg_decoder->GetVertSampFactor(2) == 1 &&
mjpeg_decoder->GetHorizSampFactor(2) == 1) {
ret = mjpeg_decoder->DecodeToCallback(&JpegI411ToI420, &bufs, dw, dh);
// YUV400
} else if (mjpeg_decoder->GetColorSpace() ==
MJpegDecoder::kColorSpaceGrayscale &&
mjpeg_decoder->GetNumComponents() == 1 &&
mjpeg_decoder->GetVertSampFactor(0) == 1 &&
mjpeg_decoder->GetHorizSampFactor(0) == 1) {
ret = mjpeg_decoder->DecodeToCallback(&JpegI400ToI420, &bufs, dw, dh);
} else {
// TODO(fbarchard): Implement conversion for any other colorspace/sample
// factors that occur in practice. 411 is supported by libjpeg
// ERROR: Unable to convert MJPEG frame because format is not supported
mjpeg_decoder->UnloadFrame();
delete mjpeg_decoder;
return 1;
}
}
delete mjpeg_decoder;
return 0;
}
#endif
// Convert camera sample to I420 with cropping, rotation and vertical flip. // Convert camera sample to I420 with cropping, rotation and vertical flip.
// src_width is used for source stride computation // src_width is used for source stride computation
// src_height is used to compute location of planes, and indicate inversion // src_height is used to compute location of planes, and indicate inversion
// TODO(fbarchard): sample_size should be used to ensure the low levels do // sample_size is measured in bytes and is the size of the frame.
// not read outside the buffer provided. It is measured in bytes and is the // With MJPEG it is the compressed size of the frame.
// size of the frame. With MJPEG it is the compressed size of the frame.
int ConvertToI420(const uint8* sample, size_t sample_size, int ConvertToI420(const uint8* sample, size_t sample_size,
uint8* y, int y_stride, uint8* y, int y_stride,
uint8* u, int u_stride, uint8* u, int u_stride,
...@@ -1389,12 +1582,12 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1389,12 +1582,12 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
if (src_height < 0) { if (src_height < 0) {
inv_dst_height = -inv_dst_height; inv_dst_height = -inv_dst_height;
} }
int r = 0;
switch (format) { switch (format) {
// Single plane formats // Single plane formats
case FOURCC_YUY2: case FOURCC_YUY2:
src = sample + (aligned_src_width * crop_y + crop_x) * 2 ; src = sample + (aligned_src_width * crop_y + crop_x) * 2 ;
YUY2ToI420(src, aligned_src_width * 2, r = YUY2ToI420(src, aligned_src_width * 2,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1402,7 +1595,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1402,7 +1595,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_UYVY: case FOURCC_UYVY:
src = sample + (aligned_src_width * crop_y + crop_x) * 2; src = sample + (aligned_src_width * crop_y + crop_x) * 2;
UYVYToI420(src, aligned_src_width * 2, r = UYVYToI420(src, aligned_src_width * 2,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1413,7 +1606,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1413,7 +1606,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
// pixels come in groups of 6 = 16 bytes // pixels come in groups of 6 = 16 bytes
src = sample + (aligned_src_width + 47) / 48 * 128 * crop_y + src = sample + (aligned_src_width + 47) / 48 * 128 * crop_y +
crop_x / 6 * 16; crop_x / 6 * 16;
V210ToI420(src, (aligned_src_width + 47) / 48 * 128, r = V210ToI420(src, (aligned_src_width + 47) / 48 * 128,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1421,7 +1614,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1421,7 +1614,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_24BG: case FOURCC_24BG:
src = sample + (src_width * crop_y + crop_x) * 3; src = sample + (src_width * crop_y + crop_x) * 3;
RGB24ToI420(src, src_width * 3, r = RGB24ToI420(src, src_width * 3,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1429,7 +1622,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1429,7 +1622,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_RAW: case FOURCC_RAW:
src = sample + (src_width * crop_y + crop_x) * 3; src = sample + (src_width * crop_y + crop_x) * 3;
RAWToI420(src, src_width * 3, r = RAWToI420(src, src_width * 3,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1437,7 +1630,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1437,7 +1630,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_ARGB: case FOURCC_ARGB:
src = sample + (src_width * crop_y + crop_x) * 4; src = sample + (src_width * crop_y + crop_x) * 4;
ARGBToI420(src, src_width * 4, r = ARGBToI420(src, src_width * 4,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1445,7 +1638,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1445,7 +1638,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_BGRA: case FOURCC_BGRA:
src = sample + (src_width * crop_y + crop_x) * 4; src = sample + (src_width * crop_y + crop_x) * 4;
BGRAToI420(src, src_width * 4, r = BGRAToI420(src, src_width * 4,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1453,7 +1646,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1453,7 +1646,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_ABGR: case FOURCC_ABGR:
src = sample + (src_width * crop_y + crop_x) * 4; src = sample + (src_width * crop_y + crop_x) * 4;
ABGRToI420(src, src_width * 4, r = ABGRToI420(src, src_width * 4,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1461,35 +1654,23 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1461,35 +1654,23 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_RGBP: case FOURCC_RGBP:
src = sample + (src_width * crop_y + crop_x) * 2; src = sample + (src_width * crop_y + crop_x) * 2;
RGB565ToI420(src, src_width * 2, r = RGB565ToI420(src, src_width * 2,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
dst_width, inv_dst_height); dst_width, inv_dst_height);
break; break;
// V4L2_PIX_FMT_RGB555 'RGBO'
// Byte 0 Byte 1
// Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
// g2 g1 g0 b4 b3 b2 b1 b0 a r4 r3 r2 r1 r0 g4 g3
// Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// a r4 r3 r2 r1 r0 g4 g3 g2 g1 g0 b4 b3 b2 b1 b0
case FOURCC_RGBO: case FOURCC_RGBO:
src = sample + (src_width * crop_y + crop_x) * 2; src = sample + (src_width * crop_y + crop_x) * 2;
ARGB1555ToI420(src, src_width * 2, r = ARGB1555ToI420(src, src_width * 2,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
dst_width, inv_dst_height); dst_width, inv_dst_height);
break; break;
// V4L2_PIX_FMT_RGB444 'R444'
// Byte 0 Byte 1
// Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
// g3 g2 g1 g0 b3 b2 b1 b0 a3 a2 a1 a0 r3 r2 r1 r0
// Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// a3 a2 a1 a0 r3 r2 r1 r0 g3 g2 g1 g0 b3 b2 b1 b0
case FOURCC_R444: case FOURCC_R444:
src = sample + (src_width * crop_y + crop_x) * 2; src = sample + (src_width * crop_y + crop_x) * 2;
ARGB4444ToI420(src, src_width * 2, r = ARGB4444ToI420(src, src_width * 2,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1499,7 +1680,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1499,7 +1680,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
// by adjusting fourcc. // by adjusting fourcc.
case FOURCC_BGGR: case FOURCC_BGGR:
src = sample + (src_width * crop_y + crop_x); src = sample + (src_width * crop_y + crop_x);
BayerBGGRToI420(src, src_width, r = BayerBGGRToI420(src, src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1508,7 +1689,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1508,7 +1689,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
case FOURCC_GBRG: case FOURCC_GBRG:
src = sample + (src_width * crop_y + crop_x); src = sample + (src_width * crop_y + crop_x);
BayerGBRGToI420(src, src_width, r = BayerGBRGToI420(src, src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1517,7 +1698,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1517,7 +1698,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
case FOURCC_GRBG: case FOURCC_GRBG:
src = sample + (src_width * crop_y + crop_x); src = sample + (src_width * crop_y + crop_x);
BayerGRBGToI420(src, src_width, r = BayerGRBGToI420(src, src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1526,7 +1707,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1526,7 +1707,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
case FOURCC_RGGB: case FOURCC_RGGB:
src = sample + (src_width * crop_y + crop_x); src = sample + (src_width * crop_y + crop_x);
BayerRGGBToI420(src, src_width, r = BayerRGGBToI420(src, src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1535,7 +1716,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1535,7 +1716,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
case FOURCC_I400: case FOURCC_I400:
src = sample + src_width * crop_y + crop_x; src = sample + src_width * crop_y + crop_x;
I400ToI420(src, src_width, r = I400ToI420(src, src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1546,7 +1727,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1546,7 +1727,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
case FOURCC_NV12: case FOURCC_NV12:
src = sample + (src_width * crop_y + crop_x); src = sample + (src_width * crop_y + crop_x);
src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x; src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x;
NV12ToI420Rotate(src, src_width, r = NV12ToI420Rotate(src, src_width,
src_uv, aligned_src_width, src_uv, aligned_src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
...@@ -1557,7 +1738,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1557,7 +1738,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
src = sample + (src_width * crop_y + crop_x); src = sample + (src_width * crop_y + crop_x);
src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x; src_uv = sample + aligned_src_width * (src_height + crop_y / 2) + crop_x;
// Call NV12 but with u and v parameters swapped. // Call NV12 but with u and v parameters swapped.
NV12ToI420Rotate(src, src_width, r = NV12ToI420Rotate(src, src_width,
src_uv, aligned_src_width, src_uv, aligned_src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
...@@ -1566,7 +1747,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1566,7 +1747,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
break; break;
case FOURCC_M420: case FOURCC_M420:
src = sample + (src_width * crop_y) * 12 / 8 + crop_x; src = sample + (src_width * crop_y) * 12 / 8 + crop_x;
M420ToI420(src, src_width, r = M420ToI420(src, src_width,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
v, v_stride, v, v_stride,
...@@ -1576,7 +1757,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1576,7 +1757,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x; src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
src_uv = sample + (src_width + aligned_src_width * 2) * crop_y + src_uv = sample + (src_width + aligned_src_width * 2) * crop_y +
src_width + crop_x * 2; src_width + crop_x * 2;
Q420ToI420(src, src_width * 3, r = Q420ToI420(src, src_width * 3,
src_uv, src_width * 3, src_uv, src_width * 3,
y, y_stride, y, y_stride,
u, u_stride, u, u_stride,
...@@ -1602,7 +1783,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1602,7 +1783,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
src_u = sample + src_width * abs_src_height + src_u = sample + src_width * abs_src_height +
halfwidth * (halfheight + crop_y / 2) + crop_x / 2; halfwidth * (halfheight + crop_y / 2) + crop_x / 2;
} }
I420Rotate(src_y, src_width, r = I420Rotate(src_y, src_width,
src_u, halfwidth, src_u, halfwidth,
src_v, halfwidth, src_v, halfwidth,
y, y_stride, y, y_stride,
...@@ -1628,7 +1809,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1628,7 +1809,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
src_u = sample + src_width * abs_src_height + src_u = sample + src_width * abs_src_height +
halfwidth * (abs_src_height + crop_y) + crop_x / 2; halfwidth * (abs_src_height + crop_y) + crop_x / 2;
} }
I422ToI420(src_y, src_width, r = I422ToI420(src_y, src_width,
src_u, halfwidth, src_u, halfwidth,
src_v, halfwidth, src_v, halfwidth,
y, y_stride, y, y_stride,
...@@ -1649,7 +1830,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1649,7 +1830,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
src_v = sample + src_width * (abs_src_height + crop_y) + crop_x; src_v = sample + src_width * (abs_src_height + crop_y) + crop_x;
src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x;
} }
I444ToI420(src_y, src_width, r = I444ToI420(src_y, src_width,
src_u, src_width, src_u, src_width,
src_v, src_width, src_v, src_width,
y, y_stride, y, y_stride,
...@@ -1665,7 +1846,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1665,7 +1846,7 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
quarterwidth * crop_y + crop_x / 4; quarterwidth * crop_y + crop_x / 4;
const uint8* src_v = sample + src_width * abs_src_height + const uint8* src_v = sample + src_width * abs_src_height +
quarterwidth * (abs_src_height + crop_y) + crop_x / 4; quarterwidth * (abs_src_height + crop_y) + crop_x / 4;
I411ToI420(src_y, src_width, r = I411ToI420(src_y, src_width,
src_u, quarterwidth, src_u, quarterwidth,
src_v, quarterwidth, src_v, quarterwidth,
y, y_stride, y, y_stride,
...@@ -1674,13 +1855,17 @@ int ConvertToI420(const uint8* sample, size_t sample_size, ...@@ -1674,13 +1855,17 @@ int ConvertToI420(const uint8* sample, size_t sample_size,
dst_width, inv_dst_height); dst_width, inv_dst_height);
break; break;
} }
// Formats not supported
case FOURCC_MJPG: case FOURCC_MJPG:
r = MJPGToI420(sample, sample_size,
y, y_stride,
u, u_stride,
v, v_stride,
src_width, abs_src_height, dst_width, inv_dst_height);
break;
default: default:
return -1; // unknown fourcc - return failure code. return -1; // unknown fourcc - return failure code.
} }
return 0; return r;
} }
#ifdef __cplusplus #ifdef __cplusplus
......
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