From f079e487ae682d7305dbb970f3cea48993456b4d Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Tue, 20 Jan 2015 00:34:09 -0800 Subject: [PATCH] use uint16_t for chosen_path[] len is MAX_LENGTH (4096) at max. This reduce memory for path by a half. Change-Id: I399fda4093d93b1e9d956397b7b210956c5b948f --- src/enc/backward_references.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/enc/backward_references.c b/src/enc/backward_references.c index 774f0a2e..d495445e 100644 --- a/src/enc/backward_references.c +++ b/src/enc/backward_references.c @@ -547,7 +547,7 @@ static void AddSingleLiteralWithCostModel( const uint32_t* const argb, VP8LHashChain* const hash_chain, VP8LColorCache* const hashers, const CostModel* const cost_model, int idx, int is_last, int use_color_cache, double prev_cost, float* const cost, - uint32_t* const dist_array) { + uint16_t* const dist_array) { double cost_val = prev_cost; const uint32_t color = argb[0]; if (!is_last) { @@ -571,7 +571,7 @@ static void AddSingleLiteralWithCostModel( static int BackwardReferencesHashChainDistanceOnly( int xsize, int ysize, const uint32_t* const argb, int quality, int cache_bits, VP8LHashChain* const hash_chain, - VP8LBackwardRefs* const refs, uint32_t* const dist_array) { + VP8LBackwardRefs* const refs, uint16_t* const dist_array) { int i; int ok = 0; int cc_init = 0; @@ -691,12 +691,12 @@ static int BackwardReferencesHashChainDistanceOnly( // We pack the path at the end of *dist_array and return // a pointer to this part of the array. Example: // dist_array = [1x2xx3x2] => packed [1x2x1232], chosen_path = [1232] -static void TraceBackwards(uint32_t* const dist_array, +static void TraceBackwards(uint16_t* const dist_array, int dist_array_size, - uint32_t** const chosen_path, + uint16_t** const chosen_path, int* const chosen_path_size) { - uint32_t* path = dist_array + dist_array_size; - uint32_t* cur = dist_array + dist_array_size - 1; + uint16_t* path = dist_array + dist_array_size; + uint16_t* cur = dist_array + dist_array_size - 1; while (cur >= dist_array) { const int k = *cur; --path; @@ -710,7 +710,7 @@ static void TraceBackwards(uint32_t* const dist_array, static int BackwardReferencesHashChainFollowChosenPath( int xsize, int ysize, const uint32_t* const argb, int quality, int cache_bits, - const uint32_t* const chosen_path, int chosen_path_size, + const uint16_t* const chosen_path, int chosen_path_size, VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs) { const int pix_count = xsize * ysize; @@ -780,10 +780,10 @@ static int BackwardReferencesTraceBackwards(int xsize, int ysize, VP8LBackwardRefs* const refs) { int ok = 0; const int dist_array_size = xsize * ysize; - uint32_t* chosen_path = NULL; + uint16_t* chosen_path = NULL; int chosen_path_size = 0; - uint32_t* dist_array = - (uint32_t*)WebPSafeMalloc(dist_array_size, sizeof(*dist_array)); + uint16_t* dist_array = + (uint16_t*)WebPSafeMalloc(dist_array_size, sizeof(*dist_array)); if (dist_array == NULL) goto Error;