mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
rescaler: simplify ImportRow logic
incorporates the loop over 'channel' and removes one parameter Change-Id: I4e3b33c111ca825fe96461583420413b17326409
This commit is contained in:
parent
5ff0079ece
commit
9ba1894b9b
@ -338,8 +338,7 @@ struct WebPRescaler;
|
|||||||
// 'channel' denotes the channel number to be imported. 'Expand' corresponds to
|
// 'channel' denotes the channel number to be imported. 'Expand' corresponds to
|
||||||
// the wrk->x_expand case. Otherwise, 'Shrink' is to be used.
|
// the wrk->x_expand case. Otherwise, 'Shrink' is to be used.
|
||||||
typedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk,
|
typedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk,
|
||||||
const uint8_t* const src,
|
const uint8_t* src);
|
||||||
int channel);
|
|
||||||
|
|
||||||
extern WebPRescalerImportRowFunc WebPRescalerImportRowExpand;
|
extern WebPRescalerImportRowFunc WebPRescalerImportRowExpand;
|
||||||
extern WebPRescalerImportRowFunc WebPRescalerImportRowShrink;
|
extern WebPRescalerImportRowFunc WebPRescalerImportRowShrink;
|
||||||
@ -353,15 +352,15 @@ extern WebPRescalerExportRowFunc WebPRescalerExportRowShrink;
|
|||||||
|
|
||||||
// Plain-C implementation, as fall-back.
|
// Plain-C implementation, as fall-back.
|
||||||
extern void WebPRescalerImportRowExpandC(struct WebPRescaler* const wrk,
|
extern void WebPRescalerImportRowExpandC(struct WebPRescaler* const wrk,
|
||||||
const uint8_t* const src, int channel);
|
const uint8_t* src);
|
||||||
extern void WebPRescalerImportRowShrinkC(struct WebPRescaler* const wrk,
|
extern void WebPRescalerImportRowShrinkC(struct WebPRescaler* const wrk,
|
||||||
const uint8_t* const src, int channel);
|
const uint8_t* src);
|
||||||
extern void WebPRescalerExportRowExpandC(struct WebPRescaler* const wrk);
|
extern void WebPRescalerExportRowExpandC(struct WebPRescaler* const wrk);
|
||||||
extern void WebPRescalerExportRowShrinkC(struct WebPRescaler* const wrk);
|
extern void WebPRescalerExportRowShrinkC(struct WebPRescaler* const wrk);
|
||||||
|
|
||||||
// Main entry calls:
|
// Main entry calls:
|
||||||
extern void WebPRescalerImportRow(struct WebPRescaler* const wrk,
|
extern void WebPRescalerImportRow(struct WebPRescaler* const wrk,
|
||||||
const uint8_t* const src, int channel);
|
const uint8_t* src);
|
||||||
// Export one row (starting at x_out position) from rescaler.
|
// Export one row (starting at x_out position) from rescaler.
|
||||||
extern void WebPRescalerExportRow(struct WebPRescaler* const wrk);
|
extern void WebPRescalerExportRow(struct WebPRescaler* const wrk);
|
||||||
|
|
||||||
|
@ -23,21 +23,20 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Row import
|
// Row import
|
||||||
|
|
||||||
void WebPRescalerImportRowExpandC(WebPRescaler* const wrk,
|
void WebPRescalerImportRowExpandC(WebPRescaler* wrk, const uint8_t* src) {
|
||||||
const uint8_t* const src, int channel) {
|
|
||||||
const int x_stride = wrk->num_channels;
|
const int x_stride = wrk->num_channels;
|
||||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||||
|
int channel;
|
||||||
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
|
assert(wrk->x_expand);
|
||||||
|
for (channel = 0; channel < x_stride; ++channel) {
|
||||||
int x_in = channel;
|
int x_in = channel;
|
||||||
int x_out;
|
int x_out = channel;
|
||||||
// simple bilinear interpolation
|
// simple bilinear interpolation
|
||||||
int accum = wrk->x_add;
|
int accum = wrk->x_add;
|
||||||
int left = src[x_in];
|
int left = src[x_in];
|
||||||
int right = (wrk->src_width > 1) ? src[x_in + x_stride] : left;
|
int right = (wrk->src_width > 1) ? src[x_in + x_stride] : left;
|
||||||
x_in += x_stride;
|
x_in += x_stride;
|
||||||
x_out = channel;
|
|
||||||
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
|
||||||
assert(wrk->x_expand);
|
|
||||||
while (1) {
|
while (1) {
|
||||||
wrk->frow[x_out] = right * wrk->x_add + (left - right) * accum;
|
wrk->frow[x_out] = right * wrk->x_add + (left - right) * accum;
|
||||||
x_out += x_stride;
|
x_out += x_stride;
|
||||||
@ -53,19 +52,21 @@ void WebPRescalerImportRowExpandC(WebPRescaler* const wrk,
|
|||||||
}
|
}
|
||||||
assert(wrk->x_sub == 0 /* <- special case for src_width=1 */ || accum == 0);
|
assert(wrk->x_sub == 0 /* <- special case for src_width=1 */ || accum == 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebPRescalerImportRowShrinkC(WebPRescaler* const wrk,
|
void WebPRescalerImportRowShrinkC(WebPRescaler* const wrk,
|
||||||
const uint8_t* const src, int channel) {
|
const uint8_t* src) {
|
||||||
const int x_stride = wrk->num_channels;
|
const int x_stride = wrk->num_channels;
|
||||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||||
int x_in = channel;
|
int channel;
|
||||||
int x_out;
|
|
||||||
uint32_t sum = 0;
|
|
||||||
int accum = 0;
|
|
||||||
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
assert(!wrk->x_expand);
|
assert(!wrk->x_expand);
|
||||||
for (x_out = channel; x_out < x_out_max; x_out += x_stride) {
|
for (channel = 0; channel < x_stride; ++channel) {
|
||||||
|
int x_in = channel;
|
||||||
|
int x_out = channel;
|
||||||
|
uint32_t sum = 0;
|
||||||
|
int accum = 0;
|
||||||
|
while (x_out < x_out_max) {
|
||||||
uint32_t base = 0;
|
uint32_t base = 0;
|
||||||
accum += wrk->x_add;
|
accum += wrk->x_add;
|
||||||
while (accum > 0) {
|
while (accum > 0) {
|
||||||
@ -81,9 +82,11 @@ void WebPRescalerImportRowShrinkC(WebPRescaler* const wrk,
|
|||||||
// fresh fractional start for next pixel
|
// fresh fractional start for next pixel
|
||||||
sum = (int)MULT_FIX(frac, wrk->fx_scale);
|
sum = (int)MULT_FIX(frac, wrk->fx_scale);
|
||||||
}
|
}
|
||||||
|
x_out += x_stride;
|
||||||
}
|
}
|
||||||
assert(accum == 0);
|
assert(accum == 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Row export
|
// Row export
|
||||||
@ -145,13 +148,12 @@ void WebPRescalerExportRowShrinkC(WebPRescaler* const wrk) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Main entry calls
|
// Main entry calls
|
||||||
|
|
||||||
void WebPRescalerImportRow(WebPRescaler* const wrk,
|
void WebPRescalerImportRow(WebPRescaler* const wrk, const uint8_t* const src) {
|
||||||
const uint8_t* const src, int channel) {
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
if (!wrk->x_expand) {
|
if (!wrk->x_expand) {
|
||||||
WebPRescalerImportRowShrink(wrk, src, channel);
|
WebPRescalerImportRowShrink(wrk, src);
|
||||||
} else {
|
} else {
|
||||||
WebPRescalerImportRowExpand(wrk, src, channel);
|
WebPRescalerImportRowExpand(wrk, src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,23 +18,25 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "../utils/rescaler.h"
|
#include "../utils/rescaler.h"
|
||||||
|
|
||||||
static void ImportRowShrink(WebPRescaler* const wrk,
|
static void ImportRowShrink(WebPRescaler* const wrk, const uint8_t* src) {
|
||||||
const uint8_t* const src, int channel) {
|
|
||||||
const int x_stride = wrk->num_channels;
|
const int x_stride = wrk->num_channels;
|
||||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||||
const int fx_scale = wrk->fx_scale;
|
const int fx_scale = wrk->fx_scale;
|
||||||
const int x_add = wrk->x_add;
|
const int x_add = wrk->x_add;
|
||||||
const int x_sub = wrk->x_sub;
|
const int x_sub = wrk->x_sub;
|
||||||
int* frow = wrk->frow + channel;
|
const int x_stride1 = x_stride << 2;
|
||||||
|
int channel;
|
||||||
|
assert(!wrk->x_expand);
|
||||||
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
|
|
||||||
|
for (channel = 0; channel < x_stride; ++channel) {
|
||||||
const uint8_t* src1 = src + channel;
|
const uint8_t* src1 = src + channel;
|
||||||
|
int* frow = wrk->frow + channel;
|
||||||
int temp1, temp2, temp3;
|
int temp1, temp2, temp3;
|
||||||
int base, frac, sum;
|
int base, frac, sum;
|
||||||
int accum, accum1;
|
int accum, accum1;
|
||||||
const int x_stride1 = x_stride << 2;
|
int loop_c = x_out_max;
|
||||||
int loop_c = x_out_max - channel;
|
|
||||||
|
|
||||||
assert(!wrk->x_expand);
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
"li %[temp1], 0x8000 \n\t"
|
"li %[temp1], 0x8000 \n\t"
|
||||||
"li %[temp2], 0x10000 \n\t"
|
"li %[temp2], 0x10000 \n\t"
|
||||||
@ -73,24 +75,27 @@ static void ImportRowShrink(WebPRescaler* const wrk,
|
|||||||
: "memory", "hi", "lo"
|
: "memory", "hi", "lo"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ImportRowExpand(WebPRescaler* const wrk,
|
static void ImportRowExpand(WebPRescaler* const wrk, const uint8_t* src) {
|
||||||
const uint8_t* const src, int channel) {
|
|
||||||
const int x_stride = wrk->num_channels;
|
const int x_stride = wrk->num_channels;
|
||||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||||
const int x_add = wrk->x_add;
|
const int x_add = wrk->x_add;
|
||||||
const int x_sub = wrk->x_sub;
|
const int x_sub = wrk->x_sub;
|
||||||
const int src_width = wrk->src_width;
|
const int src_width = wrk->src_width;
|
||||||
int* frow = wrk->frow + channel;
|
const int x_stride1 = x_stride << 2;
|
||||||
|
int channel;
|
||||||
|
assert(wrk->x_expand);
|
||||||
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
|
|
||||||
|
for (channel = 0; channel < x_stride; ++channel) {
|
||||||
const uint8_t* src1 = src + channel;
|
const uint8_t* src1 = src + channel;
|
||||||
|
int* frow = wrk->frow + channel;
|
||||||
int temp1, temp2, temp3, temp4;
|
int temp1, temp2, temp3, temp4;
|
||||||
int frac;
|
int frac;
|
||||||
int accum;
|
int accum;
|
||||||
const int x_stride1 = x_stride << 2;
|
int x_out = 0;
|
||||||
int x_out = channel;
|
|
||||||
|
|
||||||
assert(wrk->x_expand);
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
"addiu %[temp3], %[src_width], -1 \n\t"
|
"addiu %[temp3], %[src_width], -1 \n\t"
|
||||||
"lbu %[temp2], 0(%[src1]) \n\t"
|
"lbu %[temp2], 0(%[src1]) \n\t"
|
||||||
@ -130,6 +135,7 @@ static void ImportRowExpand(WebPRescaler* const wrk,
|
|||||||
: "memory", "hi", "lo"
|
: "memory", "hi", "lo"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ExportRowShrink(WebPRescaler* const wrk) {
|
static void ExportRowShrink(WebPRescaler* const wrk) {
|
||||||
assert(!WebPRescalerOutputDone(wrk));
|
assert(!WebPRescalerOutputDone(wrk));
|
||||||
|
@ -18,23 +18,25 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "../utils/rescaler.h"
|
#include "../utils/rescaler.h"
|
||||||
|
|
||||||
static void ImportRowShrink(WebPRescaler* const wrk,
|
static void ImportRowShrink(WebPRescaler* const wrk, const uint8_t* src) {
|
||||||
const uint8_t* const src, int channel) {
|
|
||||||
const int x_stride = wrk->num_channels;
|
const int x_stride = wrk->num_channels;
|
||||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||||
const int fx_scale = wrk->fx_scale;
|
const int fx_scale = wrk->fx_scale;
|
||||||
const int x_add = wrk->x_add;
|
const int x_add = wrk->x_add;
|
||||||
const int x_sub = wrk->x_sub;
|
const int x_sub = wrk->x_sub;
|
||||||
|
const int x_stride1 = x_stride << 2;
|
||||||
|
int channel;
|
||||||
|
assert(!wrk->x_expand);
|
||||||
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
|
|
||||||
|
for (channel = 0; channel < x_stride; ++channel) {
|
||||||
int* frow = wrk->frow + channel;
|
int* frow = wrk->frow + channel;
|
||||||
const uint8_t* src1 = src + channel;
|
const uint8_t* src1 = src + channel;
|
||||||
int temp3;
|
int temp3;
|
||||||
int base, frac, sum;
|
int base, frac, sum;
|
||||||
int accum, accum1;
|
int accum, accum1;
|
||||||
const int x_stride1 = x_stride << 2;
|
int loop_c = x_out_max;
|
||||||
int loop_c = x_out_max - channel;
|
|
||||||
|
|
||||||
assert(!wrk->x_expand);
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
"li %[sum], 0 \n\t"
|
"li %[sum], 0 \n\t"
|
||||||
"li %[accum], 0 \n\t"
|
"li %[accum], 0 \n\t"
|
||||||
@ -68,24 +70,27 @@ static void ImportRowShrink(WebPRescaler* const wrk,
|
|||||||
: "memory", "hi", "lo"
|
: "memory", "hi", "lo"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ImportRowExpand(WebPRescaler* const wrk,
|
static void ImportRowExpand(WebPRescaler* const wrk, const uint8_t* src) {
|
||||||
const uint8_t* const src, int channel) {
|
|
||||||
const int x_stride = wrk->num_channels;
|
const int x_stride = wrk->num_channels;
|
||||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||||
const int x_add = wrk->x_add;
|
const int x_add = wrk->x_add;
|
||||||
const int x_sub = wrk->x_sub;
|
const int x_sub = wrk->x_sub;
|
||||||
const int src_width = wrk->src_width;
|
const int src_width = wrk->src_width;
|
||||||
|
const int x_stride1 = x_stride << 2;
|
||||||
|
int channel;
|
||||||
|
assert(wrk->x_expand);
|
||||||
|
assert(!WebPRescalerInputDone(wrk));
|
||||||
|
|
||||||
|
for (channel = 0; channel < x_stride; ++channel) {
|
||||||
int* frow = wrk->frow + channel;
|
int* frow = wrk->frow + channel;
|
||||||
const uint8_t* src1 = src + channel;
|
const uint8_t* src1 = src + channel;
|
||||||
int temp1, temp2, temp3, temp4;
|
int temp1, temp2, temp3, temp4;
|
||||||
int frac;
|
int frac;
|
||||||
int accum;
|
int accum;
|
||||||
const int x_stride1 = x_stride << 2;
|
|
||||||
int x_out = channel;
|
int x_out = channel;
|
||||||
|
|
||||||
assert(wrk->x_expand);
|
|
||||||
assert(!WebPRescalerInputDone(wrk));
|
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
"addiu %[temp3], %[src_width], -1 \n\t"
|
"addiu %[temp3], %[src_width], -1 \n\t"
|
||||||
"lbu %[temp2], 0(%[src1]) \n\t"
|
"lbu %[temp2], 0(%[src1]) \n\t"
|
||||||
@ -125,6 +130,7 @@ static void ImportRowExpand(WebPRescaler* const wrk,
|
|||||||
: "memory", "hi", "lo"
|
: "memory", "hi", "lo"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ExportRowShrink(WebPRescaler* const wrk) {
|
static void ExportRowShrink(WebPRescaler* const wrk) {
|
||||||
assert(!WebPRescalerOutputDone(wrk));
|
assert(!WebPRescalerOutputDone(wrk));
|
||||||
|
@ -102,16 +102,14 @@ int WebPRescalerImport(WebPRescaler* const wrk, int num_lines,
|
|||||||
const uint8_t* src, int src_stride) {
|
const uint8_t* src, int src_stride) {
|
||||||
int total_imported = 0;
|
int total_imported = 0;
|
||||||
while (total_imported < num_lines && !WebPRescalerHasPendingOutput(wrk)) {
|
while (total_imported < num_lines && !WebPRescalerHasPendingOutput(wrk)) {
|
||||||
int x, channel;
|
|
||||||
if (wrk->y_expand) {
|
if (wrk->y_expand) {
|
||||||
rescaler_t* const tmp = wrk->irow;
|
rescaler_t* const tmp = wrk->irow;
|
||||||
wrk->irow = wrk->frow;
|
wrk->irow = wrk->frow;
|
||||||
wrk->frow = tmp;
|
wrk->frow = tmp;
|
||||||
}
|
}
|
||||||
for (channel = 0; channel < wrk->num_channels; ++channel) {
|
WebPRescalerImportRow(wrk, src);
|
||||||
WebPRescalerImportRow(wrk, src, channel);
|
|
||||||
}
|
|
||||||
if (!wrk->y_expand) { // Accumulate the contribution of the new row.
|
if (!wrk->y_expand) { // Accumulate the contribution of the new row.
|
||||||
|
int x;
|
||||||
for (x = 0; x < wrk->num_channels * wrk->dst_width; ++x) {
|
for (x = 0; x < wrk->num_channels * wrk->dst_width; ++x) {
|
||||||
wrk->irow[x] += wrk->frow[x];
|
wrk->irow[x] += wrk->frow[x];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user