]>
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];
950 int lookup
[128][128];
954 im
= malloc(sizeof(GdkImlibImage
));
969 line
= data
[count
++];
973 sscanf(line
, "%i %i %i %i", &w
, &h
, &ncolors
, &cpp
);
976 fprintf(stderr
, "gdk_imlib ERROR: XPM data with characters per pixel > 7 not supported\n");
982 fprintf(stderr
, "gdk_imlib ERROR: Image width > 32767 pixels for data\n");
988 fprintf(stderr
, "gdk_imlib ERROR: Image height > 32767 pixels for data\n");
992 cmap
= malloc(sizeof(struct _cmap
) * ncolors
);
1001 im
->rgb_data
= malloc(im
->rgb_width
* im
->rgb_height
* 3);
1008 im
->alpha_data
= NULL
;
1009 g_snprintf(s
, sizeof(s
), "creat_%x_%x", (int)time(NULL
), (int)rand());
1010 im
->filename
= malloc(strlen(s
) + 1);
1012 strcpy(im
->filename
, s
);
1015 im
->border
.left
= 0;
1016 im
->border
.right
= 0;
1018 im
->border
.bottom
= 0;
1020 im
->shape_mask
= NULL
;
1022 im
->mod
.gamma
= id
->mod
.gamma
;
1023 im
->mod
.brightness
= id
->mod
.brightness
;
1024 im
->mod
.contrast
= id
->mod
.contrast
;
1025 im
->rmod
.gamma
= id
->rmod
.gamma
;
1026 im
->rmod
.brightness
= id
->rmod
.brightness
;
1027 im
->rmod
.contrast
= id
->rmod
.contrast
;
1028 im
->gmod
.gamma
= id
->gmod
.gamma
;
1029 im
->gmod
.brightness
= id
->gmod
.brightness
;
1030 im
->gmod
.contrast
= id
->gmod
.contrast
;
1031 im
->bmod
.gamma
= id
->bmod
.gamma
;
1032 im
->bmod
.brightness
= id
->bmod
.brightness
;
1033 im
->bmod
.contrast
= id
->bmod
.contrast
;
1038 else if (context
== 1)
1050 strncpy(cmap
[j
].str
, line
, cpp
);
1051 cmap
[j
].str
[cpp
] = 0;
1054 for (k
= cpp
; k
< len
; k
++)
1058 sscanf(&line
[k
], "%65536s", s
);
1060 if ((!strcmp(s
, "m")) || (!strcmp(s
, "s")) ||
1061 (!strcmp(s
, "g4")) || (!strcmp(s
, "g")) ||
1062 (!strcmp(s
, "c")) || (k
>= len
))
1070 if (col
[0] && colptr
< sizeof(col
))
1072 strcpy(col
+ colptr
, " ");
1075 if (colptr
+ ls
<= sizeof(col
))
1077 strcpy(col
+ colptr
, s
);
1084 if (!strcasecmp(col
, "none"))
1091 if ((cmap
[j
].r
< 0) ||
1092 (!strcmp(tok
, "c")))
1094 XParseColor(id
->x
.disp
,
1097 cmap
[j
].r
= xcol
.red
>> 8;
1098 cmap
[j
].g
= xcol
.green
>> 8;
1099 cmap
[j
].b
= xcol
.blue
>> 8;
1100 if ((cmap
[j
].r
== 255) &&
1107 if (strlen(s
) < sizeof(tok
))
1117 if (col
[0] && colptr
< sizeof(col
))
1119 strcpy(col
+ colptr
, " ");
1122 if (ls
+ colptr
< sizeof(col
))
1124 strcpy(col
+ colptr
, s
);
1135 for (i
= 0; i
< ncolors
; i
++)
1136 lookup
[cmap
[i
].str
[0]][cmap
[i
].str
[1]] = i
;
1138 for (i
= 0; i
< ncolors
; i
++)
1139 lookup
[cmap
[i
].str
[0]][cmap
[i
].str
[1]] = i
;
1154 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1157 if (cmap
[lookup
[col
[0]][0]].transp
)
1165 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][0]].r
;
1166 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][0]].g
;
1167 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][0]].b
;
1173 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1176 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][0]].r
;
1177 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][0]].g
;
1178 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][0]].b
;
1186 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1190 if (cmap
[lookup
[col
[0]][col
[1]]].transp
)
1198 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][col
[1]]].r
;
1199 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][col
[1]]].g
;
1200 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][col
[1]]].b
;
1206 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1210 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][col
[1]]].r
;
1211 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][col
[1]]].g
;
1212 *ptr
++ = (unsigned char)cmap
[lookup
[col
[0]][col
[1]]].b
;
1220 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1222 for (j
= 0; j
< cpp
; j
++, i
++)
1228 for (j
= 0; j
< ncolors
; j
++)
1230 if (!strcmp(col
, cmap
[j
].str
))
1240 *ptr
++ = (unsigned char)cmap
[j
].r
;
1241 *ptr
++ = (unsigned char)cmap
[j
].g
;
1242 *ptr
++ = (unsigned char)cmap
[j
].b
;
1251 for (i
= 0; ((i
< 65536) && (line
[i
])); i
++)
1253 for (j
= 0; j
< cpp
; j
++, i
++)
1259 for (j
= 0; j
< ncolors
; j
++)
1261 if (!strcmp(col
, cmap
[j
].str
))
1263 *ptr
++ = (unsigned char)cmap
[j
].r
;
1264 *ptr
++ = (unsigned char)cmap
[j
].g
;
1265 *ptr
++ = (unsigned char)cmap
[j
].b
;
1273 if ((ptr
) && ((ptr
- im
->rgb_data
) >= w
* h
* 3))
1278 im
->shape_color
.r
= -1;
1279 im
->shape_color
.g
= -1;
1280 im
->shape_color
.b
= -1;
1284 im
->shape_color
.r
= 255;
1285 im
->shape_color
.g
= 0;
1286 im
->shape_color
.b
= 255;
1288 if (id
->cache
.on_image
)
1289 gadd_image(im
, im
->filename
);
1290 gcalc_map_tables(im
);
1296 gdk_imlib_data_to_pixmap(char **data
, GdkPixmap
** pmap
, GdkBitmap
** mask
)
1300 im
= gdk_imlib_create_image_from_xpm_data(data
);
1309 if (!gdk_imlib_render(im
, im
->rgb_width
, im
->rgb_height
))
1311 gdk_imlib_destroy_image(im
);
1319 *pmap
= gdk_imlib_move_image(im
);
1321 *mask
= gdk_imlib_move_mask(im
);
1322 gdk_imlib_kill_image(im
);
1327 #include <sys/wait.h>
1334 void *oldpiper
; /* actually sighandler_t but BSD uses sig_t. */
1337 open_helper(const char *instring
, const char *fn
, const char *mode
)
1339 char buf
[256]; /* This is safe since our input strings
1343 static char *vec
[16];
1344 char *p
= strdup(instring
);
1358 if (strncmp(instring
, "%Q", 2) == 0)
1361 * Generate a quanting pipeline
1363 fprintf(stderr
, "Not currently supported: install ImageMagic.\n");
1367 * Ok split the instring on spaces and translate
1370 * FIXME: We need to handle a format string that begins
1371 * %Q to indicate an 8bit quant in the pipeline first.
1378 while (*pp
&& isspace(*pp
))
1381 while (*ep
&& !isspace(*ep
))
1385 /* pp->ep is now the input string block */
1389 if (strcmp(pp
, "%s") == 0)
1390 vec
[vn
] = strdup(fn
);
1391 else if (strncmp(pp
, "%P/", 3) == 0)
1393 strcpy(buf
, NETPBM_PATH
);
1394 strcat(buf
, pp
+ 2);
1395 if ((vec
[vn
] = strdup(buf
)) == NULL
)
1398 else if (strncmp(pp
, "%J", 3) == 0)
1400 if ((vec
[vn
] = strdup(DJPEG_PROG
)) == NULL
)
1403 else if (strncmp(pp
, "%H", 3) == 0)
1405 if ((vec
[vn
] = strdup(CJPEG_PROG
)) == NULL
)
1408 else if (strncmp(pp
, "%C/", 3) == 0)
1410 strcpy(buf
, CONVERT_PATH
);
1411 strcat(buf
, pp
+ 2);
1412 if ((vec
[vn
] = strdup(buf
)) == NULL
)
1415 else if (strncmp(pp
, ">%s", 3) == 0)
1424 if ((vec
[vn
] = strdup(pp
)) == NULL
)
1433 if (pipe(pfd
) == -1)
1438 fp
= fdopen(pfd
[0], "r");
1442 else if (*mode
== 'w')
1444 fp
= fdopen(pfd
[1], "w");
1452 if ((ofd
= open(ofil
, O_WRONLY
| O_TRUNC
| O_CREAT
)) == -1)
1455 switch (pid
= fork())
1460 signal(SIGPIPE
, SIG_DFL
);
1477 * This MUST be _exit or we will hit the SIGPIPE
1478 * handler in ways we dont want. We want our parent
1479 * to flush the inherited file buffers not us.
1492 for (vn
= 0; vn
< 16; vn
++)
1495 oldpiper
= signal(SIGPIPE
, SIG_IGN
);
1503 for (vn
= 0; vn
< 16; vn
++)
1510 close_helper(FILE * fp
)
1515 signal(SIGPIPE
, oldpiper
);
1516 waitpid(hpid
, &info
, 0);
1517 return WEXITSTATUS(info
);