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
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
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 ** *********************************************************
66 ** * Contents: Image and Area functions for the PS DDX driver
68 ** * Created By: Roger Helmendach (Liberty Systems)
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
72 ** *********************************************************
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
82 #include "windowstr.h"
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
;
93 PixmapPtr pix
= (PixmapPtr
)pDrawable
;
94 PsPixmapPrivPtr priv
= (PsPixmapPrivPtr
)pix
->devPrivate
.ptr
;
98 if ((gc
= PsCreateAndCopyGC(pDrawable
, pGC
)) == NULL
) return;
100 disp
= PsGetFreeDisplayBlock(priv
);
101 elm
= &disp
->elms
[disp
->nelms
];
102 elm
->type
= PutImageCmd
;
104 elm
->c
.image
.depth
= depth
;
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
);
124 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
) return;
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
);
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
155 #elif IMAGE_BYTE_ORDER == MSBFirst
157 #error Unsupported byte order
159 PsOut_OutImageBytes(psOut
, 3, &ipt
[1]);
163 PsOut_EndImage(psOut
);
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;
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
185 #error Unsupported byte order
188 PsOut_OutImageBytes(psOut
, 1, &c
);
191 PsOut_EndImage(psOut
);
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
;
204 PixmapPtr pix
= (PixmapPtr
)pDrawable
;
205 PsPixmapPrivPtr priv
= (PsPixmapPrivPtr
)pix
->devPrivate
.ptr
;
209 if ((gc
= PsCreateAndCopyGC(pDrawable
, pGC
)) == NULL
) return;
211 disp
= PsGetFreeDisplayBlock(priv
);
212 elm
= &disp
->elms
[disp
->nelms
];
213 elm
->type
= PutImageCmd
;
215 elm
->c
.image
.depth
= depth
;
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
);
238 if( PsUpdateDrawableGC(pGC
, pDrawable
, &psOut
, &cMap
)==FALSE
) return;
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
);
250 cache_id
= PsBmIsImageCached(w
, h
, pImage
);
254 cache_id
= PsBmPutImageInCache(w
, h
, pImage
);
259 PsOut_BeginImageCache(psOut
, cache_id
);
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
281 #elif IMAGE_BYTE_ORDER == MSBFirst
283 #error Unsupported byte order
285 PsOut_OutImageBytes(psOut
, 3, &ipt
[1]);
289 PsOut_EndImage(psOut
);
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;
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
311 #error Unsupported byte order
314 PsOut_OutImageBytes(psOut
, 1, &c
);
317 PsOut_EndImage(psOut
);
320 PsOut_EndImageCache(psOut
);
322 PsOut_ImageCache(psOut
, x
, y
, cache_id
, PsGetPixelColor(cMap
, pGC
->bgPixel
),
323 PsGetPixelColor(cMap
, pGC
->fgPixel
));
328 PsPutImage(DrawablePtr pDrawable
, GCPtr pGC
, int depth
, int x
, int y
,
329 int w
, int h
, int leftPad
, int format
, char *pImage
)
332 if (requestingClient
&& (pcon
= XpGetPrintContext(requestingClient
)))
333 PsPutScaledImage(pDrawable
, pGC
, depth
, x
, y
, w
, h
, leftPad
, format
,
334 pcon
->imageRes
, pImage
);
337 PsPutImageMask(DrawablePtr pDrawable
, GCPtr pGC
, int depth
, int x
, int y
,
338 int w
, int h
, int leftPad
, int format
, char *pImage
)
341 if (requestingClient
&& (pcon
= XpGetPrintContext(requestingClient
)))
342 PsPutScaledImageIM(pDrawable
, pGC
, depth
, x
, y
, w
, h
, leftPad
, format
,
343 pcon
->imageRes
, pImage
);
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
)
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
,
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
)
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
,