diff --git a/src/dsp/lossless.c b/src/dsp/lossless.c index cc193bdd..f5da54ba 100644 --- a/src/dsp/lossless.c +++ b/src/dsp/lossless.c @@ -19,8 +19,10 @@ extern "C" { #include #include "./lossless.h" #include "../dec/vp8li.h" -#include "../enc/histogram.h" +#ifdef USE_LOSSLESS_ENCODER + +#include "../enc/histogram.h" // A lookup table for small values of log(int) to be used in entropy // computation. @@ -122,6 +124,8 @@ double VP8LFastLog(int v) { return log(v); } +#endif + //------------------------------------------------------------------------------ // Image transforms. @@ -288,6 +292,7 @@ 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) { @@ -472,6 +477,8 @@ 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) { @@ -524,6 +531,7 @@ 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) { @@ -534,6 +542,7 @@ 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'). @@ -606,6 +615,7 @@ 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]; @@ -844,6 +854,7 @@ 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 7ec5cae4..2ea4e31a 100644 --- a/src/dsp/lossless.h +++ b/src/dsp/lossless.h @@ -33,6 +33,7 @@ void VP8LInverseTransform(const struct VP8LTransform* const transform, int row_start, int row_end, uint32_t* const data_in, uint32_t* const data_out); +#ifdef USE_LOSSLESS_ENCODER // Subtracts green from blue and red channels. void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs); @@ -41,6 +42,8 @@ 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. @@ -52,21 +55,23 @@ void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels, //------------------------------------------------------------------------------ // Misc methods. -// Faster logarithm for small integers, with the property of log(0) == 0. -double VP8LFastLog(int v); - // Computes sampled size of 'size' when sampling using 'sampling bits'. static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size, uint32_t sampling_bits) { return (size + (1 << sampling_bits) - 1) >> sampling_bits; } +#ifdef USE_LOSSLESS_ENCODER +// Faster logarithm for small integers, with the property of log(0) == 0. +double VP8LFastLog(int v); + // In-place difference of each component with mod 256. static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { const uint32_t alpha_and_green = (a & 0xff00ff00u) - (b & 0xff00ff00u); const uint32_t red_and_blue = (a & 0x00ff00ffu) - (b & 0x00ff00ffu); return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); } +#endif //------------------------------------------------------------------------------ diff --git a/src/enc/backward_references.c b/src/enc/backward_references.c index 7ed673be..ee233d46 100644 --- a/src/enc/backward_references.c +++ b/src/enc/backward_references.c @@ -8,6 +8,8 @@ // Author: Jyrki Alakuijala (jyrki@google.com) // +#ifdef USE_LOSSLESS_ENCODER + #include #include #include @@ -785,3 +787,5 @@ Error: free(stream); return ok; } + +#endif diff --git a/src/enc/backward_references.h b/src/enc/backward_references.h index b8d05e6b..49cca9a7 100644 --- a/src/enc/backward_references.h +++ b/src/enc/backward_references.h @@ -11,6 +11,8 @@ #ifndef WEBP_ENC_BACKWARD_REFERENCES_H_ #define WEBP_ENC_BACKWARD_REFERENCES_H_ +#ifdef USE_LOSSLESS_ENCODER + #include #include @@ -231,4 +233,6 @@ int VP8LCalculateEstimateForPaletteSize(const uint32_t *argb, } #endif +#endif + #endif // WEBP_ENC_BACKWARD_REFERENCES_H_ diff --git a/src/enc/config.c b/src/enc/config.c index 5e1b2540..178d4689 100644 --- a/src/enc/config.c +++ b/src/enc/config.c @@ -117,8 +117,13 @@ 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 6ef92942..5c08f97e 100644 --- a/src/enc/histogram.c +++ b/src/enc/histogram.c @@ -8,6 +8,7 @@ // Author: Jyrki Alakuijala (jyrki@google.com) // +#ifdef USE_LOSSLESS_ENCODER #include #include @@ -392,3 +393,5 @@ void VP8LHistogramRefine(VP8LHistogram** raw, int raw_size, VP8LHistogramAdd(out[symbols[i]], raw[i]); } } + +#endif diff --git a/src/enc/histogram.h b/src/enc/histogram.h index 533f5e83..7ce29f7b 100644 --- a/src/enc/histogram.h +++ b/src/enc/histogram.h @@ -12,6 +12,8 @@ #ifndef WEBP_ENC_HISTOGRAM_H_ #define WEBP_ENC_HISTOGRAM_H_ +#ifdef USE_LOSSLESS_ENCODER + #include #include #include @@ -146,4 +148,6 @@ void VP8LHistogramRefine(VP8LHistogram** raw, } #endif +#endif + #endif // WEBP_ENC_HISTOGRAM_H_ diff --git a/src/enc/picture.c b/src/enc/picture.c index 75fc9038..68a3bd6e 100644 --- a/src/enc/picture.c +++ b/src/enc/picture.c @@ -105,6 +105,7 @@ 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 || @@ -116,6 +117,9 @@ 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; @@ -129,14 +133,18 @@ 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); } } @@ -185,9 +193,13 @@ 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; } @@ -524,6 +536,7 @@ 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) { @@ -551,6 +564,9 @@ 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 0aeb8ea2..f21cc42f 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -10,6 +10,8 @@ // Author: Vikas Arora (vikaas.arora@gmail.com) // +#ifdef USE_LOSSLESS_ENCODER + #include #include #include @@ -535,3 +537,5 @@ 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 b579dfdf..3a6ab927 100644 --- a/src/enc/vp8li.h +++ b/src/enc/vp8li.h @@ -12,6 +12,8 @@ #ifndef WEBP_ENC_VP8LI_H_ #define WEBP_ENC_VP8LI_H_ +#ifdef USE_LOSSLESS_ENCODER + #include "./histogram.h" #include "../webp/encode.h" #include "../utils/bit_writer.h" @@ -70,4 +72,6 @@ int VP8LEncodeImage(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 dc183333..dbe9045e 100644 --- a/src/enc/webpenc.c +++ b/src/enc/webpenc.c @@ -364,10 +364,14 @@ 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/bit_writer.c b/src/utils/bit_writer.c index 04c0db63..bc6e4097 100644 --- a/src/utils/bit_writer.c +++ b/src/utils/bit_writer.c @@ -187,6 +187,7 @@ void VP8BitWriterWipeOut(VP8BitWriter* const bw) { } } +#ifdef USE_LOSSLESS_ENCODER //------------------------------------------------------------------------------ // VP8LBitWriter @@ -264,6 +265,7 @@ void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits) { } } +#endif //------------------------------------------------------------------------------ diff --git a/src/utils/bit_writer.h b/src/utils/bit_writer.h index f7ca0849..b9cf0b92 100644 --- a/src/utils/bit_writer.h +++ b/src/utils/bit_writer.h @@ -64,6 +64,7 @@ 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 @@ -115,6 +116,7 @@ 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 aece1453..bd83f251 100644 --- a/src/utils/color_cache.h +++ b/src/utils/color_cache.h @@ -39,6 +39,7 @@ 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_; @@ -49,6 +50,7 @@ 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 405ead37..a5e29168 100644 --- a/src/utils/huffman_encode.c +++ b/src/utils/huffman_encode.c @@ -9,6 +9,8 @@ // // Flate like entropy encoding (Huffman) for webp lossless. +#ifdef USE_LOSSLESS_ENCODER + #include "./huffman_encode.h" #include @@ -311,3 +313,5 @@ void ConvertBitDepthsToSymbols(const uint8_t* depth, int len, } } } + +#endif diff --git a/src/utils/huffman_encode.h b/src/utils/huffman_encode.h index fa484b7a..fe85cbc2 100644 --- a/src/utils/huffman_encode.h +++ b/src/utils/huffman_encode.h @@ -12,6 +12,8 @@ #ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_ #define WEBP_UTILS_HUFFMAN_ENCODE_H_ +#ifdef USE_LOSSLESS_ENCODER + #include #if defined(__cplusplus) || defined(c_plusplus) @@ -49,4 +51,6 @@ void ConvertBitDepthsToSymbols(const uint8_t* depth, int len, uint16_t* bits); } #endif +#endif + #endif // WEBP_UTILS_HUFFMAN_ENCODE_H_