ifdef code not used by Chrome/Android.

Change-Id: Id086f6fd602b1fe3dc9034764b6a920a696ff1d2
This commit is contained in:
Vincent Rabaud
2017-08-31 14:02:05 +02:00
parent 3993af127e
commit a80fcc4ae1
7 changed files with 68 additions and 3 deletions

View File

@ -26,7 +26,6 @@ static const uint32_t kMaskAlpha = 0xff000000;
// Mostly used to reduce code size + readability
static WEBP_INLINE int GetMin(int a, int b) { return (a > b) ? b : a; }
static WEBP_INLINE int GetMax(int a, int b) { return (a < b) ? b : a; }
//------------------------------------------------------------------------------
// Methods to calculate Entropy (Shannon).
@ -90,6 +89,9 @@ static WEBP_INLINE void PredictBatch(int mode, int x_start, int y,
}
}
#if (WEBP_NEAR_LOSSLESS == 1)
static WEBP_INLINE int GetMax(int a, int b) { return (a < b) ? b : a; }
static int MaxDiffBetweenPixels(uint32_t p1, uint32_t p2) {
const int diff_a = abs((int)(p1 >> 24) - (int)(p2 >> 24));
const int diff_r = abs((int)((p1 >> 16) & 0xff) - (int)((p2 >> 16) & 0xff));
@ -220,6 +222,7 @@ static uint32_t NearLossless(uint32_t value, uint32_t predict,
return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
}
#undef NEAR_LOSSLESS_DIFF
#endif // (WEBP_NEAR_LOSSLESS == 1)
// Stores the difference between the pixel and its prediction in "out".
// In case of a lossy encoding, updates the source image to avoid propagating
@ -246,6 +249,7 @@ static WEBP_INLINE void GetResidual(
} else {
predict = pred_func(current_row[x - 1], upper_row + x);
}
#if (WEBP_NEAR_LOSSLESS == 1)
if (max_quantization == 1 || mode == 0 || y == 0 || y == height - 1 ||
x == 0 || x == width - 1) {
residual = VP8LSubPixels(current_row[x], predict);
@ -256,6 +260,11 @@ static WEBP_INLINE void GetResidual(
current_row[x] = VP8LAddPixels(predict, residual);
// x is never 0 here so we do not need to update upper_row like below.
}
#else
(void)max_quantization;
(void)used_subtract_green;
residual = VP8LSubPixels(current_row[x], predict);
#endif
if ((current_row[x] & kMaskAlpha) == 0) {
// If alpha is 0, cleanup RGB. We can choose the RGB values of the
// residual for best compression. The prediction of alpha itself can be
@ -298,11 +307,12 @@ static int GetBestPredictorForTile(int width, int height,
const int max_x = GetMin(tile_size, width - start_x);
// Whether there exist columns just outside the tile.
const int have_left = (start_x > 0);
const int have_right = (max_x < width - start_x);
// Position and size of the strip covering the tile and adjacent columns if
// they exist.
const int context_start_x = start_x - have_left;
const int context_width = max_x + have_left + have_right;
#if (WEBP_NEAR_LOSSLESS == 1)
const int context_width = max_x + have_left + (max_x < width - start_x);
#endif
const int tiles_per_row = VP8LSubSampleSize(width, bits);
// Prediction modes of the left and above neighbor tiles.
const int left_mode = (tile_x > 0) ?
@ -314,7 +324,9 @@ static int GetBestPredictorForTile(int width, int height,
// when at the right edge.
uint32_t* upper_row = argb_scratch;
uint32_t* current_row = upper_row + width + 1;
#if (WEBP_NEAR_LOSSLESS == 1)
uint8_t* const max_diffs = (uint8_t*)(current_row + width + 1);
#endif
float best_diff = MAX_DIFF_COST;
int best_mode = 0;
int mode;
@ -354,10 +366,12 @@ static int GetBestPredictorForTile(int width, int height,
memcpy(current_row + context_start_x,
argb + y * width + context_start_x,
sizeof(*argb) * (max_x + have_left + (y + 1 < height)));
#if (WEBP_NEAR_LOSSLESS == 1)
if (max_quantization > 1 && y >= 1 && y + 1 < height) {
MaxDiffsForRow(context_width, width, argb + y * width + context_start_x,
max_diffs + context_start_x, used_subtract_green);
}
#endif
GetResidual(width, height, upper_row, current_row, max_diffs, mode,
start_x, start_x + max_x, y, max_quantization, exact,
@ -406,8 +420,10 @@ static void CopyImageWithPrediction(int width, int height,
// when at the right edge.
uint32_t* upper_row = argb_scratch;
uint32_t* current_row = upper_row + width + 1;
#if (WEBP_NEAR_LOSSLESS == 1)
uint8_t* current_max_diffs = (uint8_t*)(current_row + width + 1);
uint8_t* lower_max_diffs = current_max_diffs + width;
#endif
int y;
for (y = 0; y < height; ++y) {
@ -422,6 +438,7 @@ static void CopyImageWithPrediction(int width, int height,
PredictBatch(kPredLowEffort, 0, y, width, current_row, upper_row,
argb + y * width);
} else {
#if (WEBP_NEAR_LOSSLESS == 1)
if (max_quantization > 1) {
// Compute max_diffs for the lower row now, because that needs the
// contents of argb for the current row, which we will overwrite with
@ -434,6 +451,7 @@ static void CopyImageWithPrediction(int width, int height,
used_subtract_green);
}
}
#endif
for (x = 0; x < width;) {
const int mode =
(modes[(y >> bits) * tiles_per_row + (x >> bits)] >> 8) & 0xff;