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

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