]>
Commit | Line | Data |
---|---|---|
7d1d0aae PG |
1 | --- gdk-pixbuf-0.22.0/gdk-pixbuf/io-bmp.c.bmp-colormap 2002-09-27 17:12:40.000000000 -0400 |
2 | +++ gdk-pixbuf-0.22.0/gdk-pixbuf/io-bmp.c 2004-03-03 08:58:43.000000000 -0500 | |
3 | @@ -129,6 +129,7 @@ | |
4 | guint depth; | |
5 | guint Negative; /* Negative = 1 -> top down BMP, | |
6 | Negative = 0 -> bottom up BMP */ | |
7 | + guint n_colors; | |
8 | }; | |
9 | ||
10 | /* Data needed for the "state" during decompression */ | |
11 | @@ -153,8 +154,8 @@ | |
12 | guint Lines; /* # of finished lines */ | |
13 | ||
14 | guchar *buff; | |
15 | - gint BufferSize; | |
16 | - gint BufferDone; | |
17 | + guint BufferSize; | |
18 | + guint BufferDone; | |
19 | ||
20 | guchar (*Colormap)[3]; | |
21 | ||
22 | @@ -258,6 +259,8 @@ | |
23 | DecodeHeader (unsigned char *BFH, unsigned char *BIH, | |
24 | struct bmp_progressive_state *State) | |
25 | { | |
26 | + gint clrUsed; | |
27 | + | |
28 | g_assert (State->read_state == READ_STATE_HEADERS); | |
29 | ||
30 | /* FIXME this is totally unrobust against bogus image data. */ | |
31 | @@ -295,6 +298,23 @@ | |
32 | return FALSE; | |
33 | } | |
34 | ||
35 | + clrUsed = (int) (BIH[35] << 24) + (BIH[34] << 16) + (BIH[33] << 8) + (BIH[32]); | |
36 | + if (clrUsed != 0) | |
37 | + State->Header.n_colors = clrUsed; | |
38 | + else | |
39 | + State->Header.n_colors = 1 << State->Header.depth; | |
40 | + | |
41 | + if (State->Header.n_colors > 1 << State->Header.depth) { | |
42 | +#if 0 | |
43 | + g_set_error (error, | |
44 | + GDK_PIXBUF_ERROR, | |
45 | + GDK_PIXBUF_ERROR_CORRUPT_IMAGE, | |
46 | + _("BMP image has bogus header data")); | |
47 | +#endif | |
48 | + State->read_state = READ_STATE_ERROR; | |
49 | + return FALSE; | |
50 | + } | |
51 | + | |
52 | State->Type = State->Header.depth; /* This may be less trivial someday */ | |
53 | ||
54 | /* Negative heights indicates bottom-down pixelorder */ | |
55 | @@ -422,16 +442,25 @@ | |
56 | struct bmp_progressive_state *State) | |
57 | { | |
58 | gint i; | |
59 | - | |
60 | + gint samples; | |
61 | + | |
62 | g_assert (State->read_state == READ_STATE_PALETTE); | |
63 | ||
64 | + samples = (State->Header.size == 12 ? 3 : 4); | |
65 | + if (State->BufferSize < State->Header.n_colors * samples) { | |
66 | + State->BufferSize = State->Header.n_colors * samples; | |
67 | + if (!grow_buffer (State)) | |
68 | + return FALSE; | |
69 | + return TRUE; | |
70 | + } | |
71 | + | |
72 | State->Colormap = g_malloc ((1 << State->Header.depth) * sizeof (*State->Colormap)); | |
73 | ||
74 | - for (i = 0; i < (1 << State->Header.depth); i++) | |
75 | + for (i = 0; i < State->Header.n_colors; i++) | |
76 | { | |
77 | - State->Colormap[i][0] = buff[i * (State->Header.size == 12 ? 3 : 4)]; | |
78 | - State->Colormap[i][1] = buff[i * (State->Header.size == 12 ? 3 : 4) + 1]; | |
79 | - State->Colormap[i][2] = buff[i * (State->Header.size == 12 ? 3 : 4) + 2]; | |
80 | + State->Colormap[i][0] = buff[i * samples]; | |
81 | + State->Colormap[i][1] = buff[i * samples + 1]; | |
82 | + State->Colormap[i][2] = buff[i * samples + 2]; | |
83 | } | |
84 | ||
85 | State->read_state = READ_STATE_DATA; |