From b299c47eac7f424d6ca8ebfe8a8fcbeb4658edca Mon Sep 17 00:00:00 2001 From: James Zern Date: Wed, 22 Nov 2017 17:35:39 -0800 Subject: [PATCH] add WEBP_REDUCE_SIZE remove auto-filter (-af) support and make WebPPictureCopy, WebPPictureIsView, WebPPictureView, WebPPictureCrop, and WebPPictureRescale noops. Change-Id: If39d512cc268a0015298a1138dbc94feb86575e5 --- src/dsp/dsp.h | 2 ++ src/dsp/ssim.c | 8 ++++++ src/dsp/ssim_sse2.c | 6 +++++ src/enc/filter_enc.c | 18 +++++++++++++- src/enc/picture_psnr_enc.c | 2 +- src/enc/picture_rescale_enc.c | 47 ++++++++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h index ec466f59..99eefe09 100644 --- a/src/dsp/dsp.h +++ b/src/dsp/dsp.h @@ -308,6 +308,7 @@ typedef double (*VP8SSIMGetClippedFunc)(const uint8_t* src1, int stride1, int xo, int yo, // center position int W, int H); // plane dimension +#if !defined(WEBP_REDUCE_SIZE) // This version is called with the guarantee that you can load 8 bytes and // 8 rows at offset src1 and src2 typedef double (*VP8SSIMGetFunc)(const uint8_t* src1, int stride1, @@ -315,6 +316,7 @@ typedef double (*VP8SSIMGetFunc)(const uint8_t* src1, int stride1, extern VP8SSIMGetFunc VP8SSIMGet; // unclipped / unchecked extern VP8SSIMGetClippedFunc VP8SSIMGetClipped; // with clipping +#endif #if !defined(WEBP_DISABLE_STATS) typedef uint32_t (*VP8AccumulateSSEFunc)(const uint8_t* src1, diff --git a/src/dsp/ssim.c b/src/dsp/ssim.c index 52c03899..dc1b518a 100644 --- a/src/dsp/ssim.c +++ b/src/dsp/ssim.c @@ -16,6 +16,8 @@ #include "src/dsp/dsp.h" +#if !defined(WEBP_REDUCE_SIZE) + //------------------------------------------------------------------------------ // SSIM / PSNR @@ -107,6 +109,8 @@ static double SSIMGet_C(const uint8_t* src1, int stride1, return VP8SSIMFromStats(&stats); } +#endif // !defined(WEBP_REDUCE_SIZE) + //------------------------------------------------------------------------------ #if !defined(WEBP_DISABLE_STATS) @@ -125,8 +129,10 @@ static uint32_t AccumulateSSE_C(const uint8_t* src1, //------------------------------------------------------------------------------ +#if !defined(WEBP_REDUCE_SIZE) VP8SSIMGetFunc VP8SSIMGet; VP8SSIMGetClippedFunc VP8SSIMGetClipped; +#endif #if !defined(WEBP_DISABLE_STATS) VP8AccumulateSSEFunc VP8AccumulateSSE; #endif @@ -139,8 +145,10 @@ static volatile VP8CPUInfo ssim_last_cpuinfo_used = WEBP_TSAN_IGNORE_FUNCTION void VP8SSIMDspInit(void) { if (ssim_last_cpuinfo_used == VP8GetCPUInfo) return; +#if !defined(WEBP_REDUCE_SIZE) VP8SSIMGetClipped = SSIMGetClipped_C; VP8SSIMGet = SSIMGet_C; +#endif #if !defined(WEBP_DISABLE_STATS) VP8AccumulateSSE = AccumulateSSE_C; diff --git a/src/dsp/ssim_sse2.c b/src/dsp/ssim_sse2.c index 98dd44c6..1dcb0eb0 100644 --- a/src/dsp/ssim_sse2.c +++ b/src/dsp/ssim_sse2.c @@ -81,6 +81,8 @@ static uint32_t AccumulateSSE_SSE2(const uint8_t* src1, } #endif // !defined(WEBP_DISABLE_STATS) +#if !defined(WEBP_REDUCE_SIZE) + static uint32_t HorizontalAdd16b_SSE2(const __m128i* const m) { uint16_t tmp[8]; const __m128i a = _mm_srli_si128(*m, 8); @@ -143,13 +145,17 @@ static double SSIMGet_SSE2(const uint8_t* src1, int stride1, return VP8SSIMFromStats(&stats); } +#endif // !defined(WEBP_REDUCE_SIZE) + extern void VP8SSIMDspInitSSE2(void); WEBP_TSAN_IGNORE_FUNCTION void VP8SSIMDspInitSSE2(void) { #if !defined(WEBP_DISABLE_STATS) VP8AccumulateSSE = AccumulateSSE_SSE2; #endif +#if !defined(WEBP_REDUCE_SIZE) VP8SSIMGet = SSIMGet_SSE2; +#endif } #else // !WEBP_USE_SSE2 diff --git a/src/enc/filter_enc.c b/src/enc/filter_enc.c index 0b2044ee..580800bf 100644 --- a/src/enc/filter_enc.c +++ b/src/enc/filter_enc.c @@ -65,6 +65,8 @@ int VP8FilterStrengthFromDelta(int sharpness, int delta) { //------------------------------------------------------------------------------ // Paragraph 15.4: compute the inner-edge filtering strength +#if !defined(WEBP_REDUCE_SIZE) + static int GetILevel(int sharpness, int level) { if (sharpness > 0) { if (sharpness > 4) { @@ -129,11 +131,14 @@ static double GetMBSSIM(const uint8_t* yuv1, const uint8_t* yuv2) { return sum; } +#endif // !defined(WEBP_REDUCE_SIZE) + //------------------------------------------------------------------------------ // Exposed APIs: Encoder should call the following 3 functions to adjust // loop filter strength void VP8InitFilter(VP8EncIterator* const it) { +#if !defined(WEBP_REDUCE_SIZE) if (it->lf_stats_ != NULL) { int s, i; for (s = 0; s < NUM_MB_SEGMENTS; s++) { @@ -143,9 +148,13 @@ void VP8InitFilter(VP8EncIterator* const it) { } VP8SSIMDspInit(); } +#else + (void)it; +#endif } void VP8StoreFilterStats(VP8EncIterator* const it) { +#if !defined(WEBP_REDUCE_SIZE) int d; VP8Encoder* const enc = it->enc_; const int s = it->mb_->segment_; @@ -177,10 +186,14 @@ void VP8StoreFilterStats(VP8EncIterator* const it) { DoFilter(it, level); (*it->lf_stats_)[s][level] += GetMBSSIM(it->yuv_in_, it->yuv_out2_); } +#else // defined(WEBP_REDUCE_SIZE) + (void)it; +#endif // !defined(WEBP_REDUCE_SIZE) } void VP8AdjustFilterStrength(VP8EncIterator* const it) { VP8Encoder* const enc = it->enc_; +#if !defined(WEBP_REDUCE_SIZE) if (it->lf_stats_ != NULL) { int s; for (s = 0; s < NUM_MB_SEGMENTS; s++) { @@ -196,7 +209,10 @@ void VP8AdjustFilterStrength(VP8EncIterator* const it) { } enc->dqm_[s].fstrength_ = best_level; } - } else if (enc->config_->filter_strength > 0) { + return; + } +#endif // !defined(WEBP_REDUCE_SIZE) + if (enc->config_->filter_strength > 0) { int max_level = 0; int s; for (s = 0; s < NUM_MB_SEGMENTS; s++) { diff --git a/src/enc/picture_psnr_enc.c b/src/enc/picture_psnr_enc.c index 1163e94c..362a7c79 100644 --- a/src/enc/picture_psnr_enc.c +++ b/src/enc/picture_psnr_enc.c @@ -13,7 +13,7 @@ #include "src/webp/encode.h" -#if !defined(WEBP_DISABLE_STATS) +#if !(defined(WEBP_DISABLE_STATS) || defined(WEBP_REDUCE_SIZE)) #include #include diff --git a/src/enc/picture_rescale_enc.c b/src/enc/picture_rescale_enc.c index 1c0b9875..58a6ae7b 100644 --- a/src/enc/picture_rescale_enc.c +++ b/src/enc/picture_rescale_enc.c @@ -11,6 +11,10 @@ // // Author: Skal (pascal.massimino@gmail.com) +#include "src/webp/encode.h" + +#if !defined(WEBP_REDUCE_SIZE) + #include #include @@ -261,4 +265,45 @@ int WebPPictureRescale(WebPPicture* pic, int width, int height) { return 1; } -//------------------------------------------------------------------------------ +#else // defined(WEBP_REDUCE_SIZE) + +int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) { + (void)src; + (void)dst; + return 0; +} + +int WebPPictureIsView(const WebPPicture* picture) { + (void)picture; + return 0; +} + +int WebPPictureView(const WebPPicture* src, + int left, int top, int width, int height, + WebPPicture* dst) { + (void)src; + (void)left; + (void)top; + (void)width; + (void)height; + (void)dst; + return 0; +} + +int WebPPictureCrop(WebPPicture* pic, + int left, int top, int width, int height) { + (void)pic; + (void)left; + (void)top; + (void)width; + (void)height; + return 0; +} + +int WebPPictureRescale(WebPPicture* pic, int width, int height) { + (void)pic; + (void)width; + (void)height; + return 0; +} +#endif // !defined(WEBP_REDUCE_SIZE)