bitblt_test.c

Thu, 20 Feb 2003 12:20:28 +0000

author
eric
date
Thu, 20 Feb 2003 12:20:28 +0000
changeset 60
ffb5b1e54eb2
parent 48
3d0be1c1c1b2
child 137
ce565d98baf3
permissions
-rw-r--r--

fix includes.

     1 #include <stdbool.h>
     2 #include <stdint.h>
     3 #include <stdio.h>
     4 #include <stdlib.h>
     6 #include "bitblt.h"
     9 #define WIDTH 20
    10 #define HEIGHT 9
    12 char test_data [HEIGHT][WIDTH] =
    13 {
    14   ".....XXXXXXXXXX.....",
    15   ".....XX.......X.....",
    16   "XXXXXX.X......XXXXXX",
    17   ".....X..X.....X.....",
    18   ".....X...X....X.....",
    19   ".....X....X...X.....",
    20   ".....X.....X..X.....",
    21   ".....XXXXXXXXXX.....",
    22   ".....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   print_bitmap (stdout, b);
    75   printf ("\n");
    77   flip_h (b);
    79   print_bitmap (stdout, b);
    80   printf ("\n");
    82 #if 1
    83   r.min.x = r.min.y = 0;
    84   r.max.x = b->rect.max.x + 8;
    85   r.max.y = b->rect.max.y + 8;
    87   b2 = create_bitmap (& r);
    89   r.min.x = r.min.y = 0;
    90   r.max.x = b->rect.max.x;
    91   r.max.y = b->rect.max.y;
    93   p.x = -3;
    94   p.y = -3;
    96   b2 = bitblt (b, & r,
    97 	       b2, & p,
    98 	       TF_SRC, 0);
    99   if (! b2)
   100     {
   101       fprintf (stderr, "bitblt failed\n");
   102       exit (2);
   103     }
   105   print_bitmap (stdout, b2);
   106 #endif
   108   exit (0);
   109 }