8 #define INDEX_TO_15BPP(i) ((WORD)((((palptr[(i)].r/2)&31)<<10)+(((palptr[(i)].g/2)&31)<<5)+((palptr[(i)].b/2 )&31)))
10 extern int parse_iff(FILE *ifile,struct bitmap_header *bitmap_header);
13 int bytes_per_row,color;
14 int mask,first_bit_value;
16 struct bitmap_header iff_bitmap_header;
18 // Parse ilbm style data at my_bh->raw_data.
19 BITMAP15 * IFF_To_15BPP(char * ifilename)
21 struct bitmap_header * my_bh;
22 int Process_width,Process_height;
24 struct pal_entry *palptr;
29 my_bh = &iff_bitmap_header;
30 palptr=my_bh->palette;
33 Process_width = 32767; // say to process full width of bitmap
34 Process_height = 32767; // say to process full height of bitmap
36 if ((ifile = fopen(ifilename,"rb")) == NULL) {
37 printf("Unable to open bitmap file %s.\n", ifilename);
41 parse_iff(ifile,&iff_bitmap_header);
42 if (Process_width > iff_bitmap_header.w)
43 Process_width = iff_bitmap_header.w;
45 if (Process_height > iff_bitmap_header.h)
46 Process_height = iff_bitmap_header.h;
48 //printf( "%d, %d\n", Process_width, Process_height );
50 new = (BITMAP15 *)malloc( sizeof(BITMAP15)+ (Process_width * Process_height * 2 ));
51 if (new==NULL) exit(1);
53 new->Width = Process_width;
54 new->Height = Process_height;
56 //printf("Process_width = %i, Process_height = %i\n",Process_width,Process_height);
57 first_bit_value = 1 << (my_bh->nplanes-1);
58 bytes_per_row = 2*((my_bh->w+15)/16);
59 for (y=0; y<Process_height; y++) {
61 p = &my_bh->raw_data[y*bytes_per_row*my_bh->nplanes];
63 switch (my_bh->type) {
65 for (x=0; x<my_bh->w; x++) {
66 new->Data[newptr++] = INDEX_TO_15BPP(my_bh->raw_data[y*my_bh->w+x]);
70 for (x=0; x<bytes_per_row; x++) {
71 for (mask=128; mask; mask /=2) {
73 for (pl=0; pl<my_bh->nplanes; pl++) {
75 if ( p[pl*bytes_per_row+x] & mask)
76 color += first_bit_value;
78 new->Data[newptr++] = INDEX_TO_15BPP(color);
88 free( my_bh->raw_data );