mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 02:15:42 +01:00 
			
		
		
		
	Code cleanup for VP8LGetHistoImageSymbols.
Fix comments and few nits. Change-Id: I8fa25ed523f12c6a7bfe125f0e4d638466ba4304
This commit is contained in:
		| @@ -423,10 +423,10 @@ static int GetHistoBinIndex( | |||||||
| // Construct the histograms from backward references. | // Construct the histograms from backward references. | ||||||
| static void HistogramBuild( | static void HistogramBuild( | ||||||
|     int xsize, int histo_bits, const VP8LBackwardRefs* const backward_refs, |     int xsize, int histo_bits, const VP8LBackwardRefs* const backward_refs, | ||||||
|     VP8LHistogramSet* const init_histo) { |     VP8LHistogramSet* const image_histo) { | ||||||
|   int x = 0, y = 0; |   int x = 0, y = 0; | ||||||
|   const int histo_xsize = VP8LSubSampleSize(xsize, histo_bits); |   const int histo_xsize = VP8LSubSampleSize(xsize, histo_bits); | ||||||
|   VP8LHistogram** const histograms = init_histo->histograms; |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|   VP8LRefsCursor c = VP8LRefsCursorInit(backward_refs); |   VP8LRefsCursor c = VP8LRefsCursorInit(backward_refs); | ||||||
|   assert(histo_bits > 0); |   assert(histo_bits > 0); | ||||||
|   // Construct the Histo from a given backward references. |   // Construct the Histo from a given backward references. | ||||||
| @@ -443,38 +443,35 @@ static void HistogramBuild( | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| // Compute the histogram aggregate bit_cost. | // Copies the histograms and computes its bit_cost. | ||||||
| static void HistogramAnalyze( | static void HistogramCopyAndAnalyze( | ||||||
|     VP8LHistogramSet* const init_histo, VP8LHistogramSet* const histo_image) { |     VP8LHistogramSet* const orig_histo, VP8LHistogramSet* const image_histo) { | ||||||
|   int i; |   int i; | ||||||
|   const int histo_size = init_histo->size; |   const int histo_size = orig_histo->size; | ||||||
|   VP8LHistogram** const histograms = init_histo->histograms; |   VP8LHistogram** const orig_histograms = orig_histo->histograms; | ||||||
|  |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|   for (i = 0; i < histo_size; ++i) { |   for (i = 0; i < histo_size; ++i) { | ||||||
|     VP8LHistogram* const histo = histograms[i]; |     VP8LHistogram* const histo = orig_histograms[i]; | ||||||
|     histo->bit_cost_ = VP8LHistogramEstimateBits(histo); |     UpdateHistogramCost(histo); | ||||||
|     // Copy histograms from init_histo[] to histo_image[]. |     // Copy histograms from orig_histo[] to image_histo[]. | ||||||
|     HistogramCopy(histo, histo_image->histograms[i]); |     HistogramCopy(histo, histograms[i]); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| // Partition Histograms to different entropy bins for three dominant (literal, | // Partition histograms to different entropy bins for three dominant (literal, | ||||||
| // red and blue) symbol costs and compute the histogram aggregate bit_cost. | // red and blue) symbol costs and compute the histogram aggregate bit_cost. | ||||||
| static void HistogramAnalyzeBin( | static void HistogramAnalyzeEntropyBin( | ||||||
|     VP8LHistogramSet* const init_histo, VP8LHistogramSet* const histo_image, |     VP8LHistogramSet* const image_histo, int16_t* const bin_map) { | ||||||
|     int16_t* const bin_map) { |  | ||||||
|   int i; |   int i; | ||||||
|   const int histo_size = init_histo->size; |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|   VP8LHistogram** const histograms = init_histo->histograms; |   const int histo_size = image_histo->size; | ||||||
|   const int bin_depth = init_histo->size + 1; |   const int bin_depth = histo_size + 1; | ||||||
|   DominantCostRange cost_range; |   DominantCostRange cost_range; | ||||||
|   DominantCostRangeInit(&cost_range); |   DominantCostRangeInit(&cost_range); | ||||||
|  |  | ||||||
|   // Analyze the dominant (literal, red and blue) entropy costs. |   // Analyze the dominant (literal, red and blue) entropy costs. | ||||||
|   for (i = 0; i < histo_size; ++i) { |   for (i = 0; i < histo_size; ++i) { | ||||||
|     VP8LHistogram* const histo = histograms[i]; |     VP8LHistogram* const histo = histograms[i]; | ||||||
|     UpdateHistogramCost(histo); |  | ||||||
|     // Copy histograms from init_histo[] to histo_image[]. |  | ||||||
|     HistogramCopy(histo, histo_image->histograms[i]); |  | ||||||
|     UpdateDominantCostRange(histo, &cost_range); |     UpdateDominantCostRange(histo, &cost_range); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -499,39 +496,38 @@ static void HistogramAnalyzeBin( | |||||||
| // head and moving the ones that have been merged to other histograms towards | // head and moving the ones that have been merged to other histograms towards | ||||||
| // the end. | // the end. | ||||||
| // TODO(vikasa): Evaluate if this method can be avoided by altering the code | // TODO(vikasa): Evaluate if this method can be avoided by altering the code | ||||||
| // logic of HistogramCombineBin main loop. | // logic of HistogramCombineEntropyBin main loop. | ||||||
| static void HistogramCompactBins(VP8LHistogramSet* const histo_image) { | static void HistogramCompactBins(VP8LHistogramSet* const image_histo) { | ||||||
|   int start = 0; |   int start = 0; | ||||||
|   int end = histo_image->size - 1; |   int end = image_histo->size - 1; | ||||||
|  |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|   while (start < end) { |   while (start < end) { | ||||||
|     while (start <= end && |     while (start <= end && histograms[start] != NULL && | ||||||
|            histo_image->histograms[start] != NULL && |            histograms[start]->bit_cost_ != 0.) { | ||||||
|            histo_image->histograms[start]->bit_cost_ != 0.) { |  | ||||||
|       ++start; |       ++start; | ||||||
|     } |     } | ||||||
|     while (start <= end && |     while (start <= end && histograms[end]->bit_cost_ == 0.) { | ||||||
|            histo_image->histograms[end]->bit_cost_ == 0.) { |       histograms[end] = NULL; | ||||||
|       histo_image->histograms[end] = NULL; |  | ||||||
|       --end; |       --end; | ||||||
|     } |     } | ||||||
|     if (start < end) { |     if (start < end) { | ||||||
|       assert(histo_image->histograms[start] != NULL); |       assert(histograms[start] != NULL); | ||||||
|       assert(histo_image->histograms[end] != NULL); |       assert(histograms[end] != NULL); | ||||||
|       HistogramCopy(histo_image->histograms[end], |       HistogramCopy(histograms[end], histograms[start]); | ||||||
|                     histo_image->histograms[start]); |       histograms[end] = NULL; | ||||||
|       histo_image->histograms[end] = NULL; |  | ||||||
|       --end; |       --end; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   histo_image->size = end + 1; |   image_histo->size = end + 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void HistogramCombineBin(VP8LHistogramSet* const histo_image, | static void HistogramCombineEntropyBin(VP8LHistogramSet* const image_histo, | ||||||
|                                 VP8LHistogram* const histos, int bin_depth, |                                        VP8LHistogram* const histos, | ||||||
|                                 double combine_cost_factor, |                                        int16_t* const bin_map, int bin_depth, | ||||||
|                                 int16_t* const bin_map) { |                                        double combine_cost_factor) { | ||||||
|   int bin_id; |   int bin_id; | ||||||
|   VP8LHistogram* cur_combo = histos; |   VP8LHistogram* cur_combo = histos; | ||||||
|  |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|  |  | ||||||
|   for (bin_id = 0; bin_id < BIN_SIZE; ++bin_id) { |   for (bin_id = 0; bin_id < BIN_SIZE; ++bin_id) { | ||||||
|     const int bin_offset = bin_id * bin_depth; |     const int bin_offset = bin_id * bin_depth; | ||||||
| @@ -540,21 +536,20 @@ static void HistogramCombineBin(VP8LHistogramSet* const histo_image, | |||||||
|     int n; |     int n; | ||||||
|     for (n = 2; n <= num_histos; ++n) { |     for (n = 2; n <= num_histos; ++n) { | ||||||
|       const int idx2 = bin_map[bin_offset + n]; |       const int idx2 = bin_map[bin_offset + n]; | ||||||
|       const double bit_cost_idx2 = histo_image->histograms[idx2]->bit_cost_; |       const double bit_cost_idx2 = histograms[idx2]->bit_cost_; | ||||||
|       if (bit_cost_idx2 > 0.) { |       if (bit_cost_idx2 > 0.) { | ||||||
|         const double bit_cost_thresh = -bit_cost_idx2 * combine_cost_factor; |         const double bit_cost_thresh = -bit_cost_idx2 * combine_cost_factor; | ||||||
|         const double curr_cost_diff = |         const double curr_cost_diff = | ||||||
|             HistogramAddEval(histo_image->histograms[idx1], |             HistogramAddEval(histograms[idx1], histograms[idx2], | ||||||
|                              histo_image->histograms[idx2], |  | ||||||
|                              cur_combo, bit_cost_thresh); |                              cur_combo, bit_cost_thresh); | ||||||
|         if (curr_cost_diff < bit_cost_thresh) { |         if (curr_cost_diff < bit_cost_thresh) { | ||||||
|           HistogramCopy(cur_combo, histo_image->histograms[idx1]); |           HistogramCopy(cur_combo, histograms[idx1]); | ||||||
|           histo_image->histograms[idx2]->bit_cost_ = 0.; |           histograms[idx2]->bit_cost_ = 0.; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   HistogramCompactBins(histo_image); |   HistogramCompactBins(image_histo); | ||||||
| } | } | ||||||
|  |  | ||||||
| static uint32_t MyRand(uint32_t *seed) { | static uint32_t MyRand(uint32_t *seed) { | ||||||
| @@ -565,45 +560,45 @@ static uint32_t MyRand(uint32_t *seed) { | |||||||
|   return *seed; |   return *seed; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void HistogramCombine(VP8LHistogramSet* const histo_image, | static void HistogramCombine(VP8LHistogramSet* const image_histo, | ||||||
|                              VP8LHistogramSet* const histos, int quality) { |                              VP8LHistogramSet* const histos, int quality) { | ||||||
|   int iter; |   int iter; | ||||||
|   uint32_t seed = 0; |   uint32_t seed = 0; | ||||||
|   int tries_with_no_success = 0; |   int tries_with_no_success = 0; | ||||||
|   int histo_image_size = histo_image->size; |   int image_histo_size = image_histo->size; | ||||||
|   const int iter_mult = (quality < 25) ? 2 : 2 + (quality - 25) / 8; |   const int iter_mult = (quality < 25) ? 2 : 2 + (quality - 25) / 8; | ||||||
|   const int outer_iters = histo_image_size * iter_mult; |   const int outer_iters = image_histo_size * iter_mult; | ||||||
|   const int num_pairs = histo_image_size / 2; |   const int num_pairs = image_histo_size / 2; | ||||||
|   const int num_tries_no_success = outer_iters / 2; |   const int num_tries_no_success = outer_iters / 2; | ||||||
|   const int min_cluster_size = 2; |   const int min_cluster_size = 2; | ||||||
|  |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|   VP8LHistogram* cur_combo = histos->histograms[0];   // trial histogram |   VP8LHistogram* cur_combo = histos->histograms[0];   // trial histogram | ||||||
|   VP8LHistogram* best_combo = histos->histograms[1];  // best histogram so far |   VP8LHistogram* best_combo = histos->histograms[1];  // best histogram so far | ||||||
|  |  | ||||||
|   // Collapse similar histograms in 'histo_image'. |   // Collapse similar histograms in 'image_histo'. | ||||||
|   for (iter = 0; |   for (iter = 0; | ||||||
|        iter < outer_iters && histo_image_size >= min_cluster_size; |        iter < outer_iters && image_histo_size >= min_cluster_size; | ||||||
|        ++iter) { |        ++iter) { | ||||||
|     double best_cost_diff = 0.; |     double best_cost_diff = 0.; | ||||||
|     int best_idx1 = -1, best_idx2 = 1; |     int best_idx1 = -1, best_idx2 = 1; | ||||||
|     int j; |     int j; | ||||||
|     const int num_tries = |     const int num_tries = | ||||||
|         (num_pairs < histo_image_size) ? num_pairs : histo_image_size; |         (num_pairs < image_histo_size) ? num_pairs : image_histo_size; | ||||||
|     seed += iter; |     seed += iter; | ||||||
|     for (j = 0; j < num_tries; ++j) { |     for (j = 0; j < num_tries; ++j) { | ||||||
|       double curr_cost_diff; |       double curr_cost_diff; | ||||||
|       // Choose two histograms at random and try to combine them. |       // Choose two histograms at random and try to combine them. | ||||||
|       const uint32_t idx1 = MyRand(&seed) % histo_image_size; |       const uint32_t idx1 = MyRand(&seed) % image_histo_size; | ||||||
|       const uint32_t tmp = (j & 7) + 1; |       const uint32_t tmp = (j & 7) + 1; | ||||||
|       const uint32_t diff = |       const uint32_t diff = | ||||||
|           (tmp < 3) ? tmp : MyRand(&seed) % (histo_image_size - 1); |           (tmp < 3) ? tmp : MyRand(&seed) % (image_histo_size - 1); | ||||||
|       const uint32_t idx2 = (idx1 + diff + 1) % histo_image_size; |       const uint32_t idx2 = (idx1 + diff + 1) % image_histo_size; | ||||||
|       if (idx1 == idx2) { |       if (idx1 == idx2) { | ||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       // Calculate cost reduction on combining. |       // Calculate cost reduction on combining. | ||||||
|       curr_cost_diff = HistogramAddEval(histo_image->histograms[idx1], |       curr_cost_diff = HistogramAddEval(histograms[idx1], histograms[idx2], | ||||||
|                                         histo_image->histograms[idx2], |  | ||||||
|                                         cur_combo, best_cost_diff); |                                         cur_combo, best_cost_diff); | ||||||
|       if (curr_cost_diff < best_cost_diff) {    // found a better pair? |       if (curr_cost_diff < best_cost_diff) {    // found a better pair? | ||||||
|         {     // swap cur/best combo histograms |         {     // swap cur/best combo histograms | ||||||
| @@ -618,13 +613,12 @@ static void HistogramCombine(VP8LHistogramSet* const histo_image, | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (best_idx1 >= 0) { |     if (best_idx1 >= 0) { | ||||||
|       HistogramCopy(best_combo, histo_image->histograms[best_idx1]); |       HistogramCopy(best_combo, histograms[best_idx1]); | ||||||
|       // swap best_idx2 slot with last one (which is now unused) |       // swap best_idx2 slot with last one (which is now unused) | ||||||
|       --histo_image_size; |       --image_histo_size; | ||||||
|       if (best_idx2 != histo_image_size) { |       if (best_idx2 != image_histo_size) { | ||||||
|         HistogramCopy(histo_image->histograms[histo_image_size], |         HistogramCopy(histograms[image_histo_size], histograms[best_idx2]); | ||||||
|                       histo_image->histograms[best_idx2]); |         histograms[image_histo_size] = NULL; | ||||||
|         histo_image->histograms[histo_image_size] = NULL; |  | ||||||
|       } |       } | ||||||
|       tries_with_no_success = 0; |       tries_with_no_success = 0; | ||||||
|     } |     } | ||||||
| @@ -632,7 +626,7 @@ static void HistogramCombine(VP8LHistogramSet* const histo_image, | |||||||
|       break; |       break; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   histo_image->size = histo_image_size; |   image_histo->size = image_histo_size; | ||||||
| } | } | ||||||
|  |  | ||||||
| // ----------------------------------------------------------------------------- | // ----------------------------------------------------------------------------- | ||||||
| @@ -640,19 +634,20 @@ static void HistogramCombine(VP8LHistogramSet* const histo_image, | |||||||
|  |  | ||||||
| // Find the best 'out' histogram for each of the 'in' histograms. | // Find the best 'out' histogram for each of the 'in' histograms. | ||||||
| // Note: we assume that out[]->bit_cost_ is already up-to-date. | // Note: we assume that out[]->bit_cost_ is already up-to-date. | ||||||
| static void HistogramRemap(const VP8LHistogramSet* const init_histo, | static void HistogramRemap(const VP8LHistogramSet* const orig_histo, | ||||||
|                            const VP8LHistogramSet* const histo_image, |                            const VP8LHistogramSet* const image_histo, | ||||||
|                            uint16_t* const symbols) { |                            uint16_t* const symbols) { | ||||||
|   int i; |   int i; | ||||||
|   for (i = 0; i < init_histo->size; ++i) { |   VP8LHistogram** const orig_histograms = orig_histo->histograms; | ||||||
|  |   VP8LHistogram** const histograms = image_histo->histograms; | ||||||
|  |   for (i = 0; i < orig_histo->size; ++i) { | ||||||
|     int best_out = 0; |     int best_out = 0; | ||||||
|     double best_bits = HistogramAddThresh(histo_image->histograms[0], |     double best_bits = | ||||||
|                                           init_histo->histograms[i], MAX_COST); |         HistogramAddThresh(histograms[0], orig_histograms[i], MAX_COST); | ||||||
|     int k; |     int k; | ||||||
|     for (k = 1; k < histo_image->size; ++k) { |     for (k = 1; k < image_histo->size; ++k) { | ||||||
|       const double cur_bits = HistogramAddThresh(histo_image->histograms[k], |       const double cur_bits = | ||||||
|                                                  init_histo->histograms[i], |           HistogramAddThresh(histograms[k], orig_histograms[i], best_bits); | ||||||
|                                                  best_bits); |  | ||||||
|       if (cur_bits < best_bits) { |       if (cur_bits < best_bits) { | ||||||
|         best_bits = cur_bits; |         best_bits = cur_bits; | ||||||
|         best_out = k; |         best_out = k; | ||||||
| @@ -662,14 +657,13 @@ static void HistogramRemap(const VP8LHistogramSet* const init_histo, | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Recompute each out based on raw and symbols. |   // Recompute each out based on raw and symbols. | ||||||
|   for (i = 0; i < histo_image->size; ++i) { |   for (i = 0; i < image_histo->size; ++i) { | ||||||
|     HistogramClear(histo_image->histograms[i]); |     HistogramClear(histograms[i]); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   for (i = 0; i < init_histo->size; ++i) { |   for (i = 0; i < orig_histo->size; ++i) { | ||||||
|     VP8LHistogramAdd(init_histo->histograms[i], |     const int idx = symbols[i]; | ||||||
|                      histo_image->histograms[symbols[i]], |     VP8LHistogramAdd(orig_histograms[i], histograms[idx], histograms[idx]); | ||||||
|                      histo_image->histograms[symbols[i]]); |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -685,62 +679,63 @@ static double GetCombineCostFactor(int histo_size, int quality) { | |||||||
| int VP8LGetHistoImageSymbols(int xsize, int ysize, | int VP8LGetHistoImageSymbols(int xsize, int ysize, | ||||||
|                              const VP8LBackwardRefs* const refs, |                              const VP8LBackwardRefs* const refs, | ||||||
|                              int quality, int histo_bits, int cache_bits, |                              int quality, int histo_bits, int cache_bits, | ||||||
|                              VP8LHistogramSet* const histo_image, |                              VP8LHistogramSet* const image_histo, | ||||||
|                              uint16_t* const histogram_symbols) { |                              uint16_t* const histogram_symbols) { | ||||||
|   int ok = 0; |   int ok = 0; | ||||||
|   const int histo_xsize = histo_bits ? VP8LSubSampleSize(xsize, histo_bits) : 1; |   const int histo_xsize = histo_bits ? VP8LSubSampleSize(xsize, histo_bits) : 1; | ||||||
|   const int histo_ysize = histo_bits ? VP8LSubSampleSize(ysize, histo_bits) : 1; |   const int histo_ysize = histo_bits ? VP8LSubSampleSize(ysize, histo_bits) : 1; | ||||||
|   const int histo_image_raw_size = histo_xsize * histo_ysize; |   const int image_histo_raw_size = histo_xsize * histo_ysize; | ||||||
|  |  | ||||||
|   // The bin_map for every bin follows following semantics: |   // The bin_map for every bin follows following semantics: | ||||||
|   // bin_map[n][0] = num_histo; // The number of histograms in that bin. |   // bin_map[n][0] = num_histo; // The number of histograms in that bin. | ||||||
|   // bin_map[n][1] = index of first histogram in that bin; |   // bin_map[n][1] = index of first histogram in that bin; | ||||||
|   // bin_map[n][num_histo] = index of last histogram in that bin; |   // bin_map[n][num_histo] = index of last histogram in that bin; | ||||||
|   // bin_map[n][num_histo + 1] ... bin_map[n][bin_depth - 1] = un-used indices. |   // bin_map[n][num_histo + 1] ... bin_map[n][bin_depth - 1] = un-used indices. | ||||||
|   const int bin_depth = histo_image_raw_size + 1; |   const int bin_depth = image_histo_raw_size + 1; | ||||||
|   int16_t* bin_map = NULL; |   int16_t* bin_map = NULL; | ||||||
|   VP8LHistogramSet* const histos = VP8LAllocateHistogramSet(2, cache_bits); |   VP8LHistogramSet* const histos = VP8LAllocateHistogramSet(2, cache_bits); | ||||||
|   VP8LHistogramSet* const init_histo = |   VP8LHistogramSet* const orig_histo = | ||||||
|       VP8LAllocateHistogramSet(histo_image_raw_size, cache_bits); |       VP8LAllocateHistogramSet(image_histo_raw_size, cache_bits); | ||||||
|  |  | ||||||
|   if (init_histo == NULL || histos == NULL) { |   if (orig_histo == NULL || histos == NULL) { | ||||||
|     goto Error; |     goto Error; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Don't attempt linear bin-partition heuristic for: |   // Don't attempt linear bin-partition heuristic for: | ||||||
|   // Histograms of small sizes, as bin_map will be very sparse and; |   // histograms of small sizes, as bin_map will be very sparse and; | ||||||
|   // Higher qualities (> 90), to preserve the compression gains at those |   // Higher qualities (> 90), to preserve the compression gains at those | ||||||
|   // quality settings. |   // quality settings. | ||||||
|   if (init_histo->size > 2 * BIN_SIZE && quality < 90) { |   if (orig_histo->size > 2 * BIN_SIZE && quality < 90) { | ||||||
|     const int bin_map_size = bin_depth * BIN_SIZE; |     const int bin_map_size = bin_depth * BIN_SIZE; | ||||||
|     bin_map = (int16_t*)WebPSafeCalloc(bin_map_size, sizeof(*bin_map)); |     bin_map = (int16_t*)WebPSafeCalloc(bin_map_size, sizeof(*bin_map)); | ||||||
|     if (bin_map == NULL) goto Error; |     if (bin_map == NULL) goto Error; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Construct the histogram from backward references. |   // Construct the histograms from backward references. | ||||||
|   HistogramBuild(xsize, histo_bits, refs, init_histo); |   HistogramBuild(xsize, histo_bits, refs, orig_histo); | ||||||
|  |   // Copies the histograms and computes its bit_cost. | ||||||
|  |   HistogramCopyAndAnalyze(orig_histo, image_histo); | ||||||
|  |  | ||||||
|   if (bin_map != NULL) { |   if (bin_map != NULL) { | ||||||
|     const double combine_cost_factor = |     const double combine_cost_factor = | ||||||
|         GetCombineCostFactor(histo_image_raw_size, quality); |         GetCombineCostFactor(image_histo_raw_size, quality); | ||||||
|     HistogramAnalyzeBin(init_histo, histo_image, bin_map); |     HistogramAnalyzeEntropyBin(orig_histo, bin_map); | ||||||
|     HistogramCombineBin(histo_image, histos->histograms[0], |     // Collapse histograms with similar entropy. | ||||||
|                         bin_depth, combine_cost_factor, bin_map); |     HistogramCombineEntropyBin(image_histo, histos->histograms[0], | ||||||
|   } else { |                                bin_map, bin_depth, combine_cost_factor); | ||||||
|     HistogramAnalyze(init_histo, histo_image); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Collapse similar histograms. |   // Collapse similar histograms by random histogram-pair compares. | ||||||
|   HistogramCombine(histo_image, histos, quality); |   HistogramCombine(image_histo, histos, quality); | ||||||
|  |  | ||||||
|   // Find the optimal map from original histograms to the final ones. |   // Find the optimal map from original histograms to the final ones. | ||||||
|   HistogramRemap(init_histo, histo_image, histogram_symbols); |   HistogramRemap(orig_histo, image_histo, histogram_symbols); | ||||||
|  |  | ||||||
|   ok = 1; |   ok = 1; | ||||||
|  |  | ||||||
|  Error: |  Error: | ||||||
|   WebPSafeFree(bin_map); |   WebPSafeFree(bin_map); | ||||||
|   VP8LFreeHistogramSet(init_histo); |   VP8LFreeHistogramSet(orig_histo); | ||||||
|   VP8LFreeHistogramSet(histos); |   VP8LFreeHistogramSet(histos); | ||||||
|   return ok; |   return ok; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user