diff --git a/src/dsp/filters.c b/src/dsp/filters.c index bb779b39..9c1fa919 100644 --- a/src/dsp/filters.c +++ b/src/dsp/filters.c @@ -26,8 +26,6 @@ assert(width > 0); \ assert(height > 0); \ assert(stride >= width); \ - assert(row >= 0 && num_rows > 0 && row + num_rows <= height); \ - (void)height; /* Silence unused warning. */ \ } while (0) #if !WEBP_NEON_OMIT_C_CODE @@ -42,32 +40,23 @@ static WEBP_INLINE void PredictLine_C(const uint8_t* src, const uint8_t* pred, static WEBP_INLINE void DoHorizontalFilter_C(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const uint8_t* preds; - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + const uint8_t* preds = in; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - preds = in; - if (row == 0) { - // Leftmost pixel is the same as input for topmost scanline. - out[0] = in[0]; - PredictLine_C(in + 1, preds, out + 1, width - 1); - row = 1; - preds += stride; - in += stride; - out += stride; - } + // Leftmost pixel is the same as input for topmost scanline. + out[0] = in[0]; + PredictLine_C(in + 1, preds, out + 1, width - 1); + preds += stride; + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { // Leftmost pixel is predicted from above. PredictLine_C(in, preds - stride, out, 1); PredictLine_C(in + 1, preds, out + 1, width - 1); - ++row; preds += stride; in += stride; out += stride; @@ -79,33 +68,21 @@ static WEBP_INLINE void DoHorizontalFilter_C(const uint8_t* in, static WEBP_INLINE void DoVerticalFilter_C(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const uint8_t* preds; - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + const uint8_t* preds = in; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - preds = in; - if (row == 0) { - // Very first top-left pixel is copied. - out[0] = in[0]; - // Rest of top scan-line is left-predicted. - PredictLine_C(in + 1, preds, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } else { - // We are starting from in-between. Make sure 'preds' points to prev row. - preds -= stride; - } + // Very first top-left pixel is copied. + out[0] = in[0]; + // Rest of top scan-line is left-predicted. + PredictLine_C(in + 1, preds, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { PredictLine_C(in, preds, out, width); - ++row; preds += stride; in += stride; out += stride; @@ -124,28 +101,20 @@ static WEBP_INLINE int GradientPredictor_C(uint8_t a, uint8_t b, uint8_t c) { #if !WEBP_NEON_OMIT_C_CODE static WEBP_INLINE void DoGradientFilter_C(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const uint8_t* preds; - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + const uint8_t* preds = in; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - preds = in; // left prediction for top scan-line - if (row == 0) { - out[0] = in[0]; - PredictLine_C(in + 1, preds, out + 1, width - 1); - row = 1; - preds += stride; - in += stride; - out += stride; - } + out[0] = in[0]; + PredictLine_C(in + 1, preds, out + 1, width - 1); + preds += stride; + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { int w; // leftmost pixel: predict from above. PredictLine_C(in, preds - stride, out, 1); @@ -155,7 +124,6 @@ static WEBP_INLINE void DoGradientFilter_C(const uint8_t* in, preds[w - stride - 1]); out[w] = (uint8_t)(in[w] - pred); } - ++row; preds += stride; in += stride; out += stride; @@ -170,17 +138,17 @@ static WEBP_INLINE void DoGradientFilter_C(const uint8_t* in, #if !WEBP_NEON_OMIT_C_CODE static void HorizontalFilter_C(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoHorizontalFilter_C(data, width, height, stride, 0, height, filtered_data); + DoHorizontalFilter_C(data, width, height, stride, filtered_data); } static void VerticalFilter_C(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoVerticalFilter_C(data, width, height, stride, 0, height, filtered_data); + DoVerticalFilter_C(data, width, height, stride, filtered_data); } static void GradientFilter_C(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoGradientFilter_C(data, width, height, stride, 0, height, filtered_data); + DoGradientFilter_C(data, width, height, stride, filtered_data); } #endif // !WEBP_NEON_OMIT_C_CODE diff --git a/src/dsp/filters_mips_dsp_r2.c b/src/dsp/filters_mips_dsp_r2.c index eca866f5..2c2c63c0 100644 --- a/src/dsp/filters_mips_dsp_r2.c +++ b/src/dsp/filters_mips_dsp_r2.c @@ -31,8 +31,6 @@ assert(width > 0); \ assert(height > 0); \ assert(stride >= width); \ - assert(row >= 0 && num_rows > 0 && row + num_rows <= height); \ - (void)height; /* Silence unused warning. */ \ } while (0) #define DO_PREDICT_LINE(SRC, DST, LENGTH, INVERSE) do { \ @@ -184,10 +182,9 @@ static WEBP_INLINE void PredictLine_MIPSdspR2(const uint8_t* src, uint8_t* dst, // Horizontal filter. #define FILTER_LINE_BY_LINE do { \ - while (row < last_row) { \ + for (row = 1; row < height; ++row) { \ PREDICT_LINE_ONE_PASS(in, preds - stride, out); \ DO_PREDICT_LINE(in + 1, out + 1, width - 1, 0); \ - ++row; \ preds += stride; \ in += stride; \ out += stride; \ @@ -196,26 +193,17 @@ static WEBP_INLINE void PredictLine_MIPSdspR2(const uint8_t* src, uint8_t* dst, static WEBP_INLINE void DoHorizontalFilter_MIPSdspR2(const uint8_t* in, int width, int height, - int stride, - int row, int num_rows, - uint8_t* out) { - const uint8_t* preds; - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int stride, uint8_t* out) { + const uint8_t* preds = in; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - preds = in; - if (row == 0) { - // Leftmost pixel is the same as input for topmost scanline. - out[0] = in[0]; - PredictLine_MIPSdspR2(in + 1, out + 1, width - 1); - row = 1; - preds += stride; - in += stride; - out += stride; - } + // Leftmost pixel is the same as input for topmost scanline. + out[0] = in[0]; + PredictLine_MIPSdspR2(in + 1, out + 1, width - 1); + preds += stride; + in += stride; + out += stride; // Filter line-by-line. FILTER_LINE_BY_LINE; @@ -225,17 +213,15 @@ static WEBP_INLINE void DoHorizontalFilter_MIPSdspR2(const uint8_t* in, static void HorizontalFilter_MIPSdspR2(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoHorizontalFilter_MIPSdspR2(data, width, height, stride, 0, height, - filtered_data); + DoHorizontalFilter_MIPSdspR2(data, width, height, stride, filtered_data); } //------------------------------------------------------------------------------ // Vertical filter. #define FILTER_LINE_BY_LINE do { \ - while (row < last_row) { \ + for (row = 1; row < height; ++row) { \ DO_PREDICT_LINE_VERTICAL(in, preds, out, width, 0); \ - ++row; \ preds += stride; \ in += stride; \ out += stride; \ @@ -244,29 +230,17 @@ static void HorizontalFilter_MIPSdspR2(const uint8_t* data, static WEBP_INLINE void DoVerticalFilter_MIPSdspR2(const uint8_t* in, int width, int height, - int stride, - int row, int num_rows, - uint8_t* out) { - const uint8_t* preds; - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int stride, uint8_t* out) { + const uint8_t* preds = in; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - preds = in; - if (row == 0) { - // Very first top-left pixel is copied. - out[0] = in[0]; - // Rest of top scan-line is left-predicted. - PredictLine_MIPSdspR2(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } else { - // We are starting from in-between. Make sure 'preds' points to prev row. - preds -= stride; - } + // Very first top-left pixel is copied. + out[0] = in[0]; + // Rest of top scan-line is left-predicted. + PredictLine_MIPSdspR2(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. FILTER_LINE_BY_LINE; @@ -275,8 +249,7 @@ static WEBP_INLINE void DoVerticalFilter_MIPSdspR2(const uint8_t* in, static void VerticalFilter_MIPSdspR2(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoVerticalFilter_MIPSdspR2(data, width, height, stride, 0, height, - filtered_data); + DoVerticalFilter_MIPSdspR2(data, width, height, stride, filtered_data); } //------------------------------------------------------------------------------ @@ -297,7 +270,7 @@ static int GradientPredictor_MIPSdspR2(uint8_t a, uint8_t b, uint8_t c) { } #define FILTER_LINE_BY_LINE(PREDS, OPERATION) do { \ - while (row < last_row) { \ + for (row = 1; row < height; ++row) { \ int w; \ PREDICT_LINE_ONE_PASS(in, PREDS - stride, out); \ for (w = 1; w < width; ++w) { \ @@ -306,7 +279,6 @@ static int GradientPredictor_MIPSdspR2(uint8_t a, uint8_t b, uint8_t c) { PREDS[w - stride - 1]); \ out[w] = in[w] OPERATION pred; \ } \ - ++row; \ in += stride; \ out += stride; \ } \ @@ -314,24 +286,17 @@ static int GradientPredictor_MIPSdspR2(uint8_t a, uint8_t b, uint8_t c) { static void DoGradientFilter_MIPSdspR2(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const uint8_t* preds; - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + uint8_t* out) { + const uint8_t* preds = in; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - preds = in; // left prediction for top scan-line - if (row == 0) { - out[0] = in[0]; - PredictLine_MIPSdspR2(in + 1, out + 1, width - 1); - row = 1; - preds += stride; - in += stride; - out += stride; - } + out[0] = in[0]; + PredictLine_MIPSdspR2(in + 1, out + 1, width - 1); + preds += stride; + in += stride; + out += stride; // Filter line-by-line. FILTER_LINE_BY_LINE(in, -); @@ -340,8 +305,7 @@ static void DoGradientFilter_MIPSdspR2(const uint8_t* in, static void GradientFilter_MIPSdspR2(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoGradientFilter_MIPSdspR2(data, width, height, stride, 0, height, - filtered_data); + DoGradientFilter_MIPSdspR2(data, width, height, stride, filtered_data); } //------------------------------------------------------------------------------ diff --git a/src/dsp/filters_neon.c b/src/dsp/filters_neon.c index b49e515a..0b0a8421 100644 --- a/src/dsp/filters_neon.c +++ b/src/dsp/filters_neon.c @@ -28,8 +28,6 @@ assert(width > 0); \ assert(height > 0); \ assert(stride >= width); \ - assert(row >= 0 && num_rows > 0 && row + num_rows <= height); \ - (void)height; /* Silence unused warning. */ \ } while (0) // load eight u8 and widen to s16 @@ -68,30 +66,21 @@ static void PredictLineLeft_NEON(const uint8_t* src, uint8_t* dst, int length) { static WEBP_INLINE void DoHorizontalFilter_NEON(const uint8_t* in, int width, int height, - int stride, - int row, int num_rows, - uint8_t* out) { - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int stride, uint8_t* out) { + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - if (row == 0) { - // Leftmost pixel is the same as input for topmost scanline. - out[0] = in[0]; - PredictLineLeft_NEON(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } + // Leftmost pixel is the same as input for topmost scanline. + out[0] = in[0]; + PredictLineLeft_NEON(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { // Leftmost pixel is predicted from above. out[0] = in[0] - in[-stride]; PredictLineLeft_NEON(in + 1, out + 1, width - 1); - ++row; in += stride; out += stride; } @@ -99,8 +88,7 @@ static WEBP_INLINE void DoHorizontalFilter_NEON(const uint8_t* in, static void HorizontalFilter_NEON(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoHorizontalFilter_NEON(data, width, height, stride, 0, height, - filtered_data); + DoHorizontalFilter_NEON(data, width, height, stride, filtered_data); } //------------------------------------------------------------------------------ @@ -108,28 +96,20 @@ static void HorizontalFilter_NEON(const uint8_t* data, int width, int height, static WEBP_INLINE void DoVerticalFilter_NEON(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - if (row == 0) { - // Very first top-left pixel is copied. - out[0] = in[0]; - // Rest of top scan-line is left-predicted. - PredictLineLeft_NEON(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } + // Very first top-left pixel is copied. + out[0] = in[0]; + // Rest of top scan-line is left-predicted. + PredictLineLeft_NEON(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { PredictLine_NEON(in, in - stride, out, width); - ++row; in += stride; out += stride; } @@ -137,8 +117,7 @@ static WEBP_INLINE void DoVerticalFilter_NEON(const uint8_t* in, static void VerticalFilter_NEON(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoVerticalFilter_NEON(data, width, height, stride, 0, height, - filtered_data); + DoVerticalFilter_NEON(data, width, height, stride, filtered_data); } //------------------------------------------------------------------------------ @@ -168,30 +147,21 @@ static void GradientPredictDirect_NEON(const uint8_t* const row, } static WEBP_INLINE void DoGradientFilter_NEON(const uint8_t* in, - int width, int height, - int stride, - int row, int num_rows, + int width, int height, int stride, uint8_t* out) { - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; // left prediction for top scan-line - if (row == 0) { - out[0] = in[0]; - PredictLineLeft_NEON(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } + out[0] = in[0]; + PredictLineLeft_NEON(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { out[0] = in[0] - in[-stride]; GradientPredictDirect_NEON(in + 1, in + 1 - stride, out + 1, width - 1); - ++row; in += stride; out += stride; } @@ -199,8 +169,7 @@ static WEBP_INLINE void DoGradientFilter_NEON(const uint8_t* in, static void GradientFilter_NEON(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoGradientFilter_NEON(data, width, height, stride, 0, height, - filtered_data); + DoGradientFilter_NEON(data, width, height, stride, filtered_data); } #undef DCHECK diff --git a/src/dsp/filters_sse2.c b/src/dsp/filters_sse2.c index bb4b5d58..add4f493 100644 --- a/src/dsp/filters_sse2.c +++ b/src/dsp/filters_sse2.c @@ -30,8 +30,6 @@ assert(width > 0); \ assert(height > 0); \ assert(stride >= width); \ - assert(row >= 0 && num_rows > 0 && row + num_rows <= height); \ - (void)height; /* Silence unused warning. */ \ } while (0) static void PredictLineTop_SSE2(const uint8_t* src, const uint8_t* pred, @@ -75,30 +73,21 @@ static void PredictLineLeft_SSE2(const uint8_t* src, uint8_t* dst, int length) { static WEBP_INLINE void DoHorizontalFilter_SSE2(const uint8_t* in, int width, int height, - int stride, - int row, int num_rows, - uint8_t* out) { - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int stride, uint8_t* out) { + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - if (row == 0) { - // Leftmost pixel is the same as input for topmost scanline. - out[0] = in[0]; - PredictLineLeft_SSE2(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } + // Leftmost pixel is the same as input for topmost scanline. + out[0] = in[0]; + PredictLineLeft_SSE2(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { // Leftmost pixel is predicted from above. out[0] = in[0] - in[-stride]; PredictLineLeft_SSE2(in + 1, out + 1, width - 1); - ++row; in += stride; out += stride; } @@ -109,28 +98,20 @@ static WEBP_INLINE void DoHorizontalFilter_SSE2(const uint8_t* in, static WEBP_INLINE void DoVerticalFilter_SSE2(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; - if (row == 0) { - // Very first top-left pixel is copied. - out[0] = in[0]; - // Rest of top scan-line is left-predicted. - PredictLineLeft_SSE2(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } + // Very first top-left pixel is copied. + out[0] = in[0]; + // Rest of top scan-line is left-predicted. + PredictLineLeft_SSE2(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { PredictLineTop_SSE2(in, in - stride, out, width); - ++row; in += stride; out += stride; } @@ -172,28 +153,20 @@ static void GradientPredictDirect_SSE2(const uint8_t* const row, static WEBP_INLINE void DoGradientFilter_SSE2(const uint8_t* in, int width, int height, int stride, - int row, int num_rows, uint8_t* out) { - const size_t start_offset = row * stride; - const int last_row = row + num_rows; + int row; DCHECK(in, out); - in += start_offset; - out += start_offset; // left prediction for top scan-line - if (row == 0) { - out[0] = in[0]; - PredictLineLeft_SSE2(in + 1, out + 1, width - 1); - row = 1; - in += stride; - out += stride; - } + out[0] = in[0]; + PredictLineLeft_SSE2(in + 1, out + 1, width - 1); + in += stride; + out += stride; // Filter line-by-line. - while (row < last_row) { + for (row = 1; row < height; ++row) { out[0] = (uint8_t)(in[0] - in[-stride]); GradientPredictDirect_SSE2(in + 1, in + 1 - stride, out + 1, width - 1); - ++row; in += stride; out += stride; } @@ -205,18 +178,17 @@ static WEBP_INLINE void DoGradientFilter_SSE2(const uint8_t* in, static void HorizontalFilter_SSE2(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoHorizontalFilter_SSE2(data, width, height, stride, 0, height, - filtered_data); + DoHorizontalFilter_SSE2(data, width, height, stride, filtered_data); } static void VerticalFilter_SSE2(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoVerticalFilter_SSE2(data, width, height, stride, 0, height, filtered_data); + DoVerticalFilter_SSE2(data, width, height, stride, filtered_data); } static void GradientFilter_SSE2(const uint8_t* data, int width, int height, int stride, uint8_t* filtered_data) { - DoGradientFilter_SSE2(data, width, height, stride, 0, height, filtered_data); + DoGradientFilter_SSE2(data, width, height, stride, filtered_data); } //------------------------------------------------------------------------------