7 extern int parse_iff(FILE *ifile,struct bitmap_header *bitmap_header);
10 int bytes_per_row,color;
11 int mask,first_bit_value;
13 struct bitmap_header iff_bitmap_header;
15 // Parse ilbm style data at my_bh->raw_data.
16 BITMAP8 * IFF_To_8BPP(char * ifilename)
18 struct bitmap_header * my_bh;
19 int Process_width,Process_height;
21 struct pal_entry *palptr;
26 my_bh = &iff_bitmap_header;
27 palptr=my_bh->palette;
30 Process_width = 32767; // say to process full width of bitmap
31 Process_height = 32767; // say to process full height of bitmap
33 if ((ifile = fopen(ifilename,"rb")) == NULL) {
34 printf("Unable to open bitmap file %s.\n", ifilename);
38 parse_iff(ifile,&iff_bitmap_header);
39 if (Process_width > iff_bitmap_header.w)
40 Process_width = iff_bitmap_header.w;
42 if (Process_height > iff_bitmap_header.h)
43 Process_height = iff_bitmap_header.h;
45 printf( "%d, %d\n", Process_width, Process_height );
47 new = (BITMAP8 *)malloc( sizeof(BITMAP8)+ (Process_width * Process_height ) );
48 if (new==NULL) exit(1);
50 new->Width = Process_width;
51 new->Height = Process_height;
53 new->Palette[3*i] = my_bh->palette[i].r;
54 new->Palette[3*i+1] = my_bh->palette[i].g;
55 new->Palette[3*i+2] = my_bh->palette[i].b;
57 printf("Process_width = %i, Process_height = %i\n",Process_width,Process_height);
58 first_bit_value = 1 << (my_bh->nplanes-1);
59 bytes_per_row = 2*((my_bh->w+15)/16);
60 for (y=0; y<Process_height; y++) {
62 p = &my_bh->raw_data[y*bytes_per_row*my_bh->nplanes];
64 switch (my_bh->type) {
66 for (x=0; x<my_bh->w; x++) {
67 new->Data[newptr++] = my_bh->raw_data[y*my_bh->w+x];
71 for (x=0; x<bytes_per_row; x++) {
72 for (mask=128; mask; mask /=2) {
74 for (pl=0; pl<my_bh->nplanes; pl++) {
76 if ( p[pl*bytes_per_row+x] & mask)
77 color += first_bit_value;
79 new->Data[newptr++] = color;
89 free( my_bh->raw_data );