static WEBP_INLINE void AddSingleLiteral(uint32_t pixel, int use_color_cache, VP8LColorCache* const hashers, VP8LBackwardRefs* const refs) { PixOrCopy v; if (use_color_cache) { const uint32_t key = VP8LColorCacheGetIndex(hashers, pixel); if (VP8LColorCacheLookup(hashers, key) == pixel) { v = PixOrCopyCreateCacheIdx(key); } else { v = PixOrCopyCreateLiteral(pixel); VP8LColorCacheSet(hashers, key, pixel); } } else { v = PixOrCopyCreateLiteral(pixel); } VP8LBackwardRefsCursorAdd(refs, v); }
static int AnalyzeEntropy(const uint32_t* argb, int width, int height, int argb_stride, double* const nonpredicted_bits, double* const predicted_bits) { // Allocate histogram set with cache_bits = 0. VP8LHistogramSet* const histo_set = VP8LAllocateHistogramSet(2, 0); assert(nonpredicted_bits != NULL); assert(predicted_bits != NULL); if (histo_set != NULL) { int x, y; const uint32_t* prev_row = argb; const uint32_t* curr_row = argb + argb_stride; VP8LHistogram* const histo_non_pred = histo_set->histograms[0]; VP8LHistogram* const histo_pred = histo_set->histograms[1]; for (y = 1; y < height; ++y) { uint32_t prev_pix = curr_row[0]; for (x = 1; x < width; ++x) { const uint32_t pix = curr_row[x]; const uint32_t pix_diff = VP8LSubPixels(pix, prev_pix); if ((pix_diff == 0) || (pix == prev_row[x])) continue; prev_pix = pix; { const PixOrCopy pix_token = PixOrCopyCreateLiteral(pix); const PixOrCopy pix_diff_token = PixOrCopyCreateLiteral(pix_diff); VP8LHistogramAddSinglePixOrCopy(histo_non_pred, &pix_token); VP8LHistogramAddSinglePixOrCopy(histo_pred, &pix_diff_token); } } prev_row = curr_row; curr_row += argb_stride; } *nonpredicted_bits = VP8LHistogramEstimateBitsBulk(histo_non_pred); *predicted_bits = VP8LHistogramEstimateBitsBulk(histo_pred); VP8LFreeHistogramSet(histo_set); return 1; } else { return 0; } }