]>
Commit | Line | Data |
---|---|---|
a3145df4 | 1 | --- tk8.0-8.0.5.orig/generic/tkImgBmap.c Mon Sep 14 13:23:12 1998 |
2 | +++ tk8.0-8.0.5/generic/tkImgBmap.c Fri Nov 27 17:07:29 1998 | |
3 | @@ -479,6 +479,21 @@ | |
4 | char *data = NULL; | |
5 | Tcl_DString buffer; | |
6 | ||
7 | +/* ==================================================================== */ | |
8 | +/* The pilbitmap booster patch -- patch section */ | |
9 | +/* ==================================================================== */ | |
10 | + | |
11 | + char *PILGetBitmapData(); | |
12 | + | |
13 | + if (string) { | |
14 | + /* Is this a PIL bitmap reference? */ | |
15 | + data = PILGetBitmapData(string, widthPtr, heightPtr, hotXPtr, hotYPtr); | |
16 | + if (data) | |
17 | + return data; | |
18 | + } | |
19 | + | |
20 | +/* ==================================================================== */ | |
21 | + | |
22 | pi.string = string; | |
23 | if (string == NULL) { | |
24 | if ((interp != NULL) && Tcl_IsSafe(interp)) { | |
25 | @@ -1066,3 +1081,95 @@ | |
26 | return buffer; | |
27 | } | |
28 | } | |
29 | + | |
30 | +/* ==================================================================== */ | |
31 | +/* The pilbitmap booster patch -- code section */ | |
32 | +/* ==================================================================== */ | |
33 | + | |
34 | +/* Imaging declaration boldly copied from Imaging.h (!) */ | |
35 | + | |
36 | +typedef struct ImagingInstance *Imaging; /* a.k.a. ImagingImage :-) */ | |
37 | + | |
38 | +typedef unsigned char UINT8; | |
39 | +/*typedef int INT32;*/ | |
40 | + | |
41 | +struct ImagingInstance { | |
42 | + | |
43 | + /* Format */ | |
44 | + char mode[4+1]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK") */ | |
45 | + int type; /* Always 0 in this version */ | |
46 | + int depth; /* Always 8 in this version */ | |
47 | + int bands; /* Number of bands (1, 3, or 4) */ | |
48 | + int xsize; /* Image dimension. */ | |
49 | + int ysize; | |
50 | + | |
51 | + /* Colour palette (for "P" images only) */ | |
52 | + void* palette; | |
53 | + | |
54 | + /* Data pointers */ | |
55 | + UINT8 **image8; /* Set for 8-bit image (pixelsize=1). */ | |
56 | + INT32 **image32; /* Set for 32-bit image (pixelsize=4). */ | |
57 | + | |
58 | + /* Internals */ | |
59 | + char **image; /* Actual raster data. */ | |
60 | + char *block; /* Set if data is allocated in a single block. */ | |
61 | + | |
62 | + int pixelsize; /* Size of a pixel, in bytes (1 or 4) */ | |
63 | + int linesize; /* Size of a line, in bytes (xsize * pixelsize) */ | |
64 | + | |
65 | + /* Virtual methods */ | |
66 | + void (*im_delete)(Imaging *); | |
67 | + | |
68 | +}; | |
69 | + | |
70 | +/* The pilbitmap booster patch allows you to pass PIL images to the | |
71 | + Tk bitmap decoder. Passing images this way is much more efficient | |
72 | + than using the "tobitmap" method. */ | |
73 | + | |
74 | +char * | |
75 | +PILGetBitmapData(string, widthPtr, heightPtr, hotXPtr, hotYPtr) | |
76 | + char *string; | |
77 | + int *widthPtr, *heightPtr; | |
78 | + int *hotXPtr, *hotYPtr; | |
79 | +{ | |
80 | + char* data; | |
81 | + char* p; | |
82 | + int y; | |
83 | + Imaging im; | |
84 | + | |
85 | + if (strncmp(string, "PIL:", 4) != 0) | |
86 | + return NULL; | |
87 | + | |
88 | + im = (Imaging) atol(string + 4); | |
89 | + | |
90 | + if (strcmp(im->mode, "1") != 0 && strcmp(im->mode, "L") != 0) | |
91 | + return NULL; | |
92 | + | |
93 | + data = p = (char *) ckalloc((unsigned) ((im->xsize+7)/8) * im->ysize); | |
94 | + | |
95 | + for (y = 0; y < im->ysize; y++) { | |
96 | + char* in = im->image8[y]; | |
97 | + int i, m, b; | |
98 | + b = 0; m = 1; | |
99 | + for (i = 0; i < im->xsize; i++) { | |
100 | + if (in[i] != 0) | |
101 | + b |= m; | |
102 | + m <<= 1; | |
103 | + if (m == 256){ | |
104 | + *p++ = b; | |
105 | + b = 0; m = 1; | |
106 | + } | |
107 | + } | |
108 | + if (m != 1) | |
109 | + *p++ = b; | |
110 | + } | |
111 | + | |
112 | + *widthPtr = im->xsize; | |
113 | + *heightPtr = im->ysize; | |
114 | + *hotXPtr = -1; | |
115 | + *hotYPtr = -1; | |
116 | + | |
117 | + return data; | |
118 | +} | |
119 | + | |
120 | +/* ==================================================================== */ |