mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
simplify/reorganize arguments for CollectColorBlueTransforms
and other various call sites too. Change-Id: Icb8f828dfe25672662de18d0e48e7d3144b1f38d
This commit is contained in:
parent
b9e356b998
commit
3fd59039bd
@ -879,15 +879,13 @@ void VP8LResidualImage(int width, int height, int bits, int low_effort,
|
||||
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;
|
||||
int all_y = tile_y_offset + y;
|
||||
if (all_y >= height) {
|
||||
break;
|
||||
}
|
||||
ix = all_y * width + tile_x_offset;
|
||||
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x, ++ix) {
|
||||
UpdateHisto(histo, argb[ix]);
|
||||
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x) {
|
||||
UpdateHisto(histo, argb[all_y * width + all_x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1067,29 +1065,27 @@ static float PredictionCostCrossColor(const int accumulated[256],
|
||||
PredictionCostSpatial(counts, 3, kExpValue);
|
||||
}
|
||||
|
||||
static void CollectColorRedTransforms(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, int green_to_red, int* histo, const uint32_t* const argb) {
|
||||
int all_y;
|
||||
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) {
|
||||
int ix = all_y * xsize + tile_x_offset;
|
||||
int all_x;
|
||||
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x, ++ix) {
|
||||
++histo[TransformColorRed(green_to_red, argb[ix])]; // red.
|
||||
static void CollectColorRedTransforms(const uint32_t* argb, int stride,
|
||||
int tile_width, int tile_height,
|
||||
int green_to_red, int histo[]) {
|
||||
while (tile_height-- > 0) {
|
||||
int x;
|
||||
for (x = 0; x < tile_width; ++x) {
|
||||
++histo[TransformColorRed(green_to_red, argb[x])];
|
||||
}
|
||||
argb += stride;
|
||||
}
|
||||
}
|
||||
|
||||
static float GetPredictionCostCrossColorRed(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y, int green_to_red,
|
||||
const int accumulated_red_histo[256], const uint32_t* const argb) {
|
||||
const uint32_t* argb, int stride, int tile_width, int tile_height,
|
||||
VP8LMultipliers prev_x, VP8LMultipliers prev_y, int green_to_red,
|
||||
const int accumulated_red_histo[256]) {
|
||||
int histo[256] = { 0 };
|
||||
float cur_diff;
|
||||
|
||||
VP8LCollectColorRedTransforms(tile_x_offset, tile_y_offset, all_x_max,
|
||||
all_y_max, xsize, green_to_red,
|
||||
histo, argb);
|
||||
VP8LCollectColorRedTransforms(argb, stride, tile_width, tile_height,
|
||||
green_to_red, histo);
|
||||
|
||||
cur_diff = PredictionCostCrossColor(accumulated_red_histo, histo);
|
||||
if ((uint8_t)green_to_red == prev_x.green_to_red_) {
|
||||
@ -1105,10 +1101,9 @@ static float GetPredictionCostCrossColorRed(
|
||||
}
|
||||
|
||||
static void GetBestGreenToRed(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y,
|
||||
const int accumulated_red_histo[256], const uint32_t* const argb,
|
||||
VP8LMultipliers* const best_tx) {
|
||||
const uint32_t* argb, int stride, int tile_width, int tile_height,
|
||||
VP8LMultipliers prev_x, VP8LMultipliers prev_y,
|
||||
const int accumulated_red_histo[256], VP8LMultipliers* const best_tx) {
|
||||
int min_green_to_red = -64;
|
||||
int max_green_to_red = 64;
|
||||
int green_to_red = 0;
|
||||
@ -1120,14 +1115,14 @@ static void GetBestGreenToRed(
|
||||
while (max_green_to_red - min_green_to_red > 2) {
|
||||
if (eval_min) {
|
||||
cur_diff_min = GetPredictionCostCrossColorRed(
|
||||
tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize,
|
||||
prev_x, prev_y, min_green_to_red, accumulated_red_histo, argb);
|
||||
argb, stride, tile_width, tile_height,
|
||||
prev_x, prev_y, min_green_to_red, accumulated_red_histo);
|
||||
eval_min = 0;
|
||||
}
|
||||
if (eval_max) {
|
||||
cur_diff_max = GetPredictionCostCrossColorRed(
|
||||
tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize,
|
||||
prev_x, prev_y, max_green_to_red, accumulated_red_histo, argb);
|
||||
argb, stride, tile_width, tile_height,
|
||||
prev_x, prev_y, max_green_to_red, accumulated_red_histo);
|
||||
eval_max = 0;
|
||||
}
|
||||
if (cur_diff_min < cur_diff_max) {
|
||||
@ -1143,31 +1138,28 @@ static void GetBestGreenToRed(
|
||||
best_tx->green_to_red_ = green_to_red;
|
||||
}
|
||||
|
||||
static void CollectColorBlueTransforms(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, int green_to_blue, int red_to_blue, int* histo,
|
||||
const uint32_t* const argb) {
|
||||
int all_y;
|
||||
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) {
|
||||
int all_x;
|
||||
int ix = all_y * xsize + tile_x_offset;
|
||||
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x, ++ix) {
|
||||
++histo[TransformColorBlue(green_to_blue, red_to_blue, argb[ix])];
|
||||
static void CollectColorBlueTransforms(const uint32_t* argb, int stride,
|
||||
int tile_width, int tile_height,
|
||||
int green_to_blue, int red_to_blue,
|
||||
int histo[]) {
|
||||
while (tile_height-- > 0) {
|
||||
int x;
|
||||
for (x = 0; x < tile_width; ++x) {
|
||||
++histo[TransformColorBlue(green_to_blue, red_to_blue, argb[x])];
|
||||
}
|
||||
argb += stride;
|
||||
}
|
||||
}
|
||||
|
||||
static float GetPredictionCostCrossColorBlue(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y,
|
||||
int green_to_blue, int red_to_blue, const int accumulated_blue_histo[256],
|
||||
const uint32_t* const argb) {
|
||||
const uint32_t* argb, int stride, int tile_width, int tile_height,
|
||||
VP8LMultipliers prev_x, VP8LMultipliers prev_y,
|
||||
int green_to_blue, int red_to_blue, const int accumulated_blue_histo[256]) {
|
||||
int histo[256] = { 0 };
|
||||
float cur_diff;
|
||||
|
||||
VP8LCollectColorBlueTransforms(tile_x_offset, tile_y_offset, all_x_max,
|
||||
all_y_max, xsize, green_to_blue, red_to_blue,
|
||||
histo, argb);
|
||||
VP8LCollectColorBlueTransforms(argb, stride, tile_width, tile_height,
|
||||
green_to_blue, red_to_blue, histo);
|
||||
|
||||
cur_diff = PredictionCostCrossColor(accumulated_blue_histo, histo);
|
||||
if ((uint8_t)green_to_blue == prev_x.green_to_blue_) {
|
||||
@ -1192,9 +1184,9 @@ static float GetPredictionCostCrossColorBlue(
|
||||
}
|
||||
|
||||
static void GetBestGreenRedToBlue(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y, int quality,
|
||||
const int accumulated_blue_histo[256], const uint32_t* const argb,
|
||||
const uint32_t* argb, int stride, int tile_width, int tile_height,
|
||||
VP8LMultipliers prev_x, VP8LMultipliers prev_y, int quality,
|
||||
const int accumulated_blue_histo[256],
|
||||
VP8LMultipliers* const best_tx) {
|
||||
float best_diff = MAX_DIFF_COST;
|
||||
float cur_diff;
|
||||
@ -1221,8 +1213,8 @@ static void GetBestGreenRedToBlue(
|
||||
num_tries_after_min < max_tries_after_min;
|
||||
red_to_blue += step) {
|
||||
cur_diff = GetPredictionCostCrossColorBlue(
|
||||
tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize, prev_x,
|
||||
prev_y, green_to_blue, red_to_blue, accumulated_blue_histo, argb);
|
||||
argb, stride, tile_width, tile_height, prev_x, prev_y,
|
||||
green_to_blue, red_to_blue, accumulated_blue_histo);
|
||||
if (cur_diff < best_diff) {
|
||||
best_diff = cur_diff;
|
||||
best_tx->green_to_blue_ = green_to_blue;
|
||||
@ -1248,14 +1240,18 @@ static VP8LMultipliers GetBestColorTransformForTile(
|
||||
const int tile_x_offset = tile_x * max_tile_size;
|
||||
const int all_x_max = GetMin(tile_x_offset + max_tile_size, xsize);
|
||||
const int all_y_max = GetMin(tile_y_offset + max_tile_size, ysize);
|
||||
const int tile_width = all_x_max - tile_x_offset;
|
||||
const int tile_height = all_y_max - tile_y_offset;
|
||||
const uint32_t* const tile_argb = argb + tile_y_offset * xsize
|
||||
+ tile_x_offset;
|
||||
VP8LMultipliers best_tx;
|
||||
MultipliersClear(&best_tx);
|
||||
|
||||
GetBestGreenToRed(tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize,
|
||||
prev_x, prev_y, accumulated_red_histo, argb, &best_tx);
|
||||
GetBestGreenRedToBlue(tile_x_offset, tile_y_offset, all_x_max, all_y_max,
|
||||
xsize, prev_x, prev_y, quality, accumulated_blue_histo,
|
||||
argb, &best_tx);
|
||||
GetBestGreenToRed(tile_argb, xsize, tile_width, tile_height,
|
||||
prev_x, prev_y, accumulated_red_histo, &best_tx);
|
||||
GetBestGreenRedToBlue(tile_argb, xsize, tile_width, tile_height,
|
||||
prev_x, prev_y, quality, accumulated_blue_histo,
|
||||
&best_tx);
|
||||
return best_tx;
|
||||
}
|
||||
|
||||
|
@ -60,14 +60,15 @@ extern VP8LConvertFunc VP8LConvertBGRAToRGB565;
|
||||
extern VP8LConvertFunc VP8LConvertBGRAToBGR;
|
||||
|
||||
typedef void (*VP8LCollectColorBlueTransformsFunc)(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, int green_to_blue, int red_to_blue, int* histo,
|
||||
const uint32_t* const argb);
|
||||
const uint32_t* argb, int stride,
|
||||
int tile_width, int tile_height,
|
||||
int green_to_blue, int red_to_blue, int histo[]);
|
||||
extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
|
||||
|
||||
typedef void (*VP8LCollectColorRedTransformsFunc)(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, int green_to_red, int* histo, const uint32_t* const argb);
|
||||
const uint32_t* argb, int stride,
|
||||
int tile_width, int tile_height,
|
||||
int green_to_red, int histo[]);
|
||||
extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
|
||||
|
||||
// Expose some C-only fallback functions
|
||||
|
@ -378,21 +378,18 @@ static WEBP_INLINE uint8_t TransformColorBlue(uint8_t green_to_blue,
|
||||
return (new_blue & 0xff);
|
||||
}
|
||||
|
||||
static void CollectColorBlueTransforms(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, int green_to_blue, int red_to_blue, int* histo,
|
||||
const uint32_t* const argb) {
|
||||
static void CollectColorBlueTransforms(const uint32_t* argb, int stride,
|
||||
int tile_width, int tile_height,
|
||||
int green_to_blue, int red_to_blue,
|
||||
int histo[]) {
|
||||
const int rtb = (red_to_blue << 16) | (red_to_blue & 0xffff);
|
||||
const int gtb = (green_to_blue << 16) | (green_to_blue & 0xffff);
|
||||
const uint32_t mask = 0xff00ffu;
|
||||
int ix = tile_y_offset * xsize + tile_x_offset;
|
||||
int all_y;
|
||||
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) {
|
||||
uint32_t* p_argb = (uint32_t*)&argb[ix];
|
||||
const int loop_cnt = all_x_max - tile_x_offset;
|
||||
int all_x;
|
||||
ix += xsize;
|
||||
for (all_x = 0; all_x < (loop_cnt >> 1); ++all_x) {
|
||||
while (tile_height-- > 0) {
|
||||
int x;
|
||||
const uint32_t* p_argb = argb;
|
||||
argb += stride;
|
||||
for (x = 0; x < (tile_width >> 1); ++x) {
|
||||
int temp0, temp1, temp2, temp3, temp4, temp5, temp6;
|
||||
__asm__ volatile (
|
||||
"lw %[temp0], 0(%[p_argb]) \n\t"
|
||||
@ -418,7 +415,7 @@ static void CollectColorBlueTransforms(
|
||||
++histo[(uint8_t)(temp2 >> 16)];
|
||||
++histo[(uint8_t)temp2];
|
||||
}
|
||||
if (loop_cnt & 1) {
|
||||
if (tile_width & 1) {
|
||||
++histo[TransformColorBlue(green_to_blue, red_to_blue, *p_argb)];
|
||||
}
|
||||
}
|
||||
@ -432,18 +429,15 @@ static WEBP_INLINE uint8_t TransformColorRed(uint8_t green_to_red,
|
||||
return (new_red & 0xff);
|
||||
}
|
||||
|
||||
static void CollectColorRedTransforms(
|
||||
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max,
|
||||
int xsize, int green_to_red, int* histo, const uint32_t* const argb) {
|
||||
static void CollectColorRedTransforms(const uint32_t* argb, int stride,
|
||||
int tile_width, int tile_height,
|
||||
int green_to_red, int histo[]) {
|
||||
const int gtr = (green_to_red << 16) | (green_to_red & 0xffff);
|
||||
int ix = tile_y_offset * xsize + tile_x_offset;
|
||||
int all_y;
|
||||
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) {
|
||||
uint32_t* p_argb = (uint32_t*)&argb[ix];
|
||||
const int loop_cnt = all_x_max - tile_x_offset;
|
||||
int all_x;
|
||||
ix += xsize;
|
||||
for (all_x = 0; all_x < (loop_cnt >> 1); ++all_x) {
|
||||
while (tile_height-- > 0) {
|
||||
int x;
|
||||
const uint32_t* p_argb = argb;
|
||||
argb += stride;
|
||||
for (x = 0; x < (tile_width >> 1); ++x) {
|
||||
int temp0, temp1, temp2, temp3, temp4;
|
||||
__asm__ volatile (
|
||||
"lw %[temp0], 0(%[p_argb]) \n\t"
|
||||
@ -463,7 +457,7 @@ static void CollectColorRedTransforms(
|
||||
++histo[(uint8_t)(temp2 >> 16)];
|
||||
++histo[(uint8_t)temp2];
|
||||
}
|
||||
if (loop_cnt & 1) {
|
||||
if (tile_width & 1) {
|
||||
++histo[TransformColorRed(green_to_red, *p_argb)];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user