From d62b75679a07785e5e5bbb4dc7d7b6138fe76712 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 22 May 2009 11:22:16 +0200 Subject: [PATCH] image: Remove some code duplication Only the indices are different between the big / little endian versions of this loop, so just move the indices into local variables and we are done. Signed-off-by: Uli Schlachter Signed-off-by: Julien Danjou --- image.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/image.c b/image.c index a9d54a3a6..680c52dd2 100644 --- a/image.c +++ b/image.c @@ -108,6 +108,11 @@ image_getdata(image_t *image) uint32_t *data; double alpha; uint8_t *dataimg; +#if AWESOME_IS_BIG_ENDIAN + const int index_a = 0, index_r = 1, index_g = 2, index_b = 3; +#else + const int index_a = 3, index_r = 2, index_g = 1, index_b = 0; +#endif if(image->isupdated) return image->data; @@ -123,21 +128,12 @@ image_getdata(image_t *image) for(i = 0; i < size; i++, dataimg += 4) { -#if AWESOME_IS_BIG_ENDIAN - dataimg[0] = (data[i] >> 24) & 0xff; /* A */ + dataimg[index_a] = (data[i] >> 24) & 0xff; /* A */ /* cairo wants pre-multiplied alpha */ - alpha = dataimg[0] / 255.0; - dataimg[1] = ((data[i] >> 16) & 0xff) * alpha; /* R */ - dataimg[2] = ((data[i] >> 8) & 0xff) * alpha; /* G */ - dataimg[3] = (data[i] & 0xff) * alpha; /* B */ -#else - dataimg[3] = (data[i] >> 24) & 0xff; /* A */ - /* cairo wants pre-multiplied alpha */ - alpha = dataimg[3] / 255.0; - dataimg[2] = ((data[i] >> 16) & 0xff) * alpha; /* R */ - dataimg[1] = ((data[i] >> 8) & 0xff) * alpha; /* G */ - dataimg[0] = (data[i] & 0xff) * alpha; /* B */ -#endif + alpha = dataimg[index_a] / 255.0; + dataimg[index_r] = ((data[i] >> 16) & 0xff) * alpha; /* R */ + dataimg[index_g] = ((data[i] >> 8) & 0xff) * alpha; /* G */ + dataimg[index_b] = (data[i] & 0xff) * alpha; /* B */ } image->isupdated = true;