mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 12:28:26 +01:00
Do not use a palette for one color images.
1 color images now always take 30 bytes. Change-Id: Ifa86bc5320362c659672b3836160353d63576467
This commit is contained in:
parent
98bbe35b51
commit
b6513fbaa8
@ -550,6 +550,25 @@ static int BackwardReferencesLz77(int xsize, int ysize,
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int BackwardReferencesNone(int xsize, int ysize,
|
||||||
|
const uint32_t* const argb, int cache_bits,
|
||||||
|
VP8LBackwardRefs* const refs) {
|
||||||
|
const int pix_count = xsize * ysize;
|
||||||
|
int i;
|
||||||
|
const int use_color_cache = (cache_bits > 0);
|
||||||
|
VP8LColorCache hashers;
|
||||||
|
|
||||||
|
if (use_color_cache && !VP8LColorCacheInit(&hashers, cache_bits)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
VP8LClearBackwardRefs(refs);
|
||||||
|
for (i = 0; i < pix_count; ++i) {
|
||||||
|
AddSingleLiteral(argb[i], use_color_cache, &hashers, refs);
|
||||||
|
}
|
||||||
|
if (use_color_cache) VP8LColorCacheClear(&hashers);
|
||||||
|
return !refs->error_;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute an LZ77 by forcing matches to happen within a given distance cost.
|
// Compute an LZ77 by forcing matches to happen within a given distance cost.
|
||||||
// We therefore limit the algorithm to the lowest 32 values in the PlaneCode
|
// We therefore limit the algorithm to the lowest 32 values in the PlaneCode
|
||||||
// definition.
|
// definition.
|
||||||
@ -919,6 +938,9 @@ static int GetBackwardReferences(int width, int height,
|
|||||||
res = BackwardReferencesLz77Box(width, height, argb, 0, hash_chain,
|
res = BackwardReferencesLz77Box(width, height, argb, 0, hash_chain,
|
||||||
&hash_chain_box, refs_tmp);
|
&hash_chain_box, refs_tmp);
|
||||||
break;
|
break;
|
||||||
|
case kLZ77None:
|
||||||
|
res = BackwardReferencesNone(width, height, argb, 0, refs_tmp);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,10 @@ static WEBP_INLINE void VP8LRefsCursorNext(VP8LRefsCursor* const c) {
|
|||||||
enum VP8LLZ77Type {
|
enum VP8LLZ77Type {
|
||||||
kLZ77Standard = 1,
|
kLZ77Standard = 1,
|
||||||
kLZ77RLE = 2,
|
kLZ77RLE = 2,
|
||||||
kLZ77Box = 4
|
kLZ77Box = 4,
|
||||||
|
// With kLZ77None, LZ77 is not even tried. For now, this is only useful for
|
||||||
|
// 1-color images but we could use it if we are sure the image is a photo.
|
||||||
|
kLZ77None = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
// Evaluates best possible backward references for specified quality.
|
// Evaluates best possible backward references for specified quality.
|
||||||
|
@ -591,6 +591,19 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
|
|||||||
sizeof(*enc->palette_sorted_), PaletteCompareColorsForQsort);
|
sizeof(*enc->palette_sorted_), PaletteCompareColorsForQsort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (use_palette && enc->palette_size_ == 1) {
|
||||||
|
crunch_configs[0].entropy_idx_ = kDirect;
|
||||||
|
crunch_configs[0].sub_configs_size_ = 1;
|
||||||
|
crunch_configs[0].sub_configs_[0].lz77_ = kLZ77None;
|
||||||
|
crunch_configs[0].sub_configs_[0].do_no_cache_ = 1;
|
||||||
|
*crunch_configs_size = 1;
|
||||||
|
// Get the entropy image as small as possible.
|
||||||
|
enc->histo_bits_ = MAX_HUFFMAN_BITS;
|
||||||
|
// The transform image is unused as we are direct.
|
||||||
|
enc->transform_bits_ = MAX_TRANSFORM_BITS;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Empirical bit sizes.
|
// Empirical bit sizes.
|
||||||
enc->histo_bits_ = GetHistoBits(method, use_palette,
|
enc->histo_bits_ = GetHistoBits(method, use_palette,
|
||||||
pic->width, pic->height);
|
pic->width, pic->height);
|
||||||
|
Loading…
Reference in New Issue
Block a user