mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
Change name of variable for convert to crop_width/height instead of dst_width/height to clarify that it is used to crop the original before rotation and is not the final destination size.
BUG=none TESTED=local builds still work R=wjia@google.com, wjia@webrtc.org Review URL: https://webrtc-codereview.appspot.com/5859004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@915 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
parent
6f0a1dca2c
commit
f2bd31538e
@ -1,6 +1,6 @@
|
|||||||
Name: libyuv
|
Name: libyuv
|
||||||
URL: http://code.google.com/p/libyuv/
|
URL: http://code.google.com/p/libyuv/
|
||||||
Version: 912
|
Version: 915
|
||||||
License: BSD
|
License: BSD
|
||||||
License File: LICENSE
|
License File: LICENSE
|
||||||
|
|
||||||
|
|||||||
@ -229,7 +229,7 @@ int MJPGSize(const uint8* sample, size_t sample_size,
|
|||||||
// crop_y = (src_height - dst_height) / 2
|
// crop_y = (src_height - dst_height) / 2
|
||||||
// "src_width" / "src_height" is size of src_frame in pixels.
|
// "src_width" / "src_height" is size of src_frame in pixels.
|
||||||
// "src_height" can be negative indicating a vertically flipped image source.
|
// "src_height" can be negative indicating a vertically flipped image source.
|
||||||
// "dst_width" / "dst_height" is size of destination to crop to.
|
// "crop_width" / "crop_height" is the size to crop the src to.
|
||||||
// Must be less than or equal to src_width/src_height
|
// Must be less than or equal to src_width/src_height
|
||||||
// Cropping parameters are pre-rotation.
|
// Cropping parameters are pre-rotation.
|
||||||
// "rotation" can be 0, 90, 180 or 270.
|
// "rotation" can be 0, 90, 180 or 270.
|
||||||
@ -242,7 +242,7 @@ int ConvertToI420(const uint8* src_frame, size_t src_size,
|
|||||||
uint8* dst_v, int dst_stride_v,
|
uint8* dst_v, int dst_stride_v,
|
||||||
int crop_x, int crop_y,
|
int crop_x, int crop_y,
|
||||||
int src_width, int src_height,
|
int src_width, int src_height,
|
||||||
int dst_width, int dst_height,
|
int crop_width, int crop_height,
|
||||||
enum RotationMode rotation,
|
enum RotationMode rotation,
|
||||||
uint32 format);
|
uint32 format);
|
||||||
|
|
||||||
|
|||||||
@ -202,7 +202,7 @@ int MJPGToARGB(const uint8* sample, size_t sample_size,
|
|||||||
// crop_y = (src_height - dst_height) / 2
|
// crop_y = (src_height - dst_height) / 2
|
||||||
// "src_width" / "src_height" is size of src_frame in pixels.
|
// "src_width" / "src_height" is size of src_frame in pixels.
|
||||||
// "src_height" can be negative indicating a vertically flipped image source.
|
// "src_height" can be negative indicating a vertically flipped image source.
|
||||||
// "dst_width" / "dst_height" is size of destination to crop to.
|
// "crop_width" / "crop_height" is the size to crop the src to.
|
||||||
// Must be less than or equal to src_width/src_height
|
// Must be less than or equal to src_width/src_height
|
||||||
// Cropping parameters are pre-rotation.
|
// Cropping parameters are pre-rotation.
|
||||||
// "rotation" can be 0, 90, 180 or 270.
|
// "rotation" can be 0, 90, 180 or 270.
|
||||||
@ -213,7 +213,7 @@ int ConvertToARGB(const uint8* src_frame, size_t src_size,
|
|||||||
uint8* dst_argb, int dst_stride_argb,
|
uint8* dst_argb, int dst_stride_argb,
|
||||||
int crop_x, int crop_y,
|
int crop_x, int crop_y,
|
||||||
int src_width, int src_height,
|
int src_width, int src_height,
|
||||||
int dst_width, int dst_height,
|
int crop_width, int crop_height,
|
||||||
enum RotationMode rotation,
|
enum RotationMode rotation,
|
||||||
uint32 format);
|
uint32 format);
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,6 @@
|
|||||||
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
|
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
|
||||||
#define INCLUDE_LIBYUV_VERSION_H_
|
#define INCLUDE_LIBYUV_VERSION_H_
|
||||||
|
|
||||||
#define LIBYUV_VERSION 912
|
#define LIBYUV_VERSION 915
|
||||||
|
|
||||||
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
|
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
|
||||||
|
|||||||
@ -31,46 +31,46 @@ extern "C" {
|
|||||||
// With MJPEG it is the compressed size of the frame.
|
// With MJPEG it is the compressed size of the frame.
|
||||||
LIBYUV_API
|
LIBYUV_API
|
||||||
int ConvertToARGB(const uint8* sample, size_t sample_size,
|
int ConvertToARGB(const uint8* sample, size_t sample_size,
|
||||||
uint8* dst_argb, int argb_stride,
|
uint8* crop_argb, int argb_stride,
|
||||||
int crop_x, int crop_y,
|
int crop_x, int crop_y,
|
||||||
int src_width, int src_height,
|
int src_width, int src_height,
|
||||||
int dst_width, int dst_height,
|
int crop_width, int crop_height,
|
||||||
RotationMode rotation,
|
RotationMode rotation,
|
||||||
uint32 fourcc) {
|
uint32 fourcc) {
|
||||||
uint32 format = CanonicalFourCC(fourcc);
|
uint32 format = CanonicalFourCC(fourcc);
|
||||||
if (dst_argb == NULL || sample == NULL ||
|
if (crop_argb == NULL || sample == NULL ||
|
||||||
src_width <= 0 || dst_width <= 0 ||
|
src_width <= 0 || crop_width <= 0 ||
|
||||||
src_height == 0 || dst_height == 0) {
|
src_height == 0 || crop_height == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int aligned_src_width = (src_width + 1) & ~1;
|
int aligned_src_width = (src_width + 1) & ~1;
|
||||||
const uint8* src;
|
const uint8* src;
|
||||||
const uint8* src_uv;
|
const uint8* src_uv;
|
||||||
int abs_src_height = (src_height < 0) ? -src_height : src_height;
|
int abs_src_height = (src_height < 0) ? -src_height : src_height;
|
||||||
int inv_dst_height = (dst_height < 0) ? -dst_height : dst_height;
|
int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height;
|
||||||
if (src_height < 0) {
|
if (src_height < 0) {
|
||||||
inv_dst_height = -inv_dst_height;
|
inv_crop_height = -inv_crop_height;
|
||||||
}
|
}
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
// One pass rotation is available for some formats. For the rest, convert
|
// One pass rotation is available for some formats. For the rest, convert
|
||||||
// to I420 (with optional vertical flipping) into a temporary I420 buffer,
|
// to I420 (with optional vertical flipping) into a temporary I420 buffer,
|
||||||
// and then rotate the I420 to the final destination buffer.
|
// and then rotate the I420 to the final destination buffer.
|
||||||
// For in-place conversion, if destination dst_argb is same as source sample,
|
// For in-place conversion, if destination crop_argb is same as source sample,
|
||||||
// also enable temporary buffer.
|
// also enable temporary buffer.
|
||||||
bool need_buf = (rotation && format != FOURCC_ARGB) || dst_argb == sample;
|
bool need_buf = (rotation && format != FOURCC_ARGB) || crop_argb == sample;
|
||||||
uint8* tmp_argb = dst_argb;
|
uint8* tmp_argb = crop_argb;
|
||||||
int tmp_argb_stride = argb_stride;
|
int tmp_argb_stride = argb_stride;
|
||||||
uint8* rotate_buffer = NULL;
|
uint8* rotate_buffer = NULL;
|
||||||
int abs_dst_height = (dst_height < 0) ? -dst_height : dst_height;
|
int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height;
|
||||||
if (need_buf) {
|
if (need_buf) {
|
||||||
int argb_size = dst_width * abs_dst_height * 4;
|
int argb_size = crop_width * abs_crop_height * 4;
|
||||||
rotate_buffer = new uint8[argb_size];
|
rotate_buffer = new uint8[argb_size];
|
||||||
if (!rotate_buffer) {
|
if (!rotate_buffer) {
|
||||||
return 1; // Out of memory runtime error.
|
return 1; // Out of memory runtime error.
|
||||||
}
|
}
|
||||||
dst_argb = rotate_buffer;
|
crop_argb = rotate_buffer;
|
||||||
argb_stride = dst_width;
|
argb_stride = crop_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
@ -78,104 +78,104 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
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;
|
||||||
r = YUY2ToARGB(src, aligned_src_width * 2,
|
r = YUY2ToARGB(src, aligned_src_width * 2,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = UYVYToARGB(src, aligned_src_width * 2,
|
r = UYVYToARGB(src, aligned_src_width * 2,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = RGB24ToARGB(src, src_width * 3,
|
r = RGB24ToARGB(src, src_width * 3,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = RAWToARGB(src, src_width * 3,
|
r = RAWToARGB(src, src_width * 3,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = ARGBToARGB(src, src_width * 4,
|
r = ARGBToARGB(src, src_width * 4,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = BGRAToARGB(src, src_width * 4,
|
r = BGRAToARGB(src, src_width * 4,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = ABGRToARGB(src, src_width * 4,
|
r = ABGRToARGB(src, src_width * 4,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_RGBA:
|
case FOURCC_RGBA:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 4;
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
||||||
r = RGBAToARGB(src, src_width * 4,
|
r = RGBAToARGB(src, src_width * 4,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = RGB565ToARGB(src, src_width * 2,
|
r = RGB565ToARGB(src, src_width * 2,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_RGBO:
|
case FOURCC_RGBO:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 2;
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
||||||
r = ARGB1555ToARGB(src, src_width * 2,
|
r = ARGB1555ToARGB(src, src_width * 2,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_R444:
|
case FOURCC_R444:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 2;
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
||||||
r = ARGB4444ToARGB(src, src_width * 2,
|
r = ARGB4444ToARGB(src, src_width * 2,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
// TODO(fbarchard): Support cropping Bayer by odd numbers
|
// TODO(fbarchard): Support cropping Bayer by odd numbers
|
||||||
// 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);
|
||||||
r = BayerBGGRToARGB(src, src_width,
|
r = BayerBGGRToARGB(src, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOURCC_GBRG:
|
case FOURCC_GBRG:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
r = BayerGBRGToARGB(src, src_width,
|
r = BayerGBRGToARGB(src, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOURCC_GRBG:
|
case FOURCC_GRBG:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
r = BayerGRBGToARGB(src, src_width,
|
r = BayerGRBGToARGB(src, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOURCC_RGGB:
|
case FOURCC_RGGB:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
r = BayerRGGBToARGB(src, src_width,
|
r = BayerRGGBToARGB(src, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOURCC_I400:
|
case FOURCC_I400:
|
||||||
src = sample + src_width * crop_y + crop_x;
|
src = sample + src_width * crop_y + crop_x;
|
||||||
r = I400ToARGB(src, src_width,
|
r = I400ToARGB(src, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Biplanar formats
|
// Biplanar formats
|
||||||
@ -184,8 +184,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
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;
|
||||||
r = NV12ToARGB(src, src_width,
|
r = NV12ToARGB(src, src_width,
|
||||||
src_uv, aligned_src_width,
|
src_uv, aligned_src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_NV21:
|
case FOURCC_NV21:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
@ -193,14 +193,14 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
// Call NV12 but with u and v parameters swapped.
|
// Call NV12 but with u and v parameters swapped.
|
||||||
r = NV21ToARGB(src, src_width,
|
r = NV21ToARGB(src, src_width,
|
||||||
src_uv, aligned_src_width,
|
src_uv, aligned_src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
r = M420ToARGB(src, src_width,
|
r = M420ToARGB(src, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
// case FOURCC_Q420:
|
// case FOURCC_Q420:
|
||||||
// src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
|
// src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
|
||||||
@ -208,8 +208,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
// src_width + crop_x * 2;
|
// src_width + crop_x * 2;
|
||||||
// r = Q420ToARGB(src, src_width * 3,
|
// r = Q420ToARGB(src, src_width * 3,
|
||||||
// src_uv, src_width * 3,
|
// src_uv, src_width * 3,
|
||||||
// dst_argb, argb_stride,
|
// crop_argb, argb_stride,
|
||||||
// dst_width, inv_dst_height);
|
// crop_width, inv_crop_height);
|
||||||
// break;
|
// break;
|
||||||
// Triplanar formats
|
// Triplanar formats
|
||||||
case FOURCC_I420:
|
case FOURCC_I420:
|
||||||
@ -234,8 +234,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
r = I420ToARGB(src_y, src_width,
|
r = I420ToARGB(src_y, src_width,
|
||||||
src_u, halfwidth,
|
src_u, halfwidth,
|
||||||
src_v, halfwidth,
|
src_v, halfwidth,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOURCC_I422:
|
case FOURCC_I422:
|
||||||
@ -258,8 +258,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
r = I422ToARGB(src_y, src_width,
|
r = I422ToARGB(src_y, src_width,
|
||||||
src_u, halfwidth,
|
src_u, halfwidth,
|
||||||
src_v, halfwidth,
|
src_v, halfwidth,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOURCC_I444:
|
case FOURCC_I444:
|
||||||
@ -277,8 +277,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
r = I444ToARGB(src_y, src_width,
|
r = I444ToARGB(src_y, src_width,
|
||||||
src_u, src_width,
|
src_u, src_width,
|
||||||
src_v, src_width,
|
src_v, src_width,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOURCC_I411: {
|
case FOURCC_I411: {
|
||||||
@ -291,15 +291,15 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
r = I411ToARGB(src_y, src_width,
|
r = I411ToARGB(src_y, src_width,
|
||||||
src_u, quarterwidth,
|
src_u, quarterwidth,
|
||||||
src_v, quarterwidth,
|
src_v, quarterwidth,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_JPEG
|
#ifdef HAVE_JPEG
|
||||||
case FOURCC_MJPG:
|
case FOURCC_MJPG:
|
||||||
r = MJPGToARGB(sample, sample_size,
|
r = MJPGToARGB(sample, sample_size,
|
||||||
dst_argb, argb_stride,
|
crop_argb, argb_stride,
|
||||||
src_width, abs_src_height, dst_width, inv_dst_height);
|
src_width, abs_src_height, crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
@ -308,9 +308,9 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
|
|||||||
|
|
||||||
if (need_buf) {
|
if (need_buf) {
|
||||||
if (!r) {
|
if (!r) {
|
||||||
r = ARGBRotate(dst_argb, argb_stride,
|
r = ARGBRotate(crop_argb, argb_stride,
|
||||||
tmp_argb, tmp_argb_stride,
|
tmp_argb, tmp_argb_stride,
|
||||||
dst_width, abs_dst_height, rotation);
|
crop_width, abs_crop_height, rotation);
|
||||||
}
|
}
|
||||||
delete [] rotate_buffer;
|
delete [] rotate_buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,22 +35,22 @@ int ConvertToI420(const uint8* sample,
|
|||||||
uint8* v, int v_stride,
|
uint8* v, int v_stride,
|
||||||
int crop_x, int crop_y,
|
int crop_x, int crop_y,
|
||||||
int src_width, int src_height,
|
int src_width, int src_height,
|
||||||
int dst_width, int dst_height,
|
int crop_width, int crop_height,
|
||||||
RotationMode rotation,
|
RotationMode rotation,
|
||||||
uint32 fourcc) {
|
uint32 fourcc) {
|
||||||
uint32 format = CanonicalFourCC(fourcc);
|
uint32 format = CanonicalFourCC(fourcc);
|
||||||
if (!y || !u || !v || !sample ||
|
if (!y || !u || !v || !sample ||
|
||||||
src_width <= 0 || dst_width <= 0 ||
|
src_width <= 0 || crop_width <= 0 ||
|
||||||
src_height == 0 || dst_height == 0) {
|
src_height == 0 || crop_height == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int aligned_src_width = (src_width + 1) & ~1;
|
int aligned_src_width = (src_width + 1) & ~1;
|
||||||
const uint8* src;
|
const uint8* src;
|
||||||
const uint8* src_uv;
|
const uint8* src_uv;
|
||||||
int abs_src_height = (src_height < 0) ? -src_height : src_height;
|
int abs_src_height = (src_height < 0) ? -src_height : src_height;
|
||||||
int inv_dst_height = (dst_height < 0) ? -dst_height : dst_height;
|
int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height;
|
||||||
if (src_height < 0) {
|
if (src_height < 0) {
|
||||||
inv_dst_height = -inv_dst_height;
|
inv_crop_height = -inv_crop_height;
|
||||||
}
|
}
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
@ -69,10 +69,10 @@ int ConvertToI420(const uint8* sample,
|
|||||||
int tmp_u_stride = u_stride;
|
int tmp_u_stride = u_stride;
|
||||||
int tmp_v_stride = v_stride;
|
int tmp_v_stride = v_stride;
|
||||||
uint8* rotate_buffer = NULL;
|
uint8* rotate_buffer = NULL;
|
||||||
int abs_dst_height = (dst_height < 0) ? -dst_height : dst_height;
|
int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height;
|
||||||
if (need_buf) {
|
if (need_buf) {
|
||||||
int y_size = dst_width * abs_dst_height;
|
int y_size = crop_width * abs_crop_height;
|
||||||
int uv_size = ((dst_width + 1) / 2) * ((abs_dst_height + 1) / 2);
|
int uv_size = ((crop_width + 1) / 2) * ((abs_crop_height + 1) / 2);
|
||||||
rotate_buffer = new uint8[y_size + uv_size * 2];
|
rotate_buffer = new uint8[y_size + uv_size * 2];
|
||||||
if (!rotate_buffer) {
|
if (!rotate_buffer) {
|
||||||
return 1; // Out of memory runtime error.
|
return 1; // Out of memory runtime error.
|
||||||
@ -80,8 +80,8 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y = rotate_buffer;
|
y = rotate_buffer;
|
||||||
u = y + y_size;
|
u = y + y_size;
|
||||||
v = u + uv_size;
|
v = u + uv_size;
|
||||||
y_stride = dst_width;
|
y_stride = crop_width;
|
||||||
u_stride = v_stride = ((dst_width + 1) / 2);
|
u_stride = v_stride = ((crop_width + 1) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
@ -92,7 +92,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -100,7 +100,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -108,7 +108,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_RGBO:
|
case FOURCC_RGBO:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 2;
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
||||||
@ -116,7 +116,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_R444:
|
case FOURCC_R444:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 2;
|
src = sample + (src_width * crop_y + crop_x) * 2;
|
||||||
@ -124,7 +124,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -132,7 +132,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -140,7 +140,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -148,7 +148,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -156,7 +156,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
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;
|
||||||
@ -164,7 +164,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_RGBA:
|
case FOURCC_RGBA:
|
||||||
src = sample + (src_width * crop_y + crop_x) * 4;
|
src = sample + (src_width * crop_y + crop_x) * 4;
|
||||||
@ -172,7 +172,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
// TODO(fbarchard): Support cropping Bayer by odd numbers
|
// TODO(fbarchard): Support cropping Bayer by odd numbers
|
||||||
// by adjusting fourcc.
|
// by adjusting fourcc.
|
||||||
@ -182,7 +182,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_GBRG:
|
case FOURCC_GBRG:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
@ -190,7 +190,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_GRBG:
|
case FOURCC_GRBG:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
@ -198,7 +198,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_RGGB:
|
case FOURCC_RGGB:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
@ -206,7 +206,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_I400:
|
case FOURCC_I400:
|
||||||
src = sample + src_width * crop_y + crop_x;
|
src = sample + src_width * crop_y + crop_x;
|
||||||
@ -214,7 +214,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
// Biplanar formats
|
// Biplanar formats
|
||||||
case FOURCC_NV12:
|
case FOURCC_NV12:
|
||||||
@ -225,7 +225,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height, rotation);
|
crop_width, inv_crop_height, rotation);
|
||||||
break;
|
break;
|
||||||
case FOURCC_NV21:
|
case FOURCC_NV21:
|
||||||
src = sample + (src_width * crop_y + crop_x);
|
src = sample + (src_width * crop_y + crop_x);
|
||||||
@ -236,7 +236,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
dst_width, inv_dst_height, rotation);
|
crop_width, inv_crop_height, rotation);
|
||||||
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;
|
||||||
@ -244,7 +244,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
case FOURCC_Q420:
|
case FOURCC_Q420:
|
||||||
src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
|
src = sample + (src_width + aligned_src_width * 2) * crop_y + crop_x;
|
||||||
@ -255,7 +255,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
// Triplanar formats
|
// Triplanar formats
|
||||||
case FOURCC_I420:
|
case FOURCC_I420:
|
||||||
@ -283,7 +283,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height, rotation);
|
crop_width, inv_crop_height, rotation);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOURCC_I422:
|
case FOURCC_I422:
|
||||||
@ -309,7 +309,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOURCC_I444:
|
case FOURCC_I444:
|
||||||
@ -330,7 +330,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOURCC_I411: {
|
case FOURCC_I411: {
|
||||||
@ -346,7 +346,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
dst_width, inv_dst_height);
|
crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_JPEG
|
#ifdef HAVE_JPEG
|
||||||
@ -355,7 +355,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
y, y_stride,
|
y, y_stride,
|
||||||
u, u_stride,
|
u, u_stride,
|
||||||
v, v_stride,
|
v, v_stride,
|
||||||
src_width, abs_src_height, dst_width, inv_dst_height);
|
src_width, abs_src_height, crop_width, inv_crop_height);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
@ -370,7 +370,7 @@ int ConvertToI420(const uint8* sample,
|
|||||||
tmp_y, tmp_y_stride,
|
tmp_y, tmp_y_stride,
|
||||||
tmp_u, tmp_u_stride,
|
tmp_u, tmp_u_stride,
|
||||||
tmp_v, tmp_v_stride,
|
tmp_v, tmp_v_stride,
|
||||||
dst_width, abs_dst_height, rotation);
|
crop_width, abs_crop_height, rotation);
|
||||||
}
|
}
|
||||||
delete [] rotate_buffer;
|
delete [] rotate_buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user