diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-25 10:13:00 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-25 11:56:37 (GMT) |
commit | d2089600ea247b5d6354e8eee4becf40802c4693 (patch) | |
tree | e84583a27233aeea7c232747e478d73710b43eac /src | |
parent | 3061e45108afc13848e9020790b2d60f07e16aa9 (diff) | |
download | Qt-d2089600ea247b5d6354e8eee4becf40802c4693.zip Qt-d2089600ea247b5d6354e8eee4becf40802c4693.tar.gz Qt-d2089600ea247b5d6354e8eee4becf40802c4693.tar.bz2 |
Refactor blend_transformed_bilinear to simplify the blend type checking
The function blend_transformed_bilinear_argb() was checking the blend type
at runtime for each pixel in order to clamp the coordinates. This
code was duplicated in both branch of the function.
This patch factorize the code by doing the clamping in a template
function.
Reviewed-by: Samuel Rødal
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qdrawhelper.cpp | 133 |
1 files changed, 67 insertions, 66 deletions
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index be4275c..59bef66 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -5159,6 +5159,61 @@ static void blend_tiled_rgb444(int count, const QSpan *spans, void *userData) blend_tiled_generic<RegularSpans>(count, spans, userData); } +template<int> +Q_STATIC_INLINE_FUNCTION void blend_transformed_bilinear_argb_clamp_coordinates (int &x1, int &x2, int &y1, int &y2, + const int image_width, const int image_height, + const int image_x1, const int image_x2, + const int image_y1, const int image_y2); + +template<> +Q_STATIC_INLINE_FUNCTION void blend_transformed_bilinear_argb_clamp_coordinates <BlendTransformedBilinearTiled> (int &x1, int &x2, int &y1, int &y2, + const int image_width, const int image_height, + const int image_x1, const int image_x2, + const int image_y1, const int image_y2) +{ + Q_UNUSED(image_x1) + Q_UNUSED(image_x2) + Q_UNUSED(image_y1) + Q_UNUSED(image_y2) + x1 %= image_width; + if (x1 < 0) x1 += image_width; + x2 = x1 + 1; + x2 %= image_width; + + y1 %= image_height; + if (y1 < 0) y1 += image_height; + y2 = y1 + 1; + y2 %= image_height; + + Q_ASSERT(x1 >= 0 && x1 < image_width); + Q_ASSERT(x2 >= 0 && x2 < image_width); + Q_ASSERT(y1 >= 0 && y1 < image_height); + Q_ASSERT(y2 >= 0 && y2 < image_height); +} + +template <> +Q_STATIC_INLINE_FUNCTION void blend_transformed_bilinear_argb_clamp_coordinates<BlendTransformedBilinear>(int &x1, int &x2, int &y1, int &y2, + const int image_width, const int image_height, + const int image_x1, const int image_x2, + const int image_y1, const int image_y2) +{ + Q_UNUSED(image_width) + Q_UNUSED(image_height) + if (x1 < image_x1) { + x2 = x1 = image_x1; + } else if (x1 >= image_x2) { + x2 = x1 = image_x2; + } else { + x2 = x1 + 1; + } + if (y1 < image_y1) { + y2 = y1 = image_y1; + } else if (y1 >= image_y2) { + y2 = y1 = image_y2; + } else { + y2 = y1 + 1; + } +} template <SpanMethod spanMethod, TextureBlendType blendType> /* blendType must be either BlendTransformedBilinear or BlendTransformedBilinearTiled */ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const QSpan *spans, void *userData) @@ -5175,8 +5230,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const const int image_x1 = data->texture.x1; const int image_y1 = data->texture.y1; - const int image_x2 = data->texture.x2; - const int image_y2 = data->texture.y2; + const int image_x2 = data->texture.x2 - 1; + const int image_y2 = data->texture.y2 - 1; const int image_width = data->texture.width; const int image_height = data->texture.height; const int scanline_offset = data->texture.bytesPerLine / 4; @@ -5206,43 +5261,16 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const int l = qMin(length, buffer_size); const uint *end = buffer + l; uint *b = buffer; - while (b < end) { + while (b != end) { int x1 = (x >> 16); int x2; int y1 = (y >> 16); int y2; - if (blendType == BlendTransformedBilinearTiled) { - x1 %= image_width; - if (x1 < 0) x1 += image_width; - x2 = x1 + 1; - x2 %= image_width; - - y1 %= image_height; - if (y1 < 0) y1 += image_height; - y2 = y1 + 1; - y2 %= image_height; - - Q_ASSERT(x1 >= 0 && x1 < image_width); - Q_ASSERT(x2 >= 0 && x2 < image_width); - Q_ASSERT(y1 >= 0 && y1 < image_height); - Q_ASSERT(y2 >= 0 && y2 < image_height); - } else { - if (x1 < image_x1) { - x2 = x1 = image_x1; - } else if (x1 >= image_x2 - 1) { - x2 = x1 = image_x2 - 1; - } else { - x2 = x1 + 1; - } - if (y1 < image_y1) { - y2 = y1 = image_y1; - } else if (y1 >= image_y2 - 1) { - y2 = y1 = image_y2 - 1; - } else { - y2 = y1 + 1; - } - } + blend_transformed_bilinear_argb_clamp_coordinates<blendType>(x1, x2, y1, y2, + image_width, image_height, + image_x1, image_x2, + image_y1, image_y2); int y1_offset = y1 * scanline_offset; int y2_offset = y2 * scanline_offset; @@ -5307,7 +5335,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const int l = qMin(length, buffer_size); const uint *end = buffer + l; uint *b = buffer; - while (b < end) { + while (b != end) { const qreal iw = w == 0 ? 1 : 1 / w; const qreal px = x * iw - 0.5; const qreal py = y * iw - 0.5; @@ -5322,37 +5350,10 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const int idistx = 256 - distx; int idisty = 256 - disty; - if (blendType == BlendTransformedBilinearTiled) { - x1 %= image_width; - if (x1 < 0) x1 += image_width; - x2 = x1 + 1; - x2 %= image_width; - - y1 %= image_height; - if (y1 < 0) y1 += image_height; - y2 = y1 + 1; - y2 %= image_height; - - Q_ASSERT(x1 >= 0 && x1 < image_width); - Q_ASSERT(x2 >= 0 && x2 < image_width); - Q_ASSERT(y1 >= 0 && y1 < image_height); - Q_ASSERT(y2 >= 0 && y2 < image_height); - } else { - if (x1 < image_x1) { - x2 = x1 = image_x1; - } else if (x1 >= image_x2 - 1) { - x2 = x1 = image_x2 - 1; - } else { - x2 = x1 + 1; - } - if (y1 < image_y1) { - y2 = y1 = image_y1; - } else if (y1 >= image_y2 - 1) { - y2 = y1 = image_y2 - 1; - } else { - y2 = y1 + 1; - } - } + blend_transformed_bilinear_argb_clamp_coordinates<blendType>(x1, x2, y1, y2, + image_width, image_height, + image_x1, image_x2, + image_y1, image_y2); int y1_offset = y1 * scanline_offset; int y2_offset = y2 * scanline_offset; |