WEBP_REDUCE_SIZE: disable all rescaler code

BUG=webp:355

Change-Id: Id87cb11902e3fb8544a214308526ea9665ce8440
This commit is contained in:
Pascal Massimino 2017-11-24 00:13:27 -08:00
parent 9ca568ef82
commit 0df22b9eed
9 changed files with 36 additions and 8 deletions

View File

@ -194,7 +194,9 @@ VP8StatusCode WebPAllocateDecBuffer(int width, int height,
width = cw; width = cw;
height = ch; height = ch;
} }
if (options->use_scaling) { if (options->use_scaling) {
#if !defined(WEBP_REDUCE_SIZE)
int scaled_width = options->scaled_width; int scaled_width = options->scaled_width;
int scaled_height = options->scaled_height; int scaled_height = options->scaled_height;
if (!WebPRescalerGetScaledDimensions( if (!WebPRescalerGetScaledDimensions(
@ -203,6 +205,9 @@ VP8StatusCode WebPAllocateDecBuffer(int width, int height,
} }
width = scaled_width; width = scaled_width;
height = scaled_height; height = scaled_height;
#else
return VP8_STATUS_INVALID_PARAM; // rescaling not supported
#endif
} }
} }
buffer->width = width; buffer->width = width;

View File

@ -241,6 +241,7 @@ static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// YUV rescaling (no final RGB conversion needed) // YUV rescaling (no final RGB conversion needed)
#if !defined(WEBP_REDUCE_SIZE)
static int Rescale(const uint8_t* src, int src_stride, static int Rescale(const uint8_t* src, int src_stride,
int new_lines, WebPRescaler* const wrk) { int new_lines, WebPRescaler* const wrk) {
int num_lines_out = 0; int num_lines_out = 0;
@ -541,6 +542,8 @@ static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) {
return 1; return 1;
} }
#endif // WEBP_REDUCE_SIZE
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Default custom functions // Default custom functions
@ -561,10 +564,14 @@ static int CustomSetup(VP8Io* io) {
WebPInitUpsamplers(); WebPInitUpsamplers();
} }
if (io->use_scaling) { if (io->use_scaling) {
#if !defined(WEBP_REDUCE_SIZE)
const int ok = is_rgb ? InitRGBRescaler(io, p) : InitYUVRescaler(io, p); const int ok = is_rgb ? InitRGBRescaler(io, p) : InitYUVRescaler(io, p);
if (!ok) { if (!ok) {
return 0; // memory error return 0; // memory error
} }
#else
return 0; // rescaling support not compiled
#endif
} else { } else {
if (is_rgb) { if (is_rgb) {
WebPInitSamplers(); WebPInitSamplers();

View File

@ -485,6 +485,7 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Scaling. // Scaling.
#if !defined(WEBP_REDUCE_SIZE)
static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) { static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) {
const int num_channels = 4; const int num_channels = 4;
const int in_width = io->mb_w; const int in_width = io->mb_w;
@ -516,10 +517,13 @@ static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) {
out_width, out_height, 0, num_channels, work); out_width, out_height, 0, num_channels, work);
return 1; return 1;
} }
#endif // WEBP_REDUCE_SIZE
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Export to ARGB // Export to ARGB
#if !defined(WEBP_REDUCE_SIZE)
// We have special "export" function since we need to convert from BGRA // We have special "export" function since we need to convert from BGRA
static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace, static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace,
int rgba_stride, uint8_t* const rgba) { int rgba_stride, uint8_t* const rgba) {
@ -561,6 +565,8 @@ static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec,
return num_lines_out; return num_lines_out;
} }
#endif // WEBP_REDUCE_SIZE
// Emit rows without any scaling. // Emit rows without any scaling.
static int EmitRows(WEBP_CSP_MODE colorspace, static int EmitRows(WEBP_CSP_MODE colorspace,
const uint8_t* row_in, int in_stride, const uint8_t* row_in, int in_stride,
@ -746,9 +752,12 @@ static void ProcessRows(VP8LDecoder* const dec, int row) {
if (WebPIsRGBMode(output->colorspace)) { // convert to RGBA if (WebPIsRGBMode(output->colorspace)) { // convert to RGBA
const WebPRGBABuffer* const buf = &output->u.RGBA; const WebPRGBABuffer* const buf = &output->u.RGBA;
uint8_t* const rgba = buf->rgba + dec->last_out_row_ * buf->stride; uint8_t* const rgba = buf->rgba + dec->last_out_row_ * buf->stride;
const int num_rows_out = io->use_scaling ? const int num_rows_out =
#if !defined(WEBP_REDUCE_SIZE)
io->use_scaling ?
EmitRescaledRowsRGBA(dec, rows_data, in_stride, io->mb_h, EmitRescaledRowsRGBA(dec, rows_data, in_stride, io->mb_h,
rgba, buf->stride) : rgba, buf->stride) :
#endif // WEBP_REDUCE_SIZE
EmitRows(output->colorspace, rows_data, in_stride, EmitRows(output->colorspace, rows_data, in_stride,
io->mb_w, io->mb_h, rgba, buf->stride); io->mb_w, io->mb_h, rgba, buf->stride);
// Update 'last_out_row_'. // Update 'last_out_row_'.
@ -1632,12 +1641,19 @@ int VP8LDecodeImage(VP8LDecoder* const dec) {
if (!AllocateInternalBuffers32b(dec, io->width)) goto Err; if (!AllocateInternalBuffers32b(dec, io->width)) goto Err;
#if !defined(WEBP_REDUCE_SIZE)
if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err; if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err;
if (io->use_scaling || WebPIsPremultipliedMode(dec->output_->colorspace)) { if (io->use_scaling || WebPIsPremultipliedMode(dec->output_->colorspace)) {
// need the alpha-multiply functions for premultiplied output or rescaling // need the alpha-multiply functions for premultiplied output or rescaling
WebPInitAlphaProcessing(); WebPInitAlphaProcessing();
} }
#else
if (io->use_scaling) {
dec->status_ = VP8_STATUS_INVALID_PARAM;
goto Err;
}
#endif
if (!WebPIsRGBMode(dec->output_->colorspace)) { if (!WebPIsRGBMode(dec->output_->colorspace)) {
WebPInitConvertARGBToYUV(); WebPInitConvertARGBToYUV();
if (dec->output_->u.YUVA.a != NULL) WebPInitAlphaProcessing(); if (dec->output_->u.YUVA.a != NULL) WebPInitAlphaProcessing();

View File

@ -209,7 +209,7 @@ static volatile VP8CPUInfo rescaler_last_cpuinfo_used =
WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) { WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) {
if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return; if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return;
#if !defined(WEBP_REDUCE_SIZE)
#if !WEBP_NEON_OMIT_C_CODE #if !WEBP_NEON_OMIT_C_CODE
WebPRescalerExportRowExpand = WebPRescalerExportRowExpand_C; WebPRescalerExportRowExpand = WebPRescalerExportRowExpand_C;
WebPRescalerExportRowShrink = WebPRescalerExportRowShrink_C; WebPRescalerExportRowShrink = WebPRescalerExportRowShrink_C;
@ -252,6 +252,6 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) {
assert(WebPRescalerExportRowShrink != NULL); assert(WebPRescalerExportRowShrink != NULL);
assert(WebPRescalerImportRowExpand != NULL); assert(WebPRescalerImportRowExpand != NULL);
assert(WebPRescalerImportRowShrink != NULL); assert(WebPRescalerImportRowShrink != NULL);
#endif // WEBP_REDUCE_SIZE
rescaler_last_cpuinfo_used = VP8GetCPUInfo; rescaler_last_cpuinfo_used = VP8GetCPUInfo;
} }

View File

@ -13,7 +13,7 @@
#include "src/dsp/dsp.h" #include "src/dsp/dsp.h"
#if defined(WEBP_USE_MIPS32) #if defined(WEBP_USE_MIPS32) && !defined(WEBP_REDUCE_SIZE)
#include <assert.h> #include <assert.h>
#include "src/utils/rescaler_utils.h" #include "src/utils/rescaler_utils.h"

View File

@ -13,7 +13,7 @@
#include "src/dsp/dsp.h" #include "src/dsp/dsp.h"
#if defined(WEBP_USE_MIPS_DSP_R2) #if defined(WEBP_USE_MIPS_DSP_R2) && !defined(WEBP_REDUCE_SIZE)
#include <assert.h> #include <assert.h>
#include "src/utils/rescaler_utils.h" #include "src/utils/rescaler_utils.h"

View File

@ -13,7 +13,7 @@
#include "src/dsp/dsp.h" #include "src/dsp/dsp.h"
#if defined(WEBP_USE_MSA) #if defined(WEBP_USE_MSA) && !defined(WEBP_REDUCE_SIZE)
#include <assert.h> #include <assert.h>

View File

@ -13,7 +13,7 @@
#include "src/dsp/dsp.h" #include "src/dsp/dsp.h"
#if defined(WEBP_USE_NEON) #if defined(WEBP_USE_NEON) && !defined(WEBP_REDUCE_SIZE)
#include <arm_neon.h> #include <arm_neon.h>
#include <assert.h> #include <assert.h>

View File

@ -13,7 +13,7 @@
#include "src/dsp/dsp.h" #include "src/dsp/dsp.h"
#if defined(WEBP_USE_SSE2) #if defined(WEBP_USE_SSE2) && !defined(WEBP_REDUCE_SIZE)
#include <emmintrin.h> #include <emmintrin.h>
#include <assert.h> #include <assert.h>