[libyuv] Keep LIBYUV_API in basic_types.h and remove legacy types and bool macros

Reduces include/libyuv/basic_types.h to only define LIBYUV_API.
Directly includes <stdint.h> and <stddef.h> where needed in public
headers.
Replaces LIBYUV_BOOL, LIBYUV_FALSE, and LIBYUV_TRUE with C++ bool,
true, and false in C++ code (MJpegDecoder, unit tests) and int (0, 1)
for C API functions.
Updates documentation and unit tests.

Test: ninja -C out/Release libyuv_unittest && ./out/Release/libyuv_unittest --gtest_filter=*
Change-Id: I2d58e872f0f976263bcda546dcc3b1b5f7e53d58
TAG=agy
CONV=2730bc56-93ff-48ed-b615-dcde1b834394
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8280662
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
This commit is contained in:
Frank Barchard 2026-08-27 18:36:37 -07:00 committed by libyuv-scoped@luci-project-accounts.iam.gserviceaccount.com
parent cb6c9d6fd9
commit 0c781f87b8
53 changed files with 137 additions and 164 deletions

View File

@ -144,13 +144,13 @@ A fourcc provided by capturer, can be thought of string, e.g. "ARGB".
On little endian machines, as an int, this would have 'A' in the lowest byte. The FOURCC macro reverses the order:
#define FOURCC(a, b, c, d) (((uint32)(a)) | ((uint32)(b) << 8) | ((uint32)(c) << 16) | ((uint32)(d) << 24))
#define FOURCC(a, b, c, d) (((uint32_t)(a)) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
So the "ARGB" string, read as an uint32, is
So the "ARGB" string, read as an uint32_t, is
FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B')
If you were to read ARGB pixels as uint32's, the alpha would be in the high byte, and the blue in the lowest byte. In memory, these are stored little endian, so 'B' is first, then 'G', 'R' and 'A' last.
If you were to read ARGB pixels as uint32_t's, the alpha would be in the high byte, and the blue in the lowest byte. In memory, these are stored little endian, so 'B' is first, then 'G', 'R' and 'A' last.
When calling conversion functions, the names match the FOURCC, so in this case it would be I420ToARGB().

View File

@ -11,37 +11,6 @@
#ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_
#define INCLUDE_LIBYUV_BASIC_TYPES_H_
#include <stddef.h> // For size_t and NULL
#if !defined(INT_TYPES_DEFINED) && !defined(GG_LONGLONG)
#define INT_TYPES_DEFINED
#if defined(_MSC_VER) && (_MSC_VER < 1600)
#include <sys/types.h> // for uintptr_t on x86
typedef unsigned __int64 uint64_t;
typedef __int64 int64_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned char uint8_t;
typedef signed char int8_t;
#else
#include <stdint.h> // for uintptr_t and C99 types
#endif // defined(_MSC_VER) && (_MSC_VER < 1600)
// Types are deprecated. Enable this macro for legacy types.
#ifdef LIBYUV_LEGACY_TYPES
typedef uint64_t uint64;
typedef int64_t int64;
typedef uint32_t uint32;
typedef int32_t int32;
typedef uint16_t uint16;
typedef int16_t int16;
typedef uint8_t uint8;
typedef int8_t int8;
#endif // LIBYUV_LEGACY_TYPES
#endif // INT_TYPES_DEFINED
#if !defined(LIBYUV_API)
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(LIBYUV_BUILDING_SHARED_LIBRARY)
@ -60,9 +29,4 @@ typedef int8_t int8;
#endif // __GNUC__
#endif // LIBYUV_API
// TODO(fbarchard): Remove bool macros.
#define LIBYUV_BOOL int
#define LIBYUV_FALSE 0
#define LIBYUV_TRUE 1
#endif // INCLUDE_LIBYUV_BASIC_TYPES_H_

View File

@ -11,6 +11,9 @@
#ifndef INCLUDE_LIBYUV_COMPARE_H_
#define INCLUDE_LIBYUV_COMPARE_H_
#include <stddef.h>
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus

