mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
Merge "Enable lossless encoder code"
This commit is contained in:
commit
2bbe1c9aa0
@ -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) {
|
||||
|
@ -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 \
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -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 =
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -8,8 +8,6 @@
|
||||
// Author: Jyrki Alakuijala (jyrki@google.com)
|
||||
//
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
@ -816,5 +814,3 @@ int VP8LCalculateEstimateForCacheSize(const uint32_t* const argb,
|
||||
VP8LClearBackwardRefs(&refs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,8 +11,6 @@
|
||||
#ifndef WEBP_ENC_BACKWARD_REFERENCES_H_
|
||||
#define WEBP_ENC_BACKWARD_REFERENCES_H_
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "../webp/types.h"
|
||||
@ -203,6 +201,4 @@ int VP8LCalculateEstimateForCacheSize(const uint32_t* const argb,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // WEBP_ENC_BACKWARD_REFERENCES_H_
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -443,5 +441,3 @@ Error:
|
||||
free(image_out);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -12,8 +12,6 @@
|
||||
#ifndef WEBP_ENC_HISTOGRAM_H_
|
||||
#define WEBP_ENC_HISTOGRAM_H_
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
@ -142,6 +140,4 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // WEBP_ENC_HISTOGRAM_H_
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
// Author: Vikas Arora (vikaas.arora@gmail.com)
|
||||
//
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -1069,5 +1067,3 @@ int VP8LEncodeImage(const WebPConfig* const config,
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -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_ */
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -9,8 +9,6 @@
|
||||
//
|
||||
// Flate-like entropy encoding (Huffman) for webp lossless.
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -438,5 +436,3 @@ int VP8LCreateHuffmanTree(int* const histogram, int tree_depth_limit,
|
||||
ConvertBitDepthsToSymbols(tree);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -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_
|
||||
|
Loading…
Reference in New Issue
Block a user