]>
git.saurik.com Git - wxWidgets.git/blob - src/gdk_imlib/utils.c
3 #include "../gdk_imlib/gdk_imlib.h"
4 #include "../gdk_imlib/gdk_imlib_private.h"
7 gcalc_map_tables(GdkImlibImage
* im
)
10 double g
, b
, c
, ii
, v
;
15 g
= ((double)im
->mod
.gamma
) / 256;
16 b
= ((double)im
->mod
.brightness
) / 256;
17 c
= ((double)im
->mod
.contrast
) / 256;
21 for (i
= 0; i
< 256; i
++)
23 ii
= ((double)i
) / 256;
24 v
= ((ii
- 0.5) * c
) + 0.5 + (b
- 1);
26 v
= pow(((ii
- 0.5) * c
) + 0.5 + (b
- 1), 1 / g
) * 256;
33 im
->rmap
[i
] = (unsigned char)v
;
34 im
->gmap
[i
] = (unsigned char)v
;
35 im
->bmap
[i
] = (unsigned char)v
;
37 g
= ((double)im
->rmod
.gamma
) / 256;
38 b
= ((double)im
->rmod
.brightness
) / 256;
39 c
= ((double)im
->rmod
.contrast
) / 256;
43 for (i
= 0; i
< 256; i
++)
45 ii
= ((double)im
->rmap
[i
]) / 256;
46 v
= ((ii
- 0.5) * c
) + 0.5 + (b
- 1);
48 v
= pow(((ii
- 0.5) * c
) + 0.5 + (b
- 1), 1 / g
) * 256;
55 im
->rmap
[i
] = (unsigned char)v
;
57 g
= ((double)im
->gmod
.gamma
) / 256;
58 b
= ((double)im
->gmod
.brightness
) / 256;
59 c
= ((double)im
->gmod
.contrast
) / 256;
63 for (i
= 0; i
< 256; i
++)
65 ii
= ((double)im
->gmap
[i
]) / 256;
66 v
= ((ii
- 0.5) * c
) + 0.5 + (b
- 1);
68 v
= pow(((ii
- 0.5) * c
) + 0.5 + (b
- 1), 1 / g
) * 256;
75 im
->gmap
[i
] = (unsigned char)v
;
77 g
= ((double)im
->bmod
.gamma
) / 256;
78 b
= ((double)im
->bmod
.brightness
) / 256;
79 c
= ((double)im
->bmod
.contrast
) / 256;
82 for (i
= 0; i
< 256; i
++)
84 ii
= ((double)im
->bmap
[i
]) / 256;
85 v
= ((ii
- 0.5) * c
) + 0.5 + (b
- 1);
87 v
= pow(((ii
- 0.5) * c
) + 0.5 + (b
- 1), 1 / g
) * 256;
94 im
->bmap
[i
] = (unsigned char)v
;
100 gdk_imlib_load_file_to_pixmap(char *filename
, GdkPixmap
** pmap
, GdkBitmap
** mask
)
104 im
= gdk_imlib_load_image(filename
);
113 if (!gdk_imlib_render(im
, im
->rgb_width
, im
->rgb_height
))
115 gdk_imlib_destroy_image(im
);
123 *pmap
= gdk_imlib_move_image(im
);
125 *mask
= gdk_imlib_move_mask(im
);
126 gdk_imlib_destroy_image(im
);
131 gdk_imlib_set_image_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
135 im
->mod
.gamma
= mod
->gamma
;
136 im
->mod
.brightness
= mod
->brightness
;
137 im
->mod
.contrast
= mod
->contrast
;
138 gcalc_map_tables(im
);
142 gdk_imlib_set_image_red_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
146 im
->rmod
.gamma
= mod
->gamma
;
147 im
->rmod
.brightness
= mod
->brightness
;
148 im
->rmod
.contrast
= mod
->contrast
;
149 gcalc_map_tables(im
);
153 gdk_imlib_set_image_green_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
157 im
->gmod
.gamma
= mod
->gamma
;
158 im
->gmod
.brightness
= mod
->brightness
;
159 im
->gmod
.contrast
= mod
->contrast
;
160 gcalc_map_tables(im
);
164 gdk_imlib_set_image_blue_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
168 im
->bmod
.gamma
= mod
->gamma
;
169 im
->bmod
.brightness
= mod
->brightness
;
170 im
->bmod
.contrast
= mod
->contrast
;
171 gcalc_map_tables(im
);
175 gdk_imlib_get_image_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
179 mod
->gamma
= im
->mod
.gamma
;
180 mod
->brightness
= im
->mod
.brightness
;
181 mod
->contrast
= im
->mod
.contrast
;
182 gcalc_map_tables(im
);
186 gdk_imlib_get_image_red_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
190 mod
->gamma
= im
->rmod
.gamma
;
191 mod
->brightness
= im
->rmod
.brightness
;
192 mod
->contrast
= im
->rmod
.contrast
;
196 gdk_imlib_get_image_green_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
200 mod
->gamma
= im
->gmod
.gamma
;
201 mod
->brightness
= im
->gmod
.brightness
;
202 mod
->contrast
= im
->gmod
.contrast
;
206 gdk_imlib_get_image_blue_modifier(GdkImlibImage
* im
, GdkImlibColorModifier
* mod
)
210 mod
->gamma
= im
->bmod
.gamma
;
211 mod
->brightness
= im
->bmod
.brightness
;
212 mod
->contrast
= im
->bmod
.contrast
;
216 gdk_imlib_set_image_red_curve(GdkImlibImage
* im
, unsigned char *mod
)
222 for (i
= 0; i
< 256; i
++)
223 im
->rmap
[i
] = mod
[i
];
225 im
->mod
.contrast
= 257;
229 gdk_imlib_set_image_green_curve(GdkImlibImage
* im
, unsigned char *mod
)
235 for (i
= 0; i
< 256; i
++)
236 im
->gmap
[i
] = mod
[i
];
238 im
->mod
.contrast
= 257;
242 gdk_imlib_set_image_blue_curve(GdkImlibImage
* im
, unsigned char *mod
)
248 for (i
= 0; i
< 256; i
++)
249 im
->bmap
[i
] = mod
[i
];
251 im
->mod
.contrast
= 257;
255 gdk_imlib_get_image_red_curve(GdkImlibImage
* im
, unsigned char *mod
)
261 for (i
= 0; i
< 256; i
++)
262 mod
[i
] = im
->rmap
[i
];
266 gdk_imlib_get_image_green_curve(GdkImlibImage
* im
, unsigned char *mod
)
272 for (i
= 0; i
< 256; i
++)
273 mod
[i
] = im
->gmap
[i
];
277 gdk_imlib_get_image_blue_curve(GdkImlibImage
* im
, unsigned char *mod
)
283 for (i
= 0; i
< 256; i
++)
284 mod
[i
] = im
->bmap
[i
];
288 gdk_imlib_apply_modifiers_to_rgb(GdkImlibImage
* im
)
296 for (y
= 0; y
< im
->rgb_height
; y
++)
298 for (x
= 0; x
< im
->rgb_width
; x
++)
300 *ptr
= im
->rmap
[*ptr
];
302 *ptr
= im
->gmap
[*ptr
];
304 *ptr
= im
->bmap
[*ptr
];
309 im
->mod
.brightness
= 256;
310 im
->mod
.contrast
= 256;
311 im
->rmod
.gamma
= 256;
312 im
->rmod
.brightness
= 256;
313 im
->rmod
.contrast
= 256;
314 im
->gmod
.gamma
= 256;
315 im
->gmod
.brightness
= 256;
316 im
->gmod
.contrast
= 256;
317 im
->bmod
.gamma
= 256;
318 im
->bmod
.brightness
= 256;
319 im
->bmod
.contrast
= 256;
320 gcalc_map_tables(im
);
326 gdk_imlib_crop_image(GdkImlibImage
* im
, gint x
, gint y
, gint w
, gint h
)
330 unsigned char *ptr1
, *ptr2
;
344 if (x
>= im
->rgb_width
)
346 if (y
>= im
->rgb_height
)
352 if (x
+ w
> im
->rgb_width
)
353 w
= im
->rgb_width
- x
;
354 if (y
+ h
> im
->rgb_height
)
355 h
= im
->rgb_height
- y
;
361 w3
= im
->rgb_width
* 3;
362 w4
= (im
->rgb_width
- w
) * 3;
363 data
= malloc(w
* h
* 3);
366 ptr1
= im
->rgb_data
+ (y
* w3
) + (x
* 3);
368 for (yy
= 0; yy
< h
; yy
++)
370 for (xx
= 0; xx
< w
; xx
++)
380 if (im
->border
.left
> x
)
381 im
->border
.left
= im
->border
.left
- x
;
384 if (im
->border
.top
> y
)
385 im
->border
.top
= im
->border
.top
- y
;
388 if (im
->rgb_width
- im
->border
.right
< x
+ w
)
389 im
->border
.right
= im
->border
.right
- (im
->rgb_width
- (x
+ w
));
391 im
->border
.right
= 0;
392 if (im
->rgb_height
- im
->border
.bottom
< y
+ h
)
393 im
->border
.bottom
= im
->border
.bottom
- (im
->rgb_height
- (y
+ h
));
395 im
->border
.bottom
= 0;
403 gdk_imlib_changed_image(GdkImlibImage
* im
)
412 gdk_imlib_apply_image(GdkImlibImage
* im
, GdkWindow
* p
)
419 gdk_window_get_size(p
, &w
, &h
);
420 if (w
<= 0 || h
<= 0)
422 gdk_imlib_render(im
, w
, h
);
423 pp
= gdk_imlib_move_image(im
);
424 mm
= gdk_imlib_move_mask(im
);
425 gdk_window_set_back_pixmap(p
, pp
, 0);
427 gdk_window_shape_combine_mask(p
, mm
, 0, 0);
429 gdk_imlib_free_pixmap(pp
);
433 gdk_imlib_paste_image(GdkImlibImage
* im
, GdkWindow
* p
, gint x
, gint y
, gint w
, gint h
)
440 if ((w
<= 0) || (h
<= 0))
443 gdk_imlib_render(im
, w
, h
);
444 pp
= gdk_imlib_move_image(im
);
445 mm
= gdk_imlib_move_mask(im
);
448 gdk_gc_set_clip_mask(gc
, mm
);
449 gdk_gc_set_clip_origin(gc
, x
, y
);
451 gdk_draw_pixmap(p
, gc
, pp
, 0, 0, x
, y
, w
, h
);
452 gdk_imlib_free_pixmap(pp
);
457 gdk_imlib_paste_image_border(GdkImlibImage
* im
, GdkWindow
* p
, gint x
, gint y
, gint w
, gint h
)
465 if (w
<= 0 || h
<= 0)
468 gdk_imlib_render(im
, w
, h
);
469 pp
= gdk_imlib_move_image(im
);
470 mm
= gdk_imlib_move_mask(im
);
473 gdk_gc_set_clip_mask(gc
, mm
);
474 gdk_gc_set_clip_origin(gc
, x
, y
);
476 if ((w
<= (im
->border
.left
+ im
->border
.right
)) ||
477 (h
<= (im
->border
.top
+ im
->border
.bottom
)))
478 gdk_draw_pixmap(p
, gc
, pp
, 0, 0, x
, y
, w
, h
);
481 gdk_draw_pixmap(p
, gc
, pp
, 0, 0, x
, y
, w
, im
->border
.top
);
482 gdk_draw_pixmap(p
, gc
, pp
, 0, h
- im
->border
.bottom
,
483 x
, y
+ (h
- im
->border
.bottom
),
484 w
, im
->border
.bottom
);
485 gdk_draw_pixmap(p
, gc
, pp
, 0, im
->border
.top
,
486 x
, y
+ im
->border
.top
,
487 im
->border
.left
, h
- (im
->border
.top
+ im
->border
.bottom
));
488 gdk_draw_pixmap(p
, gc
, pp
, w
- im
->border
.right
, h
- im
->border
.bottom
,
489 x
+ (w
- im
->border
.right
), y
+ (h
- im
->border
.bottom
),
490 im
->border
.right
, h
- (im
->border
.top
+ im
->border
.bottom
));
492 gdk_imlib_free_pixmap(pp
);
497 gdk_imlib_flip_image_horizontal(GdkImlibImage
* im
)
499 unsigned char *ptr1
, *ptr2
, r
, rr
;
505 w3
= im
->rgb_width
* 3;
506 for (y
= 0; y
< im
->rgb_height
; y
++)
508 ptr1
= im
->rgb_data
+ (y
* w3
);
509 ptr2
= im
->rgb_data
+ (y
* w3
) + w3
- 3;
510 for (x
= 0; x
< im
->rgb_width
>> 1; x
++)
530 w3
= im
->border
.left
;
531 im
->border
.left
= im
->border
.right
;
532 im
->border
.right
= w3
;
538 gdk_imlib_flip_image_vertical(GdkImlibImage
* im
)
540 unsigned char *ptr1
, *ptr2
, r
, rr
;
547 w3
= im
->rgb_width
* 3;
548 for (yy
= im
->rgb_height
- 1, y
= 0; y
< im
->rgb_height
>> 1; y
++, yy
--)
550 ptr1
= im
->rgb_data
+ (y
* w3
);
551 ptr2
= im
->rgb_data
+ (yy
* w3
);
552 for (x
= 0; x
< im
->rgb_width
; x
++)
569 im
->border
.top
= im
->border
.bottom
;
570 im
->border
.bottom
= w3
;
576 gdk_imlib_rotate_image(GdkImlibImage
* im
, gint d
)
580 unsigned char *ptr1
, *ptr2
;
584 w3
= im
->rgb_width
* 3;
585 w4
= im
->rgb_height
* 3;
587 data
= malloc(im
->rgb_width
* im
->rgb_height
* 3);
591 for (y
= 0; y
< im
->rgb_height
; y
++)
593 ptr1
= im
->rgb_data
+ (y
* w3
);
594 ptr2
= data
+ (y
* 3);
595 for (x
= 0; x
< im
->rgb_width
; x
++)
606 im
->rgb_width
= im
->rgb_height
;
609 im
->border
.top
= im
->border
.left
;
610 im
->border
.left
= w3
;
611 w3
= im
->border
.bottom
;
612 im
->border
.bottom
= im
->border
.right
;
613 im
->border
.right
= w3
;
619 gdk_imlib_create_image_from_data(unsigned char *data
, unsigned char *alpha
, gint w
, gint h
)
624 if (!data
|| w
<= 0 || h
<= 0)
627 im
= malloc(sizeof(GdkImlibImage
));
633 im
->rgb_data
= malloc(im
->rgb_width
* im
->rgb_height
* 3);
640 memcpy(im
->rgb_data
, data
, im
->rgb_width
* im
->rgb_height
* 3);
641 /* im->alpha_data=alpha; */
642 im
->alpha_data
= NULL
;
643 g_snprintf(s
, sizeof(s
), "creat_%x_%x", (int)time(NULL
), (int)rand());
644 im
->filename
= malloc(strlen(s
) + 1);
646 strcpy(im
->filename
, s
);
649 im
->shape_color
.r
= -1;
650 im
->shape_color
.g
= -1;
651 im
->shape_color
.b
= -1;
653 im
->border
.right
= 0;
655 im
->border
.bottom
= 0;
657 im
->shape_mask
= NULL
;
659 im
->mod
.gamma
= id
->mod
.gamma
;
660 im
->mod
.brightness
= id
->mod
.brightness
;
661 im
->mod
.contrast
= id
->mod
.contrast
;
662 im
->rmod
.gamma
= id
->rmod
.gamma
;
663 im
->rmod
.brightness
= id
->rmod
.brightness
;
664 im
->rmod
.contrast
= id
->rmod
.contrast
;
665 im
->gmod
.gamma
= id
->gmod
.gamma
;
666 im
->gmod
.brightness
= id
->gmod
.brightness
;
667 im
->gmod
.contrast
= id
->gmod
.contrast
;
668 im
->bmod
.gamma
= id
->bmod
.gamma
;
669 im
->bmod
.brightness
= id
->bmod
.brightness
;
670 im
->bmod
.contrast
= id
->bmod
.contrast
;
671 if (id
->cache
.on_image
)
672 gadd_image(im
, im
->filename
);
673 gcalc_map_tables(im
);
678 gdk_imlib_clone_image(GdkImlibImage
* im
)
685 im2
= malloc(sizeof(GdkImlibImage
));
688 im2
->rgb_width
= im
->rgb_width
;
689 im2
->rgb_height
= im
->rgb_height
;
690 im2
->rgb_data
= malloc(im2
->rgb_width
* im2
->rgb_height
* 3);
697 memcpy(im2
->rgb_data
, im
->rgb_data
, im2
->rgb_width
* im2
->rgb_height
* 3);
700 im2
->alpha_data
= malloc(im2
->rgb_width
* im2
->rgb_height
);
701 if (!im2
->alpha_data
)
707 memcpy(im2
->alpha_data
, im
->alpha_data
, im2
->rgb_width
* im2
->rgb_height
);
710 im2
->alpha_data
= NULL
;
711 s
= malloc(strlen(im
->filename
) + 320);
714 g_snprintf(s
, sizeof(s
), "%s_%x_%x", im
->filename
, (int)time(NULL
), (int)rand());
715 im2
->filename
= malloc(strlen(s
) + 1);
717 strcpy(im2
->filename
, s
);
721 im2
->filename
= NULL
;
724 im2
->shape_color
.r
= im
->shape_color
.r
;
725 im2
->shape_color
.g
= im
->shape_color
.g
;
726 im2
->shape_color
.b
= im
->shape_color
.b
;
727 im2
->border
.left
= im
->border
.left
;
728 im2
->border
.right
= im
->border
.right
;
729 im2
->border
.top
= im
->border
.top
;
730 im2
->border
.bottom
= im
->border
.bottom
;
732 im2
->shape_mask
= NULL
;
734 im2
->mod
.gamma
= im
->mod
.gamma
;
735 im2
->mod
.brightness
= im
->mod
.brightness
;
736 im2
->mod
.contrast
= im
->mod
.contrast
;
737 im2
->rmod
.gamma
= im
->rmod
.gamma
;
738 im2
->rmod
.brightness
= im
->rmod
.brightness
;
739 im2
->rmod
.contrast
= im
->rmod
.contrast
;
740 im2
->gmod
.gamma
= im
->gmod
.gamma
;
741 im2
->gmod
.brightness
= im
->gmod
.brightness
;
742 im2
->gmod
.contrast
= im
->gmod
.contrast
;
743 im2
->bmod
.gamma
= im
->bmod
.gamma
;
744 im2
->bmod
.brightness
= im
->bmod
.brightness
;
745 im2
->bmod
.contrast
= im
->bmod
.contrast
;
746 gcalc_map_tables(im2
);
747 if (id
->cache
.on_image
)
748 gadd_image(im2
, im2
->filename
);
753 gdk_imlib_clone_scaled_image(GdkImlibImage
* im
, int w
, int h
)
758 if (!im
|| w
<= 0 || h
<= 0)
761 im2
= malloc(sizeof(GdkImlibImage
));
766 im2
->rgb_data
= malloc(w
* h
* 3);
774 unsigned char **yarray
, *ptr
, *ptr2
, *ptr22
;
775 int l
, r
, m
, pos
, inc
, w3
;
777 xarray
= malloc(sizeof(int) * w
);
781 fprintf(stderr
, "ERROR: Cannot allocate X co-ord buffer\n");
786 yarray
= malloc(sizeof(unsigned char *) * h
);
790 fprintf(stderr
, "ERROR: Cannot allocate Y co-ord buffer\n");
796 ptr22
= im
->rgb_data
;
797 w3
= im
->rgb_width
* 3;
799 if (w
< im
->border
.left
+ im
->border
.right
)
808 r
= im
->border
.right
;
812 inc
= ((im
->rgb_width
- im
->border
.left
- im
->border
.right
) << 16) / m
;
816 for (x
= 0; x
< l
; x
++)
818 xarray
[x
] = (pos
>> 16) + (pos
>> 16) + (pos
>> 16);
824 for (x
= l
; x
< l
+ m
; x
++)
826 xarray
[x
] = (pos
>> 16) + (pos
>> 16) + (pos
>> 16);
830 pos
= (im
->rgb_width
- r
) << 16;
831 for (x
= w
- r
; x
< w
; x
++)
833 xarray
[x
] = (pos
>> 16) + (pos
>> 16) + (pos
>> 16);
837 if (h
< im
->border
.top
+ im
->border
.bottom
)
846 r
= im
->border
.bottom
;
850 inc
= ((im
->rgb_height
- im
->border
.top
- im
->border
.bottom
) << 16) / m
;
852 for (x
= 0; x
< l
; x
++)
854 yarray
[x
] = ptr22
+ ((pos
>> 16) * w3
);
859 for (x
= l
; x
< l
+ m
; x
++)
861 yarray
[x
] = ptr22
+ ((pos
>> 16) * w3
);
865 pos
= (im
->rgb_height
- r
) << 16;
866 for (x
= h
- r
; x
< h
; x
++)
868 yarray
[x
] = ptr22
+ ((pos
>> 16) * w3
);
873 for (y
= 0; y
< h
; y
++)
875 for (x
= 0; x
< w
; x
++)
877 ptr2
= yarray
[y
] + xarray
[x
];
878 *ptr
++ = (int)*ptr2
++;
879 *ptr
++ = (int)*ptr2
++;
886 im2
->alpha_data
= NULL
;
887 /* yet to be filled in */
890 im2
->alpha_data
= NULL
;
892 s
= malloc(strlen(im
->filename
) + 320);
895 g_snprintf(s
, sizeof(s
), "%s_%x_%x_%x_%x", im
->filename
, (int)time(NULL
), w
, h
, (int)rand());
896 im2
->filename
= malloc(strlen(s
) + 1);
898 strcpy(im2
->filename
, s
);
902 im2
->filename
= NULL
;
905 im2
->shape_color
.r
= im
->shape_color
.r
;
906 im2
->shape_color
.g
= im
->shape_color
.g
;
907 im2
->shape_color
.b
= im
->shape_color
.b
;
908 im2
->border
.left
= im
->border
.left
;
909 im2
->border
.right
= im
->border
.right
;
910 im2
->border
.top
= im
->border
.top
;
911 im2
->border
.bottom
= im
->border
.bottom
;
913 im2
->shape_mask
= NULL
;
915 im2
->mod
.gamma
= im
->mod
.gamma
;
916 im2
->mod
.brightness
= im
->mod
.brightness
;
917 im2
->mod
.contrast
= im
->mod
.contrast
;
918 im2
->rmod
.gamma
= im
->rmod
.gamma
;
919 im2
->rmod
.brightness
= im
->rmod
.brightness
;
920 im2
->rmod
.contrast
= im
->rmod
.contrast
;
921 im2
->gmod
.gamma
= im
->gmod
.gamma
;
922 im2
->gmod
.brightness
= im
->gmod
.brightness
;
923 im2
->gmod
.contrast
= im
->gmod
.contrast
;
924 im2
->bmod
.gamma
= im
->bmod
.gamma
;
925 im2
->bmod
.brightness
= im
->bmod
.brightness
;
926 im2
->bmod
.contrast
= im
->bmod
.contrast
;
927 gcalc_map_tables(im2
);
928 if (id
->cache
.on_image
)
929 gadd_image(im2
, im2
->filename
);
934 gdk_imlib_create_image_from_xpm_data(char **data
)
938 int /* pc, */ c
, i
, j
, k
, ncolors
, cpp
, comment
, transp
, quote
,
939 context
, len
, count
, done
;
941 char *line
, s
[65536], tok
[65536], col
[65536];
951 int lookup
[128][128];
957 im
= malloc(sizeof(GdkImlibImage
));
972 line
= data
[count
++];
976 sscanf(line
, "%i %i %i %i", &w
, &h
, &ncolors
, &cpp
);
979 fprintf(stderr
, "gdk_imlib ERROR: XPM data with characters per pixel > 7 not supported\n");
985 fprintf(stderr
, "gdk_imlib ERROR: Image width > 32767 pixels for data\n");
991 fprintf(stderr
, "gdk_imlib ERROR: Image height > 32767 pixels for data\n");
995 cmap
= malloc(sizeof(struct _cmap
) * ncolors
);
1004 im
->rgb_data
= malloc(im
->rgb_width
* im
->rgb_height
* 3);
1011 im
->alpha_data
= NULL
;
1012 g_snprintf(s
, sizeof(s
), "creat_%x_%x", (int)time(NULL
), (int)rand());
1013 im
->filename
= malloc(strlen(s
) + 1);
1015 strcpy(im
->filename
, s
);
1018 im
->border
.left
= 0;
1019 im
->border
.right
= 0;
1021 im
->border
.bottom
= 0;
1023 im
->shape_mask
= NULL
;
1025 im
->mod
.gamma
= id
->mod
.gamma
;
1026 im
->mod
.brightness
= id
->mod
.brightness
;
1027 im
->mod
.contrast
= id
->mod
.contrast
;
1028 im
->rmod
.gamma
= id
->rmod
.gamma
;
1029 im
->rmod
.brightness
= id
->rmod
.brightness
;
1030 im
->rmod
.contrast
= id
->rmod
.contrast
;
1031 im
->gmod
.gamma
= id
->gmod
.gamma
;
1032 im
->gmod
.brightness
= id
->gmod
.brightness
;
1033 im
->gmod
.contrast
= id
->gmod
.contrast
;
1034 im
->bmod
.gamma
= id
->bmod
.gamma
;
1035 im
->bmod
.brightness
= id
->bmod
.brightness
;
1036 im
->bmod
.contrast
= id
->bmod
.contrast
;
1041 else if (context
== 1)
1053 strncpy(cmap
[j
].str
, line
, cpp
);
1054 cmap
[j
].str
[cpp
] = 0;
1057 for (k
= cpp
; k
< len
; k
++)
1061 sscanf(&line
[k
], "%65536s", s
);
1063 if ((!strcmp(s
, "m")) || (!strcmp(s
, "s")) ||
1064 (!strcmp(s
, "g4")) || (!strcmp(s
, "g")) ||
1065 (!strcmp(s
, "c")) || (k
>= len
))
1073 if (col
[0] && colptr
< sizeof(col
))
1075 strcpy(col
+ colptr
, " ");
1078 if (colptr
+ ls
<= sizeof(col
))
1080 strcpy(col
+ colptr
, s
);
1087 if (!strcasecmp(col
, "none"))
1094 if ((cmap
[j
].r
< 0) ||
1095 (!strcmp(tok
, "c")))
1097 XParseColor(id
->x
.disp
,
1100 cmap
[j
].r
= xcol
.red
>> 8;
1101 cmap
[j
].g
= xcol
.green
>> 8;
1102 cmap
[j
].b
= xcol
.blue
>> 8;
1103 if ((cmap
[j
].r
== 255) &&
1110 if (strlen(s
) < sizeof(tok
))
1120 if (col
[0] && colptr
< sizeof(col
))
1122 strcpy(col
+ colptr
, " ");
1125 if (ls
+ colptr
< sizeof(col
))
1127 strcpy(col
+ colptr
, s
);
1138 for (i
= 0; i
< ncolors
; i
++)
1139 lookup
[(int)cmap
[i
].str
[0]][(int)cmap
[i
].str
[1]] = i
;
1141 for (i
= 0; i
< ncolors
; i
++)
1142 lookup
[(int)cmap
[i
].str
[0]][(int)cmap
[i
].str
[1]] = i
;
1157 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1160 if (cmap
[lookup
[(int)col
[0]][0]].transp
)
1168 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][0]].r
;
1169 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][0]].g
;
1170 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][0]].b
;
1176 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1179 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][0]].r
;
1180 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][0]].g
;
1181 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][0]].b
;
1189 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1193 if (cmap
[lookup
[(int)col
[0]][(int)col
[1]]].transp
)
1201 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][(int)col
[1]]].r
;
1202 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][(int)col
[1]]].g
;
1203 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][(int)col
[1]]].b
;
1209 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1213 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][(int)col
[1]]].r
;
1214 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][(int)col
[1]]].g
;
1215 *ptr
++ = (unsigned char)cmap
[lookup
[(int)col
[0]][(int)col
[1]]].b
;
1223 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1225 for (j
= 0; j
< cpp
; j
++, i
++)
1231 for (j
= 0; j
< ncolors
; j
++)
1233 if (!strcmp(col
, cmap
[j
].str
))
1243 *ptr
++ = (unsigned char)cmap
[j
].r
;
1244 *ptr
++ = (unsigned char)cmap
[j
].g
;
1245 *ptr
++ = (unsigned char)cmap
[j
].b
;
1254 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1256 for (j
= 0; j
< cpp
; j
++, i
++)
1262 for (j
= 0; j
< ncolors
; j
++)
1264 if (!strcmp(col
, cmap
[j
].str
))
1266 *ptr
++ = (unsigned char)cmap
[j
].r
;
1267 *ptr
++ = (unsigned char)cmap
[j
].g
;
1268 *ptr
++ = (unsigned char)cmap
[j
].b
;
1276 if ((ptr
) && ((ptr
- im
->rgb_data
) >= w
* h
* 3))
1281 im
->shape_color
.r
= -1;
1282 im
->shape_color
.g
= -1;
1283 im
->shape_color
.b
= -1;
1287 im
->shape_color
.r
= 255;
1288 im
->shape_color
.g
= 0;
1289 im
->shape_color
.b
= 255;
1291 if (id
->cache
.on_image
)
1292 gadd_image(im
, im
->filename
);
1293 gcalc_map_tables(im
);
1299 gdk_imlib_data_to_pixmap(char **data
, GdkPixmap
** pmap
, GdkBitmap
** mask
)
1303 im
= gdk_imlib_create_image_from_xpm_data(data
);
1312 if (!gdk_imlib_render(im
, im
->rgb_width
, im
->rgb_height
))
1314 gdk_imlib_destroy_image(im
);
1322 *pmap
= gdk_imlib_move_image(im
);
1324 *mask
= gdk_imlib_move_mask(im
);
1325 gdk_imlib_kill_image(im
);
1330 #include <sys/wait.h>
1337 void *oldpiper
; /* actually sighandler_t but BSD uses sig_t. */
1340 open_helper(const char *instring
, const char *fn
, const char *mode
)
1342 char buf
[256]; /* This is safe since our input strings
1346 static char *vec
[16];
1347 char *p
= strdup(instring
);
1361 if (strncmp(instring
, "%Q", 2) == 0)
1364 * Generate a quanting pipeline
1366 fprintf(stderr
, "Not currently supported: install ImageMagic.\n");
1370 * Ok split the instring on spaces and translate
1373 * FIXME: We need to handle a format string that begins
1374 * %Q to indicate an 8bit quant in the pipeline first.
1381 while (*pp
&& isspace(*pp
))
1384 while (*ep
&& !isspace(*ep
))
1388 /* pp->ep is now the input string block */
1392 if (strcmp(pp
, "%s") == 0)
1393 vec
[vn
] = strdup(fn
);
1394 else if (strncmp(pp
, "%P/", 3) == 0)
1396 strcpy(buf
, NETPBM_PATH
);
1397 strcat(buf
, pp
+ 2);
1398 if ((vec
[vn
] = strdup(buf
)) == NULL
)
1401 else if (strncmp(pp
, "%J", 3) == 0)
1403 if ((vec
[vn
] = strdup(DJPEG_PROG
)) == NULL
)
1406 else if (strncmp(pp
, "%H", 3) == 0)
1408 if ((vec
[vn
] = strdup(CJPEG_PROG
)) == NULL
)
1411 else if (strncmp(pp
, "%C/", 3) == 0)
1413 strcpy(buf
, CONVERT_PATH
);
1414 strcat(buf
, pp
+ 2);
1415 if ((vec
[vn
] = strdup(buf
)) == NULL
)
1418 else if (strncmp(pp
, ">%s", 3) == 0)
1427 if ((vec
[vn
] = strdup(pp
)) == NULL
)
1436 if (pipe(pfd
) == -1)
1441 fp
= fdopen(pfd
[0], "r");
1445 else if (*mode
== 'w')
1447 fp
= fdopen(pfd
[1], "w");
1455 if ((ofd
= open(ofil
, O_WRONLY
| O_TRUNC
| O_CREAT
)) == -1)
1458 switch (pid
= fork())
1463 signal(SIGPIPE
, SIG_DFL
);
1480 * This MUST be _exit or we will hit the SIGPIPE
1481 * handler in ways we dont want. We want our parent
1482 * to flush the inherited file buffers not us.
1495 for (vn
= 0; vn
< 16; vn
++)
1498 oldpiper
= signal(SIGPIPE
, SIG_IGN
);
1506 for (vn
= 0; vn
< 16; vn
++)
1513 close_helper(FILE * fp
)
1518 signal(SIGPIPE
, oldpiper
);
1519 waitpid(hpid
, &info
, 0);
1520 return WEXITSTATUS(info
);