Guard the lossless encoder (in flux) under a flag

Change-Id: I6dd8fd17089c199001c06b1afde14233dc3e3234
This commit is contained in:
Urvang Joshi 2012-04-11 09:52:13 +00:00 committed by James Zern
parent 09f7532cce
commit 6b38378acb
16 changed files with 82 additions and 4 deletions

View File

@ -19,8 +19,10 @@ extern "C" {
#include <stdlib.h> #include <stdlib.h>
#include "./lossless.h" #include "./lossless.h"
#include "../dec/vp8li.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 // A lookup table for small values of log(int) to be used in entropy
// computation. // computation.
@ -122,6 +124,8 @@ double VP8LFastLog(int v) {
return log(v); return log(v);
} }
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Image transforms. // Image transforms.
@ -288,6 +292,7 @@ static const PredictorFunc kPredictors[16] = {
Predictor0, Predictor0 // <- padding security sentinels Predictor0, Predictor0 // <- padding security sentinels
}; };
#ifdef USE_LOSSLESS_ENCODER
// TODO(vikasa): Replace 256 etc with defines. // TODO(vikasa): Replace 256 etc with defines.
static double PredictionCostSpatial(const int* counts, static double PredictionCostSpatial(const int* counts,
int weight_0, double exp_val) { int weight_0, double exp_val) {
@ -472,6 +477,8 @@ void VP8LResidualImage(int width, int height, int bits,
} }
} }
#endif
// Inverse prediction. // Inverse prediction.
static void PredictorInverseTransform(const VP8LTransform* const transform, static void PredictorInverseTransform(const VP8LTransform* const transform,
int y_start, int y_end, uint32_t* data) { 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) { void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs) {
int i; int i;
for (i = 0; i < num_pixs; ++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; 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 // Add green to blue and red channels (i.e. perform the inverse transform of
// 'subtract green'). // 'subtract green').
@ -606,6 +615,7 @@ static WEBP_INLINE uint32_t TransformColor(const Multipliers* const m,
return (argb & 0xff00ff00u) | (new_red << 16) | (new_blue); return (argb & 0xff00ff00u) | (new_red << 16) | (new_blue);
} }
#ifdef USE_LOSSLESS_ENCODER
static WEBP_INLINE int SkipRepeatedPixels(const uint32_t* const argb, static WEBP_INLINE int SkipRepeatedPixels(const uint32_t* const argb,
int ix, int xsize) { int ix, int xsize) {
const uint32_t v = argb[ix]; 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. // Color space inverse transform.
static void ColorSpaceInverseTransform(const VP8LTransform* const transform, static void ColorSpaceInverseTransform(const VP8LTransform* const transform,

View File

@ -33,6 +33,7 @@ void VP8LInverseTransform(const struct VP8LTransform* const transform,
int row_start, int row_end, int row_start, int row_end,
uint32_t* const data_in, uint32_t* const data_out); uint32_t* const data_in, uint32_t* const data_out);
#ifdef USE_LOSSLESS_ENCODER
// Subtracts green from blue and red channels. // Subtracts green from blue and red channels.
void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs); 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, void VP8LColorSpaceTransform(int width, int height, int bits, int step,
uint32_t* const argb, uint32_t* image); uint32_t* const argb, uint32_t* image);
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Color space conversion. // Color space conversion.
@ -52,21 +55,23 @@ void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Misc methods. // 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'. // Computes sampled size of 'size' when sampling using 'sampling bits'.
static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size, static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size,
uint32_t sampling_bits) { uint32_t sampling_bits) {
return (size + (1 << sampling_bits) - 1) >> 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. // In-place difference of each component with mod 256.
static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { 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 alpha_and_green = (a & 0xff00ff00u) - (b & 0xff00ff00u);
const uint32_t red_and_blue = (a & 0x00ff00ffu) - (b & 0x00ff00ffu); const uint32_t red_and_blue = (a & 0x00ff00ffu) - (b & 0x00ff00ffu);
return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
} }
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -8,6 +8,8 @@
// Author: Jyrki Alakuijala (jyrki@google.com) // Author: Jyrki Alakuijala (jyrki@google.com)
// //
#ifdef USE_LOSSLESS_ENCODER
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
@ -785,3 +787,5 @@ Error:
free(stream); free(stream);
return ok; return ok;
} }
#endif

View File

