1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
/* $XConsortium: mefax.c,v 1.6 94/01/18 15:12:58 rws Exp $ */
/**** module mefax.c ****/
/******************************************************************************
Copyright (c) 1993, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
NOTICE
This software is being provided by AGE Logic, Inc. under the
following license. By obtaining, using and/or copying this software,
you agree that you have read, understood, and will comply with these
terms and conditions:
Permission to use, copy, modify, distribute and sell this
software and its documentation for any purpose and without
fee or royalty and to grant others any or all rights granted
herein is hereby granted, provided that you agree to comply
with the following copyright notice and statements, including
the disclaimer, and that the same appears on all copies and
derivative works of the software and documentation you make.
"Copyright 1993, 1994 by AGE Logic, Inc."
THIS SOFTWARE IS PROVIDED "AS IS". AGE LOGIC MAKES NO
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way of
example, but not limitation, AGE LOGIC MAKE NO
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
INFRINGE THIRD-PARTY PROPRIETARY RIGHTS. AGE LOGIC
SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE. IN NO
EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
The name of AGE Logic, Inc. may not be used in
advertising or publicity pertaining to this software without
specific, written prior permission from AGE Logic.
Title to this software shall at all times remain with AGE
Logic, Inc.
*****************************************************************************
mefax.c -- DDXIE prototype export photomap coded with one of
many FAX techiques (g31d,g32d,g42d,tiff2,packbits)
Ben Fahy -- AGE Logic, Inc. Oct, 1993
*****************************************************************************/
#define _XIEC_MEPHOTO
#define _XIEC_EPHOTO
/*
* Include files
*/
#include <stdio.h>
/*
* Core X Includes
*/
#include <X.h>
#include <Xproto.h>
/*
* XIE Includes
*/
#include <XIE.h>
#include <XIEproto.h>
/*
* more X server includes.
*/
#include <misc.h>
#include <dixstruct.h>
/*
* Server XIE Includes
*/
#include <error.h>
#include <macro.h>
#include <photomap.h>
#include <element.h>
#include <texstr.h>
#include <../include/fax.h> /* XXX - ugh! */
#include <../fax/fencode.h> /* XXX - even ugh-ier! */
#include <xiemd.h>
/*
* routines referenced by other DDXIE modules
*/
int CreateEPhotoFAX();
int InitializeEPhotoFAX();
int ActivateEPhotoFAX();
int ResetEPhotoFAX();
int DestroyEPhotoFAX();
int InitializeECPhotoFAX();
/* ECPhoto Create routines are shared */
/* ECPhoto Activate routines are shared */
/* ECPhoto Reset routines are shared */
/* ECPhoto Destroy routines are shared */
/*
* routines used internal to this module
*/
static int common_init();
static int sub_fun();
static void FreeFaxData();
/*
* Local Declarations
*/
typedef struct _fax_encode_pvt {
int (*encodptr)(); /* function used to encode the data */
FaxEncodeState state; /* holds all coding info for FAX dudes */
int notify; /* relevant for ECPhoto only */
int encoded_order; /* LSfirst or MSfirst */
xieTypEncodeTechnique encode_technique;
char *tech_params; /* scroll away technique information */
int height; /* image height, so we know when done */
int strip_req_newbytes;
/* when we GetDstBytes, how much */
} faxPvtRec, *faxPvtPtr;
#define MaybeSwapOutput() \
if (texpvt->encoded_order == xieValLSFirst) { \
register int size=dbnd->maxLocal-dbnd->minLocal; \
register unsigned char *ucp = dst; \
while (size--) \
{ \
*ucp = _ByteReverseTable[*ucp]; \
ucp++; \
} \
}
/*------------------------------------------------------------------------
---------------------------- create peTex . . . --------------------------
------------------------------------------------------------------------*/
int CreateEPhotoFAX(flo,ped)
floDefPtr flo;
peDefPtr ped;
{
/* attach an execution context to the photo element definition */
return(MakePETex(flo, ped, sizeof(faxPvtRec), NO_SYNC, NO_SYNC));
} /* end CreateEPhotoFAX */
/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
int InitializeEPhotoFAX(flo,ped)
floDefPtr flo;
peDefPtr ped;
{
ePhotoDefPtr pvt = (ePhotoDefPtr)ped->elemPvt;
return( common_init(flo,ped,pvt->encodeParms,pvt->encodeNumber) );
}
/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
int InitializeECPhotoFAX(flo,ped)
floDefPtr flo;
peDefPtr ped;
{
xieFloExportClientPhoto *raw = (xieFloExportClientPhoto *) ped->elemRaw;
peTexPtr pet = ped->peTex;
faxPvtPtr texpvt = (faxPvtPtr)pet->private;
ePhotoDefPtr pvt = (ePhotoDefPtr)ped->elemPvt;
if( !common_init(flo,ped,pvt->encodeParms,pvt->encodeNumber) )
return FALSE;
texpvt->notify = raw->notify;
return TRUE;
}
/*------------------------------------------------------------------------
------- lots of stuff shared between ECPhoto and EPhoto. . . -------------
------------------------------------------------------------------------*/
static int common_init(flo,ped,tec,encodeTechnique)
floDefPtr flo;
peDefPtr ped;
char *tec;
CARD16 encodeTechnique;
{
peTexPtr pet = ped->peTex;
faxPvtPtr texpvt=(faxPvtPtr) pet->private;
formatPtr inf = pet->receptor[0].band[0].format;
FaxEncodeState *state = &texpvt->state;
int pbytes,max_lines_in;
/* every time we run, reset this */
bzero(texpvt,sizeof(faxPvtRec));
/* now save away protocol technique info */
texpvt->encode_technique = encodeTechnique;
texpvt->tech_params = tec;
/* we also need width */
state->width = inf->width;
texpvt->height = inf->height;
/* do technique-dependent initialization */
switch(encodeTechnique) {
case xieValEncodeG31D:
{
G31DEncodePvt *epvt;
xieTecEncodeG31D *g31dtec = (xieTecEncodeG31D *)tec;
state->goal = ENCODE_FAX_GOAL_StartNewLine;
state->radiometric = g31dtec->radiometric;
texpvt->encoded_order = g31dtec->encodedOrder;
/* set up data private to this technique */
epvt = (G31DEncodePvt *) XieMalloc(sizeof(G31DEncodePvt));
bzero(epvt,sizeof(G31DEncodePvt));
epvt->counts = (int *) XieMalloc((state->width+1) * sizeof(int));
if (!epvt->counts) {
FreeFaxData(flo,ped);
AllocError(flo, ped, return(FALSE));
}
epvt->align_eol = g31dtec->alignEol;
state->private = (pointer ) epvt;
texpvt->encodptr = encode_g31d;
}
break;
case xieValEncodeG32D:
{
G32DEncodePvt *epvt;
xieTecEncodeG32D *g32dtec = (xieTecEncodeG32D *)tec;
state->goal = ENCODE_FAX_GOAL_StartNewLine;
state->radiometric = g32dtec->radiometric;
texpvt->encoded_order = g32dtec->encodedOrder;
/* set up data private to this technique */
epvt = (G32DEncodePvt *) XieMalloc(sizeof(G32DEncodePvt));
bzero(epvt,sizeof(G32DEncodePvt));
epvt->counts = (int *) XieMalloc((state->width+1) * sizeof(int));
epvt->above = (int *) XieMalloc((state->width+1) * sizeof(int));
if (!epvt->counts || !epvt->above) {
FreeFaxData(flo,ped);
AllocError(flo, ped, return(FALSE));
}
epvt->k = g32dtec->kFactor;
epvt->align_eol = g32dtec->alignEol;
epvt->uncompressed = g32dtec->uncompressed;
state->private = (pointer ) epvt;
}
texpvt->encodptr = encode_g32d;
break;
case xieValEncodeG42D:
{
G42DEncodePvt *epvt;
xieTecEncodeG42D *g42dtec = (xieTecEncodeG42D *)tec;
state->goal = ENCODE_FAX_GOAL_StartNewLine;
texpvt->encoded_order = g42dtec->encodedOrder;
state->radiometric = g42dtec->radiometric;
/* set up data private to this technique */
epvt = (G42DEncodePvt *) XieMalloc(sizeof(G42DEncodePvt));
bzero(epvt,sizeof(G42DEncodePvt));
epvt->counts = (int *) XieMalloc((state->width+1) * sizeof(int));
epvt->above = (int *) XieMalloc((state->width+1) * sizeof(int));
if (!epvt->counts || !epvt->above) {
FreeFaxData(flo,ped);
AllocError(flo, ped, return(FALSE));
}
/* for G4, initialize imaginary line to "all white" */
epvt->counts[0] = state->width;
epvt->nvals = 1;
epvt->uncompressed = ((xieTecEncodeG42D *)tec)->uncompressed;
epvt->really_g4 = 1;
state->private = (pointer ) epvt;
}
texpvt->encodptr = encode_g32d;
break;
case xieValEncodeTIFF2:
{
Tiff2EncodePvt *epvt;
xieTecEncodeTIFF2 *tiff2tec = (xieTecEncodeTIFF2 *)tec;
state->goal = ENCODE_FAX_GOAL_StartNewLine;
state->radiometric = tiff2tec->radiometric;
texpvt->encoded_order = tiff2tec->encodedOrder;
/* set up data private to this technique */
epvt = (Tiff2EncodePvt *) XieMalloc(sizeof(Tiff2EncodePvt));
bzero(epvt,sizeof(Tiff2EncodePvt));
epvt->counts = (int *) XieMalloc((state->width+1) * sizeof(int));
if (!epvt->counts) {
FreeFaxData(flo,ped);
AllocError(flo, ped, return(FALSE));
}
state->private = (pointer ) epvt;
}
texpvt->encodptr = encode_tiff2;
break;
case xieValEncodeTIFFPackBits:
{
PackBitsEncodePvt *epvt;
xieTecEncodeTIFFPackBits *tiffpbtec = (xieTecEncodeTIFFPackBits *)tec;
state->goal = ENCODE_FAX_GOAL_StartNewLine;
state->width = 8 * ((state->width + 7)/8);
/* packbits assumes lines are padded to an even byte */
texpvt->encoded_order = tiffpbtec->encodedOrder;
/* set up data private to this technique */
epvt = (PackBitsEncodePvt *) XieMalloc(sizeof(PackBitsEncodePvt));
bzero(epvt,sizeof(PackBitsEncodePvt));
epvt->values = (int *) XieMalloc((state->width) * sizeof(int));
epvt->counts = (int *) XieMalloc((state->width) * sizeof(int));
if (!epvt->counts || !epvt->values) {
FreeFaxData(flo,ped);
AllocError(flo, ped, return(FALSE));
}
state->private = (pointer ) epvt;
}
texpvt->encodptr = encode_tiffpb;
break;
default:
ImplementationError(flo,ped, return(FALSE));
}
/* size of first output strip */
texpvt->strip_req_newbytes = flo->floTex->stripSize;
state->strip_state = StripStateNew;
/* calculate size of the input strip data map we will need */
pbytes = (inf->pitch + 7) >> 3;
max_lines_in = flo->floTex->stripSize / pbytes;
if (!max_lines_in)
max_lines_in = 1; /* in case a line was bigger than std stripsize */
return(InitReceptors(flo, ped, max_lines_in, 1) &&
InitEmitter(flo, ped, NO_DATAMAP, NO_INPLACE));
} /* end common_init() */
/*------------------------------------------------------------------------
----------------------------- free some data ----------------------------
------------------------------------------------------------------------*/
static void FreeFaxData(flo,ped)
floDefPtr flo;
peDefPtr ped;
{
peTexPtr pet = ped->peTex;
faxPvtPtr texpvt=(faxPvtPtr) pet->private;
FaxEncodeState *state = &texpvt->state;
switch(texpvt->encode_technique) {
case xieValEncodeG31D:
{
G31DEncodePvt *epvt = (G31DEncodePvt *) state->private;
if (epvt) {
if (epvt->counts)
XieFree(epvt->counts);
XieFree(epvt);
}
}
break;
case xieValEncodeG32D:
case xieValEncodeG42D:
{
G32DEncodePvt *epvt = (G32DEncodePvt *) state->private;
if (epvt) {
if (epvt->counts) XieFree(epvt->counts);
if (epvt->above) XieFree(epvt->above);
XieFree(epvt);
}
}
break;
case xieValEncodeTIFF2:
{
Tiff2EncodePvt *epvt = (Tiff2EncodePvt *) state->private;
if (epvt) {
if (epvt->counts)
XieFree(epvt->counts);
XieFree(epvt);
}
}
break;
case xieValEncodeTIFFPackBits:
{
PackBitsEncodePvt *epvt = (PackBitsEncodePvt *) state->private;
if (epvt) {
if (epvt->counts) XieFree(epvt->counts);
if (epvt->values) XieFree(epvt->values);
XieFree(epvt);
}
}
break;
default:
break;
}
}
/*------------------------------------------------------------------------
----------------------------- crank some data ----------------------------
------------------------------------------------------------------------*/
int ActivateEPhotoFAX(flo,ped,pet)
floDefPtr flo;
peDefPtr ped;
peTexPtr pet;
{
receptorPtr rcp = pet->receptor;
bandPtr sbnd = &rcp->band[0];
bandPtr dbnd = &pet->emitter[0];
faxPvtPtr texpvt=(faxPvtPtr) pet->private;
FaxEncodeState *state = &texpvt->state;
int was_ready, status;
if (texpvt->notify)
was_ready = ped->outFlo.ready & 1;
status = sub_fun(flo,ped,pet,texpvt,state,sbnd,dbnd);
if(texpvt->notify && ~was_ready & ped->outFlo.ready & 1 &&
(texpvt->notify==xieValNewData ||
texpvt->notify==xieValFirstData && !ped->outFlo.output[0].flink->start))
SendExportAvailableEvent(flo,ped,0,0,0,0);
return( status );
}
/*------------------------------------------------------------------------
-------------------- *really* crank some data ----------------------------
------------------------------------------------------------------------*/
static int sub_fun(flo,ped,pet,texpvt,state,sbnd,dbnd)
floDefPtr flo;
peDefPtr ped;
peTexPtr pet;
faxPvtPtr texpvt;
FaxEncodeState *state;
bandPtr sbnd,dbnd;
{
BytePixel *src,*dst;
int lines_coded;
int nl_mappable;
/*** This program can exit the while(dst) loop because:
1) no new dst is available. This would only be because the
scheduler wants to activate somebody else.
2) We can't get (map) a new input strip. Maybe it's not available
because our data is coming from the client. We want to return
so we can get some.
3) we finished encoding all requested lines.
4) we notice an error.
Now, the scheduler will always keep calling us as long as
we either have input data or final isn't set. We only set
final when we have used all input data and flushed all
output data. So there is no way for us to exit without
coming back properly.
***/
src = GetCurrentSrc(flo,pet,sbnd);
if (dbnd->final) {
/* be forgiving if extra data gets passed to us */
FreeData(flo,pet,sbnd,sbnd->maxGlobal);
return(TRUE);
}
while (dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current,
texpvt->strip_req_newbytes,KEEP)) {
if (!state->strip) {
state->strip = dst;
state->strip_size = dbnd->maxLocal - dbnd->current;
state->strip_state = StripStateNew;
}
nl_mappable = sbnd->maxLocal - sbnd->current;
if (nl_mappable + sbnd->current > texpvt->height)
nl_mappable = texpvt->height - sbnd->current;
if (!MapData(flo,pet,sbnd,0,sbnd->current,nl_mappable,FLUSH)) {
FreeData(flo,pet,sbnd,sbnd->maxLocal);
return(TRUE); /* need another input strip */
}
state->i_lines = (char **)sbnd->dataMap;
state->nl_tocode = nl_mappable;
lines_coded = (*(texpvt->encodptr))(state);
if (lines_coded < 0 || state->encoder_done > FAX_ENCODE_DONE_OK) {
/* coding error. But we should be able to *en*code anything! */
ImplementationError(flo,ped, return(FALSE));
}
state->i_line += lines_coded;
sbnd->current = state->i_line;
if (state->i_line >= texpvt->height) {
/* We're all done! */
if (state->bits.bitpos) {
/* we need to make sure the stager gets flushed */
unsigned char *byteptr= state->bits.byteptr;
if (state->bits.endptr > byteptr) {
/* there is room in this strip for the stager */
*byteptr = state->stager >> 24;
}
else {
/* woe is us. Stager won't fit in current output strip */
MaybeSwapOutput();
PutData(flo,pet,dbnd,dbnd->maxGlobal);
/* flush current strip */
/* ask for one more strip of length 1 */
dst = (BytePixel*)GetDstBytes(flo,pet,
dbnd,dbnd->current,1,KEEP);
*dst = state->stager >> 24;
}
state->bits.byteptr++;
}
/* however we got here, we now have one strip to flush,
which contains all the remaining encoded data.
*/
TruncateStrip(dbnd,
dbnd->minLocal + state->bits.byteptr - state->strip);
SetBandFinal(dbnd);
MaybeSwapOutput();
PutData(flo,pet,dbnd,dbnd->maxGlobal);
FreeData(flo,pet,sbnd,sbnd->maxGlobal);
return(TRUE);
}
if (state->magic_needs) {
/* encoder needs a new output strip */
if (state->strip_state != StripStateDone)
ImplementationError(flo,ped, return(FALSE));
MaybeSwapOutput();
PutData(flo,pet,dbnd,dbnd->maxGlobal);
/* I presume this will increment dbnd->current */
state->strip = 0;
continue;
}
} /* end of while (GetDstBytes) */
return(TRUE);
} /* end ActivateEPhotoFAX */
/*------------------------------------------------------------------------
------------------------ get rid of run-time stuff -----------------------
------------------------------------------------------------------------*/
int ResetEPhotoFAX(flo,ped)
floDefPtr flo;
peDefPtr ped;
{
faxPvtPtr texpvt=(faxPvtPtr) ped->peTex->private;
if (texpvt) FreeFaxData(flo,ped);
ResetReceptors(ped);
ResetEmitter(ped);
return(TRUE);
} /* end ResetEPhotoFAX */
/*------------------------------------------------------------------------
-------------------------- get rid of this element -----------------------
------------------------------------------------------------------------*/
int DestroyEPhotoFAX(flo,ped)
floDefPtr flo;
peDefPtr ped;
{
/* get rid of the peTex structure */
ped->peTex = (peTexPtr) XieFree(ped->peTex);
/* zap this element's entry point vector */
ped->ddVec.create = (xieIntProc) NULL;
ped->ddVec.initialize = (xieIntProc) NULL;
ped->ddVec.activate = (xieIntProc) NULL;
ped->ddVec.reset = (xieIntProc) NULL;
ped->ddVec.destroy = (xieIntProc) NULL;
return(TRUE);
} /* end DestroyEPhotoFAX */
/* end module mefax.c */
|