mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
Revert "fix 'unsigned integer overflow' warnings in ubsan"
This reverts commit e44f5248ff
.
contains unintentional changes in quant.c
Change-Id: I1928f072566788b0c9ea80f6fbc9e571061f9b3e
This commit is contained in:
parent
9d4f209f80
commit
8a4ebc6ab0
@ -919,15 +919,14 @@ void VP8LResidualImage(int width, int height, int bits, int low_effort,
|
||||
used_subtract_green);
|
||||
}
|
||||
|
||||
void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* const argb_data,
|
||||
int num_pixels) {
|
||||
void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels) {
|
||||
int i;
|
||||
for (i = 0; i < num_pixels; ++i) {
|
||||
const int argb = argb_data[i];
|
||||
const int green = (argb >> 8) & 0xff;
|
||||
const uint32_t argb = argb_data[i];
|
||||
const uint32_t green = (argb >> 8) & 0xff;
|
||||
const uint32_t new_r = (((argb >> 16) & 0xff) - green) & 0xff;
|
||||
const uint32_t new_b = (((argb >> 0) & 0xff) - green) & 0xff;
|
||||
argb_data[i] = (argb & 0xff00ff00u) | (new_r << 16) | new_b;
|
||||
const uint32_t new_b = ((argb & 0xff) - green) & 0xff;
|
||||
argb_data[i] = (argb & 0xff00ff00) | (new_r << 16) | new_b;
|
||||
}
|
||||
}
|
||||
|
||||
@ -937,9 +936,9 @@ static WEBP_INLINE void MultipliersClear(VP8LMultipliers* const m) {
|
||||
m->red_to_blue_ = 0;
|
||||
}
|
||||
|
||||
static WEBP_INLINE int ColorTransformDelta(int8_t color_pred,
|
||||
int8_t color) {
|
||||
return ((int)(color_pred) * color) >> 5;
|
||||
static WEBP_INLINE uint32_t ColorTransformDelta(int8_t color_pred,
|
||||
int8_t color) {
|
||||
return (uint32_t)((int)(color_pred) * color) >> 5;
|
||||
}
|
||||
|
||||
static WEBP_INLINE void ColorCodeToMultipliers(uint32_t color_code,
|
||||
@ -964,8 +963,8 @@ void VP8LTransformColor_C(const VP8LMultipliers* const m, uint32_t* data,
|
||||
const uint32_t argb = data[i];
|
||||
const uint32_t green = argb >> 8;
|
||||
const uint32_t red = argb >> 16;
|
||||
int new_red = red;
|
||||
int new_blue = argb;
|
||||
uint32_t new_red = red;
|
||||
uint32_t new_blue = argb;
|
||||
new_red -= ColorTransformDelta(m->green_to_red_, green);
|
||||
new_red &= 0xff;
|
||||
new_blue -= ColorTransformDelta(m->green_to_blue_, green);
|
||||
@ -978,7 +977,7 @@ void VP8LTransformColor_C(const VP8LMultipliers* const m, uint32_t* data,
|
||||
static WEBP_INLINE uint8_t TransformColorRed(uint8_t green_to_red,
|
||||
uint32_t argb) {
|
||||
const uint32_t green = argb >> 8;
|
||||
int new_red = argb >> 16;
|
||||
uint32_t new_red = argb >> 16;
|
||||
new_red -= ColorTransformDelta(green_to_red, green);
|
||||
return (new_red & 0xff);
|
||||
}
|
||||
|
@ -211,13 +211,13 @@ void VP8LHashChainClear(VP8LHashChain* const p) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define HASH_MULTIPLIER_HI (0xc6a4a793ULL)
|
||||
#define HASH_MULTIPLIER_LO (0x5bd1e996ULL)
|
||||
#define HASH_MULTIPLIER_HI (0xc6a4a793U)
|
||||
#define HASH_MULTIPLIER_LO (0x5bd1e996U)
|
||||
|
||||
static WEBP_INLINE uint32_t GetPixPairHash64(const uint32_t* const argb) {
|
||||
uint32_t key;
|
||||
key = (argb[1] * HASH_MULTIPLIER_HI) & 0xffffffffu;
|
||||
key += (argb[0] * HASH_MULTIPLIER_LO) & 0xffffffffu;
|
||||
key = argb[1] * HASH_MULTIPLIER_HI;
|
||||
key += argb[0] * HASH_MULTIPLIER_LO;
|
||||
key = key >> (32 - HASH_BITS);
|
||||
return key;
|
||||
}
|
||||
|
@ -1004,7 +1004,7 @@ static int PickBestIntra4(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
||||
|
||||
InitScore(&rd_i4);
|
||||
VP8MakeIntra4Preds(it);
|
||||
for (mode = 0; mode < 2 /*NUM_BMODES*/; ++mode) {
|
||||
for (mode = 0; mode < NUM_BMODES; ++mode) {
|
||||
VP8ModeScore rd_tmp;
|
||||
int16_t tmp_levels[16];
|
||||
|
||||
|
@ -163,25 +163,18 @@ typedef enum {
|
||||
kHistoTotal // Must be last.
|
||||
} HistoIx;
|
||||
|
||||
static void AddSingleSubGreen(int p, uint32_t* const r, uint32_t* const b) {
|
||||
const int green = p >> 8; // The upper bits are masked away later.
|
||||
static void AddSingleSubGreen(uint32_t p, uint32_t* r, uint32_t* b) {
|
||||
const uint32_t green = p >> 8; // The upper bits are masked away later.
|
||||
++r[((p >> 16) - green) & 0xff];
|
||||
++b[((p >> 0) - green) & 0xff];
|
||||
++b[(p - green) & 0xff];
|
||||
}
|
||||
|
||||
static void AddSingle(uint32_t p,
|
||||
uint32_t* const a, uint32_t* const r,
|
||||
uint32_t* const g, uint32_t* const b) {
|
||||
++a[(p >> 24) & 0xff];
|
||||
uint32_t* a, uint32_t* r, uint32_t* g, uint32_t* b) {
|
||||
++a[p >> 24];
|
||||
++r[(p >> 16) & 0xff];
|
||||
++g[(p >> 8) & 0xff];
|
||||
++b[(p >> 0) & 0xff];
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t HashPix(uint32_t pix) {
|
||||
// Note that masking with 0xffffffffu is for preventing an
|
||||
// 'unsigned int overflow' warning. Doesn't impact the compiled code.
|
||||
return (((pix + (pix >> 19)) * 0x39c5fba7ull) & 0xffffffffu) >> 24;
|
||||
++g[(p >> 8) & 0xff];
|
||||
++b[(p & 0xff)];
|
||||
}
|
||||
|
||||
static int AnalyzeEntropy(const uint32_t* argb,
|
||||
@ -221,8 +214,8 @@ static int AnalyzeEntropy(const uint32_t* argb,
|
||||
&histo[kHistoBluePredSubGreen * 256]);
|
||||
{
|
||||
// Approximate the palette by the entropy of the multiplicative hash.
|
||||
const uint32_t hash = HashPix(pix);
|
||||
++histo[kHistoPalette * 256 + hash];
|
||||
const int hash = ((pix + (pix >> 19)) * 0x39c5fba7) >> 24;
|
||||
++histo[kHistoPalette * 256 + (hash & 0xff)];
|
||||
}
|
||||
}
|
||||
prev_row = curr_row;
|
||||
|
@ -149,8 +149,7 @@ static WEBP_INLINE int VP8GetBit(VP8BitReader* const br, int prob) {
|
||||
}
|
||||
|
||||
// simplified version of VP8GetBit() for prob=0x80 (note shift is always 1 here)
|
||||
static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW
|
||||
WEBP_INLINE int VP8GetSigned(VP8BitReader* const br, int v) {
|
||||
static WEBP_INLINE int VP8GetSigned(VP8BitReader* const br, int v) {
|
||||
if (br->bits_ < 0) {
|
||||
VP8LoadNewBytes(br);
|
||||
}
|
||||
|
@ -28,11 +28,7 @@ typedef struct {
|
||||
int hash_bits_;
|
||||
} VP8LColorCache;
|
||||
|
||||
static const uint64_t kHashMul = 0x1e35a7bdull;
|
||||
|
||||
static WEBP_INLINE int HashPix(uint32_t argb, int shift) {
|
||||
return (int)(((argb * kHashMul) & 0xffffffffu) >> shift);
|
||||
}
|
||||
static const uint32_t kHashMul = 0x1e35a7bd;
|
||||
|
||||
static WEBP_INLINE uint32_t VP8LColorCacheLookup(
|
||||
const VP8LColorCache* const cc, uint32_t key) {
|
||||
@ -48,20 +44,20 @@ static WEBP_INLINE void VP8LColorCacheSet(const VP8LColorCache* const cc,
|
||||
|
||||
static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc,
|
||||
uint32_t argb) {
|
||||
const int key = HashPix(argb, cc->hash_shift_);
|
||||
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
|
||||
cc->colors_[key] = argb;
|
||||
}
|
||||
|
||||
static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
|
||||
uint32_t argb) {
|
||||
return HashPix(argb, cc->hash_shift_);
|
||||
return (kHashMul * argb) >> cc->hash_shift_;
|
||||
}
|
||||
|
||||
// Return the key if cc contains argb, and -1 otherwise.
|
||||
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
|
||||
uint32_t argb) {
|
||||
const int key = HashPix(argb, cc->hash_shift_);
|
||||
return (cc->colors_[key] == argb) ? key : -1;
|
||||
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
|
||||
return (cc->colors_[key] == argb) ? (int)key : -1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -248,7 +248,7 @@ int WebPGetColorPalette(const WebPPicture* const pic, uint32_t* const palette) {
|
||||
int num_colors = 0;
|
||||
uint8_t in_use[COLOR_HASH_SIZE] = { 0 };
|
||||
uint32_t colors[COLOR_HASH_SIZE];
|
||||
static const uint64_t kHashMul = 0x1e35a7bdull;
|
||||
static const uint32_t kHashMul = 0x1e35a7bdU;
|
||||
const uint32_t* argb = pic->argb;
|
||||
const int width = pic->width;
|
||||
const int height = pic->height;
|
||||
@ -263,7 +263,7 @@ int WebPGetColorPalette(const WebPPicture* const pic, uint32_t* const palette) {
|
||||
continue;
|
||||
}
|
||||
last_pix = argb[x];
|
||||
key = ((last_pix * kHashMul) & 0xffffffffu) >> COLOR_HASH_RIGHT_SHIFT;
|
||||
key = (kHashMul * last_pix) >> COLOR_HASH_RIGHT_SHIFT;
|
||||
while (1) {
|
||||
if (!in_use[key]) {
|
||||
colors[key] = last_pix;
|
||||
|
Loading…
Reference in New Issue
Block a user