alphamap.c revision 952204ab
1#include <stdio.h> 2#include <stdlib.h> 3#include "utils.h" 4 5#define WIDTH 400 6#define HEIGHT 200 7 8int 9main (int argc, char **argv) 10{ 11 uint8_t *alpha = make_random_bytes (WIDTH * HEIGHT); 12 uint32_t *src = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4); 13 uint32_t *dest = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4); 14 int i; 15 16 pixman_image_t *a = pixman_image_create_bits (PIXMAN_a8, WIDTH, HEIGHT, (uint32_t *)alpha, WIDTH); 17 pixman_image_t *d = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); 18 19 for (i = 0; i < 2; ++i) 20 { 21 pixman_format_code_t sformat = (i == 0)? PIXMAN_a8r8g8b8 : PIXMAN_a2r10g10b10; 22 pixman_image_t *s = pixman_image_create_bits (sformat, WIDTH, HEIGHT, src, WIDTH * 4); 23 int j, k; 24 25 pixman_image_set_alpha_map (s, a, 0, 0); 26 27 pixman_image_composite (PIXMAN_OP_SRC, s, NULL, d, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); 28 29 for (j = 0; j < HEIGHT; ++j) 30 { 31 for (k = 0; k < WIDTH; ++k) 32 { 33 uint8_t ap = ((uint8_t *)alpha)[j * WIDTH + k]; 34 uint32_t dap = (dest[j * WIDTH + k] >> 24); 35 uint32_t sap = (src[j * WIDTH + k] >> 24); 36 37 if (ap != dap) 38 { 39 printf ("Wrong alpha value at (%d, %d). Should be %d; got %d (src was %d)\n", k, j, ap, dap, sap); 40 return 1; 41 } 42 } 43 } 44 45 pixman_image_unref (s); 46 } 47 48 return 0; 49} 50