@ -11,6 +11,8 @@
#ifndef WEBP_ENC_BACKWARD_REFERENCES_H_ #ifndef WEBP_ENC_BACKWARD_REFERENCES_H_
#define WEBP_ENC_BACKWARD_REFERENCES_H_ #define WEBP_ENC_BACKWARD_REFERENCES_H_
#ifdef USE_LOSSLESS_ENCODER
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
@ -231,4 +233,6 @@ int VP8LCalculateEstimateForPaletteSize(const uint32_t *argb,
} }
#endif #endif
#endif
#endif // WEBP_ENC_BACKWARD_REFERENCES_H_ #endif // WEBP_ENC_BACKWARD_REFERENCES_H_

View File

@ -117,8 +117,13 @@ int WebPValidateConfig(const WebPConfig* const config) {
return 0; return 0;
if (config->alpha_quality < 0 || config->alpha_quality > 100) if (config->alpha_quality < 0 || config->alpha_quality > 100)
return 0; return 0;
#ifdef USE_LOSSLESS_ENCODER
if (config->lossless < 0 || config->lossless > 1) if (config->lossless < 0 || config->lossless > 1)
return 0; return 0;
#else
if (config->lossless != 0)
return 0;
#endif
return 1; return 1;
} }

View File

@ -8,6 +8,7 @@
// Author: Jyrki Alakuijala (jyrki@google.com) // Author: Jyrki Alakuijala (jyrki@google.com)
// //
#ifdef USE_LOSSLESS_ENCODER
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
@ -392,3 +393,5 @@ void VP8LHistogramRefine(VP8LHistogram** raw, int raw_size,
VP8LHistogramAdd(out[symbols[i]], raw[i]); VP8LHistogramAdd(out[symbols[i]], raw[i]);
} }
} }
#endif

View File

@ -12,6 +12,8 @@
#ifndef WEBP_ENC_HISTOGRAM_H_ #ifndef WEBP_ENC_HISTOGRAM_H_
#define WEBP_ENC_HISTOGRAM_H_ #define WEBP_ENC_HISTOGRAM_H_
#ifdef USE_LOSSLESS_ENCODER
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -146,4 +148,6 @@ void VP8LHistogramRefine(VP8LHistogram** raw,
} }
#endif #endif
#endif
#endif // WEBP_ENC_HISTOGRAM_H_ #endif // WEBP_ENC_HISTOGRAM_H_

View File

@ -105,6 +105,7 @@ int WebPPictureAlloc(WebPPicture* const picture) {
mem += uv0_size; mem += uv0_size;
} }
} else { } else {
#ifdef USE_LOSSLESS_ENCODER
const uint64_t argb_size = (uint64_t)width * height; const uint64_t argb_size = (uint64_t)width * height;
const uint64_t total_size = argb_size * sizeof(*picture->argb); const uint64_t total_size = argb_size * sizeof(*picture->argb);
if (width <= 0 || height <= 0 || if (width <= 0 || height <= 0 ||
@ -116,6 +117,9 @@ int WebPPictureAlloc(WebPPicture* const picture) {
picture->argb = (uint32_t*)malloc(total_size); picture->argb = (uint32_t*)malloc(total_size);
if (picture->argb == NULL) return 0; if (picture->argb == NULL) return 0;
picture->argb_stride = width; picture->argb_stride = width;
#else
return 0;
#endif
} }
} }
return 1; return 1;
@ -129,14 +133,18 @@ static void WebPPictureGrabSpecs(const WebPPicture* const src,
dst->y = dst->u = dst->v = NULL; dst->y = dst->u = dst->v = NULL;
dst->u0 = dst->v0 = NULL; dst->u0 = dst->v0 = NULL;
dst->a = NULL; dst->a = NULL;
#ifdef USE_LOSSLESS_ENCODER
dst->argb = NULL; dst->argb = NULL;
#endif
} }
// Release memory owned by 'picture'. // Release memory owned by 'picture'.
void WebPPictureFree(WebPPicture* const picture) { void WebPPictureFree(WebPPicture* const picture) {
if (picture != NULL) { if (picture != NULL) {
free(picture->y); free(picture->y);
#ifdef USE_LOSSLESS_ENCODER
free(picture->argb); free(picture->argb);
#endif
WebPPictureGrabSpecs(NULL, picture); WebPPictureGrabSpecs(NULL, picture);
} }
} }
@ -185,9 +193,13 @@ int WebPPictureCopy(const WebPPicture* const src, WebPPicture* const dst) {
} }
#endif #endif
} else { } else {
#ifdef USE_LOSSLESS_ENCODER
CopyPlane((uint8_t*)src->argb, 4 * src->argb_stride, CopyPlane((uint8_t*)src->argb, 4 * src->argb_stride,
(uint8_t*)dst->argb, 4 * dst->argb_stride, (uint8_t*)dst->argb, 4 * dst->argb_stride,
4 * dst->width, dst->height); 4 * dst->width, dst->height);
#else
return 0;
#endif
} }
return 1; return 1;
} }
@ -524,6 +536,7 @@ static int Import(WebPPicture* const picture,
} }
} }
} else { } else {
#ifdef USE_LOSSLESS_ENCODER
if (!import_alpha) { if (!import_alpha) {
for (y = 0; y < height; ++y) { for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) { for (x = 0; x < width; ++x) {
@ -551,6 +564,9 @@ static int Import(WebPPicture* const picture,
} }
} }
} }
#else
return 0;
#endif
} }
return 1; return 1;
} }

