use uint16_t for chosen_path[]

len is MAX_LENGTH (4096) at max. This reduce memory for path by a half.

Change-Id: I399fda4093d93b1e9d956397b7b210956c5b948f
This commit is contained in:
Pascal Massimino 2015-01-20 00:34:09 -08:00
parent b8c2013512
commit f079e487ae

View File

@ -547,7 +547,7 @@ static void AddSingleLiteralWithCostModel(
const uint32_t* const argb, VP8LHashChain* const hash_chain, const uint32_t* const argb, VP8LHashChain* const hash_chain,
VP8LColorCache* const hashers, const CostModel* const cost_model, int idx, VP8LColorCache* const hashers, const CostModel* const cost_model, int idx,
int is_last, int use_color_cache, double prev_cost, float* const cost, 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; double cost_val = prev_cost;
const uint32_t color = argb[0]; const uint32_t color = argb[0];
if (!is_last) { if (!is_last) {
@ -571,7 +571,7 @@ static void AddSingleLiteralWithCostModel(
static int BackwardReferencesHashChainDistanceOnly( static int BackwardReferencesHashChainDistanceOnly(
int xsize, int ysize, const uint32_t* const argb, int xsize, int ysize, const uint32_t* const argb,
int quality, int cache_bits, VP8LHashChain* const hash_chain, 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 i;
int ok = 0; int ok = 0;
int cc_init = 0; int cc_init = 0;
@ -691,12 +691,12 @@ static int BackwardReferencesHashChainDistanceOnly(
// We pack the path at the end of *dist_array and return // We pack the path at the end of *dist_array and return
// a pointer to this part of the array. Example: // a pointer to this part of the array. Example:
// dist_array = [1x2xx3x2] => packed [1x2x1232], chosen_path = [1232] // 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, int dist_array_size,
uint32_t** const chosen_path, uint16_t** const chosen_path,
int* const chosen_path_size) { int* const chosen_path_size) {
uint32_t* path = dist_array + dist_array_size; uint16_t* path = dist_array + dist_array_size;
uint32_t* cur = dist_array + dist_array_size - 1; uint16_t* cur = dist_array + dist_array_size - 1;
while (cur >= dist_array) { while (cur >= dist_array) {
const int k = *cur; const int k = *cur;
--path; --path;
@ -710,7 +710,7 @@ static void TraceBackwards(uint32_t* const dist_array,
static int BackwardReferencesHashChainFollowChosenPath( static int BackwardReferencesHashChainFollowChosenPath(
int xsize, int ysize, const uint32_t* const argb, int xsize, int ysize, const uint32_t* const argb,
int quality, int cache_bits, 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, VP8LHashChain* const hash_chain,
VP8LBackwardRefs* const refs) { VP8LBackwardRefs* const refs) {
const int pix_count = xsize * ysize; const int pix_count = xsize * ysize;
@ -780,10 +780,10 @@ static int BackwardReferencesTraceBackwards(int xsize, int ysize,
VP8LBackwardRefs* const refs) { VP8LBackwardRefs* const refs) {
int ok = 0; int ok = 0;
const int dist_array_size = xsize * ysize; const int dist_array_size = xsize * ysize;
uint32_t* chosen_path = NULL; uint16_t* chosen_path = NULL;
int chosen_path_size = 0; int chosen_path_size = 0;
uint32_t* dist_array = uint16_t* dist_array =
(uint32_t*)WebPSafeMalloc(dist_array_size, sizeof(*dist_array)); (uint16_t*)WebPSafeMalloc(dist_array_size, sizeof(*dist_array));
if (dist_array == NULL) goto Error; if (dist_array == NULL) goto Error;