1
/* $Xorg: medraw.c,v 1.4 2001/02/09 02:04:24 xorgcvs Exp $ */
2
/**** module medraw.c ****/
3
/******************************************************************************
5
Copyright 1993, 1994, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
30
This software is being provided by AGE Logic, Inc. under the
31
following license. By obtaining, using and/or copying this software,
32
you agree that you have read, understood, and will comply with these
35
Permission to use, copy, modify, distribute and sell this
36
software and its documentation for any purpose and without
37
fee or royalty and to grant others any or all rights granted
38
herein is hereby granted, provided that you agree to comply
39
with the following copyright notice and statements, including
40
the disclaimer, and that the same appears on all copies and
41
derivative works of the software and documentation you make.
43
"Copyright 1993, 1994 by AGE Logic, Inc."
45
THIS SOFTWARE IS PROVIDED "AS IS". AGE LOGIC MAKES NO
46
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way of
47
example, but not limitation, AGE LOGIC MAKE NO
48
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
49
FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
50
INFRINGE THIRD-PARTY PROPRIETARY RIGHTS. AGE LOGIC
51
SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE. IN NO
52
EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
53
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
54
OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
55
ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
56
BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
57
HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
60
The name of AGE Logic, Inc. may not be used in
61
advertising or publicity pertaining to this software without
62
specific, written prior permission from AGE Logic.
64
Title to this software shall at all times remain with AGE
66
*****************************************************************************
68
medraw.c -- DDXIE prototype export drawable element
70
Robert NC Shelley -- AGE Logic, Inc. April, 1993
72
*****************************************************************************/
73
/* $XFree86: xc/programs/Xserver/XIE/mixie/export/medraw.c,v 3.6 2001/12/14 19:58:19 dawes Exp $ */
93
* more X server includes.
96
#include <dixstruct.h>
97
#include <pixmapstr.h>
100
* Server XIE Includes
111
* routines referenced by other DDXIE modules
113
extern int miAnalyzeEDraw(floDefPtr flo, peDefPtr ped);
116
* routines used internal to this module
118
static int CreateEDraw(floDefPtr flo, peDefPtr ped);
119
static int InitializeEDraw(floDefPtr flo, peDefPtr ped);
120
static int ActivateEDrawAlign(floDefPtr flo, peDefPtr ped, peTexPtr pet);
121
static int ActivateEDrawStrip(floDefPtr flo, peDefPtr ped, peTexPtr pet);
122
static int ResetEDraw(floDefPtr flo, peDefPtr ped);
123
static int DestroyEDraw(floDefPtr flo, peDefPtr ped);
125
static void adjustStride8to4(char *dst, char *src, CARD32 width);
126
static void adjustStride32to24(char *dst, char *src, CARD32 width);
128
extern Bool DrawableAndGC();
131
* DDXIE ExportDrawable entry points
133
static ddElemVecRec EDrawVec = {
142
typedef struct _medraw {
145
} meDrawRec, *meDrawPtr;
148
/*------------------------------------------------------------------------
149
------------------- see if we can handle this element --------------------
150
------------------------------------------------------------------------*/
151
int miAnalyzeEDraw(floDefPtr flo, peDefPtr ped)
153
/* for now just stash our entry point vector in the peDef */
154
ped->ddVec = EDrawVec;
157
} /* end miAnalyzeEDraw */
159
/*------------------------------------------------------------------------
160
---------------------------- create peTex . . . --------------------------
161
------------------------------------------------------------------------*/
162
static int CreateEDraw(floDefPtr flo, peDefPtr ped)
164
/* attach an execution context to the photo element definition */
165
return MakePETex(flo, ped, sizeof(meDrawRec), NO_SYNC, NO_SYNC);
166
} /* end CreateEDraw */
168
/*------------------------------------------------------------------------
169
---------------------------- initialize peTex . . . ----------------------
170
------------------------------------------------------------------------*/
171
static int InitializeEDraw(floDefPtr flo, peDefPtr ped)
173
peTexPtr pet = ped->peTex;
174
meDrawPtr ddx = (meDrawPtr) pet->private;
175
formatPtr sf = &ped->inFloLst[SRCtag].format[0];
176
formatPtr df = &ped->outFlo.format[0];
177
Bool adj_stride = sf->stride != df->stride;
178
Bool adj_pitch = sf->pitch != df->pitch;
180
if(adj_stride || adj_pitch) {
181
ped->ddVec.activate = ActivateEDrawAlign;
184
if(!(ddx->buf = (char*) XieMalloc(df->pitch>>3)))
185
AllocError(flo,ped, return(FALSE));
187
if(sf->stride == 32 && df->stride == 24)
188
ddx->adjust = adjustStride32to24;
190
else if(sf->stride == 8 && df->stride == 4)
191
ddx->adjust = adjustStride8to4;
193
/* add more adjustment routines as required */
196
ped->ddVec.activate = ActivateEDrawStrip;
198
return(InitReceptors(flo,ped,NO_DATAMAP,1));
199
} /* end InitializeEDraw */
202
/*------------------------------------------------------------------------
203
----------------------------- crank some data ----------------------------
204
------------------------------------------------------------------------*/
205
static int ActivateEDrawAlign(floDefPtr flo, peDefPtr ped, peTexPtr pet)
207
xieFloExportDrawable *raw = (xieFloExportDrawable *) ped->elemRaw;
208
eDrawDefPtr dix = (eDrawDefPtr) ped->elemPvt;
209
meDrawPtr ddx = (meDrawPtr) pet->private;
210
bandPtr bnd = &pet->receptor[SRCtag].band[0];
211
char *dst, *src = (char*)GetCurrentSrc(flo,pet,bnd);
212
CARD32 width = bnd->format->width;
214
if (!DrawableAndGC(flo,ped,raw->drawable,raw->gc,&dix->pDraw,&dix->pGC))
219
dst = AlterSrc(flo,pet,bnd->strip) ? src : ddx->buf;
220
(*ddx->adjust)(dst, src, width);
224
(*dix->pGC->ops->PutImage)(dix->pDraw, /* drawable */
226
dix->pDraw->depth, /* depth */
227
raw->dstX, /* drawable-x */
228
raw->dstY + bnd->current, /* drawable-y */
229
width, 1, /* width, height */
230
bnd->strip->bitOff, /* padding? */
231
ZPixmap, /* data format */
232
dst /* data buffer */
234
} while ((src = (char*)GetNextSrc(flo,pet,bnd,KEEP)) != 0);
236
/* make sure the scheduler knows how much src we used */
237
FreeData(flo,pet,bnd,bnd->current);
240
} /* end ActivateEDrawAlign */
243
/*------------------------------------------------------------------------
244
----------------------------- crank some data ----------------------------
245
------------------------------------------------------------------------*/
246
static int ActivateEDrawStrip(floDefPtr flo, peDefPtr ped, peTexPtr pet)
248
xieFloExportDrawable *raw = (xieFloExportDrawable *) ped->elemRaw;
249
eDrawDefPtr pvt = (eDrawDefPtr) ped->elemPvt;
250
bandPtr bnd = &pet->receptor[SRCtag].band[0];
251
char *src = (char*)GetCurrentSrc(flo,pet,bnd);
254
if (!DrawableAndGC(flo,ped,raw->drawable,raw->gc,&pvt->pDraw,&pvt->pGC))
257
(*pvt->pGC->ops->PutImage)(pvt->pDraw, /* drawable */
259
pvt->pDraw->depth, /* depth */
260
raw->dstX, /* drawable-x */
261
raw->dstY+bnd->minLocal, /* drawable-y */
262
bnd->format->width, /* width */
263
bnd->strip->length, /* height */
264
bnd->strip->bitOff, /* padding? */
265
ZPixmap, /* data format */
266
src /* data buffer */
268
while ((src = (char*)GetSrc(flo,pet,bnd,bnd->maxLocal,KEEP)) != 0);
270
/* make sure the scheduler knows how much src we used */
271
FreeData(flo,pet,bnd,bnd->current);
274
} /* end ActivateEDrawStrip */
277
/*------------------------------------------------------------------------
278
------------------------ get rid of run-time stuff -----------------------
279
------------------------------------------------------------------------*/
280
static int ResetEDraw(floDefPtr flo, peDefPtr ped)
282
meDrawPtr ddx = (meDrawPtr) ped->peTex->private;
284
if(ddx->buf) ddx->buf = (char*)XieFree(ddx->buf);
285
ddx->adjust = (xieVoidProc)NULL;
290
} /* end ResetEDraw */
293
/*------------------------------------------------------------------------
294
-------------------------- get rid of this element -----------------------
295
------------------------------------------------------------------------*/
296
static int DestroyEDraw(floDefPtr flo, peDefPtr ped)
298
/* get rid of the peTex structure */
300
ped->peTex = (peTexPtr) XieFree(ped->peTex);
302
/* zap this element's entry point vector */
303
ped->ddVec.create = (xieIntProc) NULL;
304
ped->ddVec.initialize = (xieIntProc) NULL;
305
ped->ddVec.activate = (xieIntProc) NULL;
306
ped->ddVec.reset = (xieIntProc) NULL;
307
ped->ddVec.destroy = (xieIntProc) NULL;
310
} /* end DestroyEDraw */
313
/*------------------------------------------------------------------------
314
---------------------------- alignment routines --------------------------
315
------------------------------------------------------------------------*/
316
static void adjustStride32to24(char *dst, char *src, CARD32 width)
318
register char *ip, *op;
321
#if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
324
for(i = 0; i < width; ip += 2, ++i) {
325
*op++ = *ip++; *op++ = *ip++; *op++ = *ip;
328
/* we'll do the first 2 pixels by hand in case we're doing this in-place
342
for(i = 2; i < width; ip += 4, ++i) {
343
*op++ = ip[2]; *op++ = ip[1]; *op++ = *ip;
349
static void adjustStride8to4(char *dst, char *src, CARD32 width)
351
register char *ip = src, *op = dst;
354
for(i = 0; i < width; ip += 2, ++i) {
355
#if (BITMAP_BIT_ORDER == LSBFirst)
356
*op++ = *ip | *(ip+1)<<8;
358
*op++ = *ip<<8 | *(ip+1);
363
/* end module medraw.c */