/[public]/psiconv/trunk/lib/psiconv/generate_image.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/generate_image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 175 Revision 176
42} psiconv_pixel_floats_t; 42} psiconv_pixel_floats_t;
43 43
44static int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels, 44static int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels,
45 int xsize,int ysize, 45 int xsize,int ysize,
46 const psiconv_pixel_floats_t data, 46 const psiconv_pixel_floats_t data,
47 int colordepth, 47 int colordepth,int color,
48 int redbits,int greenbits,int bluebits,
48 const psiconv_pixel_floats_t palet); 49 const psiconv_pixel_floats_t palet);
49static int psiconv_pixel_data_to_bytes(const psiconv_config config, 50static int psiconv_pixel_data_to_bytes(const psiconv_config config,
50 psiconv_pixel_bytes *bytes, int xsize, 51 psiconv_pixel_bytes *bytes, int xsize,
51 int ysize, const psiconv_pixel_ints pixels, 52 int ysize, const psiconv_pixel_ints pixels,
52 int colordepth); 53 int colordepth);
53static int psiconv_encode_rle8(const psiconv_config config, 54static int psiconv_encode_rle8(const psiconv_config config,
54 const psiconv_pixel_bytes plain_bytes, 55 const psiconv_pixel_bytes plain_bytes,
55 psiconv_pixel_bytes *encoded_bytes); 56 psiconv_pixel_bytes *encoded_bytes);
57static int psiconv_encode_rle12(const psiconv_config config,
58 const psiconv_pixel_bytes plain_bytes,
59 psiconv_pixel_bytes *encoded_bytes);
56static int psiconv_encode_rle16(const psiconv_config config, 60static int psiconv_encode_rle16(const psiconv_config config,
57 const psiconv_pixel_bytes plain_bytes, 61 const psiconv_pixel_bytes plain_bytes,
58 psiconv_pixel_bytes *encoded_bytes); 62 psiconv_pixel_bytes *encoded_bytes);
59static int psiconv_encode_rle24(const psiconv_config config, 63static int psiconv_encode_rle24(const psiconv_config config,
60 const psiconv_pixel_bytes plain_bytes, 64 const psiconv_pixel_bytes plain_bytes,
61 psiconv_pixel_bytes *encoded_bytes); 65 psiconv_pixel_bytes *encoded_bytes);
62 66
63#define PALET_GREY_2_LEN 4
64float palet_grey_2_rgb[PALET_GREY_2_LEN] = {0.0/3, 1.0/3, 2.0/3, 3.0/3};
65#define PALET_GREY_4_LEN 16
66float palet_grey_4_rgb[PALET_GREY_4_LEN] =
67 { 0.0/15, 1.0/15, 2.0/15, 3.0/15,
68 4.0/15, 5.0/15, 6.0/15, 7.0/15,
69 8.0/15, 9.0/15, 10.0/15, 11.0/15,
70 12.0/15, 13.0/15, 14.0/15, 15.0/15};
71#define PALET_NONE_LEN 0 67#define PALET_NONE_LEN 0
72
73psiconv_pixel_floats_t palet_grey_2 =
74 {
75 PALET_GREY_2_LEN,
76 (float *) palet_grey_2_rgb,
77 (float *) palet_grey_2_rgb,
78 (float *) palet_grey_2_rgb
79 };
80
81psiconv_pixel_floats_t palet_grey_4 =
82 {
83 PALET_GREY_4_LEN,
84 (float *) palet_grey_4_rgb,
85 (float *) palet_grey_4_rgb,
86 (float *) palet_grey_4_rgb
87 };
88 68
89psiconv_pixel_floats_t palet_none = 69psiconv_pixel_floats_t palet_none =
90 { 70 {
91 PALET_NONE_LEN, 71 PALET_NONE_LEN,
92 NULL, 72 NULL,
93 NULL, 73 NULL,
94 NULL 74 NULL
95 }; 75 };
96 76
77#define PALET_COLOR_4_LEN 16
78float 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
85float 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
92float 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
99psiconv_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
108float 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
175float 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
242float 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
309psiconv_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 };
97 316
98int psiconv_write_paint_data_section(const psiconv_config config, 317int psiconv_write_paint_data_section(const psiconv_config config,
99 psiconv_buffer buf, 318 psiconv_buffer buf,
100 const psiconv_paint_data_section value, 319 const psiconv_paint_data_section value,
101 int is_clipart) 320 int is_clipart)
104 psiconv_pixel_ints ints; 323 psiconv_pixel_ints ints;
105 psiconv_pixel_floats_t floats,palet; 324 psiconv_pixel_floats_t floats,palet;
106 psiconv_list bytes,bytes_rle; 325 psiconv_list bytes,bytes_rle;
107 psiconv_u8 *byteptr,encoding; 326 psiconv_u8 *byteptr,encoding;
108 327
328 /* First, we check whether we can cope with the current configuration.
329 If not, we stop at once */
330 if ((config->colordepth != 2) && (config->colordepth != 4) &&
331 (config->colordepth != 8) && (config->colordepth != 12) &&
332 (config->colordepth != 16) && (config->colordepth != 24)) {
333 psiconv_warn(config,0,psiconv_buffer_length(buf),
334 "Unsupported color depth (%d); try 2, 4, 8, 16 or 24",
335 config->colordepth);
336 res = -PSICONV_E_GENERATE;
337 goto ERROR1;
338 }
339
340 if ((config->color) &&
341 (config->bluebits || config->redbits || config->greenbits) &&
342 (config->bluebits+config->redbits+config->greenbits!=config->colordepth)) {
343 psiconv_warn(config,0,psiconv_buffer_length(buf),
344 "Sum of red (%d), green (%d) and blue (%d) bits should be "
345 "equal to the color depth (%d)",
346 config->redbits,config->greenbits,config->bluebits,
347 config->colordepth);
348 res = -PSICONV_E_GENERATE;
349 goto ERROR1;
350 }
351
352 if (config->color &&
353 !(config->redbits || config->greenbits || config->bluebits) &&
354 (config->colordepth != 4) && (config->colordepth != 8)) {
355 psiconv_warn(config,0,psiconv_buffer_length(buf),
356 "Current color depth (%d) has no palet associated with it",
357 config->colordepth);
358 res = -PSICONV_E_GENERATE;
359 goto ERROR1;
360 }
361
362 if (config->color || (config->colordepth != 2))
363 psiconv_warn(config,0,psiconv_buffer_length(buf),
364 "All image types except 2-bit greyscale are experimental!");
365
366
109 if (!value) { 367 if (!value) {
110 psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paint data section"); 368 psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paint data section");
111 res = -PSICONV_E_GENERATE; 369 res = -PSICONV_E_GENERATE;
112 goto ERROR1; 370 goto ERROR1;
113 } 371 }
115 floats.red = value->red; 373 floats.red = value->red;
116 floats.green = value->green; 374 floats.green = value->green;
117 floats.blue = value->blue; 375 floats.blue = value->blue;
118 floats.length = value->xsize * value->ysize; 376 floats.length = value->xsize * value->ysize;
119 377
378 palet = palet_none;
379 if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) &&\
380 (config->bluebits == 0))
120 switch (config->colordepth) { 381 switch (config->colordepth) {
121 default: 382 case 4: palet = palet_color_4; break;
122 case 2: palet = (config->color?palet_none:palet_grey_2); 383 case 8: palet = palet_color_8; break;
123 break; 384 default: palet = palet_none; break;
124 case 4: palet = (config->color?palet_none:palet_grey_4);
125 break;
126 } 385 }
127 386
128 if ((res = psiconv_collect_pixel_data(&ints,value->xsize, 387 if ((res = psiconv_collect_pixel_data(&ints,value->xsize,
129 value->ysize,floats, 388 value->ysize,floats,
130 config->colordepth,palet))) 389 config->colordepth,config->color,
390 config->redbits,config->greenbits,
391 config->bluebits,palet)))
131 goto ERROR1; 392 goto ERROR1;
132 393
133 if ((res = psiconv_pixel_data_to_bytes(config,&bytes,value->xsize,value->ysize, 394 if ((res = psiconv_pixel_data_to_bytes(config,&bytes,value->xsize,value->ysize,
134 ints,config->colordepth))) 395 ints,config->colordepth)))
135 goto ERROR2; 396 goto ERROR2;
136 397
137 398
399 switch (config->colordepth) {
400 case 2:
401 case 4:
402 case 8:
138 encoding = 0x00; 403 encoding = 0x01;
139 if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) 404 if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle)))
140 goto ERROR3; 405 goto ERROR3;
406 break;
407 case 12:
408 encoding = 0x02;
409 if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle)))
410 goto ERROR3;
411 break;
412 case 16:
413 encoding = 0x03;
414 if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle)))
415 goto ERROR3;
416 break;
417 case 24:
418 encoding = 0x04;
419 if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle)))
420 goto ERROR3;
421 break;
422 default:
423 encoding = 0x00;
424 }
425 if (encoding) {
141 if (psiconv_list_length(bytes_rle) < psiconv_list_length(bytes)) { 426 if (psiconv_list_length(bytes_rle) < psiconv_list_length(bytes)) {
142 encoding = 0x01;
143 psiconv_list_free(bytes); 427 psiconv_list_free(bytes);
144 bytes = bytes_rle; 428 bytes = bytes_rle;
145 } else { 429 } else {
146 bytes_rle = NULL; 430 psiconv_list_free(bytes_rle);
431 encoding = 0x00;
432 }
147 } 433 }
148 434
149 if ((res = psiconv_write_u32(config,buf, 435 if ((res = psiconv_write_u32(config,buf,
150 0x28+psiconv_list_length(bytes)))) 436 0x28+psiconv_list_length(bytes))))
151 goto ERROR3; 437 goto ERROR3;
158 if ((res = psiconv_write_length(config,buf,value->pic_xsize))) 444 if ((res = psiconv_write_length(config,buf,value->pic_xsize)))
159 goto ERROR3; 445 goto ERROR3;
160 if ((res = psiconv_write_length(config,buf,value->pic_ysize))) 446 if ((res = psiconv_write_length(config,buf,value->pic_ysize)))
161 goto ERROR3; 447 goto ERROR3;
162 colordepth = config->colordepth; 448 colordepth = config->colordepth;
163 if ((colordepth != 2) && colordepth != 4)
164 colordepth = 2;
165 if ((res = psiconv_write_u32(config,buf,colordepth))) 449 if ((res = psiconv_write_u32(config,buf,colordepth)))
166 goto ERROR3; 450 goto ERROR3;
167 if ((res = psiconv_write_u32(config,buf,(config->color?1:0)))) 451 if ((res = psiconv_write_u32(config,buf,(config->color?1:0))))
168 goto ERROR3; 452 goto ERROR3;
169 if ((res = psiconv_write_u32(config,buf,0))) 453 if ((res = psiconv_write_u32(config,buf,0)))
195 The palet is optional; without it, we just use the 479 The palet is optional; without it, we just use the
196 colordepth. With a large palet this is not very fast, but it will do for 480 colordepth. With a large palet this is not very fast, but it will do for
197 now. For greyscale pictures, just use the palet. */ 481 now. For greyscale pictures, just use the palet. */
198int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels,int xsize,int ysize, 482int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels,int xsize,int ysize,
199 const psiconv_pixel_floats_t data, 483 const psiconv_pixel_floats_t data,
200 int colordepth, 484 int colordepth,int color,
485 int redbits,int bluebits,int greenbits,
201 const psiconv_pixel_floats_t palet) 486 const psiconv_pixel_floats_t palet)
202{ 487{
203 int res,x,y,i; 488 int res,x,y,i;
204 psiconv_u32 index,pixel; 489 psiconv_u32 index,pixel;
205 float p_red,p_green,p_blue,mult,dist,new_dist; 490 float p_red,p_green,p_blue,dist,new_dist;
206 491
207 if (!(*pixels = psiconv_list_new(sizeof(psiconv_u32)))) { 492 if (!(*pixels = psiconv_list_new(sizeof(psiconv_u32)))) {
208 res = -PSICONV_E_NOMEM; 493 res = -PSICONV_E_NOMEM;
209 goto ERROR1; 494 goto ERROR1;
210 } 495 }
211 496
212 mult = 1 << colordepth;
213 for (y = 0; y < ysize; y++) { 497 for (y = 0; y < ysize; y++) {
214 for (x = 0; x < xsize; x++) { 498 for (x = 0; x < xsize; x++) {
215 index = y*xsize+x; 499 index = y*xsize+x;
216 p_red = data.red[index]; 500 p_red = data.red[index];
217 p_green = data.green[index]; 501 p_green = data.green[index];
218 p_blue = data.blue[index]; 502 p_blue = data.blue[index];
219 if (!palet.length) { 503 if (!palet.length) {
220 pixel = (((psiconv_u32) (p_red*mult+0.5)) << (2*colordepth)) + 504 if (color)
221 (((psiconv_u32) (p_green*mult+0.5)) << colordepth) + 505 pixel = (((psiconv_u32) (p_red * (1 << redbits) + 0.5))
506 << (greenbits+bluebits)) +
507 (((psiconv_u32) (p_green * (1 << greenbits) + 0.5))
508 << bluebits) +
222 ((psiconv_u32) (p_blue*mult+0.5)); 509 ((psiconv_u32) (p_blue * (1 << bluebits) + 0.5));
510 else
511 pixel = (p_red + p_green + p_blue)/3.0 * (1 << colordepth);
223 } else { 512 } else {
224 dist = 4; /* Max distance is 3, so this is safe */ 513 dist = 4; /* Max distance is 3, so this is safe */
225 pixel = -1; 514 pixel = -1;
226 for (i = 0; i < palet.length; i++) { 515 for (i = 0; i < palet.length; i++) {
227 new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) + 516 new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) +
330 psiconv_list_free(*bytes); 619 psiconv_list_free(*bytes);
331ERROR1: 620ERROR1:
332 return res; 621 return res;
333} 622}
334 623
624/* RLE8 encoding:
625 Marker bytes followed by one or more data bytes.
626 Marker value 0x00-0x7f: repeat the next data byte (marker+1) times
627 Marker value 0xff-0x80: (0x100-marker) data bytes follow */
335int psiconv_encode_rle8(const psiconv_config config, 628int psiconv_encode_rle8(const psiconv_config config,
336 const psiconv_pixel_bytes plain_bytes, 629 const psiconv_pixel_bytes plain_bytes,
337 psiconv_pixel_bytes *encoded_bytes) 630 psiconv_pixel_bytes *encoded_bytes)
338{ 631{
339 int res,i,j,len; 632 int res,i,j,len;
413 psiconv_list_free(*encoded_bytes); 706 psiconv_list_free(*encoded_bytes);
414ERROR1: 707ERROR1:
415 return res; 708 return res;
416} 709}
417 710
711/* RLE12 encoding:
712 Word based. The 12 least significant bits contain the pixel colors.
713 the 4 most signigicant bits are the number of repetitions minus 1 */
714int psiconv_encode_rle12(const psiconv_config config,
715 const psiconv_pixel_bytes plain_bytes,
716 psiconv_pixel_bytes *encoded_bytes)
717{
718 typedef psiconv_list psiconv_word_data; /* of psiconv_u16 */
719 psiconv_word_data data;
720 int res,i,len,location;
721 psiconv_u16 *word_entry,*word_next;
722 psiconv_u16 word_data;
723 psiconv_u8 byte_temp;
724 psiconv_u8 *byte_entry;
725
726
727 /* First extract the 12-bit values to encode */
728 if (!(data = psiconv_list_new(sizeof(psiconv_u16)))) {
729 res = -PSICONV_E_NOMEM;
730 goto ERROR1;
731 }
732
733 for (i = 0; i < psiconv_list_length(plain_bytes); i++) {
734 if (!(byte_entry = psiconv_list_get(plain_bytes,i))) {
735 res = -PSICONV_E_NOMEM;
736 goto ERROR2;
737 }
738 location = 0;
739 if (location == 0) {
740 word_data = *byte_entry;
741 location ++;
742 } else if (location == 1) {
743 word_data = (word_data << 4) + (*byte_entry & 0x0f);
744 if ((res = psiconv_list_add(data,&word_data)))
745 goto ERROR2;
746 word_data = *byte_entry >> 4;
747 location ++;
748 } else {
749 word_data = (word_data << 8) + *byte_entry;
750 if ((res = psiconv_list_add(data,&word_data)))
751 goto ERROR2;
752 location = 0;
753 }
754 }
755
756 if (!(*encoded_bytes = psiconv_list_new(sizeof(psiconv_u8)))) {
757 res = -PSICONV_E_NOMEM;
758 goto ERROR2;
759 }
760
761 for (i = 0; i < psiconv_list_length(data);) {
762 if (!(word_entry = psiconv_list_get(data,i))) {
763 res = -PSICONV_E_NOMEM;
764 goto ERROR3;
765 }
766
767 if (!(word_next = psiconv_list_get(data,i+1))) {
768 res = -PSICONV_E_NOMEM;
769 goto ERROR3;
770 }
771
772 if (i == psiconv_list_length(data) - 2) {
773 byte_temp = *word_entry && 0xff;
774 if ((res = psiconv_list_add(*encoded_bytes,&byte_temp)))
775 goto ERROR3;
776 byte_temp = *word_entry >> 8;
777 if ((res = psiconv_list_add(*encoded_bytes,&byte_temp)))
778 goto ERROR3;
779 byte_temp = *word_next && 0xff;
780 if ((res = psiconv_list_add(*encoded_bytes,&byte_temp)))
781 goto ERROR3;
782 byte_temp = *word_next >> 8;
783 if ((res = psiconv_list_add(*encoded_bytes,&byte_temp)))
784 goto ERROR3;
785 i += 2;
786 }
787
788 len = 0;
789 while ((*word_entry == *word_next) && (len < 16) &&
790 (i+len+1 < psiconv_list_length(data))) {
791 len ++;
792 if (!(word_next = psiconv_list_get(data,i+len))) {
793 res = -PSICONV_E_NOMEM;
794 goto ERROR3;
795 }
796 }
797
798 byte_temp = *word_entry && 0xff;
799 if ((res = psiconv_list_add(*encoded_bytes,&byte_temp)))
800 goto ERROR3;
801 byte_temp = (*word_entry >> 8) + ((len - 1) << 4);
802 if ((res = psiconv_list_add(*encoded_bytes,&byte_temp)))
803 goto ERROR3;
804 i += len;
805 }
806 return 0;
807
808ERROR3:
809 psiconv_list_free(*encoded_bytes);
810ERROR2:
811 psiconv_list_free(data);
812ERROR1:
813 return res;
814}
815
816/* RLE16 encoding:
817 Marker bytes followed by one or more data words.
818 Marker value 0x00-0x7f: repeat the next data word (marker+1) times
819 Marker value 0xff-0x80: (0x100-marker) data words follow */
418int psiconv_encode_rle16(const psiconv_config config, 820int psiconv_encode_rle16(const psiconv_config config,
419 const psiconv_pixel_bytes plain_bytes, 821 const psiconv_pixel_bytes plain_bytes,
420 psiconv_pixel_bytes *encoded_bytes) 822 psiconv_pixel_bytes *encoded_bytes)
421{ 823{
422 int res,i,j,len; 824 int res,i,j,len;
525 psiconv_list_free(*encoded_bytes); 927 psiconv_list_free(*encoded_bytes);
526ERROR1: 928ERROR1:
527 return res; 929 return res;
528} 930}
529 931
932/* RLE24 encoding:
933 Marker bytes followed by one or more data byte-triplets.
934 Marker value 0x00-0x7f: repeat the next data byte-triplets (marker+1) times
935 Marker value 0xff-0x80: (0x100-marker) data byte-triplets follow */
530int psiconv_encode_rle24(const psiconv_config config, 936int psiconv_encode_rle24(const psiconv_config config,
531 const psiconv_pixel_bytes plain_bytes, 937 const psiconv_pixel_bytes plain_bytes,
532 psiconv_pixel_bytes *encoded_bytes) 938 psiconv_pixel_bytes *encoded_bytes)
533{ 939{
534 int res,i,j,len; 940 int res,i,j,len;

Legend:
Removed from v.175  
changed lines
  Added in v.176

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26