View File

@ -10,6 +10,8 @@
// Author: Vikas Arora (vikaas.arora@gmail.com) // Author: Vikas Arora (vikaas.arora@gmail.com)
// //
#ifdef USE_LOSSLESS_ENCODER
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -535,3 +537,5 @@ int VP8LEncodeImage(const WebPConfig* const config,
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} // extern "C" } // extern "C"
#endif #endif
#endif

View File

@ -12,6 +12,8 @@
#ifndef WEBP_ENC_VP8LI_H_ #ifndef WEBP_ENC_VP8LI_H_
#define WEBP_ENC_VP8LI_H_ #define WEBP_ENC_VP8LI_H_
#ifdef USE_LOSSLESS_ENCODER
#include "./histogram.h" #include "./histogram.h"
#include "../webp/encode.h" #include "../webp/encode.h"
#include "../utils/bit_writer.h" #include "../utils/bit_writer.h"
@ -70,4 +72,6 @@ int VP8LEncodeImage(const WebPConfig* const config,
} // extern "C" } // extern "C"
#endif #endif
#endif
#endif /* WEBP_ENC_VP8LI_H_ */ #endif /* WEBP_ENC_VP8LI_H_ */

View File

@ -364,10 +364,14 @@ int WebPEncode(const WebPConfig* const config, WebPPicture* const pic) {
} }
DeleteVP8Encoder(enc); DeleteVP8Encoder(enc);
} else { } else {
#ifdef USE_LOSSLESS_ENCODER
if (pic->argb == NULL) if (pic->argb == NULL)
return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER); return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER);
ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem. ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem.
#else
return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION);
#endif
} }
return ok; return ok;

View File

@ -187,6 +187,7 @@ void VP8BitWriterWipeOut(VP8BitWriter* const bw) {
} }
} }
#ifdef USE_LOSSLESS_ENCODER
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// VP8LBitWriter // VP8LBitWriter
@ -264,6 +265,7 @@ void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits) {
} }
} }
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -64,6 +64,7 @@ static WEBP_INLINE size_t VP8BitWriterSize(const VP8BitWriter* const bw) {
return bw->pos_; return bw->pos_;
} }
#ifdef USE_LOSSLESS_ENCODER
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// VP8LBitWriter // VP8LBitWriter
// TODO(vikasa): VP8LBitWriter is copied as-is from lossless code. There's scope // 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); void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#endif
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} // extern "C" } // extern "C"

View File

@ -39,6 +39,7 @@ static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc,
cc->colors_[key] = argb; cc->colors_[key] = argb;
} }
#ifdef USE_LOSSLESS_ENCODER
static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc, static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
uint32_t argb) { uint32_t argb) {
return (kHashMul * argb) >> cc->hash_shift_; 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_; const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
return cc->colors_[key] == argb; return cc->colors_[key] == argb;
} }
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -9,6 +9,8 @@
// //
// Flate like entropy encoding (Huffman) for webp lossless. // Flate like entropy encoding (Huffman) for webp lossless.
#ifdef USE_LOSSLESS_ENCODER
#include "./huffman_encode.h" #include "./huffman_encode.h"
#include <stdint.h> #include <stdint.h>
@ -311,3 +313,5 @@ void ConvertBitDepthsToSymbols(const uint8_t* depth, int len,
} }
} }
} }
#endif

View File

@ -12,6 +12,8 @@
#ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_ #ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_
#define WEBP_UTILS_HUFFMAN_ENCODE_H_ #define WEBP_UTILS_HUFFMAN_ENCODE_H_
#ifdef USE_LOSSLESS_ENCODER
#include <stdint.h> #include <stdint.h>
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
@ -49,4 +51,6 @@ void ConvertBitDepthsToSymbols(const uint8_t* depth, int len, uint16_t* bits);
} }
#endif #endif
#endif
#endif // WEBP_UTILS_HUFFMAN_ENCODE_H_ #endif // WEBP_UTILS_HUFFMAN_ENCODE_H_