mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
Fix CopyTileWithPrediction()
so that it uses original values of left, top etc for prediction rather than the predicted values of the same. Also, do some renaming in the same to make it more readable. Change-Id: I2fe94e35a6700bd437f5c601e2af12323bf32445
This commit is contained in:
@ -398,44 +398,55 @@ static int GetBestPredictorForTile(int tile_x, int tile_y, int max_tile_size,
|
||||
return best_mode;
|
||||
}
|
||||
|
||||
static void CopyTileWithPrediction(int xsize, int ysize,
|
||||
static void CopyTileWithPrediction(int width, int height,
|
||||
int tile_x, int tile_y, int bits, int mode,
|
||||
uint32_t* const argb_scratch,
|
||||
uint32_t* const argb) {
|
||||
int ymax = 1 << bits;
|
||||
int xmax = 1 << bits;
|
||||
int y;
|
||||
const int col_start = tile_x << bits;
|
||||
const int row_start = tile_y << bits;
|
||||
const int transform_size = 1 << bits;
|
||||
const int ymax = (transform_size <= height - row_start) ?
|
||||
transform_size : height - row_start;
|
||||
const int xmax = (transform_size <= width - col_start) ?
|
||||
transform_size : width - col_start;
|
||||
const PredictorFunc pred_func = kPredictors[mode];
|
||||
if (ymax > ysize - (tile_y << bits)) {
|
||||
ymax = ysize - (tile_y << bits);
|
||||
}
|
||||
if (xmax > xsize - (tile_x << bits)) {
|
||||
xmax = xsize - (tile_x << bits);
|
||||
}
|
||||
uint32_t* const top_row = argb_scratch;
|
||||
uint32_t* const current_row = argb_scratch + width;
|
||||
|
||||
int y;
|
||||
for (y = 0; y < ymax; ++y) {
|
||||
const int all_y = (tile_y << bits) + y;
|
||||
int x;
|
||||
const int row = row_start + y;
|
||||
// Update current_row & top_row.
|
||||
if (row > 0) {
|
||||
memcpy(top_row, current_row, width * sizeof(*top_row));
|
||||
}
|
||||
memcpy(current_row, &argb[row * width], width * sizeof(*current_row));
|
||||
for (x = 0; x < xmax; ++x) {
|
||||
const int all_x = (tile_x << bits) + x;
|
||||
const int ix = all_y * xsize + all_x;
|
||||
const int col = col_start + x;
|
||||
const int pix = row * width + col;
|
||||
uint32_t predict;
|
||||
if (all_y == 0) {
|
||||
if (all_x == 0) {
|
||||
if (row == 0) {
|
||||
if (col == 0) {
|
||||
predict = ARGB_BLACK;
|
||||
} else {
|
||||
predict = argb[ix - 1];
|
||||
const uint32_t left = current_row[col - 1];
|
||||
predict = left;
|
||||
}
|
||||
} else if (all_x == 0) {
|
||||
predict = argb[ix - xsize];
|
||||
} else if (col == 0) {
|
||||
const uint32_t top = top_row[col];
|
||||
predict = top;
|
||||
} else {
|
||||
predict = pred_func(argb + ix, argb + ix - xsize);
|
||||
predict = pred_func(argb + pix, top_row + col);
|
||||
}
|
||||
argb[ix] = VP8LSubPixels(argb[ix], predict);
|
||||
argb[pix] = VP8LSubPixels(argb[pix], predict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VP8LResidualImage(int width, int height, int bits,
|
||||
uint32_t* const argb, uint32_t* const image) {
|
||||
uint32_t* const argb, uint32_t* const argb_scratch,
|
||||
uint32_t* const image) {
|
||||
const int max_tile_size = 1 << bits;
|
||||
const int tile_xsize = VP8LSubSampleSize(width, bits);
|
||||
const int tile_ysize = VP8LSubSampleSize(height, bits);
|
||||
@ -456,7 +467,8 @@ void VP8LResidualImage(int width, int height, int bits,
|
||||
pred = GetBestPredictorForTile(tile_x, tile_y, max_tile_size,
|
||||
width, height, histo, argb);
|
||||
image[tile_y * tile_xsize + tile_x] = 0xff000000u | (pred << 8);
|
||||
CopyTileWithPrediction(width, height, tile_x, tile_y, bits, pred, argb);
|
||||
CopyTileWithPrediction(width, height, tile_x, tile_y, bits, pred,
|
||||
argb_scratch, argb);
|
||||
for (y = 0; y < max_tile_size; ++y) {
|
||||
int ix;
|
||||
int all_x;
|
||||
|
@ -38,7 +38,8 @@ void VP8LInverseTransform(const struct VP8LTransform* const transform,
|
||||
void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs);
|
||||
|
||||
void VP8LResidualImage(int width, int height, int bits,
|
||||
uint32_t* const argb, uint32_t* const image);
|
||||
uint32_t* const argb, uint32_t* const argb_scratch,
|
||||
uint32_t* const image);
|
||||
|
||||
void VP8LColorSpaceTransform(int width, int height, int bits, int step,
|
||||
uint32_t* const argb, uint32_t* image);
|
||||
@ -67,8 +68,10 @@ double VP8LFastLog(int v);
|
||||
|
||||
// In-place difference of each component with mod 256.
|
||||
static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
|
||||
const uint32_t alpha_and_green = (a & 0xff00ff00u) - (b & 0xff00ff00u);
|
||||
const uint32_t red_and_blue = (a & 0x00ff00ffu) - (b & 0x00ff00ffu);
|
||||
const uint32_t alpha_and_green =
|
||||
0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u);
|
||||
const uint32_t red_and_blue =
|
||||
0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu);
|
||||
return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user