simplify/reorganize arguments for CollectColorBlueTransforms

and other various call sites too.

Change-Id: Icb8f828dfe25672662de18d0e48e7d3144b1f38d
This commit is contained in:
Pascal Massimino 2015-01-15 07:31:46 -08:00 committed by James Zern
parent b9e356b998
commit 3fd59039bd
3 changed files with 75 additions and 84 deletions

View File

@ -879,15 +879,13 @@ void VP8LResidualImage(int width, int height, int bits, int low_effort,
CopyTileWithPrediction(width, height, tile_x, tile_y, bits, pred, CopyTileWithPrediction(width, height, tile_x, tile_y, bits, pred,
argb_scratch, argb); argb_scratch, argb);
for (y = 0; y < max_tile_size; ++y) { for (y = 0; y < max_tile_size; ++y) {
int ix;
int all_x; int all_x;
int all_y = tile_y_offset + y; int all_y = tile_y_offset + y;
if (all_y >= height) { if (all_y >= height) {
break; break;
} }
ix = all_y * width + tile_x_offset; for (all_x = tile_x_offset; all_x < all_x_max; ++all_x) {
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x, ++ix) { UpdateHisto(histo, argb[all_y * width + all_x]);
UpdateHisto(histo, argb[ix]);
} }
} }
} }
@ -1067,29 +1065,27 @@ static float PredictionCostCrossColor(const int accumulated[256],
PredictionCostSpatial(counts, 3, kExpValue); PredictionCostSpatial(counts, 3, kExpValue);
} }
static void CollectColorRedTransforms( static void CollectColorRedTransforms(const uint32_t* argb, int stride,
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, int tile_width, int tile_height,
int xsize, int green_to_red, int* histo, const uint32_t* const argb) { int green_to_red, int histo[]) {
int all_y; while (tile_height-- > 0) {
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) { int x;
int ix = all_y * xsize + tile_x_offset; for (x = 0; x < tile_width; ++x) {
int all_x; ++histo[TransformColorRed(green_to_red, argb[x])];
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x, ++ix) {
++histo[TransformColorRed(green_to_red, argb[ix])]; // red.
} }
argb += stride;
} }
} }
static float GetPredictionCostCrossColorRed( static float GetPredictionCostCrossColorRed(
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, const uint32_t* argb, int stride, int tile_width, int tile_height,
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y, int green_to_red, VP8LMultipliers prev_x, VP8LMultipliers prev_y, int green_to_red,
const int accumulated_red_histo[256], const uint32_t* const argb) { const int accumulated_red_histo[256]) {
int histo[256] = { 0 }; int histo[256] = { 0 };
float cur_diff; float cur_diff;
VP8LCollectColorRedTransforms(tile_x_offset, tile_y_offset, all_x_max, VP8LCollectColorRedTransforms(argb, stride, tile_width, tile_height,
all_y_max, xsize, green_to_red, green_to_red, histo);
histo, argb);
cur_diff = PredictionCostCrossColor(accumulated_red_histo, histo); cur_diff = PredictionCostCrossColor(accumulated_red_histo, histo);
if ((uint8_t)green_to_red == prev_x.green_to_red_) { if ((uint8_t)green_to_red == prev_x.green_to_red_) {
@ -1105,10 +1101,9 @@ static float GetPredictionCostCrossColorRed(
} }
static void GetBestGreenToRed( static void GetBestGreenToRed(
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, const uint32_t* argb, int stride, int tile_width, int tile_height,
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y, VP8LMultipliers prev_x, VP8LMultipliers prev_y,
const int accumulated_red_histo[256], const uint32_t* const argb, const int accumulated_red_histo[256], VP8LMultipliers* const best_tx) {
VP8LMultipliers* const best_tx) {
int min_green_to_red = -64; int min_green_to_red = -64;
int max_green_to_red = 64; int max_green_to_red = 64;
int green_to_red = 0; int green_to_red = 0;
@ -1120,14 +1115,14 @@ static void GetBestGreenToRed(
while (max_green_to_red - min_green_to_red > 2) { while (max_green_to_red - min_green_to_red > 2) {
if (eval_min) { if (eval_min) {
cur_diff_min = GetPredictionCostCrossColorRed( cur_diff_min = GetPredictionCostCrossColorRed(
tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize, argb, stride, tile_width, tile_height,
prev_x, prev_y, min_green_to_red, accumulated_red_histo, argb); prev_x, prev_y, min_green_to_red, accumulated_red_histo);
eval_min = 0; eval_min = 0;
} }
if (eval_max) { if (eval_max) {
cur_diff_max = GetPredictionCostCrossColorRed( cur_diff_max = GetPredictionCostCrossColorRed(
tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize, argb, stride, tile_width, tile_height,
prev_x, prev_y, max_green_to_red, accumulated_red_histo, argb); prev_x, prev_y, max_green_to_red, accumulated_red_histo);
eval_max = 0; eval_max = 0;
} }
if (cur_diff_min < cur_diff_max) { if (cur_diff_min < cur_diff_max) {
@ -1143,31 +1138,28 @@ static void GetBestGreenToRed(
best_tx->green_to_red_ = green_to_red; best_tx->green_to_red_ = green_to_red;
} }
static void CollectColorBlueTransforms( static void CollectColorBlueTransforms(const uint32_t* argb, int stride,
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, int tile_width, int tile_height,
int xsize, int green_to_blue, int red_to_blue, int* histo, int green_to_blue, int red_to_blue,
const uint32_t* const argb) { int histo[]) {
int all_y; while (tile_height-- > 0) {
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) { int x;
int all_x; for (x = 0; x < tile_width; ++x) {
int ix = all_y * xsize + tile_x_offset; ++histo[TransformColorBlue(green_to_blue, red_to_blue, argb[x])];
for (all_x = tile_x_offset; all_x < all_x_max; ++all_x, ++ix) {
++histo[TransformColorBlue(green_to_blue, red_to_blue, argb[ix])];
} }
argb += stride;
} }
} }
static float GetPredictionCostCrossColorBlue( static float GetPredictionCostCrossColorBlue(
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, const uint32_t* argb, int stride, int tile_width, int tile_height,
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y, VP8LMultipliers prev_x, VP8LMultipliers prev_y,
int green_to_blue, int red_to_blue, const int accumulated_blue_histo[256], int green_to_blue, int red_to_blue, const int accumulated_blue_histo[256]) {
const uint32_t* const argb) {
int histo[256] = { 0 }; int histo[256] = { 0 };
float cur_diff; float cur_diff;
VP8LCollectColorBlueTransforms(tile_x_offset, tile_y_offset, all_x_max, VP8LCollectColorBlueTransforms(argb, stride, tile_width, tile_height,
all_y_max, xsize, green_to_blue, red_to_blue, green_to_blue, red_to_blue, histo);
histo, argb);
cur_diff = PredictionCostCrossColor(accumulated_blue_histo, histo); cur_diff = PredictionCostCrossColor(accumulated_blue_histo, histo);
if ((uint8_t)green_to_blue == prev_x.green_to_blue_) { if ((uint8_t)green_to_blue == prev_x.green_to_blue_) {
@ -1192,9 +1184,9 @@ static float GetPredictionCostCrossColorBlue(
} }
static void GetBestGreenRedToBlue( static void GetBestGreenRedToBlue(
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, const uint32_t* argb, int stride, int tile_width, int tile_height,
int xsize, VP8LMultipliers prev_x, VP8LMultipliers prev_y, int quality, VP8LMultipliers prev_x, VP8LMultipliers prev_y, int quality,
const int accumulated_blue_histo[256], const uint32_t* const argb, const int accumulated_blue_histo[256],
VP8LMultipliers* const best_tx) { VP8LMultipliers* const best_tx) {
float best_diff = MAX_DIFF_COST; float best_diff = MAX_DIFF_COST;
float cur_diff; float cur_diff;
@ -1221,8 +1213,8 @@ static void GetBestGreenRedToBlue(
num_tries_after_min < max_tries_after_min; num_tries_after_min < max_tries_after_min;
red_to_blue += step) { red_to_blue += step) {
cur_diff = GetPredictionCostCrossColorBlue( cur_diff = GetPredictionCostCrossColorBlue(
tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize, prev_x, argb, stride, tile_width, tile_height, prev_x, prev_y,
prev_y, green_to_blue, red_to_blue, accumulated_blue_histo, argb); green_to_blue, red_to_blue, accumulated_blue_histo);
if (cur_diff < best_diff) { if (cur_diff < best_diff) {
best_diff = cur_diff; best_diff = cur_diff;
best_tx->green_to_blue_ = green_to_blue; 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 tile_x_offset = tile_x * max_tile_size;
const int all_x_max = GetMin(tile_x_offset + max_tile_size, xsize); 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 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; VP8LMultipliers best_tx;
MultipliersClear(&best_tx); MultipliersClear(&best_tx);
GetBestGreenToRed(tile_x_offset, tile_y_offset, all_x_max, all_y_max, xsize, GetBestGreenToRed(tile_argb, xsize, tile_width, tile_height,
prev_x, prev_y, accumulated_red_histo, argb, &best_tx); prev_x, prev_y, accumulated_red_histo, &best_tx);
GetBestGreenRedToBlue(tile_x_offset, tile_y_offset, all_x_max, all_y_max, GetBestGreenRedToBlue(tile_argb, xsize, tile_width, tile_height,
xsize, prev_x, prev_y, quality, accumulated_blue_histo, prev_x, prev_y, quality, accumulated_blue_histo,
argb, &best_tx); &best_tx);
return best_tx; return best_tx;
} }

View File

@ -60,14 +60,15 @@ extern VP8LConvertFunc VP8LConvertBGRAToRGB565;
extern VP8LConvertFunc VP8LConvertBGRAToBGR; extern VP8LConvertFunc VP8LConvertBGRAToBGR;
typedef void (*VP8LCollectColorBlueTransformsFunc)( typedef void (*VP8LCollectColorBlueTransformsFunc)(
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, const uint32_t* argb, int stride,
int xsize, int green_to_blue, int red_to_blue, int* histo, int tile_width, int tile_height,
const uint32_t* const argb); int green_to_blue, int red_to_blue, int histo[]);
extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms; extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
typedef void (*VP8LCollectColorRedTransformsFunc)( typedef void (*VP8LCollectColorRedTransformsFunc)(
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, const uint32_t* argb, int stride,
int xsize, int green_to_red, int* histo, const uint32_t* const argb); int tile_width, int tile_height,
int green_to_red, int histo[]);
extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms; extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
// Expose some C-only fallback functions // Expose some C-only fallback functions

View File

@ -378,21 +378,18 @@ static WEBP_INLINE uint8_t TransformColorBlue(uint8_t green_to_blue,
return (new_blue & 0xff); return (new_blue & 0xff);
} }
static void CollectColorBlueTransforms( static void CollectColorBlueTransforms(const uint32_t* argb, int stride,
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, int tile_width, int tile_height,
int xsize, int green_to_blue, int red_to_blue, int* histo, int green_to_blue, int red_to_blue,
const uint32_t* const argb) { int histo[]) {
const int rtb = (red_to_blue << 16) | (red_to_blue & 0xffff); const int rtb = (red_to_blue << 16) | (red_to_blue & 0xffff);
const int gtb = (green_to_blue << 16) | (green_to_blue & 0xffff); const int gtb = (green_to_blue << 16) | (green_to_blue & 0xffff);
const uint32_t mask = 0xff00ffu; const uint32_t mask = 0xff00ffu;
int ix = tile_y_offset * xsize + tile_x_offset; while (tile_height-- > 0) {
int all_y; int x;
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) { const uint32_t* p_argb = argb;
uint32_t* p_argb = (uint32_t*)&argb[ix]; argb += stride;
const int loop_cnt = all_x_max - tile_x_offset; for (x = 0; x < (tile_width >> 1); ++x) {
int all_x;
ix += xsize;
for (all_x = 0; all_x < (loop_cnt >> 1); ++all_x) {
int temp0, temp1, temp2, temp3, temp4, temp5, temp6; int temp0, temp1, temp2, temp3, temp4, temp5, temp6;
__asm__ volatile ( __asm__ volatile (
"lw %[temp0], 0(%[p_argb]) \n\t" "lw %[temp0], 0(%[p_argb]) \n\t"
@ -418,7 +415,7 @@ static void CollectColorBlueTransforms(
++histo[(uint8_t)(temp2 >> 16)]; ++histo[(uint8_t)(temp2 >> 16)];
++histo[(uint8_t)temp2]; ++histo[(uint8_t)temp2];
} }
if (loop_cnt & 1) { if (tile_width & 1) {
++histo[TransformColorBlue(green_to_blue, red_to_blue, *p_argb)]; ++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); return (new_red & 0xff);
} }
static void CollectColorRedTransforms( static void CollectColorRedTransforms(const uint32_t* argb, int stride,
int tile_x_offset, int tile_y_offset, int all_x_max, int all_y_max, int tile_width, int tile_height,
int xsize, int green_to_red, int* histo, const uint32_t* const argb) { int green_to_red, int histo[]) {
const int gtr = (green_to_red << 16) | (green_to_red & 0xffff); const int gtr = (green_to_red << 16) | (green_to_red & 0xffff);
int ix = tile_y_offset * xsize + tile_x_offset; while (tile_height-- > 0) {
int all_y; int x;
for (all_y = tile_y_offset; all_y < all_y_max; ++all_y) { const uint32_t* p_argb = argb;
uint32_t* p_argb = (uint32_t*)&argb[ix]; argb += stride;
const int loop_cnt = all_x_max - tile_x_offset; for (x = 0; x < (tile_width >> 1); ++x) {
int all_x;
ix += xsize;
for (all_x = 0; all_x < (loop_cnt >> 1); ++all_x) {
int temp0, temp1, temp2, temp3, temp4; int temp0, temp1, temp2, temp3, temp4;
__asm__ volatile ( __asm__ volatile (
"lw %[temp0], 0(%[p_argb]) \n\t" "lw %[temp0], 0(%[p_argb]) \n\t"
@ -463,7 +457,7 @@ static void CollectColorRedTransforms(
++histo[(uint8_t)(temp2 >> 16)]; ++histo[(uint8_t)(temp2 >> 16)];
++histo[(uint8_t)temp2]; ++histo[(uint8_t)temp2];
} }
if (loop_cnt & 1) { if (tile_width & 1) {
++histo[TransformColorRed(green_to_red, *p_argb)]; ++histo[TransformColorRed(green_to_red, *p_argb)];
} }
} }