rescaler: move the 1x1 or 2x1 handling one level up

=> no need to handle it in the sub-functions.

Change-Id: I4b0211ecfafbc9c80a73bf2206809a13c94e7911
This commit is contained in:
Pascal Massimino 2015-09-25 18:49:28 +00:00 committed by James Zern
parent cced974bb2
commit 306ce4fde1
5 changed files with 127 additions and 143 deletions

View File

@ -140,18 +140,13 @@ void WebPRescalerExportRowShrinkC(WebPRescaler* const wrk) {
dst[x_out] = v; dst[x_out] = v;
irow[x_out] = frac; // new fractional start irow[x_out] = frac; // new fractional start
} }
} else if (wrk->fxy_scale) { } else {
for (x_out = 0; x_out < x_out_max; ++x_out) { for (x_out = 0; x_out < x_out_max; ++x_out) {
const int v = (int)MULT_FIX(irow[x_out], wrk->fxy_scale); const int v = (int)MULT_FIX(irow[x_out], wrk->fxy_scale);
assert(v >= 0 && v <= 255); assert(v >= 0 && v <= 255);
dst[x_out] = v; dst[x_out] = v;
irow[x_out] = 0; irow[x_out] = 0;
} }
} else { // very special case for src = dst = 1x1
for (x_out = 0; x_out < x_out_max; ++x_out) {
dst[x_out] = irow[x_out];
irow[x_out] = 0;
}
} }
} }
@ -175,8 +170,16 @@ void WebPRescalerExportRow(WebPRescaler* const wrk) {
assert(!WebPRescalerOutputDone(wrk)); assert(!WebPRescalerOutputDone(wrk));
if (wrk->y_expand) { if (wrk->y_expand) {
WebPRescalerExportRowExpand(wrk); WebPRescalerExportRowExpand(wrk);
} else { } else if (wrk->fxy_scale) {
WebPRescalerExportRowShrink(wrk); WebPRescalerExportRowShrink(wrk);
} else { // very special case for src = dst = 1x1
int i;
assert(wrk->src_width == 1 && wrk->dst_width <= 2);
assert(wrk->src_height == 1 && wrk->dst_height == 1);
for (i = 0; i < wrk->num_channels * wrk->dst_width; ++i) {
wrk->dst[i] = wrk->irow[i];
wrk->irow[i] = 0;
}
} }
wrk->y_accum += wrk->y_add; wrk->y_accum += wrk->y_add;
wrk->dst += wrk->dst_stride; wrk->dst += wrk->dst_stride;

View File

@ -141,16 +141,16 @@ static void ExportRowShrink(WebPRescaler* const wrk) {
const int x_out_max = wrk->dst_width * wrk->num_channels; const int x_out_max = wrk->dst_width * wrk->num_channels;
uint8_t* dst = wrk->dst; uint8_t* dst = wrk->dst;
rescaler_t* irow = wrk->irow; rescaler_t* irow = wrk->irow;
assert(!WebPRescalerOutputDone(wrk));
assert(wrk->y_accum <= 0);
assert(!wrk->y_expand);
if (wrk->fxy_scale != 0) {
const rescaler_t* frow = wrk->frow; const rescaler_t* frow = wrk->frow;
const int yscale = wrk->fy_scale * (-wrk->y_accum); const int yscale = wrk->fy_scale * (-wrk->y_accum);
int temp0, temp1, temp3, temp4, temp5, temp6, temp7, loop_end; int temp0, temp1, temp3, temp4, temp5, temp6, temp7, loop_end;
const int temp2 = (int)(wrk->fxy_scale); const int temp2 = (int)wrk->fxy_scale;
const int temp8 = x_out_max << 2; const int temp8 = x_out_max << 2;
assert(!WebPRescalerOutputDone(wrk));
assert(wrk->y_accum <= 0);
assert(!wrk->y_expand);
assert(wrk->fxy_scale != 0);
__asm__ volatile( __asm__ volatile(
"addiu %[temp6], $zero, -256 \n\t" "addiu %[temp6], $zero, -256 \n\t"
"addiu %[temp7], $zero, 255 \n\t" "addiu %[temp7], $zero, 255 \n\t"
@ -189,13 +189,6 @@ static void ExportRowShrink(WebPRescaler* const wrk) {
: [temp2]"r"(temp2), [yscale]"r"(yscale), [temp8]"r"(temp8) : [temp2]"r"(temp2), [yscale]"r"(yscale), [temp8]"r"(temp8)
: "memory", "hi", "lo" : "memory", "hi", "lo"
); );
} else { // very special case for src = dst = 1x1
int x_out;
for (x_out = 0; x_out < x_out_max; ++x_out) {
dst[x_out] = irow[x_out];
irow[x_out] = 0;
}
}
} }
// no ExportRowExpand yet. // no ExportRowExpand yet.

View File

@ -136,10 +136,6 @@ static void ExportRowShrink(WebPRescaler* const wrk) {
uint8_t* dst = wrk->dst; uint8_t* dst = wrk->dst;
rescaler_t* irow = wrk->irow; rescaler_t* irow = wrk->irow;
const int x_out_max = wrk->dst_width * wrk->num_channels; const int x_out_max = wrk->dst_width * wrk->num_channels;
assert(!WebPRescalerOutputDone(wrk));
assert(wrk->y_accum <= 0);
assert(!wrk->y_expand);
if (wrk->fxy_scale) {
const rescaler_t* frow = wrk->frow; const rescaler_t* frow = wrk->frow;
const int yscale = wrk->fy_scale * (-wrk->y_accum); const int yscale = wrk->fy_scale * (-wrk->y_accum);
@ -148,6 +144,10 @@ static void ExportRowShrink(WebPRescaler* const wrk) {
const int rest = x_out_max & 1; const int rest = x_out_max & 1;
const rescaler_t* const loop_end = frow + x_out_max - rest; const rescaler_t* const loop_end = frow + x_out_max - rest;
assert(!WebPRescalerOutputDone(wrk));
assert(wrk->y_accum <= 0);
assert(!wrk->y_expand);
assert(wrk->fxy_scale);
__asm__ volatile ( __asm__ volatile (
".set push \n\t" ".set push \n\t"
".set noreorder \n\t" ".set noreorder \n\t"
@ -210,13 +210,6 @@ static void ExportRowShrink(WebPRescaler* const wrk) {
[rest]"r"(rest) [rest]"r"(rest)
: "memory", "hi", "lo" : "memory", "hi", "lo"
); );
} else { // very special case for src = dst = 1x1
int x_out;
for (x_out = 0; x_out < x_out_max; ++x_out) {
dst[x_out] = irow[x_out];
irow[x_out] = 0;
}
}
} }
// no ExportRowExpand yet. // no ExportRowExpand yet.

View File

@ -187,7 +187,7 @@ static void RescalerExportRowShrinkSSE2(WebPRescaler* const wrk) {
dst[x_out] = v; dst[x_out] = v;
irow[x_out] = frac; // new fractional start irow[x_out] = frac; // new fractional start
} }
} else if (wrk->fxy_scale) { } else {
const uint32_t scale = wrk->fxy_scale; const uint32_t scale = wrk->fxy_scale;
const __m128i mult = _mm_set_epi32(0, scale, 0, scale); const __m128i mult = _mm_set_epi32(0, scale, 0, scale);
const __m128i zero = _mm_setzero_si128(); const __m128i zero = _mm_setzero_si128();
@ -204,11 +204,6 @@ static void RescalerExportRowShrinkSSE2(WebPRescaler* const wrk) {
dst[x_out] = v; dst[x_out] = v;
irow[x_out] = 0; irow[x_out] = 0;
} }
} else { // very special case for src = 1x1
for (x_out = 0; x_out < x_out_max; ++x_out) {
dst[x_out] = irow[x_out];
irow[x_out] = 0;
}
} }
} }

View File

@ -49,7 +49,7 @@ void WebPRescalerInit(WebPRescaler* const wrk, int src_width, int src_height,
wrk->y_accum = wrk->y_expand ? wrk->y_sub : wrk->y_add; wrk->y_accum = wrk->y_expand ? wrk->y_sub : wrk->y_add;
if (!wrk->y_expand) { if (!wrk->y_expand) {
// note the very special case where x_add = y_add = 1 cannot be represented. // note the very special case where x_add = y_add = 1 cannot be represented.
// We special-case fxy_scale = 0 in this case, in ExportRowShrink // We special-case fxy_scale = 0 in this case, in WebPRescalerExportRow().
wrk->fxy_scale = WEBP_RESCALER_FRAC(dst_height, wrk->x_add * wrk->y_add); wrk->fxy_scale = WEBP_RESCALER_FRAC(dst_height, wrk->x_add * wrk->y_add);
wrk->fy_scale = WEBP_RESCALER_FRAC(1, wrk->y_sub); wrk->fy_scale = WEBP_RESCALER_FRAC(1, wrk->y_sub);
} else { } else {