From 78f3e345046840172dbeed9440e2ce0e6e860fde Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Tue, 12 Jun 2012 23:44:09 -0700 Subject: [PATCH] Enable lossless encoder code Remove USE_LOSSLESS_ENCODER compile flag Update Makefile.am and makefile.unix Change-Id: If7080c4d8f37994c7c784730c5e547bb0a851455 --- examples/cwebp.c | 2 -- makefile.unix | 2 +- src/dsp/lossless.c | 12 ------------ src/dsp/lossless.h | 4 ---- src/enc/Makefile.am | 3 +++ src/enc/alpha.c | 12 ------------ src/enc/backward_references.c | 4 ---- src/enc/backward_references.h | 4 ---- src/enc/config.c | 5 ----- src/enc/histogram.c | 4 ---- src/enc/histogram.h | 4 ---- src/enc/picture.c | 16 ---------------- src/enc/vp8l.c | 4 ---- src/enc/vp8li.h | 4 ---- src/enc/webpenc.c | 4 ---- src/utils/Makefile.am | 3 +++ src/utils/bit_writer.c | 3 --- src/utils/bit_writer.h | 2 -- src/utils/color_cache.h | 2 -- src/utils/huffman_encode.c | 4 ---- src/utils/huffman_encode.h | 4 ---- 21 files changed, 7 insertions(+), 95 deletions(-) diff --git a/examples/cwebp.c b/examples/cwebp.c index 887fa841..7fda7f4d 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -863,11 +863,9 @@ int main(int argc, const char *argv[]) { } } else if (!strcmp(argv[c], "-noalpha")) { keep_alpha = 0; -#ifdef USE_LOSSLESS_ENCODER } else if (!strcmp(argv[c], "-lossless")) { config.lossless = 1; picture.use_argb_input = 1; -#endif } else if (!strcmp(argv[c], "-size") && c < argc - 1) { config.target_size = strtol(argv[++c], NULL, 0); } else if (!strcmp(argv[c], "-psnr") && c < argc - 1) { diff --git a/makefile.unix b/makefile.unix index 55bba685..6f4d0726 100644 --- a/makefile.unix +++ b/makefile.unix @@ -38,7 +38,6 @@ endif # Extra flags to enable experimental features and code # EXTRA_FLAGS += -DWEBP_EXPERIMENTAL_FEATURES -EXTRA_FLAGS += -DUSE_LOSSLESS_ENCODER # Extra flags to enable multi-threading EXTRA_FLAGS += -DWEBP_USE_THREAD @@ -142,6 +141,7 @@ HDRS = \ src/utils/color_cache.h \ src/utils/filters.h \ src/utils/huffman.h \ + src/utils/huffman_encode.h \ src/utils/quant_levels.h \ src/utils/rescaler.h \ src/utils/thread.h \ diff --git a/src/dsp/lossless.c b/src/dsp/lossless.c index 3fab2630..00d81e08 100644 --- a/src/dsp/lossless.c +++ b/src/dsp/lossless.c @@ -21,9 +21,6 @@ extern "C" { #include "../dec/vp8li.h" #include "../dsp/yuv.h" #include "../dsp/dsp.h" - -#ifdef USE_LOSSLESS_ENCODER - #include "../enc/histogram.h" // A lookup table for small values of log(int) to be used in entropy @@ -135,8 +132,6 @@ float VP8LFastLog(int v) { return (float)log(v); } -#endif - //------------------------------------------------------------------------------ // Image transforms. @@ -288,7 +283,6 @@ static const PredictorFunc kPredictors[16] = { Predictor0, Predictor0 // <- padding security sentinels }; -#ifdef USE_LOSSLESS_ENCODER // TODO(vikasa): Replace 256 etc with defines. static double PredictionCostSpatial(const int* counts, int weight_0, double exp_val) { @@ -484,8 +478,6 @@ void VP8LResidualImage(int width, int height, int bits, } } -#endif - // Inverse prediction. static void PredictorInverseTransform(const VP8LTransform* const transform, int y_start, int y_end, uint32_t* data) { @@ -537,7 +529,6 @@ static void PredictorInverseTransform(const VP8LTransform* const transform, } } -#ifdef USE_LOSSLESS_ENCODER void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs) { int i; for (i = 0; i < num_pixs; ++i) { @@ -548,7 +539,6 @@ void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs) { argb_data[i] = (argb & 0xff00ff00) | (new_r << 16) | new_b; } } -#endif // Add green to blue and red channels (i.e. perform the inverse transform of // 'subtract green'). @@ -623,7 +613,6 @@ static WEBP_INLINE uint32_t TransformColor(const Multipliers* const m, return (argb & 0xff00ff00u) | (new_red << 16) | (new_blue); } -#ifdef USE_LOSSLESS_ENCODER static WEBP_INLINE int SkipRepeatedPixels(const uint32_t* const argb, int ix, int xsize) { const uint32_t v = argb[ix]; @@ -862,7 +851,6 @@ void VP8LColorSpaceTransform(int width, int height, int bits, int step, } } } -#endif // Color space inverse transform. static void ColorSpaceInverseTransform(const VP8LTransform* const transform, diff --git a/src/dsp/lossless.h b/src/dsp/lossless.h index 7b898227..b35557b6 100644 --- a/src/dsp/lossless.h +++ b/src/dsp/lossless.h @@ -33,7 +33,6 @@ void VP8LInverseTransform(const struct VP8LTransform* const transform, int row_start, int row_end, const uint32_t* const in, uint32_t* const out); -#ifdef USE_LOSSLESS_ENCODER // Subtracts green from blue and red channels. void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs); @@ -43,7 +42,6 @@ void VP8LResidualImage(int width, int height, int bits, void VP8LColorSpaceTransform(int width, int height, int bits, int step, uint32_t* const argb, uint32_t* image); -#endif //------------------------------------------------------------------------------ // Color space conversion. @@ -61,7 +59,6 @@ static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size, return (size + (1 << sampling_bits) - 1) >> sampling_bits; } -#ifdef USE_LOSSLESS_ENCODER // Faster logarithm for small integers, with the property of log(0) == 0. float VP8LFastLog(int v); @@ -73,7 +70,6 @@ static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { 0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu); return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); } -#endif //------------------------------------------------------------------------------ diff --git a/src/enc/Makefile.am b/src/enc/Makefile.am index 15d9b22e..26698d2e 100644 --- a/src/enc/Makefile.am +++ b/src/enc/Makefile.am @@ -4,11 +4,13 @@ noinst_LTLIBRARIES = libwebpencode.la libwebpencode_la_SOURCES = libwebpencode_la_SOURCES += alpha.c libwebpencode_la_SOURCES += analysis.c +libwebpencode_la_SOURCES += backward_references.c libwebpencode_la_SOURCES += config.c libwebpencode_la_SOURCES += cost.c libwebpencode_la_SOURCES += cost.h libwebpencode_la_SOURCES += filter.c libwebpencode_la_SOURCES += frame.c +libwebpencode_la_SOURCES += histogram.c libwebpencode_la_SOURCES += iterator.c libwebpencode_la_SOURCES += layer.c libwebpencode_la_SOURCES += picture.c @@ -16,6 +18,7 @@ libwebpencode_la_SOURCES += quant.c libwebpencode_la_SOURCES += syntax.c libwebpencode_la_SOURCES += tree.c libwebpencode_la_SOURCES += vp8enci.h +libwebpencode_la_SOURCES += vp8l.c libwebpencode_la_SOURCES += webpenc.c libwebpencodeinclude_HEADERS = diff --git a/src/enc/alpha.c b/src/enc/alpha.c index f6ddedef..9841bdf2 100644 --- a/src/enc/alpha.c +++ b/src/enc/alpha.c @@ -48,8 +48,6 @@ extern "C" { // invalid quality or method, or // memory allocation for the compressed data fails. -#ifdef USE_LOSSLESS_ENCODER - #include "../enc/vp8li.h" static int EncodeLossless(const uint8_t* data, int width, int height, @@ -100,8 +98,6 @@ static int EncodeLossless(const uint8_t* data, int width, int height, return ok && !bw->error_; } -#endif - // ----------------------------------------------------------------------------- static int EncodeAlphaInternal(const uint8_t* data, int width, int height, @@ -115,9 +111,6 @@ static int EncodeAlphaInternal(const uint8_t* data, int width, int height, size_t expected_size; const size_t data_size = width * height; -#ifndef USE_LOSSLESS_ENCODER - method = ALPHA_NO_COMPRESSION; -#endif assert(filter >= 0 && filter < WEBP_FILTER_LAST); assert(method >= ALPHA_NO_COMPRESSION); assert(method <= ALPHA_LOSSLESS_COMPRESSION); @@ -145,13 +138,8 @@ static int EncodeAlphaInternal(const uint8_t* data, int width, int height, ok = VP8BitWriterAppend(bw, alpha_src, width * height); ok = ok && !bw->error_; } else { -#ifdef USE_LOSSLESS_ENCODER ok = EncodeLossless(alpha_src, width, height, effort_level, bw); VP8BitWriterFinish(bw); -#else - (void)effort_level; - assert(0); // not reached. -#endif } return ok; } diff --git a/src/enc/backward_references.c b/src/enc/backward_references.c index 20e3a8ec..e2573398 100644 --- a/src/enc/backward_references.c +++ b/src/enc/backward_references.c @@ -8,8 +8,6 @@ // Author: Jyrki Alakuijala (jyrki@google.com) // -#ifdef USE_LOSSLESS_ENCODER - #include #include #include @@ -816,5 +814,3 @@ int VP8LCalculateEstimateForCacheSize(const uint32_t* const argb, VP8LClearBackwardRefs(&refs); return ok; } - -#endif diff --git a/src/enc/backward_references.h b/src/enc/backward_references.h index de8055f1..3fbdd5a2 100644 --- a/src/enc/backward_references.h +++ b/src/enc/backward_references.h @@ -11,8 +11,6 @@ #ifndef WEBP_ENC_BACKWARD_REFERENCES_H_ #define WEBP_ENC_BACKWARD_REFERENCES_H_ -#ifdef USE_LOSSLESS_ENCODER - #include #include #include "../webp/types.h" @@ -203,6 +201,4 @@ int VP8LCalculateEstimateForCacheSize(const uint32_t* const argb, } #endif -#endif - #endif // WEBP_ENC_BACKWARD_REFERENCES_H_ diff --git a/src/enc/config.c b/src/enc/config.c index 178d4689..5e1b2540 100644 --- a/src/enc/config.c +++ b/src/enc/config.c @@ -117,13 +117,8 @@ int WebPValidateConfig(const WebPConfig* const config) { return 0; if (config->alpha_quality < 0 || config->alpha_quality > 100) return 0; -#ifdef USE_LOSSLESS_ENCODER if (config->lossless < 0 || config->lossless > 1) return 0; -#else - if (config->lossless != 0) - return 0; -#endif return 1; } diff --git a/src/enc/histogram.c b/src/enc/histogram.c index 50bffa23..e0379d54 100644 --- a/src/enc/histogram.c +++ b/src/enc/histogram.c @@ -11,8 +11,6 @@ #include "config.h" #endif -#ifdef USE_LOSSLESS_ENCODER - #include #include @@ -443,5 +441,3 @@ Error: free(image_out); return ok; } - -#endif diff --git a/src/enc/histogram.h b/src/enc/histogram.h index 912bbb18..931fd853 100644 --- a/src/enc/histogram.h +++ b/src/enc/histogram.h @@ -12,8 +12,6 @@ #ifndef WEBP_ENC_HISTOGRAM_H_ #define WEBP_ENC_HISTOGRAM_H_ -#ifdef USE_LOSSLESS_ENCODER - #include #include #include @@ -142,6 +140,4 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize, } #endif -#endif - #endif // WEBP_ENC_HISTOGRAM_H_ diff --git a/src/enc/picture.c b/src/enc/picture.c index 0f15d7bf..58240b66 100644 --- a/src/enc/picture.c +++ b/src/enc/picture.c @@ -105,7 +105,6 @@ int WebPPictureAlloc(WebPPicture* const picture) { mem += uv0_size; } } else { -#ifdef USE_LOSSLESS_ENCODER const uint64_t argb_size = (uint64_t)width * height; const uint64_t total_size = argb_size * sizeof(*picture->argb); if (width <= 0 || height <= 0 || @@ -117,9 +116,6 @@ int WebPPictureAlloc(WebPPicture* const picture) { picture->argb = (uint32_t*)malloc(total_size); if (picture->argb == NULL) return 0; picture->argb_stride = width; -#else - return 0; -#endif } } return 1; @@ -133,18 +129,14 @@ static void WebPPictureGrabSpecs(const WebPPicture* const src, dst->y = dst->u = dst->v = NULL; dst->u0 = dst->v0 = NULL; dst->a = NULL; -#ifdef USE_LOSSLESS_ENCODER dst->argb = NULL; -#endif } // Release memory owned by 'picture'. void WebPPictureFree(WebPPicture* const picture) { if (picture != NULL) { free(picture->y); -#ifdef USE_LOSSLESS_ENCODER free(picture->argb); -#endif WebPPictureGrabSpecs(NULL, picture); } } @@ -193,13 +185,9 @@ int WebPPictureCopy(const WebPPicture* const src, WebPPicture* const dst) { } #endif } else { -#ifdef USE_LOSSLESS_ENCODER CopyPlane((uint8_t*)src->argb, 4 * src->argb_stride, (uint8_t*)dst->argb, 4 * dst->argb_stride, 4 * dst->width, dst->height); -#else - return 0; -#endif } return 1; } @@ -543,7 +531,6 @@ static int Import(WebPPicture* const picture, } } } else { -#ifdef USE_LOSSLESS_ENCODER if (!import_alpha) { for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { @@ -571,9 +558,6 @@ static int Import(WebPPicture* const picture, } } } -#else - return 0; -#endif } return 1; } diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index ca4485de..bb090efd 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -10,8 +10,6 @@ // Author: Vikas Arora (vikaas.arora@gmail.com) // -#ifdef USE_LOSSLESS_ENCODER - #include #include #include @@ -1069,5 +1067,3 @@ int VP8LEncodeImage(const WebPConfig* const config, #if defined(__cplusplus) || defined(c_plusplus) } // extern "C" #endif - -#endif diff --git a/src/enc/vp8li.h b/src/enc/vp8li.h index a9b98c13..083ff595 100644 --- a/src/enc/vp8li.h +++ b/src/enc/vp8li.h @@ -12,8 +12,6 @@ #ifndef WEBP_ENC_VP8LI_H_ #define WEBP_ENC_VP8LI_H_ -#ifdef USE_LOSSLESS_ENCODER - #include "./histogram.h" #include "../utils/bit_writer.h" #include "../webp/encode.h" @@ -66,6 +64,4 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, } // extern "C" #endif -#endif - #endif /* WEBP_ENC_VP8LI_H_ */ diff --git a/src/enc/webpenc.c b/src/enc/webpenc.c index 28e45f95..d347c8b0 100644 --- a/src/enc/webpenc.c +++ b/src/enc/webpenc.c @@ -365,14 +365,10 @@ int WebPEncode(const WebPConfig* const config, WebPPicture* const pic) { } DeleteVP8Encoder(enc); } else { -#ifdef USE_LOSSLESS_ENCODER if (pic->argb == NULL) return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER); ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem. -#else - return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION); -#endif } return ok; diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index e9f5571b..96b2bd45 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -12,9 +12,12 @@ libwebputils_la_SOURCES += filters.c libwebputils_la_SOURCES += filters.h libwebputils_la_SOURCES += huffman.c libwebputils_la_SOURCES += huffman.h +libwebputils_la_SOURCES += huffman_encode.c +libwebputils_la_SOURCES += huffman_encode.h libwebputils_la_SOURCES += quant_levels.c libwebputils_la_SOURCES += quant_levels.h libwebputils_la_SOURCES += rescaler.c +libwebputils_la_SOURCES += rescaler.h libwebputils_la_SOURCES += thread.c libwebputils_la_SOURCES += thread.h diff --git a/src/utils/bit_writer.c b/src/utils/bit_writer.c index bc6e4097..260ad89e 100644 --- a/src/utils/bit_writer.c +++ b/src/utils/bit_writer.c @@ -187,7 +187,6 @@ void VP8BitWriterWipeOut(VP8BitWriter* const bw) { } } -#ifdef USE_LOSSLESS_ENCODER //------------------------------------------------------------------------------ // VP8LBitWriter @@ -265,8 +264,6 @@ void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits) { } } -#endif - //------------------------------------------------------------------------------ #if defined(__cplusplus) || defined(c_plusplus) diff --git a/src/utils/bit_writer.h b/src/utils/bit_writer.h index b9cf0b92..f7ca0849 100644 --- a/src/utils/bit_writer.h +++ b/src/utils/bit_writer.h @@ -64,7 +64,6 @@ static WEBP_INLINE size_t VP8BitWriterSize(const VP8BitWriter* const bw) { return bw->pos_; } -#ifdef USE_LOSSLESS_ENCODER //------------------------------------------------------------------------------ // VP8LBitWriter // TODO(vikasa): VP8LBitWriter is copied as-is from lossless code. There's scope @@ -116,7 +115,6 @@ void VP8LBitWriterDestroy(VP8LBitWriter* const bw); void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits); //------------------------------------------------------------------------------ -#endif #if defined(__cplusplus) || defined(c_plusplus) } // extern "C" diff --git a/src/utils/color_cache.h b/src/utils/color_cache.h index 64435b5a..d37425c2 100644 --- a/src/utils/color_cache.h +++ b/src/utils/color_cache.h @@ -39,7 +39,6 @@ static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc, cc->colors_[key] = argb; } -#ifdef USE_LOSSLESS_ENCODER static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc, uint32_t argb) { return (kHashMul * argb) >> cc->hash_shift_; @@ -50,7 +49,6 @@ static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc, const uint32_t key = (kHashMul * argb) >> cc->hash_shift_; return cc->colors_[key] == argb; } -#endif //------------------------------------------------------------------------------ diff --git a/src/utils/huffman_encode.c b/src/utils/huffman_encode.c index fa407e62..2ac1f0e9 100644 --- a/src/utils/huffman_encode.c +++ b/src/utils/huffman_encode.c @@ -9,8 +9,6 @@ // // Flate-like entropy encoding (Huffman) for webp lossless. -#ifdef USE_LOSSLESS_ENCODER - #include #include #include @@ -438,5 +436,3 @@ int VP8LCreateHuffmanTree(int* const histogram, int tree_depth_limit, ConvertBitDepthsToSymbols(tree); return 1; } - -#endif diff --git a/src/utils/huffman_encode.h b/src/utils/huffman_encode.h index ee187d8d..d28da39a 100644 --- a/src/utils/huffman_encode.h +++ b/src/utils/huffman_encode.h @@ -12,8 +12,6 @@ #ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_ #define WEBP_UTILS_HUFFMAN_ENCODE_H_ -#ifdef USE_LOSSLESS_ENCODER - #include "../webp/types.h" #if defined(__cplusplus) || defined(c_plusplus) @@ -46,6 +44,4 @@ int VP8LCreateHuffmanTree(int* const histogram, int tree_depth_limit, } #endif -#endif - #endif // WEBP_UTILS_HUFFMAN_ENCODE_H_