OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [unix/] [tixUnixXpm.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixUnixImgXpm.c --
3
 *
4
 *      Implement the Windows specific function calls for the pixmap
5
 *      image type.
6
 *
7
 * Copyright (c) 1996, Expert Interface Technologies
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 */
13
 
14
#include <tixPort.h>
15
#include <tixUnixInt.h>
16
#include <tixImgXpm.h>
17
 
18
typedef struct PixmapData {
19
    Pixmap mask;                /* Mask: only display pixmap pixels where
20
                                 * there are 1's here. */
21
    GC gc;                      /* Graphics context for displaying pixmap.
22
                                 * None means there was an error while
23
                                 * setting up the instance, so it cannot
24
                                 * be displayed. */
25
} PixmapData;
26
 
27
 
28
/*----------------------------------------------------------------------
29
 * TixpInitPixmapInstance --
30
 *
31
 *      Initializes the platform-specific data of a pixmap instance
32
 *
33
 *----------------------------------------------------------------------
34
 */
35
 
36
void
37
TixpInitPixmapInstance(masterPtr, instancePtr)
38
    PixmapMaster *masterPtr;    /* Pointer to master for image. */
39
    PixmapInstance *instancePtr;/* The pixmap instance. */
40
{
41
    PixmapData * dataPtr;
42
 
43
    dataPtr = (PixmapData *)ckalloc(sizeof(PixmapData));
44
    dataPtr->mask = None;
45
    dataPtr->gc = None;
46
 
47
    instancePtr->clientData = (ClientData)dataPtr;
48
}
49
 
50
/*----------------------------------------------------------------------
51
 * TixpXpmAllocTmpBuffer --
52
 *
53
 *      Allocate a temporary space to draw the image.
54
 *
55
 *----------------------------------------------------------------------
56
 */
57
 
58
void
59
TixpXpmAllocTmpBuffer(masterPtr, instancePtr, imagePtr, maskPtr)
60
    PixmapMaster * masterPtr;
61
    PixmapInstance * instancePtr;
62
    XImage ** imagePtr;
63
    XImage ** maskPtr;
64
{
65
    int pad;
66
    XImage * image = NULL, * mask = NULL;
67
    Display *display = Tk_Display(instancePtr->tkwin);
68
    int depth;
69
 
70
    depth = Tk_Depth(instancePtr->tkwin);
71
 
72
    if (depth > 16) {
73
        pad = 32;
74
    } else if (depth > 8) {
75
        pad = 16;
76
    } else {
77
        pad = 8;
78
    }
79
 
80
    /*
81
     * Create the XImage structures to store the temporary image
82
     */
83
    image = XCreateImage(display,
84
        Tk_Visual(instancePtr->tkwin),
85
        depth, ZPixmap, 0, 0,
86
        masterPtr->size[0], masterPtr->size[1], pad, 0);
87
    image->data =
88
      (char *)ckalloc(image->bytes_per_line * masterPtr->size[1]);
89
 
90
    mask  = XCreateImage(display,
91
        Tk_Visual(instancePtr->tkwin),
92
        1, XYPixmap, 0, 0,
93
        masterPtr->size[0], masterPtr->size[1], pad, 0);
94
 
95
    mask->data =
96
      (char *)ckalloc(mask->bytes_per_line  * masterPtr->size[1]);
97
 
98
    *imagePtr = image;
99
    *maskPtr = mask;
100
}
101
 
102
void
103
TixpXpmFreeTmpBuffer(masterPtr, instancePtr, image, mask)
104
    PixmapMaster * masterPtr;
105
    PixmapInstance * instancePtr;
106
    XImage * image;
107
    XImage * mask;
108
{
109
    if (image) {
110
        ckfree((char*)image->data);
111
        image->data = NULL;
112
        XDestroyImage(image);
113
    }
114
    if (mask) {
115
        ckfree((char*)mask->data);
116
        mask->data = NULL;
117
        XDestroyImage(mask);
118
    }
119
}
120
 
121
/*----------------------------------------------------------------------
122
 * TixpXpmSetPixel --
123
 *
124
 *      Sets the pixel at the given (x,y) coordinate to be the given
125
 *      color.
126
 *----------------------------------------------------------------------
127
 */
128
void
129
TixpXpmSetPixel(instancePtr, image, mask, x, y, colorPtr, isTranspPtr)
130
    PixmapInstance * instancePtr;
131
    XImage * image;
132
    XImage * mask;
133
    int x;
134
    int y;
135
    XColor * colorPtr;
136
    int * isTranspPtr;
137
{
138
    if (colorPtr != NULL) {
139
        XPutPixel(image, x, y, colorPtr->pixel);
140
        XPutPixel(mask,  x, y, 1);
141
    } else {
142
        XPutPixel(mask,  x, y, 0);
143
        *isTranspPtr = 1;
144
    }
145
}
146
 
147
/*----------------------------------------------------------------------
148
 * TixpXpmRealizePixmap --
149
 *
150
 *      On Unix:        Create the pixmap from the buffer.
151
 *      On Windows:     Free the mask if there are no transparent pixels.
152
 *----------------------------------------------------------------------
153
 */
154
 
155
void
156
TixpXpmRealizePixmap(masterPtr, instancePtr, image, mask, isTransp)
157
    PixmapMaster * masterPtr;
158
    PixmapInstance * instancePtr;
159
    XImage * image;
160
    XImage * mask;
161
    int isTransp;
162
{
163
    Display *display = Tk_Display(instancePtr->tkwin);
164
    int depth = Tk_Depth(instancePtr->tkwin);
165
    PixmapData *dataPtr = (PixmapData*)instancePtr->clientData;
166
    unsigned int gcMask;
167
    XGCValues gcValues;
168
    GC gc;
169
 
170
    instancePtr->pixmap = Tk_GetPixmap(display,
171
        Tk_WindowId(instancePtr->tkwin),
172
        masterPtr->size[0], masterPtr->size[1], depth);
173
 
174
    gc = Tk_GetGC(instancePtr->tkwin, 0, NULL);
175
 
176
    XPutImage(display, instancePtr->pixmap,
177
        gc, image, 0, 0, 0, 0, masterPtr->size[0], masterPtr->size[1]);
178
 
179
    Tk_FreeGC(display, gc);
180
 
181
    if (isTransp) {
182
        /*
183
         * There are transparent pixels. We need a mask.
184
         */
185
        dataPtr->mask = Tk_GetPixmap(display,
186
            Tk_WindowId(instancePtr->tkwin),
187
            masterPtr->size[0], masterPtr->size[1], 1);
188
        gc = XCreateGC(display, dataPtr->mask, 0, NULL);
189
        XPutImage(display, dataPtr->mask,
190
            gc, mask,  0, 0, 0, 0, masterPtr->size[0], masterPtr->size[1]);
191
        XFreeGC(display, gc);
192
    } else {
193
        dataPtr->mask = None;
194
    }
195
 
196
    /*
197
     * Allocate a GC for drawing this instance (mask is not used if there
198
     * is no transparent pixels inside the image).
199
     */
200
    if (dataPtr->mask != None) {
201
        gcMask = GCGraphicsExposures|GCClipMask;
202
    } else {
203
        gcMask = GCGraphicsExposures;
204
    }
205
    gcValues.graphics_exposures = False;
206
    gcValues.clip_mask = dataPtr->mask;
207
 
208
    gc = Tk_GetGC(instancePtr->tkwin, gcMask, &gcValues);
209
    dataPtr->gc = gc;
210
}
211
 
212
void
213
TixpXpmFreeInstanceData(instancePtr, delete, display)
214
    PixmapInstance *instancePtr;/* Pixmap instance. */
215
    int delete;                 /* Should the instance data structure
216
                                 * be deleted as well? */
217
    Display *display;           /* Display containing window that used image.*/
218
{
219
    PixmapData *dataPtr = (PixmapData*)instancePtr->clientData;
220
 
221
    if (dataPtr->mask != None) {
222
        Tk_FreePixmap(display, dataPtr->mask);
223
        dataPtr->mask = None;
224
    }
225
    if (dataPtr->gc != None) {
226
        Tk_FreeGC(display, dataPtr->gc);
227
        dataPtr->gc = None;
228
    }
229
    if (delete) {
230
        ckfree((char*)dataPtr);
231
        instancePtr->clientData = NULL;
232
    }
233
}
234
 
235
void
236
TixpXpmDisplay(clientData, display, drawable, imageX, imageY, width,
237
        height, drawableX, drawableY)
238
    ClientData clientData;      /* Pointer to PixmapInstance structure for
239
                                 * for instance to be displayed. */
240
    Display *display;           /* Display on which to draw image. */
241
    Drawable drawable;          /* Pixmap or window in which to draw image. */
242
    int imageX, imageY;         /* Upper-left corner of region within image
243
                                 * to draw. */
244
    int width, height;          /* Dimensions of region within image to draw.*/
245
    int drawableX, drawableY;   /* Coordinates within drawable that
246
                                 * correspond to imageX and imageY. */
247
{
248
    PixmapInstance *instancePtr = (PixmapInstance *) clientData;
249
    PixmapData *dataPtr = (PixmapData*)instancePtr->clientData;
250
 
251
    /*
252
     * If there's no graphics context, it means that an error occurred
253
     * while creating the image instance so it can't be displayed.
254
     */
255
    if (dataPtr->gc == None) {
256
        return;
257
    }
258
 
259
    /*
260
     * We always use clipping: modify the clip origin within
261
     * the graphics context to line up with the image's origin.
262
     * Then draw the image and reset the clip origin.
263
     */
264
    XSetClipOrigin(display, dataPtr->gc, drawableX - imageX,
265
        drawableY - imageY);
266
    XCopyArea(display, instancePtr->pixmap, drawable, dataPtr->gc,
267
        imageX, imageY, (unsigned) width, (unsigned) height,
268
        drawableX, drawableY);
269
    XSetClipOrigin(display, dataPtr->gc, 0, 0);
270
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.