bitblt_test.c

Mon, 14 Dec 2009 16:18:21 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 14 Dec 2009 16:18:21 +0000
changeset 172
2fae6df568f6
parent 137
ce565d98baf3
permissions
-rw-r--r--

remove erroneous 0.33-philpem1 tag

eric@48 1 #include <stdbool.h>
eric@48 2 #include <stdint.h>
eric@2 3 #include <stdio.h>
eric@43 4 #include <stdlib.h>
eric@2 5
eric@2 6 #include "bitblt.h"
eric@2 7
eric@2 8
eric@137 9 #define WIDTH 44
eric@2 10 #define HEIGHT 9
eric@2 11
eric@2 12 char test_data [HEIGHT][WIDTH] =
eric@2 13 {
eric@137 14 ".....XXXXXXXXXX.......XX............X......X",
eric@137 15 ".....XX.......X.......X.X..........X......X.",
eric@137 16 "XXXXXX.X......XXXXXX..X..X........X......X..",
eric@137 17 ".....X..X.....X.......XX.........X......X...",
eric@137 18 ".....X...X....X.......X.X.......X......X....",
eric@137 19 ".....X....X...X.......X..X.....X......X.....",
eric@137 20 ".....X.....X..X.......XX..... X......X......",
eric@137 21 ".....XXXXXXXXXX.......X.X....X......X.......",
eric@137 22 ".....X.X.X.X.X........X..X..X......X........"
eric@2 23 };
eric@2 24
eric@2 25 Bitmap *setup (void)
eric@2 26 {
eric@2 27 Bitmap *b;
eric@2 28 Point p;
eric@43 29 Rect r = {{ 0, 0 }, { WIDTH, HEIGHT }};
eric@2 30
eric@43 31 b = create_bitmap (& r);
eric@2 32 if (! b)
eric@2 33 return (NULL);
eric@2 34
eric@2 35 for (p.y = 0; p.y < HEIGHT; p.y++)
eric@2 36 for (p.x = 0; p.x < WIDTH; p.x++)
eric@2 37 set_pixel (b, p, test_data [p.y][p.x] == 'X');
eric@2 38
eric@2 39 return (b);
eric@2 40 }
eric@2 41
eric@2 42 void print_bitmap (FILE *o, Bitmap *b)
eric@2 43 {
eric@2 44 Point p;
eric@43 45 printf ("row_words: %d\n", b->row_words);
eric@43 46 for (p.y = b->rect.min.y; p.y < b->rect.max.y; p.y++)
eric@2 47 {
eric@43 48 for (p.x = b->rect.min.x; p.x < b->rect.max.x; p.x++)
eric@2 49 fputc (".X" [get_pixel (b, p)], o);
eric@2 50 fprintf (o, "\n");
eric@2 51 }
eric@2 52 }
eric@2 53
eric@2 54
eric@2 55 int main (int argc, char *argv[])
eric@2 56 {
eric@2 57 Bitmap *b;
eric@2 58 Bitmap *b2;
eric@2 59 Rect r;
eric@2 60 Point p;
eric@2 61
eric@2 62 b = setup ();
eric@2 63 if (! b)
eric@2 64 {
eric@2 65 fprintf (stderr, "setup failed\n");
eric@2 66 exit (2);
eric@2 67 }
eric@2 68
eric@2 69 print_bitmap (stdout, b);
eric@43 70 printf ("\n");
eric@2 71
eric@43 72 flip_v (b);
eric@43 73
eric@137 74 printf ("flipped vertically:\n");
eric@43 75 print_bitmap (stdout, b);
eric@43 76 printf ("\n");
eric@43 77
eric@43 78 flip_h (b);
eric@43 79
eric@137 80 printf ("flipped horizontally:\n");
eric@43 81 print_bitmap (stdout, b);
eric@2 82 printf ("\n");
eric@2 83
eric@47 84 #if 1
eric@47 85 r.min.x = r.min.y = 0;
eric@47 86 r.max.x = b->rect.max.x + 8;
eric@47 87 r.max.y = b->rect.max.y + 8;
eric@47 88
eric@47 89 b2 = create_bitmap (& r);
eric@2 90
eric@47 91 r.min.x = r.min.y = 0;
eric@47 92 r.max.x = b->rect.max.x;
eric@47 93 r.max.y = b->rect.max.y;
eric@47 94
eric@47 95 p.x = -3;
eric@47 96 p.y = -3;
eric@47 97
eric@47 98 b2 = bitblt (b, & r,
eric@47 99 b2, & p,
eric@47 100 TF_SRC, 0);
eric@2 101 if (! b2)
eric@2 102 {
eric@2 103 fprintf (stderr, "bitblt failed\n");
eric@2 104 exit (2);
eric@2 105 }
eric@2 106
eric@137 107 printf ("after bitblt\n");
eric@2 108 print_bitmap (stdout, b2);
eric@43 109 #endif
eric@2 110
eric@2 111 exit (0);
eric@2 112 }
eric@2 113
eric@2 114