aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Image.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/generic/Image.c b/generic/Image.c
index e568beb..1f4025b 100644
--- a/generic/Image.c
+++ b/generic/Image.c
@@ -46,6 +46,7 @@ typedef struct {
typedef struct _ImagePixmap {
Display *dpy;
Pixmap pixmap;
+ Pixmap mask_pmap;
struct _ImagePixmap *next;
} ImagePixmap;
@@ -63,6 +64,7 @@ static Tcl_HashTable bitmap_masks;
*/
ImageBits *
GetImageBits(ZnWindow win,
+ char *image_name,
ZnImage image)
{
static int inited = 0;
@@ -78,10 +80,10 @@ GetImageBits(ZnWindow win,
ZnBool full_mask=True;
if (!inited) {
- Tcl_InitHashTable(&image_bits, TCL_ONE_WORD_KEYS);
+ Tcl_InitHashTable(&image_bits, TCL_STRING_KEYS);
inited = 1;
}
- entry = Tcl_FindHashEntry(&image_bits, (char *) image);
+ entry = Tcl_FindHashEntry(&image_bits, image_name);
if (entry != NULL) {
im_bits = (ImageBits *) Tcl_GetHashValue(entry);
}
@@ -138,7 +140,7 @@ GetImageBits(ZnWindow win,
im_bits->mask = mask;
}
- entry = Tcl_CreateHashEntry(&image_bits, (char *) image, &new);
+ entry = Tcl_CreateHashEntry(&image_bits, image_name, &new);
Tcl_SetHashValue(entry, (ClientData) im_bits);
}
@@ -146,7 +148,7 @@ GetImageBits(ZnWindow win,
}
void
-InvalidateImage(ZnImage image)
+InvalidateImage(char *image_name)
{
Tcl_HashEntry *entry;
ImageBits *im_bits;
@@ -156,8 +158,10 @@ InvalidateImage(ZnImage image)
* Destroy the image entry and wait the cache fault to
* reload the new one.
*/
- entry = Tcl_FindHashEntry(&image_bits, (char *) image);
+ /*printf("InvalidateImage %s\n", image_name);*/
+ entry = Tcl_FindHashEntry(&image_bits, image_name);
if (entry != NULL) {
+ /*printf("deallocating bits for image %s\n", image_name);*/
im_bits = (ImageBits *) Tcl_GetHashValue(entry);
XDestroyImage(im_bits->pixels);
if (im_bits->mask) {
@@ -167,6 +171,9 @@ InvalidateImage(ZnImage image)
while (im_pmap) {
next_im_pmap = im_pmap->next;
XFreePixmap(im_pmap->dpy, im_pmap->pixmap);
+ if (im_bits->mask) {
+ XFreePixmap(im_pmap->dpy, im_pmap->mask_pmap);
+ }
ZnFree(im_pmap);
im_pmap = next_im_pmap;
}
@@ -185,28 +192,53 @@ InvalidateImage(ZnImage image)
*/
Pixmap
GetImagePixmap(ZnWindow win,
- ZnImage image)
+ char *image_name,
+ ZnImage image,
+ Pixmap *mask_pmap)
{
ImageBits *im_bits;
Display *dpy = Tk_Display(win);
int depth = Tk_Depth(win);
ImagePixmap *im_pmap, *next_im_pmap;
Pixmap pixmap;
-
- im_bits = GetImageBits(win, image);
+ GC gc;
+ XGCValues values;
+
+ im_bits = GetImageBits(win, image_name, image);
im_pmap = next_im_pmap = im_bits->pixmaps;
while (next_im_pmap && (im_pmap->dpy != dpy)) {
im_pmap = next_im_pmap;
next_im_pmap = next_im_pmap->next;
}
if (!im_pmap || (im_pmap->dpy != dpy)) {
+ /* printf("New pixmap\n");*/
next_im_pmap = (ImagePixmap *) ZnMalloc(sizeof(ImagePixmap));
next_im_pmap->next = NULL;
next_im_pmap->dpy = dpy;
pixmap = XCreatePixmap(dpy, ZnWindowId(win),
im_bits->width, im_bits->height, depth);
- Tk_RedrawImage(image, 0, 0, im_bits->width, im_bits->height, pixmap, 0, 0);
+ gc = XCreateGC(dpy, pixmap, 0, NULL);
+ XPutImage(dpy, pixmap, gc, im_bits->pixels, 0, 0, 0, 0,
+ im_bits->width, im_bits->height);
+ XFreeGC(dpy, gc);
next_im_pmap->pixmap = pixmap;
+ if (im_bits->mask) {
+ next_im_pmap->mask_pmap = XCreatePixmap(dpy, ZnWindowId(win),
+ im_bits->width, im_bits->height, 1);
+ values.foreground = 1;
+ values.background = 0;
+ gc = XCreateGC(dpy, next_im_pmap->mask_pmap,
+ GCForeground|GCBackground, &values);
+ XPutImage(dpy, next_im_pmap->mask_pmap, gc, im_bits->mask, 0, 0, 0, 0,
+ im_bits->width, im_bits->height);
+ XFreeGC(dpy, gc);
+ if (mask_pmap) {
+ *mask_pmap = next_im_pmap->mask_pmap;
+ }
+ }
+ else {
+ next_im_pmap->mask_pmap = None;
+ }
if (im_pmap) {
im_pmap->next = next_im_pmap;
}
@@ -215,7 +247,11 @@ GetImagePixmap(ZnWindow win,
}
}
else {
+ /*printf("Reusing pixmap\n");*/
pixmap = im_pmap->pixmap;
+ if (mask_pmap) {
+ *mask_pmap = im_pmap->mask_pmap;
+ }
}
return pixmap;