First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xprint / ps / PsArea.c
blob6ab9fa25cee6eb440f3dd2fd4ab7a3e1f4fcaadc
1 /*
3 Copyright 1996, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 * (c) Copyright 1996 Hewlett-Packard Company
28 * (c) Copyright 1996 International Business Machines Corp.
29 * (c) Copyright 1996, 2000 Sun Microsystems, Inc.
30 * (c) Copyright 1996 Novell, Inc.
31 * (c) Copyright 1996 Digital Equipment Corp.
32 * (c) Copyright 1996 Fujitsu Limited
33 * (c) Copyright 1996 Hitachi, Ltd.
35 * Permission is hereby granted, free of charge, to any person obtaining
36 * a copy of this software and associated documentation files (the
37 * "Software"), to deal in the Software without restriction, including
38 * without limitation the rights to use, copy, modify, merge, publish,
39 * distribute, sublicense, and/or sell copies of the Software, and to
40 * permit persons to whom the Software is furnished to do so, subject
41 * to the following conditions:
43 * The above copyright notice and this permission notice shall be included
44 * in all copies or substantial portions of the Software.
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
51 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52 * SOFTWARE.
54 * Except as contained in this notice, the names of the copyright holders
55 * shall not be used in advertising or otherwise to promote the sale, use
56 * or other dealings in this Software without prior written authorization
57 * from said copyright holders.
60 /*******************************************************************
62 ** *********************************************************
63 ** *
64 ** * File: PsArea.c
65 ** *
66 ** * Contents: Image and Area functions for the PS DDX driver
67 ** *
68 ** * Created By: Roger Helmendach (Liberty Systems)
69 ** *
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
71 ** *
72 ** *********************************************************
73 **
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
78 #endif
80 #include "Ps.h"
81 #include "gcstruct.h"
82 #include "windowstr.h"
85 void
86 PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
87 int w, int h, int leftPad, int format, int imageRes, char *pImage)
89 if( pDrawable->type==DRAWABLE_PIXMAP )
91 int size = PixmapBytePad(w, depth)*h;
92 DisplayElmPtr elm;
93 PixmapPtr pix = (PixmapPtr)pDrawable;
94 PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
95 DisplayListPtr disp;
96 GCPtr gc;
98 if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
100 disp = PsGetFreeDisplayBlock(priv);
101 elm = &disp->elms[disp->nelms];
102 elm->type = PutImageCmd;
103 elm->gc = gc;
104 elm->c.image.depth = depth;
105 elm->c.image.x = x;
106 elm->c.image.y = y;
107 elm->c.image.w = w;
108 elm->c.image.h = h;
109 elm->c.image.leftPad = leftPad;
110 elm->c.image.format = format;
111 elm->c.image.res = imageRes;
112 elm->c.image.pData = (char *)xalloc(size);
113 memcpy(elm->c.image.pData, pImage, size);
114 disp->nelms += 1;
116 else
118 int i, j;
119 int r, c;
120 PsOutPtr psOut;
121 ColormapPtr cMap;
122 int pageRes, sw, sh;
124 if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
125 if (!imageRes) {
126 sw = w;
127 sh = h;
128 } else {
129 pageRes = XpGetResolution(XpGetPrintContext(requestingClient));
130 sw = (float)w * (float)pageRes / (float)imageRes + 0.5;
131 sh = (float)h * (float)pageRes / (float)imageRes + 0.5;
133 PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
135 if( depth!=1 )
137 PsOut_BeginImage(psOut, 0, 0, x, y, w, h, sw, sh, 3);
139 for( r=0 ; r<h ; r++ )
141 for( c=0 ; c<w ; c++ )
143 unsigned long pv = PsGetImagePixel(pImage, depth, w, h, leftPad, format, c, r);
144 PsOutColor clr = PsGetPixelColor(cMap, pv);
145 /* XXX: This needs to be fixed for endian swapping and to support
146 * depths deeper than 8bit per R-,G-,B-gun... */
147 unsigned long val = PSOUTCOLOR_TO_RGB24BIT(clr);
148 char *ipt = (char *)&val;
149 /* XXX: Is this the right way to detect the platform endianess ? */
150 #if IMAGE_BYTE_ORDER == LSBFirst
152 long l;
153 swapl(&val, l);
155 #elif IMAGE_BYTE_ORDER == MSBFirst
156 #else
157 #error Unsupported byte order
158 #endif
159 PsOut_OutImageBytes(psOut, 3, &ipt[1]);
163 PsOut_EndImage(psOut);
165 else
167 int rowsiz = BitmapBytePad(w);
168 int psrsiz = (w+7)/8;
169 PsOut_BeginImage(psOut, PsGetPixelColor(cMap, pGC->bgPixel),
170 PsGetPixelColor(cMap, pGC->fgPixel),
171 x, y, w, h, sw, sh, 1);
172 for( r=0 ; r<h ; r++ )
174 char *pt = &pImage[rowsiz*r];
175 for( i=0 ; i<psrsiz ; i++ )
177 int iv_, iv = (int)pt[i]&0xFF;
178 char c;
179 /* XXX: Is this the right way to detect the platform endianess ? */
180 #if IMAGE_BYTE_ORDER == LSBFirst
181 { for( j=0,iv_=0 ; j<8 ; j++ ) iv_ |= (((iv>>j)&1)<<(7-j)); }
182 #elif IMAGE_BYTE_ORDER == MSBFirst
183 iv_ = iv;
184 #else
185 #error Unsupported byte order
186 #endif
187 c = iv_;
188 PsOut_OutImageBytes(psOut, 1, &c);
191 PsOut_EndImage(psOut);
196 void
197 PsPutScaledImageIM(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
198 int w, int h, int leftPad, int format, int imageRes, char *pImage)
200 if( pDrawable->type==DRAWABLE_PIXMAP )
202 int size = PixmapBytePad(w, depth)*h;
203 DisplayElmPtr elm;
204 PixmapPtr pix = (PixmapPtr)pDrawable;
205 PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
206 DisplayListPtr disp;
207 GCPtr gc;
209 if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
211 disp = PsGetFreeDisplayBlock(priv);
212 elm = &disp->elms[disp->nelms];
213 elm->type = PutImageCmd;
214 elm->gc = gc;
215 elm->c.image.depth = depth;
216 elm->c.image.x = x;
217 elm->c.image.y = y;
218 elm->c.image.w = w;
219 elm->c.image.h = h;
220 elm->c.image.leftPad = leftPad;
221 elm->c.image.format = format;
222 elm->c.image.res = imageRes;
223 elm->c.image.pData = (char *)xalloc(size);
224 memcpy(elm->c.image.pData, pImage, size);
225 disp->nelms += 1;
227 else
229 int i, j;
230 int r, c;
231 PsOutPtr psOut;
232 ColormapPtr cMap;
233 int pageRes, sw, sh;
234 #ifdef BM_CACHE
235 long cache_id = 0;
236 #endif
238 if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
239 if (!imageRes) {
240 sw = w;
241 sh = h;
242 } else {
243 pageRes = XpGetResolution(XpGetPrintContext(requestingClient));
244 sw = (float)w * (float)pageRes / (float)imageRes + 0.5;
245 sh = (float)h * (float)pageRes / (float)imageRes + 0.5;
247 PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
249 #ifdef BM_CACHE
250 cache_id = PsBmIsImageCached(w, h, pImage);
252 if(!cache_id)
254 cache_id = PsBmPutImageInCache(w, h, pImage);
256 if(!cache_id)
257 return;
259 PsOut_BeginImageCache(psOut, cache_id);
260 #endif
261 if( depth!=1 )
263 PsOut_BeginImageIM(psOut, 0, 0, x, y, w, h, sw, sh, 3);
265 for( r=0 ; r<h ; r++ )
267 for( c=0 ; c<w ; c++ )
269 unsigned long pv = PsGetImagePixel(pImage, depth, w, h, leftPad, format, c, r);
270 PsOutColor clr = PsGetPixelColor(cMap, pv);
271 /* XXX: This needs to be fixed for endian swapping and to support
272 * depths deeper than 8bit per R-,G-,B-gun... */
273 unsigned long val = PSOUTCOLOR_TO_RGB24BIT(clr);
274 char *ipt = (char *)&val;
275 /* XXX: Is this the right way to detect the platform endianess ? */
276 #if IMAGE_BYTE_ORDER == LSBFirst
278 long l;
279 swapl(&val, l);
281 #elif IMAGE_BYTE_ORDER == MSBFirst
282 #else
283 #error Unsupported byte order
284 #endif
285 PsOut_OutImageBytes(psOut, 3, &ipt[1]);
289 PsOut_EndImage(psOut);
291 else
293 int rowsiz = BitmapBytePad(w);
294 int psrsiz = (w+7)/8;
295 PsOut_BeginImageIM(psOut, PsGetPixelColor(cMap, pGC->bgPixel),
296 PsGetPixelColor(cMap, pGC->fgPixel),
297 x, y, w, h, sw, sh, 1);
298 for( r=0 ; r<h ; r++ )
300 char *pt = &pImage[rowsiz*r];
301 for( i=0 ; i<psrsiz ; i++ )
303 int iv_, iv = (int)pt[i]&0xFF;
304 char c;
305 /* XXX: Is this the right way to detect the platform endianess ? */
306 #if IMAGE_BYTE_ORDER == LSBFirst
307 { for( j=0,iv_=0 ; j<8 ; j++ ) iv_ |= (((iv>>j)&1)<<(7-j)); }
308 #elif IMAGE_BYTE_ORDER == MSBFirst
309 iv_ = iv;
310 #else
311 #error Unsupported byte order
312 #endif
313 c = iv_;
314 PsOut_OutImageBytes(psOut, 1, &c);
317 PsOut_EndImage(psOut);
319 #ifdef BM_CACHE
320 PsOut_EndImageCache(psOut);
322 PsOut_ImageCache(psOut, x, y, cache_id, PsGetPixelColor(cMap, pGC->bgPixel),
323 PsGetPixelColor(cMap, pGC->fgPixel));
324 #endif
327 void
328 PsPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
329 int w, int h, int leftPad, int format, char *pImage)
331 XpContextPtr pcon;
332 if (requestingClient && (pcon = XpGetPrintContext(requestingClient)))
333 PsPutScaledImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format,
334 pcon->imageRes, pImage);
336 void
337 PsPutImageMask(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
338 int w, int h, int leftPad, int format, char *pImage)
340 XpContextPtr pcon;
341 if (requestingClient && (pcon = XpGetPrintContext(requestingClient)))
342 PsPutScaledImageIM(pDrawable, pGC, depth, x, y, w, h, leftPad, format,
343 pcon->imageRes, pImage);
346 RegionPtr
347 PsCopyArea(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC, int srcx, int srcy,
348 int width, int height, int dstx, int dsty)
350 PixmapPtr src = (PixmapPtr)pSrc;
351 PixmapPtr dst = (PixmapPtr)pDst;
353 if( pSrc->type!=DRAWABLE_PIXMAP ) return NULL;
354 if( pDst->type!=DRAWABLE_PIXMAP )
356 PsOutPtr psOut;
357 ColormapPtr cMap;
358 if( PsUpdateDrawableGC(pGC, pDst, &psOut, &cMap)==FALSE ) return NULL;
359 PsOut_Offset(psOut, pDst->x, pDst->y);
360 PsOut_BeginFrame(psOut, dstx-srcx, dsty-srcy, dstx, dsty, width, height);
361 PsReplayPixmap(src, pDst);
362 PsOut_EndFrame(psOut);
364 else PsCopyDisplayList(src, dst, dstx-srcx, dsty-srcy, dstx, dsty,
365 width, height);
366 return NULL;
369 RegionPtr
370 PsCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC, int srcx, int srcy,
371 int width, int height, int dstx, int dsty, unsigned long plane)
373 PixmapPtr src = (PixmapPtr)pSrc;
374 PixmapPtr dst = (PixmapPtr)pDst;
376 if( pSrc->type!=DRAWABLE_PIXMAP ) return NULL;
377 if( pDst->type!=DRAWABLE_PIXMAP )
379 PsOutPtr psOut;
380 ColormapPtr cMap;
381 if( PsUpdateDrawableGC(pGC, pDst, &psOut, &cMap)==FALSE ) return NULL;
382 PsOut_Offset(psOut, pDst->x, pDst->y);
383 PsOut_BeginFrame(psOut, dstx-srcx, dsty-srcy, dstx, dsty, width, height);
384 PsReplayPixmap(src, pDst);
385 PsOut_EndFrame(psOut);
387 else PsCopyDisplayList(src, dst, dstx-srcx, dsty-srcy, dstx, dsty,
388 width, height);
389 return NULL;