big code clean-up and refactoring and optimization

* de-inline some function
* make VP8LBackwardRefs be more like a vectorwith max capacity
* add bit_cost_ field to VP8LHistogram
* general code simplifications
* remove some memmov() from HistogramRefine
* simplify HistogramDistance()
...

Change-Id: I16904d9fa2380e1cf4a3fdddf56ed1fcadfa25dc
This commit is contained in:
Pascal Massimino
2012-04-30 12:18:50 +00:00
committed by James Zern
parent 41b5c8ff71
commit 1a210ef1a9
5 changed files with 322 additions and 328 deletions

View File

@ -103,10 +103,6 @@ typedef struct {
uint32_t argb_or_distance;
} PixOrCopy;
typedef struct {
PixOrCopy* refs;
int size;
} VP8LBackwardRefs;
static WEBP_INLINE PixOrCopy PixOrCopyCreateCopy(uint32_t distance,
uint16_t len) {
@ -136,15 +132,15 @@ static WEBP_INLINE PixOrCopy PixOrCopyCreateLiteral(uint32_t argb) {
}
static WEBP_INLINE int PixOrCopyIsLiteral(const PixOrCopy* const p) {
return p->mode == kLiteral;
return (p->mode == kLiteral);
}
static WEBP_INLINE int PixOrCopyIsCacheIdx(const PixOrCopy* const p) {
return p->mode == kCacheIdx;
return (p->mode == kCacheIdx);
}
static WEBP_INLINE int PixOrCopyIsCopy(const PixOrCopy* const p) {
return p->mode == kCopy;
return (p->mode == kCopy);
}
static WEBP_INLINE uint32_t PixOrCopyLiteral(const PixOrCopy* const p,
@ -173,10 +169,21 @@ static WEBP_INLINE uint32_t PixOrCopyDistance(const PixOrCopy* const p) {
return p->argb_or_distance;
}
// -----------------------------------------------------------------------------
// VP8LBackwardRefs
typedef struct {
PixOrCopy* refs;
int size; // currently used
int max_size; // maximum capacity
} VP8LBackwardRefs;
static WEBP_INLINE void VP8LInitBackwardRefs(VP8LBackwardRefs* const refs) {
if (refs != NULL) {
refs->refs = NULL;
refs->size = 0;
refs->max_size = 0;
}
}
@ -187,32 +194,41 @@ static WEBP_INLINE void VP8LClearBackwardRefs(VP8LBackwardRefs* const refs) {
}
}
// Allocate 'max_size' references. Returns false in case of memory error.
static WEBP_INLINE int VP8LBackwardRefsAlloc(VP8LBackwardRefs* const refs,
int max_size) {
assert(refs != NULL);
refs->size = 0;
refs->max_size = 0;
refs->refs = (PixOrCopy*)malloc(max_size * sizeof(*refs->refs));
if (refs->refs == NULL) return 0;
refs->max_size = max_size;
return 1;
}
// Ridiculously simple backward references for images where it is unlikely
// that there are large backward references (photos).
void VP8LBackwardReferencesRle(
int xsize, int ysize, const uint32_t* const argb, PixOrCopy* const stream,
int* const stream_size);
int xsize, int ysize, const uint32_t* const argb,
VP8LBackwardRefs* const refs);
// This is a simple fast function for obtaining backward references
// based on simple heuristics. Returns 1 on success.
int VP8LBackwardReferencesHashChain(
int xsize, int ysize, int use_color_cache, const uint32_t* const argb,
int cache_bits, int quality, PixOrCopy* const stream,
int* const stream_size);
int cache_bits, int quality, VP8LBackwardRefs* const refs);
// This method looks for a shortest path through the backward reference
// network based on a cost model generated by a first round of compression.
// Returns 1 on success.
int VP8LBackwardReferencesTraceBackwards(
int xsize, int ysize, int recursive_cost_model, int use_color_cache,
const uint32_t* const argb, int cache_bits, PixOrCopy* const stream,
int* const stream_size);
const uint32_t* const argb, int cache_bits, VP8LBackwardRefs* const refs);
// Convert backward references that are of linear distance along
// the image scan lines to have a 2d locality indexing where
// smaller values are used for backward references that are close by.
void VP8LBackwardReferences2DLocality(int xsize, int data_size,
PixOrCopy* const data);
void VP8LBackwardReferences2DLocality(int xsize, VP8LBackwardRefs* const refs);
// Internals of locality transform exposed for testing use.
int VP8LDistanceToPlaneCode(int xsize, int distance);
@ -221,7 +237,7 @@ int VP8LDistanceToPlaneCode(int xsize, int distance);
// the image given in tuple (argb, xsize, ysize).
int VP8LVerifyBackwardReferences(
const uint32_t* const argb, int xsize, int ysize, int cache_bits,
const PixOrCopy* const lit, int lit_size);
const VP8LBackwardRefs* const refs);
// Produce an estimate for a good color cache size for the image.
int VP8LCalculateEstimateForCacheSize(