Commit db73518b authored by fbarchard@google.com's avatar fbarchard@google.com

use LIBYUV_BOOL instead of bool

BUG=303
TESTED=try
R=tpsiaki@google.com

Review URL: https://webrtc-codereview.appspot.com/6519006

git-svn-id: http://libyuv.googlecode.com/svn/trunk@953 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent a1f5254a
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 952 Version: 953
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -70,11 +70,12 @@ class LIBYUV_API MJpegDecoder { ...@@ -70,11 +70,12 @@ class LIBYUV_API MJpegDecoder {
~MJpegDecoder(); ~MJpegDecoder();
// Loads a new frame, reads its headers, and determines the uncompressed // Loads a new frame, reads its headers, and determines the uncompressed
// image format. Returns true if image looks valid and format is supported. // image format.
// If return value is true, then the values for all the following getters // Returns LIBYUV_TRUE if image looks valid and format is supported.
// are populated. // If return value is LIBYUV_TRUE, then the values for all the following
// getters are populated.
// src_len is the size of the compressed mjpeg frame in bytes. // src_len is the size of the compressed mjpeg frame in bytes.
bool LoadFrame(const uint8* src, size_t src_len); LIBYUV_BOOL LoadFrame(const uint8* src, size_t src_len);
// Returns width of the last loaded frame in pixels. // Returns width of the last loaded frame in pixels.
int GetWidth(); int GetWidth();
...@@ -118,7 +119,7 @@ class LIBYUV_API MJpegDecoder { ...@@ -118,7 +119,7 @@ class LIBYUV_API MJpegDecoder {
// Call this after LoadFrame() if you decide you don't want to decode it // Call this after LoadFrame() if you decide you don't want to decode it
// after all. // after all.
bool UnloadFrame(); LIBYUV_BOOL UnloadFrame();
// Decodes the entire image into a one-buffer-per-color-component format. // Decodes the entire image into a one-buffer-per-color-component format.
// dst_width must match exactly. dst_height must be <= to image height; if // dst_width must match exactly. dst_height must be <= to image height; if
...@@ -127,13 +128,13 @@ class LIBYUV_API MJpegDecoder { ...@@ -127,13 +128,13 @@ class LIBYUV_API MJpegDecoder {
// at least GetComponentSize(i). The pointers in planes are incremented // at least GetComponentSize(i). The pointers in planes are incremented
// to point to after the end of the written data. // to point to after the end of the written data.
// TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded. // TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded.
bool DecodeToBuffers(uint8** planes, int dst_width, int dst_height); LIBYUV_BOOL DecodeToBuffers(uint8** planes, int dst_width, int dst_height);
// Decodes the entire image and passes the data via repeated calls to a // Decodes the entire image and passes the data via repeated calls to a
// callback function. Each call will get the data for a whole number of // callback function. Each call will get the data for a whole number of
// image scanlines. // image scanlines.
// TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded. // TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded.
bool DecodeToCallback(CallbackFunction fn, void* opaque, LIBYUV_BOOL DecodeToCallback(CallbackFunction fn, void* opaque,
int dst_width, int dst_height); int dst_width, int dst_height);
// The helper function which recognizes the jpeg sub-sampling type. // The helper function which recognizes the jpeg sub-sampling type.
...@@ -164,11 +165,11 @@ class LIBYUV_API MJpegDecoder { ...@@ -164,11 +165,11 @@ class LIBYUV_API MJpegDecoder {
void AllocOutputBuffers(int num_outbufs); void AllocOutputBuffers(int num_outbufs);
void DestroyOutputBuffers(); void DestroyOutputBuffers();
bool StartDecode(); LIBYUV_BOOL StartDecode();
bool FinishDecode(); LIBYUV_BOOL FinishDecode();
void SetScanlinePointers(uint8** data); void SetScanlinePointers(uint8** data);
bool DecodeImcuRow(); LIBYUV_BOOL DecodeImcuRow();
int GetComponentScanlinePadding(int component); int GetComponentScanlinePadding(int component);
...@@ -180,9 +181,9 @@ class LIBYUV_API MJpegDecoder { ...@@ -180,9 +181,9 @@ class LIBYUV_API MJpegDecoder {
jpeg_source_mgr* source_mgr_; jpeg_source_mgr* source_mgr_;
SetJmpErrorMgr* error_mgr_; SetJmpErrorMgr* error_mgr_;
// true iff at least one component has scanline padding. (i.e., // LIBYUV_TRUE iff at least one component has scanline padding. (i.e.,
// GetComponentScanlinePadding() != 0.) // GetComponentScanlinePadding() != 0.)
bool has_scanline_padding_; LIBYUV_BOOL has_scanline_padding_;
// Temporaries used to point to scanline outputs. // Temporaries used to point to scanline outputs.
int num_outbufs_; // Outermost size of all arrays below. int num_outbufs_; // Outermost size of all arrays below.
......
...@@ -19,7 +19,7 @@ extern "C" { ...@@ -19,7 +19,7 @@ extern "C" {
#endif #endif
// Supported rotation. // Supported rotation.
enum RotationMode { typedef enum RotationMode {
kRotate0 = 0, // No rotation. kRotate0 = 0, // No rotation.
kRotate90 = 90, // Rotate 90 degrees clockwise. kRotate90 = 90, // Rotate 90 degrees clockwise.
kRotate180 = 180, // Rotate 180 degrees. kRotate180 = 180, // Rotate 180 degrees.
...@@ -29,7 +29,7 @@ enum RotationMode { ...@@ -29,7 +29,7 @@ enum RotationMode {
kRotateNone = 0, kRotateNone = 0,
kRotateClockwise = 90, kRotateClockwise = 90,
kRotateCounterClockwise = 270, kRotateCounterClockwise = 270,
}; } RotationModeEnum;
// Rotate I420 frame. // Rotate I420 frame.
LIBYUV_API LIBYUV_API
......
...@@ -33,15 +33,14 @@ extern "C" { ...@@ -33,15 +33,14 @@ extern "C" {
#define align_buffer_64(var, size) \ #define align_buffer_64(var, size) \
uint8* var; \ uint8* var; \
uint8* var##_mem; \ uint8* var##_mem; \
var##_mem = (uint8*)(malloc((size) + 63)); \ var##_mem = (uint8*)(malloc((size) + 63)); /* NOLINT */ \
var = (uint8*) (((intptr_t)(var##_mem) + 63) & ~63) var = (uint8*) (((intptr_t)(var##_mem) + 63) & ~63) /* NOLINT */
#endif #endif
#define free_aligned_buffer_64(var) \ #define free_aligned_buffer_64(var) \
free(var##_mem); \ free(var##_mem); \
var = 0 var = 0
#if defined(__CLR_VER) || defined(COVERAGE_ENABLED) || \ #if defined(__CLR_VER) || defined(COVERAGE_ENABLED) || \
defined(TARGET_IPHONE_SIMULATOR) defined(TARGET_IPHONE_SIMULATOR)
#define LIBYUV_DISABLE_X86 #define LIBYUV_DISABLE_X86
......
...@@ -19,12 +19,12 @@ extern "C" { ...@@ -19,12 +19,12 @@ extern "C" {
#endif #endif
// Supported filtering. // Supported filtering.
enum FilterMode { typedef enum FilterMode {
kFilterNone = 0, // Point sample; Fastest. kFilterNone = 0, // Point sample; Fastest.
kFilterLinear = 1, // Filter horizontally only. kFilterLinear = 1, // Filter horizontally only.
kFilterBilinear = 2, // Faster than box, but lower quality scaling down. kFilterBilinear = 2, // Faster than box, but lower quality scaling down.
kFilterBox = 3 // Highest quality. kFilterBox = 3 // Highest quality.
}; } FilterModeEnum;
// Scale a YUV plane. // Scale a YUV plane.
LIBYUV_API LIBYUV_API
...@@ -64,17 +64,17 @@ int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v, ...@@ -64,17 +64,17 @@ int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v,
uint8* dst_y, uint8* dst_u, uint8* dst_v, uint8* dst_y, uint8* dst_u, uint8* dst_v,
int dst_stride_y, int dst_stride_u, int dst_stride_v, int dst_stride_y, int dst_stride_u, int dst_stride_v,
int dst_width, int dst_height, int dst_width, int dst_height,
bool interpolate); LIBYUV_BOOL interpolate);
// Legacy API. Deprecated. // Legacy API. Deprecated.
LIBYUV_API LIBYUV_API
int ScaleOffset(const uint8* src_i420, int src_width, int src_height, int ScaleOffset(const uint8* src_i420, int src_width, int src_height,
uint8* dst_i420, int dst_width, int dst_height, int dst_yoffset, uint8* dst_i420, int dst_width, int dst_height, int dst_yoffset,
bool interpolate); LIBYUV_BOOL interpolate);
// For testing, allow disabling of specialized scalers. // For testing, allow disabling of specialized scalers.
LIBYUV_API LIBYUV_API
void SetUseReferenceImpl(bool use); void SetUseReferenceImpl(LIBYUV_BOOL use);
#endif // __cplusplus #endif // __cplusplus
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -11,6 +11,6 @@ ...@@ -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 952 #define LIBYUV_VERSION 953
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -124,7 +124,7 @@ LIBYUV_API ...@@ -124,7 +124,7 @@ LIBYUV_API
int MJPGSize(const uint8* sample, size_t sample_size, int MJPGSize(const uint8* sample, size_t sample_size,
int* width, int* height) { int* width, int* height) {
MJpegDecoder mjpeg_decoder; MJpegDecoder mjpeg_decoder;
bool ret = mjpeg_decoder.LoadFrame(sample, sample_size); LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(sample, sample_size);
if (ret) { if (ret) {
*width = mjpeg_decoder.GetWidth(); *width = mjpeg_decoder.GetWidth();
*height = mjpeg_decoder.GetHeight(); *height = mjpeg_decoder.GetHeight();
...@@ -150,7 +150,7 @@ int MJPGToI420(const uint8* sample, ...@@ -150,7 +150,7 @@ int MJPGToI420(const uint8* sample,
// TODO(fbarchard): Port MJpeg to C. // TODO(fbarchard): Port MJpeg to C.
MJpegDecoder mjpeg_decoder; MJpegDecoder mjpeg_decoder;
bool ret = mjpeg_decoder.LoadFrame(sample, sample_size); LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(sample, sample_size);
if (ret && (mjpeg_decoder.GetWidth() != w || if (ret && (mjpeg_decoder.GetWidth() != w ||
mjpeg_decoder.GetHeight() != h)) { mjpeg_decoder.GetHeight() != h)) {
// ERROR: MJPEG frame has unexpected dimensions // ERROR: MJPEG frame has unexpected dimensions
...@@ -312,7 +312,7 @@ int MJPGToARGB(const uint8* sample, ...@@ -312,7 +312,7 @@ int MJPGToARGB(const uint8* sample,
// TODO(fbarchard): Port MJpeg to C. // TODO(fbarchard): Port MJpeg to C.
MJpegDecoder mjpeg_decoder; MJpegDecoder mjpeg_decoder;
bool ret = mjpeg_decoder.LoadFrame(sample, sample_size); LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(sample, sample_size);
if (ret && (mjpeg_decoder.GetWidth() != w || if (ret && (mjpeg_decoder.GetWidth() != w ||
mjpeg_decoder.GetHeight() != h)) { mjpeg_decoder.GetHeight() != h)) {
// ERROR: MJPEG frame has unexpected dimensions // ERROR: MJPEG frame has unexpected dimensions
......
...@@ -35,7 +35,7 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, ...@@ -35,7 +35,7 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
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 crop_width, int crop_height, int crop_width, int crop_height,
RotationMode rotation, enum RotationMode rotation,
uint32 fourcc) { uint32 fourcc) {
uint32 format = CanonicalFourCC(fourcc); uint32 format = CanonicalFourCC(fourcc);
if (crop_argb == NULL || sample == NULL || if (crop_argb == NULL || sample == NULL ||
...@@ -58,7 +58,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size, ...@@ -58,7 +58,8 @@ int ConvertToARGB(const uint8* sample, size_t sample_size,
// 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 crop_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) || crop_argb == sample; LIBYUV_BOOL need_buf = (rotation && format != FOURCC_ARGB) ||
crop_argb == sample;
uint8* tmp_argb = crop_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;
......
...@@ -36,7 +36,7 @@ int ConvertToI420(const uint8* sample, ...@@ -36,7 +36,7 @@ int ConvertToI420(const uint8* sample,
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 crop_width, int crop_height, int crop_width, int crop_height,
RotationMode rotation, enum RotationMode rotation,
uint32 fourcc) { uint32 fourcc) {
uint32 format = CanonicalFourCC(fourcc); uint32 format = CanonicalFourCC(fourcc);
if (!y || !u || !v || !sample || if (!y || !u || !v || !sample ||
...@@ -59,7 +59,7 @@ int ConvertToI420(const uint8* sample, ...@@ -59,7 +59,7 @@ int ConvertToI420(const uint8* sample,
// 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 y is same as source sample, // For in-place conversion, if destination y is same as source sample,
// also enable temporary buffer. // also enable temporary buffer.
bool need_buf = (rotation && format != FOURCC_I420 && LIBYUV_BOOL need_buf = (rotation && format != FOURCC_I420 &&
format != FOURCC_NV12 && format != FOURCC_NV21 && format != FOURCC_NV12 && format != FOURCC_NV21 &&
format != FOURCC_YU12 && format != FOURCC_YV12) || y == sample; format != FOURCC_YU12 && format != FOURCC_YV12) || y == sample;
uint8* tmp_y = y; uint8* tmp_y = y;
......
...@@ -39,7 +39,7 @@ const int MJpegDecoder::kColorSpaceCMYK = JCS_CMYK; ...@@ -39,7 +39,7 @@ const int MJpegDecoder::kColorSpaceCMYK = JCS_CMYK;
const int MJpegDecoder::kColorSpaceYCCK = JCS_YCCK; const int MJpegDecoder::kColorSpaceYCCK = JCS_YCCK;
MJpegDecoder::MJpegDecoder() MJpegDecoder::MJpegDecoder()
: has_scanline_padding_(false), : has_scanline_padding_(LIBYUV_FALSE),
num_outbufs_(0), num_outbufs_(0),
scanlines_(NULL), scanlines_(NULL),
scanlines_sizes_(NULL), scanlines_sizes_(NULL),
...@@ -75,9 +75,9 @@ MJpegDecoder::~MJpegDecoder() { ...@@ -75,9 +75,9 @@ MJpegDecoder::~MJpegDecoder() {
DestroyOutputBuffers(); DestroyOutputBuffers();
} }
bool MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) { LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) {
if (!ValidateJpeg(src, src_len)) { if (!ValidateJpeg(src, src_len)) {
return false; return LIBYUV_FALSE;
} }
buf_.data = src; buf_.data = src;
...@@ -88,12 +88,12 @@ bool MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) { ...@@ -88,12 +88,12 @@ bool MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) {
if (setjmp(error_mgr_->setjmp_buffer)) { if (setjmp(error_mgr_->setjmp_buffer)) {
// We called jpeg_read_header, it experienced an error, and we called // We called jpeg_read_header, it experienced an error, and we called
// longjmp() and rewound the stack to here. Return error. // longjmp() and rewound the stack to here. Return error.
return false; return LIBYUV_FALSE;
} }
#endif #endif
if (jpeg_read_header(decompress_struct_, TRUE) != JPEG_HEADER_OK) { if (jpeg_read_header(decompress_struct_, TRUE) != JPEG_HEADER_OK) {
// ERROR: Bad MJPEG header // ERROR: Bad MJPEG header
return false; return LIBYUV_FALSE;
} }
AllocOutputBuffers(GetNumComponents()); AllocOutputBuffers(GetNumComponents());
for (int i = 0; i < num_outbufs_; ++i) { for (int i = 0; i < num_outbufs_; ++i) {
...@@ -123,10 +123,10 @@ bool MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) { ...@@ -123,10 +123,10 @@ bool MJpegDecoder::LoadFrame(const uint8* src, size_t src_len) {
} }
if (GetComponentStride(i) != GetComponentWidth(i)) { if (GetComponentStride(i) != GetComponentWidth(i)) {
has_scanline_padding_ = true; has_scanline_padding_ = LIBYUV_TRUE;
} }
} }
return true; return LIBYUV_TRUE;
} }
static int DivideAndRoundUp(int numerator, int denominator) { static int DivideAndRoundUp(int numerator, int denominator) {
...@@ -205,36 +205,36 @@ int MJpegDecoder::GetComponentSize(int component) { ...@@ -205,36 +205,36 @@ int MJpegDecoder::GetComponentSize(int component) {
return GetComponentWidth(component) * GetComponentHeight(component); return GetComponentWidth(component) * GetComponentHeight(component);
} }
bool MJpegDecoder::UnloadFrame() { LIBYUV_BOOL MJpegDecoder::UnloadFrame() {
#ifdef HAVE_SETJMP #ifdef HAVE_SETJMP
if (setjmp(error_mgr_->setjmp_buffer)) { if (setjmp(error_mgr_->setjmp_buffer)) {
// We called jpeg_abort_decompress, it experienced an error, and we called // We called jpeg_abort_decompress, it experienced an error, and we called
// longjmp() and rewound the stack to here. Return error. // longjmp() and rewound the stack to here. Return error.
return false; return LIBYUV_FALSE;
} }
#endif #endif
jpeg_abort_decompress(decompress_struct_); jpeg_abort_decompress(decompress_struct_);
return true; return LIBYUV_TRUE;
} }
// TODO(fbarchard): Allow rectangle to be specified: x, y, width, height. // TODO(fbarchard): Allow rectangle to be specified: x, y, width, height.
bool MJpegDecoder::DecodeToBuffers( LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(
uint8** planes, int dst_width, int dst_height) { uint8** planes, int dst_width, int dst_height) {
if (dst_width != GetWidth() || if (dst_width != GetWidth() ||
dst_height > GetHeight()) { dst_height > GetHeight()) {
// ERROR: Bad dimensions // ERROR: Bad dimensions
return false; return LIBYUV_FALSE;
} }
#ifdef HAVE_SETJMP #ifdef HAVE_SETJMP
if (setjmp(error_mgr_->setjmp_buffer)) { if (setjmp(error_mgr_->setjmp_buffer)) {
// We called into jpeglib, it experienced an error sometime during this // We called into jpeglib, it experienced an error sometime during this
// function call, and we called longjmp() and rewound the stack to here. // function call, and we called longjmp() and rewound the stack to here.
// Return error. // Return error.
return false; return LIBYUV_FALSE;
} }
#endif #endif
if (!StartDecode()) { if (!StartDecode()) {
return false; return LIBYUV_FALSE;
} }
SetScanlinePointers(databuf_); SetScanlinePointers(databuf_);
int lines_left = dst_height; int lines_left = dst_height;
...@@ -248,7 +248,7 @@ bool MJpegDecoder::DecodeToBuffers( ...@@ -248,7 +248,7 @@ bool MJpegDecoder::DecodeToBuffers(
while (skip >= GetImageScanlinesPerImcuRow()) { while (skip >= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
skip -= GetImageScanlinesPerImcuRow(); skip -= GetImageScanlinesPerImcuRow();
} }
...@@ -257,7 +257,7 @@ bool MJpegDecoder::DecodeToBuffers( ...@@ -257,7 +257,7 @@ bool MJpegDecoder::DecodeToBuffers(
// copy the parts we want into the destination. // copy the parts we want into the destination.
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
for (int i = 0; i < num_outbufs_; ++i) { for (int i = 0; i < num_outbufs_; ++i) {
// TODO(fbarchard): Compute skip to avoid this // TODO(fbarchard): Compute skip to avoid this
...@@ -281,7 +281,7 @@ bool MJpegDecoder::DecodeToBuffers( ...@@ -281,7 +281,7 @@ bool MJpegDecoder::DecodeToBuffers(
lines_left -= GetImageScanlinesPerImcuRow()) { lines_left -= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
for (int i = 0; i < num_outbufs_; ++i) { for (int i = 0; i < num_outbufs_; ++i) {
int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i); int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i);
...@@ -296,7 +296,7 @@ bool MJpegDecoder::DecodeToBuffers( ...@@ -296,7 +296,7 @@ bool MJpegDecoder::DecodeToBuffers(
// Have a partial iMCU row left over to decode. // Have a partial iMCU row left over to decode.
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
for (int i = 0; i < num_outbufs_; ++i) { for (int i = 0; i < num_outbufs_; ++i) {
int scanlines_to_copy = int scanlines_to_copy =
...@@ -310,23 +310,23 @@ bool MJpegDecoder::DecodeToBuffers( ...@@ -310,23 +310,23 @@ bool MJpegDecoder::DecodeToBuffers(
return FinishDecode(); return FinishDecode();
} }
bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque, LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque,
int dst_width, int dst_height) { int dst_width, int dst_height) {
if (dst_width != GetWidth() || if (dst_width != GetWidth() ||
dst_height > GetHeight()) { dst_height > GetHeight()) {
// ERROR: Bad dimensions // ERROR: Bad dimensions
return false; return LIBYUV_FALSE;
} }
#ifdef HAVE_SETJMP #ifdef HAVE_SETJMP
if (setjmp(error_mgr_->setjmp_buffer)) { if (setjmp(error_mgr_->setjmp_buffer)) {
// We called into jpeglib, it experienced an error sometime during this // We called into jpeglib, it experienced an error sometime during this
// function call, and we called longjmp() and rewound the stack to here. // function call, and we called longjmp() and rewound the stack to here.
// Return error. // Return error.
return false; return LIBYUV_FALSE;
} }
#endif #endif
if (!StartDecode()) { if (!StartDecode()) {
return false; return LIBYUV_FALSE;
} }
SetScanlinePointers(databuf_); SetScanlinePointers(databuf_);
int lines_left = dst_height; int lines_left = dst_height;
...@@ -336,7 +336,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque, ...@@ -336,7 +336,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque,
while (skip >= GetImageScanlinesPerImcuRow()) { while (skip >= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
skip -= GetImageScanlinesPerImcuRow(); skip -= GetImageScanlinesPerImcuRow();
} }
...@@ -344,7 +344,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque, ...@@ -344,7 +344,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque,
// Have a partial iMCU row left over to skip. // Have a partial iMCU row left over to skip.
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
for (int i = 0; i < num_outbufs_; ++i) { for (int i = 0; i < num_outbufs_; ++i) {
// TODO(fbarchard): Compute skip to avoid this // TODO(fbarchard): Compute skip to avoid this
...@@ -371,7 +371,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque, ...@@ -371,7 +371,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque,
lines_left -= GetImageScanlinesPerImcuRow()) { lines_left -= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
(*fn)(opaque, databuf_, databuf_strides_, GetImageScanlinesPerImcuRow()); (*fn)(opaque, databuf_, databuf_strides_, GetImageScanlinesPerImcuRow());
} }
...@@ -379,7 +379,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque, ...@@ -379,7 +379,7 @@ bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, void* opaque,
// Have a partial iMCU row left over to decode. // Have a partial iMCU row left over to decode.
if (!DecodeImcuRow()) { if (!DecodeImcuRow()) {
FinishDecode(); FinishDecode();
return false; return LIBYUV_FALSE;
} }
(*fn)(opaque, databuf_, databuf_strides_, lines_left); (*fn)(opaque, databuf_, databuf_strides_, lines_left);
} }
...@@ -474,26 +474,29 @@ void MJpegDecoder::DestroyOutputBuffers() { ...@@ -474,26 +474,29 @@ void MJpegDecoder::DestroyOutputBuffers() {
} }
// JDCT_IFAST and do_block_smoothing improve performance substantially. // JDCT_IFAST and do_block_smoothing improve performance substantially.
bool MJpegDecoder::StartDecode() { LIBYUV_BOOL MJpegDecoder::StartDecode() {
decompress_struct_->raw_data_out = TRUE; decompress_struct_->raw_data_out = TRUE;
decompress_struct_->dct_method = JDCT_IFAST; // JDCT_ISLOW is default decompress_struct_->dct_method = JDCT_IFAST; // JDCT_ISLOW is default
decompress_struct_->dither_mode = JDITHER_NONE; decompress_struct_->dither_mode = JDITHER_NONE;
decompress_struct_->do_fancy_upsampling = false; // Not applicable to 'raw' // Not applicable to 'raw':
decompress_struct_->enable_2pass_quant = false; // Only for buffered mode decompress_struct_->do_fancy_upsampling = LIBYUV_FALSE;
decompress_struct_->do_block_smoothing = false; // blocky but fast // Only for buffered mode:
decompress_struct_->enable_2pass_quant = LIBYUV_FALSE;
// Blocky but fast:
decompress_struct_->do_block_smoothing = LIBYUV_FALSE;
if (!jpeg_start_decompress(decompress_struct_)) { if (!jpeg_start_decompress(decompress_struct_)) {
// ERROR: Couldn't start JPEG decompressor"; // ERROR: Couldn't start JPEG decompressor";
return false; return LIBYUV_FALSE;
} }
return true; return LIBYUV_TRUE;
} }
bool MJpegDecoder::FinishDecode() { LIBYUV_BOOL MJpegDecoder::FinishDecode() {
// jpeglib considers it an error if we finish without decoding the whole // jpeglib considers it an error if we finish without decoding the whole
// image, so we call "abort" rather than "finish". // image, so we call "abort" rather than "finish".
jpeg_abort_decompress(decompress_struct_); jpeg_abort_decompress(decompress_struct_);
return true; return LIBYUV_TRUE;
} }
void MJpegDecoder::SetScanlinePointers(uint8** data) { void MJpegDecoder::SetScanlinePointers(uint8** data) {
...@@ -506,7 +509,7 @@ void MJpegDecoder::SetScanlinePointers(uint8** data) { ...@@ -506,7 +509,7 @@ void MJpegDecoder::SetScanlinePointers(uint8** data) {
} }
} }
inline bool MJpegDecoder::DecodeImcuRow() { inline LIBYUV_BOOL MJpegDecoder::DecodeImcuRow() {
return (unsigned int)(GetImageScanlinesPerImcuRow()) == return (unsigned int)(GetImageScanlinesPerImcuRow()) ==
jpeg_read_raw_data(decompress_struct_, jpeg_read_raw_data(decompress_struct_,
scanlines_, scanlines_,
......
...@@ -1102,7 +1102,7 @@ LIBYUV_API ...@@ -1102,7 +1102,7 @@ LIBYUV_API
int RotatePlane(const uint8* src, int src_stride, int RotatePlane(const uint8* src, int src_stride,
uint8* dst, int dst_stride, uint8* dst, int dst_stride,
int width, int height, int width, int height,
RotationMode mode) { enum RotationMode mode) {
if (!src || width <= 0 || height == 0 || !dst) { if (!src || width <= 0 || height == 0 || !dst) {
return -1; return -1;
} }
...@@ -1150,7 +1150,7 @@ int I420Rotate(const uint8* src_y, int src_stride_y, ...@@ -1150,7 +1150,7 @@ int I420Rotate(const uint8* src_y, int src_stride_y,
uint8* dst_u, int dst_stride_u, uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v, uint8* dst_v, int dst_stride_v,
int width, int height, int width, int height,
RotationMode mode) { enum RotationMode mode) {
if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || if (!src_y || !src_u || !src_v || width <= 0 || height == 0 ||
!dst_y || !dst_u || !dst_v) { !dst_y || !dst_u || !dst_v) {
return -1; return -1;
...@@ -1226,7 +1226,7 @@ int NV12ToI420Rotate(const uint8* src_y, int src_stride_y, ...@@ -1226,7 +1226,7 @@ int NV12ToI420Rotate(const uint8* src_y, int src_stride_y,
uint8* dst_u, int dst_stride_u, uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v, uint8* dst_v, int dst_stride_v,
int width, int height, int width, int height,
RotationMode mode) { enum RotationMode mode) {
if (!src_y || !src_uv || width <= 0 || height == 0 || if (!src_y || !src_uv || width <= 0 || height == 0 ||
!dst_y || !dst_u || !dst_v) { !dst_y || !dst_u || !dst_v) {
return -1; return -1;
......
...@@ -162,7 +162,7 @@ LIBYUV_API ...@@ -162,7 +162,7 @@ LIBYUV_API
int ARGBRotate(const uint8* src_argb, int src_stride_argb, int ARGBRotate(const uint8* src_argb, int src_stride_argb,
uint8* dst_argb, int dst_stride_argb, uint8* dst_argb, int dst_stride_argb,
int width, int height, int width, int height,
RotationMode mode) { enum RotationMode mode) {
if (!src_argb || width <= 0 || height == 0 || !dst_argb) { if (!src_argb || width <= 0 || height == 0 || !dst_argb) {
return -1; return -1;
} }
......
...@@ -40,7 +40,7 @@ static void ScalePlaneDown2(int /* src_width */, int /* src_height */, ...@@ -40,7 +40,7 @@ static void ScalePlaneDown2(int /* src_width */, int /* src_height */,
int dst_width, int dst_height, int dst_width, int dst_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_ptr, uint8* dst_ptr, const uint8* src_ptr, uint8* dst_ptr,
FilterMode filtering) { enum FilterMode filtering) {
void (*ScaleRowDown2)(const uint8* src_ptr, ptrdiff_t src_stride, void (*ScaleRowDown2)(const uint8* src_ptr, ptrdiff_t src_stride,
uint8* dst_ptr, int dst_width) = uint8* dst_ptr, int dst_width) =
filtering == kFilterNone ? ScaleRowDown2_C : filtering == kFilterNone ? ScaleRowDown2_C :
...@@ -97,7 +97,7 @@ static void ScalePlaneDown4(int /* src_width */, int /* src_height */, ...@@ -97,7 +97,7 @@ static void ScalePlaneDown4(int /* src_width */, int /* src_height */,
int dst_width, int dst_height, int dst_width, int dst_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_ptr, uint8* dst_ptr, const uint8* src_ptr, uint8* dst_ptr,
FilterMode filtering) { enum FilterMode filtering) {
void (*ScaleRowDown4)(const uint8* src_ptr, ptrdiff_t src_stride, void (*ScaleRowDown4)(const uint8* src_ptr, ptrdiff_t src_stride,
uint8* dst_ptr, int dst_width) = uint8* dst_ptr, int dst_width) =
filtering ? ScaleRowDown4Box_C : ScaleRowDown4_C; filtering ? ScaleRowDown4Box_C : ScaleRowDown4_C;
...@@ -141,7 +141,7 @@ static void ScalePlaneDown34(int /* src_width */, int /* src_height */, ...@@ -141,7 +141,7 @@ static void ScalePlaneDown34(int /* src_width */, int /* src_height */,
int dst_width, int dst_height, int dst_width, int dst_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_ptr, uint8* dst_ptr, const uint8* src_ptr, uint8* dst_ptr,
FilterMode filtering) { enum FilterMode filtering) {
assert(dst_width % 3 == 0); assert(dst_width % 3 == 0);
void (*ScaleRowDown34_0)(const uint8* src_ptr, ptrdiff_t src_stride, void (*ScaleRowDown34_0)(const uint8* src_ptr, ptrdiff_t src_stride,
uint8* dst_ptr, int dst_width); uint8* dst_ptr, int dst_width);
...@@ -236,7 +236,7 @@ static void ScalePlaneDown38(int /* src_width */, int /* src_height */, ...@@ -236,7 +236,7 @@ static void ScalePlaneDown38(int /* src_width */, int /* src_height */,
int dst_width, int dst_height, int dst_width, int dst_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_ptr, uint8* dst_ptr, const uint8* src_ptr, uint8* dst_ptr,
FilterMode filtering) { enum FilterMode filtering) {
assert(dst_width % 3 == 0); assert(dst_width % 3 == 0);
void (*ScaleRowDown38_3)(const uint8* src_ptr, ptrdiff_t src_stride, void (*ScaleRowDown38_3)(const uint8* src_ptr, ptrdiff_t src_stride,
uint8* dst_ptr, int dst_width); uint8* dst_ptr, int dst_width);
...@@ -448,7 +448,7 @@ void ScalePlaneBilinearDown(int src_width, int src_height, ...@@ -448,7 +448,7 @@ void ScalePlaneBilinearDown(int src_width, int src_height,
int dst_width, int dst_height, int dst_width, int dst_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_ptr, uint8* dst_ptr, const uint8* src_ptr, uint8* dst_ptr,
FilterMode filtering) { enum FilterMode filtering) {
assert(dst_width > 0); assert(dst_width > 0);
assert(dst_height > 0); assert(dst_height > 0);
...@@ -549,7 +549,7 @@ void ScalePlaneBilinearUp(int src_width, int src_height, ...@@ -549,7 +549,7 @@ void ScalePlaneBilinearUp(int src_width, int src_height,
int dst_width, int dst_height, int dst_width, int dst_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_ptr, uint8* dst_ptr, const uint8* src_ptr, uint8* dst_ptr,
FilterMode filtering) { enum FilterMode filtering) {
assert(src_width != 0); assert(src_width != 0);
assert(src_height != 0); assert(src_height != 0);
assert(dst_width > 0); assert(dst_width > 0);
...@@ -731,7 +731,7 @@ void ScalePlane(const uint8* src, int src_stride, ...@@ -731,7 +731,7 @@ void ScalePlane(const uint8* src, int src_stride,
int src_width, int src_height, int src_width, int src_height,
uint8* dst, int dst_stride, uint8* dst, int dst_stride,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering) { enum FilterMode filtering) {
// Simplify filtering when possible. // Simplify filtering when possible.
filtering = ScaleFilterReduce(src_width, src_height, filtering = ScaleFilterReduce(src_width, src_height,
dst_width, dst_height, dst_width, dst_height,
...@@ -822,7 +822,7 @@ int I420Scale(const uint8* src_y, int src_stride_y, ...@@ -822,7 +822,7 @@ int I420Scale(const uint8* src_y, int src_stride_y,
uint8* dst_u, int dst_stride_u, uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v, uint8* dst_v, int dst_stride_v,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering) { enum FilterMode filtering) {
if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 ||
!dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) {
return -1; return -1;
...@@ -852,7 +852,7 @@ int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v, ...@@ -852,7 +852,7 @@ int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v,
uint8* dst_y, uint8* dst_u, uint8* dst_v, uint8* dst_y, uint8* dst_u, uint8* dst_v,
int dst_stride_y, int dst_stride_u, int dst_stride_v, int dst_stride_y, int dst_stride_u, int dst_stride_v,
int dst_width, int dst_height, int dst_width, int dst_height,
bool interpolate) { LIBYUV_BOOL interpolate) {
return I420Scale(src_y, src_stride_y, return I420Scale(src_y, src_stride_y,
src_u, src_stride_u, src_u, src_stride_u,
src_v, src_stride_v, src_v, src_stride_v,
...@@ -868,7 +868,7 @@ int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v, ...@@ -868,7 +868,7 @@ int Scale(const uint8* src_y, const uint8* src_u, const uint8* src_v,
LIBYUV_API LIBYUV_API
int ScaleOffset(const uint8* src, int src_width, int src_height, int ScaleOffset(const uint8* src, int src_width, int src_height,
uint8* dst, int dst_width, int dst_height, int dst_yoffset, uint8* dst, int dst_width, int dst_height, int dst_yoffset,
bool interpolate) { LIBYUV_BOOL interpolate) {
if (!src || src_width <= 0 || src_height <= 0 || if (!src || src_width <= 0 || src_height <= 0 ||
!dst || dst_width <= 0 || dst_height <= 0 || dst_yoffset < 0 || !dst || dst_width <= 0 || dst_height <= 0 || dst_yoffset < 0 ||
dst_yoffset >= dst_height) { dst_yoffset >= dst_height) {
......
...@@ -35,7 +35,7 @@ static void ScaleARGBDown2(int /* src_width */, int /* src_height */, ...@@ -35,7 +35,7 @@ static void ScaleARGBDown2(int /* src_width */, int /* src_height */,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_argb, uint8* dst_argb, const uint8* src_argb, uint8* dst_argb,
int x, int dx, int y, int dy, int x, int dx, int y, int dy,
FilterMode filtering) { enum FilterMode filtering) {
assert(dx == 65536 * 2); // Test scale factor of 2. assert(dx == 65536 * 2); // Test scale factor of 2.
assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2. assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2.
// Advance to odd row, even column. // Advance to odd row, even column.
...@@ -128,7 +128,7 @@ static void ScaleARGBDownEven(int src_width, int src_height, ...@@ -128,7 +128,7 @@ static void ScaleARGBDownEven(int src_width, int src_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_argb, uint8* dst_argb, const uint8* src_argb, uint8* dst_argb,
int x, int dx, int y, int dy, int x, int dx, int y, int dy,
FilterMode filtering) { enum FilterMode filtering) {
assert(IS_ALIGNED(src_width, 2)); assert(IS_ALIGNED(src_width, 2));
assert(IS_ALIGNED(src_height, 2)); assert(IS_ALIGNED(src_height, 2));
int col_step = dx >> 16; int col_step = dx >> 16;
...@@ -167,7 +167,7 @@ static void ScaleARGBBilinearDown(int src_width, int src_height, ...@@ -167,7 +167,7 @@ static void ScaleARGBBilinearDown(int src_width, int src_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_argb, uint8* dst_argb, const uint8* src_argb, uint8* dst_argb,
int x, int dx, int y, int dy, int x, int dx, int y, int dy,
FilterMode filtering) { enum FilterMode filtering) {
assert(src_height > 0); assert(src_height > 0);
assert(dst_width > 0); assert(dst_width > 0);
assert(dst_height > 0); assert(dst_height > 0);
...@@ -267,7 +267,7 @@ static void ScaleARGBBilinearUp(int src_width, int src_height, ...@@ -267,7 +267,7 @@ static void ScaleARGBBilinearUp(int src_width, int src_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_argb, uint8* dst_argb, const uint8* src_argb, uint8* dst_argb,
int x, int dx, int y, int dy, int x, int dx, int y, int dy,
FilterMode filtering) { enum FilterMode filtering) {
assert(src_width > 0); assert(src_width > 0);
assert(src_height > 0); assert(src_height > 0);
assert(dst_width > 0); assert(dst_width > 0);
...@@ -410,7 +410,7 @@ static void ScaleYUVToARGBBilinearUp(int src_width, int src_height, ...@@ -410,7 +410,7 @@ static void ScaleYUVToARGBBilinearUp(int src_width, int src_height,
const uint8* src_v, const uint8* src_v,
uint8* dst_argb, uint8* dst_argb,
int x, int dx, int y, int dy, int x, int dx, int y, int dy,
FilterMode filtering) { enum FilterMode filtering) {
assert(src_width > 0); assert(src_width > 0);
assert(src_height > 0); assert(src_height > 0);
assert(dst_width > 0); assert(dst_width > 0);
...@@ -658,7 +658,7 @@ static void ScaleARGB(const uint8* src, int src_stride, ...@@ -658,7 +658,7 @@ static void ScaleARGB(const uint8* src, int src_stride,
uint8* dst, int dst_stride, uint8* dst, int dst_stride,
int dst_width, int dst_height, int dst_width, int dst_height,
int clip_x, int clip_y, int clip_width, int clip_height, int clip_x, int clip_y, int clip_width, int clip_height,
FilterMode filtering) { enum FilterMode filtering) {
// ARGB does not support box filter yet, but allow the user to pass it. // ARGB does not support box filter yet, but allow the user to pass it.
// Simplify filtering when possible. // Simplify filtering when possible.
filtering = ScaleFilterReduce(src_width, src_height, filtering = ScaleFilterReduce(src_width, src_height,
...@@ -785,7 +785,7 @@ int ARGBScale(const uint8* src_argb, int src_stride_argb, ...@@ -785,7 +785,7 @@ int ARGBScale(const uint8* src_argb, int src_stride_argb,
int src_width, int src_height, int src_width, int src_height,
uint8* dst_argb, int dst_stride_argb, uint8* dst_argb, int dst_stride_argb,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering) { enum FilterMode filtering) {
if (!src_argb || src_width == 0 || src_height == 0 || if (!src_argb || src_width == 0 || src_height == 0 ||
!dst_argb || dst_width <= 0 || dst_height <= 0) { !dst_argb || dst_width <= 0 || dst_height <= 0) {
return -1; return -1;
......
...@@ -533,7 +533,7 @@ void ScalePlaneVertical(int src_height, ...@@ -533,7 +533,7 @@ void ScalePlaneVertical(int src_height,
int src_stride, int dst_stride, int src_stride, int dst_stride,
const uint8* src_argb, uint8* dst_argb, const uint8* src_argb, uint8* dst_argb,
int x, int y, int dy, int x, int y, int dy,
int bpp, FilterMode filtering) { int bpp, enum FilterMode filtering) {
// TODO(fbarchard): Allow higher bpp. // TODO(fbarchard): Allow higher bpp.
assert(bpp >= 1 && bpp <= 4); assert(bpp >= 1 && bpp <= 4);
assert(src_height != 0); assert(src_height != 0);
...@@ -609,9 +609,9 @@ void ScalePlaneVertical(int src_height, ...@@ -609,9 +609,9 @@ void ScalePlaneVertical(int src_height,
} }
// Simplify the filtering based on scale factors. // Simplify the filtering based on scale factors.
FilterMode ScaleFilterReduce(int src_width, int src_height, enum FilterMode ScaleFilterReduce(int src_width, int src_height,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering) { enum FilterMode filtering) {
if (src_width < 0) { if (src_width < 0) {
src_width = -src_width; src_width = -src_width;
} }
...@@ -670,7 +670,7 @@ int FixedDiv1_C(int num, int div) { ...@@ -670,7 +670,7 @@ int FixedDiv1_C(int num, int div) {
// Compute slope values for stepping. // Compute slope values for stepping.
void ScaleSlope(int src_width, int src_height, void ScaleSlope(int src_width, int src_height,
int dst_width, int dst_height, int dst_width, int dst_height,
FilterMode filtering, enum FilterMode filtering,
int* x, int* y, int* dx, int* dy) { int* x, int* y, int* dx, int* dy) {
assert(x != NULL); assert(x != NULL);
assert(y != NULL); assert(y != NULL);
......
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