From 1b27bf8b76fb4914ae8b5f3e5147db2cfb8fec26 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Fri, 24 Nov 2017 00:13:27 -0800 Subject: [PATCH] WEBP_REDUCE_SIZE: disable all rescaler code BUG=webp:355 Change-Id: Id87cb11902e3fb8544a214308526ea9665ce8440 (cherry picked from commit 0df22b9eed70f51029648de5218a9b576a72ba54) --- src/dec/buffer_dec.c | 5 +++++ src/dec/io_dec.c | 7 +++++++ src/dec/vp8l_dec.c | 18 +++++++++++++++++- src/dsp/rescaler.c | 4 ++-- src/dsp/rescaler_mips32.c | 2 +- src/dsp/rescaler_mips_dsp_r2.c | 2 +- src/dsp/rescaler_msa.c | 2 +- src/dsp/rescaler_neon.c | 2 +- src/dsp/rescaler_sse2.c | 2 +- 9 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/dec/buffer_dec.c b/src/dec/buffer_dec.c index 5fea4021..75eb3c40 100644 --- a/src/dec/buffer_dec.c +++ b/src/dec/buffer_dec.c @@ -194,7 +194,9 @@ VP8StatusCode WebPAllocateDecBuffer(int width, int height, width = cw; height = ch; } + if (options->use_scaling) { +#if !defined(WEBP_REDUCE_SIZE) int scaled_width = options->scaled_width; int scaled_height = options->scaled_height; if (!WebPRescalerGetScaledDimensions( @@ -203,6 +205,9 @@ VP8StatusCode WebPAllocateDecBuffer(int width, int height, } width = scaled_width; height = scaled_height; +#else + return VP8_STATUS_INVALID_PARAM; // rescaling not supported +#endif } } buffer->width = width; diff --git a/src/dec/io_dec.c b/src/dec/io_dec.c index 576c12d4..e603f19c 100644 --- a/src/dec/io_dec.c +++ b/src/dec/io_dec.c @@ -241,6 +241,7 @@ static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p, //------------------------------------------------------------------------------ // YUV rescaling (no final RGB conversion needed) +#if !defined(WEBP_REDUCE_SIZE) static int Rescale(const uint8_t* src, int src_stride, int new_lines, WebPRescaler* const wrk) { int num_lines_out = 0; @@ -541,6 +542,8 @@ static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) { return 1; } +#endif // WEBP_REDUCE_SIZE + //------------------------------------------------------------------------------ // Default custom functions @@ -561,10 +564,14 @@ static int CustomSetup(VP8Io* io) { WebPInitUpsamplers(); } if (io->use_scaling) { +#if !defined(WEBP_REDUCE_SIZE) const int ok = is_rgb ? InitRGBRescaler(io, p) : InitYUVRescaler(io, p); if (!ok) { return 0; // memory error } +#else + return 0; // rescaling support not compiled +#endif } else { if (is_rgb) { WebPInitSamplers(); diff --git a/src/dec/vp8l_dec.c b/src/dec/vp8l_dec.c index b3ffcbda..42ea3b5e 100644 --- a/src/dec/vp8l_dec.c +++ b/src/dec/vp8l_dec.c @@ -485,6 +485,7 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize, //------------------------------------------------------------------------------ // Scaling. +#if !defined(WEBP_REDUCE_SIZE) static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) { const int num_channels = 4; 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); return 1; } +#endif // WEBP_REDUCE_SIZE //------------------------------------------------------------------------------ // Export to ARGB +#if !defined(WEBP_REDUCE_SIZE) + // We have special "export" function since we need to convert from BGRA static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace, int rgba_stride, uint8_t* const rgba) { @@ -561,6 +565,8 @@ static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec, return num_lines_out; } +#endif // WEBP_REDUCE_SIZE + // Emit rows without any scaling. static int EmitRows(WEBP_CSP_MODE colorspace, 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 const WebPRGBABuffer* const buf = &output->u.RGBA; 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, rgba, buf->stride) : +#endif // WEBP_REDUCE_SIZE EmitRows(output->colorspace, rows_data, in_stride, io->mb_w, io->mb_h, rgba, buf->stride); // Update 'last_out_row_'. @@ -1632,12 +1641,19 @@ int VP8LDecodeImage(VP8LDecoder* const dec) { 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 || WebPIsPremultipliedMode(dec->output_->colorspace)) { // need the alpha-multiply functions for premultiplied output or rescaling WebPInitAlphaProcessing(); } +#else + if (io->use_scaling) { + dec->status_ = VP8_STATUS_INVALID_PARAM; + goto Err; + } +#endif if (!WebPIsRGBMode(dec->output_->colorspace)) { WebPInitConvertARGBToYUV(); if (dec->output_->u.YUVA.a != NULL) WebPInitAlphaProcessing(); diff --git a/src/dsp/rescaler.c b/src/dsp/rescaler.c index dc61325b..4b6b7834 100644 --- a/src/dsp/rescaler.c +++ b/src/dsp/rescaler.c @@ -209,7 +209,7 @@ static volatile VP8CPUInfo rescaler_last_cpuinfo_used = WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) { if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return; - +#if !defined(WEBP_REDUCE_SIZE) #if !WEBP_NEON_OMIT_C_CODE WebPRescalerExportRowExpand = WebPRescalerExportRowExpand_C; WebPRescalerExportRowShrink = WebPRescalerExportRowShrink_C; @@ -252,6 +252,6 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) { assert(WebPRescalerExportRowShrink != NULL); assert(WebPRescalerImportRowExpand != NULL); assert(WebPRescalerImportRowShrink != NULL); - +#endif // WEBP_REDUCE_SIZE rescaler_last_cpuinfo_used = VP8GetCPUInfo; } diff --git a/src/dsp/rescaler_mips32.c b/src/dsp/rescaler_mips32.c index 17014fc8..542f7e59 100644 --- a/src/dsp/rescaler_mips32.c +++ b/src/dsp/rescaler_mips32.c @@ -13,7 +13,7 @@ #include "src/dsp/dsp.h" -#if defined(WEBP_USE_MIPS32) +#if defined(WEBP_USE_MIPS32) && !defined(WEBP_REDUCE_SIZE) #include #include "src/utils/rescaler_utils.h" diff --git a/src/dsp/rescaler_mips_dsp_r2.c b/src/dsp/rescaler_mips_dsp_r2.c index 3a02f9b0..b78aac15 100644 --- a/src/dsp/rescaler_mips_dsp_r2.c +++ b/src/dsp/rescaler_mips_dsp_r2.c @@ -13,7 +13,7 @@ #include "src/dsp/dsp.h" -#if defined(WEBP_USE_MIPS_DSP_R2) +#if defined(WEBP_USE_MIPS_DSP_R2) && !defined(WEBP_REDUCE_SIZE) #include #include "src/utils/rescaler_utils.h" diff --git a/src/dsp/rescaler_msa.c b/src/dsp/rescaler_msa.c index b33c6bcb..f3bc99f1 100644 --- a/src/dsp/rescaler_msa.c +++ b/src/dsp/rescaler_msa.c @@ -13,7 +13,7 @@ #include "src/dsp/dsp.h" -#if defined(WEBP_USE_MSA) +#if defined(WEBP_USE_MSA) && !defined(WEBP_REDUCE_SIZE) #include diff --git a/src/dsp/rescaler_neon.c b/src/dsp/rescaler_neon.c index ab443f6f..3eff9fba 100644 --- a/src/dsp/rescaler_neon.c +++ b/src/dsp/rescaler_neon.c @@ -13,7 +13,7 @@ #include "src/dsp/dsp.h" -#if defined(WEBP_USE_NEON) +#if defined(WEBP_USE_NEON) && !defined(WEBP_REDUCE_SIZE) #include #include diff --git a/src/dsp/rescaler_sse2.c b/src/dsp/rescaler_sse2.c index 7bbcd0ff..f93b204f 100644 --- a/src/dsp/rescaler_sse2.c +++ b/src/dsp/rescaler_sse2.c @@ -13,7 +13,7 @@ #include "src/dsp/dsp.h" -#if defined(WEBP_USE_SSE2) +#if defined(WEBP_USE_SSE2) && !defined(WEBP_REDUCE_SIZE) #include #include