bitblt_test.c

Mon, 26 Aug 2002 05:43:49 +0000

author
eric
date
Mon, 26 Aug 2002 05:43:49 +0000
changeset 47
bfc6aaa089b0
parent 43
b80cb5a4282a
child 48
3d0be1c1c1b2
permissions
-rw-r--r--

fixed 'middle-endian' output from TIFFReadScanline

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