]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | #define _GNU_SOURCE |
1f0299c1 KB |
2 | #include "../gdk_imlib/gdk_imlib.h" |
3 | #include "../gdk_imlib/gdk_imlib_private.h" | |
c801d85f KB |
4 | |
5 | GdkPixmap * | |
6 | gdk_imlib_pixmap_foreign_new(gint width, gint height, | |
7 | gint depth, Pixmap pmap) | |
8 | { | |
9 | GdkPixmap *pixmap; | |
10 | GdkWindowPrivate *private; | |
11 | GdkWindowPrivate *window_private; | |
12 | ||
13 | private = g_new(GdkWindowPrivate, 1); | |
14 | pixmap = (GdkPixmap *) private; | |
15 | ||
16 | window_private = (GdkWindowPrivate *) id->x.gdk_win; | |
17 | ||
18 | private->xdisplay = window_private->xdisplay; | |
19 | private->window_type = GDK_WINDOW_PIXMAP; | |
20 | private->xwindow = pmap; | |
21 | private->colormap = id->x.gdk_cmap; | |
22 | private->children = NULL; | |
23 | private->parent = NULL; | |
24 | private->x = 0; | |
25 | private->y = 0; | |
26 | private->width = width; | |
27 | private->height = height; | |
28 | private->resize_count = 0; | |
29 | private->ref_count = 1; | |
30 | private->destroyed = 0; | |
31 | ||
32 | gdk_xid_table_insert(&private->xwindow, pixmap); | |
33 | ||
34 | return pixmap; | |
35 | } | |
36 | ||
37 | gint | |
38 | gdk_imlib_best_color_match(gint * r, gint * g, gint * b) | |
39 | { | |
40 | int i; | |
41 | int dif; | |
42 | int dr, dg, db; | |
43 | int col; | |
44 | int mindif = 0x7fffffff; | |
45 | XColor xcl; | |
46 | ||
47 | col = 0; | |
48 | if (!id) | |
49 | { | |
50 | fprintf(stderr, "ImLib ERROR: No ImlibData initialised\n"); | |
51 | return -1; | |
52 | } | |
53 | if ((id->render_type == RT_PLAIN_TRUECOL) || | |
54 | (id->render_type == RT_DITHER_TRUECOL)) | |
55 | { | |
56 | xcl.red = (unsigned short)((*r << 8) | (*r)); | |
57 | xcl.green = (unsigned short)((*g << 8) | (*g)); | |
58 | xcl.blue = (unsigned short)((*b << 8) | (*b)); | |
59 | xcl.flags = DoRed | DoGreen | DoBlue; | |
60 | XAllocColor(id->x.disp, id->x.root_cmap, &xcl); | |
61 | *r = xcl.red >> 8; | |
62 | *g = xcl.green >> 8; | |
63 | *b = xcl.blue >> 8; | |
64 | return xcl.pixel; | |
65 | } | |
66 | for (i = 0; i < id->num_colors; i++) | |
67 | { | |
68 | dr = *r - id->palette[i].r; | |
69 | if (dr < 0) | |
70 | dr = -dr; | |
71 | dg = *g - id->palette[i].g; | |
72 | if (dg < 0) | |
73 | dg = -dg; | |
74 | db = *b - id->palette[i].b; | |
75 | if (db < 0) | |
76 | db = -db; | |
77 | dif = dr + dg + db; | |
78 | if (dif < mindif) | |
79 | { | |
80 | mindif = dif; | |
81 | col = i; | |
82 | } | |
83 | } | |
84 | *r -= id->palette[col].r; | |
85 | *g -= id->palette[col].g; | |
86 | *b -= id->palette[col].b; | |
87 | col = id->palette[col].pixel; | |
88 | return col; | |
89 | } | |
90 | ||
91 | gint | |
92 | gindex_best_color_match(gint * r, gint * g, gint * b) | |
93 | { | |
94 | int i; | |
95 | int dif; | |
96 | int dr, dg, db; | |
97 | int col; | |
98 | int mindif = 0x7fffffff; | |
99 | XColor xcl; | |
100 | ||
101 | col = 0; | |
102 | if (!id) | |
103 | { | |
104 | fprintf(stderr, "ImLib ERROR: No ImlibData initialised\n"); | |
105 | return -1; | |
106 | } | |
107 | if ((id->render_type == RT_PLAIN_TRUECOL) || | |
108 | (id->render_type == RT_DITHER_TRUECOL)) | |
109 | { | |
110 | xcl.red = (unsigned short)((*r << 8) | (*r)); | |
111 | xcl.green = (unsigned short)((*g << 8) | (*g)); | |
112 | xcl.blue = (unsigned short)((*b << 8) | (*b)); | |
113 | xcl.flags = DoRed | DoGreen | DoBlue; | |
114 | XAllocColor(id->x.disp, id->x.root_cmap, &xcl); | |
115 | *r = xcl.red >> 8; | |
116 | *g = xcl.green >> 8; | |
117 | *b = xcl.blue >> 8; | |
118 | return xcl.pixel; | |
119 | } | |
120 | for (i = 0; i < id->num_colors; i++) | |
121 | { | |
122 | dr = *r - id->palette[i].r; | |
123 | if (dr < 0) | |
124 | dr = -dr; | |
125 | dg = *g - id->palette[i].g; | |
126 | if (dg < 0) | |
127 | dg = -dg; | |
128 | db = *b - id->palette[i].b; | |
129 | if (db < 0) | |
130 | db = -db; | |
131 | dif = dr + dg + db; | |
132 | if (dif < mindif) | |
133 | { | |
134 | mindif = dif; | |
135 | col = i; | |
136 | } | |
137 | } | |
138 | *r -= id->palette[col].r; | |
139 | *g -= id->palette[col].g; | |
140 | *b -= id->palette[col].b; | |
141 | return col; | |
142 | } | |
143 | ||
144 | void | |
145 | grender_shaped_15_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
146 | XImage * sxim, int *er1, int *er2, int *xarray, | |
147 | unsigned char **yarray) | |
148 | { | |
149 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
150 | unsigned char *ptr2; | |
151 | unsigned short *img; | |
152 | int jmp; | |
153 | ||
154 | jmp = (xim->bytes_per_line >> 1) - w; | |
155 | img = (unsigned short *)xim->data; | |
156 | for (y = 0; y < h; y++) | |
157 | { | |
158 | ter = er1; | |
159 | er1 = er2; | |
160 | er2 = ter; | |
161 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
162 | er2[ex] = 0; | |
163 | ex = 3; | |
164 | for (x = 0; x < w; x++) | |
165 | { | |
166 | ptr2 = yarray[y] + xarray[x]; | |
167 | r = (int)*ptr2++; | |
168 | g = (int)*ptr2++; | |
169 | b = (int)*ptr2; | |
170 | if ((r == im->shape_color.r) && | |
171 | (g == im->shape_color.g) && | |
172 | (b == im->shape_color.b)) | |
173 | { | |
174 | XPutPixel(sxim, x, y, 0); | |
175 | img++; | |
176 | ex += 3; | |
177 | } | |
178 | else | |
179 | { | |
180 | XPutPixel(sxim, x, y, 1); | |
181 | er = r + er1[ex++]; | |
182 | eg = g + er1[ex++]; | |
183 | eb = b + er1[ex++]; | |
184 | if (er > 255) | |
185 | er = 255; | |
186 | if (eg > 255) | |
187 | eg = 255; | |
188 | if (eb > 255) | |
189 | eb = 255; | |
190 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
191 | er = er & 0x07; | |
192 | eg = eg & 0x07; | |
193 | eb = eb & 0x07; | |
194 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
195 | *img++ = val; | |
196 | } | |
197 | } | |
198 | img += jmp; | |
199 | } | |
200 | } | |
201 | ||
202 | void | |
203 | grender_shaped_15_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
204 | XImage * sxim, int *er1, int *er2, int *xarray, | |
205 | unsigned char **yarray) | |
206 | { | |
207 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
208 | unsigned char *ptr2; | |
209 | unsigned short *img; | |
210 | int jmp; | |
211 | ||
212 | unsigned char dither[4][4] = | |
213 | { | |
214 | {0, 4, 6, 5}, | |
215 | {6, 2, 7, 3}, | |
216 | {2, 6, 1, 5}, | |
217 | {7, 4, 7, 3} | |
218 | }; | |
219 | int dithy, dithx; | |
220 | ||
221 | jmp = (xim->bytes_per_line >> 1) - w; | |
222 | img = (unsigned short *)xim->data; | |
223 | for (y = 0; y < h; y++) | |
224 | { | |
225 | dithy = y & 0x3; | |
226 | for (x = 0; x < w; x++) | |
227 | { | |
228 | ptr2 = yarray[y] + xarray[x]; | |
229 | r = (int)*ptr2++; | |
230 | g = (int)*ptr2++; | |
231 | b = (int)*ptr2; | |
232 | if ((r == im->shape_color.r) && | |
233 | (g == im->shape_color.g) && | |
234 | (b == im->shape_color.b)) | |
235 | { | |
236 | XPutPixel(sxim, x, y, 0); | |
237 | img++; | |
238 | } | |
239 | else | |
240 | { | |
241 | XPutPixel(sxim, x, y, 1); | |
242 | er = r & 0x07; | |
243 | eg = g & 0x07; | |
244 | eb = b & 0x07; | |
245 | dithx = x & 0x3; | |
246 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
247 | r += 8; | |
248 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
249 | g += 8; | |
250 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
251 | b += 8; | |
252 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
253 | *img++ = val; | |
254 | } | |
255 | } | |
256 | img += jmp; | |
257 | } | |
258 | } | |
259 | ||
260 | void | |
261 | grender_15_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
262 | XImage * sxim, int *er1, int *er2, int *xarray, | |
263 | unsigned char **yarray) | |
264 | { | |
265 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
266 | unsigned char *ptr2; | |
267 | unsigned short *img; | |
268 | int jmp; | |
269 | ||
270 | jmp = (xim->bytes_per_line >> 1) - w; | |
271 | img = (unsigned short *)xim->data; | |
272 | for (y = 0; y < h; y++) | |
273 | { | |
274 | ter = er1; | |
275 | er1 = er2; | |
276 | er2 = ter; | |
277 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
278 | er2[ex] = 0; | |
279 | ex = 3; | |
280 | for (x = 0; x < w; x++) | |
281 | { | |
282 | ptr2 = yarray[y] + xarray[x]; | |
283 | r = (int)*ptr2++; | |
284 | g = (int)*ptr2++; | |
285 | b = (int)*ptr2; | |
286 | er = r + er1[ex++]; | |
287 | eg = g + er1[ex++]; | |
288 | eb = b + er1[ex++]; | |
289 | if (er > 255) | |
290 | er = 255; | |
291 | if (eg > 255) | |
292 | eg = 255; | |
293 | if (eb > 255) | |
294 | eb = 255; | |
295 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
296 | er = er & 0x07; | |
297 | eg = eg & 0x07; | |
298 | eb = eb & 0x07; | |
299 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
300 | *img++ = val; | |
301 | } | |
302 | img += jmp; | |
303 | } | |
304 | } | |
305 | ||
306 | void | |
307 | grender_15_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
308 | XImage * sxim, int *er1, int *er2, int *xarray, | |
309 | unsigned char **yarray) | |
310 | { | |
311 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
312 | unsigned char *ptr2; | |
313 | ||
314 | unsigned short *img; | |
315 | int jmp; | |
316 | ||
317 | unsigned char dither[4][4] = | |
318 | { | |
319 | {0, 4, 6, 5}, | |
320 | {6, 2, 7, 3}, | |
321 | {2, 6, 1, 5}, | |
322 | {7, 4, 7, 3} | |
323 | }; | |
324 | int dithy, dithx; | |
325 | ||
326 | jmp = (xim->bytes_per_line >> 1) - w; | |
327 | img = (unsigned short *)xim->data; | |
328 | for (y = 0; y < h; y++) | |
329 | { | |
330 | dithy = y & 0x3; | |
331 | for (x = 0; x < w; x++) | |
332 | { | |
333 | ptr2 = yarray[y] + xarray[x]; | |
334 | r = (int)*ptr2++; | |
335 | g = (int)*ptr2++; | |
336 | b = (int)*ptr2; | |
337 | er = r & 0x07; | |
338 | eg = g & 0x07; | |
339 | eb = b & 0x07; | |
340 | dithx = x & 0x3; | |
341 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
342 | r += 8; | |
343 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
344 | g += 8; | |
345 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
346 | b += 8; | |
347 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
348 | *img++ = val; | |
349 | } | |
350 | img += jmp; | |
351 | } | |
352 | } | |
353 | ||
354 | void | |
355 | grender_shaped_16_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
356 | XImage * sxim, int *er1, int *er2, int *xarray, | |
357 | unsigned char **yarray) | |
358 | { | |
359 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
360 | unsigned char *ptr2; | |
361 | unsigned short *img; | |
362 | int jmp; | |
363 | ||
364 | jmp = (xim->bytes_per_line >> 1) - w; | |
365 | img = (unsigned short *)xim->data; | |
366 | for (y = 0; y < h; y++) | |
367 | { | |
368 | ter = er1; | |
369 | er1 = er2; | |
370 | er2 = ter; | |
371 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
372 | er2[ex] = 0; | |
373 | ex = 3; | |
374 | for (x = 0; x < w; x++) | |
375 | { | |
376 | ptr2 = yarray[y] + xarray[x]; | |
377 | r = (int)*ptr2++; | |
378 | g = (int)*ptr2++; | |
379 | b = (int)*ptr2; | |
380 | if ((r == im->shape_color.r) && | |
381 | (g == im->shape_color.g) && | |
382 | (b == im->shape_color.b)) | |
383 | { | |
384 | XPutPixel(sxim, x, y, 0); | |
385 | img++; | |
386 | ex += 3; | |
387 | } | |
388 | else | |
389 | { | |
390 | XPutPixel(sxim, x, y, 1); | |
391 | er = r + er1[ex++]; | |
392 | eg = g + er1[ex++]; | |
393 | eb = b + er1[ex++]; | |
394 | if (er > 255) | |
395 | er = 255; | |
396 | if (eg > 255) | |
397 | eg = 255; | |
398 | if (eb > 255) | |
399 | eb = 255; | |
400 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
401 | er = er & 0x07; | |
402 | eg = eg & 0x03; | |
403 | eb = eb & 0x07; | |
404 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
405 | *img++ = val; | |
406 | } | |
407 | } | |
408 | img += jmp; | |
409 | } | |
410 | } | |
411 | ||
412 | void | |
413 | grender_shaped_16_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
414 | XImage * sxim, int *er1, int *er2, int *xarray, | |
415 | unsigned char **yarray) | |
416 | { | |
417 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
418 | unsigned char *ptr2; | |
419 | unsigned short *img; | |
420 | int jmp; | |
421 | ||
422 | unsigned char dither[4][4] = | |
423 | { | |
424 | {0, 4, 6, 5}, | |
425 | {6, 2, 7, 3}, | |
426 | {2, 6, 1, 5}, | |
427 | {7, 4, 7, 3} | |
428 | }; | |
429 | int dithy, dithx; | |
430 | ||
431 | jmp = (xim->bytes_per_line >> 1) - w; | |
432 | img = (unsigned short *)xim->data; | |
433 | for (y = 0; y < h; y++) | |
434 | { | |
435 | dithy = y & 0x3; | |
436 | for (x = 0; x < w; x++) | |
437 | { | |
438 | ptr2 = yarray[y] + xarray[x]; | |
439 | r = (int)*ptr2++; | |
440 | g = (int)*ptr2++; | |
441 | b = (int)*ptr2; | |
442 | if ((r == im->shape_color.r) && | |
443 | (g == im->shape_color.g) && | |
444 | (b == im->shape_color.b)) | |
445 | { | |
446 | XPutPixel(sxim, x, y, 0); | |
447 | img++; | |
448 | } | |
449 | else | |
450 | { | |
451 | XPutPixel(sxim, x, y, 1); | |
452 | er = r & 0x07; | |
453 | eg = g & 0x03; | |
454 | eb = b & 0x07; | |
455 | dithx = x & 0x3; | |
456 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
457 | r += 8; | |
458 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
459 | g += 4; | |
460 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
461 | b += 8; | |
462 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
463 | *img++ = val; | |
464 | } | |
465 | } | |
466 | img += jmp; | |
467 | } | |
468 | } | |
469 | ||
470 | void | |
471 | grender_16_fast_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
472 | XImage * sxim, int *er1, int *er2, int *xarray, | |
473 | unsigned char **yarray) | |
474 | { | |
475 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
476 | unsigned char *ptr2; | |
477 | ||
478 | unsigned short *img; | |
479 | int jmp; | |
480 | ||
481 | jmp = (xim->bytes_per_line >> 1) - w; | |
482 | img = (unsigned short *)xim->data; | |
483 | for (y = 0; y < h; y++) | |
484 | { | |
485 | ter = er1; | |
486 | er1 = er2; | |
487 | er2 = ter; | |
488 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
489 | er2[ex] = 0; | |
490 | ex = 3; | |
491 | for (x = 0; x < w; x++) | |
492 | { | |
493 | ptr2 = yarray[y] + xarray[x]; | |
494 | r = (int)*ptr2++; | |
495 | g = (int)*ptr2++; | |
496 | b = (int)*ptr2; | |
497 | er = r + er1[ex++]; | |
498 | eg = g + er1[ex++]; | |
499 | eb = b + er1[ex++]; | |
500 | if (er > 255) | |
501 | er = 255; | |
502 | if (eg > 255) | |
503 | eg = 255; | |
504 | if (eb > 255) | |
505 | eb = 255; | |
506 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
507 | er = er & 0x07; | |
508 | eg = eg & 0x03; | |
509 | eb = eb & 0x07; | |
510 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
511 | *img++ = val; | |
512 | } | |
513 | img += jmp; | |
514 | } | |
515 | } | |
516 | ||
517 | void | |
518 | grender_16_fast_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
519 | XImage * sxim, int *er1, int *er2, int *xarray, | |
520 | unsigned char **yarray) | |
521 | { | |
522 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
523 | unsigned char *ptr2; | |
524 | ||
525 | unsigned short *img; | |
526 | int jmp; | |
527 | ||
528 | unsigned char dither[4][4] = | |
529 | { | |
530 | {0, 4, 6, 5}, | |
531 | {6, 2, 7, 3}, | |
532 | {2, 6, 1, 5}, | |
533 | {7, 4, 7, 3} | |
534 | }; | |
535 | int dithy, dithx; | |
536 | ||
537 | jmp = (xim->bytes_per_line >> 1) - w; | |
538 | img = (unsigned short *)xim->data; | |
539 | for (y = 0; y < h; y++) | |
540 | { | |
541 | dithy = y & 0x3; | |
542 | for (x = 0; x < w; x++) | |
543 | { | |
544 | ptr2 = yarray[y] + xarray[x]; | |
545 | r = (int)*ptr2++; | |
546 | g = (int)*ptr2++; | |
547 | b = (int)*ptr2; | |
548 | er = r & 0x07; | |
549 | eg = g & 0x03; | |
550 | eb = b & 0x07; | |
551 | dithx = x & 0x3; | |
552 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
553 | r += 8; | |
554 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
555 | g += 4; | |
556 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
557 | b += 8; | |
558 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
559 | *img++ = val; | |
560 | } | |
561 | img += jmp; | |
562 | } | |
563 | } | |
564 | ||
565 | void | |
566 | grender_shaped_15_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
567 | XImage * sxim, int *er1, int *er2, int *xarray, | |
568 | unsigned char **yarray) | |
569 | { | |
570 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
571 | unsigned char *ptr2; | |
572 | ||
573 | for (y = 0; y < h; y++) | |
574 | { | |
575 | ter = er1; | |
576 | er1 = er2; | |
577 | er2 = ter; | |
578 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
579 | er2[ex] = 0; | |
580 | ex = 3; | |
581 | for (x = 0; x < w; x++) | |
582 | { | |
583 | ptr2 = yarray[y] + xarray[x]; | |
584 | r = (int)*ptr2++; | |
585 | g = (int)*ptr2++; | |
586 | b = (int)*ptr2; | |
587 | if ((r == im->shape_color.r) && | |
588 | (g == im->shape_color.g) && | |
589 | (b == im->shape_color.b)) | |
590 | { | |
591 | XPutPixel(sxim, x, y, 0); | |
592 | ex += 3; | |
593 | } | |
594 | else | |
595 | { | |
596 | XPutPixel(sxim, x, y, 1); | |
597 | er = r + er1[ex++]; | |
598 | eg = g + er1[ex++]; | |
599 | eb = b + er1[ex++]; | |
600 | if (er > 255) | |
601 | er = 255; | |
602 | if (eg > 255) | |
603 | eg = 255; | |
604 | if (eb > 255) | |
605 | eb = 255; | |
606 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
607 | er = er & 0x07; | |
608 | eg = eg & 0x07; | |
609 | eb = eb & 0x07; | |
610 | if (er > 255) | |
611 | er = 255; | |
612 | else if (er < 0) | |
613 | er = 0; | |
614 | if (eg > 255) | |
615 | eg = 255; | |
616 | else if (eg < 0) | |
617 | eg = 0; | |
618 | if (eb > 255) | |
619 | eb = 255; | |
620 | else if (eb < 0) | |
621 | eb = 0; | |
622 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
623 | er = r & 0x07; | |
624 | eg = g & 0x07; | |
625 | eb = b & 0x07; | |
626 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
627 | XPutPixel(xim, x, y, val); | |
628 | } | |
629 | } | |
630 | } | |
631 | } | |
632 | ||
633 | void | |
634 | grender_shaped_15_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
635 | XImage * sxim, int *er1, int *er2, int *xarray, | |
636 | unsigned char **yarray) | |
637 | { | |
638 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
639 | unsigned char *ptr2; | |
640 | ||
641 | unsigned char dither[4][4] = | |
642 | { | |
643 | {0, 4, 6, 5}, | |
644 | {6, 2, 7, 3}, | |
645 | {2, 6, 1, 5}, | |
646 | {7, 4, 7, 3} | |
647 | }; | |
648 | int dithy, dithx; | |
649 | ||
650 | for (y = 0; y < h; y++) | |
651 | { | |
652 | dithy = y & 0x3; | |
653 | for (x = 0; x < w; x++) | |
654 | { | |
655 | ptr2 = yarray[y] + xarray[x]; | |
656 | r = (int)*ptr2++; | |
657 | g = (int)*ptr2++; | |
658 | b = (int)*ptr2; | |
659 | if ((r == im->shape_color.r) && | |
660 | (g == im->shape_color.g) && | |
661 | (b == im->shape_color.b)) | |
662 | { | |
663 | XPutPixel(sxim, x, y, 0); | |
664 | } | |
665 | else | |
666 | { | |
667 | XPutPixel(sxim, x, y, 1); | |
668 | er = r & 0x07; | |
669 | eg = g & 0x07; | |
670 | eb = b & 0x07; | |
671 | dithx = x & 0x3; | |
672 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
673 | r += 8; | |
674 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
675 | g += 8; | |
676 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
677 | b += 8; | |
678 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
679 | XPutPixel(xim, x, y, val); | |
680 | } | |
681 | } | |
682 | } | |
683 | } | |
684 | ||
685 | void | |
686 | grender_15_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
687 | XImage * sxim, int *er1, int *er2, int *xarray, | |
688 | unsigned char **yarray) | |
689 | { | |
690 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
691 | unsigned char *ptr2; | |
692 | ||
693 | for (y = 0; y < h; y++) | |
694 | { | |
695 | ter = er1; | |
696 | er1 = er2; | |
697 | er2 = ter; | |
698 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
699 | er2[ex] = 0; | |
700 | ex = 3; | |
701 | for (x = 0; x < w; x++) | |
702 | { | |
703 | ptr2 = yarray[y] + xarray[x]; | |
704 | r = (int)*ptr2++; | |
705 | g = (int)*ptr2++; | |
706 | b = (int)*ptr2; | |
707 | er = r + er1[ex++]; | |
708 | eg = g + er1[ex++]; | |
709 | eb = b + er1[ex++]; | |
710 | if (er > 255) | |
711 | er = 255; | |
712 | if (eg > 255) | |
713 | eg = 255; | |
714 | if (eb > 255) | |
715 | eb = 255; | |
716 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
717 | er = er & 0x07; | |
718 | eg = eg & 0x07; | |
719 | eb = eb & 0x07; | |
720 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
721 | XPutPixel(xim, x, y, val); | |
722 | } | |
723 | } | |
724 | } | |
725 | ||
726 | void | |
727 | grender_15_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
728 | XImage * sxim, int *er1, int *er2, int *xarray, | |
729 | unsigned char **yarray) | |
730 | { | |
731 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
732 | unsigned char *ptr2; | |
733 | ||
734 | unsigned char dither[4][4] = | |
735 | { | |
736 | {0, 4, 6, 5}, | |
737 | {6, 2, 7, 3}, | |
738 | {2, 6, 1, 5}, | |
739 | {7, 4, 7, 3} | |
740 | }; | |
741 | int dithy, dithx; | |
742 | ||
743 | for (y = 0; y < h; y++) | |
744 | { | |
745 | dithy = y & 0x3; | |
746 | for (x = 0; x < w; x++) | |
747 | { | |
748 | ptr2 = yarray[y] + xarray[x]; | |
749 | r = (int)*ptr2++; | |
750 | g = (int)*ptr2++; | |
751 | b = (int)*ptr2; | |
752 | er = r & 0x07; | |
753 | eg = g & 0x07; | |
754 | eb = b & 0x07; | |
755 | dithx = x & 0x3; | |
756 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
757 | r += 8; | |
758 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
759 | g += 8; | |
760 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
761 | b += 8; | |
762 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
763 | XPutPixel(xim, x, y, val); | |
764 | } | |
765 | } | |
766 | } | |
767 | ||
768 | void | |
769 | grender_shaped_16_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
770 | XImage * sxim, int *er1, int *er2, int *xarray, | |
771 | unsigned char **yarray) | |
772 | { | |
773 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
774 | unsigned char *ptr2; | |
775 | ||
776 | for (y = 0; y < h; y++) | |
777 | { | |
778 | ter = er1; | |
779 | er1 = er2; | |
780 | er2 = ter; | |
781 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
782 | er2[ex] = 0; | |
783 | ex = 3; | |
784 | for (x = 0; x < w; x++) | |
785 | { | |
786 | ptr2 = yarray[y] + xarray[x]; | |
787 | r = (int)*ptr2++; | |
788 | g = (int)*ptr2++; | |
789 | b = (int)*ptr2; | |
790 | if ((r == im->shape_color.r) && | |
791 | (g == im->shape_color.g) && | |
792 | (b == im->shape_color.b)) | |
793 | { | |
794 | XPutPixel(sxim, x, y, 0); | |
795 | ex += 3; | |
796 | } | |
797 | else | |
798 | { | |
799 | XPutPixel(sxim, x, y, 1); | |
800 | er = r + er1[ex++]; | |
801 | eg = g + er1[ex++]; | |
802 | eb = b + er1[ex++]; | |
803 | if (er > 255) | |
804 | er = 255; | |
805 | if (eg > 255) | |
806 | eg = 255; | |
807 | if (eb > 255) | |
808 | eb = 255; | |
809 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
810 | er = er & 0x07; | |
811 | eg = eg & 0x03; | |
812 | eb = eb & 0x07; | |
813 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
814 | XPutPixel(xim, x, y, val); | |
815 | } | |
816 | } | |
817 | } | |
818 | } | |
819 | ||
820 | void | |
821 | grender_shaped_16_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
822 | XImage * sxim, int *er1, int *er2, int *xarray, | |
823 | unsigned char **yarray) | |
824 | { | |
825 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
826 | unsigned char *ptr2; | |
827 | ||
828 | unsigned char dither[4][4] = | |
829 | { | |
830 | {0, 4, 6, 5}, | |
831 | {6, 2, 7, 3}, | |
832 | {2, 6, 1, 5}, | |
833 | {7, 4, 7, 3} | |
834 | }; | |
835 | int dithy, dithx; | |
836 | ||
837 | for (y = 0; y < h; y++) | |
838 | { | |
839 | dithy = y & 0x3; | |
840 | for (x = 0; x < w; x++) | |
841 | { | |
842 | ptr2 = yarray[y] + xarray[x]; | |
843 | r = (int)*ptr2++; | |
844 | g = (int)*ptr2++; | |
845 | b = (int)*ptr2; | |
846 | if ((r == im->shape_color.r) && | |
847 | (g == im->shape_color.g) && | |
848 | (b == im->shape_color.b)) | |
849 | { | |
850 | XPutPixel(sxim, x, y, 0); | |
851 | } | |
852 | else | |
853 | { | |
854 | XPutPixel(sxim, x, y, 1); | |
855 | er = r & 0x07; | |
856 | eg = g & 0x03; | |
857 | eb = b & 0x07; | |
858 | dithx = x & 0x3; | |
859 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
860 | r += 8; | |
861 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
862 | g += 4; | |
863 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
864 | b += 8; | |
865 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
866 | XPutPixel(xim, x, y, val); | |
867 | } | |
868 | } | |
869 | } | |
870 | } | |
871 | ||
872 | void | |
873 | grender_16_dither(GdkImlibImage * im, int w, int h, XImage * xim, | |
874 | XImage * sxim, int *er1, int *er2, int *xarray, | |
875 | unsigned char **yarray) | |
876 | { | |
877 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
878 | unsigned char *ptr2; | |
879 | ||
880 | for (y = 0; y < h; y++) | |
881 | { | |
882 | ter = er1; | |
883 | er1 = er2; | |
884 | er2 = ter; | |
885 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
886 | er2[ex] = 0; | |
887 | ex = 3; | |
888 | for (x = 0; x < w; x++) | |
889 | { | |
890 | ptr2 = yarray[y] + xarray[x]; | |
891 | r = (int)*ptr2++; | |
892 | g = (int)*ptr2++; | |
893 | b = (int)*ptr2; | |
894 | er = r + er1[ex++]; | |
895 | eg = g + er1[ex++]; | |
896 | eb = b + er1[ex++]; | |
897 | if (er > 255) | |
898 | er = 255; | |
899 | if (eg > 255) | |
900 | eg = 255; | |
901 | if (eb > 255) | |
902 | eb = 255; | |
903 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
904 | er = er & 0x07; | |
905 | eg = eg & 0x03; | |
906 | eb = eb & 0x07; | |
907 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
908 | XPutPixel(xim, x, y, val); | |
909 | } | |
910 | } | |
911 | } | |
912 | ||
913 | void | |
914 | grender_16_dither_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
915 | XImage * sxim, int *er1, int *er2, int *xarray, | |
916 | unsigned char **yarray) | |
917 | { | |
918 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
919 | unsigned char *ptr2; | |
920 | ||
921 | unsigned char dither[4][4] = | |
922 | { | |
923 | {0, 4, 6, 5}, | |
924 | {6, 2, 7, 3}, | |
925 | {2, 6, 1, 5}, | |
926 | {7, 4, 7, 3} | |
927 | }; | |
928 | int dithy, dithx; | |
929 | ||
930 | for (y = 0; y < h; y++) | |
931 | { | |
932 | dithy = y & 0x3; | |
933 | for (x = 0; x < w; x++) | |
934 | { | |
935 | ptr2 = yarray[y] + xarray[x]; | |
936 | r = (int)*ptr2++; | |
937 | g = (int)*ptr2++; | |
938 | b = (int)*ptr2; | |
939 | er = r & 0x07; | |
940 | eg = g & 0x03; | |
941 | eb = b & 0x07; | |
942 | dithx = x & 0x3; | |
943 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
944 | r += 8; | |
945 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
946 | g += 4; | |
947 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
948 | b += 8; | |
949 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
950 | XPutPixel(xim, x, y, val); | |
951 | } | |
952 | } | |
953 | } | |
954 | ||
955 | void | |
956 | grender_shaped_15_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
957 | XImage * sxim, int *er1, int *er2, int *xarray, | |
958 | unsigned char **yarray) | |
959 | { | |
960 | int x, y, val, r, g, b; | |
961 | unsigned char *ptr2; | |
962 | unsigned short *img; | |
963 | int jmp; | |
964 | ||
965 | jmp = (xim->bytes_per_line >> 1) - w; | |
966 | img = (unsigned short *)xim->data; | |
967 | for (y = 0; y < h; y++) | |
968 | { | |
969 | for (x = 0; x < w; x++) | |
970 | { | |
971 | ptr2 = yarray[y] + xarray[x]; | |
972 | r = (int)*ptr2++; | |
973 | g = (int)*ptr2++; | |
974 | b = (int)*ptr2; | |
975 | if ((r == im->shape_color.r) && | |
976 | (g == im->shape_color.g) && | |
977 | (b == im->shape_color.b)) | |
978 | { | |
979 | XPutPixel(sxim, x, y, 0); | |
980 | img++; | |
981 | } | |
982 | else | |
983 | { | |
984 | XPutPixel(sxim, x, y, 1); | |
985 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
986 | *img++ = val; | |
987 | } | |
988 | } | |
989 | img += jmp; | |
990 | } | |
991 | } | |
992 | ||
993 | void | |
994 | grender_15_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
995 | XImage * sxim, int *er1, int *er2, int *xarray, | |
996 | unsigned char **yarray) | |
997 | { | |
998 | int x, y, val, r, g, b; | |
999 | unsigned char *ptr2; | |
1000 | unsigned short *img; | |
1001 | int jmp; | |
1002 | ||
1003 | jmp = (xim->bytes_per_line >> 1) - w; | |
1004 | img = (unsigned short *)xim->data; | |
1005 | for (y = 0; y < h; y++) | |
1006 | { | |
1007 | for (x = 0; x < w; x++) | |
1008 | { | |
1009 | ptr2 = yarray[y] + xarray[x]; | |
1010 | r = (int)*ptr2++; | |
1011 | g = (int)*ptr2++; | |
1012 | b = (int)*ptr2; | |
1013 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
1014 | *img++ = val; | |
1015 | } | |
1016 | img += jmp; | |
1017 | } | |
1018 | } | |
1019 | ||
1020 | void | |
1021 | grender_shaped_16_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
1022 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1023 | unsigned char **yarray) | |
1024 | { | |
1025 | int x, y, val, r, g, b; | |
1026 | unsigned char *ptr2; | |
1027 | unsigned short *img; | |
1028 | int jmp; | |
1029 | ||
1030 | jmp = (xim->bytes_per_line >> 1) - w; | |
1031 | img = (unsigned short *)xim->data; | |
1032 | for (y = 0; y < h; y++) | |
1033 | { | |
1034 | for (x = 0; x < w; x++) | |
1035 | { | |
1036 | ptr2 = yarray[y] + xarray[x]; | |
1037 | r = (int)*ptr2++; | |
1038 | g = (int)*ptr2++; | |
1039 | b = (int)*ptr2; | |
1040 | if ((r == im->shape_color.r) && | |
1041 | (g == im->shape_color.g) && | |
1042 | (b == im->shape_color.b)) | |
1043 | { | |
1044 | XPutPixel(sxim, x, y, 0); | |
1045 | img++; | |
1046 | } | |
1047 | else | |
1048 | { | |
1049 | XPutPixel(sxim, x, y, 1); | |
1050 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
1051 | *img++ = val; | |
1052 | } | |
1053 | } | |
1054 | img += jmp; | |
1055 | } | |
1056 | } | |
1057 | ||
1058 | void | |
1059 | grender_16_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
1060 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1061 | unsigned char **yarray) | |
1062 | { | |
1063 | int x, y, val, r, g, b; | |
1064 | unsigned char *ptr2; | |
1065 | ||
1066 | unsigned short *img; | |
1067 | int jmp; | |
1068 | ||
1069 | jmp = (xim->bytes_per_line >> 1) - w; | |
1070 | img = (unsigned short *)xim->data; | |
1071 | for (y = 0; y < h; y++) | |
1072 | { | |
1073 | for (x = 0; x < w; x++) | |
1074 | { | |
1075 | ptr2 = yarray[y] + xarray[x]; | |
1076 | r = (int)*ptr2++; | |
1077 | g = (int)*ptr2++; | |
1078 | b = (int)*ptr2; | |
1079 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
1080 | *img++ = val; | |
1081 | } | |
1082 | img += jmp; | |
1083 | } | |
1084 | } | |
1085 | ||
1086 | void | |
1087 | grender_shaped_24_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
1088 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1089 | unsigned char **yarray) | |
1090 | { | |
1091 | int x, y, r, g, b; | |
1092 | unsigned char *ptr2; | |
1093 | unsigned char *img; | |
1094 | int jmp; | |
1095 | ||
1096 | jmp = (xim->bytes_per_line) - w; | |
1097 | img = (unsigned char *)xim->data; | |
1098 | if (id->byte_order == BYTE_ORD_24_RGB) | |
1099 | { | |
1100 | for (y = 0; y < h; y++) | |
1101 | { | |
1102 | for (x = 0; x < w; x++) | |
1103 | { | |
1104 | ptr2 = yarray[y] + xarray[x]; | |
1105 | r = (int)*ptr2++; | |
1106 | g = (int)*ptr2++; | |
1107 | b = (int)*ptr2; | |
1108 | if ((r == im->shape_color.r) && | |
1109 | (g == im->shape_color.g) && | |
1110 | (b == im->shape_color.b)) | |
1111 | { | |
1112 | XPutPixel(sxim, x, y, 0); | |
1113 | img += 3; | |
1114 | } | |
1115 | else | |
1116 | { | |
1117 | XPutPixel(sxim, x, y, 1); | |
1118 | *img++ = r; | |
1119 | *img++ = g; | |
1120 | *img++ = b; | |
1121 | } | |
1122 | } | |
1123 | img += jmp; | |
1124 | } | |
1125 | } | |
1126 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
1127 | { | |
1128 | for (y = 0; y < h; y++) | |
1129 | { | |
1130 | for (x = 0; x < w; x++) | |
1131 | { | |
1132 | ptr2 = yarray[y] + xarray[x]; | |
1133 | r = (int)*ptr2++; | |
1134 | g = (int)*ptr2++; | |
1135 | b = (int)*ptr2; | |
1136 | if ((r == im->shape_color.r) && | |
1137 | (g == im->shape_color.g) && | |
1138 | (b == im->shape_color.b)) | |
1139 | { | |
1140 | XPutPixel(sxim, x, y, 0); | |
1141 | img += 3; | |
1142 | } | |
1143 | else | |
1144 | { | |
1145 | XPutPixel(sxim, x, y, 1); | |
1146 | *img++ = r; | |
1147 | *img++ = b; | |
1148 | *img++ = g; | |
1149 | } | |
1150 | } | |
1151 | img += jmp; | |
1152 | } | |
1153 | } | |
1154 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
1155 | { | |
1156 | for (y = 0; y < h; y++) | |
1157 | { | |
1158 | for (x = 0; x < w; x++) | |
1159 | { | |
1160 | ptr2 = yarray[y] + xarray[x]; | |
1161 | r = (int)*ptr2++; | |
1162 | g = (int)*ptr2++; | |
1163 | b = (int)*ptr2; | |
1164 | if ((r == im->shape_color.r) && | |
1165 | (g == im->shape_color.g) && | |
1166 | (b == im->shape_color.b)) | |
1167 | { | |
1168 | XPutPixel(sxim, x, y, 0); | |
1169 | img += 3; | |
1170 | } | |
1171 | else | |
1172 | { | |
1173 | XPutPixel(sxim, x, y, 1); | |
1174 | *img++ = b; | |
1175 | *img++ = r; | |
1176 | *img++ = g; | |
1177 | } | |
1178 | } | |
1179 | img += jmp; | |
1180 | } | |
1181 | } | |
1182 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
1183 | { | |
1184 | for (y = 0; y < h; y++) | |
1185 | { | |
1186 | for (x = 0; x < w; x++) | |
1187 | { | |
1188 | ptr2 = yarray[y] + xarray[x]; | |
1189 | r = (int)*ptr2++; | |
1190 | g = (int)*ptr2++; | |
1191 | b = (int)*ptr2; | |
1192 | if ((r == im->shape_color.r) && | |
1193 | (g == im->shape_color.g) && | |
1194 | (b == im->shape_color.b)) | |
1195 | { | |
1196 | XPutPixel(sxim, x, y, 0); | |
1197 | img += 3; | |
1198 | } | |
1199 | else | |
1200 | { | |
1201 | XPutPixel(sxim, x, y, 1); | |
1202 | *img++ = b; | |
1203 | *img++ = g; | |
1204 | *img++ = r; | |
1205 | } | |
1206 | } | |
1207 | img += jmp; | |
1208 | } | |
1209 | } | |
1210 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
1211 | { | |
1212 | for (y = 0; y < h; y++) | |
1213 | { | |
1214 | for (x = 0; x < w; x++) | |
1215 | { | |
1216 | ptr2 = yarray[y] + xarray[x]; | |
1217 | r = (int)*ptr2++; | |
1218 | g = (int)*ptr2++; | |
1219 | b = (int)*ptr2; | |
1220 | if ((r == im->shape_color.r) && | |
1221 | (g == im->shape_color.g) && | |
1222 | (b == im->shape_color.b)) | |
1223 | { | |
1224 | XPutPixel(sxim, x, y, 0); | |
1225 | img += 3; | |
1226 | } | |
1227 | else | |
1228 | { | |
1229 | XPutPixel(sxim, x, y, 1); | |
1230 | *img++ = g; | |
1231 | *img++ = r; | |
1232 | *img++ = b; | |
1233 | } | |
1234 | } | |
1235 | img += jmp; | |
1236 | } | |
1237 | } | |
1238 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
1239 | { | |
1240 | for (y = 0; y < h; y++) | |
1241 | { | |
1242 | for (x = 0; x < w; x++) | |
1243 | { | |
1244 | ptr2 = yarray[y] + xarray[x]; | |
1245 | r = (int)*ptr2++; | |
1246 | g = (int)*ptr2++; | |
1247 | b = (int)*ptr2; | |
1248 | if ((r == im->shape_color.r) && | |
1249 | (g == im->shape_color.g) && | |
1250 | (b == im->shape_color.b)) | |
1251 | { | |
1252 | XPutPixel(sxim, x, y, 0); | |
1253 | img += 3; | |
1254 | } | |
1255 | else | |
1256 | { | |
1257 | XPutPixel(sxim, x, y, 1); | |
1258 | *img++ = g; | |
1259 | *img++ = b; | |
1260 | *img++ = r; | |
1261 | } | |
1262 | } | |
1263 | img += jmp; | |
1264 | } | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | void | |
1269 | grender_24_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
1270 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1271 | unsigned char **yarray) | |
1272 | { | |
1273 | int x, y, r, g, b; | |
1274 | unsigned char *ptr2; | |
1275 | unsigned char *img; | |
1276 | int jmp; | |
1277 | ||
1278 | jmp = (xim->bytes_per_line) - w; | |
1279 | img = (unsigned char *)xim->data; | |
1280 | if (id->byte_order == BYTE_ORD_24_RGB) | |
1281 | { | |
1282 | for (y = 0; y < h; y++) | |
1283 | { | |
1284 | for (x = 0; x < w; x++) | |
1285 | { | |
1286 | ptr2 = yarray[y] + xarray[x]; | |
1287 | r = (int)*ptr2++; | |
1288 | g = (int)*ptr2++; | |
1289 | b = (int)*ptr2; | |
1290 | *img++ = r; | |
1291 | *img++ = g; | |
1292 | *img++ = b; | |
1293 | } | |
1294 | img += jmp; | |
1295 | } | |
1296 | } | |
1297 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
1298 | { | |
1299 | for (y = 0; y < h; y++) | |
1300 | { | |
1301 | for (x = 0; x < w; x++) | |
1302 | { | |
1303 | ptr2 = yarray[y] + xarray[x]; | |
1304 | r = (int)*ptr2++; | |
1305 | g = (int)*ptr2++; | |
1306 | b = (int)*ptr2; | |
1307 | *img++ = r; | |
1308 | *img++ = b; | |
1309 | *img++ = g; | |
1310 | } | |
1311 | img += jmp; | |
1312 | } | |
1313 | } | |
1314 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
1315 | { | |
1316 | for (y = 0; y < h; y++) | |
1317 | { | |
1318 | for (x = 0; x < w; x++) | |
1319 | { | |
1320 | ptr2 = yarray[y] + xarray[x]; | |
1321 | r = (int)*ptr2++; | |
1322 | g = (int)*ptr2++; | |
1323 | b = (int)*ptr2; | |
1324 | *img++ = b; | |
1325 | *img++ = r; | |
1326 | *img++ = g; | |
1327 | } | |
1328 | img += jmp; | |
1329 | } | |
1330 | } | |
1331 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
1332 | { | |
1333 | for (y = 0; y < h; y++) | |
1334 | { | |
1335 | for (x = 0; x < w; x++) | |
1336 | { | |
1337 | ptr2 = yarray[y] + xarray[x]; | |
1338 | r = (int)*ptr2++; | |
1339 | g = (int)*ptr2++; | |
1340 | b = (int)*ptr2; | |
1341 | *img++ = b; | |
1342 | *img++ = g; | |
1343 | *img++ = r; | |
1344 | } | |
1345 | img += jmp; | |
1346 | } | |
1347 | } | |
1348 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
1349 | { | |
1350 | for (y = 0; y < h; y++) | |
1351 | { | |
1352 | for (x = 0; x < w; x++) | |
1353 | { | |
1354 | ptr2 = yarray[y] + xarray[x]; | |
1355 | r = (int)*ptr2++; | |
1356 | g = (int)*ptr2++; | |
1357 | b = (int)*ptr2; | |
1358 | *img++ = g; | |
1359 | *img++ = r; | |
1360 | *img++ = b; | |
1361 | } | |
1362 | img += jmp; | |
1363 | } | |
1364 | } | |
1365 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
1366 | { | |
1367 | for (y = 0; y < h; y++) | |
1368 | { | |
1369 | for (x = 0; x < w; x++) | |
1370 | { | |
1371 | ptr2 = yarray[y] + xarray[x]; | |
1372 | r = (int)*ptr2++; | |
1373 | g = (int)*ptr2++; | |
1374 | b = (int)*ptr2; | |
1375 | *img++ = g; | |
1376 | *img++ = b; | |
1377 | *img++ = r; | |
1378 | } | |
1379 | img += jmp; | |
1380 | } | |
1381 | } | |
1382 | } | |
1383 | ||
1384 | void | |
1385 | grender_shaped_32_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
1386 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1387 | unsigned char **yarray) | |
1388 | { | |
1389 | int x, y, val, r, g, b; | |
1390 | unsigned char *ptr2; | |
1391 | unsigned int *img; | |
1392 | int jmp; | |
1393 | ||
1394 | jmp = (xim->bytes_per_line >> 2) - w; | |
1395 | img = (unsigned int *)xim->data; | |
1396 | if (id->byte_order == BYTE_ORD_24_RGB) | |
1397 | { | |
1398 | for (y = 0; y < h; y++) | |
1399 | { | |
1400 | for (x = 0; x < w; x++) | |
1401 | { | |
1402 | ptr2 = yarray[y] + xarray[x]; | |
1403 | r = (int)*ptr2++; | |
1404 | g = (int)*ptr2++; | |
1405 | b = (int)*ptr2; | |
1406 | if ((r == im->shape_color.r) && | |
1407 | (g == im->shape_color.g) && | |
1408 | (b == im->shape_color.b)) | |
1409 | { | |
1410 | XPutPixel(sxim, x, y, 0); | |
1411 | img++; | |
1412 | } | |
1413 | else | |
1414 | { | |
1415 | XPutPixel(sxim, x, y, 1); | |
1416 | val = (r << 16) | (g << 8) | b; | |
1417 | *img++ = val; | |
1418 | } | |
1419 | } | |
1420 | img += jmp; | |
1421 | } | |
1422 | } | |
1423 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
1424 | { | |
1425 | for (y = 0; y < h; y++) | |
1426 | { | |
1427 | for (x = 0; x < w; x++) | |
1428 | { | |
1429 | ptr2 = yarray[y] + xarray[x]; | |
1430 | r = (int)*ptr2++; | |
1431 | g = (int)*ptr2++; | |
1432 | b = (int)*ptr2; | |
1433 | if ((r == im->shape_color.r) && | |
1434 | (g == im->shape_color.g) && | |
1435 | (b == im->shape_color.b)) | |
1436 | { | |
1437 | XPutPixel(sxim, x, y, 0); | |
1438 | img++; | |
1439 | } | |
1440 | else | |
1441 | { | |
1442 | XPutPixel(sxim, x, y, 1); | |
1443 | val = (r << 16) | (b << 8) | g; | |
1444 | *img++ = val; | |
1445 | } | |
1446 | } | |
1447 | img += jmp; | |
1448 | } | |
1449 | } | |
1450 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
1451 | { | |
1452 | for (y = 0; y < h; y++) | |
1453 | { | |
1454 | for (x = 0; x < w; x++) | |
1455 | { | |
1456 | ptr2 = yarray[y] + xarray[x]; | |
1457 | r = (int)*ptr2++; | |
1458 | g = (int)*ptr2++; | |
1459 | b = (int)*ptr2; | |
1460 | if ((r == im->shape_color.r) && | |
1461 | (g == im->shape_color.g) && | |
1462 | (b == im->shape_color.b)) | |
1463 | { | |
1464 | XPutPixel(sxim, x, y, 0); | |
1465 | img++; | |
1466 | } | |
1467 | else | |
1468 | { | |
1469 | XPutPixel(sxim, x, y, 1); | |
1470 | val = (b << 16) | (r << 8) | g; | |
1471 | *img++ = val; | |
1472 | } | |
1473 | } | |
1474 | img += jmp; | |
1475 | } | |
1476 | } | |
1477 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
1478 | { | |
1479 | for (y = 0; y < h; y++) | |
1480 | { | |
1481 | for (x = 0; x < w; x++) | |
1482 | { | |
1483 | ptr2 = yarray[y] + xarray[x]; | |
1484 | r = (int)*ptr2++; | |
1485 | g = (int)*ptr2++; | |
1486 | b = (int)*ptr2; | |
1487 | if ((r == im->shape_color.r) && | |
1488 | (g == im->shape_color.g) && | |
1489 | (b == im->shape_color.b)) | |
1490 | { | |
1491 | XPutPixel(sxim, x, y, 0); | |
1492 | img++; | |
1493 | } | |
1494 | else | |
1495 | { | |
1496 | XPutPixel(sxim, x, y, 1); | |
1497 | val = (b << 16) | (g << 8) | r; | |
1498 | *img++ = val; | |
1499 | } | |
1500 | } | |
1501 | img += jmp; | |
1502 | } | |
1503 | } | |
1504 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
1505 | { | |
1506 | for (y = 0; y < h; y++) | |
1507 | { | |
1508 | for (x = 0; x < w; x++) | |
1509 | { | |
1510 | ptr2 = yarray[y] + xarray[x]; | |
1511 | r = (int)*ptr2++; | |
1512 | g = (int)*ptr2++; | |
1513 | b = (int)*ptr2; | |
1514 | if ((r == im->shape_color.r) && | |
1515 | (g == im->shape_color.g) && | |
1516 | (b == im->shape_color.b)) | |
1517 | { | |
1518 | XPutPixel(sxim, x, y, 0); | |
1519 | img++; | |
1520 | } | |
1521 | else | |
1522 | { | |
1523 | XPutPixel(sxim, x, y, 1); | |
1524 | val = (g << 16) | (r << 8) | b; | |
1525 | *img++ = val; | |
1526 | } | |
1527 | } | |
1528 | img += jmp; | |
1529 | } | |
1530 | } | |
1531 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
1532 | { | |
1533 | for (y = 0; y < h; y++) | |
1534 | { | |
1535 | for (x = 0; x < w; x++) | |
1536 | { | |
1537 | ptr2 = yarray[y] + xarray[x]; | |
1538 | r = (int)*ptr2++; | |
1539 | g = (int)*ptr2++; | |
1540 | b = (int)*ptr2; | |
1541 | if ((r == im->shape_color.r) && | |
1542 | (g == im->shape_color.g) && | |
1543 | (b == im->shape_color.b)) | |
1544 | { | |
1545 | XPutPixel(sxim, x, y, 0); | |
1546 | img++; | |
1547 | } | |
1548 | else | |
1549 | { | |
1550 | XPutPixel(sxim, x, y, 1); | |
1551 | val = (g << 16) | (b << 8) | r; | |
1552 | *img++ = val; | |
1553 | } | |
1554 | } | |
1555 | img += jmp; | |
1556 | } | |
1557 | } | |
1558 | } | |
1559 | ||
1560 | void | |
1561 | grender_32_fast(GdkImlibImage * im, int w, int h, XImage * xim, | |
1562 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1563 | unsigned char **yarray) | |
1564 | { | |
1565 | int x, y, val, r, g, b; | |
1566 | unsigned char *ptr2; | |
1567 | unsigned int *img; | |
1568 | int jmp; | |
1569 | ||
1570 | jmp = (xim->bytes_per_line >> 2) - w; | |
1571 | img = (unsigned int *)xim->data; | |
1572 | if (id->byte_order == BYTE_ORD_24_RGB) | |
1573 | { | |
1574 | for (y = 0; y < h; y++) | |
1575 | { | |
1576 | for (x = 0; x < w; x++) | |
1577 | { | |
1578 | ptr2 = yarray[y] + xarray[x]; | |
1579 | r = (int)*ptr2++; | |
1580 | g = (int)*ptr2++; | |
1581 | b = (int)*ptr2; | |
1582 | val = (r << 16) | (g << 8) | b; | |
1583 | *img++ = val; | |
1584 | } | |
1585 | img += jmp; | |
1586 | } | |
1587 | } | |
1588 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
1589 | { | |
1590 | for (y = 0; y < h; y++) | |
1591 | { | |
1592 | for (x = 0; x < w; x++) | |
1593 | { | |
1594 | ptr2 = yarray[y] + xarray[x]; | |
1595 | r = (int)*ptr2++; | |
1596 | g = (int)*ptr2++; | |
1597 | b = (int)*ptr2; | |
1598 | val = (r << 16) | (b << 8) | g; | |
1599 | *img++ = val; | |
1600 | } | |
1601 | img += jmp; | |
1602 | } | |
1603 | } | |
1604 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
1605 | { | |
1606 | for (y = 0; y < h; y++) | |
1607 | { | |
1608 | for (x = 0; x < w; x++) | |
1609 | { | |
1610 | ptr2 = yarray[y] + xarray[x]; | |
1611 | r = (int)*ptr2++; | |
1612 | g = (int)*ptr2++; | |
1613 | b = (int)*ptr2; | |
1614 | val = (b << 16) | (r << 8) | g; | |
1615 | *img++ = val; | |
1616 | } | |
1617 | img += jmp; | |
1618 | } | |
1619 | } | |
1620 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
1621 | { | |
1622 | for (y = 0; y < h; y++) | |
1623 | { | |
1624 | for (x = 0; x < w; x++) | |
1625 | { | |
1626 | ptr2 = yarray[y] + xarray[x]; | |
1627 | r = (int)*ptr2++; | |
1628 | g = (int)*ptr2++; | |
1629 | b = (int)*ptr2; | |
1630 | val = (b << 16) | (g << 8) | r; | |
1631 | *img++ = val; | |
1632 | } | |
1633 | img += jmp; | |
1634 | } | |
1635 | } | |
1636 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
1637 | { | |
1638 | for (y = 0; y < h; y++) | |
1639 | { | |
1640 | for (x = 0; x < w; x++) | |
1641 | { | |
1642 | ptr2 = yarray[y] + xarray[x]; | |
1643 | r = (int)*ptr2++; | |
1644 | g = (int)*ptr2++; | |
1645 | b = (int)*ptr2; | |
1646 | val = (g << 16) | (r << 8) | b; | |
1647 | *img++ = val; | |
1648 | } | |
1649 | img += jmp; | |
1650 | } | |
1651 | } | |
1652 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
1653 | { | |
1654 | for (y = 0; y < h; y++) | |
1655 | { | |
1656 | for (x = 0; x < w; x++) | |
1657 | { | |
1658 | ptr2 = yarray[y] + xarray[x]; | |
1659 | r = (int)*ptr2++; | |
1660 | g = (int)*ptr2++; | |
1661 | b = (int)*ptr2; | |
1662 | val = (g << 16) | (b << 8) | r; | |
1663 | *img++ = val; | |
1664 | } | |
1665 | img += jmp; | |
1666 | } | |
1667 | } | |
1668 | } | |
1669 | ||
1670 | void | |
1671 | grender_shaped_15(GdkImlibImage * im, int w, int h, XImage * xim, | |
1672 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1673 | unsigned char **yarray) | |
1674 | { | |
1675 | int x, y, val, r, g, b; | |
1676 | unsigned char *ptr2; | |
1677 | ||
1678 | for (y = 0; y < h; y++) | |
1679 | { | |
1680 | for (x = 0; x < w; x++) | |
1681 | { | |
1682 | ptr2 = yarray[y] + xarray[x]; | |
1683 | r = (int)*ptr2++; | |
1684 | g = (int)*ptr2++; | |
1685 | b = (int)*ptr2; | |
1686 | if ((r == im->shape_color.r) && | |
1687 | (g == im->shape_color.g) && | |
1688 | (b == im->shape_color.b)) | |
1689 | XPutPixel(sxim, x, y, 0); | |
1690 | else | |
1691 | { | |
1692 | XPutPixel(sxim, x, y, 1); | |
1693 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
1694 | XPutPixel(xim, x, y, val); | |
1695 | } | |
1696 | } | |
1697 | } | |
1698 | } | |
1699 | ||
1700 | void | |
1701 | grender_15(GdkImlibImage * im, int w, int h, XImage * xim, | |
1702 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1703 | unsigned char **yarray) | |
1704 | { | |
1705 | int x, y, val, r, g, b; | |
1706 | unsigned char *ptr2; | |
1707 | ||
1708 | for (y = 0; y < h; y++) | |
1709 | { | |
1710 | for (x = 0; x < w; x++) | |
1711 | { | |
1712 | ptr2 = yarray[y] + xarray[x]; | |
1713 | r = (int)*ptr2++; | |
1714 | g = (int)*ptr2++; | |
1715 | b = (int)*ptr2; | |
1716 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
1717 | XPutPixel(xim, x, y, val); | |
1718 | } | |
1719 | } | |
1720 | } | |
1721 | ||
1722 | void | |
1723 | grender_shaped_16(GdkImlibImage * im, int w, int h, XImage * xim, | |
1724 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1725 | unsigned char **yarray) | |
1726 | { | |
1727 | int x, y, val, r, g, b; | |
1728 | unsigned char *ptr2; | |
1729 | ||
1730 | for (y = 0; y < h; y++) | |
1731 | { | |
1732 | for (x = 0; x < w; x++) | |
1733 | { | |
1734 | ptr2 = yarray[y] + xarray[x]; | |
1735 | r = (int)*ptr2++; | |
1736 | g = (int)*ptr2++; | |
1737 | b = (int)*ptr2; | |
1738 | if ((r == im->shape_color.r) && | |
1739 | (g == im->shape_color.g) && | |
1740 | (b == im->shape_color.b)) | |
1741 | XPutPixel(sxim, x, y, 0); | |
1742 | else | |
1743 | { | |
1744 | XPutPixel(sxim, x, y, 1); | |
1745 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
1746 | XPutPixel(xim, x, y, val); | |
1747 | } | |
1748 | } | |
1749 | } | |
1750 | } | |
1751 | ||
1752 | void | |
1753 | grender_16(GdkImlibImage * im, int w, int h, XImage * xim, | |
1754 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1755 | unsigned char **yarray) | |
1756 | { | |
1757 | int x, y, val, r, g, b; | |
1758 | unsigned char *ptr2; | |
1759 | ||
1760 | for (y = 0; y < h; y++) | |
1761 | { | |
1762 | for (x = 0; x < w; x++) | |
1763 | { | |
1764 | ptr2 = yarray[y] + xarray[x]; | |
1765 | r = (int)*ptr2++; | |
1766 | g = (int)*ptr2++; | |
1767 | b = (int)*ptr2; | |
1768 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
1769 | XPutPixel(xim, x, y, val); | |
1770 | } | |
1771 | } | |
1772 | } | |
1773 | ||
1774 | void | |
1775 | grender_shaped_24(GdkImlibImage * im, int w, int h, XImage * xim, | |
1776 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1777 | unsigned char **yarray) | |
1778 | { | |
1779 | int x, y, val, r, g, b; | |
1780 | unsigned char *ptr2; | |
1781 | ||
1782 | if (id->byte_order == BYTE_ORD_24_RGB) | |
1783 | { | |
1784 | for (y = 0; y < h; y++) | |
1785 | { | |
1786 | for (x = 0; x < w; x++) | |
1787 | { | |
1788 | ptr2 = yarray[y] + xarray[x]; | |
1789 | r = (int)*ptr2++; | |
1790 | g = (int)*ptr2++; | |
1791 | b = (int)*ptr2; | |
1792 | if ((r == im->shape_color.r) && | |
1793 | (g == im->shape_color.g) && | |
1794 | (b == im->shape_color.b)) | |
1795 | XPutPixel(sxim, x, y, 0); | |
1796 | else | |
1797 | { | |
1798 | XPutPixel(sxim, x, y, 1); | |
1799 | val = (r << 16) | (g << 8) | b; | |
1800 | XPutPixel(xim, x, y, val); | |
1801 | } | |
1802 | } | |
1803 | } | |
1804 | } | |
1805 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
1806 | { | |
1807 | for (y = 0; y < h; y++) | |
1808 | { | |
1809 | for (x = 0; x < w; x++) | |
1810 | { | |
1811 | ptr2 = yarray[y] + xarray[x]; | |
1812 | r = (int)*ptr2++; | |
1813 | g = (int)*ptr2++; | |
1814 | b = (int)*ptr2; | |
1815 | if ((r == im->shape_color.r) && | |
1816 | (g == im->shape_color.g) && | |
1817 | (b == im->shape_color.b)) | |
1818 | XPutPixel(sxim, x, y, 0); | |
1819 | else | |
1820 | { | |
1821 | XPutPixel(sxim, x, y, 1); | |
1822 | val = (r << 16) | (b << 8) | g; | |
1823 | XPutPixel(xim, x, y, val); | |
1824 | } | |
1825 | } | |
1826 | } | |
1827 | } | |
1828 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
1829 | { | |
1830 | for (y = 0; y < h; y++) | |
1831 | { | |
1832 | for (x = 0; x < w; x++) | |
1833 | { | |
1834 | ptr2 = yarray[y] + xarray[x]; | |
1835 | r = (int)*ptr2++; | |
1836 | g = (int)*ptr2++; | |
1837 | b = (int)*ptr2; | |
1838 | if ((r == im->shape_color.r) && | |
1839 | (g == im->shape_color.g) && | |
1840 | (b == im->shape_color.b)) | |
1841 | XPutPixel(sxim, x, y, 0); | |
1842 | else | |
1843 | { | |
1844 | XPutPixel(sxim, x, y, 1); | |
1845 | val = (b << 16) | (r << 8) | g; | |
1846 | XPutPixel(xim, x, y, val); | |
1847 | } | |
1848 | } | |
1849 | } | |
1850 | } | |
1851 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
1852 | { | |
1853 | for (y = 0; y < h; y++) | |
1854 | { | |
1855 | for (x = 0; x < w; x++) | |
1856 | { | |
1857 | ptr2 = yarray[y] + xarray[x]; | |
1858 | r = (int)*ptr2++; | |
1859 | g = (int)*ptr2++; | |
1860 | b = (int)*ptr2; | |
1861 | if ((r == im->shape_color.r) && | |
1862 | (g == im->shape_color.g) && | |
1863 | (b == im->shape_color.b)) | |
1864 | XPutPixel(sxim, x, y, 0); | |
1865 | else | |
1866 | { | |
1867 | XPutPixel(sxim, x, y, 1); | |
1868 | val = (b << 16) | (g << 8) | r; | |
1869 | XPutPixel(xim, x, y, val); | |
1870 | } | |
1871 | } | |
1872 | } | |
1873 | } | |
1874 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
1875 | { | |
1876 | for (y = 0; y < h; y++) | |
1877 | { | |
1878 | for (x = 0; x < w; x++) | |
1879 | { | |
1880 | ptr2 = yarray[y] + xarray[x]; | |
1881 | r = (int)*ptr2++; | |
1882 | g = (int)*ptr2++; | |
1883 | b = (int)*ptr2; | |
1884 | if ((r == im->shape_color.r) && | |
1885 | (g == im->shape_color.g) && | |
1886 | (b == im->shape_color.b)) | |
1887 | XPutPixel(sxim, x, y, 0); | |
1888 | else | |
1889 | { | |
1890 | XPutPixel(sxim, x, y, 1); | |
1891 | val = (g << 16) | (r << 8) | b; | |
1892 | XPutPixel(xim, x, y, val); | |
1893 | } | |
1894 | } | |
1895 | } | |
1896 | } | |
1897 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
1898 | { | |
1899 | for (y = 0; y < h; y++) | |
1900 | { | |
1901 | for (x = 0; x < w; x++) | |
1902 | { | |
1903 | ptr2 = yarray[y] + xarray[x]; | |
1904 | r = (int)*ptr2++; | |
1905 | g = (int)*ptr2++; | |
1906 | b = (int)*ptr2; | |
1907 | if ((r == im->shape_color.r) && | |
1908 | (g == im->shape_color.g) && | |
1909 | (b == im->shape_color.b)) | |
1910 | XPutPixel(sxim, x, y, 0); | |
1911 | else | |
1912 | { | |
1913 | XPutPixel(sxim, x, y, 1); | |
1914 | val = (g << 16) | (b << 8) | r; | |
1915 | XPutPixel(xim, x, y, val); | |
1916 | } | |
1917 | } | |
1918 | } | |
1919 | } | |
1920 | } | |
1921 | ||
1922 | void | |
1923 | grender_24(GdkImlibImage * im, int w, int h, XImage * xim, | |
1924 | XImage * sxim, int *er1, int *er2, int *xarray, | |
1925 | unsigned char **yarray) | |
1926 | { | |
1927 | int x, y, val, r, g, b; | |
1928 | unsigned char *ptr2; | |
1929 | ||
1930 | if (id->byte_order == BYTE_ORD_24_RGB) | |
1931 | { | |
1932 | for (y = 0; y < h; y++) | |
1933 | { | |
1934 | for (x = 0; x < w; x++) | |
1935 | { | |
1936 | ptr2 = yarray[y] + xarray[x]; | |
1937 | r = (int)*ptr2++; | |
1938 | g = (int)*ptr2++; | |
1939 | b = (int)*ptr2; | |
1940 | val = (r << 16) | (g << 8) | b; | |
1941 | XPutPixel(xim, x, y, val); | |
1942 | } | |
1943 | } | |
1944 | } | |
1945 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
1946 | { | |
1947 | for (y = 0; y < h; y++) | |
1948 | { | |
1949 | for (x = 0; x < w; x++) | |
1950 | { | |
1951 | ptr2 = yarray[y] + xarray[x]; | |
1952 | r = (int)*ptr2++; | |
1953 | g = (int)*ptr2++; | |
1954 | b = (int)*ptr2; | |
1955 | val = (r << 16) | (b << 8) | g; | |
1956 | XPutPixel(xim, x, y, val); | |
1957 | } | |
1958 | } | |
1959 | } | |
1960 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
1961 | { | |
1962 | for (y = 0; y < h; y++) | |
1963 | { | |
1964 | for (x = 0; x < w; x++) | |
1965 | { | |
1966 | ptr2 = yarray[y] + xarray[x]; | |
1967 | r = (int)*ptr2++; | |
1968 | g = (int)*ptr2++; | |
1969 | b = (int)*ptr2; | |
1970 | val = (b << 16) | (r << 8) | g; | |
1971 | XPutPixel(xim, x, y, val); | |
1972 | } | |
1973 | } | |
1974 | } | |
1975 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
1976 | { | |
1977 | for (y = 0; y < h; y++) | |
1978 | { | |
1979 | for (x = 0; x < w; x++) | |
1980 | { | |
1981 | ptr2 = yarray[y] + xarray[x]; | |
1982 | r = (int)*ptr2++; | |
1983 | g = (int)*ptr2++; | |
1984 | b = (int)*ptr2; | |
1985 | val = (b << 16) | (g << 8) | r; | |
1986 | XPutPixel(xim, x, y, val); | |
1987 | } | |
1988 | } | |
1989 | } | |
1990 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
1991 | { | |
1992 | for (y = 0; y < h; y++) | |
1993 | { | |
1994 | for (x = 0; x < w; x++) | |
1995 | { | |
1996 | ptr2 = yarray[y] + xarray[x]; | |
1997 | r = (int)*ptr2++; | |
1998 | g = (int)*ptr2++; | |
1999 | b = (int)*ptr2; | |
2000 | val = (g << 16) | (r << 8) | b; | |
2001 | XPutPixel(xim, x, y, val); | |
2002 | } | |
2003 | } | |
2004 | } | |
2005 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
2006 | { | |
2007 | for (y = 0; y < h; y++) | |
2008 | { | |
2009 | for (x = 0; x < w; x++) | |
2010 | { | |
2011 | ptr2 = yarray[y] + xarray[x]; | |
2012 | r = (int)*ptr2++; | |
2013 | g = (int)*ptr2++; | |
2014 | b = (int)*ptr2; | |
2015 | val = (g << 16) | (b << 8) | r; | |
2016 | XPutPixel(xim, x, y, val); | |
2017 | } | |
2018 | } | |
2019 | } | |
2020 | } | |
2021 | ||
2022 | void | |
2023 | grender_shaped(GdkImlibImage * im, int w, int h, XImage * xim, | |
2024 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2025 | unsigned char **yarray, int bpp) | |
2026 | { | |
2027 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2028 | unsigned char *ptr2; | |
2029 | unsigned char *img; | |
2030 | int jmp; | |
2031 | ||
2032 | jmp = (xim->bytes_per_line) - w; | |
2033 | img = (unsigned char *)xim->data; | |
2034 | switch (id->render_type) | |
2035 | { | |
2036 | case RT_PLAIN_PALETTE: | |
2037 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2038 | { | |
2039 | for (y = 0; y < h; y++) | |
2040 | { | |
2041 | for (x = 0; x < w; x++) | |
2042 | { | |
2043 | ptr2 = yarray[y] + xarray[x]; | |
2044 | r = (int)*ptr2++; | |
2045 | g = (int)*ptr2++; | |
2046 | b = (int)*ptr2; | |
2047 | if ((r == im->shape_color.r) && | |
2048 | (g == im->shape_color.g) && | |
2049 | (b == im->shape_color.b)) | |
2050 | { | |
2051 | XPutPixel(sxim, x, y, 0); | |
2052 | img++; | |
2053 | } | |
2054 | else | |
2055 | { | |
2056 | XPutPixel(sxim, x, y, 1); | |
2057 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
2058 | *img++ = val; | |
2059 | } | |
2060 | } | |
2061 | img += jmp; | |
2062 | } | |
2063 | } | |
2064 | else | |
2065 | { | |
2066 | for (y = 0; y < h; y++) | |
2067 | { | |
2068 | for (x = 0; x < w; x++) | |
2069 | { | |
2070 | ptr2 = yarray[y] + xarray[x]; | |
2071 | r = (int)*ptr2++; | |
2072 | g = (int)*ptr2++; | |
2073 | b = (int)*ptr2; | |
2074 | if ((r == im->shape_color.r) && | |
2075 | (g == im->shape_color.g) && | |
2076 | (b == im->shape_color.b)) | |
2077 | XPutPixel(sxim, x, y, 0); | |
2078 | else | |
2079 | { | |
2080 | XPutPixel(sxim, x, y, 1); | |
2081 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
2082 | XPutPixel(xim, x, y, val); | |
2083 | } | |
2084 | } | |
2085 | } | |
2086 | } | |
2087 | break; | |
2088 | case RT_PLAIN_PALETTE_FAST: | |
2089 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2090 | { | |
2091 | for (y = 0; y < h; y++) | |
2092 | { | |
2093 | for (x = 0; x < w; x++) | |
2094 | { | |
2095 | ptr2 = yarray[y] + xarray[x]; | |
2096 | r = (int)*ptr2++; | |
2097 | g = (int)*ptr2++; | |
2098 | b = (int)*ptr2; | |
2099 | if ((r == im->shape_color.r) && | |
2100 | (g == im->shape_color.g) && | |
2101 | (b == im->shape_color.b)) | |
2102 | { | |
2103 | XPutPixel(sxim, x, y, 0); | |
2104 | img++; | |
2105 | } | |
2106 | else | |
2107 | { | |
2108 | XPutPixel(sxim, x, y, 1); | |
2109 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
2110 | *img++ = val; | |
2111 | } | |
2112 | } | |
2113 | img += jmp; | |
2114 | } | |
2115 | } | |
2116 | else | |
2117 | { | |
2118 | for (y = 0; y < h; y++) | |
2119 | { | |
2120 | for (x = 0; x < w; x++) | |
2121 | { | |
2122 | ptr2 = yarray[y] + xarray[x]; | |
2123 | r = (int)*ptr2++; | |
2124 | g = (int)*ptr2++; | |
2125 | b = (int)*ptr2; | |
2126 | if ((r == im->shape_color.r) && | |
2127 | (g == im->shape_color.g) && | |
2128 | (b == im->shape_color.b)) | |
2129 | XPutPixel(sxim, x, y, 0); | |
2130 | else | |
2131 | { | |
2132 | XPutPixel(sxim, x, y, 1); | |
2133 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
2134 | XPutPixel(xim, x, y, val); | |
2135 | } | |
2136 | } | |
2137 | } | |
2138 | } | |
2139 | break; | |
2140 | case RT_DITHER_PALETTE: | |
2141 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2142 | { | |
2143 | for (y = 0; y < h; y++) | |
2144 | { | |
2145 | ter = er1; | |
2146 | er1 = er2; | |
2147 | er2 = ter; | |
2148 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2149 | er2[ex] = 0; | |
2150 | ex = 3; | |
2151 | for (x = 0; x < w; x++) | |
2152 | { | |
2153 | ptr2 = yarray[y] + xarray[x]; | |
2154 | r = (int)*ptr2++; | |
2155 | g = (int)*ptr2++; | |
2156 | b = (int)*ptr2; | |
2157 | if ((r == im->shape_color.r) && | |
2158 | (g == im->shape_color.g) && | |
2159 | (b == im->shape_color.b)) | |
2160 | { | |
2161 | { | |
2162 | XPutPixel(sxim, x, y, 0); | |
2163 | img++; | |
2164 | } | |
2165 | ex += 3; | |
2166 | } | |
2167 | else | |
2168 | { | |
2169 | XPutPixel(sxim, x, y, 1); | |
2170 | er = r + er1[ex++]; | |
2171 | eg = g + er1[ex++]; | |
2172 | eb = b + er1[ex++]; | |
2173 | if (er > 255) | |
2174 | er = 255; | |
2175 | else if (er < 0) | |
2176 | er = 0; | |
2177 | if (eg > 255) | |
2178 | eg = 255; | |
2179 | else if (eg < 0) | |
2180 | eg = 0; | |
2181 | if (eb > 255) | |
2182 | eb = 255; | |
2183 | else if (eb < 0) | |
2184 | eb = 0; | |
2185 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
2186 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2187 | *img++ = val; | |
2188 | } | |
2189 | } | |
2190 | img += jmp; | |
2191 | } | |
2192 | } | |
2193 | else | |
2194 | { | |
2195 | for (y = 0; y < h; y++) | |
2196 | { | |
2197 | ter = er1; | |
2198 | er1 = er2; | |
2199 | er2 = ter; | |
2200 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2201 | er2[ex] = 0; | |
2202 | ex = 3; | |
2203 | for (x = 0; x < w; x++) | |
2204 | { | |
2205 | ptr2 = yarray[y] + xarray[x]; | |
2206 | r = (int)*ptr2++; | |
2207 | g = (int)*ptr2++; | |
2208 | b = (int)*ptr2; | |
2209 | if ((r == im->shape_color.r) && | |
2210 | (g == im->shape_color.g) && | |
2211 | (b == im->shape_color.b)) | |
2212 | { | |
2213 | XPutPixel(sxim, x, y, 0); | |
2214 | ex += 3; | |
2215 | } | |
2216 | else | |
2217 | { | |
2218 | XPutPixel(sxim, x, y, 1); | |
2219 | er = r + er1[ex++]; | |
2220 | eg = g + er1[ex++]; | |
2221 | eb = b + er1[ex++]; | |
2222 | if (er > 255) | |
2223 | er = 255; | |
2224 | else if (er < 0) | |
2225 | er = 0; | |
2226 | if (eg > 255) | |
2227 | eg = 255; | |
2228 | else if (eg < 0) | |
2229 | eg = 0; | |
2230 | if (eb > 255) | |
2231 | eb = 255; | |
2232 | else if (eb < 0) | |
2233 | eb = 0; | |
2234 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
2235 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2236 | XPutPixel(xim, x, y, val); | |
2237 | } | |
2238 | } | |
2239 | } | |
2240 | } | |
2241 | break; | |
2242 | case RT_DITHER_PALETTE_FAST: | |
2243 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2244 | { | |
2245 | for (y = 0; y < h; y++) | |
2246 | { | |
2247 | ter = er1; | |
2248 | er1 = er2; | |
2249 | er2 = ter; | |
2250 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2251 | er2[ex] = 0; | |
2252 | ex = 3; | |
2253 | for (x = 0; x < w; x++) | |
2254 | { | |
2255 | ptr2 = yarray[y] + xarray[x]; | |
2256 | r = (int)*ptr2++; | |
2257 | g = (int)*ptr2++; | |
2258 | b = (int)*ptr2; | |
2259 | if ((r == im->shape_color.r) && | |
2260 | (g == im->shape_color.g) && | |
2261 | (b == im->shape_color.b)) | |
2262 | { | |
2263 | { | |
2264 | XPutPixel(sxim, x, y, 0); | |
2265 | img++; | |
2266 | } | |
2267 | ex += 3; | |
2268 | } | |
2269 | else | |
2270 | { | |
2271 | XPutPixel(sxim, x, y, 1); | |
2272 | er = r + er1[ex++]; | |
2273 | eg = g + er1[ex++]; | |
2274 | eb = b + er1[ex++]; | |
2275 | if (er > 255) | |
2276 | er = 255; | |
2277 | else if (er < 0) | |
2278 | er = 0; | |
2279 | if (eg > 255) | |
2280 | eg = 255; | |
2281 | else if (eg < 0) | |
2282 | eg = 0; | |
2283 | if (eb > 255) | |
2284 | eb = 255; | |
2285 | else if (eb < 0) | |
2286 | eb = 0; | |
2287 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
2288 | er = ERROR_RED(er, val); | |
2289 | eg = ERROR_GRN(eg, val); | |
2290 | eb = ERROR_BLU(eb, val); | |
2291 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2292 | *img++ = COLOR_INDEX(val); | |
2293 | } | |
2294 | } | |
2295 | img += jmp; | |
2296 | } | |
2297 | } | |
2298 | else | |
2299 | { | |
2300 | for (y = 0; y < h; y++) | |
2301 | { | |
2302 | ter = er1; | |
2303 | er1 = er2; | |
2304 | er2 = ter; | |
2305 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2306 | er2[ex] = 0; | |
2307 | ex = 3; | |
2308 | for (x = 0; x < w; x++) | |
2309 | { | |
2310 | ptr2 = yarray[y] + xarray[x]; | |
2311 | r = (int)*ptr2++; | |
2312 | g = (int)*ptr2++; | |
2313 | b = (int)*ptr2; | |
2314 | if ((r == im->shape_color.r) && | |
2315 | (g == im->shape_color.g) && | |
2316 | (b == im->shape_color.b)) | |
2317 | { | |
2318 | XPutPixel(sxim, x, y, 0); | |
2319 | ex += 3; | |
2320 | } | |
2321 | else | |
2322 | { | |
2323 | XPutPixel(sxim, x, y, 1); | |
2324 | er = r + er1[ex++]; | |
2325 | eg = g + er1[ex++]; | |
2326 | eb = b + er1[ex++]; | |
2327 | if (er > 255) | |
2328 | er = 255; | |
2329 | else if (er < 0) | |
2330 | er = 0; | |
2331 | if (eg > 255) | |
2332 | eg = 255; | |
2333 | else if (eg < 0) | |
2334 | eg = 0; | |
2335 | if (eb > 255) | |
2336 | eb = 255; | |
2337 | else if (eb < 0) | |
2338 | eb = 0; | |
2339 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
2340 | er = ERROR_RED(er, val); | |
2341 | eg = ERROR_GRN(eg, val); | |
2342 | eb = ERROR_BLU(eb, val); | |
2343 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2344 | XPutPixel(xim, x, y, COLOR_INDEX(val)); | |
2345 | } | |
2346 | } | |
2347 | } | |
2348 | } | |
2349 | break; | |
2350 | default: | |
2351 | if (id->fastrend) | |
2352 | { | |
2353 | switch (bpp) | |
2354 | { | |
2355 | case 8: | |
2356 | break; | |
2357 | case 15: | |
2358 | if (id->render_type == RT_DITHER_TRUECOL) | |
2359 | { | |
2360 | if (id->ordered_dither) | |
2361 | grender_shaped_15_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2362 | else | |
2363 | grender_shaped_15_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2364 | } | |
2365 | else | |
2366 | grender_shaped_15_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2367 | break; | |
2368 | case 16: | |
2369 | if (id->render_type == RT_DITHER_TRUECOL) | |
2370 | { | |
2371 | if (id->ordered_dither) | |
2372 | grender_shaped_16_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2373 | else | |
2374 | grender_shaped_16_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2375 | } | |
2376 | else | |
2377 | grender_shaped_16_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2378 | break; | |
2379 | case 24: | |
2380 | case 32: | |
2381 | if (xim->bits_per_pixel == 24) | |
2382 | grender_shaped_24_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2383 | else | |
2384 | grender_shaped_32_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2385 | break; | |
2386 | default: | |
2387 | break; | |
2388 | } | |
2389 | } | |
2390 | else | |
2391 | { | |
2392 | switch (bpp) | |
2393 | { | |
2394 | case 8: | |
2395 | break; | |
2396 | case 15: | |
2397 | if (id->render_type == RT_DITHER_TRUECOL) | |
2398 | { | |
2399 | if (id->ordered_dither) | |
2400 | grender_shaped_15_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2401 | else | |
2402 | grender_shaped_15_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2403 | } | |
2404 | else | |
2405 | grender_shaped_15(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2406 | break; | |
2407 | case 16: | |
2408 | if (id->render_type == RT_DITHER_TRUECOL) | |
2409 | { | |
2410 | if (id->ordered_dither) | |
2411 | grender_shaped_16_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2412 | else | |
2413 | grender_shaped_16_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2414 | } | |
2415 | else | |
2416 | grender_shaped_16(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2417 | break; | |
2418 | case 24: | |
2419 | grender_shaped_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2420 | case 32: | |
2421 | grender_shaped_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2422 | break; | |
2423 | default: | |
2424 | break; | |
2425 | } | |
2426 | } | |
2427 | break; | |
2428 | } | |
2429 | } | |
2430 | ||
2431 | void | |
2432 | grender(GdkImlibImage * im, int w, int h, XImage * xim, | |
2433 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2434 | unsigned char **yarray, int bpp) | |
2435 | { | |
2436 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2437 | unsigned char *ptr2; | |
2438 | unsigned char *img; | |
2439 | int jmp; | |
2440 | ||
2441 | jmp = (xim->bytes_per_line) - w; | |
2442 | img = (unsigned char *)xim->data; | |
2443 | switch (id->render_type) | |
2444 | { | |
2445 | case RT_PLAIN_PALETTE: | |
2446 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2447 | { | |
2448 | for (y = 0; y < h; y++) | |
2449 | { | |
2450 | for (x = 0; x < w; x++) | |
2451 | { | |
2452 | ptr2 = yarray[y] + xarray[x]; | |
2453 | r = (int)*ptr2++; | |
2454 | g = (int)*ptr2++; | |
2455 | b = (int)*ptr2; | |
2456 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
2457 | *img++ = val; | |
2458 | } | |
2459 | img += jmp; | |
2460 | } | |
2461 | } | |
2462 | else | |
2463 | { | |
2464 | for (y = 0; y < h; y++) | |
2465 | { | |
2466 | for (x = 0; x < w; x++) | |
2467 | { | |
2468 | ptr2 = yarray[y] + xarray[x]; | |
2469 | r = (int)*ptr2++; | |
2470 | g = (int)*ptr2++; | |
2471 | b = (int)*ptr2; | |
2472 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
2473 | XPutPixel(xim, x, y, val); | |
2474 | } | |
2475 | } | |
2476 | } | |
2477 | break; | |
2478 | case RT_PLAIN_PALETTE_FAST: | |
2479 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2480 | { | |
2481 | for (y = 0; y < h; y++) | |
2482 | { | |
2483 | for (x = 0; x < w; x++) | |
2484 | { | |
2485 | ptr2 = yarray[y] + xarray[x]; | |
2486 | r = (int)*ptr2++; | |
2487 | g = (int)*ptr2++; | |
2488 | b = (int)*ptr2; | |
2489 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
2490 | *img++ = val; | |
2491 | } | |
2492 | img += jmp; | |
2493 | } | |
2494 | } | |
2495 | else | |
2496 | { | |
2497 | for (y = 0; y < h; y++) | |
2498 | { | |
2499 | for (x = 0; x < w; x++) | |
2500 | { | |
2501 | ptr2 = yarray[y] + xarray[x]; | |
2502 | r = (int)*ptr2++; | |
2503 | g = (int)*ptr2++; | |
2504 | b = (int)*ptr2; | |
2505 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
2506 | XPutPixel(xim, x, y, val); | |
2507 | } | |
2508 | } | |
2509 | } | |
2510 | break; | |
2511 | case RT_DITHER_PALETTE: | |
2512 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2513 | { | |
2514 | for (y = 0; y < h; y++) | |
2515 | { | |
2516 | ter = er1; | |
2517 | er1 = er2; | |
2518 | er2 = ter; | |
2519 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2520 | er2[ex] = 0; | |
2521 | ex = 3; | |
2522 | for (x = 0; x < w; x++) | |
2523 | { | |
2524 | ptr2 = yarray[y] + xarray[x]; | |
2525 | r = (int)*ptr2++; | |
2526 | g = (int)*ptr2++; | |
2527 | b = (int)*ptr2; | |
2528 | er = r + er1[ex++]; | |
2529 | eg = g + er1[ex++]; | |
2530 | eb = b + er1[ex++]; | |
2531 | if (er > 255) | |
2532 | er = 255; | |
2533 | else if (er < 0) | |
2534 | er = 0; | |
2535 | if (eg > 255) | |
2536 | eg = 255; | |
2537 | else if (eg < 0) | |
2538 | eg = 0; | |
2539 | if (eb > 255) | |
2540 | eb = 255; | |
2541 | else if (eb < 0) | |
2542 | eb = 0; | |
2543 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
2544 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2545 | *img++ = val; | |
2546 | } | |
2547 | img += jmp; | |
2548 | } | |
2549 | } | |
2550 | else | |
2551 | { | |
2552 | for (y = 0; y < h; y++) | |
2553 | { | |
2554 | ter = er1; | |
2555 | er1 = er2; | |
2556 | er2 = ter; | |
2557 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2558 | er2[ex] = 0; | |
2559 | ex = 3; | |
2560 | for (x = 0; x < w; x++) | |
2561 | { | |
2562 | ptr2 = yarray[y] + xarray[x]; | |
2563 | r = (int)*ptr2++; | |
2564 | g = (int)*ptr2++; | |
2565 | b = (int)*ptr2; | |
2566 | er = r + er1[ex++]; | |
2567 | eg = g + er1[ex++]; | |
2568 | eb = b + er1[ex++]; | |
2569 | if (er > 255) | |
2570 | er = 255; | |
2571 | else if (er < 0) | |
2572 | er = 0; | |
2573 | if (eg > 255) | |
2574 | eg = 255; | |
2575 | else if (eg < 0) | |
2576 | eg = 0; | |
2577 | if (eb > 255) | |
2578 | eb = 255; | |
2579 | else if (eb < 0) | |
2580 | eb = 0; | |
2581 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
2582 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2583 | XPutPixel(xim, x, y, val); | |
2584 | } | |
2585 | } | |
2586 | } | |
2587 | break; | |
2588 | case RT_DITHER_PALETTE_FAST: | |
2589 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
2590 | { | |
2591 | for (y = 0; y < h; y++) | |
2592 | { | |
2593 | ter = er1; | |
2594 | er1 = er2; | |
2595 | er2 = ter; | |
2596 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2597 | er2[ex] = 0; | |
2598 | ex = 3; | |
2599 | for (x = 0; x < w; x++) | |
2600 | { | |
2601 | ptr2 = yarray[y] + xarray[x]; | |
2602 | r = (int)*ptr2++; | |
2603 | g = (int)*ptr2++; | |
2604 | b = (int)*ptr2; | |
2605 | er = r + er1[ex++]; | |
2606 | eg = g + er1[ex++]; | |
2607 | eb = b + er1[ex++]; | |
2608 | if (er > 255) | |
2609 | er = 255; | |
2610 | else if (er < 0) | |
2611 | er = 0; | |
2612 | if (eg > 255) | |
2613 | eg = 255; | |
2614 | else if (eg < 0) | |
2615 | eg = 0; | |
2616 | if (eb > 255) | |
2617 | eb = 255; | |
2618 | else if (eb < 0) | |
2619 | eb = 0; | |
2620 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
2621 | er = ERROR_RED(er, val); | |
2622 | eg = ERROR_GRN(eg, val); | |
2623 | eb = ERROR_BLU(eb, val); | |
2624 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2625 | *img++ = COLOR_INDEX(val); | |
2626 | } | |
2627 | img += jmp; | |
2628 | } | |
2629 | } | |
2630 | else | |
2631 | { | |
2632 | for (y = 0; y < h; y++) | |
2633 | { | |
2634 | ter = er1; | |
2635 | er1 = er2; | |
2636 | er2 = ter; | |
2637 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2638 | er2[ex] = 0; | |
2639 | ex = 3; | |
2640 | for (x = 0; x < w; x++) | |
2641 | { | |
2642 | ptr2 = yarray[y] + xarray[x]; | |
2643 | r = (int)*ptr2++; | |
2644 | g = (int)*ptr2++; | |
2645 | b = (int)*ptr2; | |
2646 | er = r + er1[ex++]; | |
2647 | eg = g + er1[ex++]; | |
2648 | eb = b + er1[ex++]; | |
2649 | if (er > 255) | |
2650 | er = 255; | |
2651 | else if (er < 0) | |
2652 | er = 0; | |
2653 | if (eg > 255) | |
2654 | eg = 255; | |
2655 | else if (eg < 0) | |
2656 | eg = 0; | |
2657 | if (eb > 255) | |
2658 | eb = 255; | |
2659 | else if (eb < 0) | |
2660 | eb = 0; | |
2661 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
2662 | er = ERROR_RED(er, val); | |
2663 | eg = ERROR_GRN(eg, val); | |
2664 | eb = ERROR_BLU(eb, val); | |
2665 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2666 | XPutPixel(xim, x, y, COLOR_INDEX(val)); | |
2667 | } | |
2668 | } | |
2669 | } | |
2670 | break; | |
2671 | default: | |
2672 | if (id->fastrend) | |
2673 | { | |
2674 | switch (bpp) | |
2675 | { | |
2676 | case 8: | |
2677 | break; | |
2678 | case 15: | |
2679 | if (id->render_type == RT_DITHER_TRUECOL) | |
2680 | { | |
2681 | if (id->ordered_dither) | |
2682 | grender_15_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2683 | else | |
2684 | grender_15_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2685 | } | |
2686 | else | |
2687 | grender_15_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2688 | break; | |
2689 | case 16: | |
2690 | if (id->render_type == RT_DITHER_TRUECOL) | |
2691 | { | |
2692 | if (id->ordered_dither) | |
2693 | grender_16_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2694 | else | |
2695 | grender_16_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2696 | } | |
2697 | else | |
2698 | grender_16_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2699 | break; | |
2700 | case 24: | |
2701 | case 32: | |
2702 | if (xim->bits_per_pixel == 24) | |
2703 | grender_24_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2704 | else | |
2705 | grender_32_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2706 | break; | |
2707 | default: | |
2708 | break; | |
2709 | } | |
2710 | } | |
2711 | else | |
2712 | { | |
2713 | switch (bpp) | |
2714 | { | |
2715 | case 8: | |
2716 | break; | |
2717 | case 15: | |
2718 | if (id->render_type == RT_DITHER_TRUECOL) | |
2719 | { | |
2720 | if (id->ordered_dither) | |
2721 | grender_15_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2722 | else | |
2723 | grender_15_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2724 | } | |
2725 | else | |
2726 | grender_15(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2727 | break; | |
2728 | case 16: | |
2729 | if (id->render_type == RT_DITHER_TRUECOL) | |
2730 | { | |
2731 | if (id->ordered_dither) | |
2732 | grender_16_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2733 | else | |
2734 | grender_16_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2735 | } | |
2736 | else | |
2737 | grender_16(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2738 | break; | |
2739 | case 24: | |
2740 | grender_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2741 | break; | |
2742 | case 32: | |
2743 | grender_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
2744 | break; | |
2745 | default: | |
2746 | break; | |
2747 | } | |
2748 | break; | |
2749 | } | |
2750 | } | |
2751 | } | |
2752 | ||
2753 | void | |
2754 | grender_shaped_15_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
2755 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2756 | unsigned char **yarray) | |
2757 | { | |
2758 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2759 | unsigned char *ptr2; | |
2760 | unsigned short *img; | |
2761 | int jmp; | |
2762 | ||
2763 | jmp = (xim->bytes_per_line >> 1) - w; | |
2764 | img = (unsigned short *)xim->data; | |
2765 | for (y = 0; y < h; y++) | |
2766 | { | |
2767 | ter = er1; | |
2768 | er1 = er2; | |
2769 | er2 = ter; | |
2770 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2771 | er2[ex] = 0; | |
2772 | ex = 3; | |
2773 | for (x = 0; x < w; x++) | |
2774 | { | |
2775 | ptr2 = yarray[y] + xarray[x]; | |
2776 | r = (int)*ptr2++; | |
2777 | g = (int)*ptr2++; | |
2778 | b = (int)*ptr2; | |
2779 | if ((r == im->shape_color.r) && | |
2780 | (g == im->shape_color.g) && | |
2781 | (b == im->shape_color.b)) | |
2782 | { | |
2783 | XPutPixel(sxim, x, y, 0); | |
2784 | img++; | |
2785 | ex += 3; | |
2786 | } | |
2787 | else | |
2788 | { | |
2789 | r = im->rmap[r]; | |
2790 | g = im->gmap[g]; | |
2791 | b = im->bmap[b]; | |
2792 | XPutPixel(sxim, x, y, 1); | |
2793 | er = r + er1[ex++]; | |
2794 | eg = g + er1[ex++]; | |
2795 | eb = b + er1[ex++]; | |
2796 | if (er > 255) | |
2797 | er = 255; | |
2798 | if (eg > 255) | |
2799 | eg = 255; | |
2800 | if (eb > 255) | |
2801 | eb = 255; | |
2802 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
2803 | er = er & 0x07; | |
2804 | eg = eg & 0x07; | |
2805 | eb = eb & 0x07; | |
2806 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2807 | *img++ = val; | |
2808 | } | |
2809 | } | |
2810 | img += jmp; | |
2811 | } | |
2812 | } | |
2813 | ||
2814 | void | |
2815 | grender_shaped_15_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
2816 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2817 | unsigned char **yarray) | |
2818 | { | |
2819 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2820 | unsigned char *ptr2; | |
2821 | unsigned short *img; | |
2822 | int jmp; | |
2823 | ||
2824 | unsigned char dither[4][4] = | |
2825 | { | |
2826 | {0, 4, 6, 5}, | |
2827 | {6, 2, 7, 3}, | |
2828 | {2, 6, 1, 5}, | |
2829 | {7, 4, 7, 3} | |
2830 | }; | |
2831 | int dithy, dithx; | |
2832 | ||
2833 | jmp = (xim->bytes_per_line >> 1) - w; | |
2834 | img = (unsigned short *)xim->data; | |
2835 | for (y = 0; y < h; y++) | |
2836 | { | |
2837 | dithy = y & 0x3; | |
2838 | for (x = 0; x < w; x++) | |
2839 | { | |
2840 | ptr2 = yarray[y] + xarray[x]; | |
2841 | r = (int)*ptr2++; | |
2842 | g = (int)*ptr2++; | |
2843 | b = (int)*ptr2; | |
2844 | if ((r == im->shape_color.r) && | |
2845 | (g == im->shape_color.g) && | |
2846 | (b == im->shape_color.b)) | |
2847 | { | |
2848 | XPutPixel(sxim, x, y, 0); | |
2849 | img++; | |
2850 | } | |
2851 | else | |
2852 | { | |
2853 | r = im->rmap[r]; | |
2854 | g = im->gmap[g]; | |
2855 | b = im->bmap[b]; | |
2856 | XPutPixel(sxim, x, y, 1); | |
2857 | er = r & 0x07; | |
2858 | eg = g & 0x07; | |
2859 | eb = b & 0x07; | |
2860 | dithx = x & 0x3; | |
2861 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
2862 | r += 8; | |
2863 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
2864 | g += 8; | |
2865 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
2866 | b += 8; | |
2867 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
2868 | *img++ = val; | |
2869 | } | |
2870 | } | |
2871 | img += jmp; | |
2872 | } | |
2873 | } | |
2874 | ||
2875 | void | |
2876 | grender_15_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
2877 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2878 | unsigned char **yarray) | |
2879 | { | |
2880 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2881 | unsigned char *ptr2; | |
2882 | unsigned short *img; | |
2883 | int jmp; | |
2884 | ||
2885 | jmp = (xim->bytes_per_line >> 1) - w; | |
2886 | img = (unsigned short *)xim->data; | |
2887 | for (y = 0; y < h; y++) | |
2888 | { | |
2889 | ter = er1; | |
2890 | er1 = er2; | |
2891 | er2 = ter; | |
2892 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2893 | er2[ex] = 0; | |
2894 | ex = 3; | |
2895 | for (x = 0; x < w; x++) | |
2896 | { | |
2897 | ptr2 = yarray[y] + xarray[x]; | |
2898 | r = (int)*ptr2++; | |
2899 | g = (int)*ptr2++; | |
2900 | b = (int)*ptr2; | |
2901 | r = im->rmap[r]; | |
2902 | g = im->gmap[g]; | |
2903 | b = im->bmap[b]; | |
2904 | er = r + er1[ex++]; | |
2905 | eg = g + er1[ex++]; | |
2906 | eb = b + er1[ex++]; | |
2907 | if (er > 255) | |
2908 | er = 255; | |
2909 | if (eg > 255) | |
2910 | eg = 255; | |
2911 | if (eb > 255) | |
2912 | eb = 255; | |
2913 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
2914 | er = er & 0x07; | |
2915 | eg = eg & 0x07; | |
2916 | eb = eb & 0x07; | |
2917 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
2918 | *img++ = val; | |
2919 | } | |
2920 | img += jmp; | |
2921 | } | |
2922 | } | |
2923 | ||
2924 | void | |
2925 | grender_15_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
2926 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2927 | unsigned char **yarray) | |
2928 | { | |
2929 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2930 | unsigned char *ptr2; | |
2931 | ||
2932 | unsigned short *img; | |
2933 | int jmp; | |
2934 | ||
2935 | unsigned char dither[4][4] = | |
2936 | { | |
2937 | {0, 4, 6, 5}, | |
2938 | {6, 2, 7, 3}, | |
2939 | {2, 6, 1, 5}, | |
2940 | {7, 4, 7, 3} | |
2941 | }; | |
2942 | int dithy, dithx; | |
2943 | ||
2944 | jmp = (xim->bytes_per_line >> 1) - w; | |
2945 | img = (unsigned short *)xim->data; | |
2946 | for (y = 0; y < h; y++) | |
2947 | { | |
2948 | dithy = y & 0x3; | |
2949 | for (x = 0; x < w; x++) | |
2950 | { | |
2951 | ptr2 = yarray[y] + xarray[x]; | |
2952 | r = (int)*ptr2++; | |
2953 | g = (int)*ptr2++; | |
2954 | b = (int)*ptr2; | |
2955 | r = im->rmap[r]; | |
2956 | g = im->gmap[g]; | |
2957 | b = im->bmap[b]; | |
2958 | er = r & 0x07; | |
2959 | eg = g & 0x07; | |
2960 | eb = b & 0x07; | |
2961 | dithx = x & 0x3; | |
2962 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
2963 | r += 8; | |
2964 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
2965 | g += 8; | |
2966 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
2967 | b += 8; | |
2968 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
2969 | *img++ = val; | |
2970 | } | |
2971 | img += jmp; | |
2972 | } | |
2973 | } | |
2974 | ||
2975 | void | |
2976 | grender_shaped_16_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
2977 | XImage * sxim, int *er1, int *er2, int *xarray, | |
2978 | unsigned char **yarray) | |
2979 | { | |
2980 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
2981 | unsigned char *ptr2; | |
2982 | unsigned short *img; | |
2983 | int jmp; | |
2984 | ||
2985 | jmp = (xim->bytes_per_line >> 1) - w; | |
2986 | img = (unsigned short *)xim->data; | |
2987 | for (y = 0; y < h; y++) | |
2988 | { | |
2989 | ter = er1; | |
2990 | er1 = er2; | |
2991 | er2 = ter; | |
2992 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
2993 | er2[ex] = 0; | |
2994 | ex = 3; | |
2995 | for (x = 0; x < w; x++) | |
2996 | { | |
2997 | ptr2 = yarray[y] + xarray[x]; | |
2998 | r = (int)*ptr2++; | |
2999 | g = (int)*ptr2++; | |
3000 | b = (int)*ptr2; | |
3001 | if ((r == im->shape_color.r) && | |
3002 | (g == im->shape_color.g) && | |
3003 | (b == im->shape_color.b)) | |
3004 | { | |
3005 | XPutPixel(sxim, x, y, 0); | |
3006 | img++; | |
3007 | ex += 3; | |
3008 | } | |
3009 | else | |
3010 | { | |
3011 | XPutPixel(sxim, x, y, 1); | |
3012 | r = im->rmap[r]; | |
3013 | g = im->gmap[g]; | |
3014 | b = im->bmap[b]; | |
3015 | er = r + er1[ex++]; | |
3016 | eg = g + er1[ex++]; | |
3017 | eb = b + er1[ex++]; | |
3018 | if (er > 255) | |
3019 | er = 255; | |
3020 | if (eg > 255) | |
3021 | eg = 255; | |
3022 | if (eb > 255) | |
3023 | eb = 255; | |
3024 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
3025 | er = er & 0x07; | |
3026 | eg = eg & 0x03; | |
3027 | eb = eb & 0x07; | |
3028 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
3029 | *img++ = val; | |
3030 | } | |
3031 | } | |
3032 | img += jmp; | |
3033 | } | |
3034 | } | |
3035 | ||
3036 | void | |
3037 | grender_shaped_16_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
3038 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3039 | unsigned char **yarray) | |
3040 | { | |
3041 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3042 | unsigned char *ptr2; | |
3043 | unsigned short *img; | |
3044 | int jmp; | |
3045 | ||
3046 | unsigned char dither[4][4] = | |
3047 | { | |
3048 | {0, 4, 6, 5}, | |
3049 | {6, 2, 7, 3}, | |
3050 | {2, 6, 1, 5}, | |
3051 | {7, 4, 7, 3} | |
3052 | }; | |
3053 | int dithy, dithx; | |
3054 | ||
3055 | jmp = (xim->bytes_per_line >> 1) - w; | |
3056 | img = (unsigned short *)xim->data; | |
3057 | for (y = 0; y < h; y++) | |
3058 | { | |
3059 | dithy = y & 0x3; | |
3060 | for (x = 0; x < w; x++) | |
3061 | { | |
3062 | ptr2 = yarray[y] + xarray[x]; | |
3063 | r = (int)*ptr2++; | |
3064 | g = (int)*ptr2++; | |
3065 | b = (int)*ptr2; | |
3066 | if ((r == im->shape_color.r) && | |
3067 | (g == im->shape_color.g) && | |
3068 | (b == im->shape_color.b)) | |
3069 | { | |
3070 | XPutPixel(sxim, x, y, 0); | |
3071 | img++; | |
3072 | } | |
3073 | else | |
3074 | { | |
3075 | r = im->rmap[r]; | |
3076 | g = im->gmap[g]; | |
3077 | b = im->bmap[b]; | |
3078 | XPutPixel(sxim, x, y, 1); | |
3079 | er = r & 0x07; | |
3080 | eg = g & 0x03; | |
3081 | eb = b & 0x07; | |
3082 | dithx = x & 0x3; | |
3083 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
3084 | r += 8; | |
3085 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
3086 | g += 4; | |
3087 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
3088 | b += 8; | |
3089 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
3090 | *img++ = val; | |
3091 | } | |
3092 | } | |
3093 | img += jmp; | |
3094 | } | |
3095 | } | |
3096 | ||
3097 | void | |
3098 | grender_16_fast_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3099 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3100 | unsigned char **yarray) | |
3101 | { | |
3102 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3103 | unsigned char *ptr2; | |
3104 | ||
3105 | unsigned short *img; | |
3106 | int jmp; | |
3107 | ||
3108 | jmp = (xim->bytes_per_line >> 1) - w; | |
3109 | img = (unsigned short *)xim->data; | |
3110 | for (y = 0; y < h; y++) | |
3111 | { | |
3112 | ter = er1; | |
3113 | er1 = er2; | |
3114 | er2 = ter; | |
3115 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
3116 | er2[ex] = 0; | |
3117 | ex = 3; | |
3118 | for (x = 0; x < w; x++) | |
3119 | { | |
3120 | ptr2 = yarray[y] + xarray[x]; | |
3121 | r = (int)*ptr2++; | |
3122 | g = (int)*ptr2++; | |
3123 | b = (int)*ptr2; | |
3124 | r = im->rmap[r]; | |
3125 | g = im->gmap[g]; | |
3126 | b = im->bmap[b]; | |
3127 | er = r + er1[ex++]; | |
3128 | eg = g + er1[ex++]; | |
3129 | eb = b + er1[ex++]; | |
3130 | if (er > 255) | |
3131 | er = 255; | |
3132 | if (eg > 255) | |
3133 | eg = 255; | |
3134 | if (eb > 255) | |
3135 | eb = 255; | |
3136 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
3137 | er = er & 0x07; | |
3138 | eg = eg & 0x03; | |
3139 | eb = eb & 0x07; | |
3140 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
3141 | *img++ = val; | |
3142 | } | |
3143 | img += jmp; | |
3144 | } | |
3145 | } | |
3146 | ||
3147 | void | |
3148 | grender_16_fast_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
3149 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3150 | unsigned char **yarray) | |
3151 | { | |
3152 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3153 | unsigned char *ptr2; | |
3154 | ||
3155 | unsigned short *img; | |
3156 | int jmp; | |
3157 | ||
3158 | unsigned char dither[4][4] = | |
3159 | { | |
3160 | {0, 4, 6, 5}, | |
3161 | {6, 2, 7, 3}, | |
3162 | {2, 6, 1, 5}, | |
3163 | {7, 4, 7, 3} | |
3164 | }; | |
3165 | int dithy, dithx; | |
3166 | ||
3167 | jmp = (xim->bytes_per_line >> 1) - w; | |
3168 | img = (unsigned short *)xim->data; | |
3169 | for (y = 0; y < h; y++) | |
3170 | { | |
3171 | dithy = y & 0x3; | |
3172 | for (x = 0; x < w; x++) | |
3173 | { | |
3174 | ptr2 = yarray[y] + xarray[x]; | |
3175 | r = (int)*ptr2++; | |
3176 | g = (int)*ptr2++; | |
3177 | b = (int)*ptr2; | |
3178 | r = im->rmap[r]; | |
3179 | g = im->gmap[g]; | |
3180 | b = im->bmap[b]; | |
3181 | er = r & 0x07; | |
3182 | eg = g & 0x03; | |
3183 | eb = b & 0x07; | |
3184 | dithx = x & 0x3; | |
3185 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
3186 | r += 8; | |
3187 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
3188 | g += 4; | |
3189 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
3190 | b += 8; | |
3191 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
3192 | *img++ = val; | |
3193 | } | |
3194 | img += jmp; | |
3195 | } | |
3196 | } | |
3197 | ||
3198 | void | |
3199 | grender_shaped_15_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
3200 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3201 | unsigned char **yarray) | |
3202 | { | |
3203 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3204 | unsigned char *ptr2; | |
3205 | ||
3206 | unsigned char dither[4][4] = | |
3207 | { | |
3208 | {0, 4, 6, 5}, | |
3209 | {6, 2, 7, 3}, | |
3210 | {2, 6, 1, 5}, | |
3211 | {7, 4, 7, 3} | |
3212 | }; | |
3213 | int dithy, dithx; | |
3214 | ||
3215 | for (y = 0; y < h; y++) | |
3216 | { | |
3217 | dithy = y & 0x3; | |
3218 | for (x = 0; x < w; x++) | |
3219 | { | |
3220 | ptr2 = yarray[y] + xarray[x]; | |
3221 | r = (int)*ptr2++; | |
3222 | g = (int)*ptr2++; | |
3223 | b = (int)*ptr2; | |
3224 | if ((r == im->shape_color.r) && | |
3225 | (g == im->shape_color.g) && | |
3226 | (b == im->shape_color.b)) | |
3227 | { | |
3228 | XPutPixel(sxim, x, y, 0); | |
3229 | } | |
3230 | else | |
3231 | { | |
3232 | r = im->rmap[r]; | |
3233 | g = im->gmap[g]; | |
3234 | b = im->bmap[b]; | |
3235 | XPutPixel(sxim, x, y, 1); | |
3236 | er = r & 0x07; | |
3237 | eg = g & 0x07; | |
3238 | eb = b & 0x07; | |
3239 | dithx = x & 0x3; | |
3240 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
3241 | r += 8; | |
3242 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
3243 | g += 8; | |
3244 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
3245 | b += 8; | |
3246 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
3247 | XPutPixel(xim, x, y, val); | |
3248 | } | |
3249 | } | |
3250 | } | |
3251 | } | |
3252 | ||
3253 | void | |
3254 | grender_15_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
3255 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3256 | unsigned char **yarray) | |
3257 | { | |
3258 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3259 | unsigned char *ptr2; | |
3260 | ||
3261 | unsigned char dither[4][4] = | |
3262 | { | |
3263 | {0, 4, 6, 5}, | |
3264 | {6, 2, 7, 3}, | |
3265 | {2, 6, 1, 5}, | |
3266 | {7, 4, 7, 3} | |
3267 | }; | |
3268 | int dithy, dithx; | |
3269 | ||
3270 | for (y = 0; y < h; y++) | |
3271 | { | |
3272 | dithy = y & 0x3; | |
3273 | for (x = 0; x < w; x++) | |
3274 | { | |
3275 | ptr2 = yarray[y] + xarray[x]; | |
3276 | r = (int)*ptr2++; | |
3277 | g = (int)*ptr2++; | |
3278 | b = (int)*ptr2; | |
3279 | r = im->rmap[r]; | |
3280 | g = im->gmap[g]; | |
3281 | b = im->bmap[b]; | |
3282 | er = r & 0x07; | |
3283 | eg = g & 0x07; | |
3284 | eb = b & 0x07; | |
3285 | dithx = x & 0x3; | |
3286 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
3287 | r += 8; | |
3288 | if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) | |
3289 | g += 8; | |
3290 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
3291 | b += 8; | |
3292 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
3293 | XPutPixel(xim, x, y, val); | |
3294 | } | |
3295 | } | |
3296 | } | |
3297 | ||
3298 | void | |
3299 | grender_shaped_16_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
3300 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3301 | unsigned char **yarray) | |
3302 | { | |
3303 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3304 | unsigned char *ptr2; | |
3305 | ||
3306 | unsigned char dither[4][4] = | |
3307 | { | |
3308 | {0, 4, 6, 5}, | |
3309 | {6, 2, 7, 3}, | |
3310 | {2, 6, 1, 5}, | |
3311 | {7, 4, 7, 3} | |
3312 | }; | |
3313 | int dithy, dithx; | |
3314 | ||
3315 | for (y = 0; y < h; y++) | |
3316 | { | |
3317 | dithy = y & 0x3; | |
3318 | for (x = 0; x < w; x++) | |
3319 | { | |
3320 | ptr2 = yarray[y] + xarray[x]; | |
3321 | r = (int)*ptr2++; | |
3322 | g = (int)*ptr2++; | |
3323 | b = (int)*ptr2; | |
3324 | if ((r == im->shape_color.r) && | |
3325 | (g == im->shape_color.g) && | |
3326 | (b == im->shape_color.b)) | |
3327 | { | |
3328 | XPutPixel(sxim, x, y, 0); | |
3329 | } | |
3330 | else | |
3331 | { | |
3332 | r = im->rmap[r]; | |
3333 | g = im->gmap[g]; | |
3334 | b = im->bmap[b]; | |
3335 | XPutPixel(sxim, x, y, 1); | |
3336 | er = r & 0x07; | |
3337 | eg = g & 0x03; | |
3338 | eb = b & 0x07; | |
3339 | dithx = x & 0x3; | |
3340 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
3341 | r += 8; | |
3342 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
3343 | g += 4; | |
3344 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
3345 | b += 8; | |
3346 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
3347 | XPutPixel(xim, x, y, val); | |
3348 | } | |
3349 | } | |
3350 | } | |
3351 | } | |
3352 | ||
3353 | void | |
3354 | grender_16_dither_mod_ordered(GdkImlibImage * im, int w, int h, XImage * xim, | |
3355 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3356 | unsigned char **yarray) | |
3357 | { | |
3358 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3359 | unsigned char *ptr2; | |
3360 | ||
3361 | unsigned char dither[4][4] = | |
3362 | { | |
3363 | {0, 4, 6, 5}, | |
3364 | {6, 2, 7, 3}, | |
3365 | {2, 6, 1, 5}, | |
3366 | {7, 4, 7, 3} | |
3367 | }; | |
3368 | int dithy, dithx; | |
3369 | ||
3370 | for (y = 0; y < h; y++) | |
3371 | { | |
3372 | dithy = y & 0x3; | |
3373 | for (x = 0; x < w; x++) | |
3374 | { | |
3375 | ptr2 = yarray[y] + xarray[x]; | |
3376 | r = (int)*ptr2++; | |
3377 | g = (int)*ptr2++; | |
3378 | b = (int)*ptr2; | |
3379 | r = im->rmap[r]; | |
3380 | g = im->gmap[g]; | |
3381 | b = im->bmap[b]; | |
3382 | er = r & 0x07; | |
3383 | eg = g & 0x03; | |
3384 | eb = b & 0x07; | |
3385 | dithx = x & 0x3; | |
3386 | if ((dither[dithy][dithx] < er) && (r < (256 - 8))) | |
3387 | r += 8; | |
3388 | if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) | |
3389 | g += 4; | |
3390 | if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) | |
3391 | b += 8; | |
3392 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
3393 | XPutPixel(xim, x, y, val); | |
3394 | } | |
3395 | } | |
3396 | } | |
3397 | ||
3398 | void | |
3399 | grender_shaped_15_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3400 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3401 | unsigned char **yarray) | |
3402 | { | |
3403 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3404 | unsigned char *ptr2; | |
3405 | ||
3406 | for (y = 0; y < h; y++) | |
3407 | { | |
3408 | ter = er1; | |
3409 | er1 = er2; | |
3410 | er2 = ter; | |
3411 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
3412 | er2[ex] = 0; | |
3413 | ex = 3; | |
3414 | for (x = 0; x < w; x++) | |
3415 | { | |
3416 | ptr2 = yarray[y] + xarray[x]; | |
3417 | r = (int)*ptr2++; | |
3418 | g = (int)*ptr2++; | |
3419 | b = (int)*ptr2; | |
3420 | if ((r == im->shape_color.r) && | |
3421 | (g == im->shape_color.g) && | |
3422 | (b == im->shape_color.b)) | |
3423 | { | |
3424 | XPutPixel(sxim, x, y, 0); | |
3425 | ex += 3; | |
3426 | } | |
3427 | else | |
3428 | { | |
3429 | XPutPixel(sxim, x, y, 1); | |
3430 | r = im->rmap[r]; | |
3431 | g = im->gmap[g]; | |
3432 | b = im->bmap[b]; | |
3433 | er = r + er1[ex++]; | |
3434 | eg = g + er1[ex++]; | |
3435 | eb = b + er1[ex++]; | |
3436 | if (er > 255) | |
3437 | er = 255; | |
3438 | if (eg > 255) | |
3439 | eg = 255; | |
3440 | if (eb > 255) | |
3441 | eb = 255; | |
3442 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
3443 | er = er & 0x07; | |
3444 | eg = eg & 0x07; | |
3445 | eb = eb & 0x07; | |
3446 | if (er > 255) | |
3447 | er = 255; | |
3448 | else if (er < 0) | |
3449 | er = 0; | |
3450 | if (eg > 255) | |
3451 | eg = 255; | |
3452 | else if (eg < 0) | |
3453 | eg = 0; | |
3454 | if (eb > 255) | |
3455 | eb = 255; | |
3456 | else if (eb < 0) | |
3457 | eb = 0; | |
3458 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
3459 | er = r & 0x07; | |
3460 | eg = g & 0x07; | |
3461 | eb = b & 0x07; | |
3462 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
3463 | XPutPixel(xim, x, y, val); | |
3464 | } | |
3465 | } | |
3466 | } | |
3467 | } | |
3468 | ||
3469 | void | |
3470 | grender_15_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3471 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3472 | unsigned char **yarray) | |
3473 | { | |
3474 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3475 | unsigned char *ptr2; | |
3476 | ||
3477 | for (y = 0; y < h; y++) | |
3478 | { | |
3479 | ter = er1; | |
3480 | er1 = er2; | |
3481 | er2 = ter; | |
3482 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
3483 | er2[ex] = 0; | |
3484 | ex = 3; | |
3485 | for (x = 0; x < w; x++) | |
3486 | { | |
3487 | ptr2 = yarray[y] + xarray[x]; | |
3488 | r = (int)*ptr2++; | |
3489 | g = (int)*ptr2++; | |
3490 | b = (int)*ptr2; | |
3491 | r = im->rmap[r]; | |
3492 | g = im->gmap[g]; | |
3493 | b = im->bmap[b]; | |
3494 | er = r + er1[ex++]; | |
3495 | eg = g + er1[ex++]; | |
3496 | eb = b + er1[ex++]; | |
3497 | if (er > 255) | |
3498 | er = 255; | |
3499 | if (eg > 255) | |
3500 | eg = 255; | |
3501 | if (eb > 255) | |
3502 | eb = 255; | |
3503 | val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); | |
3504 | er = er & 0x07; | |
3505 | eg = eg & 0x07; | |
3506 | eb = eb & 0x07; | |
3507 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
3508 | XPutPixel(xim, x, y, val); | |
3509 | } | |
3510 | } | |
3511 | } | |
3512 | ||
3513 | void | |
3514 | grender_shaped_16_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3515 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3516 | unsigned char **yarray) | |
3517 | { | |
3518 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3519 | unsigned char *ptr2; | |
3520 | ||
3521 | for (y = 0; y < h; y++) | |
3522 | { | |
3523 | ter = er1; | |
3524 | er1 = er2; | |
3525 | er2 = ter; | |
3526 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
3527 | er2[ex] = 0; | |
3528 | ex = 3; | |
3529 | for (x = 0; x < w; x++) | |
3530 | { | |
3531 | ptr2 = yarray[y] + xarray[x]; | |
3532 | r = (int)*ptr2++; | |
3533 | g = (int)*ptr2++; | |
3534 | b = (int)*ptr2; | |
3535 | if ((r == im->shape_color.r) && | |
3536 | (g == im->shape_color.g) && | |
3537 | (b == im->shape_color.b)) | |
3538 | { | |
3539 | XPutPixel(sxim, x, y, 0); | |
3540 | ex += 3; | |
3541 | } | |
3542 | else | |
3543 | { | |
3544 | XPutPixel(sxim, x, y, 1); | |
3545 | r = im->rmap[r]; | |
3546 | g = im->gmap[g]; | |
3547 | b = im->bmap[b]; | |
3548 | er = r + er1[ex++]; | |
3549 | eg = g + er1[ex++]; | |
3550 | eb = b + er1[ex++]; | |
3551 | if (er > 255) | |
3552 | er = 255; | |
3553 | if (eg > 255) | |
3554 | eg = 255; | |
3555 | if (eb > 255) | |
3556 | eb = 255; | |
3557 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
3558 | er = er & 0x07; | |
3559 | eg = eg & 0x03; | |
3560 | eb = eb & 0x07; | |
3561 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
3562 | XPutPixel(xim, x, y, val); | |
3563 | } | |
3564 | } | |
3565 | } | |
3566 | } | |
3567 | ||
3568 | void | |
3569 | grender_16_dither_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3570 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3571 | unsigned char **yarray) | |
3572 | { | |
3573 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
3574 | unsigned char *ptr2; | |
3575 | ||
3576 | for (y = 0; y < h; y++) | |
3577 | { | |
3578 | ter = er1; | |
3579 | er1 = er2; | |
3580 | er2 = ter; | |
3581 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
3582 | er2[ex] = 0; | |
3583 | ex = 3; | |
3584 | for (x = 0; x < w; x++) | |
3585 | { | |
3586 | ptr2 = yarray[y] + xarray[x]; | |
3587 | r = (int)*ptr2++; | |
3588 | g = (int)*ptr2++; | |
3589 | b = (int)*ptr2; | |
3590 | r = im->rmap[r]; | |
3591 | g = im->gmap[g]; | |
3592 | b = im->bmap[b]; | |
3593 | er = r + er1[ex++]; | |
3594 | eg = g + er1[ex++]; | |
3595 | eb = b + er1[ex++]; | |
3596 | if (er > 255) | |
3597 | er = 255; | |
3598 | if (eg > 255) | |
3599 | eg = 255; | |
3600 | if (eb > 255) | |
3601 | eb = 255; | |
3602 | val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); | |
3603 | er = er & 0x07; | |
3604 | eg = eg & 0x03; | |
3605 | eb = eb & 0x07; | |
3606 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
3607 | XPutPixel(xim, x, y, val); | |
3608 | } | |
3609 | } | |
3610 | } | |
3611 | ||
3612 | void | |
3613 | grender_shaped_15_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3614 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3615 | unsigned char **yarray) | |
3616 | { | |
3617 | int x, y, val, r, g, b; | |
3618 | unsigned char *ptr2; | |
3619 | unsigned short *img; | |
3620 | int jmp; | |
3621 | ||
3622 | jmp = (xim->bytes_per_line >> 1) - w; | |
3623 | img = (unsigned short *)xim->data; | |
3624 | for (y = 0; y < h; y++) | |
3625 | { | |
3626 | for (x = 0; x < w; x++) | |
3627 | { | |
3628 | ptr2 = yarray[y] + xarray[x]; | |
3629 | r = (int)*ptr2++; | |
3630 | g = (int)*ptr2++; | |
3631 | b = (int)*ptr2; | |
3632 | if ((r == im->shape_color.r) && | |
3633 | (g == im->shape_color.g) && | |
3634 | (b == im->shape_color.b)) | |
3635 | { | |
3636 | XPutPixel(sxim, x, y, 0); | |
3637 | img++; | |
3638 | } | |
3639 | else | |
3640 | { | |
3641 | XPutPixel(sxim, x, y, 1); | |
3642 | r = im->rmap[r]; | |
3643 | g = im->gmap[g]; | |
3644 | b = im->bmap[b]; | |
3645 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
3646 | *img++ = val; | |
3647 | } | |
3648 | } | |
3649 | img += jmp; | |
3650 | } | |
3651 | } | |
3652 | ||
3653 | void | |
3654 | grender_15_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3655 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3656 | unsigned char **yarray) | |
3657 | { | |
3658 | int x, y, val, r, g, b; | |
3659 | unsigned char *ptr2; | |
3660 | unsigned short *img; | |
3661 | int jmp; | |
3662 | ||
3663 | jmp = (xim->bytes_per_line >> 1) - w; | |
3664 | img = (unsigned short *)xim->data; | |
3665 | for (y = 0; y < h; y++) | |
3666 | { | |
3667 | for (x = 0; x < w; x++) | |
3668 | { | |
3669 | ptr2 = yarray[y] + xarray[x]; | |
3670 | r = (int)*ptr2++; | |
3671 | g = (int)*ptr2++; | |
3672 | b = (int)*ptr2; | |
3673 | r = im->rmap[r]; | |
3674 | g = im->gmap[g]; | |
3675 | b = im->bmap[b]; | |
3676 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
3677 | *img++ = val; | |
3678 | } | |
3679 | img += jmp; | |
3680 | } | |
3681 | } | |
3682 | ||
3683 | void | |
3684 | grender_shaped_16_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3685 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3686 | unsigned char **yarray) | |
3687 | { | |
3688 | int x, y, val, r, g, b; | |
3689 | unsigned char *ptr2; | |
3690 | unsigned short *img; | |
3691 | int jmp; | |
3692 | ||
3693 | jmp = (xim->bytes_per_line >> 1) - w; | |
3694 | img = (unsigned short *)xim->data; | |
3695 | for (y = 0; y < h; y++) | |
3696 | { | |
3697 | for (x = 0; x < w; x++) | |
3698 | { | |
3699 | ptr2 = yarray[y] + xarray[x]; | |
3700 | r = (int)*ptr2++; | |
3701 | g = (int)*ptr2++; | |
3702 | b = (int)*ptr2; | |
3703 | if ((r == im->shape_color.r) && | |
3704 | (g == im->shape_color.g) && | |
3705 | (b == im->shape_color.b)) | |
3706 | { | |
3707 | XPutPixel(sxim, x, y, 0); | |
3708 | img++; | |
3709 | } | |
3710 | else | |
3711 | { | |
3712 | XPutPixel(sxim, x, y, 1); | |
3713 | r = im->rmap[r]; | |
3714 | g = im->gmap[g]; | |
3715 | b = im->bmap[b]; | |
3716 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
3717 | *img++ = val; | |
3718 | } | |
3719 | } | |
3720 | img += jmp; | |
3721 | } | |
3722 | } | |
3723 | ||
3724 | void | |
3725 | grender_16_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3726 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3727 | unsigned char **yarray) | |
3728 | { | |
3729 | int x, y, val, r, g, b; | |
3730 | unsigned char *ptr2; | |
3731 | ||
3732 | unsigned short *img; | |
3733 | int jmp; | |
3734 | ||
3735 | jmp = (xim->bytes_per_line >> 1) - w; | |
3736 | img = (unsigned short *)xim->data; | |
3737 | for (y = 0; y < h; y++) | |
3738 | { | |
3739 | for (x = 0; x < w; x++) | |
3740 | { | |
3741 | ptr2 = yarray[y] + xarray[x]; | |
3742 | r = (int)*ptr2++; | |
3743 | g = (int)*ptr2++; | |
3744 | b = (int)*ptr2; | |
3745 | r = im->rmap[r]; | |
3746 | g = im->gmap[g]; | |
3747 | b = im->bmap[b]; | |
3748 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
3749 | *img++ = val; | |
3750 | } | |
3751 | img += jmp; | |
3752 | } | |
3753 | } | |
3754 | ||
3755 | void | |
3756 | grender_shaped_24_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3757 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3758 | unsigned char **yarray) | |
3759 | { | |
3760 | int x, y, r, g, b; | |
3761 | unsigned char *ptr2; | |
3762 | unsigned char *img; | |
3763 | int jmp; | |
3764 | ||
3765 | jmp = (xim->bytes_per_line) - w; | |
3766 | img = (unsigned char *)xim->data; | |
3767 | if (id->byte_order == BYTE_ORD_24_RGB) | |
3768 | { | |
3769 | for (y = 0; y < h; y++) | |
3770 | { | |
3771 | for (x = 0; x < w; x++) | |
3772 | { | |
3773 | ptr2 = yarray[y] + xarray[x]; | |
3774 | r = (int)*ptr2++; | |
3775 | g = (int)*ptr2++; | |
3776 | b = (int)*ptr2; | |
3777 | if ((r == im->shape_color.r) && | |
3778 | (g == im->shape_color.g) && | |
3779 | (b == im->shape_color.b)) | |
3780 | { | |
3781 | XPutPixel(sxim, x, y, 0); | |
3782 | img += 3; | |
3783 | } | |
3784 | else | |
3785 | { | |
3786 | XPutPixel(sxim, x, y, 1); | |
3787 | r = im->rmap[r]; | |
3788 | g = im->gmap[g]; | |
3789 | b = im->bmap[b]; | |
3790 | *img++ = r; | |
3791 | *img++ = g; | |
3792 | *img++ = b; | |
3793 | } | |
3794 | } | |
3795 | img += jmp; | |
3796 | } | |
3797 | } | |
3798 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
3799 | { | |
3800 | for (y = 0; y < h; y++) | |
3801 | { | |
3802 | for (x = 0; x < w; x++) | |
3803 | { | |
3804 | ptr2 = yarray[y] + xarray[x]; | |
3805 | r = (int)*ptr2++; | |
3806 | g = (int)*ptr2++; | |
3807 | b = (int)*ptr2; | |
3808 | if ((r == im->shape_color.r) && | |
3809 | (g == im->shape_color.g) && | |
3810 | (b == im->shape_color.b)) | |
3811 | { | |
3812 | XPutPixel(sxim, x, y, 0); | |
3813 | img += 3; | |
3814 | } | |
3815 | else | |
3816 | { | |
3817 | XPutPixel(sxim, x, y, 1); | |
3818 | r = im->rmap[r]; | |
3819 | g = im->gmap[g]; | |
3820 | b = im->bmap[b]; | |
3821 | *img++ = r; | |
3822 | *img++ = b; | |
3823 | *img++ = g; | |
3824 | } | |
3825 | } | |
3826 | img += jmp; | |
3827 | } | |
3828 | } | |
3829 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
3830 | { | |
3831 | for (y = 0; y < h; y++) | |
3832 | { | |
3833 | for (x = 0; x < w; x++) | |
3834 | { | |
3835 | ptr2 = yarray[y] + xarray[x]; | |
3836 | r = (int)*ptr2++; | |
3837 | g = (int)*ptr2++; | |
3838 | b = (int)*ptr2; | |
3839 | if ((r == im->shape_color.r) && | |
3840 | (g == im->shape_color.g) && | |
3841 | (b == im->shape_color.b)) | |
3842 | { | |
3843 | XPutPixel(sxim, x, y, 0); | |
3844 | img += 3; | |
3845 | } | |
3846 | else | |
3847 | { | |
3848 | XPutPixel(sxim, x, y, 1); | |
3849 | r = im->rmap[r]; | |
3850 | g = im->gmap[g]; | |
3851 | b = im->bmap[b]; | |
3852 | *img++ = b; | |
3853 | *img++ = r; | |
3854 | *img++ = g; | |
3855 | } | |
3856 | } | |
3857 | img += jmp; | |
3858 | } | |
3859 | } | |
3860 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
3861 | { | |
3862 | for (y = 0; y < h; y++) | |
3863 | { | |
3864 | for (x = 0; x < w; x++) | |
3865 | { | |
3866 | ptr2 = yarray[y] + xarray[x]; | |
3867 | r = (int)*ptr2++; | |
3868 | g = (int)*ptr2++; | |
3869 | b = (int)*ptr2; | |
3870 | if ((r == im->shape_color.r) && | |
3871 | (g == im->shape_color.g) && | |
3872 | (b == im->shape_color.b)) | |
3873 | { | |
3874 | XPutPixel(sxim, x, y, 0); | |
3875 | img += 3; | |
3876 | } | |
3877 | else | |
3878 | { | |
3879 | XPutPixel(sxim, x, y, 1); | |
3880 | r = im->rmap[r]; | |
3881 | g = im->gmap[g]; | |
3882 | b = im->bmap[b]; | |
3883 | *img++ = b; | |
3884 | *img++ = g; | |
3885 | *img++ = r; | |
3886 | } | |
3887 | } | |
3888 | img += jmp; | |
3889 | } | |
3890 | } | |
3891 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
3892 | { | |
3893 | for (y = 0; y < h; y++) | |
3894 | { | |
3895 | for (x = 0; x < w; x++) | |
3896 | { | |
3897 | ptr2 = yarray[y] + xarray[x]; | |
3898 | r = (int)*ptr2++; | |
3899 | g = (int)*ptr2++; | |
3900 | b = (int)*ptr2; | |
3901 | if ((r == im->shape_color.r) && | |
3902 | (g == im->shape_color.g) && | |
3903 | (b == im->shape_color.b)) | |
3904 | { | |
3905 | XPutPixel(sxim, x, y, 0); | |
3906 | img += 3; | |
3907 | } | |
3908 | else | |
3909 | { | |
3910 | XPutPixel(sxim, x, y, 1); | |
3911 | *img++ = g; | |
3912 | *img++ = r; | |
3913 | *img++ = b; | |
3914 | r = im->rmap[r]; | |
3915 | g = im->gmap[g]; | |
3916 | b = im->bmap[b]; | |
3917 | } | |
3918 | } | |
3919 | img += jmp; | |
3920 | } | |
3921 | } | |
3922 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
3923 | { | |
3924 | for (y = 0; y < h; y++) | |
3925 | { | |
3926 | for (x = 0; x < w; x++) | |
3927 | { | |
3928 | ptr2 = yarray[y] + xarray[x]; | |
3929 | r = (int)*ptr2++; | |
3930 | g = (int)*ptr2++; | |
3931 | b = (int)*ptr2; | |
3932 | if ((r == im->shape_color.r) && | |
3933 | (g == im->shape_color.g) && | |
3934 | (b == im->shape_color.b)) | |
3935 | { | |
3936 | XPutPixel(sxim, x, y, 0); | |
3937 | img += 3; | |
3938 | } | |
3939 | else | |
3940 | { | |
3941 | XPutPixel(sxim, x, y, 1); | |
3942 | *img++ = g; | |
3943 | *img++ = b; | |
3944 | *img++ = r; | |
3945 | r = im->rmap[r]; | |
3946 | g = im->gmap[g]; | |
3947 | b = im->bmap[b]; | |
3948 | } | |
3949 | } | |
3950 | img += jmp; | |
3951 | } | |
3952 | } | |
3953 | } | |
3954 | ||
3955 | void | |
3956 | grender_24_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
3957 | XImage * sxim, int *er1, int *er2, int *xarray, | |
3958 | unsigned char **yarray) | |
3959 | { | |
3960 | int x, y, r, g, b; | |
3961 | unsigned char *ptr2; | |
3962 | unsigned char *img; | |
3963 | int jmp; | |
3964 | ||
3965 | jmp = (xim->bytes_per_line) - w; | |
3966 | img = (unsigned char *)xim->data; | |
3967 | if (id->byte_order == BYTE_ORD_24_RGB) | |
3968 | { | |
3969 | for (y = 0; y < h; y++) | |
3970 | { | |
3971 | for (x = 0; x < w; x++) | |
3972 | { | |
3973 | ptr2 = yarray[y] + xarray[x]; | |
3974 | r = (int)*ptr2++; | |
3975 | g = (int)*ptr2++; | |
3976 | b = (int)*ptr2; | |
3977 | r = im->rmap[r]; | |
3978 | g = im->gmap[g]; | |
3979 | b = im->bmap[b]; | |
3980 | *img++ = r; | |
3981 | *img++ = g; | |
3982 | *img++ = b; | |
3983 | } | |
3984 | img += jmp; | |
3985 | } | |
3986 | } | |
3987 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
3988 | { | |
3989 | for (y = 0; y < h; y++) | |
3990 | { | |
3991 | for (x = 0; x < w; x++) | |
3992 | { | |
3993 | ptr2 = yarray[y] + xarray[x]; | |
3994 | r = (int)*ptr2++; | |
3995 | g = (int)*ptr2++; | |
3996 | b = (int)*ptr2; | |
3997 | r = im->rmap[r]; | |
3998 | g = im->gmap[g]; | |
3999 | b = im->bmap[b]; | |
4000 | *img++ = r; | |
4001 | *img++ = b; | |
4002 | *img++ = g; | |
4003 | } | |
4004 | img += jmp; | |
4005 | } | |
4006 | } | |
4007 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
4008 | { | |
4009 | for (y = 0; y < h; y++) | |
4010 | { | |
4011 | for (x = 0; x < w; x++) | |
4012 | { | |
4013 | ptr2 = yarray[y] + xarray[x]; | |
4014 | r = (int)*ptr2++; | |
4015 | g = (int)*ptr2++; | |
4016 | b = (int)*ptr2; | |
4017 | r = im->rmap[r]; | |
4018 | g = im->gmap[g]; | |
4019 | b = im->bmap[b]; | |
4020 | *img++ = b; | |
4021 | *img++ = r; | |
4022 | *img++ = g; | |
4023 | } | |
4024 | img += jmp; | |
4025 | } | |
4026 | } | |
4027 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
4028 | { | |
4029 | for (y = 0; y < h; y++) | |
4030 | { | |
4031 | for (x = 0; x < w; x++) | |
4032 | { | |
4033 | ptr2 = yarray[y] + xarray[x]; | |
4034 | r = (int)*ptr2++; | |
4035 | g = (int)*ptr2++; | |
4036 | b = (int)*ptr2; | |
4037 | r = im->rmap[r]; | |
4038 | g = im->gmap[g]; | |
4039 | b = im->bmap[b]; | |
4040 | *img++ = b; | |
4041 | *img++ = g; | |
4042 | *img++ = r; | |
4043 | } | |
4044 | img += jmp; | |
4045 | } | |
4046 | } | |
4047 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
4048 | { | |
4049 | for (y = 0; y < h; y++) | |
4050 | { | |
4051 | for (x = 0; x < w; x++) | |
4052 | { | |
4053 | ptr2 = yarray[y] + xarray[x]; | |
4054 | r = (int)*ptr2++; | |
4055 | g = (int)*ptr2++; | |
4056 | b = (int)*ptr2; | |
4057 | r = im->rmap[r]; | |
4058 | g = im->gmap[g]; | |
4059 | b = im->bmap[b]; | |
4060 | *img++ = g; | |
4061 | *img++ = r; | |
4062 | *img++ = b; | |
4063 | } | |
4064 | img += jmp; | |
4065 | } | |
4066 | } | |
4067 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
4068 | { | |
4069 | for (y = 0; y < h; y++) | |
4070 | { | |
4071 | for (x = 0; x < w; x++) | |
4072 | { | |
4073 | ptr2 = yarray[y] + xarray[x]; | |
4074 | r = (int)*ptr2++; | |
4075 | g = (int)*ptr2++; | |
4076 | b = (int)*ptr2; | |
4077 | r = im->rmap[r]; | |
4078 | g = im->gmap[g]; | |
4079 | b = im->bmap[b]; | |
4080 | *img++ = g; | |
4081 | *img++ = b; | |
4082 | *img++ = r; | |
4083 | } | |
4084 | img += jmp; | |
4085 | } | |
4086 | } | |
4087 | } | |
4088 | ||
4089 | void | |
4090 | grender_shaped_32_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4091 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4092 | unsigned char **yarray) | |
4093 | { | |
4094 | int x, y, val, r, g, b; | |
4095 | unsigned char *ptr2; | |
4096 | unsigned int *img; | |
4097 | int jmp; | |
4098 | ||
4099 | jmp = (xim->bytes_per_line >> 2) - w; | |
4100 | img = (unsigned int *)xim->data; | |
4101 | if (id->byte_order == BYTE_ORD_24_RGB) | |
4102 | { | |
4103 | for (y = 0; y < h; y++) | |
4104 | { | |
4105 | for (x = 0; x < w; x++) | |
4106 | { | |
4107 | ptr2 = yarray[y] + xarray[x]; | |
4108 | r = (int)*ptr2++; | |
4109 | g = (int)*ptr2++; | |
4110 | b = (int)*ptr2; | |
4111 | if ((r == im->shape_color.r) && | |
4112 | (g == im->shape_color.g) && | |
4113 | (b == im->shape_color.b)) | |
4114 | { | |
4115 | XPutPixel(sxim, x, y, 0); | |
4116 | img++; | |
4117 | } | |
4118 | else | |
4119 | { | |
4120 | XPutPixel(sxim, x, y, 1); | |
4121 | r = im->rmap[r]; | |
4122 | g = im->gmap[g]; | |
4123 | b = im->bmap[b]; | |
4124 | val = (r << 16) | (g << 8) | b; | |
4125 | *img++ = val; | |
4126 | } | |
4127 | } | |
4128 | img += jmp; | |
4129 | } | |
4130 | } | |
4131 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
4132 | { | |
4133 | for (y = 0; y < h; y++) | |
4134 | { | |
4135 | for (x = 0; x < w; x++) | |
4136 | { | |
4137 | ptr2 = yarray[y] + xarray[x]; | |
4138 | r = (int)*ptr2++; | |
4139 | g = (int)*ptr2++; | |
4140 | b = (int)*ptr2; | |
4141 | if ((r == im->shape_color.r) && | |
4142 | (g == im->shape_color.g) && | |
4143 | (b == im->shape_color.b)) | |
4144 | { | |
4145 | XPutPixel(sxim, x, y, 0); | |
4146 | img++; | |
4147 | } | |
4148 | else | |
4149 | { | |
4150 | XPutPixel(sxim, x, y, 1); | |
4151 | r = im->rmap[r]; | |
4152 | g = im->gmap[g]; | |
4153 | b = im->bmap[b]; | |
4154 | val = (r << 16) | (b << 8) | g; | |
4155 | *img++ = val; | |
4156 | } | |
4157 | } | |
4158 | img += jmp; | |
4159 | } | |
4160 | } | |
4161 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
4162 | { | |
4163 | for (y = 0; y < h; y++) | |
4164 | { | |
4165 | for (x = 0; x < w; x++) | |
4166 | { | |
4167 | ptr2 = yarray[y] + xarray[x]; | |
4168 | r = (int)*ptr2++; | |
4169 | g = (int)*ptr2++; | |
4170 | b = (int)*ptr2; | |
4171 | if ((r == im->shape_color.r) && | |
4172 | (g == im->shape_color.g) && | |
4173 | (b == im->shape_color.b)) | |
4174 | { | |
4175 | XPutPixel(sxim, x, y, 0); | |
4176 | img++; | |
4177 | } | |
4178 | else | |
4179 | { | |
4180 | XPutPixel(sxim, x, y, 1); | |
4181 | r = im->rmap[r]; | |
4182 | g = im->gmap[g]; | |
4183 | b = im->bmap[b]; | |
4184 | val = (b << 16) | (r << 8) | g; | |
4185 | *img++ = val; | |
4186 | } | |
4187 | } | |
4188 | img += jmp; | |
4189 | } | |
4190 | } | |
4191 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
4192 | { | |
4193 | for (y = 0; y < h; y++) | |
4194 | { | |
4195 | for (x = 0; x < w; x++) | |
4196 | { | |
4197 | ptr2 = yarray[y] + xarray[x]; | |
4198 | r = (int)*ptr2++; | |
4199 | g = (int)*ptr2++; | |
4200 | b = (int)*ptr2; | |
4201 | if ((r == im->shape_color.r) && | |
4202 | (g == im->shape_color.g) && | |
4203 | (b == im->shape_color.b)) | |
4204 | { | |
4205 | XPutPixel(sxim, x, y, 0); | |
4206 | img++; | |
4207 | } | |
4208 | else | |
4209 | { | |
4210 | XPutPixel(sxim, x, y, 1); | |
4211 | r = im->rmap[r]; | |
4212 | g = im->gmap[g]; | |
4213 | b = im->bmap[b]; | |
4214 | val = (b << 16) | (g << 8) | r; | |
4215 | *img++ = val; | |
4216 | } | |
4217 | } | |
4218 | img += jmp; | |
4219 | } | |
4220 | } | |
4221 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
4222 | { | |
4223 | for (y = 0; y < h; y++) | |
4224 | { | |
4225 | for (x = 0; x < w; x++) | |
4226 | { | |
4227 | ptr2 = yarray[y] + xarray[x]; | |
4228 | r = (int)*ptr2++; | |
4229 | g = (int)*ptr2++; | |
4230 | b = (int)*ptr2; | |
4231 | if ((r == im->shape_color.r) && | |
4232 | (g == im->shape_color.g) && | |
4233 | (b == im->shape_color.b)) | |
4234 | { | |
4235 | XPutPixel(sxim, x, y, 0); | |
4236 | img++; | |
4237 | } | |
4238 | else | |
4239 | { | |
4240 | XPutPixel(sxim, x, y, 1); | |
4241 | r = im->rmap[r]; | |
4242 | g = im->gmap[g]; | |
4243 | b = im->bmap[b]; | |
4244 | val = (g << 16) | (r << 8) | b; | |
4245 | *img++ = val; | |
4246 | } | |
4247 | } | |
4248 | img += jmp; | |
4249 | } | |
4250 | } | |
4251 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
4252 | { | |
4253 | for (y = 0; y < h; y++) | |
4254 | { | |
4255 | for (x = 0; x < w; x++) | |
4256 | { | |
4257 | ptr2 = yarray[y] + xarray[x]; | |
4258 | r = (int)*ptr2++; | |
4259 | g = (int)*ptr2++; | |
4260 | b = (int)*ptr2; | |
4261 | if ((r == im->shape_color.r) && | |
4262 | (g == im->shape_color.g) && | |
4263 | (b == im->shape_color.b)) | |
4264 | { | |
4265 | XPutPixel(sxim, x, y, 0); | |
4266 | img++; | |
4267 | } | |
4268 | else | |
4269 | { | |
4270 | XPutPixel(sxim, x, y, 1); | |
4271 | r = im->rmap[r]; | |
4272 | g = im->gmap[g]; | |
4273 | b = im->bmap[b]; | |
4274 | val = (g << 16) | (b << 8) | r; | |
4275 | *img++ = val; | |
4276 | } | |
4277 | } | |
4278 | img += jmp; | |
4279 | } | |
4280 | } | |
4281 | } | |
4282 | ||
4283 | void | |
4284 | grender_32_fast_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4285 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4286 | unsigned char **yarray) | |
4287 | { | |
4288 | int x, y, val, r, g, b; | |
4289 | unsigned char *ptr2; | |
4290 | unsigned int *img; | |
4291 | int jmp; | |
4292 | ||
4293 | jmp = (xim->bytes_per_line >> 2) - w; | |
4294 | img = (unsigned int *)xim->data; | |
4295 | if (id->byte_order == BYTE_ORD_24_RGB) | |
4296 | { | |
4297 | for (y = 0; y < h; y++) | |
4298 | { | |
4299 | for (x = 0; x < w; x++) | |
4300 | { | |
4301 | ptr2 = yarray[y] + xarray[x]; | |
4302 | r = (int)*ptr2++; | |
4303 | g = (int)*ptr2++; | |
4304 | b = (int)*ptr2; | |
4305 | r = im->rmap[r]; | |
4306 | g = im->gmap[g]; | |
4307 | b = im->bmap[b]; | |
4308 | val = (r << 16) | (g << 8) | b; | |
4309 | *img++ = val; | |
4310 | } | |
4311 | img += jmp; | |
4312 | } | |
4313 | } | |
4314 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
4315 | { | |
4316 | for (y = 0; y < h; y++) | |
4317 | { | |
4318 | for (x = 0; x < w; x++) | |
4319 | { | |
4320 | ptr2 = yarray[y] + xarray[x]; | |
4321 | r = (int)*ptr2++; | |
4322 | g = (int)*ptr2++; | |
4323 | b = (int)*ptr2; | |
4324 | r = im->rmap[r]; | |
4325 | g = im->gmap[g]; | |
4326 | b = im->bmap[b]; | |
4327 | val = (r << 16) | (b << 8) | g; | |
4328 | *img++ = val; | |
4329 | } | |
4330 | img += jmp; | |
4331 | } | |
4332 | } | |
4333 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
4334 | { | |
4335 | for (y = 0; y < h; y++) | |
4336 | { | |
4337 | for (x = 0; x < w; x++) | |
4338 | { | |
4339 | ptr2 = yarray[y] + xarray[x]; | |
4340 | r = (int)*ptr2++; | |
4341 | g = (int)*ptr2++; | |
4342 | b = (int)*ptr2; | |
4343 | r = im->rmap[r]; | |
4344 | g = im->gmap[g]; | |
4345 | b = im->bmap[b]; | |
4346 | val = (b << 16) | (r << 8) | g; | |
4347 | *img++ = val; | |
4348 | } | |
4349 | img += jmp; | |
4350 | } | |
4351 | } | |
4352 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
4353 | { | |
4354 | for (y = 0; y < h; y++) | |
4355 | { | |
4356 | for (x = 0; x < w; x++) | |
4357 | { | |
4358 | ptr2 = yarray[y] + xarray[x]; | |
4359 | r = (int)*ptr2++; | |
4360 | g = (int)*ptr2++; | |
4361 | b = (int)*ptr2; | |
4362 | r = im->rmap[r]; | |
4363 | g = im->gmap[g]; | |
4364 | b = im->bmap[b]; | |
4365 | val = (b << 16) | (g << 8) | r; | |
4366 | *img++ = val; | |
4367 | } | |
4368 | img += jmp; | |
4369 | } | |
4370 | } | |
4371 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
4372 | { | |
4373 | for (y = 0; y < h; y++) | |
4374 | { | |
4375 | for (x = 0; x < w; x++) | |
4376 | { | |
4377 | ptr2 = yarray[y] + xarray[x]; | |
4378 | r = (int)*ptr2++; | |
4379 | g = (int)*ptr2++; | |
4380 | b = (int)*ptr2; | |
4381 | r = im->rmap[r]; | |
4382 | g = im->gmap[g]; | |
4383 | b = im->bmap[b]; | |
4384 | val = (g << 16) | (r << 8) | b; | |
4385 | *img++ = val; | |
4386 | } | |
4387 | img += jmp; | |
4388 | } | |
4389 | } | |
4390 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
4391 | { | |
4392 | for (y = 0; y < h; y++) | |
4393 | { | |
4394 | for (x = 0; x < w; x++) | |
4395 | { | |
4396 | ptr2 = yarray[y] + xarray[x]; | |
4397 | r = (int)*ptr2++; | |
4398 | g = (int)*ptr2++; | |
4399 | b = (int)*ptr2; | |
4400 | r = im->rmap[r]; | |
4401 | g = im->gmap[g]; | |
4402 | b = im->bmap[b]; | |
4403 | val = (g << 16) | (b << 8) | r; | |
4404 | *img++ = val; | |
4405 | } | |
4406 | img += jmp; | |
4407 | } | |
4408 | } | |
4409 | } | |
4410 | ||
4411 | void | |
4412 | grender_shaped_15_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4413 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4414 | unsigned char **yarray) | |
4415 | { | |
4416 | int x, y, val, r, g, b; | |
4417 | unsigned char *ptr2; | |
4418 | ||
4419 | for (y = 0; y < h; y++) | |
4420 | { | |
4421 | for (x = 0; x < w; x++) | |
4422 | { | |
4423 | ptr2 = yarray[y] + xarray[x]; | |
4424 | r = (int)*ptr2++; | |
4425 | g = (int)*ptr2++; | |
4426 | b = (int)*ptr2; | |
4427 | if ((r == im->shape_color.r) && | |
4428 | (g == im->shape_color.g) && | |
4429 | (b == im->shape_color.b)) | |
4430 | XPutPixel(sxim, x, y, 0); | |
4431 | else | |
4432 | { | |
4433 | XPutPixel(sxim, x, y, 1); | |
4434 | r = im->rmap[r]; | |
4435 | g = im->gmap[g]; | |
4436 | b = im->bmap[b]; | |
4437 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
4438 | XPutPixel(xim, x, y, val); | |
4439 | } | |
4440 | } | |
4441 | } | |
4442 | } | |
4443 | ||
4444 | void | |
4445 | grender_15_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4446 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4447 | unsigned char **yarray) | |
4448 | { | |
4449 | int x, y, val, r, g, b; | |
4450 | unsigned char *ptr2; | |
4451 | ||
4452 | for (y = 0; y < h; y++) | |
4453 | { | |
4454 | for (x = 0; x < w; x++) | |
4455 | { | |
4456 | ptr2 = yarray[y] + xarray[x]; | |
4457 | r = (int)*ptr2++; | |
4458 | g = (int)*ptr2++; | |
4459 | b = (int)*ptr2; | |
4460 | r = im->rmap[r]; | |
4461 | g = im->gmap[g]; | |
4462 | b = im->bmap[b]; | |
4463 | val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); | |
4464 | XPutPixel(xim, x, y, val); | |
4465 | } | |
4466 | } | |
4467 | } | |
4468 | ||
4469 | void | |
4470 | grender_shaped_16_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4471 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4472 | unsigned char **yarray) | |
4473 | { | |
4474 | int x, y, val, r, g, b; | |
4475 | unsigned char *ptr2; | |
4476 | ||
4477 | for (y = 0; y < h; y++) | |
4478 | { | |
4479 | for (x = 0; x < w; x++) | |
4480 | { | |
4481 | ptr2 = yarray[y] + xarray[x]; | |
4482 | r = (int)*ptr2++; | |
4483 | g = (int)*ptr2++; | |
4484 | b = (int)*ptr2; | |
4485 | if ((r == im->shape_color.r) && | |
4486 | (g == im->shape_color.g) && | |
4487 | (b == im->shape_color.b)) | |
4488 | XPutPixel(sxim, x, y, 0); | |
4489 | else | |
4490 | { | |
4491 | XPutPixel(sxim, x, y, 1); | |
4492 | r = im->rmap[r]; | |
4493 | g = im->gmap[g]; | |
4494 | b = im->bmap[b]; | |
4495 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
4496 | XPutPixel(xim, x, y, val); | |
4497 | } | |
4498 | } | |
4499 | } | |
4500 | } | |
4501 | ||
4502 | void | |
4503 | grender_16_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4504 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4505 | unsigned char **yarray) | |
4506 | { | |
4507 | int x, y, val, r, g, b; | |
4508 | unsigned char *ptr2; | |
4509 | ||
4510 | for (y = 0; y < h; y++) | |
4511 | { | |
4512 | for (x = 0; x < w; x++) | |
4513 | { | |
4514 | ptr2 = yarray[y] + xarray[x]; | |
4515 | r = (int)*ptr2++; | |
4516 | g = (int)*ptr2++; | |
4517 | b = (int)*ptr2; | |
4518 | r = im->rmap[r]; | |
4519 | g = im->gmap[g]; | |
4520 | b = im->bmap[b]; | |
4521 | val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); | |
4522 | XPutPixel(xim, x, y, val); | |
4523 | } | |
4524 | } | |
4525 | } | |
4526 | ||
4527 | void | |
4528 | grender_shaped_24_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4529 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4530 | unsigned char **yarray) | |
4531 | { | |
4532 | int x, y, val, r, g, b; | |
4533 | unsigned char *ptr2; | |
4534 | ||
4535 | if (id->byte_order == BYTE_ORD_24_RGB) | |
4536 | { | |
4537 | for (y = 0; y < h; y++) | |
4538 | { | |
4539 | for (x = 0; x < w; x++) | |
4540 | { | |
4541 | ptr2 = yarray[y] + xarray[x]; | |
4542 | r = (int)*ptr2++; | |
4543 | g = (int)*ptr2++; | |
4544 | b = (int)*ptr2; | |
4545 | if ((r == im->shape_color.r) && | |
4546 | (g == im->shape_color.g) && | |
4547 | (b == im->shape_color.b)) | |
4548 | XPutPixel(sxim, x, y, 0); | |
4549 | else | |
4550 | { | |
4551 | XPutPixel(sxim, x, y, 1); | |
4552 | r = im->rmap[r]; | |
4553 | g = im->gmap[g]; | |
4554 | b = im->bmap[b]; | |
4555 | val = (r << 16) | (g << 8) | b; | |
4556 | XPutPixel(xim, x, y, val); | |
4557 | } | |
4558 | } | |
4559 | } | |
4560 | } | |
4561 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
4562 | { | |
4563 | for (y = 0; y < h; y++) | |
4564 | { | |
4565 | for (x = 0; x < w; x++) | |
4566 | { | |
4567 | ptr2 = yarray[y] + xarray[x]; | |
4568 | r = (int)*ptr2++; | |
4569 | g = (int)*ptr2++; | |
4570 | b = (int)*ptr2; | |
4571 | if ((r == im->shape_color.r) && | |
4572 | (g == im->shape_color.g) && | |
4573 | (b == im->shape_color.b)) | |
4574 | XPutPixel(sxim, x, y, 0); | |
4575 | else | |
4576 | { | |
4577 | XPutPixel(sxim, x, y, 1); | |
4578 | r = im->rmap[r]; | |
4579 | g = im->gmap[g]; | |
4580 | b = im->bmap[b]; | |
4581 | val = (r << 16) | (b << 8) | g; | |
4582 | XPutPixel(xim, x, y, val); | |
4583 | } | |
4584 | } | |
4585 | } | |
4586 | } | |
4587 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
4588 | { | |
4589 | for (y = 0; y < h; y++) | |
4590 | { | |
4591 | for (x = 0; x < w; x++) | |
4592 | { | |
4593 | ptr2 = yarray[y] + xarray[x]; | |
4594 | r = (int)*ptr2++; | |
4595 | g = (int)*ptr2++; | |
4596 | b = (int)*ptr2; | |
4597 | if ((r == im->shape_color.r) && | |
4598 | (g == im->shape_color.g) && | |
4599 | (b == im->shape_color.b)) | |
4600 | XPutPixel(sxim, x, y, 0); | |
4601 | else | |
4602 | { | |
4603 | XPutPixel(sxim, x, y, 1); | |
4604 | r = im->rmap[r]; | |
4605 | g = im->gmap[g]; | |
4606 | b = im->bmap[b]; | |
4607 | val = (b << 16) | (r << 8) | g; | |
4608 | XPutPixel(xim, x, y, val); | |
4609 | } | |
4610 | } | |
4611 | } | |
4612 | } | |
4613 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
4614 | { | |
4615 | for (y = 0; y < h; y++) | |
4616 | { | |
4617 | for (x = 0; x < w; x++) | |
4618 | { | |
4619 | ptr2 = yarray[y] + xarray[x]; | |
4620 | r = (int)*ptr2++; | |
4621 | g = (int)*ptr2++; | |
4622 | b = (int)*ptr2; | |
4623 | if ((r == im->shape_color.r) && | |
4624 | (g == im->shape_color.g) && | |
4625 | (b == im->shape_color.b)) | |
4626 | XPutPixel(sxim, x, y, 0); | |
4627 | else | |
4628 | { | |
4629 | XPutPixel(sxim, x, y, 1); | |
4630 | r = im->rmap[r]; | |
4631 | g = im->gmap[g]; | |
4632 | b = im->bmap[b]; | |
4633 | val = (b << 16) | (g << 8) | r; | |
4634 | XPutPixel(xim, x, y, val); | |
4635 | } | |
4636 | } | |
4637 | } | |
4638 | } | |
4639 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
4640 | { | |
4641 | for (y = 0; y < h; y++) | |
4642 | { | |
4643 | for (x = 0; x < w; x++) | |
4644 | { | |
4645 | ptr2 = yarray[y] + xarray[x]; | |
4646 | r = (int)*ptr2++; | |
4647 | g = (int)*ptr2++; | |
4648 | b = (int)*ptr2; | |
4649 | if ((r == im->shape_color.r) && | |
4650 | (g == im->shape_color.g) && | |
4651 | (b == im->shape_color.b)) | |
4652 | XPutPixel(sxim, x, y, 0); | |
4653 | else | |
4654 | { | |
4655 | XPutPixel(sxim, x, y, 1); | |
4656 | r = im->rmap[r]; | |
4657 | g = im->gmap[g]; | |
4658 | b = im->bmap[b]; | |
4659 | val = (g << 16) | (r << 8) | b; | |
4660 | XPutPixel(xim, x, y, val); | |
4661 | } | |
4662 | } | |
4663 | } | |
4664 | } | |
4665 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
4666 | { | |
4667 | for (y = 0; y < h; y++) | |
4668 | { | |
4669 | for (x = 0; x < w; x++) | |
4670 | { | |
4671 | ptr2 = yarray[y] + xarray[x]; | |
4672 | r = (int)*ptr2++; | |
4673 | g = (int)*ptr2++; | |
4674 | b = (int)*ptr2; | |
4675 | if ((r == im->shape_color.r) && | |
4676 | (g == im->shape_color.g) && | |
4677 | (b == im->shape_color.b)) | |
4678 | XPutPixel(sxim, x, y, 0); | |
4679 | else | |
4680 | { | |
4681 | XPutPixel(sxim, x, y, 1); | |
4682 | r = im->rmap[r]; | |
4683 | g = im->gmap[g]; | |
4684 | b = im->bmap[b]; | |
4685 | val = (g << 16) | (b << 8) | r; | |
4686 | XPutPixel(xim, x, y, val); | |
4687 | } | |
4688 | } | |
4689 | } | |
4690 | } | |
4691 | } | |
4692 | ||
4693 | void | |
4694 | grender_24_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4695 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4696 | unsigned char **yarray) | |
4697 | { | |
4698 | int x, y, val, r, g, b; | |
4699 | unsigned char *ptr2; | |
4700 | ||
4701 | if (id->byte_order == BYTE_ORD_24_RGB) | |
4702 | { | |
4703 | for (y = 0; y < h; y++) | |
4704 | { | |
4705 | for (x = 0; x < w; x++) | |
4706 | { | |
4707 | ptr2 = yarray[y] + xarray[x]; | |
4708 | r = (int)*ptr2++; | |
4709 | g = (int)*ptr2++; | |
4710 | b = (int)*ptr2; | |
4711 | r = im->rmap[r]; | |
4712 | g = im->gmap[g]; | |
4713 | b = im->bmap[b]; | |
4714 | val = (r << 16) | (g << 8) | b; | |
4715 | XPutPixel(xim, x, y, val); | |
4716 | } | |
4717 | } | |
4718 | } | |
4719 | else if (id->byte_order == BYTE_ORD_24_RBG) | |
4720 | { | |
4721 | for (y = 0; y < h; y++) | |
4722 | { | |
4723 | for (x = 0; x < w; x++) | |
4724 | { | |
4725 | ptr2 = yarray[y] + xarray[x]; | |
4726 | r = (int)*ptr2++; | |
4727 | g = (int)*ptr2++; | |
4728 | b = (int)*ptr2; | |
4729 | r = im->rmap[r]; | |
4730 | g = im->gmap[g]; | |
4731 | b = im->bmap[b]; | |
4732 | val = (r << 16) | (b << 8) | g; | |
4733 | XPutPixel(xim, x, y, val); | |
4734 | } | |
4735 | } | |
4736 | } | |
4737 | else if (id->byte_order == BYTE_ORD_24_BRG) | |
4738 | { | |
4739 | for (y = 0; y < h; y++) | |
4740 | { | |
4741 | for (x = 0; x < w; x++) | |
4742 | { | |
4743 | ptr2 = yarray[y] + xarray[x]; | |
4744 | r = (int)*ptr2++; | |
4745 | g = (int)*ptr2++; | |
4746 | b = (int)*ptr2; | |
4747 | r = im->rmap[r]; | |
4748 | g = im->gmap[g]; | |
4749 | b = im->bmap[b]; | |
4750 | val = (b << 16) | (r << 8) | g; | |
4751 | XPutPixel(xim, x, y, val); | |
4752 | } | |
4753 | } | |
4754 | } | |
4755 | else if (id->byte_order == BYTE_ORD_24_BGR) | |
4756 | { | |
4757 | for (y = 0; y < h; y++) | |
4758 | { | |
4759 | for (x = 0; x < w; x++) | |
4760 | { | |
4761 | ptr2 = yarray[y] + xarray[x]; | |
4762 | r = (int)*ptr2++; | |
4763 | g = (int)*ptr2++; | |
4764 | b = (int)*ptr2; | |
4765 | r = im->rmap[r]; | |
4766 | g = im->gmap[g]; | |
4767 | b = im->bmap[b]; | |
4768 | val = (b << 16) | (g << 8) | r; | |
4769 | XPutPixel(xim, x, y, val); | |
4770 | } | |
4771 | } | |
4772 | } | |
4773 | else if (id->byte_order == BYTE_ORD_24_GRB) | |
4774 | { | |
4775 | for (y = 0; y < h; y++) | |
4776 | { | |
4777 | for (x = 0; x < w; x++) | |
4778 | { | |
4779 | ptr2 = yarray[y] + xarray[x]; | |
4780 | r = (int)*ptr2++; | |
4781 | g = (int)*ptr2++; | |
4782 | b = (int)*ptr2; | |
4783 | r = im->rmap[r]; | |
4784 | g = im->gmap[g]; | |
4785 | b = im->bmap[b]; | |
4786 | val = (g << 16) | (r << 8) | b; | |
4787 | XPutPixel(xim, x, y, val); | |
4788 | } | |
4789 | } | |
4790 | } | |
4791 | else if (id->byte_order == BYTE_ORD_24_GBR) | |
4792 | { | |
4793 | for (y = 0; y < h; y++) | |
4794 | { | |
4795 | for (x = 0; x < w; x++) | |
4796 | { | |
4797 | ptr2 = yarray[y] + xarray[x]; | |
4798 | r = (int)*ptr2++; | |
4799 | g = (int)*ptr2++; | |
4800 | b = (int)*ptr2; | |
4801 | r = im->rmap[r]; | |
4802 | g = im->gmap[g]; | |
4803 | b = im->bmap[b]; | |
4804 | val = (g << 16) | (b << 8) | r; | |
4805 | XPutPixel(xim, x, y, val); | |
4806 | } | |
4807 | } | |
4808 | } | |
4809 | } | |
4810 | ||
4811 | void | |
4812 | grender_shaped_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
4813 | XImage * sxim, int *er1, int *er2, int *xarray, | |
4814 | unsigned char **yarray, int bpp) | |
4815 | { | |
4816 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
4817 | unsigned char *ptr2; | |
4818 | unsigned char *img; | |
4819 | int jmp; | |
4820 | ||
4821 | jmp = (xim->bytes_per_line) - w; | |
4822 | img = (unsigned char *)xim->data; | |
4823 | switch (id->render_type) | |
4824 | { | |
4825 | case RT_PLAIN_PALETTE: | |
4826 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
4827 | { | |
4828 | for (y = 0; y < h; y++) | |
4829 | { | |
4830 | for (x = 0; x < w; x++) | |
4831 | { | |
4832 | ptr2 = yarray[y] + xarray[x]; | |
4833 | r = (int)*ptr2++; | |
4834 | g = (int)*ptr2++; | |
4835 | b = (int)*ptr2; | |
4836 | if ((r == im->shape_color.r) && | |
4837 | (g == im->shape_color.g) && | |
4838 | (b == im->shape_color.b)) | |
4839 | { | |
4840 | XPutPixel(sxim, x, y, 0); | |
4841 | img++; | |
4842 | } | |
4843 | else | |
4844 | { | |
4845 | XPutPixel(sxim, x, y, 1); | |
4846 | r = im->rmap[r]; | |
4847 | g = im->gmap[g]; | |
4848 | b = im->bmap[b]; | |
4849 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
4850 | *img++ = val; | |
4851 | } | |
4852 | } | |
4853 | img += jmp; | |
4854 | } | |
4855 | } | |
4856 | else | |
4857 | { | |
4858 | for (y = 0; y < h; y++) | |
4859 | { | |
4860 | for (x = 0; x < w; x++) | |
4861 | { | |
4862 | ptr2 = yarray[y] + xarray[x]; | |
4863 | r = (int)*ptr2++; | |
4864 | g = (int)*ptr2++; | |
4865 | b = (int)*ptr2; | |
4866 | if ((r == im->shape_color.r) && | |
4867 | (g == im->shape_color.g) && | |
4868 | (b == im->shape_color.b)) | |
4869 | XPutPixel(sxim, x, y, 0); | |
4870 | else | |
4871 | { | |
4872 | XPutPixel(sxim, x, y, 1); | |
4873 | r = im->rmap[r]; | |
4874 | g = im->gmap[g]; | |
4875 | b = im->bmap[b]; | |
4876 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
4877 | XPutPixel(xim, x, y, val); | |
4878 | } | |
4879 | } | |
4880 | } | |
4881 | } | |
4882 | break; | |
4883 | case RT_PLAIN_PALETTE_FAST: | |
4884 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
4885 | { | |
4886 | for (y = 0; y < h; y++) | |
4887 | { | |
4888 | for (x = 0; x < w; x++) | |
4889 | { | |
4890 | ptr2 = yarray[y] + xarray[x]; | |
4891 | r = (int)*ptr2++; | |
4892 | g = (int)*ptr2++; | |
4893 | b = (int)*ptr2; | |
4894 | if ((r == im->shape_color.r) && | |
4895 | (g == im->shape_color.g) && | |
4896 | (b == im->shape_color.b)) | |
4897 | { | |
4898 | XPutPixel(sxim, x, y, 0); | |
4899 | img++; | |
4900 | } | |
4901 | else | |
4902 | { | |
4903 | XPutPixel(sxim, x, y, 1); | |
4904 | r = im->rmap[r]; | |
4905 | g = im->gmap[g]; | |
4906 | b = im->bmap[b]; | |
4907 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
4908 | *img++ = val; | |
4909 | } | |
4910 | } | |
4911 | img += jmp; | |
4912 | } | |
4913 | } | |
4914 | else | |
4915 | { | |
4916 | for (y = 0; y < h; y++) | |
4917 | { | |
4918 | for (x = 0; x < w; x++) | |
4919 | { | |
4920 | ptr2 = yarray[y] + xarray[x]; | |
4921 | r = (int)*ptr2++; | |
4922 | g = (int)*ptr2++; | |
4923 | b = (int)*ptr2; | |
4924 | if ((r == im->shape_color.r) && | |
4925 | (g == im->shape_color.g) && | |
4926 | (b == im->shape_color.b)) | |
4927 | XPutPixel(sxim, x, y, 0); | |
4928 | else | |
4929 | { | |
4930 | XPutPixel(sxim, x, y, 1); | |
4931 | r = im->rmap[r]; | |
4932 | g = im->gmap[g]; | |
4933 | b = im->bmap[b]; | |
4934 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
4935 | XPutPixel(xim, x, y, val); | |
4936 | } | |
4937 | } | |
4938 | } | |
4939 | } | |
4940 | break; | |
4941 | case RT_DITHER_PALETTE: | |
4942 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
4943 | { | |
4944 | for (y = 0; y < h; y++) | |
4945 | { | |
4946 | ter = er1; | |
4947 | er1 = er2; | |
4948 | er2 = ter; | |
4949 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
4950 | er2[ex] = 0; | |
4951 | ex = 3; | |
4952 | for (x = 0; x < w; x++) | |
4953 | { | |
4954 | ptr2 = yarray[y] + xarray[x]; | |
4955 | r = (int)*ptr2++; | |
4956 | g = (int)*ptr2++; | |
4957 | b = (int)*ptr2; | |
4958 | if ((r == im->shape_color.r) && | |
4959 | (g == im->shape_color.g) && | |
4960 | (b == im->shape_color.b)) | |
4961 | { | |
4962 | { | |
4963 | XPutPixel(sxim, x, y, 0); | |
4964 | img++; | |
4965 | } | |
4966 | ex += 3; | |
4967 | } | |
4968 | else | |
4969 | { | |
4970 | XPutPixel(sxim, x, y, 1); | |
4971 | r = im->rmap[r]; | |
4972 | g = im->gmap[g]; | |
4973 | b = im->bmap[b]; | |
4974 | er = r + er1[ex++]; | |
4975 | eg = g + er1[ex++]; | |
4976 | eb = b + er1[ex++]; | |
4977 | if (er > 255) | |
4978 | er = 255; | |
4979 | else if (er < 0) | |
4980 | er = 0; | |
4981 | if (eg > 255) | |
4982 | eg = 255; | |
4983 | else if (eg < 0) | |
4984 | eg = 0; | |
4985 | if (eb > 255) | |
4986 | eb = 255; | |
4987 | else if (eb < 0) | |
4988 | eb = 0; | |
4989 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
4990 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
4991 | *img++ = val; | |
4992 | } | |
4993 | } | |
4994 | img += jmp; | |
4995 | } | |
4996 | } | |
4997 | else | |
4998 | { | |
4999 | for (y = 0; y < h; y++) | |
5000 | { | |
5001 | ter = er1; | |
5002 | er1 = er2; | |
5003 | er2 = ter; | |
5004 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5005 | er2[ex] = 0; | |
5006 | ex = 3; | |
5007 | for (x = 0; x < w; x++) | |
5008 | { | |
5009 | ptr2 = yarray[y] + xarray[x]; | |
5010 | r = (int)*ptr2++; | |
5011 | g = (int)*ptr2++; | |
5012 | b = (int)*ptr2; | |
5013 | if ((r == im->shape_color.r) && | |
5014 | (g == im->shape_color.g) && | |
5015 | (b == im->shape_color.b)) | |
5016 | { | |
5017 | XPutPixel(sxim, x, y, 0); | |
5018 | ex += 3; | |
5019 | } | |
5020 | else | |
5021 | { | |
5022 | XPutPixel(sxim, x, y, 1); | |
5023 | r = im->rmap[r]; | |
5024 | g = im->gmap[g]; | |
5025 | b = im->bmap[b]; | |
5026 | er = r + er1[ex++]; | |
5027 | eg = g + er1[ex++]; | |
5028 | eb = b + er1[ex++]; | |
5029 | if (er > 255) | |
5030 | er = 255; | |
5031 | else if (er < 0) | |
5032 | er = 0; | |
5033 | if (eg > 255) | |
5034 | eg = 255; | |
5035 | else if (eg < 0) | |
5036 | eg = 0; | |
5037 | if (eb > 255) | |
5038 | eb = 255; | |
5039 | else if (eb < 0) | |
5040 | eb = 0; | |
5041 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
5042 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5043 | XPutPixel(xim, x, y, val); | |
5044 | } | |
5045 | } | |
5046 | } | |
5047 | } | |
5048 | break; | |
5049 | case RT_DITHER_PALETTE_FAST: | |
5050 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
5051 | { | |
5052 | for (y = 0; y < h; y++) | |
5053 | { | |
5054 | ter = er1; | |
5055 | er1 = er2; | |
5056 | er2 = ter; | |
5057 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5058 | er2[ex] = 0; | |
5059 | ex = 3; | |
5060 | for (x = 0; x < w; x++) | |
5061 | { | |
5062 | ptr2 = yarray[y] + xarray[x]; | |
5063 | r = (int)*ptr2++; | |
5064 | g = (int)*ptr2++; | |
5065 | b = (int)*ptr2; | |
5066 | if ((r == im->shape_color.r) && | |
5067 | (g == im->shape_color.g) && | |
5068 | (b == im->shape_color.b)) | |
5069 | { | |
5070 | { | |
5071 | XPutPixel(sxim, x, y, 0); | |
5072 | img++; | |
5073 | } | |
5074 | ex += 3; | |
5075 | } | |
5076 | else | |
5077 | { | |
5078 | XPutPixel(sxim, x, y, 1); | |
5079 | r = im->rmap[r]; | |
5080 | g = im->gmap[g]; | |
5081 | b = im->bmap[b]; | |
5082 | er = r + er1[ex++]; | |
5083 | eg = g + er1[ex++]; | |
5084 | eb = b + er1[ex++]; | |
5085 | if (er > 255) | |
5086 | er = 255; | |
5087 | else if (er < 0) | |
5088 | er = 0; | |
5089 | if (eg > 255) | |
5090 | eg = 255; | |
5091 | else if (eg < 0) | |
5092 | eg = 0; | |
5093 | if (eb > 255) | |
5094 | eb = 255; | |
5095 | else if (eb < 0) | |
5096 | eb = 0; | |
5097 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
5098 | er = ERROR_RED(er, val); | |
5099 | eg = ERROR_GRN(eg, val); | |
5100 | eb = ERROR_BLU(eb, val); | |
5101 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5102 | *img++ = COLOR_INDEX(val); | |
5103 | } | |
5104 | } | |
5105 | img += jmp; | |
5106 | } | |
5107 | } | |
5108 | else | |
5109 | { | |
5110 | for (y = 0; y < h; y++) | |
5111 | { | |
5112 | ter = er1; | |
5113 | er1 = er2; | |
5114 | er2 = ter; | |
5115 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5116 | er2[ex] = 0; | |
5117 | ex = 3; | |
5118 | for (x = 0; x < w; x++) | |
5119 | { | |
5120 | ptr2 = yarray[y] + xarray[x]; | |
5121 | r = (int)*ptr2++; | |
5122 | g = (int)*ptr2++; | |
5123 | b = (int)*ptr2; | |
5124 | if ((r == im->shape_color.r) && | |
5125 | (g == im->shape_color.g) && | |
5126 | (b == im->shape_color.b)) | |
5127 | { | |
5128 | XPutPixel(sxim, x, y, 0); | |
5129 | ex += 3; | |
5130 | } | |
5131 | else | |
5132 | { | |
5133 | XPutPixel(sxim, x, y, 1); | |
5134 | r = im->rmap[r]; | |
5135 | g = im->gmap[g]; | |
5136 | b = im->bmap[b]; | |
5137 | er = r + er1[ex++]; | |
5138 | eg = g + er1[ex++]; | |
5139 | eb = b + er1[ex++]; | |
5140 | if (er > 255) | |
5141 | er = 255; | |
5142 | else if (er < 0) | |
5143 | er = 0; | |
5144 | if (eg > 255) | |
5145 | eg = 255; | |
5146 | else if (eg < 0) | |
5147 | eg = 0; | |
5148 | if (eb > 255) | |
5149 | eb = 255; | |
5150 | else if (eb < 0) | |
5151 | eb = 0; | |
5152 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
5153 | er = ERROR_RED(er, val); | |
5154 | eg = ERROR_GRN(eg, val); | |
5155 | eb = ERROR_BLU(eb, val); | |
5156 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5157 | XPutPixel(xim, x, y, COLOR_INDEX(val)); | |
5158 | } | |
5159 | } | |
5160 | } | |
5161 | } | |
5162 | break; | |
5163 | default: | |
5164 | if (id->fastrend) | |
5165 | { | |
5166 | switch (bpp) | |
5167 | { | |
5168 | case 8: | |
5169 | break; | |
5170 | case 15: | |
5171 | if (id->render_type == RT_DITHER_TRUECOL) | |
5172 | { | |
5173 | if (id->ordered_dither) | |
5174 | grender_shaped_15_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5175 | else | |
5176 | grender_shaped_15_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5177 | } | |
5178 | else | |
5179 | grender_shaped_15_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5180 | break; | |
5181 | case 16: | |
5182 | if (id->render_type == RT_DITHER_TRUECOL) | |
5183 | { | |
5184 | if (id->ordered_dither) | |
5185 | grender_shaped_16_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5186 | else | |
5187 | grender_shaped_16_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5188 | } | |
5189 | else | |
5190 | grender_shaped_16_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5191 | break; | |
5192 | case 24: | |
5193 | case 32: | |
5194 | if (xim->bits_per_pixel == 24) | |
5195 | grender_shaped_24_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5196 | else | |
5197 | grender_shaped_32_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5198 | break; | |
5199 | default: | |
5200 | break; | |
5201 | } | |
5202 | } | |
5203 | else | |
5204 | { | |
5205 | switch (bpp) | |
5206 | { | |
5207 | case 8: | |
5208 | break; | |
5209 | case 15: | |
5210 | if (id->render_type == RT_DITHER_TRUECOL) | |
5211 | { | |
5212 | if (id->ordered_dither) | |
5213 | grender_shaped_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5214 | grender_shaped_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5215 | } | |
5216 | else | |
5217 | grender_shaped_15_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5218 | break; | |
5219 | case 16: | |
5220 | if (id->render_type == RT_DITHER_TRUECOL) | |
5221 | { | |
5222 | if (id->ordered_dither) | |
5223 | grender_shaped_16_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5224 | else | |
5225 | grender_shaped_16_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5226 | } | |
5227 | else | |
5228 | grender_shaped_16_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5229 | break; | |
5230 | case 24: | |
5231 | grender_shaped_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5232 | case 32: | |
5233 | grender_shaped_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5234 | break; | |
5235 | default: | |
5236 | break; | |
5237 | } | |
5238 | } | |
5239 | break; | |
5240 | } | |
5241 | } | |
5242 | ||
5243 | void | |
5244 | grender_mod(GdkImlibImage * im, int w, int h, XImage * xim, | |
5245 | XImage * sxim, int *er1, int *er2, int *xarray, | |
5246 | unsigned char **yarray, int bpp) | |
5247 | { | |
5248 | int x, y, val, r, g, b, *ter, ex, er, eg, eb; | |
5249 | unsigned char *ptr2; | |
5250 | unsigned char *img; | |
5251 | int jmp; | |
5252 | ||
5253 | jmp = (xim->bytes_per_line) - w; | |
5254 | img = (unsigned char *)xim->data; | |
5255 | switch (id->render_type) | |
5256 | { | |
5257 | case RT_PLAIN_PALETTE: | |
5258 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
5259 | { | |
5260 | for (y = 0; y < h; y++) | |
5261 | { | |
5262 | for (x = 0; x < w; x++) | |
5263 | { | |
5264 | ptr2 = yarray[y] + xarray[x]; | |
5265 | r = (int)*ptr2++; | |
5266 | g = (int)*ptr2++; | |
5267 | b = (int)*ptr2; | |
5268 | r = im->rmap[r]; | |
5269 | g = im->gmap[g]; | |
5270 | b = im->bmap[b]; | |
5271 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
5272 | *img++ = val; | |
5273 | } | |
5274 | img += jmp; | |
5275 | } | |
5276 | } | |
5277 | else | |
5278 | { | |
5279 | for (y = 0; y < h; y++) | |
5280 | { | |
5281 | for (x = 0; x < w; x++) | |
5282 | { | |
5283 | ptr2 = yarray[y] + xarray[x]; | |
5284 | r = (int)*ptr2++; | |
5285 | g = (int)*ptr2++; | |
5286 | b = (int)*ptr2; | |
5287 | r = im->rmap[r]; | |
5288 | g = im->gmap[g]; | |
5289 | b = im->bmap[b]; | |
5290 | val = gdk_imlib_best_color_match(&r, &g, &b); | |
5291 | XPutPixel(xim, x, y, val); | |
5292 | } | |
5293 | } | |
5294 | } | |
5295 | break; | |
5296 | case RT_PLAIN_PALETTE_FAST: | |
5297 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
5298 | { | |
5299 | for (y = 0; y < h; y++) | |
5300 | { | |
5301 | for (x = 0; x < w; x++) | |
5302 | { | |
5303 | ptr2 = yarray[y] + xarray[x]; | |
5304 | r = (int)*ptr2++; | |
5305 | g = (int)*ptr2++; | |
5306 | b = (int)*ptr2; | |
5307 | r = im->rmap[r]; | |
5308 | g = im->gmap[g]; | |
5309 | b = im->bmap[b]; | |
5310 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
5311 | *img++ = val; | |
5312 | } | |
5313 | img += jmp; | |
5314 | } | |
5315 | } | |
5316 | else | |
5317 | { | |
5318 | for (y = 0; y < h; y++) | |
5319 | { | |
5320 | for (x = 0; x < w; x++) | |
5321 | { | |
5322 | ptr2 = yarray[y] + xarray[x]; | |
5323 | r = (int)*ptr2++; | |
5324 | g = (int)*ptr2++; | |
5325 | b = (int)*ptr2; | |
5326 | r = im->rmap[r]; | |
5327 | g = im->gmap[g]; | |
5328 | b = im->bmap[b]; | |
5329 | val = COLOR_RGB(r >> 3, g >> 3, b >> 3); | |
5330 | XPutPixel(xim, x, y, val); | |
5331 | } | |
5332 | } | |
5333 | } | |
5334 | break; | |
5335 | case RT_DITHER_PALETTE: | |
5336 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
5337 | { | |
5338 | for (y = 0; y < h; y++) | |
5339 | { | |
5340 | ter = er1; | |
5341 | er1 = er2; | |
5342 | er2 = ter; | |
5343 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5344 | er2[ex] = 0; | |
5345 | ex = 3; | |
5346 | for (x = 0; x < w; x++) | |
5347 | { | |
5348 | ptr2 = yarray[y] + xarray[x]; | |
5349 | r = (int)*ptr2++; | |
5350 | g = (int)*ptr2++; | |
5351 | b = (int)*ptr2; | |
5352 | r = im->rmap[r]; | |
5353 | g = im->gmap[g]; | |
5354 | b = im->bmap[b]; | |
5355 | er = r + er1[ex++]; | |
5356 | eg = g + er1[ex++]; | |
5357 | eb = b + er1[ex++]; | |
5358 | if (er > 255) | |
5359 | er = 255; | |
5360 | else if (er < 0) | |
5361 | er = 0; | |
5362 | if (eg > 255) | |
5363 | eg = 255; | |
5364 | else if (eg < 0) | |
5365 | eg = 0; | |
5366 | if (eb > 255) | |
5367 | eb = 255; | |
5368 | else if (eb < 0) | |
5369 | eb = 0; | |
5370 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
5371 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5372 | *img++ = val; | |
5373 | } | |
5374 | img += jmp; | |
5375 | } | |
5376 | } | |
5377 | else | |
5378 | { | |
5379 | for (y = 0; y < h; y++) | |
5380 | { | |
5381 | ter = er1; | |
5382 | er1 = er2; | |
5383 | er2 = ter; | |
5384 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5385 | er2[ex] = 0; | |
5386 | ex = 3; | |
5387 | for (x = 0; x < w; x++) | |
5388 | { | |
5389 | ptr2 = yarray[y] + xarray[x]; | |
5390 | r = (int)*ptr2++; | |
5391 | g = (int)*ptr2++; | |
5392 | b = (int)*ptr2; | |
5393 | r = im->rmap[r]; | |
5394 | g = im->gmap[g]; | |
5395 | b = im->bmap[b]; | |
5396 | er = r + er1[ex++]; | |
5397 | eg = g + er1[ex++]; | |
5398 | eb = b + er1[ex++]; | |
5399 | if (er > 255) | |
5400 | er = 255; | |
5401 | else if (er < 0) | |
5402 | er = 0; | |
5403 | if (eg > 255) | |
5404 | eg = 255; | |
5405 | else if (eg < 0) | |
5406 | eg = 0; | |
5407 | if (eb > 255) | |
5408 | eb = 255; | |
5409 | else if (eb < 0) | |
5410 | eb = 0; | |
5411 | val = gdk_imlib_best_color_match(&er, &eg, &eb); | |
5412 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5413 | XPutPixel(xim, x, y, val); | |
5414 | } | |
5415 | } | |
5416 | } | |
5417 | break; | |
5418 | case RT_DITHER_PALETTE_FAST: | |
5419 | if ((id->fastrend) && (xim->bits_per_pixel == 8)) | |
5420 | { | |
5421 | for (y = 0; y < h; y++) | |
5422 | { | |
5423 | ter = er1; | |
5424 | er1 = er2; | |
5425 | er2 = ter; | |
5426 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5427 | er2[ex] = 0; | |
5428 | ex = 3; | |
5429 | for (x = 0; x < w; x++) | |
5430 | { | |
5431 | ptr2 = yarray[y] + xarray[x]; | |
5432 | r = (int)*ptr2++; | |
5433 | g = (int)*ptr2++; | |
5434 | b = (int)*ptr2; | |
5435 | r = im->rmap[r]; | |
5436 | g = im->gmap[g]; | |
5437 | b = im->bmap[b]; | |
5438 | er = r + er1[ex++]; | |
5439 | eg = g + er1[ex++]; | |
5440 | eb = b + er1[ex++]; | |
5441 | if (er > 255) | |
5442 | er = 255; | |
5443 | else if (er < 0) | |
5444 | er = 0; | |
5445 | if (eg > 255) | |
5446 | eg = 255; | |
5447 | else if (eg < 0) | |
5448 | eg = 0; | |
5449 | if (eb > 255) | |
5450 | eb = 255; | |
5451 | else if (eb < 0) | |
5452 | eb = 0; | |
5453 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
5454 | er = ERROR_RED(er, val); | |
5455 | eg = ERROR_GRN(eg, val); | |
5456 | eb = ERROR_BLU(eb, val); | |
5457 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5458 | *img++ = COLOR_INDEX(val); | |
5459 | } | |
5460 | img += jmp; | |
5461 | } | |
5462 | } | |
5463 | else | |
5464 | { | |
5465 | for (y = 0; y < h; y++) | |
5466 | { | |
5467 | ter = er1; | |
5468 | er1 = er2; | |
5469 | er2 = ter; | |
5470 | for (ex = 0; ex < (w + 2) * 3; ex++) | |
5471 | er2[ex] = 0; | |
5472 | ex = 3; | |
5473 | for (x = 0; x < w; x++) | |
5474 | { | |
5475 | ptr2 = yarray[y] + xarray[x]; | |
5476 | r = (int)*ptr2++; | |
5477 | g = (int)*ptr2++; | |
5478 | b = (int)*ptr2; | |
5479 | r = im->rmap[r]; | |
5480 | g = im->gmap[g]; | |
5481 | b = im->bmap[b]; | |
5482 | er = r + er1[ex++]; | |
5483 | eg = g + er1[ex++]; | |
5484 | eb = b + er1[ex++]; | |
5485 | if (er > 255) | |
5486 | er = 255; | |
5487 | else if (er < 0) | |
5488 | er = 0; | |
5489 | if (eg > 255) | |
5490 | eg = 255; | |
5491 | else if (eg < 0) | |
5492 | eg = 0; | |
5493 | if (eb > 255) | |
5494 | eb = 255; | |
5495 | else if (eb < 0) | |
5496 | eb = 0; | |
5497 | val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); | |
5498 | er = ERROR_RED(er, val); | |
5499 | eg = ERROR_GRN(eg, val); | |
5500 | eb = ERROR_BLU(eb, val); | |
5501 | DITHER_ERROR(er1, er2, ex, er, eg, eb); | |
5502 | XPutPixel(xim, x, y, COLOR_INDEX(val)); | |
5503 | } | |
5504 | } | |
5505 | } | |
5506 | break; | |
5507 | default: | |
5508 | if (id->fastrend) | |
5509 | { | |
5510 | switch (bpp) | |
5511 | { | |
5512 | case 8: | |
5513 | break; | |
5514 | case 15: | |
5515 | if (id->render_type == RT_DITHER_TRUECOL) | |
5516 | { | |
5517 | if (id->ordered_dither) | |
5518 | grender_15_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5519 | else | |
5520 | grender_15_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5521 | } | |
5522 | else | |
5523 | grender_15_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5524 | break; | |
5525 | case 16: | |
5526 | if (id->render_type == RT_DITHER_TRUECOL) | |
5527 | { | |
5528 | if (id->ordered_dither) | |
5529 | grender_16_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5530 | else | |
5531 | grender_16_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5532 | } | |
5533 | else | |
5534 | grender_16_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5535 | break; | |
5536 | case 24: | |
5537 | case 32: | |
5538 | if (xim->bits_per_pixel == 24) | |
5539 | grender_24_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5540 | else | |
5541 | grender_32_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5542 | break; | |
5543 | default: | |
5544 | break; | |
5545 | } | |
5546 | } | |
5547 | else | |
5548 | { | |
5549 | switch (bpp) | |
5550 | { | |
5551 | case 8: | |
5552 | break; | |
5553 | case 15: | |
5554 | if (id->render_type == RT_DITHER_TRUECOL) | |
5555 | { | |
5556 | if (id->ordered_dither) | |
5557 | grender_15_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5558 | else | |
5559 | grender_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5560 | } | |
5561 | else | |
5562 | grender_15_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5563 | break; | |
5564 | case 16: | |
5565 | if (id->render_type == RT_DITHER_TRUECOL) | |
5566 | { | |
5567 | if (id->ordered_dither) | |
5568 | grender_16_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5569 | else | |
5570 | grender_16_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5571 | } | |
5572 | else | |
5573 | grender_16_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5574 | break; | |
5575 | case 24: | |
5576 | grender_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5577 | break; | |
5578 | case 32: | |
5579 | grender_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); | |
5580 | break; | |
5581 | default: | |
5582 | break; | |
5583 | } | |
5584 | break; | |
5585 | } | |
5586 | } | |
5587 | } | |
5588 | ||
5589 | gint | |
5590 | gdk_imlib_render(GdkImlibImage * im, gint w, gint h) | |
5591 | { | |
5592 | XImage *xim, *sxim; | |
5593 | GC tgc, stgc; | |
5594 | XGCValues gcv; | |
5595 | unsigned char *tmp, *stmp, **yarray, *ptr22; | |
5596 | int w3, x, inc, pos, *error, *er1, *er2, *xarray, ex, | |
5597 | bpp, huge; | |
5598 | Pixmap pmap, mask; | |
5599 | GdkPixmap *pm, *mm; | |
5600 | int shared_pixmap, shared_image, ok; | |
5601 | ||
5602 | sxim = NULL; | |
5603 | xim = NULL; | |
5604 | tmp = NULL; | |
5605 | stmp = NULL; | |
5606 | pmap = 0; | |
5607 | mask = 0; | |
5608 | tgc = 0; | |
5609 | stgc = 0; | |
5610 | inc = 0; | |
5611 | if (!im) | |
5612 | return 0; | |
5613 | if (w <= 0) | |
5614 | return 0; | |
5615 | if (h <= 0) | |
5616 | return 0; | |
5617 | gcv.graphics_exposures = False; | |
5618 | ||
5619 | /* look for the pixmap in cache first */ | |
5620 | if (id->cache.on_pixmap) | |
5621 | { | |
5622 | pmap = 0; | |
5623 | gfind_pixmap(im, w, h, &pm, &mm); | |
5624 | if (pm) | |
5625 | { | |
5626 | im->width = w; | |
5627 | im->height = h; | |
5628 | im->pixmap = pm; | |
5629 | if (mm) | |
5630 | im->shape_mask = mm; | |
5631 | else | |
5632 | im->shape_mask = NULL; | |
5633 | return 1; | |
5634 | } | |
5635 | } | |
5636 | ||
5637 | if (im->pixmap) | |
5638 | gfree_pixmappmap(im->pixmap); | |
5639 | im->pixmap = NULL; | |
5640 | im->shape_mask = NULL; | |
5641 | /* setup stuff */ | |
5642 | huge = 0; | |
5643 | if (id->x.depth <= 8) | |
5644 | bpp = 1; | |
5645 | else if (id->x.depth <= 16) | |
5646 | bpp = 2; | |
5647 | else | |
5648 | bpp = 4; | |
5649 | if ((id->max_shm) && ((bpp * w * h) > id->max_shm)) | |
5650 | huge = 1; | |
5651 | im->width = w; | |
5652 | im->height = h; | |
5653 | ||
5654 | /* dithering array */ | |
5655 | error = (int *)malloc(sizeof(int) * (w + 2) * 2 * 3); | |
5656 | ||
5657 | if (!error) | |
5658 | { | |
5659 | fprintf(stderr, "ERROR: Cannot allocate RAM for image dither buffer\n"); | |
5660 | return 0; | |
5661 | } | |
5662 | ||
5663 | /* setup pointers to point right */ | |
5664 | er1 = error; | |
5665 | er2 = error + ((w + 2) * 3); | |
5666 | w3 = im->rgb_width * 3; | |
5667 | ptr22 = im->rgb_data; | |
5668 | ||
5669 | /* setup coord-mapping array (specially for border scaling) */ | |
5670 | xarray = malloc(sizeof(int) * w); | |
5671 | ||
5672 | if (!xarray) | |
5673 | { | |
5674 | fprintf(stderr, "ERROR: Cannot allocate X co-ord buffer\n"); | |
5675 | free(error); | |
5676 | return 0; | |
5677 | } | |
5678 | yarray = malloc(sizeof(unsigned char *) * h); | |
5679 | ||
5680 | if (!yarray) | |
5681 | { | |
5682 | fprintf(stderr, "ERROR: Cannot allocate Y co-ord buffer\n"); | |
5683 | free(xarray); | |
5684 | free(error); | |
5685 | return 0; | |
5686 | } | |
5687 | for (ex = 0; ex < ((w + 2) * 3 * 2); ex++) | |
5688 | error[ex] = 0; | |
5689 | { | |
5690 | int l, r, m; | |
5691 | ||
5692 | if (w < im->border.left + im->border.right) | |
5693 | { | |
5694 | l = w >> 1; | |
5695 | r = w - l; | |
5696 | m = 0; | |
5697 | } | |
5698 | else | |
5699 | { | |
5700 | l = im->border.left; | |
5701 | r = im->border.right; | |
5702 | m = w - l - r; | |
5703 | } | |
5704 | if (m > 0) | |
5705 | inc = ((im->rgb_width - im->border.left - im->border.right) << 16) / m; | |
5706 | pos = 0; | |
5707 | if (l) | |
5708 | for (x = 0; x < l; x++) | |
5709 | { | |
5710 | xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); | |
5711 | pos += 0x10000; | |
5712 | } | |
5713 | if (m) | |
5714 | { | |
5715 | for (x = l; x < l + m; x++) | |
5716 | { | |
5717 | xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); | |
5718 | pos += inc; | |
5719 | } | |
5720 | } | |
5721 | pos = (im->rgb_width - r) << 16; | |
5722 | for (x = w - r; x < w; x++) | |
5723 | { | |
5724 | xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); | |
5725 | pos += 0x10000; | |
5726 | } | |
5727 | ||
5728 | if (h < im->border.top + im->border.bottom) | |
5729 | { | |
5730 | l = h >> 1; | |
5731 | r = h - l; | |
5732 | m = 0; | |
5733 | } | |
5734 | else | |
5735 | { | |
5736 | l = im->border.top; | |
5737 | r = im->border.bottom; | |
5738 | m = h - l - r; | |
5739 | } | |
5740 | if (m > 0) | |
5741 | inc = ((im->rgb_height - im->border.top - im->border.bottom) << 16) / m; | |
5742 | pos = 0; | |
5743 | for (x = 0; x < l; x++) | |
5744 | { | |
5745 | yarray[x] = ptr22 + ((pos >> 16) * w3); | |
5746 | pos += 0x10000; | |
5747 | } | |
5748 | if (m) | |
5749 | { | |
5750 | for (x = l; x < l + m; x++) | |
5751 | { | |
5752 | yarray[x] = ptr22 + ((pos >> 16) * w3); | |
5753 | pos += inc; | |
5754 | } | |
5755 | } | |
5756 | pos = (im->rgb_height - r) << 16; | |
5757 | for (x = h - r; x < h; x++) | |
5758 | { | |
5759 | yarray[x] = ptr22 + ((pos >> 16) * w3); | |
5760 | pos += 0x10000; | |
5761 | } | |
5762 | } | |
5763 | ||
5764 | /* work out if we should use shared pixmap. images etc */ | |
5765 | shared_pixmap = 0; | |
5766 | shared_image = 0; | |
5767 | if ((id->x.shmp) && (id->x.shm) && (!huge)) | |
5768 | { | |
5769 | shared_pixmap = 1; | |
5770 | shared_image = 0; | |
5771 | } | |
5772 | else if ((id->x.shm) && (!huge)) | |
5773 | { | |
5774 | shared_pixmap = 0; | |
5775 | shared_image = 1; | |
5776 | } | |
5777 | else | |
5778 | shared_pixmap = 0; | |
5779 | shared_image = 0; | |
5780 | ||
5781 | /* init images and pixmaps */ | |
5782 | ok = 1; | |
5783 | if (shared_pixmap) | |
5784 | { | |
5785 | xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, NULL, &id->x.last_shminfo, w, h); | |
5786 | if (!xim) | |
5787 | { | |
5788 | fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create XImage for Shared Pixmap Wrapper\n"); | |
5789 | fprintf(stderr, " Falling back on Shared XImages\n"); | |
5790 | shared_pixmap = 0; | |
5791 | shared_image = 1; | |
5792 | ok = 0; | |
5793 | } | |
5794 | if (ok) | |
5795 | { | |
5796 | id->x.last_shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, IPC_CREAT | 0777); | |
5797 | if (id->x.last_shminfo.shmid == -1) | |
5798 | { | |
5799 | fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared Pixmap Wrapper\n"); | |
5800 | fprintf(stderr, " Falling back on Shared XImages\n"); | |
5801 | XDestroyImage(xim); | |
5802 | shared_pixmap = 0; | |
5803 | shared_image = 1; | |
5804 | ok = 1; | |
5805 | } | |
5806 | if (ok) | |
5807 | { | |
5808 | id->x.last_shminfo.shmaddr = xim->data = shmat(id->x.last_shminfo.shmid, 0, 0); | |
5809 | id->x.last_shminfo.readOnly = False; | |
5810 | XShmAttach(id->x.disp, &id->x.last_shminfo); | |
5811 | tmp = (unsigned char *)xim->data; | |
5812 | id->x.last_xim = xim; | |
5813 | pmap = XShmCreatePixmap(id->x.disp, id->x.base_window, | |
5814 | id->x.last_shminfo.shmaddr, | |
5815 | &id->x.last_shminfo, w, h, id->x.depth); | |
5816 | tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); | |
5817 | if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) | |
5818 | { | |
5819 | sxim = XShmCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, NULL, &id->x.last_sshminfo, w, h); | |
5820 | if (!sxim) | |
5821 | { | |
5822 | fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create XImage for Shared Pixmap mask Wrapper\n"); | |
5823 | fprintf(stderr, " Falling back on Shared XImages\n"); | |
5824 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
5825 | XDestroyImage(xim); | |
5826 | shmdt(id->x.last_shminfo.shmaddr); | |
5827 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
5828 | shared_pixmap = 0; | |
5829 | shared_image = 1; | |
5830 | ok = 0; | |
5831 | } | |
5832 | if (ok) | |
5833 | { | |
5834 | id->x.last_sshminfo.shmid = shmget(IPC_PRIVATE, sxim->bytes_per_line * sxim->height, IPC_CREAT | 0777); | |
5835 | if (id->x.last_sshminfo.shmid == -1) | |
5836 | { | |
5837 | fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared Pixmap mask Wrapper\n"); | |
5838 | fprintf(stderr, " Falling back on Shared XImages\n"); | |
5839 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
5840 | XDestroyImage(xim); | |
5841 | shmdt(id->x.last_shminfo.shmaddr); | |
5842 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
5843 | XDestroyImage(sxim); | |
5844 | shared_pixmap = 0; | |
5845 | shared_image = 1; | |
5846 | ok = 0; | |
5847 | } | |
5848 | id->x.last_sshminfo.shmaddr = sxim->data = shmat(id->x.last_sshminfo.shmid, 0, 0); | |
5849 | id->x.last_sshminfo.readOnly = False; | |
5850 | XShmAttach(id->x.disp, &id->x.last_sshminfo); | |
5851 | stmp = (unsigned char *)sxim->data; | |
5852 | id->x.last_sxim = sxim; | |
5853 | mask = XShmCreatePixmap(id->x.disp, id->x.base_window, | |
5854 | id->x.last_sshminfo.shmaddr, | |
5855 | &id->x.last_sshminfo, w, h, 1); | |
5856 | stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); | |
5857 | } | |
5858 | } | |
5859 | } | |
5860 | } | |
5861 | } | |
5862 | ok = 1; | |
5863 | if (shared_image) | |
5864 | { | |
5865 | xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, NULL, &id->x.last_shminfo, w, h); | |
5866 | if (!xim) | |
5867 | { | |
5868 | fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create Shared XImage\n"); | |
5869 | fprintf(stderr, " Falling back on XImages\n"); | |
5870 | shared_pixmap = 0; | |
5871 | shared_image = 0; | |
5872 | ok = 0; | |
5873 | } | |
5874 | if (ok) | |
5875 | { | |
5876 | id->x.last_shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, IPC_CREAT | 0777); | |
5877 | if (id->x.last_shminfo.shmid == -1) | |
5878 | { | |
5879 | fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared XImage\n"); | |
5880 | fprintf(stderr, " Falling back on XImages\n"); | |
5881 | XDestroyImage(xim); | |
5882 | shared_pixmap = 0; | |
5883 | shared_image = 0; | |
5884 | ok = 0; | |
5885 | } | |
5886 | if (ok) | |
5887 | { | |
5888 | id->x.last_shminfo.shmaddr = xim->data = shmat(id->x.last_shminfo.shmid, 0, 0); | |
5889 | id->x.last_shminfo.readOnly = False; | |
5890 | XShmAttach(id->x.disp, &id->x.last_shminfo); | |
5891 | tmp = (unsigned char *)xim->data; | |
5892 | id->x.last_xim = xim; | |
5893 | pmap = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); | |
5894 | tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); | |
5895 | if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) | |
5896 | { | |
5897 | sxim = XShmCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, NULL, &id->x.last_sshminfo, w, h); | |
5898 | if (!sxim) | |
5899 | { | |
5900 | fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create Shared XImage mask\n"); | |
5901 | fprintf(stderr, " Falling back on XImages\n"); | |
5902 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
5903 | XDestroyImage(xim); | |
5904 | shmdt(id->x.last_shminfo.shmaddr); | |
5905 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
5906 | shared_pixmap = 0; | |
5907 | shared_image = 0; | |
5908 | ok = 0; | |
5909 | } | |
5910 | if (ok) | |
5911 | { | |
5912 | id->x.last_sshminfo.shmid = shmget(IPC_PRIVATE, sxim->bytes_per_line * sxim->height, IPC_CREAT | 0777); | |
5913 | if (id->x.last_sshminfo.shmid == -1) | |
5914 | { | |
5915 | fprintf(stderr, "Imlib ERROR: SHM can't get SHM Identifierfor Shared XImage mask\n"); | |
5916 | fprintf(stderr, " Falling back on XImages\n"); | |
5917 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
5918 | XDestroyImage(xim); | |
5919 | shmdt(id->x.last_shminfo.shmaddr); | |
5920 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
5921 | XDestroyImage(sxim); | |
5922 | shared_pixmap = 0; | |
5923 | shared_image = 0; | |
5924 | ok = 0; | |
5925 | } | |
5926 | if (ok) | |
5927 | { | |
5928 | id->x.last_sshminfo.shmaddr = sxim->data = shmat(id->x.last_sshminfo.shmid, 0, 0); | |
5929 | id->x.last_sshminfo.readOnly = False; | |
5930 | XShmAttach(id->x.disp, &id->x.last_sshminfo); | |
5931 | stmp = (unsigned char *)sxim->data; | |
5932 | id->x.last_sxim = sxim; | |
5933 | mask = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); | |
5934 | stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); | |
5935 | } | |
5936 | } | |
5937 | } | |
5938 | } | |
5939 | } | |
5940 | } | |
5941 | ok = 1; | |
5942 | if ((!shared_pixmap) && (!shared_image)) | |
5943 | { | |
5944 | tmp = (unsigned char *)malloc(w * h * bpp); | |
5945 | if (!tmp) | |
5946 | { | |
5947 | fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for XImage data\n"); | |
5948 | free(xarray); | |
5949 | free(yarray); | |
5950 | free(error); | |
5951 | return 0; | |
5952 | } | |
5953 | xim = XCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, 0, (char *)tmp, w, h, 8, 0); | |
5954 | if (!xim) | |
5955 | { | |
5956 | fprintf(stderr, "IMLIB ERROR: Cannot allocate XImage buffer\n"); | |
5957 | free(xarray); | |
5958 | free(yarray); | |
5959 | free(error); | |
5960 | free(tmp); | |
5961 | return 0; | |
5962 | } | |
5963 | pmap = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); | |
5964 | if (!pmap) | |
5965 | { | |
5966 | fprintf(stderr, "IMLIB ERROR: Cannot create pixmap\n"); | |
5967 | free(xarray); | |
5968 | free(yarray); | |
5969 | free(error); | |
5970 | XDestroyImage(xim); | |
5971 | return 0; | |
5972 | } | |
5973 | tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); | |
5974 | if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) | |
5975 | { | |
5976 | stmp = (unsigned char *)malloc(((w >> 3) + 8) * h); | |
5977 | if (!stmp) | |
5978 | { | |
5979 | fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for shape XImage data\n"); | |
5980 | free(xarray); | |
5981 | free(yarray); | |
5982 | free(error); | |
5983 | XDestroyImage(xim); | |
5984 | return 0; | |
5985 | } | |
5986 | sxim = XCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, 0, (char *)stmp, w, h, 8, 0); | |
5987 | if (!sxim) | |
5988 | { | |
5989 | fprintf(stderr, "IMLIB ERROR: Cannot allocate XImage shape buffer\n"); | |
5990 | free(xarray); | |
5991 | free(yarray); | |
5992 | free(error); | |
5993 | free(stmp); | |
5994 | XDestroyImage(xim); | |
5995 | return 0; | |
5996 | } | |
5997 | mask = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); | |
5998 | if (!mask) | |
5999 | { | |
6000 | fprintf(stderr, "IMLIB ERROR: Cannot create shape pixmap\n"); | |
6001 | free(xarray); | |
6002 | free(yarray); | |
6003 | free(error); | |
6004 | XDestroyImage(sxim); | |
6005 | XDestroyImage(xim); | |
6006 | return 0; | |
6007 | } | |
6008 | stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); | |
6009 | } | |
6010 | } | |
6011 | ||
6012 | /* copy XImage to the pixmap, if not a shared pixmap */ | |
6013 | if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) | |
6014 | { | |
6015 | if ((im->mod.gamma == 256) && (im->mod.brightness == 256) && (im->mod.contrast == 256) && | |
6016 | (im->rmod.gamma == 256) && (im->rmod.brightness == 256) && (im->rmod.contrast == 256) && | |
6017 | (im->gmod.gamma == 256) && (im->gmod.brightness == 256) && (im->gmod.contrast == 256) && | |
6018 | (im->bmod.gamma == 256) && (im->bmod.brightness == 256) && (im->bmod.contrast == 256)) | |
6019 | { | |
6020 | if (id->x.depth <= 8) | |
6021 | grender_shaped(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); | |
6022 | else | |
6023 | grender_shaped(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); | |
6024 | } | |
6025 | else | |
6026 | { | |
6027 | if (id->x.depth <= 8) | |
6028 | grender_shaped_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); | |
6029 | else | |
6030 | grender_shaped_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); | |
6031 | } | |
6032 | if (shared_image) | |
6033 | { | |
6034 | XShmPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h, False); | |
6035 | XShmPutImage(id->x.disp, mask, stgc, sxim, 0, 0, 0, 0, w, h, False); | |
6036 | XSync(id->x.disp, False); | |
6037 | im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); | |
6038 | im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, mask); | |
6039 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
6040 | XDestroyImage(xim); | |
6041 | shmdt(id->x.last_shminfo.shmaddr); | |
6042 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
6043 | XShmDetach(id->x.disp, &id->x.last_sshminfo); | |
6044 | XDestroyImage(sxim); | |
6045 | shmdt(id->x.last_sshminfo.shmaddr); | |
6046 | shmctl(id->x.last_sshminfo.shmid, IPC_RMID, 0); | |
6047 | id->x.last_xim = NULL; | |
6048 | id->x.last_sxim = NULL; | |
6049 | xim = NULL; | |
6050 | sxim = NULL; | |
6051 | XFreeGC(id->x.disp, tgc); | |
6052 | XFreeGC(id->x.disp, stgc); | |
6053 | } | |
6054 | else if (shared_pixmap) | |
6055 | { | |
6056 | Pixmap p2, m2; | |
6057 | ||
6058 | p2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); | |
6059 | m2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); | |
6060 | XCopyArea(id->x.disp, pmap, p2, tgc, 0, 0, w, h, 0, 0); | |
6061 | XCopyArea(id->x.disp, mask, m2, stgc, 0, 0, w, h, 0, 0); | |
6062 | im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, p2); | |
6063 | im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, m2); | |
6064 | XFreeGC(id->x.disp, tgc); | |
6065 | XFreeGC(id->x.disp, stgc); | |
6066 | XFreePixmap(id->x.disp, pmap); | |
6067 | XFreePixmap(id->x.disp, mask); | |
6068 | XSync(id->x.disp, False); | |
6069 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
6070 | XDestroyImage(xim); | |
6071 | shmdt(id->x.last_shminfo.shmaddr); | |
6072 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
6073 | XShmDetach(id->x.disp, &id->x.last_sshminfo); | |
6074 | XDestroyImage(sxim); | |
6075 | shmdt(id->x.last_sshminfo.shmaddr); | |
6076 | shmctl(id->x.last_sshminfo.shmid, IPC_RMID, 0); | |
6077 | id->x.last_xim = NULL; | |
6078 | id->x.last_sxim = NULL; | |
6079 | xim = NULL; | |
6080 | sxim = NULL; | |
6081 | } | |
6082 | else | |
6083 | { | |
6084 | XPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h); | |
6085 | XPutImage(id->x.disp, mask, stgc, sxim, 0, 0, 0, 0, w, h); | |
6086 | im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); | |
6087 | im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, mask); | |
6088 | XDestroyImage(xim); | |
6089 | XDestroyImage(sxim); | |
6090 | xim = NULL; | |
6091 | sxim = NULL; | |
6092 | XFreeGC(id->x.disp, tgc); | |
6093 | XFreeGC(id->x.disp, stgc); | |
6094 | } | |
6095 | } | |
6096 | else | |
6097 | { | |
6098 | if ((im->mod.gamma == 256) && (im->mod.brightness == 256) && (im->mod.contrast == 256) && | |
6099 | (im->rmod.gamma == 256) && (im->rmod.brightness == 256) && (im->rmod.contrast == 256) && | |
6100 | (im->gmod.gamma == 256) && (im->gmod.brightness == 256) && (im->gmod.contrast == 256) && | |
6101 | (im->bmod.gamma == 256) && (im->bmod.brightness == 256) && (im->bmod.contrast == 256)) | |
6102 | { | |
6103 | if (id->x.depth <= 8) | |
6104 | grender(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); | |
6105 | else | |
6106 | grender(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); | |
6107 | } | |
6108 | else | |
6109 | { | |
6110 | if (id->x.depth <= 8) | |
6111 | grender_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); | |
6112 | else | |
6113 | grender_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); | |
6114 | } | |
6115 | if (shared_image) | |
6116 | { | |
6117 | XShmPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h, False); | |
6118 | im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); | |
6119 | im->shape_mask = NULL; | |
6120 | XSync(id->x.disp, False); | |
6121 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
6122 | XDestroyImage(xim); | |
6123 | shmdt(id->x.last_shminfo.shmaddr); | |
6124 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
6125 | id->x.last_xim = NULL; | |
6126 | xim = NULL; | |
6127 | sxim = NULL; | |
6128 | XFreeGC(id->x.disp, tgc); | |
6129 | } | |
6130 | else if (shared_pixmap) | |
6131 | { | |
6132 | Pixmap p2; | |
6133 | ||
6134 | p2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); | |
6135 | XCopyArea(id->x.disp, pmap, p2, tgc, 0, 0, w, h, 0, 0); | |
6136 | im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, p2); | |
6137 | im->shape_mask = NULL; | |
6138 | XFreeGC(id->x.disp, tgc); | |
6139 | XFreePixmap(id->x.disp, pmap); | |
6140 | XSync(id->x.disp, False); | |
6141 | XShmDetach(id->x.disp, &id->x.last_shminfo); | |
6142 | XDestroyImage(xim); | |
6143 | shmdt(id->x.last_shminfo.shmaddr); | |
6144 | shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); | |
6145 | id->x.last_xim = NULL; | |
6146 | xim = NULL; | |
6147 | sxim = NULL; | |
6148 | } | |
6149 | else | |
6150 | { | |
6151 | XPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h); | |
6152 | im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); | |
6153 | im->shape_mask = NULL; | |
6154 | XDestroyImage(xim); | |
6155 | xim = NULL; | |
6156 | sxim = NULL; | |
6157 | XFreeGC(id->x.disp, tgc); | |
6158 | } | |
6159 | } | |
6160 | ||
6161 | /* cleanup */ | |
6162 | XSync(id->x.disp, False); | |
6163 | free(error); | |
6164 | free(xarray); | |
6165 | free(yarray); | |
6166 | ||
6167 | /* add this pixmap to the cache */ | |
6168 | gadd_pixmap(im, w, h, xim, sxim); | |
6169 | return 1; | |
6170 | } |