From 7a1717e605e502b52ebca999991d2e07791e0cd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Wed, 5 Nov 2008 17:23:45 -0500 Subject: [PATCH] Use fetch_nearest() instead of having duplicated code --- pixman/pixman-transformed.c | 186 +++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 122 deletions(-) diff --git a/pixman/pixman-transformed.c b/pixman/pixman-transformed.c index cfdc48c..2a374f6 100644 --- a/pixman/pixman-transformed.c +++ b/pixman/pixman-transformed.c @@ -87,123 +87,58 @@ do_fetch (bits_image_t *pict, int x, int y, fetchPixelProc32 fetch, /* * Fetching Algorithms */ -static void -fbFetchTransformed_Nearest_Normal(bits_image_t * pict, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits, pixman_bool_t affine, pixman_vector_t v, pixman_vector_t unit) +static uint32_t +fetch_nearest (bits_image_t *pict, + fetchPixelProc32 fetch, + pixman_bool_t affine, + pixman_repeat_t repeat, + pixman_bool_t has_src_clip, + const pixman_vector_t *v) { - fetchPixelProc32 fetch; - pixman_bool_t src_clip; - int x, y, i; - - /* initialize the two function pointers */ - fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict); - - src_clip = pict->common.src_clip != &(pict->common.full_region); - - for ( i = 0; i < width; ++i) + if (!v->vector[2]) { - if (!mask || mask[i] & maskBits) - { - if (!v.vector[2]) - { - *(buffer + i) = 0; - } - else - { - if (!affine) - { - y = MOD(DIV(v.vector[1],v.vector[2]), pict->height); - x = MOD(DIV(v.vector[0],v.vector[2]), pict->width); - } - else - { - y = MOD(v.vector[1]>>16, pict->height); - x = MOD(v.vector[0]>>16, pict->width); - } - - *(buffer + i) = do_fetch (pict, x, y, fetch, src_clip, TRUE); - } - } - - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; + return 0; } -} - -static void -fbFetchTransformed_Nearest_Pad(bits_image_t * pict, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits, pixman_bool_t affine, pixman_vector_t v, pixman_vector_t unit) -{ - pixman_bool_t src_clip; - fetchPixelProc32 fetch; - int x, y, i; - - /* initialize the two function pointers */ - fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict); - - src_clip = pict->common.src_clip != &(pict->common.full_region); - - for (i = 0; i < width; ++i) + else { - if (!mask || mask[i] & maskBits) - { - if (!v.vector[2]) - { - *(buffer + i) = 0; - } - else - { - if (!affine) - { - y = CLIP(DIV(v.vector[1], v.vector[2]), 0, pict->height-1); - x = CLIP(DIV(v.vector[0], v.vector[2]), 0, pict->width-1); - } - else - { - y = CLIP(v.vector[1]>>16, 0, pict->height-1); - x = CLIP(v.vector[0]>>16, 0, pict->width-1); - } - - *(buffer + i) = do_fetch (pict, x, y, fetch, src_clip, TRUE); - } - } - - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } -} - -static void -fbFetchTransformed_Nearest_General(bits_image_t * pict, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits, pixman_bool_t affine, pixman_vector_t v, pixman_vector_t unit) -{ - fetchPixelProc32 fetch; - pixman_bool_t src_clip; - int x, y, i; + int x, y; + pixman_bool_t inside_bounds; - fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict); + if (!affine) + { + x = DIV(v->vector[0], v->vector[2]); + y = DIV(v->vector[1], v->vector[2]); + } + else + { + x = v->vector[0]>>16; + y = v->vector[1]>>16; + } - src_clip = pict->common.src_clip != &(pict->common.full_region); + switch (repeat) + { + case PIXMAN_REPEAT_NORMAL: + x = MOD (x, pict->width); + y = MOD (y, pict->height); + inside_bounds = TRUE; + break; + + case PIXMAN_REPEAT_PAD: + x = CLIP (x, 0, pict->width-1); + y = CLIP (y, 0, pict->height-1); + inside_bounds = TRUE; + break; + + case PIXMAN_REPEAT_REFLECT: /* Thanks Trolltech for not implementing reflect for images */ + case PIXMAN_REPEAT_NONE: + inside_bounds = FALSE; + break; - for (i = 0; i < width; ++i) { - if (!mask || mask[i] & maskBits) - { - if (!v.vector[2]) { - *(buffer + i) = 0; - } else { - if (!affine) { - y = DIV(v.vector[1],v.vector[2]); - x = DIV(v.vector[0],v.vector[2]); - } else { - y = v.vector[1]>>16; - x = v.vector[0]>>16; - } + default: + return 0; + } - *(buffer + i) = do_fetch (pict, x, y, fetch, src_clip, FALSE); - } - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; + return do_fetch (pict, x, y, fetch, has_src_clip, inside_bounds); } } @@ -450,22 +385,29 @@ ACCESS(fbFetchTransformed)(bits_image_t * pict, int x, int y, int width, if (pict->common.filter == PIXMAN_FILTER_NEAREST || pict->common.filter == PIXMAN_FILTER_FAST) { + fetchPixelProc32 fetch; + pixman_bool_t src_clip; + int i; + /* Round down to closest integer, ensuring that 0.5 rounds to 0, not 1 */ adjust (&v, &unit, pixman_fixed_1 / 2 - pixman_fixed_e); + + /* initialize the two function pointers */ + fetch = ACCESS(pixman_fetchPixelProcForPicture32)(pict); - if (pict->common.repeat == PIXMAN_REPEAT_NORMAL) - { - fbFetchTransformed_Nearest_Normal(pict, width, buffer, mask, maskBits, affine, v, unit); - } - else if (pict->common.repeat == PIXMAN_REPEAT_PAD) - { - fbFetchTransformed_Nearest_Pad(pict, width, buffer, mask, maskBits, affine, v, unit); - } - else - { - fbFetchTransformed_Nearest_General(pict, width, buffer, mask, maskBits, affine, v, unit); - } - } else if (pict->common.filter == PIXMAN_FILTER_BILINEAR || + src_clip = pict->common.src_clip != &(pict->common.full_region); + + for ( i = 0; i < width; ++i) + { + if (!mask || mask[i] & maskBits) + *(buffer + i) = fetch_nearest (pict, fetch, affine, pict->common.repeat, src_clip, &v); + + v.vector[0] += unit.vector[0]; + v.vector[1] += unit.vector[1]; + v.vector[2] += unit.vector[2]; + } + } + else if (pict->common.filter == PIXMAN_FILTER_BILINEAR || pict->common.filter == PIXMAN_FILTER_GOOD || pict->common.filter == PIXMAN_FILTER_BEST) { -- 2.7.4