From: Søren Sandmann Pedersen Date: Tue, 10 Nov 2009 20:48:36 +0000 (-0500) Subject: test: Move image_endian_swap() from blitters-test.c to utils.[ch] X-Git-Tag: pixman-0.17.2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=13f4e02b1429d62b08487beebd8697887a5a9608;p=platform%2Fupstream%2Fpixman.git test: Move image_endian_swap() from blitters-test.c to utils.[ch] --- diff --git a/test/blitters-test.c b/test/blitters-test.c index 80fc8fa..979af24 100644 --- a/test/blitters-test.c +++ b/test/blitters-test.c @@ -44,88 +44,6 @@ aligned_malloc (size_t align, size_t size) return result; } -/* perform endian conversion of pixel data */ -static void -image_endian_swap (pixman_image_t *img, int bpp) -{ - int stride = pixman_image_get_stride (img); - uint32_t *data = pixman_image_get_data (img); - int height = pixman_image_get_height (img); - int i, j; - - /* swap bytes only on big endian systems */ - volatile uint16_t endian_check_var = 0x1234; - if (*(volatile uint8_t *)&endian_check_var != 0x12) - return; - - for (i = 0; i < height; i++) - { - uint8_t *line_data = (uint8_t *)data + stride * i; - /* swap bytes only for 16, 24 and 32 bpp for now */ - switch (bpp) - { - case 1: - for (j = 0; j < stride; j++) - { - line_data[j] = - ((line_data[j] & 0x80) >> 7) | - ((line_data[j] & 0x40) >> 5) | - ((line_data[j] & 0x20) >> 3) | - ((line_data[j] & 0x10) >> 1) | - ((line_data[j] & 0x08) << 1) | - ((line_data[j] & 0x04) << 3) | - ((line_data[j] & 0x02) << 5) | - ((line_data[j] & 0x01) << 7); - } - break; - case 4: - for (j = 0; j < stride; j++) - { - line_data[j] = (line_data[j] >> 4) | (line_data[j] << 4); - } - break; - case 16: - for (j = 0; j + 2 <= stride; j += 2) - { - char t1 = line_data[j + 0]; - char t2 = line_data[j + 1]; - - line_data[j + 1] = t1; - line_data[j + 0] = t2; - } - break; - case 24: - for (j = 0; j + 3 <= stride; j += 3) - { - char t1 = line_data[j + 0]; - char t2 = line_data[j + 1]; - char t3 = line_data[j + 2]; - - line_data[j + 2] = t1; - line_data[j + 1] = t2; - line_data[j + 0] = t3; - } - break; - case 32: - for (j = 0; j + 4 <= stride; j += 4) - { - char t1 = line_data[j + 0]; - char t2 = line_data[j + 1]; - char t3 = line_data[j + 2]; - char t4 = line_data[j + 3]; - - line_data[j + 3] = t1; - line_data[j + 2] = t2; - line_data[j + 1] = t3; - line_data[j + 0] = t4; - } - break; - default: - break; - } - } -} - /* Create random image for testing purposes */ static pixman_image_t * create_random_image (pixman_format_code_t *allowed_formats, diff --git a/test/scaling-test.c b/test/scaling-test.c index 296b986..2977290 100644 --- a/test/scaling-test.c +++ b/test/scaling-test.c @@ -25,70 +25,6 @@ #include #include "utils.h" -/* perform endian conversion of pixel data */ -static void -image_endian_swap (pixman_image_t *img, - int bpp) -{ - int stride = pixman_image_get_stride (img); - uint32_t *data = pixman_image_get_data (img); - int height = pixman_image_get_height (img); - int i, j; - - /* swap bytes only on big endian systems */ - volatile uint16_t endian_check_var = 0x1234; - if (*(volatile uint8_t *)&endian_check_var != 0x12) - return; - - for (i = 0; i < height; i++) - { - char *line_data = (char *)data + stride * i; - - /* swap bytes only for 16, 24 and 32 bpp for now */ - switch (bpp) - { - case 16: - for (j = 0; j + 2 <= stride; j += 2) - { - char t1 = line_data[j + 0]; - char t2 = line_data[j + 1]; - line_data[j + 1] = t1; - line_data[j + 0] = t2; - } - break; - - case 24: - for (j = 0; j + 3 <= stride; j += 3) - { - char t1 = line_data[j + 0]; - char t2 = line_data[j + 1]; - char t3 = line_data[j + 2]; - line_data[j + 2] = t1; - line_data[j + 1] = t2; - line_data[j + 0] = t3; - } - break; - - case 32: - for (j = 0; j + 4 <= stride; j += 4) - { - char t1 = line_data[j + 0]; - char t2 = line_data[j + 1]; - char t3 = line_data[j + 2]; - char t4 = line_data[j + 3]; - line_data[j + 3] = t1; - line_data[j + 2] = t2; - line_data[j + 1] = t3; - line_data[j + 0] = t4; - } - break; - - default: - break; - } - } -} - #define MAX_SRC_WIDTH 10 #define MAX_SRC_HEIGHT 10 #define MAX_DST_WIDTH 10 diff --git a/test/utils.c b/test/utils.c index afd2a18..1e42d89 100644 --- a/test/utils.c +++ b/test/utils.c @@ -109,3 +109,86 @@ compute_crc32 (uint32_t in_crc32, return (crc32 ^ 0xFFFFFFFF); } +/* perform endian conversion of pixel data + */ +void +image_endian_swap (pixman_image_t *img, int bpp) +{ + int stride = pixman_image_get_stride (img); + uint32_t *data = pixman_image_get_data (img); + int height = pixman_image_get_height (img); + int i, j; + + /* swap bytes only on big endian systems */ + volatile uint16_t endian_check_var = 0x1234; + if (*(volatile uint8_t *)&endian_check_var != 0x12) + return; + + for (i = 0; i < height; i++) + { + uint8_t *line_data = (uint8_t *)data + stride * i; + /* swap bytes only for 16, 24 and 32 bpp for now */ + switch (bpp) + { + case 1: + for (j = 0; j < stride; j++) + { + line_data[j] = + ((line_data[j] & 0x80) >> 7) | + ((line_data[j] & 0x40) >> 5) | + ((line_data[j] & 0x20) >> 3) | + ((line_data[j] & 0x10) >> 1) | + ((line_data[j] & 0x08) << 1) | + ((line_data[j] & 0x04) << 3) | + ((line_data[j] & 0x02) << 5) | + ((line_data[j] & 0x01) << 7); + } + break; + case 4: + for (j = 0; j < stride; j++) + { + line_data[j] = (line_data[j] >> 4) | (line_data[j] << 4); + } + break; + case 16: + for (j = 0; j + 2 <= stride; j += 2) + { + char t1 = line_data[j + 0]; + char t2 = line_data[j + 1]; + + line_data[j + 1] = t1; + line_data[j + 0] = t2; + } + break; + case 24: + for (j = 0; j + 3 <= stride; j += 3) + { + char t1 = line_data[j + 0]; + char t2 = line_data[j + 1]; + char t3 = line_data[j + 2]; + + line_data[j + 2] = t1; + line_data[j + 1] = t2; + line_data[j + 0] = t3; + } + break; + case 32: + for (j = 0; j + 4 <= stride; j += 4) + { + char t1 = line_data[j + 0]; + char t2 = line_data[j + 1]; + char t3 = line_data[j + 2]; + char t4 = line_data[j + 3]; + + line_data[j + 3] = t1; + line_data[j + 2] = t2; + line_data[j + 1] = t3; + line_data[j + 0] = t4; + } + break; + default: + break; + } + } +} + diff --git a/test/utils.h b/test/utils.h index 2d340d1..8fdb2ce 100644 --- a/test/utils.h +++ b/test/utils.h @@ -35,3 +35,7 @@ compute_crc32 (uint32_t in_crc32, const void *buf, size_t buf_len); +/* perform endian conversion of pixel data + */ +void +image_endian_swap (pixman_image_t *img, int bpp);