diff options
Diffstat (limited to 'generic/Image.c')
-rw-r--r-- | generic/Image.c | 708 |
1 files changed, 354 insertions, 354 deletions
diff --git a/generic/Image.c b/generic/Image.c index ae4ff9e..ff5afd2 100644 --- a/generic/Image.c +++ b/generic/Image.c @@ -1,8 +1,8 @@ /* * Image.c -- Image support routines. * - * Authors : Patrick LECOANET - * Creation date : Wed Dec 8 11:04:44 1999 + * Authors : Patrick LECOANET + * Creation date : Wed Dec 8 11:04:44 1999 */ /* @@ -44,65 +44,65 @@ static const char rcsid[] = "$Id$"; static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; -static int images_inited = 0; -static Tcl_HashTable images; +static int images_inited = 0; +static Tcl_HashTable images; #ifdef GL -static Tcl_HashTable font_textures; +static Tcl_HashTable font_textures; #endif typedef struct _ClientStruct { - void (*inv_proc)(void *cd); - void *client_data; + void (*inv_proc)(void *cd); + void *client_data; int refcount; } ClientStruct; typedef struct _ImageStruct { union { - Pixmap pixmap; + Pixmap pixmap; #ifdef GL - GLuint texobj; + GLuint texobj; #endif } i; - Display *dpy; - Screen *screen; + Display *dpy; + Screen *screen; struct _ImageBits *bits; /* Bookkeeping */ - ZnBool for_gl; - int refcount; - ZnList clients; - struct _ImageStruct *next; + ZnBool for_gl; + int refcount; + ZnList clients; + struct _ImageStruct *next; } ImageStruct, *Image; typedef struct _ImageBits { - unsigned char *bpixels; /* Needed for bitmaps. Set to NULL if the image - * is not a bitmap. */ - int rowstride; + unsigned char *bpixels; /* Needed for bitmaps. Set to NULL if the image + * is not a bitmap. */ + int rowstride; #ifdef GL - ZnReal t; /* Texture parameters for the image. */ - ZnReal s; - int t_width; /* Texture size used for this image. */ - int t_height; - unsigned char *t_bits; /* Can be NULL if texture is not used (no GL - * rendering active on this image). */ + ZnReal t; /* Texture parameters for the image. */ + ZnReal s; + int t_width; /* Texture size used for this image. */ + int t_height; + unsigned char *t_bits; /* Can be NULL if texture is not used (no GL + * rendering active on this image). */ #endif /* Bookeeping */ - Display *dpy; /* The tkimage below comes from this display. */ - Tcl_Interp *interp; /* The interp that created the tkimage below. */ - Tk_Image tkimage; /* Keep this handle to be informed of changes */ + Display *dpy; /* The tkimage below comes from this display. */ + Tcl_Interp *interp; /* The interp that created the tkimage below. */ + Tk_Image tkimage; /* Keep this handle to be informed of changes */ Tk_PhotoHandle tkphoto; - TkRegion valid_region; - int width; - int height; - int depth; - Tcl_HashEntry *hash; /* From this it is easy to get the image/bitmap - * name. */ - Image images; /* Linked list of widget/display dependant - * specializations of this image. If NULL, the - * image has no specialization and can be freed. */ + TkRegion valid_region; + int width; + int height; + int depth; + Tcl_HashEntry *hash; /* From this it is easy to get the image/bitmap + * name. */ + Image images; /* Linked list of widget/display dependant + * specializations of this image. If NULL, the + * image has no specialization and can be freed. */ } ImageBits; @@ -131,19 +131,19 @@ To2Power(int a) ********************************************************************************** */ static void -InvalidateImage(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) +InvalidateImage(ClientData client_data, + int x, + int y, + int width, + int height, + int image_width, + int image_height) { ImageBits *bits = (ImageBits *) client_data; - Image this; - int num_cs, count, i; + Image this; + int num_cs, count, i; ClientStruct *cs; - char *image_name; + char *image_name; /* printf("Invalidation, bits: %d, %d %d %d %d %d %d\n", client_data, x, y, width, height, image_width, image_height);*/ @@ -181,28 +181,28 @@ InvalidateImage(ClientData client_data, #ifdef GL if (this->for_gl) { if (this->i.texobj) { - ZnGLContextEntry *ce; - ce = ZnGLMakeCurrent(this->dpy, 0); - glDeleteTextures(1, &this->i.texobj); - ZnGLReleaseContext(ce); - this->i.texobj = 0; + ZnGLContextEntry *ce; + ce = ZnGLMakeCurrent(this->dpy, 0); + glDeleteTextures(1, &this->i.texobj); + ZnGLReleaseContext(ce); + this->i.texobj = 0; } } else { #endif if (this->i.pixmap != None) { - Tk_FreePixmap(this->dpy, this->i.pixmap); - this->i.pixmap = None; + Tk_FreePixmap(this->dpy, this->i.pixmap); + this->i.pixmap = None; } #ifdef GL } #endif - + num_cs = ZnListSize(this->clients); cs = ZnListArray(this->clients); for (i = 0; i < num_cs; i++, cs++) { if (cs->inv_proc) { - (*cs->inv_proc)(cs->client_data); + (*cs->inv_proc)(cs->client_data); } } count += num_cs; @@ -213,18 +213,18 @@ InvalidateImage(ClientData client_data, } ZnImage -ZnGetImage(ZnWInfo *wi, - Tk_Uid image_name, - void (*inv_proc)(void *cd), - void *client_data) +ZnGetImage(ZnWInfo *wi, + Tk_Uid image_name, + void (*inv_proc)(void *cd), + void *client_data) { - Tcl_HashEntry *entry; - int new, num_cs, i; - ImageBits *bits; - ZnBool for_gl = wi->render>0; - Image image; - Tk_ImageType *type; - ClientStruct cs, *cs_ptr; + Tcl_HashEntry *entry; + int new, num_cs, i; + ImageBits *bits; + ZnBool for_gl = wi->render>0; + Image image; + Tk_ImageType *type; + ClientStruct cs, *cs_ptr; /*printf("ZnGetImage: %s\n", image_name);*/ if (!images_inited) { @@ -260,32 +260,32 @@ ZnGetImage(ZnWInfo *wi, * This doesn't seem to be a Tk image, try to load * a Tk bitmap. */ - Pixmap pmap; - XImage *mask; - int x, y; + Pixmap pmap; + XImage *mask; + int x, y; unsigned char *line; pmap = Tk_GetBitmap(wi->interp, wi->win, image_name); if (pmap == None) { - ZnWarning("unknown bitmap/image \""); - goto im_error; + ZnWarning("unknown bitmap/image \""); + goto im_error; } Tk_SizeOfBitmap(wi->dpy, pmap, &bits->width, &bits->height); mask = XGetImage(wi->dpy, pmap, 0, 0, (unsigned int) bits->width, - (unsigned int) bits->height, 1L, XYPixmap); + (unsigned int) bits->height, 1L, XYPixmap); bits->depth = 1; bits->rowstride = mask->bytes_per_line; bits->bpixels = ZnMalloc((unsigned int) (bits->height * bits->rowstride)); memset(bits->bpixels, 0, (unsigned int) (bits->height * bits->rowstride)); line = bits->bpixels; for (y = 0; y < bits->height; y++) { - for (x = 0; x < bits->width; x++) { - if (XGetPixel(mask, x, y)) { - line[x >> 3] |= 0x80 >> (x & 7); - } - } - line += bits->rowstride; + for (x = 0; x < bits->width; x++) { + if (XGetPixel(mask, x, y)) { + line[x >> 3] |= 0x80 >> (x & 7); + } + } + line += bits->rowstride; } XDestroyImage(mask); Tk_FreeBitmap(wi->dpy, pmap); @@ -296,27 +296,27 @@ ZnGetImage(ZnWInfo *wi, bits->tkphoto = Tk_FindPhoto(wi->interp, image_name); Tk_PhotoGetSize(bits->tkphoto, &bits->width, &bits->height); if ((bits->width == 0) || (bits->height == 0)) { - ZnWarning("bogus photo image \""); - goto im_error; + ZnWarning("bogus photo image \""); + goto im_error; } bits->depth = Tk_Depth(wi->win); bits->tkimage = Tk_GetImage(wi->interp, wi->win, image_name, - InvalidateImage, (ClientData) bits); + InvalidateImage, (ClientData) bits); } else { /* Other image types */ bits->depth = Tk_Depth(wi->win); bits->tkimage = Tk_GetImage(wi->interp, wi->win, image_name, - InvalidateImage, (ClientData) bits); + InvalidateImage, (ClientData) bits); Tk_SizeOfImage(bits->tkimage, &bits->width, &bits->height); if ((bits->width == 0) || (bits->height == 0)) { - ZnWarning("bogus "); - ZnWarning(type->name); - ZnWarning(" image \""); + ZnWarning("bogus "); + ZnWarning(type->name); + ZnWarning(" image \""); im_error: - ZnWarning(image_name); - ZnWarning("\"\n"); - ZnFree(bits); - return ZnUnspecifiedImage; + ZnWarning(image_name); + ZnWarning("\"\n"); + ZnFree(bits); + return ZnUnspecifiedImage; } } @@ -331,27 +331,27 @@ ZnGetImage(ZnWInfo *wi, for (image = bits->images; image != NULL; image = image->next) { if (image->for_gl == for_gl) { if ((for_gl && (image->dpy == wi->dpy)) || - (!for_gl && (image->screen == wi->screen))) { - if (!ZnImageIsBitmap(image)) { - cs_ptr = ZnListArray(image->clients); - num_cs = ZnListSize(image->clients); - for (i = 0; i < num_cs; i++, cs_ptr++) { - if ((cs_ptr->inv_proc == inv_proc) && - (cs_ptr->client_data == client_data)) { - cs_ptr->refcount++; - return image; - } - } - /* Add a new client reference to call back. - */ - cs.inv_proc = inv_proc; - cs.client_data = client_data; - cs.refcount = 1; - ZnListAdd(image->clients, &cs, ZnListTail); - return image; - } - image->refcount++; - return image; + (!for_gl && (image->screen == wi->screen))) { + if (!ZnImageIsBitmap(image)) { + cs_ptr = ZnListArray(image->clients); + num_cs = ZnListSize(image->clients); + for (i = 0; i < num_cs; i++, cs_ptr++) { + if ((cs_ptr->inv_proc == inv_proc) && + (cs_ptr->client_data == client_data)) { + cs_ptr->refcount++; + return image; + } + } + /* Add a new client reference to call back. + */ + cs.inv_proc = inv_proc; + cs.client_data = client_data; + cs.refcount = 1; + ZnListAdd(image->clients, &cs, ZnListTail); + return image; + } + image->refcount++; + return image; } } } @@ -388,7 +388,7 @@ ZnGetImage(ZnWInfo *wi, else { image->i.pixmap = None; /* image->i.pixmap = Tk_GetBitmap(wi->interp, wi->win, image_name); - printf("pmap: %d\n", image->i.pixmap);*/ + printf("pmap: %d\n", image->i.pixmap);*/ } image->next = bits->images; bits->images = image; @@ -405,13 +405,13 @@ ZnGetImage(ZnWInfo *wi, ********************************************************************************** */ ZnImage -ZnGetImageByValue(ZnImage image, - void (*inv_proc)(void *cd), - void *client_data) +ZnGetImageByValue(ZnImage image, + void (*inv_proc)(void *cd), + void *client_data) { - Image this = (Image) image; - ClientStruct cs, *cs_ptr; - int i, num_cs; + Image this = (Image) image; + ClientStruct cs, *cs_ptr; + int i, num_cs; /*printf("ZnGetImageByValue: %s\n", ZnNameOfImage(image));*/ if (!ZnImageIsBitmap(image)) { @@ -419,9 +419,9 @@ ZnGetImageByValue(ZnImage image, num_cs = ZnListSize(this->clients); for (i = 0; i < num_cs; i++, cs_ptr++) { if ((cs_ptr->inv_proc == inv_proc) && - (cs_ptr->client_data == client_data)) { - cs_ptr->refcount++; - return image; + (cs_ptr->client_data == client_data)) { + cs_ptr->refcount++; + return image; } } cs.inv_proc = inv_proc; @@ -444,7 +444,7 @@ ZnGetImageByValue(ZnImage image, ********************************************************************************** */ ZnBool -ZnImageIsBitmap(ZnImage image) +ZnImageIsBitmap(ZnImage image) { return (((Image) image)->bits->bpixels != NULL); } @@ -457,14 +457,14 @@ ZnImageIsBitmap(ZnImage image) ********************************************************************************** */ void -ZnFreeImage(ZnImage image, - void (*inv_proc)(void *cd), - void *client_data) +ZnFreeImage(ZnImage image, + void (*inv_proc)(void *cd), + void *client_data) { - Image prev, scan, this = ((Image) image); - ImageBits *bits = this->bits; - ClientStruct *cs_ptr; - int i, num_cs, rm_image; + Image prev, scan, this = ((Image) image); + ImageBits *bits = this->bits; + ClientStruct *cs_ptr; + int i, num_cs, rm_image; /*printf("ZnFreeImage: %s\n", ZnNameOfImage(image));*/ /* @@ -481,12 +481,12 @@ ZnFreeImage(ZnImage image, num_cs = ZnListSize(this->clients); for (i = 0; i < num_cs; i++, cs_ptr++) { if ((cs_ptr->inv_proc == inv_proc) && - (cs_ptr->client_data == client_data)) { - cs_ptr->refcount--; - if (cs_ptr->refcount == 0) { - ZnListDelete(this->clients, i); - } - break; + (cs_ptr->client_data == client_data)) { + cs_ptr->refcount--; + if (cs_ptr->refcount == 0) { + ZnListDelete(this->clients, i); + } + break; } } rm_image = ZnListSize(this->clients)==0; @@ -515,7 +515,7 @@ ZnFreeImage(ZnImage image, ZnGLContextEntry *ce; ce = ZnGLMakeCurrent(this->dpy, 0); /* printf("%d Liberation de la texture %d pour l'image %s\n", - wi, this->i.texobj, ZnNameOfImage(image));*/ + wi, this->i.texobj, ZnNameOfImage(image));*/ glDeleteTextures(1, &this->i.texobj); this->i.texobj = 0; ZnGLReleaseContext(ce); @@ -573,7 +573,7 @@ ZnFreeImage(ZnImage image, ********************************************************************************** */ char * -ZnNameOfImage(ZnImage image) +ZnNameOfImage(ZnImage image) { return Tcl_GetHashKey(&images, ((Image) image)->bits->hash); } @@ -587,11 +587,11 @@ ZnNameOfImage(ZnImage image) ********************************************************************************** */ void -ZnSizeOfImage(ZnImage image, - int *width, - int *height) +ZnSizeOfImage(ZnImage image, + int *width, + int *height) { - Image this = (Image) image; + Image this = (Image) image; *width = this->bits->width; *height = this->bits->height; @@ -606,16 +606,16 @@ ZnSizeOfImage(ZnImage image, ********************************************************************************** */ Pixmap -ZnImagePixmap(ZnImage image, - Tk_Window win) +ZnImagePixmap(ZnImage image, + Tk_Window win) { - Image this = (Image) image; - ImageBits *bits = this->bits; + Image this = (Image) image; + ImageBits *bits = this->bits; /*printf("ZnImagePixmap: %s\n", ZnNameOfImage(image));*/ if (this->for_gl) { fprintf(stderr, - "Bogus use of an image, it was created for GL and used in an X11 context\n"); + "Bogus use of an image, it was created for GL and used in an X11 context\n"); return None; } @@ -633,19 +633,19 @@ ZnImagePixmap(ZnImage image, * instance on the right display. */ if (bits->dpy == this->dpy) { - tkimage = bits->tkimage; + tkimage = bits->tkimage; } else { - /* Create a temporary tkimage to draw the pixmap. */ - tkimage = Tk_GetImage(bits->interp, win, ZnNameOfImage(image), NULL, NULL); + /* Create a temporary tkimage to draw the pixmap. */ + tkimage = Tk_GetImage(bits->interp, win, ZnNameOfImage(image), NULL, NULL); } this->i.pixmap = Tk_GetPixmap(this->dpy, Tk_WindowId(win), - bits->width, bits->height, bits->depth); + bits->width, bits->height, bits->depth); Tk_RedrawImage(tkimage, 0, 0, bits->width, bits->height, this->i.pixmap, 0, 0); if (tkimage != bits->tkimage) { - Tk_FreeImage(tkimage); + Tk_FreeImage(tkimage); } } } @@ -659,19 +659,19 @@ ZnImagePixmap(ZnImage image, * * ZnPointInImage -- * - * Return whether the given point is inside the image. + * Return whether the given point is inside the image. * ********************************************************************************** */ ZnBool -ZnPointInImage(ZnImage image, - int x, - int y) +ZnPointInImage(ZnImage image, + int x, + int y) { if (ZnImageIsBitmap(image)) { ImageBits *bits = ((Image) image)->bits; if ((x < 0) || (y < 0) || - (x >= bits->width) || (y >= bits->height)) { + (x >= bits->width) || (y >= bits->height)) { return False; } return ZnGetBitmapPixel(bits->bpixels, bits->rowstride, x, y); @@ -687,19 +687,19 @@ ZnPointInImage(ZnImage image, * * ZnImageRegion -- * - * Only defined for Tk images (including Tk images defined from bitmaps). + * Only defined for Tk images (including Tk images defined from bitmaps). * ********************************************************************************** */ static void -BuildImageRegion(Display *dpy, - ImageBits *bits) +BuildImageRegion(Display *dpy, + ImageBits *bits) { - Pixmap pmap; - int x, y, end; - GC gc; - XImage *im1, *im2; - XRectangle rect; + Pixmap pmap; + int x, y, end; + GC gc; + XImage *im1, *im2; + XRectangle rect; /*printf("BuildImageRegion: %s\n", ZnNameOfImage(bits->images));*/ pmap = Tk_GetPixmap(dpy, DefaultRootWindow(dpy), bits->width, bits->height, bits->depth); @@ -722,22 +722,22 @@ BuildImageRegion(Display *dpy, x = 0; while (x < bits->width) { while ((x < bits->width) && - (XGetPixel(im1, x, y) != XGetPixel(im2, x, y))) { - /* Search the first non-transparent pixel */ - x++; + (XGetPixel(im1, x, y) != XGetPixel(im2, x, y))) { + /* Search the first non-transparent pixel */ + x++; } end = x; while ((end < bits->width) && - (XGetPixel(im1, end, y) == XGetPixel(im2, end, y))) { - /* Search the first transparent pixel */ - end++; + (XGetPixel(im1, end, y) == XGetPixel(im2, end, y))) { + /* Search the first transparent pixel */ + end++; } if (end > x) { - rect.x = x; - rect.y = y; - rect.width = end - x; - rect.height = 1; - TkUnionRectWithRegion(&rect, bits->valid_region, bits->valid_region); + rect.x = x; + rect.y = y; + rect.width = end - x; + rect.height = 1; + TkUnionRectWithRegion(&rect, bits->valid_region, bits->valid_region); } x = end; } @@ -748,14 +748,14 @@ BuildImageRegion(Display *dpy, } TkRegion -ZnImageRegion(ZnImage image) +ZnImageRegion(ZnImage image) { if (ZnImageIsBitmap(image)) { return NULL; } else { - Image this = (Image) image; - ImageBits *bits = this->bits; + Image this = (Image) image; + ImageBits *bits = this->bits; #ifdef PTK if (!bits->valid_region) { BuildImageRegion(this->dpy, bits); @@ -767,7 +767,7 @@ ZnImageRegion(ZnImage image) } else { if (!bits->valid_region) { - BuildImageRegion(this->dpy, bits); + BuildImageRegion(this->dpy, bits); } return bits->valid_region; } @@ -791,19 +791,19 @@ ZnImageRegion(ZnImage image) */ static void From5r6g5b(unsigned char *data, - int width, - int height, - int bytes_per_line, - unsigned char *t_bits, - int t_width, - int t_height, - TkRegion valid_region) + int width, + int height, + int bytes_per_line, + unsigned char *t_bits, + int t_width, + int t_height, + TkRegion valid_region) { - int x, y; - int rowstride = t_width * 4; - unsigned char *obptr; - unsigned char *bptr, *bp2; - unsigned char alpha; + int x, y; + int rowstride = t_width * 4; + unsigned char *obptr; + unsigned char *bptr, *bp2; + unsigned char alpha; unsigned short temp; bptr = t_bits; @@ -825,7 +825,7 @@ From5r6g5b(unsigned char *data, bp2++; *bp2 = (temp >> 3) & 0xfc; /* v */ bp2++; - *bp2 = (temp << 3); /* b */ + *bp2 = (temp << 3); /* b */ bp2++; *bp2 = alpha; bp2++; @@ -852,19 +852,19 @@ From5r6g5b(unsigned char *data, static void From8r8g8b(unsigned char *data, - int width, - int height, - int bytes_per_line, - unsigned char *t_bits, - int t_width, - int t_height, - TkRegion valid_region) + int width, + int height, + int bytes_per_line, + unsigned char *t_bits, + int t_width, + int t_height, + TkRegion valid_region) { - int x, y; - int rowstride = t_width * 4; - unsigned char *obptr; - unsigned char *bptr, *bp2; - unsigned char alpha; + int x, y; + int rowstride = t_width * 4; + unsigned char *obptr; + unsigned char *bptr, *bp2; + unsigned char alpha; bptr = t_bits; @@ -908,13 +908,13 @@ From8r8g8b(unsigned char *data, } static void -GatherImageTexels(Display *dpy, - ImageBits *bits) +GatherImageTexels(Display *dpy, + ImageBits *bits) { - Pixmap pmap; - XImage *im; - TkRegion valid_region; - int t_size; + Pixmap pmap; + XImage *im; + TkRegion valid_region; + int t_size; /*printf("GatherImageTexels: %s\n", ZnNameOfImage(bits->images));*/ valid_region = ZnImageRegion(bits->images); @@ -923,32 +923,32 @@ GatherImageTexels(Display *dpy, bits->t_bits = ZnMalloc(t_size); pmap = Tk_GetPixmap(dpy, DefaultRootWindow(dpy), - bits->width, bits->height, bits->depth); + bits->width, bits->height, bits->depth); Tk_RedrawImage(bits->tkimage, 0, 0, bits->width, bits->height, pmap, 0, 0); im = XGetImage(dpy, pmap, 0, 0, bits->width, bits->height, ~0L, ZPixmap); Tk_FreePixmap(dpy, pmap); if (bits->depth == 16) { From5r6g5b(im->data, bits->width, bits->height, im->bytes_per_line, - bits->t_bits, bits->t_width, bits->t_height, valid_region); + bits->t_bits, bits->t_width, bits->t_height, valid_region); } else if ((bits->depth == 24) || (bits->depth == 32)) { From8r8g8b(im->data, bits->width, bits->height, im->bytes_per_line, - bits->t_bits, bits->t_width, bits->t_height, valid_region); + bits->t_bits, bits->t_width, bits->t_height, valid_region); } XDestroyImage(im); } GLuint -ZnImageTex(ZnImage image, - ZnReal *t, - ZnReal *s) +ZnImageTex(ZnImage image, + ZnReal *t, + ZnReal *s) { - Image this = (Image) image; - ImageBits *bits = this->bits; - ZnBool is_bmap = ZnImageIsBitmap(image); - unsigned int t_size, width, height; + Image this = (Image) image; + ImageBits *bits = this->bits; + ZnBool is_bmap = ZnImageIsBitmap(image); + unsigned int t_size, width, height; if (!this->for_gl) { fprintf(stderr, "Bogus use of an image, it was created for X11 and used in a GL context\n"); @@ -975,13 +975,13 @@ ZnImageTex(ZnImage image, ostart = bits->bpixels; dstart = bits->t_bits; for (i = 0; i < height; i++) { - d = dstart; - o = ostart; - for (j = 0; j < width; j++) { - *d++ = ZnGetBitmapPixel(bits->bpixels, bits->rowstride, j, i) ? 255 : 0; - } - ostart += bits->rowstride; - dstart += bits->t_width; + d = dstart; + o = ostart; + for (j = 0; j < width; j++) { + *d++ = ZnGetBitmapPixel(bits->bpixels, bits->rowstride, j, i) ? 255 : 0; + } + ostart += bits->rowstride; + dstart += bits->t_width; } } @@ -989,9 +989,9 @@ ZnImageTex(ZnImage image, * This is a photo: use the photo API, it is simple. */ else if (bits->tkphoto) { - unsigned int x, y, t_stride; - unsigned char *obptr, *bptr, *bp2, *pixels; - int green_off, blue_off, alpha_off; + unsigned int x, y, t_stride; + unsigned char *obptr, *bptr, *bp2, *pixels; + int green_off, blue_off, alpha_off; Tk_PhotoImageBlock block; t_stride = bits->t_width * 4; @@ -1007,34 +1007,34 @@ ZnImageTex(ZnImage image, alpha_off = block.offset[3] - block.offset[0]; #endif /*printf("width %d, height: %d redoff: %d, greenoff: %d, blueoff: %d, alphaoff: %d\n", - block.width, block.height, block.offset[0], green_off, - blue_off, alpha_off);*/ + block.width, block.height, block.offset[0], green_off, + blue_off, alpha_off);*/ pixels = block.pixelPtr; bptr = bits->t_bits; for (y = 0; y < height; y++) { - bp2 = bptr; - obptr = pixels; - for (x = 0; x < width; x++) { - *bp2++ = obptr[0]; /* r */ - *bp2++ = obptr[green_off]; /* g */ - *bp2++ = obptr[blue_off]; /* b */ - *bp2++ = obptr[alpha_off]; /* alpha */ - obptr += block.pixelSize; - } - /*for (x = width; x < t_width; x++) { - *bp2 = 0; bp2++; - *bp2 = 0; bp2++; - *bp2 = 0; bp2++; - *bp2 = 0; bp2++; - }*/ - bptr += t_stride; - pixels += block.pitch; + bp2 = bptr; + obptr = pixels; + for (x = 0; x < width; x++) { + *bp2++ = obptr[0]; /* r */ + *bp2++ = obptr[green_off]; /* g */ + *bp2++ = obptr[blue_off]; /* b */ + *bp2++ = obptr[alpha_off]; /* alpha */ + obptr += block.pixelSize; + } + /*for (x = width; x < t_width; x++) { + *bp2 = 0; bp2++; + *bp2 = 0; bp2++; + *bp2 = 0; bp2++; + *bp2 = 0; bp2++; + }*/ + bptr += t_stride; + pixels += block.pitch; } /*for (y = height; y < t_height; y++) { - memset(bptr, 0, t_stride); - bptr += t_stride; - }*/ + memset(bptr, 0, t_stride); + bptr += t_stride; + }*/ } /* @@ -1059,13 +1059,13 @@ ZnImageTex(ZnImage image, glGetError(); if (is_bmap) { glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY4, - this->bits->t_width, this->bits->t_height, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, this->bits->t_bits); + this->bits->t_width, this->bits->t_height, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, this->bits->t_bits); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, - this->bits->t_width, this->bits->t_height, - 0, GL_RGBA, GL_UNSIGNED_BYTE, this->bits->t_bits); + this->bits->t_width, this->bits->t_height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, this->bits->t_bits); } if (glGetError() != GL_NO_ERROR) { ZnWarning("Can't allocate the texture for image "); @@ -1088,34 +1088,34 @@ ZnImageTex(ZnImage image, typedef struct _TexFontInfo { struct _TexFont *txf; - GLuint texobj; - Display *dpy; - unsigned int refcount; + GLuint texobj; + Display *dpy; + unsigned int refcount; struct _TexFontInfo *next; } TexFontInfo; typedef struct { - short width; + short width; } PerGlyphInfo, *PerGlyphInfoPtr; typedef struct _TexFont { - TexFontInfo *tfi; - Tk_Font tkfont; - unsigned int tex_width; - unsigned int tex_height; - int ascent; - int descent; - unsigned int max_char_width; + TexFontInfo *tfi; + Tk_Font tkfont; + unsigned int tex_width; + unsigned int tex_height; + int ascent; + int descent; + unsigned int max_char_width; unsigned char *teximage; - unsigned int num_glyphs; - PerGlyphInfo *glyph; - ZnTexGVI *tgvi; - Tcl_HashEntry *hash; + unsigned int num_glyphs; + PerGlyphInfo *glyph; + ZnTexGVI *tgvi; + Tcl_HashEntry *hash; } TexFont; typedef struct _DeferredGLGlyphs { - ZnWInfo *wi; - TexFont *txf; + ZnWInfo *wi; + TexFont *txf; } DeferredGLGlyphsStruct; ZnList DeferredGLGlyphs; @@ -1129,26 +1129,26 @@ ZnList DeferredGLGlyphs; static void -SuckGlyphsFromServer(ZnWInfo *wi, - TexFont *txf) +SuckGlyphsFromServer(ZnWInfo *wi, + TexFont *txf) { - Pixmap offscreen = 0; - XImage *image = NULL; - GC xgc = 0; - unsigned int height, length, pixwidth; - unsigned int i, j, use_max_width; - unsigned int wgap=2, hgap=2, tex_width, tex_height; - unsigned char *to; - unsigned int x, y; - unsigned int width=0, maxSpanLength; - int grabList[MAX_GLYPHS_PER_GRAB]; - unsigned int glyphsPerGrab = MAX_GLYPHS_PER_GRAB; - unsigned int numToGrab, glyph; - ZnTexGVI *tgvip; + Pixmap offscreen = 0; + XImage *image = NULL; + GC xgc = 0; + unsigned int height, length, pixwidth; + unsigned int i, j, use_max_width; + unsigned int wgap=2, hgap=2, tex_width, tex_height; + unsigned char *to; + unsigned int x, y; + unsigned int width=0, maxSpanLength; + int grabList[MAX_GLYPHS_PER_GRAB]; + unsigned int glyphsPerGrab = MAX_GLYPHS_PER_GRAB; + unsigned int numToGrab, glyph; + ZnTexGVI *tgvip; Tk_FontMetrics fm; - CONST unsigned char *cur, *next; + CONST unsigned char *cur, *next; #ifndef PTK_800 - Tcl_UniChar uni_ch; + Tcl_UniChar uni_ch; #endif ZnGLContextEntry *ce = ZnGetGLContext(wi->dpy); @@ -1198,7 +1198,7 @@ SuckGlyphsFromServer(ZnWInfo *wi, use_max_width = 1; tex_height += height + hgap; if ((tex_height > ce->max_tex_size) || (length > ce->max_tex_size)) { - goto FreeAndReturn; + goto FreeAndReturn; } } @@ -1262,7 +1262,7 @@ SuckGlyphsFromServer(ZnWInfo *wi, } pixwidth = glyphsPerGrab * 8 * maxSpanLength; offscreen = Tk_GetPixmap(wi->dpy, RootWindowOfScreen(wi->screen), - (int) pixwidth, (int) height, 1); + (int) pixwidth, (int) height, 1); xgc = XCreateGC(wi->dpy, offscreen, 0, NULL); XSetForeground(wi->dpy, xgc, WhitePixelOfScreen(wi->screen)); @@ -1283,7 +1283,7 @@ SuckGlyphsFromServer(ZnWInfo *wi, #endif if (txf->glyph[i].width != 0) { Tk_DrawChars(wi->dpy, offscreen, xgc, txf->tkfont, cur, next - cur, - (int) (8*maxSpanLength*numToGrab), txf->ascent); + (int) (8*maxSpanLength*numToGrab), txf->ascent); grabList[numToGrab] = i; numToGrab++; } @@ -1292,39 +1292,39 @@ SuckGlyphsFromServer(ZnWInfo *wi, image = XGetImage(wi->dpy, offscreen, 0, 0, pixwidth, height, 1, XYPixmap); for (j = 0; j < numToGrab; j++) { - glyph = grabList[j]; - width = txf->glyph[glyph].width; - tgvip = &txf->tgvi[glyph]; - to = txf->teximage + (int) (tgvip->t0y * tex_width) + (int) tgvip->t0x; - tgvip->t0x = tgvip->t0x / (GLfloat) tex_width; - tgvip->t0y = tgvip->t0y / (GLfloat) tex_height; - tgvip->t1x = tgvip->t1x / (GLfloat) tex_width; - tgvip->t1y = tgvip->t1y / (GLfloat) tex_height; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++, to++) { - /* XXX The algorithm used to suck across the font ensures that - each glyph begins on a byte boundary. In theory this would - make it convienent to copy the glyph into a byte oriented - bitmap. We actually use the XGetPixel function to extract - each pixel from the image which is not that efficient. We - could either do tighter packing in the pixmap or more - efficient extraction from the image. Oh well. */ - if (XGetPixel(image, (int) (j*maxSpanLength*8) + x, y) == BlackPixelOfScreen(wi->screen)) { - *to = 255; - } - } - to += tex_width - width; - } + glyph = grabList[j]; + width = txf->glyph[glyph].width; + tgvip = &txf->tgvi[glyph]; + to = txf->teximage + (int) (tgvip->t0y * tex_width) + (int) tgvip->t0x; + tgvip->t0x = tgvip->t0x / (GLfloat) tex_width; + tgvip->t0y = tgvip->t0y / (GLfloat) tex_height; + tgvip->t1x = tgvip->t1x / (GLfloat) tex_width; + tgvip->t1y = tgvip->t1y / (GLfloat) tex_height; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++, to++) { + /* XXX The algorithm used to suck across the font ensures that + each glyph begins on a byte boundary. In theory this would + make it convienent to copy the glyph into a byte oriented + bitmap. We actually use the XGetPixel function to extract + each pixel from the image which is not that efficient. We + could either do tighter packing in the pixmap or more + efficient extraction from the image. Oh well. */ + if (XGetPixel(image, (int) (j*maxSpanLength*8) + x, y) == BlackPixelOfScreen(wi->screen)) { + *to = 255; + } + } + to += tex_width - width; + } } XDestroyImage(image); image = NULL; numToGrab = 0; /* do we need to clear the offscreen pixmap to get more? */ if (i < txf->num_glyphs - 1) { - XSetForeground(wi->dpy, xgc, WhitePixelOfScreen(wi->screen)); - XFillRectangle(wi->dpy, offscreen, xgc, 0, 0, - 8 * maxSpanLength * glyphsPerGrab, height); - XSetForeground(wi->dpy, xgc, BlackPixelOfScreen(wi->screen)); + XSetForeground(wi->dpy, xgc, WhitePixelOfScreen(wi->screen)); + XFillRectangle(wi->dpy, offscreen, xgc, 0, 0, + 8 * maxSpanLength * glyphsPerGrab, height); + XSetForeground(wi->dpy, xgc, BlackPixelOfScreen(wi->screen)); } } @@ -1355,11 +1355,11 @@ SuckGlyphsFromServer(ZnWInfo *wi, } static void -ZnNeedToGetGLGlyphs(ZnWInfo *wi, - TexFont *txf) +ZnNeedToGetGLGlyphs(ZnWInfo *wi, + TexFont *txf) { DeferredGLGlyphsStruct dgg, *dggp; - int i, num; + int i, num; if (!DeferredGLGlyphs) { DeferredGLGlyphs = ZnListNew(4, sizeof(DeferredGLGlyphsStruct)); @@ -1382,7 +1382,7 @@ void ZnGetDeferredGLGlyphs(void) { DeferredGLGlyphsStruct *dggp; - int i, num = ZnListSize(DeferredGLGlyphs); + int i, num = ZnListSize(DeferredGLGlyphs); if (!num) { return; @@ -1395,10 +1395,10 @@ ZnGetDeferredGLGlyphs(void) } static void -ZnRemovedDeferredGLGlyph(TexFont *txf) +ZnRemovedDeferredGLGlyph(TexFont *txf) { DeferredGLGlyphsStruct *dggp; - int i, num; + int i, num; dggp = ZnListArray(DeferredGLGlyphs); num = ZnListSize(DeferredGLGlyphs); @@ -1419,14 +1419,14 @@ ZnRemovedDeferredGLGlyph(TexFont *txf) ********************************************************************************** */ ZnTexFontInfo -ZnGetTexFont(ZnWInfo *wi, - Tk_Font font) +ZnGetTexFont(ZnWInfo *wi, + Tk_Font font) { - TexFont *txf; - TexFontInfo *tfi; - static int inited = 0; - Tcl_HashEntry *entry; - int new; + TexFont *txf; + TexFontInfo *tfi; + static int inited = 0; + Tcl_HashEntry *entry; + int new; if (!inited) { Tcl_InitHashTable(&font_textures, TCL_STRING_KEYS); @@ -1434,8 +1434,8 @@ ZnGetTexFont(ZnWInfo *wi, } /* printf("family: %s, size: %d, weight: %d, slant: %d, underline: %d, overstrike: %d\n", - tft->fa.family, tft->fa.size, tft->fa.weight, tft->fa.slant, tft->fa.underline, - tft->fa.overstrike); + tft->fa.family, tft->fa.size, tft->fa.weight, tft->fa.slant, tft->fa.underline, + tft->fa.overstrike); */ entry = Tcl_FindHashEntry(&font_textures, Tk_NameOfFont(font)); if (entry != NULL) { @@ -1500,7 +1500,7 @@ ZnGetTexFont(ZnWInfo *wi, ********************************************************************************** */ char const * -ZnNameOfTexFont(ZnTexFontInfo tfi) +ZnNameOfTexFont(ZnTexFontInfo tfi) { return Tk_NameOfFont(((TexFontInfo *) tfi)->txf->tkfont); } @@ -1513,10 +1513,10 @@ ZnNameOfTexFont(ZnTexFontInfo tfi) ********************************************************************************** */ GLuint -ZnTexFontTex(ZnTexFontInfo tfi) +ZnTexFontTex(ZnTexFontInfo tfi) { - TexFontInfo *this = (TexFontInfo *) tfi; - TexFont *txf = this->txf; + TexFontInfo *this = (TexFontInfo *) tfi; + TexFont *txf = this->txf; if (!txf->teximage) { return 0; @@ -1533,8 +1533,8 @@ ZnTexFontTex(ZnTexFontInfo tfi) glGetError(); /*printf("Demande texture de %d x %d\n", txf->tex_width, txf->tex_height);*/ glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, txf->tex_width, - txf->tex_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, - txf->teximage); + txf->tex_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, + txf->teximage); if (glGetError() != GL_NO_ERROR) { ZnWarning("Can't allocate the texture for font "); ZnWarning(ZnNameOfTexFont(tfi)); @@ -1556,11 +1556,11 @@ ZnTexFontTex(ZnTexFontInfo tfi) ********************************************************************************** */ void -ZnFreeTexFont(ZnTexFontInfo tfi) +ZnFreeTexFont(ZnTexFontInfo tfi) { - TexFontInfo *this = ((TexFontInfo *) tfi); - TexFont *txf = this->txf; - TexFontInfo *prev, *scan; + TexFontInfo *this = ((TexFontInfo *) tfi); + TexFont *txf = this->txf; + TexFontInfo *prev, *scan; for (prev=NULL, scan=this->txf->tfi; (scan!=NULL)&&(scan != this); prev=scan, scan=scan->next); @@ -1626,12 +1626,12 @@ ZnFreeTexFont(ZnTexFontInfo tfi) ********************************************************************************** */ int -ZnGetFontIndex(ZnTexFontInfo tfi, - int c) +ZnGetFontIndex(ZnTexFontInfo tfi, + int c) { - TexFont *txf; - ZnTexGVI *tgvi; - int code, min, max, mid; + TexFont *txf; + ZnTexGVI *tgvi; + int code, min, max, mid; if (c < 127) { /* @@ -1676,12 +1676,12 @@ ZnGetFontIndex(ZnTexFontInfo tfi, ********************************************************************************** */ ZnTexGVI * -ZnTexFontGVI(ZnTexFontInfo tfi, - int c) +ZnTexFontGVI(ZnTexFontInfo tfi, + int c) { - TexFont *txf = ((TexFontInfo *) tfi)->txf; - ZnTexGVI *tgvi = NULL; - int index; + TexFont *txf = ((TexFontInfo *) tfi)->txf; + ZnTexGVI *tgvi = NULL; + int index; index = ZnGetFontIndex(tfi, c); if (index >= 0) { |