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 | #include "iff.h" |
||
12 | |||
13 | extern int parse_iff(FILE *ifile,struct bitmap_header *bitmap_header); |
||
14 | |||
15 | int x,y,pl,bc; |
||
16 | int bytes_per_row,color; |
||
17 | int mask,first_bit_value; |
||
18 | FILE *ifile; |
||
19 | struct bitmap_header iff_bitmap_header; |
||
20 | |||
21 | // Parse ilbm style data at my_bh->raw_data. |
||
22 | BITMAP8 * IFF_To_8BPP(char * ifilename) |
||
23 | { |
||
24 | struct bitmap_header * my_bh; |
||
25 | int Process_width,Process_height; |
||
26 | unsigned char *p; |
||
27 | struct pal_entry *palptr; |
||
28 | int newptr = 0; |
||
29 | int i; |
||
30 | BITMAP8 * new; |
||
31 | |||
32 | my_bh = &iff_bitmap_header; |
||
33 | palptr=my_bh->palette; |
||
34 | p=my_bh->raw_data; |
||
35 | |||
36 | Process_width = 32767; // say to process full width of bitmap |
||
37 | Process_height = 32767; // say to process full height of bitmap |
||
38 | |||
39 | if ((ifile = fopen(ifilename,"rb")) == NULL) { |
||
40 | printf("Unable to open bitmap file %s.\n", ifilename); |
||
41 | exit(1); |
||
42 | } |
||
43 | |||
44 | parse_iff(ifile,&iff_bitmap_header); |
||
45 | if (Process_width > iff_bitmap_header.w) |
||
46 | Process_width = iff_bitmap_header.w; |
||
47 | |||
48 | if (Process_height > iff_bitmap_header.h) |
||
49 | Process_height = iff_bitmap_header.h; |
||
50 | |||
51 | printf( "%d, %d\n", Process_width, Process_height ); |
||
52 | |||
53 | new = (BITMAP8 *)malloc( sizeof(BITMAP8)+ (Process_width * Process_height ) ); |
||
54 | if (new==NULL) exit(1); |
||
55 | |||
56 | new->Width = Process_width; |
||
57 | new->Height = Process_height; |
||
58 | for (i=0;i<256;i++) { |
||
59 | new->Palette[3*i] = my_bh->palette[i].r; |
||
60 | new->Palette[3*i+1] = my_bh->palette[i].g; |
||
61 | new->Palette[3*i+2] = my_bh->palette[i].b; |
||
62 | } |
||
63 | printf("Process_width = %i, Process_height = %i\n",Process_width,Process_height); |
||
64 | first_bit_value = 1 << (my_bh->nplanes-1); |
||
65 | bytes_per_row = 2*((my_bh->w+15)/16); |
||
66 | for (y=0; y<Process_height; y++) { |
||
67 | bc = Process_width; |
||
68 | p = &my_bh->raw_data[y*bytes_per_row*my_bh->nplanes]; |
||
69 | |||
70 | switch (my_bh->type) { |
||
71 | case PBM_TYPE: |
||
72 | for (x=0; x<my_bh->w; x++) { |
||
73 | new->Data[newptr++] = my_bh->raw_data[y*my_bh->w+x]; |
||
74 | } |
||
75 | break; |
||
76 | case ILBM_TYPE: |
||
77 | for (x=0; x<bytes_per_row; x++) { |
||
78 | for (mask=128; mask; mask /=2) { |
||
79 | color = 0; |
||
80 | for (pl=0; pl<my_bh->nplanes; pl++) { |
||
81 | color /= 2; |
||
82 | if ( p[pl*bytes_per_row+x] & mask) |
||
83 | color += first_bit_value; |
||
84 | } |
||
85 | new->Data[newptr++] = color; |
||
86 | bc--; |
||
87 | if (!bc) |
||
88 | goto line_done; |
||
89 | } |
||
90 | } |
||
91 | line_done: ; |
||
92 | break; |
||
93 | } |
||
94 | } |
||
95 | free( my_bh->raw_data ); |
||
96 | fclose(ifile); |
||
97 | return new; |
||
98 | } |
||
99 | |||
100 | ÿ |