View File

@ -11,7 +11,9 @@
#ifndef INCLUDE_LIBYUV_COMPARE_ROW_H_
#define INCLUDE_LIBYUV_COMPARE_ROW_H_
#include "libyuv/basic_types.h"
#include <stddef.h>
#include <stdint.h>
#include "libyuv/cpu_support.h"
#ifdef __cplusplus

View File

@ -11,6 +11,9 @@
#ifndef INCLUDE_LIBYUV_CONVERT_H_
#define INCLUDE_LIBYUV_CONVERT_H_
#include <stddef.h>
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/rotate.h" // For enum RotationMode.

View File

@ -11,6 +11,9 @@
#ifndef INCLUDE_LIBYUV_CONVERT_ARGB_H_
#define INCLUDE_LIBYUV_CONVERT_ARGB_H_
#include <stddef.h>
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/rotate.h" // For enum RotationMode.

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_CONVERT_FROM_H_
#define INCLUDE_LIBYUV_CONVERT_FROM_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/rotate.h"

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_
#define INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_CPU_ID_H_
#define INCLUDE_LIBYUV_CPU_ID_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus

View File

@ -11,6 +11,9 @@
#ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_
#define INCLUDE_LIBYUV_MJPEG_DECODER_H_
#include <stddef.h>
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus
@ -26,7 +29,7 @@ namespace libyuv {
extern "C" {
#endif
LIBYUV_BOOL ValidateJpeg(const uint8_t* sample, size_t sample_size);
int ValidateJpeg(const uint8_t* sample, size_t sample_size);
#ifdef __cplusplus
} // extern "C"
@ -81,11 +84,11 @@ class LIBYUV_API MJpegDecoder {
// Loads a new frame, reads its headers, and determines the uncompressed
// image format.
// Returns LIBYUV_TRUE if image looks valid and format is supported.
// If return value is LIBYUV_TRUE, then the values for all the following
// Returns true if image looks valid and format is supported.
// If return value is true, then the values for all the following
// getters are populated.
// src_len is the size of the compressed mjpeg frame in bytes.
LIBYUV_BOOL LoadFrame(const uint8_t* src, size_t src_len);
bool LoadFrame(const uint8_t* src, size_t src_len);
// Returns width of the last loaded frame in pixels.
int GetWidth();
@ -129,7 +132,7 @@ class LIBYUV_API MJpegDecoder {
// Call this after LoadFrame() if you decide you don't want to decode it
// after all.
LIBYUV_BOOL UnloadFrame();
bool UnloadFrame();
// 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
@ -138,13 +141,13 @@ class LIBYUV_API MJpegDecoder {
// at least GetComponentSize(i). The pointers in planes are incremented
// to point to after the end of the written data.
// TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded.
LIBYUV_BOOL DecodeToBuffers(uint8_t** planes, int dst_width, int dst_height);
bool DecodeToBuffers(uint8_t** planes, int dst_width, int dst_height);
// 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
// image scanlines.
// TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded.
LIBYUV_BOOL DecodeToCallback(CallbackFunction fn,
bool DecodeToCallback(CallbackFunction fn,
void* opaque,
int dst_width,
int dst_height);
@ -159,11 +162,11 @@ class LIBYUV_API MJpegDecoder {
void AllocOutputBuffers(int num_outbufs);
void DestroyOutputBuffers();
LIBYUV_BOOL StartDecode();
LIBYUV_BOOL FinishDecode();
bool StartDecode();
bool FinishDecode();
void SetScanlinePointers(uint8_t** data);
LIBYUV_BOOL DecodeImcuRow();
bool DecodeImcuRow();
int GetComponentScanlinePadding(int component);
@ -175,9 +178,9 @@ class LIBYUV_API MJpegDecoder {
jpeg_source_mgr* source_mgr_;
SetJmpErrorMgr* error_mgr_;
// LIBYUV_TRUE iff at least one component has scanline padding. (i.e.,
// true iff at least one component has scanline padding. (i.e.,
// GetComponentScanlinePadding() != 0.)
LIBYUV_BOOL has_scanline_padding_;
bool has_scanline_padding_;
// Temporaries used to point to scanline outputs.
int num_outbufs_; // Outermost size of all arrays below.

View File

@ -11,6 +11,9 @@
#ifndef INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_
#define INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_
#include <stddef.h>
#include <stdint.h>
#include "libyuv/basic_types.h"
// TODO(fbarchard): Remove the following headers includes.

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_ROTATE_H_
#define INCLUDE_LIBYUV_ROTATE_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_ROTATE_ARGB_H_
#define INCLUDE_LIBYUV_ROTATE_ARGB_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/rotate.h" // For RotationMode.

View File

@ -11,7 +11,9 @@
#ifndef INCLUDE_LIBYUV_ROTATE_ROW_H_
#define INCLUDE_LIBYUV_ROTATE_ROW_H_
#include "libyuv/basic_types.h"
#include <stddef.h>
#include <stdint.h>
#include "libyuv/cpu_support.h"
#ifdef __cplusplus

View File

@ -12,6 +12,7 @@
#define INCLUDE_LIBYUV_ROW_H_
#include <stddef.h> // For NULL
#include <stdint.h>
#include <stdlib.h> // For malloc
#include "libyuv/basic_types.h"

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_SCALE_H_
#define INCLUDE_LIBYUV_SCALE_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus
@ -321,11 +323,11 @@ int Scale(const uint8_t* src_y,
int dst_stride_v,
int dst_width,
int dst_height,
LIBYUV_BOOL interpolate);
int interpolate);
// For testing, allow disabling of specialized scalers.
LIBYUV_API
void SetUseReferenceImpl(LIBYUV_BOOL use);
void SetUseReferenceImpl(int use);
#endif // __cplusplus
#ifdef __cplusplus

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_SCALE_ARGB_H_
#define INCLUDE_LIBYUV_SCALE_ARGB_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/scale.h" // For FilterMode

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_SCALE_RGB_H_
#define INCLUDE_LIBYUV_SCALE_RGB_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/scale.h" // For FilterMode

View File

@ -11,7 +11,9 @@
#ifndef INCLUDE_LIBYUV_SCALE_ROW_H_
#define INCLUDE_LIBYUV_SCALE_ROW_H_
#include "libyuv/basic_types.h"
#include <stddef.h>
#include <stdint.h>
#include "libyuv/cpu_support.h"
#include "libyuv/scale.h"

View File

@ -11,6 +11,8 @@
#ifndef INCLUDE_LIBYUV_SCALE_UV_H_
#define INCLUDE_LIBYUV_SCALE_UV_H_
#include <stdint.h>
#include "libyuv/basic_types.h"
#include "libyuv/scale.h" // For FilterMode

View File

@ -13,6 +13,9 @@
#ifndef INCLUDE_LIBYUV_VIDEO_COMMON_H_
#define INCLUDE_LIBYUV_VIDEO_COMMON_H_
#include <stddef.h>
#include <stdint.h>
#include "libyuv/basic_types.h"
#ifdef __cplusplus

View File

@ -17,7 +17,6 @@
#include <omp.h>
#endif
#include "libyuv/basic_types.h"
#include "libyuv/compare_row.h"
#include "libyuv/cpu_id.h"
#include "libyuv/row.h"

View File

@ -8,8 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "libyuv/basic_types.h"
#include "libyuv/compare_row.h"
#ifdef __cplusplus

View File

@ -8,8 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "libyuv/basic_types.h"
#include "libyuv/compare_row.h"
#include "libyuv/row.h"

View File

@ -8,8 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "libyuv/basic_types.h"
#include "libyuv/compare_row.h"
#include "libyuv/row.h"

View File

@ -8,8 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "libyuv/basic_types.h"
#include "libyuv/compare_row.h"
#include "libyuv/row.h"

View File

@ -8,8 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "libyuv/basic_types.h"
#include "libyuv/compare_row.h"
#include "libyuv/row.h"

View File

@ -12,7 +12,6 @@
#include <limits.h>
#include "libyuv/basic_types.h"
#include "libyuv/convert_from_argb.h"
#include "libyuv/cpu_id.h"
#include "libyuv/planar_functions.h"

View File

@ -12,7 +12,6 @@
#include <limits.h>
#include "libyuv/basic_types.h"
#include "libyuv/convert.h" // For I420Copy
#include "libyuv/cpu_id.h"
#include "libyuv/planar_functions.h"

View File

@ -13,7 +13,6 @@
#include <limits.h>
#include <string.h> // For memcpy.
#include "libyuv/basic_types.h"
#include "libyuv/cpu_id.h"
#include "libyuv/planar_functions.h"
#include "libyuv/row.h"

View File

@ -94,7 +94,7 @@ int MJPGSize(const uint8_t* src_mjpg,
int* width,
int* height) {
MJpegDecoder mjpeg_decoder;
LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
if (ret) {
*width = mjpeg_decoder.GetWidth();
*height = mjpeg_decoder.GetHeight();
@ -126,7 +126,7 @@ int MJPGToI420(const uint8_t* src_mjpg,
// TODO(fbarchard): Port MJpeg to C.
MJpegDecoder mjpeg_decoder;
LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
if (ret && (mjpeg_decoder.GetWidth() != src_width ||
mjpeg_decoder.GetHeight() != src_height)) {
// ERROR: MJPEG frame has unexpected dimensions
@ -266,7 +266,7 @@ int MJPGToNV21(const uint8_t* src_mjpg,
// TODO(fbarchard): Port MJpeg to C.
MJpegDecoder mjpeg_decoder;
LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
if (ret && (mjpeg_decoder.GetWidth() != src_width ||
mjpeg_decoder.GetHeight() != src_height)) {
// ERROR: MJPEG frame has unexpected dimensions
@ -399,7 +399,7 @@ int MJPGToNV12(const uint8_t* sample,
// TODO(fbarchard): Port MJpeg to C.
MJpegDecoder mjpeg_decoder;
LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(sample, sample_size);
bool ret = mjpeg_decoder.LoadFrame(sample, sample_size);
if (ret && (mjpeg_decoder.GetWidth() != src_width ||
mjpeg_decoder.GetHeight() != src_height)) {
// ERROR: MJPEG frame has unexpected dimensions
@ -531,7 +531,7 @@ int MJPGToARGB(const uint8_t* src_mjpg,
// TODO(fbarchard): Port MJpeg to C.
MJpegDecoder mjpeg_decoder;
LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg);
if (ret && (mjpeg_decoder.GetWidth() != src_width ||
mjpeg_decoder.GetHeight() != src_height)) {
// ERROR: MJPEG frame has unexpected dimensions

View File

@ -78,7 +78,7 @@ int ConvertToARGB(const uint8_t* sample,
// and then rotate the ARGB to the final destination buffer.
// For in-place conversion, if destination dst_argb is same as source sample,
// also enable temporary buffer.
LIBYUV_BOOL need_buf =
int need_buf =
(rotation && format != FOURCC_ARGB) || dst_argb == sample;
uint8_t* dest_argb = dst_argb;
int dest_dst_stride_argb = dst_stride_argb;

View File

@ -63,7 +63,7 @@ int ConvertToI420(const uint8_t* sample,
const uint8_t* src;
const uint8_t* src_uv;
int r = 0;
LIBYUV_BOOL need_buf =
int need_buf =
(rotation && format != FOURCC_I420 && format != FOURCC_NV12 &&
format != FOURCC_NV21 && format != FOURCC_YV12) ||
dst_y == sample;

View File

@ -65,7 +65,7 @@ void ErrorHandler(jpeg_common_struct* cinfo);
void OutputHandler(jpeg_common_struct* cinfo);
MJpegDecoder::MJpegDecoder()
: has_scanline_padding_(LIBYUV_FALSE),
: has_scanline_padding_(false),
num_outbufs_(0),
scanlines_(NULL),
scanlines_sizes_(NULL),
@ -102,9 +102,9 @@ MJpegDecoder::~MJpegDecoder() {
DestroyOutputBuffers();
}
LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) {
bool MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) {
if (!ValidateJpeg(src, src_len)) {
return LIBYUV_FALSE;
return false;
}
buf_.data = src;
@ -115,12 +115,12 @@ LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) {
if (setjmp(error_mgr_->setjmp_buffer)) {
// We called jpeg_read_header, it experienced an error, and we called
// longjmp() and rewound the stack to here. Return error.
return LIBYUV_FALSE;
return false;
}
#endif
if (jpeg_read_header(decompress_struct_, TRUE) != JPEG_HEADER_OK) {
// ERROR: Bad MJPEG header
return LIBYUV_FALSE;
return false;
}
AllocOutputBuffers(GetNumComponents());
for (int i = 0; i < num_outbufs_; ++i) {
@ -154,10 +154,10 @@ LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) {
}
if (GetComponentStride(i) != GetComponentWidth(i)) {
has_scanline_padding_ = LIBYUV_TRUE;
has_scanline_padding_ = true;
}
}
return LIBYUV_TRUE;
return true;
}
static int DivideAndRoundUp(int numerator, int denominator) {
@ -234,36 +234,36 @@ int MJpegDecoder::GetComponentSize(int component) {
return GetComponentWidth(component) * GetComponentHeight(component);
}
LIBYUV_BOOL MJpegDecoder::UnloadFrame() {
bool MJpegDecoder::UnloadFrame() {
#ifdef HAVE_SETJMP
if (setjmp(error_mgr_->setjmp_buffer)) {
// We called jpeg_abort_decompress, it experienced an error, and we called
// longjmp() and rewound the stack to here. Return error.
return LIBYUV_FALSE;
return false;
}
#endif
jpeg_abort_decompress(decompress_struct_);
return LIBYUV_TRUE;
return true;
}
// TODO(fbarchard): Allow rectangle to be specified: x, y, width, height.
LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
bool MJpegDecoder::DecodeToBuffers(uint8_t** planes,
int dst_width,
int dst_height) {
if (dst_width != GetWidth() || dst_height > GetHeight()) {
// ERROR: Bad dimensions
return LIBYUV_FALSE;
return false;
}
#ifdef HAVE_SETJMP
if (setjmp(error_mgr_->setjmp_buffer)) {
// We called into jpeglib, it experienced an error sometime during this
// function call, and we called longjmp() and rewound the stack to here.
// Return error.
return LIBYUV_FALSE;
return false;
}
#endif
if (!StartDecode()) {
return LIBYUV_FALSE;
return false;
}
SetScanlinePointers(databuf_);
int lines_left = dst_height;
@ -277,7 +277,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
while (skip >= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
skip -= GetImageScanlinesPerImcuRow();
}
@ -286,7 +286,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
// copy the parts we want into the destination.
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
for (int i = 0; i < num_outbufs_; ++i) {
// TODO(fbarchard): Compute skip to avoid this
@ -309,7 +309,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
lines_left -= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
for (int i = 0; i < num_outbufs_; ++i) {
int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i);
@ -323,7 +323,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
// Have a partial iMCU row left over to decode.
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
for (int i = 0; i < num_outbufs_; ++i) {
int scanlines_to_copy =
@ -336,24 +336,24 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
return FinishDecode();
}
LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn,
bool MJpegDecoder::DecodeToCallback(CallbackFunction fn,
void* opaque,
int dst_width,
int dst_height) {
if (dst_width != GetWidth() || dst_height > GetHeight()) {
// ERROR: Bad dimensions
return LIBYUV_FALSE;
return false;
}
#ifdef HAVE_SETJMP
if (setjmp(error_mgr_->setjmp_buffer)) {
// We called into jpeglib, it experienced an error sometime during this
// function call, and we called longjmp() and rewound the stack to here.
// Return error.
return LIBYUV_FALSE;
return false;
}
#endif
if (!StartDecode()) {
return LIBYUV_FALSE;
return false;
}
SetScanlinePointers(databuf_);
int lines_left = dst_height;
@ -363,7 +363,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn,
while (skip >= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
skip -= GetImageScanlinesPerImcuRow();
}
@ -371,7 +371,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn,
// Have a partial iMCU row left over to skip.
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
for (int i = 0; i < num_outbufs_; ++i) {
// TODO(fbarchard): Compute skip to avoid this
@ -398,7 +398,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn,
lines_left -= GetImageScanlinesPerImcuRow()) {
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
(*fn)(opaque, databuf_, databuf_strides_, GetImageScanlinesPerImcuRow());
}
@ -406,7 +406,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn,
// Have a partial iMCU row left over to decode.
if (!DecodeImcuRow()) {
FinishDecode();
return LIBYUV_FALSE;
return false;
}
(*fn)(opaque, databuf_, databuf_strides_, lines_left);
}
@ -513,29 +513,29 @@ void MJpegDecoder::DestroyOutputBuffers() {
}
// JDCT_IFAST and do_block_smoothing improve performance substantially.
LIBYUV_BOOL MJpegDecoder::StartDecode() {
bool MJpegDecoder::StartDecode() {
decompress_struct_->raw_data_out = TRUE;
decompress_struct_->dct_method = JDCT_IFAST; // JDCT_ISLOW is default
decompress_struct_->dither_mode = JDITHER_NONE;
// Not applicable to 'raw':
decompress_struct_->do_fancy_upsampling = (boolean)(LIBYUV_FALSE);
decompress_struct_->do_fancy_upsampling = (boolean)(0);
// Only for buffered mode:
decompress_struct_->enable_2pass_quant = (boolean)(LIBYUV_FALSE);
decompress_struct_->enable_2pass_quant = (boolean)(0);
// Blocky but fast:
decompress_struct_->do_block_smoothing = (boolean)(LIBYUV_FALSE);
decompress_struct_->do_block_smoothing = (boolean)(0);
if (!jpeg_start_decompress(decompress_struct_)) {
// ERROR: Couldn't start JPEG decompressor";
return LIBYUV_FALSE;
return false;
}
return LIBYUV_TRUE;
return true;
}
LIBYUV_BOOL MJpegDecoder::FinishDecode() {
bool MJpegDecoder::FinishDecode() {
// jpeglib considers it an error if we finish without decoding the whole
// image, so we call "abort" rather than "finish".
jpeg_abort_decompress(decompress_struct_);
return LIBYUV_TRUE;
return true;
}
void MJpegDecoder::SetScanlinePointers(uint8_t** data) {
@ -548,7 +548,7 @@ void MJpegDecoder::SetScanlinePointers(uint8_t** data) {
}
}
inline LIBYUV_BOOL MJpegDecoder::DecodeImcuRow() {
inline bool MJpegDecoder::DecodeImcuRow() {
return (unsigned int)(GetImageScanlinesPerImcuRow()) ==
jpeg_read_raw_data(decompress_struct_, scanlines_,
GetImageScanlinesPerImcuRow());

View File

@ -18,7 +18,7 @@ extern "C" {
#endif
// Helper function to scan for EOI marker (0xff 0xd9).
static LIBYUV_BOOL ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) {
static int ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) {
if (src_size_mjpg >= 2) {
const uint8_t* end = src_mjpg + src_size_mjpg - 1;
const uint8_t* it = src_mjpg;
@ -29,34 +29,34 @@ static LIBYUV_BOOL ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) {
break;
}
if (it[1] == 0xd9) {
return LIBYUV_TRUE; // Success: Valid jpeg.
return 1; // Success: Valid jpeg.
}
++it; // Skip over current 0xff.
}
}
// ERROR: Invalid jpeg end code not found. Size src_size_mjpg
return LIBYUV_FALSE;
return 0;
}
// Helper function to validate the jpeg appears intact.
LIBYUV_BOOL ValidateJpeg(const uint8_t* src_mjpg, size_t src_size_mjpg) {
int ValidateJpeg(const uint8_t* src_mjpg, size_t src_size_mjpg) {
// Maximum size that ValidateJpeg will consider valid.
const size_t kMaxJpegSize = 0x7fffffffull;
const size_t kBackSearchSize = 1024;
if (src_size_mjpg < 64 || src_size_mjpg > kMaxJpegSize || !src_mjpg) {
// ERROR: Invalid jpeg size: src_size_mjpg
return LIBYUV_FALSE;
return 0;
}
// SOI marker
if (src_mjpg[0] != 0xff || src_mjpg[1] != 0xd8 || src_mjpg[2] != 0xff) {
// ERROR: Invalid jpeg initial start code
return LIBYUV_FALSE;
return 0;
}
// Look for the End Of Image (EOI) marker near the end of the buffer.
if (src_size_mjpg > kBackSearchSize) {
if (ScanEOI(src_mjpg + src_size_mjpg - kBackSearchSize, kBackSearchSize)) {
return LIBYUV_TRUE; // Success: Valid jpeg.
return 1; // Success: Valid jpeg.
}
// Reduce search size for forward search.
src_size_mjpg = src_size_mjpg - kBackSearchSize + 1;

View File

@ -11,8 +11,6 @@
#include "libyuv/rotate.h"
#include "libyuv/rotate_row.h"
#include "libyuv/basic_types.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {

View File

@ -11,8 +11,6 @@
#include "libyuv/rotate_row.h"
#include "libyuv/row.h"
#include "libyuv/basic_types.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {

View File

@ -11,8 +11,6 @@
#include "libyuv/rotate_row.h"
#include "libyuv/row.h"
#include "libyuv/basic_types.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {

View File

@ -11,8 +11,6 @@
#include "libyuv/rotate_row.h"
#include "libyuv/row.h"
#include "libyuv/basic_types.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {

View File

@ -13,8 +13,6 @@
#include <assert.h>
#include <string.h> // For memset.
#include "libyuv/basic_types.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {

View File

@ -13,7 +13,6 @@
#include <assert.h>
#include <string.h> // For memcpy and memset.
#include "libyuv/basic_types.h"
#include "libyuv/convert_argb.h" // For kYuvI601Constants
#include "libyuv/convert_from_argb.h" // For ArgbConstants

View File

@ -2688,7 +2688,7 @@ int Scale(const uint8_t* src_y,
int dst_stride_v,
int dst_width,
int dst_height,
LIBYUV_BOOL interpolate) {
int interpolate) {
return I420Scale(src_y, src_stride_y, src_u, src_stride_u, src_v,
src_stride_v, src_width, src_height, dst_y, dst_stride_y,
dst_u, dst_stride_u, dst_v, dst_stride_v, dst_width,

View File

@ -14,8 +14,6 @@
#include "libyuv/scale.h"
#include "libyuv/scale_row.h"
#include "libyuv/basic_types.h"
#ifdef __cplusplus
namespace libyuv {
extern "C" {

View File

@ -8,8 +8,9 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdint.h>
#include "../unit_test/unit_test.h"
#include "libyuv/basic_types.h"
namespace libyuv {

View File

@ -11,7 +11,6 @@
#include <stdlib.h>
#include "../unit_test/unit_test.h"
#include "libyuv/basic_types.h"
#include "libyuv/convert.h"
#include "libyuv/convert_argb.h"
#include "libyuv/convert_from.h"

View File

@ -13,7 +13,6 @@
#include <time.h>
#include "../unit_test/unit_test.h"
#include "libyuv/basic_types.h"
#include "libyuv/compare.h"
#include "libyuv/cpu_id.h"
#include "libyuv/video_common.h"

View File

@ -13,7 +13,6 @@
#include <time.h>
#include "../unit_test/unit_test.h"
#include "libyuv/basic_types.h"
#include "libyuv/compare.h"
#include "libyuv/convert.h"
#include "libyuv/convert_argb.h"

View File

@ -12,7 +12,6 @@
#include <stdlib.h>
#include <time.h>
#include "libyuv/basic_types.h"
#include "libyuv/compare.h"
#include "libyuv/convert.h"
#include "libyuv/convert_argb.h"
@ -1737,9 +1736,9 @@ TEST_F(LibYUVConvertTest, TestMJPGToARGB) {
free_aligned_buffer_page_end(dst_argb);
}
static int ShowJPegInfo(const uint8_t* sample, size_t sample_size) {
static bool ShowJPegInfo(const uint8_t* sample, size_t sample_size) {
MJpegDecoder mjpeg_decoder;
LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(sample, sample_size);
bool ret = mjpeg_decoder.LoadFrame(sample, sample_size);
int width = mjpeg_decoder.GetWidth();
int height = mjpeg_decoder.GetHeight();
@ -1794,11 +1793,11 @@ static int ShowJPegInfo(const uint8_t* sample, size_t sample_size) {
}
TEST_F(LibYUVConvertTest, TestMJPGInfo) {
ASSERT_EQ(1, ShowJPegInfo(kTest0Jpg, kTest0JpgLen));
ASSERT_EQ(1, ShowJPegInfo(kTest1Jpg, kTest1JpgLen));
ASSERT_EQ(1, ShowJPegInfo(kTest2Jpg, kTest2JpgLen));
ASSERT_EQ(1, ShowJPegInfo(kTest3Jpg, kTest3JpgLen));
ASSERT_EQ(1, ShowJPegInfo(kTest4Jpg,
ASSERT_TRUE(ShowJPegInfo(kTest0Jpg, kTest0JpgLen));
ASSERT_TRUE(ShowJPegInfo(kTest1Jpg, kTest1JpgLen));
ASSERT_TRUE(ShowJPegInfo(kTest2Jpg, kTest2JpgLen));
ASSERT_TRUE(ShowJPegInfo(kTest3Jpg, kTest3JpgLen));
ASSERT_TRUE(ShowJPegInfo(kTest4Jpg,
kTest4JpgLen)); // Valid but unsupported.
}
#endif // HAVE_JPEG

View File

@ -18,7 +18,6 @@
#endif
#include "../unit_test/unit_test.h"
#include "libyuv/basic_types.h"
#include "libyuv/cpu_id.h"
#include "libyuv/version.h"

View File

@ -13,7 +13,6 @@
#include <time.h>
#include "../unit_test/unit_test.h"
#include "libyuv/basic_types.h"
#include "libyuv/cpu_id.h"
#include "libyuv/scale.h"

View File

@ -52,18 +52,18 @@ static const int32_t FLAGS_libyuv_cpu_info = 0;
// Test environment variable for disabling CPU features. Any non-zero value
// to disable. Zero ignored to make it easy to set the variable on/off.
#if !defined(__native_client__) && !defined(_M_ARM)
static LIBYUV_BOOL TestEnv(const char* name) {
static bool TestEnv(const char* name) {
const char* var = getenv(name);
if (var) {
if (var[0] != '0') {
return LIBYUV_TRUE;
return true;
}
}
return LIBYUV_FALSE;
return false;
}
#else // nacl does not support getenv().
static LIBYUV_BOOL TestEnv(const char*) {
return LIBYUV_FALSE;
static bool TestEnv(const char*) {
return false;
}
#endif

View File

@ -12,6 +12,7 @@
#define UNIT_TEST_UNIT_TEST_H_
#include <stddef.h> // For NULL
#include <stdint.h>
#ifdef _WIN32
#include <windows.h>
#elif !defined(__hexagon__)
@ -21,8 +22,6 @@
// pragma to disable warning for ASSERT_NE
#include <gtest/gtest.h> // IWYU pragma: export
#include "libyuv/basic_types.h"
#ifndef SIMD_ALIGNED
#if defined(_MSC_VER) && !defined(__CLR_VER)
#define SIMD_ALIGNED(var) __declspec(align(16)) var

View File

@ -13,7 +13,6 @@
#include <string.h>
#include <time.h>
#include "libyuv/basic_types.h"
#include "libyuv/compare.h"
#include "libyuv/version.h"