1 | /* |
1 | /* |
2 | |
|
|
3 | generate_image.c - Part of psiconv, a PSION 5 file formats converter |
2 | generate_image.c - Part of psiconv, a PSION 5 file formats converter |
4 | Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl> |
5 | |
4 | |
6 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
22 | #include "compat.h" |
21 | #include "compat.h" |
23 | |
22 | |
24 | #include "generate_routines.h" |
23 | #include "generate_routines.h" |
25 | #include "error.h" |
24 | #include "error.h" |
26 | #include "list.h" |
25 | #include "list.h" |
|
|
26 | #include "image.h" |
27 | |
27 | |
28 | #ifdef DMALLOC |
28 | #ifdef DMALLOC |
29 | #include <dmalloc.h> |
29 | #include <dmalloc.h> |
30 | #endif |
30 | #endif |
31 | |
31 | |
32 | typedef psiconv_list psiconv_pixel_bytes; /* psiconv_u8 */ |
|
|
33 | |
|
|
34 | typedef psiconv_list psiconv_pixel_ints; /* of psiconv_u32 */ |
|
|
35 | |
|
|
36 | typedef struct psiconv_pixel_float_s |
|
|
37 | { |
|
|
38 | psiconv_u32 length; |
|
|
39 | float *red; |
|
|
40 | float *green; |
|
|
41 | float *blue; |
|
|
42 | } psiconv_pixel_floats_t; |
|
|
43 | |
32 | |
44 | static int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels, |
33 | static int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels, |
45 | int xsize,int ysize, |
34 | int xsize,int ysize, |
46 | const psiconv_pixel_floats_t data, |
35 | const psiconv_pixel_floats_t data, |
47 | int colordepth,int color, |
36 | int colordepth,int color, |
48 | int redbits,int greenbits,int bluebits, |
37 | int redbits,int greenbits,int bluebits, |
49 | const psiconv_pixel_floats_t palet); |
38 | const psiconv_pixel_floats_t palet); |
50 | static int psiconv_pixel_data_to_bytes(const psiconv_config config, |
39 | static int psiconv_pixel_data_to_bytes(const psiconv_config config,int lev, |
51 | psiconv_pixel_bytes *bytes, int xsize, |
40 | psiconv_pixel_bytes *bytes, int xsize, |
52 | int ysize, const psiconv_pixel_ints pixels, |
41 | int ysize, const psiconv_pixel_ints pixels, |
53 | int colordepth); |
42 | int colordepth); |
54 | static int psiconv_encode_rle8(const psiconv_config config, |
43 | static int psiconv_encode_rle8(const psiconv_config config, |
55 | const psiconv_pixel_bytes plain_bytes, |
44 | const psiconv_pixel_bytes plain_bytes, |
… | |
… | |
62 | psiconv_pixel_bytes *encoded_bytes); |
51 | psiconv_pixel_bytes *encoded_bytes); |
63 | static int psiconv_encode_rle24(const psiconv_config config, |
52 | static int psiconv_encode_rle24(const psiconv_config config, |
64 | const psiconv_pixel_bytes plain_bytes, |
53 | const psiconv_pixel_bytes plain_bytes, |
65 | psiconv_pixel_bytes *encoded_bytes); |
54 | psiconv_pixel_bytes *encoded_bytes); |
66 | |
55 | |
67 | #define PALET_NONE_LEN 0 |
|
|
68 | |
|
|
69 | psiconv_pixel_floats_t palet_none = |
|
|
70 | { |
|
|
71 | PALET_NONE_LEN, |
|
|
72 | NULL, |
|
|
73 | NULL, |
|
|
74 | NULL |
|
|
75 | }; |
|
|
76 | |
|
|
77 | #define PALET_COLOR_4_LEN 16 |
|
|
78 | float palet_color_4_red[PALET_COLOR_4_LEN] = |
|
|
79 | { 0x00/256.0, 0x55/256.0, 0x80/256.0, 0x80/256.0, /* 0x00 */ |
|
|
80 | 0x00/256.0, 0xff/256.0, 0x00/256.0, 0xff/256.0, /* 0x04 */ |
|
|
81 | 0xff/256.0, 0x00/256.0, 0x00/256.0, 0x80/256.0, /* 0x08 */ |
|
|
82 | 0x00/256.0, 0x00/256.0, 0xaa/256.0, 0xff/256.0 /* 0x0c */ |
|
|
83 | }; |
|
|
84 | |
|
|
85 | float palet_color_4_green[PALET_COLOR_4_LEN] = |
|
|
86 | { 0x00/256.0, 0x55/256.0, 0x00/256.0, 0x80/256.0, /* 0x00 */ |
|
|
87 | 0x80/256.0, 0x00/256.0, 0xff/256.0, 0xff/256.0, /* 0x04 */ |
|
|
88 | 0x00/256.0, 0xff/256.0, 0xff/256.0, 0x00/256.0, /* 0x08 */ |
|
|
89 | 0x00/256.0, 0x80/256.0, 0xaa/256.0, 0xff/256.0 /* 0x0c */ |
|
|
90 | }; |
|
|
91 | |
|
|
92 | float palet_color_4_blue[PALET_COLOR_4_LEN] = |
|
|
93 | { 0x00/256.0, 0x55/256.0, 0x00/256.0, 0x00/256.0, /* 0x00 */ |
|
|
94 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x04 */ |
|
|
95 | 0xff/256.0, 0x00/256.0, 0xff/256.0, 0x80/256.0, /* 0x08 */ |
|
|
96 | 0x80/256.0, 0x80/256.0, 0xaa/256.0, 0xff/256.0 /* 0x0c */ |
|
|
97 | }; |
|
|
98 | |
|
|
99 | psiconv_pixel_floats_t palet_color_4 = |
|
|
100 | { |
|
|
101 | PALET_COLOR_4_LEN, |
|
|
102 | palet_color_4_red, |
|
|
103 | palet_color_4_green, |
|
|
104 | palet_color_4_blue, |
|
|
105 | }; |
|
|
106 | |
|
|
107 | #define PALET_COLOR_8_LEN 256 |
|
|
108 | float palet_color_8_red[PALET_COLOR_8_LEN] = |
|
|
109 | { 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x00 */ |
|
|
110 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x04 */ |
|
|
111 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x08 */ |
|
|
112 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x0c */ |
|
|
113 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x10 */ |
|
|
114 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x14 */ |
|
|
115 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x18 */ |
|
|
116 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x1c */ |
|
|
117 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x20 */ |
|
|
118 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x24 */ |
|
|
119 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x28 */ |
|
|
120 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x2c */ |
|
|
121 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x30 */ |
|
|
122 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x34 */ |
|
|
123 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x38 */ |
|
|
124 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x3c */ |
|
|
125 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x40 */ |
|
|
126 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x44 */ |
|
|
127 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x48 */ |
|
|
128 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x4c */ |
|
|
129 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x50 */ |
|
|
130 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x54 */ |
|
|
131 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x58 */ |
|
|
132 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x5c */ |
|
|
133 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x60 */ |
|
|
134 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x64 */ |
|
|
135 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x68 */ |
|
|
136 | 0x11/256.0, 0x22/256.0, 0x44/256.0, 0x55/256.0, /* 0x6c */ |
|
|
137 | 0x77/256.0, 0x11/256.0, 0x22/256.0, 0x44/256.0, /* 0x70 */ |
|
|
138 | 0x55/256.0, 0x77/256.0, 0x00/256.0, 0x00/256.0, /* 0x74 */ |
|
|
139 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x78 */ |
|
|
140 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x7c */ |
|
|
141 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x80 */ |
|
|
142 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x84 */ |
|
|
143 | 0x00/256.0, 0x00/256.0, 0x88/256.0, 0xaa/256.0, /* 0x88 */ |
|
|
144 | 0xbb/256.0, 0xdd/256.0, 0xee/256.0, 0x88/256.0, /* 0x8c */ |
|
|
145 | 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, 0xee/256.0, /* 0x90 */ |
|
|
146 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0x94 */ |
|
|
147 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0x98 */ |
|
|
148 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0x9c */ |
|
|
149 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xa0 */ |
|
|
150 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xa4 */ |
|
|
151 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xa8 */ |
|
|
152 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xac */ |
|
|
153 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xb0 */ |
|
|
154 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xb4 */ |
|
|
155 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xb8 */ |
|
|
156 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xbc */ |
|
|
157 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xc0 */ |
|
|
158 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xc4 */ |
|
|
159 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xc8 */ |
|
|
160 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xcc */ |
|
|
161 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xd0 */ |
|
|
162 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xd4 */ |
|
|
163 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xd8 */ |
|
|
164 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xdc */ |
|
|
165 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xe0 */ |
|
|
166 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xe4 */ |
|
|
167 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xe8 */ |
|
|
168 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xec */ |
|
|
169 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0, /* 0xf0 */ |
|
|
170 | 0x00/256.0, 0x33/256.0, 0x66/256.0, 0x99/256.0, /* 0xf4 */ |
|
|
171 | 0xcc/256.0, 0xff/256.0, 0x00/256.0, 0x33/256.0, /* 0xf8 */ |
|
|
172 | 0x66/256.0, 0x99/256.0, 0xcc/256.0, 0xff/256.0 /* 0xfc */ |
|
|
173 | }; |
|
|
174 | |
|
|
175 | float palet_color_8_green[PALET_COLOR_8_LEN] = |
|
|
176 | { 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x00 */ |
|
|
177 | 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x04 */ |
|
|
178 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x08 */ |
|
|
179 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x0c */ |
|
|
180 | 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0x10 */ |
|
|
181 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x14 */ |
|
|
182 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0x18 */ |
|
|
183 | 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0x1c */ |
|
|
184 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0x20 */ |
|
|
185 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x24 */ |
|
|
186 | 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x28 */ |
|
|
187 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x2c */ |
|
|
188 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x30 */ |
|
|
189 | 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0x34 */ |
|
|
190 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x38 */ |
|
|
191 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0x3c */ |
|
|
192 | 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0x40 */ |
|
|
193 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0x44 */ |
|
|
194 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x48 */ |
|
|
195 | 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x4c */ |
|
|
196 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x50 */ |
|
|
197 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x54 */ |
|
|
198 | 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0x58 */ |
|
|
199 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x5c */ |
|
|
200 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0x60 */ |
|
|
201 | 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0x64 */ |
|
|
202 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0x68 */ |
|
|
203 | 0x11/256.0, 0x22/256.0, 0x44/256.0, 0x55/256.0, /* 0x6c */ |
|
|
204 | 0x77/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x70 */ |
|
|
205 | 0x00/256.0, 0x00/256.0, 0x11/256.0, 0x22/256.0, /* 0x74 */ |
|
|
206 | 0x44/256.0, 0x55/256.0, 0x77/256.0, 0x00/256.0, /* 0x78 */ |
|
|
207 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x7c */ |
|
|
208 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x80 */ |
|
|
209 | 0x00/256.0, 0x88/256.0, 0xaa/256.0, 0xbb/256.0, /* 0x84 */ |
|
|
210 | 0xdd/256.0, 0xee/256.0, 0x00/256.0, 0x00/256.0, /* 0x88 */ |
|
|
211 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x88/256.0, /* 0x8c */ |
|
|
212 | 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, 0xee/256.0, /* 0x90 */ |
|
|
213 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x94 */ |
|
|
214 | 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0x98 */ |
|
|
215 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x9c */ |
|
|
216 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0xa0 */ |
|
|
217 | 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0xa4 */ |
|
|
218 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa8 */ |
|
|
219 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xac */ |
|
|
220 | 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0xb0 */ |
|
|
221 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xb4 */ |
|
|
222 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0xb8 */ |
|
|
223 | 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0xbc */ |
|
|
224 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0xc0 */ |
|
|
225 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0xc4 */ |
|
|
226 | 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0xc8 */ |
|
|
227 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xcc */ |
|
|
228 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd0 */ |
|
|
229 | 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0xd4 */ |
|
|
230 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xd8 */ |
|
|
231 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0xdc */ |
|
|
232 | 0x00/256.0, 0x00/256.0, 0x33/256.0, 0x33/256.0, /* 0xe0 */ |
|
|
233 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0xe4 */ |
|
|
234 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0xe8 */ |
|
|
235 | 0x66/256.0, 0x66/256.0, 0x99/256.0, 0x99/256.0, /* 0xec */ |
|
|
236 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xf0 */ |
|
|
237 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xf4 */ |
|
|
238 | 0xcc/256.0, 0xcc/256.0, 0xff/256.0, 0xff/256.0, /* 0xf8 */ |
|
|
239 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xfc */ |
|
|
240 | }; |
|
|
241 | |
|
|
242 | float palet_color_8_blue[PALET_COLOR_8_LEN] = |
|
|
243 | { 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x00 */ |
|
|
244 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x04 */ |
|
|
245 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x08 */ |
|
|
246 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x0c */ |
|
|
247 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x10 */ |
|
|
248 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x14 */ |
|
|
249 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x18 */ |
|
|
250 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x1c */ |
|
|
251 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x20 */ |
|
|
252 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x24 */ |
|
|
253 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x28 */ |
|
|
254 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x2c */ |
|
|
255 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x30 */ |
|
|
256 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x34 */ |
|
|
257 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x38 */ |
|
|
258 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x3c */ |
|
|
259 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x40 */ |
|
|
260 | 0x33/256.0, 0x33/256.0, 0x33/256.0, 0x33/256.0, /* 0x44 */ |
|
|
261 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x48 */ |
|
|
262 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x4c */ |
|
|
263 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x50 */ |
|
|
264 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x54 */ |
|
|
265 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x58 */ |
|
|
266 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x5c */ |
|
|
267 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x60 */ |
|
|
268 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x64 */ |
|
|
269 | 0x66/256.0, 0x66/256.0, 0x66/256.0, 0x66/256.0, /* 0x68 */ |
|
|
270 | 0x11/256.0, 0x22/256.0, 0x44/256.0, 0x55/256.0, /* 0x6c */ |
|
|
271 | 0x77/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x70 */ |
|
|
272 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x74 */ |
|
|
273 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x11/256.0, /* 0x78 */ |
|
|
274 | 0x22/256.0, 0x44/256.0, 0x55/256.0, 0x77/256.0, /* 0x7c */ |
|
|
275 | 0x88/256.0, 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, /* 0x80 */ |
|
|
276 | 0xee/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x84 */ |
|
|
277 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x00/256.0, /* 0x88 */ |
|
|
278 | 0x00/256.0, 0x00/256.0, 0x00/256.0, 0x88/256.0, /* 0x8c */ |
|
|
279 | 0xaa/256.0, 0xbb/256.0, 0xdd/256.0, 0xee/256.0, /* 0x90 */ |
|
|
280 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x94 */ |
|
|
281 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x98 */ |
|
|
282 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0x9c */ |
|
|
283 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa0 */ |
|
|
284 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa4 */ |
|
|
285 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xa8 */ |
|
|
286 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xac */ |
|
|
287 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xb0 */ |
|
|
288 | 0x99/256.0, 0x99/256.0, 0x99/256.0, 0x99/256.0, /* 0xb4 */ |
|
|
289 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xb8 */ |
|
|
290 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xbc */ |
|
|
291 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xc0 */ |
|
|
292 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xc4 */ |
|
|
293 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xc8 */ |
|
|
294 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xcc */ |
|
|
295 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd0 */ |
|
|
296 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd4 */ |
|
|
297 | 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, 0xcc/256.0, /* 0xd8 */ |
|
|
298 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xdc */ |
|
|
299 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xe0 */ |
|
|
300 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xe4 */ |
|
|
301 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xe8 */ |
|
|
302 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xec */ |
|
|
303 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xf0 */ |
|
|
304 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xf4 */ |
|
|
305 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xf8 */ |
|
|
306 | 0xff/256.0, 0xff/256.0, 0xff/256.0, 0xff/256.0, /* 0xfc */ |
|
|
307 | }; |
|
|
308 | |
|
|
309 | psiconv_pixel_floats_t palet_color_8 = |
|
|
310 | { |
|
|
311 | PALET_COLOR_8_LEN, |
|
|
312 | palet_color_8_red, |
|
|
313 | palet_color_8_green, |
|
|
314 | palet_color_8_blue, |
|
|
315 | }; |
|
|
316 | |
|
|
317 | int psiconv_write_paint_data_section(const psiconv_config config, |
56 | int psiconv_write_paint_data_section(const psiconv_config config, |
318 | psiconv_buffer buf, |
57 | psiconv_buffer buf, int lev, |
319 | const psiconv_paint_data_section value, |
58 | const psiconv_paint_data_section value, |
320 | int is_clipart) |
59 | int is_clipart) |
321 | { |
60 | { |
322 | int res,colordepth,i; |
61 | int res,colordepth,i; |
323 | psiconv_pixel_ints ints; |
62 | psiconv_pixel_ints ints; |
324 | psiconv_pixel_floats_t floats,palet; |
63 | psiconv_pixel_floats_t floats,palet; |
325 | psiconv_list bytes,bytes_rle; |
64 | psiconv_list bytes,bytes_rle; |
326 | psiconv_u8 *byteptr,encoding; |
65 | psiconv_u8 *byteptr,encoding; |
327 | |
66 | |
|
|
67 | psiconv_progress(config,lev,0,"Writing paint data section"); |
|
|
68 | |
328 | /* First, we check whether we can cope with the current configuration. |
69 | /* First, we check whether we can cope with the current configuration. |
329 | If not, we stop at once */ |
70 | If not, we stop at once */ |
330 | if ((config->colordepth != 2) && (config->colordepth != 4) && |
71 | if ((config->colordepth != 2) && (config->colordepth != 4) && |
331 | (config->colordepth != 8) && (config->colordepth != 12) && |
72 | (config->colordepth != 8) && (config->colordepth != 12) && |
332 | (config->colordepth != 16) && (config->colordepth != 24)) { |
73 | (config->colordepth != 16) && (config->colordepth != 24)) { |
333 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
74 | psiconv_error(config,lev,0, |
334 | "Unsupported color depth (%d); try 2, 4, 8, 16 or 24", |
75 | "Unsupported color depth (%d); try 2, 4, 8, 16 or 24", |
335 | config->colordepth); |
76 | config->colordepth); |
336 | res = -PSICONV_E_GENERATE; |
77 | res = -PSICONV_E_GENERATE; |
337 | goto ERROR1; |
78 | goto ERROR1; |
338 | } |
79 | } |
339 | |
80 | |
340 | if ((config->color) && |
81 | if ((config->color) && |
341 | (config->bluebits || config->redbits || config->greenbits) && |
82 | (config->bluebits || config->redbits || config->greenbits) && |
342 | (config->bluebits+config->redbits+config->greenbits!=config->colordepth)) { |
83 | (config->bluebits+config->redbits+config->greenbits!=config->colordepth)) { |
343 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
84 | psiconv_error(config,lev,0, |
344 | "Sum of red (%d), green (%d) and blue (%d) bits should be " |
85 | "Sum of red (%d), green (%d) and blue (%d) bits should be " |
345 | "equal to the color depth (%d)", |
86 | "equal to the color depth (%d)", |
346 | config->redbits,config->greenbits,config->bluebits, |
87 | config->redbits,config->greenbits,config->bluebits, |
347 | config->colordepth); |
88 | config->colordepth); |
348 | res = -PSICONV_E_GENERATE; |
89 | res = -PSICONV_E_GENERATE; |
… | |
… | |
350 | } |
91 | } |
351 | |
92 | |
352 | if (config->color && |
93 | if (config->color && |
353 | !(config->redbits || config->greenbits || config->bluebits) && |
94 | !(config->redbits || config->greenbits || config->bluebits) && |
354 | (config->colordepth != 4) && (config->colordepth != 8)) { |
95 | (config->colordepth != 4) && (config->colordepth != 8)) { |
355 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
96 | psiconv_error(config,lev,0, |
356 | "Current color depth (%d) has no palet associated with it", |
97 | "Current color depth (%d) has no palet associated with it", |
357 | config->colordepth); |
98 | config->colordepth); |
358 | res = -PSICONV_E_GENERATE; |
99 | res = -PSICONV_E_GENERATE; |
359 | goto ERROR1; |
100 | goto ERROR1; |
360 | } |
101 | } |
361 | |
102 | |
362 | if (config->color || (config->colordepth != 2)) |
103 | if (config->color || (config->colordepth != 2)) |
363 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
104 | psiconv_warn(config,lev,0, |
364 | "All image types except 2-bit greyscale are experimental!"); |
105 | "All image types except 2-bit greyscale are experimental!"); |
365 | |
106 | |
366 | |
107 | |
367 | if (!value) { |
108 | if (!value) { |
368 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paint data section"); |
109 | psiconv_error(config,lev,0,"Null paint data section"); |
369 | res = -PSICONV_E_GENERATE; |
110 | res = -PSICONV_E_GENERATE; |
370 | goto ERROR1; |
111 | goto ERROR1; |
371 | } |
112 | } |
372 | |
113 | |
373 | floats.red = value->red; |
114 | floats.red = value->red; |
374 | floats.green = value->green; |
115 | floats.green = value->green; |
375 | floats.blue = value->blue; |
116 | floats.blue = value->blue; |
376 | floats.length = value->xsize * value->ysize; |
117 | floats.length = value->xsize * value->ysize; |
377 | |
118 | |
378 | palet = palet_none; |
119 | palet = psiconv_palet_none; |
379 | if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) &&\ |
120 | if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) && |
380 | (config->bluebits == 0)) |
121 | (config->bluebits == 0)) |
381 | switch (config->colordepth) { |
122 | switch (config->colordepth) { |
382 | case 4: palet = palet_color_4; break; |
123 | case 4: palet = psiconv_palet_color_4; break; |
383 | case 8: palet = palet_color_8; break; |
124 | case 8: palet = psiconv_palet_color_8; break; |
384 | default: palet = palet_none; break; |
125 | default: palet = psiconv_palet_none; break; |
385 | } |
126 | } |
386 | |
127 | |
387 | if ((res = psiconv_collect_pixel_data(&ints,value->xsize, |
128 | if ((res = psiconv_collect_pixel_data(&ints,value->xsize, |
388 | value->ysize,floats, |
129 | value->ysize,floats, |
389 | config->colordepth,config->color, |
130 | config->colordepth,config->color, |
390 | config->redbits,config->greenbits, |
131 | config->redbits,config->greenbits, |
391 | config->bluebits,palet))) |
132 | config->bluebits,palet))) { |
|
|
133 | psiconv_error(config,lev,0,"Error collecting pixel data"); |
392 | goto ERROR1; |
134 | goto ERROR1; |
|
|
135 | } |
393 | |
136 | |
394 | if ((res = psiconv_pixel_data_to_bytes(config,&bytes,value->xsize,value->ysize, |
137 | if ((res = psiconv_pixel_data_to_bytes(config,lev+1,&bytes,value->xsize, |
395 | ints,config->colordepth))) |
138 | value->ysize,ints, |
|
|
139 | config->colordepth))) { |
|
|
140 | psiconv_error(config,lev,0,"Error translating pixel data to bytes"); |
396 | goto ERROR2; |
141 | goto ERROR2; |
|
|
142 | } |
397 | |
143 | |
398 | |
144 | |
399 | switch (config->colordepth) { |
145 | switch (config->colordepth) { |
400 | case 2: |
146 | case 2: |
401 | case 4: |
147 | case 4: |
402 | case 8: |
148 | case 8: |
403 | encoding = 0x01; |
149 | encoding = 0x01; |
404 | if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) |
150 | if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) { |
|
|
151 | psiconv_error(config,lev,0,"Error encoding RLE8"); |
405 | goto ERROR3; |
152 | goto ERROR3; |
|
|
153 | } |
406 | break; |
154 | break; |
407 | case 12: |
155 | case 12: |
408 | encoding = 0x02; |
156 | encoding = 0x02; |
409 | if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle))) |
157 | if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle))) { |
|
|
158 | psiconv_error(config,lev,0,"Error encoding RLE12"); |
410 | goto ERROR3; |
159 | goto ERROR3; |
|
|
160 | } |
411 | break; |
161 | break; |
412 | case 16: |
162 | case 16: |
413 | encoding = 0x03; |
163 | encoding = 0x03; |
414 | if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle))) |
164 | if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle))) { |
|
|
165 | psiconv_error(config,lev,0,"Error encoding RLE16"); |
415 | goto ERROR3; |
166 | goto ERROR3; |
|
|
167 | } |
416 | break; |
168 | break; |
417 | case 24: |
169 | case 24: |
418 | encoding = 0x04; |
170 | encoding = 0x04; |
419 | if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle))) |
171 | if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle))) { |
|
|
172 | psiconv_error(config,lev,0,"Error encoding RLE24"); |
420 | goto ERROR3; |
173 | goto ERROR3; |
|
|
174 | } |
421 | break; |
175 | break; |
422 | default: |
176 | default: |
423 | encoding = 0x00; |
177 | encoding = 0x00; |
424 | } |
178 | } |
425 | if (encoding) { |
179 | if (encoding) { |
… | |
… | |
430 | psiconv_list_free(bytes_rle); |
184 | psiconv_list_free(bytes_rle); |
431 | encoding = 0x00; |
185 | encoding = 0x00; |
432 | } |
186 | } |
433 | } |
187 | } |
434 | |
188 | |
435 | if ((res = psiconv_write_u32(config,buf, |
189 | if ((res = psiconv_write_u32(config,buf,lev+1, |
436 | 0x28+psiconv_list_length(bytes)))) |
190 | 0x28+psiconv_list_length(bytes)))) |
437 | goto ERROR3; |
191 | goto ERROR3; |
438 | if ((res = psiconv_write_u32(config,buf,0x28))) |
192 | if ((res = psiconv_write_u32(config,buf,lev+1,0x28))) |
439 | goto ERROR3; |
193 | goto ERROR3; |
440 | if ((res = psiconv_write_u32(config,buf,value->xsize))) |
194 | if ((res = psiconv_write_u32(config,buf,lev+1,value->xsize))) |
441 | goto ERROR3; |
195 | goto ERROR3; |
442 | if ((res = psiconv_write_u32(config,buf,value->ysize))) |
196 | if ((res = psiconv_write_u32(config,buf,lev+1,value->ysize))) |
443 | goto ERROR3; |
197 | goto ERROR3; |
444 | if ((res = psiconv_write_length(config,buf,value->pic_xsize))) |
198 | if ((res = psiconv_write_length(config,buf,lev+1,value->pic_xsize))) |
445 | goto ERROR3; |
199 | goto ERROR3; |
446 | if ((res = psiconv_write_length(config,buf,value->pic_ysize))) |
200 | if ((res = psiconv_write_length(config,buf,lev+1,value->pic_ysize))) |
447 | goto ERROR3; |
201 | goto ERROR3; |
448 | colordepth = config->colordepth; |
202 | colordepth = config->colordepth; |
449 | if ((res = psiconv_write_u32(config,buf,colordepth))) |
203 | if ((res = psiconv_write_u32(config,buf,lev+1,colordepth))) |
450 | goto ERROR3; |
204 | goto ERROR3; |
451 | if ((res = psiconv_write_u32(config,buf,(config->color?1:0)))) |
205 | if ((res = psiconv_write_u32(config,buf,lev+1,(config->color?1:0)))) |
452 | goto ERROR3; |
206 | goto ERROR3; |
453 | if ((res = psiconv_write_u32(config,buf,0))) |
207 | if ((res = psiconv_write_u32(config,buf,lev+1,0))) |
454 | goto ERROR3; |
208 | goto ERROR3; |
455 | if ((res = psiconv_write_u32(config,buf,encoding))) |
209 | if ((res = psiconv_write_u32(config,buf,lev+1,encoding))) |
456 | goto ERROR3; |
210 | goto ERROR3; |
457 | if (is_clipart) { |
211 | if (is_clipart) { |
458 | if ((res = psiconv_write_u32(config,buf,0xffffffff))) |
212 | if ((res = psiconv_write_u32(config,buf,lev+1,0xffffffff))) |
459 | goto ERROR3; |
213 | goto ERROR3; |
460 | if ((res = psiconv_write_u32(config,buf,0x00000044))) |
214 | if ((res = psiconv_write_u32(config,buf,lev+1,0x00000044))) |
461 | goto ERROR3; |
215 | goto ERROR3; |
462 | } |
216 | } |
463 | for (i = 0; i < psiconv_list_length(bytes); i++) { |
217 | for (i = 0; i < psiconv_list_length(bytes); i++) { |
464 | if (!(byteptr = psiconv_list_get(bytes,i))) |
218 | if (!(byteptr = psiconv_list_get(bytes,i))) |
465 | goto ERROR3; |
219 | goto ERROR3; |
466 | if ((res = psiconv_write_u8(config,buf,*byteptr))) |
220 | if ((res = psiconv_write_u8(config,buf,lev+1,*byteptr))) |
467 | goto ERROR3; |
221 | goto ERROR3; |
468 | } |
222 | } |
469 | |
223 | |
470 | ERROR3: |
224 | ERROR3: |
471 | psiconv_list_free(bytes); |
225 | psiconv_list_free(bytes); |
472 | ERROR2: |
226 | ERROR2: |
473 | psiconv_list_free(ints); |
227 | psiconv_list_free(ints); |
474 | ERROR1: |
228 | ERROR1: |
|
|
229 | if (res) |
|
|
230 | psiconv_error(config,lev,0,"Writing of paint data section failed"); |
|
|
231 | else |
|
|
232 | psiconv_progress(config,lev,0,"End of paint data section"); |
475 | return res; |
233 | return res; |
476 | } |
234 | } |
477 | |
235 | |
478 | /* Translate the floating point RGB information into pixel values. |
236 | /* Translate the floating point RGB information into pixel values. |
479 | The palet is optional; without it, we just use the |
237 | The palet is optional; without it, we just use the |
… | |
… | |
532 | psiconv_list_free(*pixels); |
290 | psiconv_list_free(*pixels); |
533 | ERROR1: |
291 | ERROR1: |
534 | return res; |
292 | return res; |
535 | } |
293 | } |
536 | |
294 | |
537 | int psiconv_pixel_data_to_bytes(const psiconv_config config, |
295 | int psiconv_pixel_data_to_bytes(const psiconv_config config,int lev, |
538 | psiconv_pixel_bytes *bytes, int xsize, |
296 | psiconv_pixel_bytes *bytes, int xsize, |
539 | int ysize, const psiconv_pixel_ints pixels, |
297 | int ysize, const psiconv_pixel_ints pixels, |
540 | int colordepth) |
298 | int colordepth) |
541 | { |
299 | { |
542 | int res; |
300 | int res; |
… | |
… | |
547 | psiconv_u32 *pixelptr; |
305 | psiconv_u32 *pixelptr; |
548 | int inputbitsleft,outputbitnr,bitsfit,outputbytenr; |
306 | int inputbitsleft,outputbitnr,bitsfit,outputbytenr; |
549 | |
307 | |
550 | |
308 | |
551 | if (!bytes) { |
309 | if (!bytes) { |
552 | psiconv_warn(config,0,0,"NULL pixel data"); |
310 | psiconv_error(config,lev,0,"NULL pixel data"); |
553 | res = -PSICONV_E_GENERATE; |
311 | res = -PSICONV_E_GENERATE; |
554 | goto ERROR1; |
312 | goto ERROR1; |
555 | } |
313 | } |
556 | if (!pixels) { |
314 | if (!pixels) { |
557 | psiconv_warn(config,0,0,"NULL pixel data"); |
315 | psiconv_error(config,lev,0,"NULL pixel data"); |
558 | res = -PSICONV_E_GENERATE; |
316 | res = -PSICONV_E_GENERATE; |
559 | goto ERROR1; |
317 | goto ERROR1; |
560 | } |
318 | } |
561 | if (psiconv_list_length(pixels) != xsize * ysize) { |
319 | if (psiconv_list_length(pixels) != xsize * ysize) { |
562 | psiconv_warn(config,0,0,"Pixel number is not correct"); |
320 | psiconv_error(config,lev,0,"Pixel number is not correct"); |
563 | res = -PSICONV_E_GENERATE; |
321 | res = -PSICONV_E_GENERATE; |
564 | goto ERROR1; |
322 | goto ERROR1; |
565 | } |
323 | } |
566 | |
324 | |
567 | if (!(*bytes = psiconv_list_new(sizeof(psiconv_u8)))) { |
325 | if (!(*bytes = psiconv_list_new(sizeof(psiconv_u8)))) { |
… | |
… | |
574 | outputbyte = 0; |
332 | outputbyte = 0; |
575 | for (y = 0; y < ysize; y++) { |
333 | for (y = 0; y < ysize; y++) { |
576 | outputbytenr = 0; |
334 | outputbytenr = 0; |
577 | for (x = 0; x < xsize; x++) { |
335 | for (x = 0; x < xsize; x++) { |
578 | if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { |
336 | if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { |
579 | psiconv_warn(config,0,0,"Massive internal corruption"); |
337 | psiconv_error(config,lev,0,"Massive internal corruption"); |
580 | res = -PSICONV_E_NOMEM; |
338 | res = -PSICONV_E_NOMEM; |
581 | goto ERROR2; |
339 | goto ERROR2; |
582 | } |
340 | } |
583 | inputbitsleft = colordepth; |
341 | inputbitsleft = colordepth; |
584 | inputdata = *pixelptr; |
342 | inputdata = *pixelptr; |
… | |
… | |
655 | goto ERROR2; |
413 | goto ERROR2; |
656 | if ((res = psiconv_list_add(*encoded_bytes,next))) |
414 | if ((res = psiconv_list_add(*encoded_bytes,next))) |
657 | goto ERROR2; |
415 | goto ERROR2; |
658 | i +=2; |
416 | i +=2; |
659 | } else if (*next == *entry) { |
417 | } else if (*next == *entry) { |
660 | len = 0; |
418 | len = 1; |
661 | while ((*next == *entry) && |
419 | while ((*next == *entry) && |
662 | (i+len + 1 < psiconv_list_length(plain_bytes)) && |
420 | (i+len + 2 < psiconv_list_length(plain_bytes)) && |
663 | len < 0x80) { |
421 | len < 0x80) { |
664 | len ++; |
422 | len ++; |
665 | if (!(next = psiconv_list_get(plain_bytes,i+len))) { |
423 | if (!(next = psiconv_list_get(plain_bytes,i+len))) { |
666 | res = -PSICONV_E_NOMEM; |
424 | res = -PSICONV_E_NOMEM; |
667 | goto ERROR2; |
425 | goto ERROR2; |
… | |
… | |
1077 | return res; |
835 | return res; |
1078 | } |
836 | } |
1079 | |
837 | |
1080 | |
838 | |
1081 | int psiconv_write_sketch_section(const psiconv_config config, |
839 | int psiconv_write_sketch_section(const psiconv_config config, |
1082 | psiconv_buffer buf, |
840 | psiconv_buffer buf, int lev, |
1083 | const psiconv_sketch_section value) |
841 | const psiconv_sketch_section value) |
1084 | { |
842 | { |
1085 | int res; |
843 | int res; |
1086 | |
844 | |
|
|
845 | psiconv_progress(config,lev,0,"Writing sketch section"); |
1087 | if (!value) { |
846 | if (!value) { |
1088 | psiconv_warn(config,0,0,"NULL sketch section"); |
847 | psiconv_error(config,lev,0,"NULL sketch section"); |
1089 | res = -PSICONV_E_GENERATE; |
848 | res = -PSICONV_E_GENERATE; |
1090 | goto ERROR1; |
849 | goto ERROR1; |
1091 | } |
850 | } |
1092 | |
851 | |
1093 | if ((res = psiconv_write_u16(config,buf,value->displayed_xsize))) |
852 | if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_xsize))) |
1094 | goto ERROR1; |
853 | goto ERROR1; |
1095 | if ((res = psiconv_write_u16(config,buf,value->displayed_ysize))) |
854 | if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_ysize))) |
1096 | goto ERROR1; |
855 | goto ERROR1; |
1097 | if ((res = psiconv_write_u16(config,buf,value->picture_data_x_offset))) |
856 | if ((res = psiconv_write_u16(config,buf,lev+1,value->picture_data_x_offset))) |
1098 | goto ERROR1; |
857 | goto ERROR1; |
1099 | if ((res = psiconv_write_u16(config,buf,value->picture_data_y_offset))) |
858 | if ((res = psiconv_write_u16(config,buf,lev+1,value->picture_data_y_offset))) |
1100 | goto ERROR1; |
859 | goto ERROR1; |
1101 | if ((res = psiconv_write_u16(config,buf,value->displayed_size_x_offset))) |
860 | if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_size_x_offset))) |
1102 | goto ERROR1; |
861 | goto ERROR1; |
1103 | if ((res = psiconv_write_u16(config,buf,value->displayed_size_y_offset))) |
862 | if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_size_y_offset))) |
1104 | goto ERROR1; |
863 | goto ERROR1; |
1105 | if ((res = psiconv_write_u16(config,buf,value->form_xsize))) |
864 | if ((res = psiconv_write_u16(config,buf,lev+1,value->form_xsize))) |
1106 | goto ERROR1; |
865 | goto ERROR1; |
1107 | if ((res = psiconv_write_u16(config,buf,value->form_ysize))) |
866 | if ((res = psiconv_write_u16(config,buf,lev+1,value->form_ysize))) |
1108 | goto ERROR1; |
867 | goto ERROR1; |
1109 | if ((res = psiconv_write_u16(config,buf,0x0000))) |
868 | if ((res = psiconv_write_u16(config,buf,lev+1,0x0000))) |
1110 | goto ERROR1; |
869 | goto ERROR1; |
1111 | if ((res = psiconv_write_paint_data_section(config,buf,value->picture,0))) |
870 | if ((res = psiconv_write_paint_data_section(config,buf,lev+1,value->picture,0))) |
1112 | goto ERROR1; |
871 | goto ERROR1; |
1113 | if ((res = psiconv_write_u16(config,buf,value->magnification_x * 0x03e8))) |
872 | if ((res = psiconv_write_u16(config,buf,lev+1,value->magnification_x * 0x03e8))) |
1114 | goto ERROR1; |
873 | goto ERROR1; |
1115 | if ((res = psiconv_write_u16(config,buf,value->magnification_y * 0x03e8))) |
874 | if ((res = psiconv_write_u16(config,buf,lev+1,value->magnification_y * 0x03e8))) |
1116 | goto ERROR1; |
875 | goto ERROR1; |
1117 | if ((res = psiconv_write_u32(config,buf,value->cut_left * 0x0c * |
876 | if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_left * 0x0c * |
1118 | value->displayed_xsize))) |
877 | value->displayed_xsize))) |
1119 | goto ERROR1; |
878 | goto ERROR1; |
1120 | if ((res = psiconv_write_u32(config,buf,value->cut_right * 0x0c * |
879 | if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_right * 0x0c * |
1121 | value->displayed_xsize))) |
880 | value->displayed_xsize))) |
1122 | goto ERROR1; |
881 | goto ERROR1; |
1123 | if ((res = psiconv_write_u32(config,buf,value->cut_top * 0x0c * |
882 | if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_top * 0x0c * |
1124 | value->displayed_ysize))) |
883 | value->displayed_ysize))) |
1125 | goto ERROR1; |
884 | goto ERROR1; |
1126 | if ((res = psiconv_write_u32(config,buf,value->cut_bottom * 0x0c * |
885 | if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_bottom * 0x0c * |
1127 | value->displayed_ysize))) |
886 | value->displayed_ysize))) |
1128 | goto ERROR1; |
887 | goto ERROR1; |
1129 | |
888 | |
1130 | ERROR1: |
889 | ERROR1: |
|
|
890 | if (res) |
|
|
891 | psiconv_error(config,lev,0,"Writing of sketch section failed"); |
|
|
892 | else |
|
|
893 | psiconv_progress(config,lev,0,"End of sketch section"); |
1131 | return res; |
894 | return res; |
1132 | } |
895 | } |
1133 | |
896 | |
1134 | int psiconv_write_clipart_section(const psiconv_config config, |
897 | int psiconv_write_clipart_section(const psiconv_config config, |
1135 | psiconv_buffer buf, |
898 | psiconv_buffer buf, int lev, |
1136 | const psiconv_clipart_section value) |
899 | const psiconv_clipart_section value) |
1137 | { |
900 | { |
1138 | int res; |
901 | int res; |
1139 | |
902 | |
1140 | |
903 | psiconv_progress(config,lev,0,"Writing clipart section"); |
1141 | if (!value) { |
904 | if (!value) { |
1142 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
905 | psiconv_error(config,lev,0, "NULL Clipart Section"); |
1143 | "NULL Clipart Section"); |
|
|
1144 | res = -PSICONV_E_GENERATE; |
906 | res = -PSICONV_E_GENERATE; |
1145 | goto ERROR; |
907 | goto ERROR; |
1146 | } |
908 | } |
1147 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART_ITEM))) |
909 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART_ITEM))) |
1148 | goto ERROR; |
910 | goto ERROR; |
1149 | if ((res = psiconv_write_u32(config,buf,0x00000002))) |
911 | if ((res = psiconv_write_u32(config,buf,lev+1,0x00000002))) |
1150 | goto ERROR; |
912 | goto ERROR; |
1151 | if ((res = psiconv_write_u32(config,buf,0x00000000))) |
913 | if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) |
1152 | goto ERROR; |
914 | goto ERROR; |
1153 | if ((res = psiconv_write_u32(config,buf,0x00000000))) |
915 | if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) |
1154 | goto ERROR; |
916 | goto ERROR; |
1155 | if ((res = psiconv_write_u32(config,buf,0x0000000C))) |
917 | if ((res = psiconv_write_u32(config,buf,lev+1,0x0000000C))) |
1156 | goto ERROR; |
918 | goto ERROR; |
1157 | if ((res = psiconv_write_paint_data_section(config,buf,value->picture,1))) |
919 | if ((res = psiconv_write_paint_data_section(config,buf,lev+1,value->picture,1))) |
1158 | goto ERROR; |
920 | goto ERROR; |
1159 | |
921 | |
1160 | ERROR: |
922 | ERROR: |
|
|
923 | if (res) |
|
|
924 | psiconv_error(config,lev,0,"Writing of clipart section failed"); |
|
|
925 | else |
|
|
926 | psiconv_progress(config,lev,0,"End of clipart section"); |
1161 | return res; |
927 | return res; |
1162 | } |
928 | } |
1163 | |
929 | |
1164 | int psiconv_write_jumptable_section(const psiconv_config config, |
930 | int psiconv_write_jumptable_section(const psiconv_config config, |
1165 | psiconv_buffer buf, |
931 | psiconv_buffer buf, int lev, |
1166 | const psiconv_jumptable_section value) |
932 | const psiconv_jumptable_section value) |
1167 | { |
933 | { |
1168 | int res,i; |
934 | int res,i; |
1169 | psiconv_u32 *offset_ptr; |
935 | psiconv_u32 *offset_ptr; |
1170 | |
936 | |
|
|
937 | psiconv_progress(config,lev,0,"Writing jumptable section"); |
1171 | |
938 | |
1172 | if (!value) { |
939 | if (!value) { |
1173 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
940 | psiconv_error(config,lev,0,"NULL Jumptable Section"); |
1174 | "NULL Jumptable Section"); |
|
|
1175 | res = -PSICONV_E_GENERATE; |
941 | res = -PSICONV_E_GENERATE; |
1176 | goto ERROR; |
942 | goto ERROR; |
1177 | } |
943 | } |
1178 | if ((res = psiconv_write_u32(config,buf,psiconv_list_length(value)))) |
944 | if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_list_length(value)))) |
1179 | goto ERROR; |
945 | goto ERROR; |
1180 | for (i = 0; i < psiconv_list_length(value); i++) { |
946 | for (i = 0; i < psiconv_list_length(value); i++) { |
1181 | if (!(offset_ptr = psiconv_list_get(value,i))) { |
947 | if (!(offset_ptr = psiconv_list_get(value,i))) { |
1182 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
948 | psiconv_error(config,lev,0,"Massive memory corruption"); |
1183 | "Massive memory corruption"); |
|
|
1184 | res = -PSICONV_E_NOMEM; |
949 | res = -PSICONV_E_NOMEM; |
1185 | goto ERROR; |
950 | goto ERROR; |
1186 | } |
951 | } |
1187 | if ((res = psiconv_write_offset(config,buf,*offset_ptr))) |
952 | if ((res = psiconv_write_offset(config,buf,lev+1,*offset_ptr))) |
1188 | goto ERROR; |
953 | goto ERROR; |
1189 | } |
954 | } |
1190 | |
955 | |
1191 | ERROR: |
956 | ERROR: |
|
|
957 | if (res) |
|
|
958 | psiconv_error(config,lev,0,"Writing of jumptable section failed"); |
|
|
959 | else |
|
|
960 | psiconv_progress(config,lev,0,"End of jumptable section"); |
1192 | return res; |
961 | return res; |
1193 | } |
962 | } |
1194 | |
963 | |