Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
3 | * It is copyright by its individual contributors, as recorded in the |
||
4 | * project's Git history. See COPYING.txt at the top level for license |
||
5 | * terms and a link to the Git history. |
||
6 | */ |
||
7 | #include <stdio.h> |
||
8 | #include <stdlib.h> |
||
9 | #include <malloc.h> |
||
10 | |||
11 | |||
12 | #include "iff.h" |
||
13 | |||
14 | #define INDEX_TO_15BPP(i) ((WORD)((((palptr[(i)].r/2)&31)<<10)+(((palptr[(i)].g/2)&31)<<5)+((palptr[(i)].b/2 )&31))) |
||
15 | |||
16 | extern int parse_iff(FILE *ifile,struct bitmap_header *bitmap_header); |
||
17 | |||
18 | int x,y,pl,bc; |
||
19 | int bytes_per_row,color; |
||
20 | int mask,first_bit_value; |
||
21 | FILE *ifile; |
||
22 | struct bitmap_header iff_bitmap_header; |
||
23 | |||
24 | // Parse ilbm style data at my_bh->raw_data. |
||
25 | BITMAP15 * IFF_To_15BPP(char * ifilename) |
||
26 | { |
||
27 | struct bitmap_header * my_bh; |
||
28 | int Process_width,Process_height; |
||
29 | unsigned char *p; |
||
30 | struct pal_entry *palptr; |
||
31 | int newptr = 0; |
||
32 | int i; |
||
33 | BITMAP15 * new; |
||
34 | |||
35 | my_bh = &iff_bitmap_header; |
||
36 | palptr=my_bh->palette; |
||
37 | p=my_bh->raw_data; |
||
38 | |||
39 | Process_width = 32767; // say to process full width of bitmap |
||
40 | Process_height = 32767; // say to process full height of bitmap |
||
41 | |||
42 | if ((ifile = fopen(ifilename,"rb")) == NULL) { |
||
43 | printf("Unable to open bitmap file %s.\n", ifilename); |
||
44 | exit(1); |
||
45 | } |
||
46 | |||
47 | parse_iff(ifile,&iff_bitmap_header); |
||
48 | if (Process_width > iff_bitmap_header.w) |
||
49 | Process_width = iff_bitmap_header.w; |
||
50 | |||
51 | if (Process_height > iff_bitmap_header.h) |
||
52 | Process_height = iff_bitmap_header.h; |
||
53 | |||
54 | //printf( "%d, %d\n", Process_width, Process_height ); |
||
55 | |||
56 | new = (BITMAP15 *)malloc( sizeof(BITMAP15)+ (Process_width * Process_height * 2 )); |
||
57 | if (new==NULL) exit(1); |
||
58 | |||
59 | new->Width = Process_width; |
||
60 | new->Height = Process_height; |
||
61 | |||
62 | //printf("Process_width = %i, Process_height = %i\n",Process_width,Process_height); |
||
63 | first_bit_value = 1 << (my_bh->nplanes-1); |
||
64 | bytes_per_row = 2*((my_bh->w+15)/16); |
||
65 | for (y=0; y<Process_height; y++) { |
||
66 | bc = Process_width; |
||
67 | p = &my_bh->raw_data[y*bytes_per_row*my_bh->nplanes]; |
||
68 | |||
69 | switch (my_bh->type) { |
||
70 | case PBM_TYPE: |
||
71 | for (x=0; x<my_bh->w; x++) { |
||
72 | new->Data[newptr++] = INDEX_TO_15BPP(my_bh->raw_data[y*my_bh->w+x]); |
||
73 | } |
||
74 | break; |
||
75 | case ILBM_TYPE: |
||
76 | for (x=0; x<bytes_per_row; x++) { |
||
77 | for (mask=128; mask; mask /=2) { |
||
78 | color = 0; |
||
79 | for (pl=0; pl<my_bh->nplanes; pl++) { |
||
80 | color /= 2; |
||
81 | if ( p[pl*bytes_per_row+x] & mask) |
||
82 | color += first_bit_value; |
||
83 | } |
||
84 | new->Data[newptr++] = INDEX_TO_15BPP(color); |
||
85 | bc--; |
||
86 | if (!bc) |
||
87 | goto line_done; |
||
88 | } |
||
89 | } |
||
90 | line_done: ; |
||
91 | break; |
||
92 | } |
||
93 | } |
||
94 | free( my_bh->raw_data ); |
||
95 | return new; |
||
96 | } |
||
97 | |||
98 | ÿ |