1
/* $Xorg: xieperf.c,v 1.4 2001/02/09 02:05:48 xorgcvs Exp $ */
3
/**** module xieperf.c ****/
4
/****************************************************************************
6
Copyright 1993, 1994, 1998 The Open Group
8
Permission to use, copy, modify, distribute, and sell this software and its
9
documentation for any purpose is hereby granted without fee, provided that
10
the above copyright notice appear in all copies and that both that
11
copyright notice and this permission notice appear in supporting
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
Except as contained in this notice, the name of The Open Group shall not be
25
used in advertising or otherwise to promote the sale, use or other dealings
26
in this Software without prior written authorization from The Open Group.
31
This software is being provided by AGE Logic, Inc. under the
32
following license. By obtaining, using and/or copying this software,
33
you agree that you have read, understood, and will comply with these
36
Permission to use, copy, modify, distribute and sell this
37
software and its documentation for any purpose and without
38
fee or royalty and to grant others any or all rights granted
39
herein is hereby granted, provided that you agree to comply
40
with the following copyright notice and statements, including
41
the disclaimer, and that the same appears on all copies and
42
derivative works of the software and documentation you make.
44
"Copyright 1993, 1994 by AGE Logic, Inc."
46
THIS SOFTWARE IS PROVIDED "AS IS". AGE LOGIC MAKES NO
47
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way of
48
example, but not limitation, AGE LOGIC MAKE NO
49
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
50
FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
51
INFRINGE THIRD-PARTY PROPRIETARY RIGHTS. AGE LOGIC
52
SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE. IN NO
53
EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
54
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
55
OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
56
ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
57
BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
58
HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
61
The name of AGE Logic, Inc. may not be used in
62
advertising or publicity pertaining to this software without
63
specific, written prior permission from AGE Logic.
65
Title to this software shall at all times remain with AGE
67
*****************************************************************************
69
xieperf.c -- xieperf main module ( looks a lot like x11perf.c )
71
Syd Logan -- AGE Logic, Inc.
73
*****************************************************************************/
74
/* $XFree86: xc/programs/xieperf/xieperf.c,v 3.8 2001/12/14 20:01:53 dawes Exp $ */
83
#include <X11/Xmu/SysUtil.h>
84
#include <X11/Xmu/StdCmap.h>
90
#define lowbit(x) ((x) & (~(x) + 1))
93
/* Only for working on ``fake'' servers, for hardware that doesn't exist */
94
static Bool drawToFakeServer = False;
95
static Pixmap tileToQuery = None;
97
static Bool labels = False;
98
static Bool loadTests = False;
99
static char *loadTestsFile;
100
#define DEFAULT_REPEAT 2
101
static int repeat = DEFAULT_REPEAT;
102
static int seconds = 5;
104
unsigned short capabilities = 0;
105
unsigned short class_request = SUBSET_FULL;
106
extern int CacheSizeMax;
107
static FILE *fp = ( FILE * ) NULL;
108
static Bool RGB_BESTStandardColormapObtained = False;
110
char *imagepath = "./images";
112
static Window status; /* Status window and GC */
115
static double syncTime = 0.0;
118
static char **saveargv;
120
static char *foreground = NULL;
121
static char *background = NULL;
123
static int fixedReps = 0;
125
static Bool sigBail = False;
128
static Bool loCal = False;
129
Bool showErrors = False;
130
static Bool runErrors = False;
131
static Bool runEvents = False;
132
static Bool showLabels = False; /* Hear me now and believe me later,
133
when 'True', is helpful if test
134
dies in calibration */
135
static Bool showTechs = False;
136
static int visualClass = -1;
138
static XRectangle ws[] = { /* Clip rectangles */
139
{195, 195, 120, 120},
140
{ 45, 145, 120, 120},
144
#define MAXCLIP (sizeof(ws) / sizeof(ws[0]))
145
static Window clipWindows[MAXCLIP];
146
static Colormap cmap, colorcmap, graycmap, emptycmap;
147
static int depth = -1; /* -1 means use default depth */
148
Window drawableWindow;
149
Window monitorWindow;
150
Window monitor2Window;
151
static unsigned long whiteidx, blackidx;
152
unsigned long DCRedMask, DCGreenMask, DCBlueMask;
153
static unsigned char rbits, gbits, bbits;
156
/* ScreenSaver state */
157
static XParmRec xparms;
158
static int ssTimeout, ssInterval, ssPreferBlanking, ssAllowExposures;
160
static void usage ( void );
161
static Window CreateXIEParent ( XParms xp );
162
static void AllocateGrayMapColors ( XParms xp );
163
static void AllocateColorMapColors ( XParms xp );
164
static void SetDirectTrueColorStuff ( XParms xp, int *n_colors );
166
static int GetWords ( int argi, int argc, char **argv, char **wordsp,
168
static int atox ( char *s );
169
static int GetNumbers ( int argi, int argc, char **argv, int *intsp,
172
static void SendTripleBandPlaneDataSequential ( XParms xp, Parms p,
174
XiePhotospace photospace,
175
int element, char *data,
177
unsigned char pixel_stride[3],
178
unsigned char left_pad[3],
179
unsigned char scanline_pad[3],
181
XieLTriplet height );
182
static void ScanlinePad ( int *value, int pad );
183
static int EventOrErrorValid ( unsigned short testcp );
184
static int ServerIsCapable ( unsigned short testcp );
185
static void ListAllTechs ( XParms xp );
187
static void FillHisto ( XieHistogramData histos[], int size, int levels );
189
static int TDLutCellSize ( XParms xp );
190
static int LutCellSize ( int depth );
191
static int icbrt_with_guess ( int a, int guess );
192
static int icbrt_with_bits ( int a, int bits );
194
/************************************************
195
* time related stuff *
196
************************************************/
200
typedef struct _vms_time {
206
long tv_sec; /* seconds since Jan. 1, 1970 */
207
long tv_usec; /* and microseconds */
211
int tz_minuteswest; /* of Greenwich */
212
int tz_dsttime; /* type of dst correction to apply */
216
static int firsttime = True;
217
static vms_time basetime;
222
vms_time current_time, resultant;
223
unsigned long mumble, foo;
227
sys$gettim(&basetime);
230
sys$gettim(¤t_time);
231
resultant.high = current_time.high - basetime.high;
232
resultant.low = current_time.low - basetime.low;
233
if (current_time.low < basetime.low) {
236
status = lib$ediv( &(10000000), &resultant, &tp->tv_sec, &tp->tv_usec);
243
static struct timeval start;
250
t = time((Time_t *)NULL);
251
printf("%s\n", ctime(&t));
257
X_GETTIMEOFDAY(&start);
261
ElapsedTime(double correction)
265
X_GETTIMEOFDAY(&stop);
266
if (stop.tv_usec < start.tv_usec) {
267
stop.tv_usec += 1000000;
270
return (double)(stop.tv_usec - start.tv_usec) +
271
(1000000.0 * (double)(stop.tv_sec - start.tv_sec)) - correction;
275
RoundTo3Digits(double d)
277
/* It's kind of silly to print out things like ``193658.4/sec'' so just
278
junk all but 3 most significant digits. */
280
double exponent, sign;
283
/* the code below won't work if d should happen to be non-positive. */
292
} while (d/exponent >= 1000.0);
293
d = (double)((int) (d/exponent + 0.5));
297
while (d*exponent < 100.0) {
301
d = (double)((int) (d*exponent + 0.5));
309
ReportTimes(double usecs, int n, char *str, int average)
311
double msecsperobj, objspersec;
317
msecsperobj = usecs / (1000.0 * (double)n);
318
objspersec = (double) n * 1000000.0 / usecs;
320
/* Round obj/sec to 3 significant digits. Leave msec untouched, to
321
allow averaging results from several repetitions. */
322
objspersec = RoundTo3Digits(objspersec);
325
printf("%6d trep @ %7.4f msec (%6.1f/sec): %s\n",
326
n, msecsperobj, objspersec, str);
328
printf("%6d reps @ %7.4f msec (%6.1f/sec): %s\n",
329
n, msecsperobj, objspersec, str);
332
printf("%6d %sreps @ 0.0 msec (unmeasurably fast): %s\n",
333
n, average ? "t" : "", str);
338
printf("0 reps @ 0.0 msec (test initialization failed): %s\n", str);
342
/************************************************
344
************************************************/
346
static char *program_name;
355
* Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete)
356
* If found, remove it from command line. Don't go past a lone -.
359
Get_Display_Name(int *pargc, /* MODIFIED */
360
char **argv) /* MODIFIED */
363
char **pargv = argv+1;
364
char *displayname = NULL;
367
for (i = 1; i != argc; i++) {
370
if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
371
if (++i >= argc) usage ();
373
displayname = argv[i];
377
if (!strcmp(arg,"-")) {
378
while (i<argc) *pargv++ = argv[i++];
385
return (displayname);
390
* Open_Display: Routine to open a display with correct error handling.
393
Open_Display(char *display_name)
397
d = XOpenDisplay(display_name);
399
fprintf (stderr, "%s: unable to open display '%s'\n",
400
program_name, XDisplayName (display_name));
412
#ifdef SIGNALRETURNSINT
417
/************************************************
418
* Performance stuff *
419
************************************************/
426
static char *help_message[] = {
427
"where options include:",
428
" -display <host:display> the XIE server to contact",
429
" -images <path> path to images supplied with this software,",
430
" defaults to ./images if flag not specified",
431
" -timeout <s> timeout value for certain tests (default=60 secs)",
432
" -sync do the tests in synchronous mode",
433
" -script file read tests from a file, ``-'' to use console",
434
" -repeat <n> do tests <n> times (outer loop) (default = 2)",
435
" -time <s> do tests for <s> seconds each (default = 5)",
436
" -depth <depth> use a visual with <depth> planes per pixel",
437
" -GrayScale use a GrayScale visual",
438
" -StaticGray use a StaticGray visual",
439
" -StaticColor use a StaticColor visual",
440
" -PseudoColor use a PseudoColor visual",
441
" -TrueColor use a TrueColor visual",
442
" -DirectColor use a DirectColor visual",
443
" -WMSafe let window manager install colormap",
444
" -showtechs print supported techniques",
445
" -showlabels print test label to screen before calibration",
446
" -showevents for error and event tests, display as received",
447
" -events include event tests",
448
" -errors include error tests",
449
" -loCal no calibration, fix reps to 5 ( -reps overrides this )",
450
" -all do all tests",
451
" -tests generate a list of all tests",
452
" -mkscript generate script file to stderr ( recognizes -repeat and -reps )",
453
" -cache <n> cache up to n photomaps in server",
454
" -labels print test labels ( use -all or -range to specify tests )",
455
" -DIS run DIS subset tests only ( use -all or -range to specify tests )",
456
" -range <test1>[,<test2>] like all, but do <test1> to <test2>",
457
" -reps <n> fix the inner loop rep count (default = auto scale)",
461
fprintf(stderr, "usage: %s [-options ...]\n", program_name);
462
for (cpp = help_message; *cpp; cpp++) {
463
fprintf(stderr, "%s\n", *cpp);
466
fprintf(stderr, "\n");
468
/* Print out original command line as the above usage message is so long */
469
for (i = 0; i != saveargc; i++) {
470
fprintf(stderr, "%s ", saveargv[i]);
472
fprintf(stderr, "\n\n");
477
NullProc(XParms xp, Parms p)
482
NullInitProc(XParms xp, Parms p, int reps)
489
HardwareSync(XParms xp)
492
* Some graphics hardware allows the server to claim it is done,
493
* while in reality the hardware is busily working away. So fetch
494
* a pixel from the window that was drawn to, which should be
495
* enough to make the server wait for the graphics hardware.
499
image = XGetImage(xp->d, xp->w, 0, 0, 1, 1, ~0, ZPixmap);
500
XDestroyImage(image);
504
DoHardwareSync(XParms xp, Parms p, int reps)
508
for (i = 0; i != reps; i++) {
513
static Test syncTest = {
514
"syncTime", "Internal test for finding how long HardwareSync takes",
515
NullInitProc, DoHardwareSync, NullProc, NullProc,
522
CreatePerfWindow(XParms xp, int x, int y, int width, int height)
524
XSetWindowAttributes xswa;
526
unsigned long value_mask;
528
xswa.background_pixel = xp->background;
529
xswa.border_pixel = xp->foreground;
530
if ( WMSafe == False )
531
xswa.override_redirect = True;
533
xswa.override_redirect = False;
534
xswa.backing_store = False;
535
xswa.save_under = False;
536
xswa.colormap = cmap;
537
value_mask = CWBackPixel | CWBorderPixel | CWColormap |
538
CWOverrideRedirect |CWBackingStore | CWSaveUnder;
540
w = XCreateWindow(xp->d, xp->p, x, y, width, height, 1,
541
xp->vinfo.depth, CopyFromParent, xp->vinfo.visual,
543
XMapWindow (xp->d, w);
548
CreatePerfWindowUnmapped(XParms xp, int x, int y, int width, int height)
550
XSetWindowAttributes xswa;
552
unsigned long value_mask;
554
xswa.background_pixel = xp->background;
555
xswa.border_pixel = xp->foreground;
556
xswa.colormap = cmap;
557
if ( WMSafe == False )
558
xswa.override_redirect = True;
560
xswa.override_redirect = False;
561
xswa.backing_store = False;
562
xswa.save_under = False;
563
value_mask = CWBackPixel | CWBorderPixel | CWColormap |
564
CWOverrideRedirect |CWBackingStore | CWSaveUnder;
565
w = XCreateWindow(xp->d, xp->p, x, y, width, height, 1,
566
xp->vinfo.depth, CopyFromParent, xp->vinfo.visual, value_mask, &xswa);
571
InstallThisColormap(XParms xp, Colormap newcmap)
573
if ( WMSafe == False )
575
XSetWindowColormap( xp->d, xp->w, newcmap );
577
XSetWindowColormap( xp->d, drawableWindow, newcmap );
579
XInstallColormap( xp->d, newcmap );
584
XSetWindowColormap( xp->d, xp->p, newcmap );
591
InstallDefaultColormap(XParms xp)
593
InstallThisColormap( xp,
594
DefaultColormap( xp->d, DefaultScreen( xp->d ) ) );
599
InstallGrayColormap(XParms xp)
602
InstallThisColormap( xp, cmap );
606
InstallEmptyColormap(XParms xp)
609
InstallThisColormap( xp, cmap );
613
InstallColorColormap(XParms xp)
616
InstallThisColormap( xp, cmap );
620
CreateClipWindows(XParms xp, int clips)
623
XWindowAttributes xwa;
625
(void) XGetWindowAttributes(xp->d, xp->w, &xwa);
626
if (clips > MAXCLIP) clips = MAXCLIP;
627
for (j = 0; j != clips; j++) {
628
clipWindows[j] = CreatePerfWindow(xp, xwa.x + ws[j].x,
629
xwa.y + ws[j].y, ws[j].width, ws[j].height);
631
} /* CreateClipWindows */
635
DestroyClipWindows(XParms xp, int clips)
639
if (clips > MAXCLIP) clips = MAXCLIP;
640
for (j = 0; j != clips; j++) {
641
XDestroyWindow(xp->d, clipWindows[j]);
643
} /* DestroyClipWindows */
647
DoTest(XParms xp, Test *test, int reps)
650
unsigned int ret_width, ret_height;
652
/* Tell screen-saver to restart counting again. See comments below for the
653
XSetScreenSaver call. */
654
XForceScreenSaver(xp->d, ScreenSaverReset);
655
if ( dontClear == False )
656
XClearWindow( xp->d, xp->w );
659
(*test->proc) (xp, &test->parms, reps);
662
time = ElapsedTime(syncTime);
663
if (drawToFakeServer)
664
XQueryBestSize(xp->d, TileShape, tileToQuery,
665
32, 32, &ret_width, &ret_height);
666
(*test->passCleanup) (xp, &test->parms);
672
CalibrateTest(XParms xp, Test *test, int seconds, double *usecperobj)
674
#define goal 2500000.0 /* Try to get up to 2.5 seconds */
675
#define enough 2000000.0 /* But settle for 2.0 seconds */
676
#define tick 10000.0 /* Assume clock not faster than .01 seconds */
679
int reps, didreps; /* Reps desired, reps performed */
682
/* Attempt to get an idea how long each rep lasts by getting enough
683
reps to last more tan enough. Then scale that up to the number of
686
If init call to test ever fails, return False and test will be skipped.
689
if (fixedReps != 0) {
694
XDestroySubwindows(xp->d, xp->w);
695
XClearWindow(xp->d, xp->w);
696
didreps = (*test->init) (xp, &test->parms, reps);
700
/* Create clip windows if requested */
701
CreateClipWindows(xp, test->clips);
702
if ( dontClear == False )
703
XClearWindow( xp->d, xp->w );
706
(*test->proc) (xp, &test->parms, reps);
708
usecs = ElapsedTime(syncTime);
709
(*test->cleanup) (xp, &test->parms);
710
DestroyClipWindows(xp, test->clips);
712
if (didreps != reps) {
713
/* The test can't do the number of reps as we asked for.
716
usecs / (double)(didreps * test->parms.objects);
719
/* Did we go long enough? */
720
if (usecs >= enough) break;
722
/* Don't let too short a clock make new reps wildly high */
723
if (usecs < tick) usecs = tick;
725
/* Try to get up to goal seconds. */
726
reps = (int) (goal * (double)reps / usecs) + 1;
729
*usecperobj = usecs / (double) (reps * test->parms.objects);
730
reps = (int) ((double)seconds * 1000000.0 * (double)reps / usecs) + 1;
732
/* Now round reps up to 1 digit accuracy, so we don't get stupid-looking
733
numbers of repetitions. */
740
reps = (reps + 1) * exponent;
742
} /* CalibrateTest */
745
CreatePerfGCs(XParms xp, int func, unsigned long pm)
747
XGCValues gcvfg, gcvbg;
748
unsigned long fg, bg;
752
gcvfg.graphics_exposures = False;
753
gcvbg.graphics_exposures = False;
754
gcvfg.plane_mask = pm;
755
gcvbg.plane_mask = pm;
756
gcvfg.function = func;
757
gcvbg.function = func;
760
/* Make test look good visually if possible */
761
gcvbg.foreground = gcvfg.foreground = bg ^ fg;
762
gcvbg.background = gcvfg.background = bg;
764
gcvfg.foreground = fg;
765
gcvfg.background = bg;
766
gcvbg.foreground = bg;
767
gcvbg.background = fg;
769
xp->fggc = XCreateGC(xp->d, xp->w,
770
GCForeground | GCBackground | GCGraphicsExposures
771
| GCFunction | GCPlaneMask, &gcvfg);
772
xp->bggc = XCreateGC(xp->d, xp->w,
773
GCForeground | GCBackground | GCGraphicsExposures
774
| GCFunction | GCPlaneMask, &gcvbg);
779
DestroyPerfGCs(XParms xp)
781
XFreeGC(xp->d, xp->fggc);
782
XFreeGC(xp->d, xp->bggc);
786
DisplayStatus(Display *d, char *message, char *test, int try)
790
XClearWindow(d, status);
791
sprintf(s, "%d %s %s", try, message, test);
792
/* We should really look at the height, descent of the font, etc. but
793
who cares. This works. */
794
XDrawString(d, status, tgc, 10, 13, s, strlen(s));
799
ProcessTest(XParms xp, Test *test, int func, unsigned long pm, char *label,
802
double time, totalTime;
806
CreatePerfGCs(xp, func, pm);
807
if ( showLabels == True )
809
fprintf( stderr, "'%s'\n", label );
812
if ( loCal == False )
814
DisplayStatus(xp->d, "Calibrating", label, 0);
815
reps = CalibrateTest(xp, test, seconds, &time);
827
XDestroySubwindows(xp->d, xp->w);
828
XClearWindow(xp->d, xp->w);
830
/* scale down the reps if needed */
832
reps = (*test->init) (xp, &test->parms, reps);
833
/* Create clip windows if requested */
834
CreateClipWindows(xp, test->clips);
837
for (j = 0; j != repeat; j++) {
838
if ( sigBail == True )
840
DisplayStatus(xp->d, "Testing", label, j+1);
841
time = DoTest(xp, test, reps);
843
ReportTimes (time, reps * test->parms.objects,
847
ReportTimes(totalTime,
848
repeat * reps * test->parms.objects,
851
(*test->cleanup) (xp, &test->parms);
852
DestroyClipWindows(xp, test->clips);
854
/* Test failed to initialize properly */
863
main(int argc, char *argv[])
866
int numTests; /* Even though the linker knows, we don't. */
869
Bool foundOne = False;
870
Bool synchronous = False;
873
XVisualInfo *vinfolist, vinfotempl;
875
XieExtensionInfo *xieInfo;
876
XWindowAttributes attribs;
878
int done, cclass, timeout;
883
/* Save away argv, argc, for usage to print out */
885
saveargv = (char **) malloc(argc * sizeof(char *));
886
for (i = 0; i != argc; i++) {
887
saveargv[i] = argv[i];
893
/* Count number of tests */
894
ForEachTest(numTests);
895
doit = (Bool *)calloc(numTests, sizeof(Bool));
897
/* Parse arguments */
898
program_name = argv[0];
899
xparms.displayName = displayName = Get_Display_Name (&argc, argv);
900
for (i = 1; i != argc; i++) {
901
if (strcmp (argv[i], "-all") == 0) {
905
} else if (strcmp (argv[i], "-labels") == 0) {
907
} else if (strcmp(argv[i], "-range") == 0) {
916
for (cp2 = cp1; *cp2 != '\0' && *cp2 != ','; cp2++) {};
925
if (strcmp (cp1, (test[j].option) + 1) == 0 &&
926
(test[j].versions & xparms.version)) {
930
} while (strcmp(cp2, (test[k].option + 1)) != 0 &&
931
(test[k].versions & xparms.version) &&
932
test[++k].option != NULL);
933
if (*cp2 != '-' && test[k].option == NULL)
938
if (test[j].option == NULL)
941
} else if (strcmp (argv[i], "-sync") == 0) {
943
} else if (strcmp (argv[i], "-images") == 0) {
948
} else if (strcmp (argv[i], "-timeout") == 0) {
952
timeout = atoi (argv[i]);
956
SetTimeout( timeout );
958
} else if (strcmp (argv[i], "-repeat") == 0) {
962
repeat = atoi (argv[i]);
965
} else if (strcmp (argv[i], "-time") == 0) {
969
seconds = atoi (argv[i]);
972
} else if (strcmp(argv[i], "-reps") == 0) {
976
fixedReps = atoi (argv[i]);
979
} else if (strcmp(argv[i], "-depth") == 0) {
983
depth = atoi(argv[i]);
986
} else if (strcmp(argv[i], "-script") == 0) {
991
loadTestsFile = argv[i];
993
} else if (strcmp(argv[i], "-cache") == 0) {
1001
if ( val < CacheSizeMax )
1004
} else if (strcmp(argv[i], "-loCal") == 0) {
1006
} else if (strcmp(argv[i], "-showtechs") == 0) {
1008
} else if (strcmp(argv[i], "-showlabels") == 0) {
1010
} else if (strcmp(argv[i], "-events") == 0) {
1012
} else if (strcmp(argv[i], "-errors") == 0) {
1014
} else if (strcmp(argv[i], "-showevents") == 0) {
1016
} else if (strcmp(argv[i], "-GrayScale") == 0) {
1017
visualClass = GrayScale;
1018
} else if (strcmp(argv[i], "-StaticGray") == 0) {
1019
visualClass = StaticGray;
1020
} else if (strcmp(argv[i], "-PseudoColor") == 0) {
1021
visualClass = PseudoColor;
1022
} else if (strcmp(argv[i], "-StaticColor") == 0) {
1023
visualClass = StaticColor;
1024
} else if (strcmp(argv[i], "-DirectColor") == 0) {
1025
visualClass = DirectColor;
1026
} else if (strcmp(argv[i], "-TrueColor") == 0) {
1027
visualClass = TrueColor;
1028
} else if (strcmp(argv[i], "-DIS") == 0) {
1029
class_request = SUBSET_DIS;
1030
} else if (strcmp(argv[i], "-WMSafe") == 0) {
1032
} else if (strcmp(argv[i], "-tests") == 0) {
1034
while (test[j].option != NULL) {
1035
fprintf(stderr, " %-24s %s\n",
1036
test[j].option, test[j].label);
1040
} else if (strcmp(argv[i], "-mkscript") == 0) {
1044
if (strcmp (argv[i], test[j].option) == 0 &&
1045
(test[j].versions & xparms.version)) {
1059
while (test[j].option != NULL) {
1060
if ( fixedReps && repeat != DEFAULT_REPEAT )
1061
fprintf(stderr, "%-30s -repeat %d -reps %d\n",
1062
&test[j].option[ 1 ], repeat, fixedReps );
1063
else if ( repeat != DEFAULT_REPEAT )
1064
fprintf(stderr, "%-30s -repeat %d\n",
1065
&test[j].option[ 1 ], repeat );
1067
fprintf(stderr, "%-30s\n", &test[j].option[ 1 ] );
1075
/* Just print out list of tests for use with .sh programs that
1076
assemble data from different xieperf runs into a nice format */
1078
if (doit[i] && (test[i].versions & xparms.version)) {
1079
printf ("%s\n", test[i].label);
1087
if ( loadTests == True )
1089
if ( !strcmp( loadTestsFile, "-" ) )
1092
fp = fopen( loadTestsFile, "r" );
1093
if ( fp == ( FILE * ) NULL )
1095
fprintf( stderr, "Couldn't open script file '%s'\n",
1097
fprintf( stderr, "script argument will be ignored\n" );
1102
xparms.d = Open_Display (displayName);
1103
screen = DefaultScreen(xparms.d);
1105
/* check for presence of XIE */
1107
printf("xieperf - XIE performance program, version 1.0\n");
1108
if ( !XieInitialize(xparms.d, &xieInfo ) ) {
1109
printf("\nXIE not supported on this display!\n");
1112
printf("\nXIE V%d.%d\n", xieInfo->server_major_rev,
1113
xieInfo->server_minor_rev);
1115
capabilities = ( xieInfo->service_class << 8 );
1116
if ( IsDIS( capabilities ) )
1117
printf( "DIS server\n" );
1119
printf( "FULL server\n" );
1121
if ( IsFull( capabilities ) && IsDIS( class_request ) )
1123
printf( "Service class is DIS - running DIS tests only\n" );
1124
capabilities = SUBSET_DIS;
1127
InitEventInfo( xparms.d, xieInfo );
1128
/* get visual info of default visual */
1129
vmask = VisualIDMask | VisualScreenMask;
1130
vinfotempl.visualid = XVisualIDFromVisual(XDefaultVisual(xparms.d, screen));
1131
vinfotempl.screen = screen;
1132
vinfolist = XGetVisualInfo(xparms.d, vmask, &vinfotempl, &n);
1133
if (!vinfolist || n != 1) {
1134
fprintf (stderr, "%s: can't get visual info of default visual\n",
1139
if (depth == -1 && visualClass == -1) {
1140
/* use the default visual and colormap */
1141
xparms.vinfo = *vinfolist;
1144
/* find the specified visual */
1145
vmask = VisualScreenMask;
1146
vinfotempl.screen = screen;
1149
vmask |= VisualDepthMask;
1150
vinfotempl.depth = depth;
1152
if ( visualClass != -1 )
1154
vmask |= VisualClassMask;
1155
#if defined(__cplusplus) || defined(c_plusplus)
1156
vinfotempl.c_class = visualClass;
1158
vinfotempl.class = visualClass;
1163
vinfolist = XGetVisualInfo(xparms.d, vmask, &vinfotempl, &n);
1166
"%s: can't find an appropriate visual for requested depth and/or class\n", program_name);
1169
xparms.vinfo = *vinfolist; /* use the first one in list */
1173
#if defined(__cplusplus) || defined(c_plusplus)
1174
cclass = xparms.vinfo.c_class;
1176
cclass = xparms.vinfo.class;
1178
printf( "Screen visual class is " );
1182
printf( "GrayScale\n" );
1185
printf( "StaticGray\n" );
1188
printf( "PseudoColor\n" );
1191
printf( "StaticColor\n" );
1194
printf( "TrueColor\n" );
1197
printf( "DirectColor\n" );
1200
printf( "Unknown\n" );
1204
if ( cclass == GrayScale || cclass == PseudoColor || cclass == DirectColor )
1206
cmap = graycmap = XCreateColormap(xparms.d, DefaultRootWindow(xparms.d),
1207
xparms.vinfo.visual, AllocAll );
1208
colorcmap = XCreateColormap(xparms.d, DefaultRootWindow(xparms.d),
1209
xparms.vinfo.visual, AllocAll );
1210
emptycmap = XCreateColormap(xparms.d, DefaultRootWindow(xparms.d),
1211
xparms.vinfo.visual, AllocNone );
1215
cmap = graycmap = XCreateColormap(xparms.d, DefaultRootWindow(xparms.d),
1216
xparms.vinfo.visual, AllocNone );
1217
colorcmap = XCreateColormap(xparms.d, DefaultRootWindow(xparms.d),
1218
xparms.vinfo.visual, AllocNone );
1221
if ( WMSafe == False )
1222
XInstallColormap( xparms.d, cmap );
1223
if ( cclass == GrayScale || cclass == PseudoColor || cclass == DirectColor )
1225
AllocateGrayMapColors( &xparms );
1226
xparms.foreground = blackidx;
1227
xparms.background = whiteidx;
1228
AllocateColorMapColors( &xparms );
1234
color.red = 65535; color.green = 65535; color.blue = 65535;
1235
XAllocColor( xparms.d, cmap, &color );
1236
xparms.background = color.pixel;
1237
color.red = 0; color.green = 0; color.blue = 0;
1238
XAllocColor( xparms.d, cmap, &color );
1239
xparms.foreground = color.pixel;
1240
if ( cclass == TrueColor )
1244
SetDirectTrueColorStuff( &xparms, &n_colors );
1248
xparms.screenDepth = DepthFromLevels( xparms.vinfo.colormap_size );
1252
printf( "Colormap has %d entries\n", xparms.vinfo.colormap_size );
1253
printf( "Effective depth is %d-bit\n\n", xparms.screenDepth );
1254
if (!foreground) foreground = "Black";
1255
if (!background) background = "White";
1257
XmuGetHostname (hostname, 100);
1258
printf ("%s server version %d on %s\nfrom %s\n",
1259
ServerVendor (xparms.d), VendorRelease (xparms.d),
1260
DisplayString (xparms.d), hostname);
1263
/* Force screen out of screen-saver mode, grab current data, and set
1264
time to blank to 8 hours. We should just be able to turn the screen-
1265
saver off, but this causes problems on some servers. We also reset
1266
the screen-saver timer each test, as 8 hours is about the maximum time
1267
we can use, and that isn't long enough for some X terminals using a
1268
serial protocol to finish all the tests. As long as the tests run to
1269
completion, the old screen-saver values are restored. */
1270
XForceScreenSaver(xparms.d, ScreenSaverReset);
1271
XGetScreenSaver(xparms.d, &ssTimeout, &ssInterval, &ssPreferBlanking,
1273
(void) signal(SIGINT, Cleanup); /* ^C */
1275
(void) signal(SIGQUIT, Cleanup);
1277
(void) signal(SIGTERM, Cleanup);
1279
(void) signal(SIGHUP, Cleanup);
1281
XSetScreenSaver(xparms.d, 8 * 3600, ssInterval, ssPreferBlanking,
1284
if (drawToFakeServer) {
1286
XCreatePixmap(xparms.d, DefaultRootWindow (xparms.d), 32, 32, 1);
1288
if ( WMSafe == True )
1290
xparms.p = CreateXIEParent( &xparms );
1291
XSetTransientForHint( xparms.d, xparms.p, DefaultRootWindow (xparms.d) );
1292
XMapRaised( xparms.d, xparms.p );
1295
xparms.p = DefaultRootWindow( xparms.d );
1296
xparms.w = CreatePerfWindowUnmapped(&xparms, 2, 2, WIDTH, HEIGHT);
1297
if ( WMSafe == True )
1298
XSetTransientForHint( xparms.d, xparms.w, xparms.p );
1299
monitorWindow = CreatePerfWindowUnmapped(&xparms, WIDTH - 100,
1300
HEIGHT - 100, MONWIDTH, MONHEIGHT);
1301
if ( WMSafe == True )
1302
XSetTransientForHint( xparms.d, monitorWindow, xparms.p );
1303
monitor2Window = CreatePerfWindowUnmapped(&xparms, WIDTH - 100,
1304
HEIGHT - 100, MONWIDTH, MONHEIGHT);
1305
if ( WMSafe == True )
1306
XSetTransientForHint( xparms.d, monitor2Window, xparms.p );
1308
drawableWindow = CreatePerfWindowUnmapped(&xparms, 610, 0,
1310
if ( WMSafe == True )
1311
XSetTransientForHint( xparms.d, drawableWindow, xparms.p );
1312
status = CreatePerfWindowUnmapped(&xparms, 2, HEIGHT+5, WIDTH, 20);
1313
if ( WMSafe == True )
1314
XSetTransientForHint( xparms.d, status, xparms.p );
1315
tgcv.foreground = xparms.foreground;
1316
tgcv.background = xparms.background;
1317
tgc = XCreateGC(xparms.d, status, GCForeground | GCBackground, &tgcv);
1320
XSynchronize (xparms.d, True);
1322
/* Get mouse pointer out of the way of the performance window. On
1323
software cursor machines it will slow graphics performance. On
1324
all current MIT-derived servers it will slow window
1325
creation/configuration performance. */
1326
XGetWindowAttributes( xparms.d, DefaultRootWindow( xparms.d ), &attribs );
1327
XSync( xparms.d, 0 );
1329
/* wait for first expose event before we trudge forward */
1331
XSelectInput( xparms.d, xparms.w, ExposureMask );
1332
XSync( xparms.d, 0 );
1333
XMapWindow( xparms.d, xparms.w );
1334
XMapWindow( xparms.d, status );
1339
XNextEvent( xparms.d, &event );
1340
switch( event.type )
1348
if ( WMSafe == True )
1349
XWarpPointer(xparms.d, None, xparms.p, 0, 0, 0, 0, 10, HEIGHT+30);
1351
XWarpPointer(xparms.d, None, DefaultRootWindow( xparms.d ),
1352
0, 0, 0, 0, 10, HEIGHT+30);
1354
/* Figure out how long to call HardwareSync, so we can adjust for that
1355
in our total elapsed time */
1357
(void) CalibrateTest(&xparms, &syncTest, 1, &syncTime);
1358
printf("Sync time adjustment is %6.4f msecs.\n\n", syncTime/1000);
1361
ListAllTechs( &xparms );
1363
if ( loadTests == False )
1369
if ( !EventOrErrorValid( test[ i ].parms.description ) )
1371
if (doit[i] && (test[i].versions & xparms.version) && ServerIsCapable( test[ i ].parms.description ) ) {
1372
strcpy (label, test[i].label);
1373
ProcessTest(&xparms, &test[i], GXcopy, ~((unsigned long)0), label, -1);
1374
if ( sigBail == True )
1387
while ( done == False )
1389
if ( sigBail == True )
1391
repeattmp = repeatsave = -1;
1392
if ( ( i = GetNextTest( fp, &repeattmp, &reps ) ) < 0 )
1398
if ( !EventOrErrorValid( test[ i ].parms.description ) )
1400
if ((test[i].versions & xparms.version) &&
1401
ServerIsCapable( test[ i ].parms.description ) )
1403
strcpy (label, test[i].label);
1404
if ( repeattmp != -1 )
1406
repeatsave = repeat;
1409
ProcessTest(&xparms,
1410
&test[i], GXcopy, ~0L, label, reps);
1411
if ( repeattmp != -1 )
1412
repeat = repeatsave;
1418
if ( fp != ( FILE * ) NULL )
1420
ReclaimPhotomapMemory(); /* shut up Purify :-) */
1422
if ( WMSafe == True )
1424
XUnmapWindow(xparms.d, xparms.p );
1425
XSync( xparms.d, 0 );
1426
XDestroyWindow(xparms.d, xparms.p );
1429
XDestroyWindow(xparms.d, xparms.w);
1430
/* Restore ScreenSaver to original state. */
1431
XSetScreenSaver(xparms.d, ssTimeout, ssInterval, ssPreferBlanking,
1433
if ( RGB_BESTStandardColormapObtained == True )
1434
XmuDeleteStandardColormap( xparms.d, DefaultScreen( xparms.d ),
1436
XCloseDisplay(xparms.d);
1441
TestIndex(char *testname)
1448
if (strcmp (testname, (test[j].option) + 1) == 0 )
1458
CreateXIEParent(XParms xp)
1461
unsigned int width, height, border_width, depth;
1462
XSetWindowAttributes xswa;
1465
unsigned long value_mask;
1468
Time for a little explaining...
1470
Xieperf puts up windows, moves them around, and associates
1471
colormaps with windows. If no window manager is running, then
1472
things are fine - I don't even call this function. I just set
1473
the window attribute override_redirect = True at window creation
1474
time, and associate my grayscale colormap with the window at
1477
If a window manager is running, I need to be nice. Nice means
1478
allow the window manager to install colormaps as my windows
1479
gain focus, and let the manager control any geometry changes
1482
The user, when a window manager is running, is required to use
1483
the -WMSafe argument to xieperf to indicate to me that a window
1484
manager is running. If this arg is given, then I do the following:
1486
I make a child window of the root window which acts as the parent
1487
window for xieperf's windows. I use XSetTransientForHint() to tell
1488
the window manager essentially that each child window of this
1489
parent is a transient window so please don't mess with my geometry
1490
requests and please install the colormap associated with each
1491
child window as that window gains focus.
1493
Since the parent window has dimensions equal to the root window,
1494
the app will have focus and my colormap ( which is also the color
1495
map of the parent window ) will be installed ( assuming the
1496
graciousness of the window manager ). Also, any child windows will
1497
appear, disappear, and be moved at my command. Finally, it was
1498
my goal to make the parent window transparent, so it has the usual
1499
root window appearance. This could be done by calling the function
1500
XSetWindowBackgroundPixmap(), and specifying ParentRelative as its
1503
But I ran into problems. I got the desired effects - namely window
1504
placement, colormap handling, and the transparency thing all seemed
1505
o.k., but under twm my parent window would not clear itself when
1506
child windows were unmapped, nor would it respond to XClearWindow()
1507
calls. Turning backing store on for the parent window fixed the
1508
problem, but that is not a viable solution since backing store isn't
1509
always around to help. And, when running under mwm, bizarro effects
1510
like side-by-side mirror images of a child window would appear. It
1511
was dazzling, but unappreciated...
1513
My solution was simple. If this function is called, and the server
1514
currently supports backing store, I use that, go for the transparent
1515
window, and things are happy.
1517
If this function is called and there is no backing store support,
1518
instead of having a transparent parent window, the parent window is
1519
created with a background pixel of BlackPixel ( also it was shown
1520
that while the transparent version of the parent window never cleared
1521
either on its own or explicitly via XClearWindow(), windows that had
1522
normal pixel-based backgrounds would clear themselves whenever the
1523
child windows were unmapped ).
1525
Comments would be appreciated... there should be a way to do this
1526
that isn't too painful. The Xlib Programming Manual ( O'Reilly
1527
Volume 1, p 96 ) states that if ParentRelative is used as a
1528
backround pixmap, the backgrounds are automatically repainted on
1529
exposure. As the above states, they aren't. My feeling is that there
1530
is a bug in the R5 cfb code or...
1533
hasBS = DoesBackingStore( DefaultScreenOfDisplay( xp->d ) );
1534
XGetGeometry( xp->d, DefaultRootWindow( xp->d ), &root, &x, &y,
1535
&width, &height, &border_width, &depth );
1537
xswa.colormap = cmap;
1540
xswa.backing_store = WhenMapped;
1544
xswa.background_pixel =
1545
BlackPixel( xp->d, DefaultScreen( xp->d ) );
1547
value_mask = CWColormap | ( hasBS ? CWBackingStore : CWBackPixel );
1548
ret = XCreateWindow( xp->d, DefaultRootWindow( xp->d ),
1549
x, y, width, height, border_width, xp->vinfo.depth,
1550
CopyFromParent, xp->vinfo.visual,
1551
value_mask, &xswa );
1555
/* make it transparent */
1557
XSetWindowBackgroundPixmap( xp->d, ret, ParentRelative );
1563
AllocateGrayMapColors(XParms xp)
1566
long intensity, rintensity, gintensity, bintensity;
1567
XColor *gray = ( XColor * ) NULL;
1571
/* get what we can, and remember it. we should get all since
1572
we created the colormap */
1574
gray = ( XColor * ) malloc(sizeof( XColor ) * xp->vinfo.colormap_size);
1575
if ( gray == ( XColor * ) NULL )
1577
fprintf( stderr, "Couldn't allocate XColor vector for XAllocColorCells\n" );
1582
#if defined(__cplusplus) || defined(c_plusplus)
1583
cclass = xp->vinfo.c_class;
1585
cclass = xp->vinfo.class;
1588
if ( cclass == DirectColor )
1590
SetDirectTrueColorStuff( xp, &n_colors );
1594
n_colors = xp->vinfo.colormap_size;
1595
xp->screenDepth = DepthFromLevels( n_colors );
1598
/* do a grey scale ramp */
1600
maxcoloridx = n_colors - 1;
1602
if ( cclass == DirectColor )
1604
for (i=0; i<n_colors; i++) {
1605
rintensity = ( (i*65535L) / (long) (n_colors-1) );
1606
gintensity = ( (i*65535L) / (long) (n_colors-1) );
1607
bintensity = ( (i*65535L) / (long) (n_colors-1) );
1608
gray[i].pixel = i * lowbit( DCRedMask );
1609
gray[i].pixel |= i * lowbit( DCGreenMask );
1610
gray[i].pixel |= i * lowbit( DCBlueMask );
1611
gray[i].red = rintensity;
1612
gray[i].green = gintensity;
1613
gray[i].blue = bintensity;
1614
gray[i].flags = DoRed | DoGreen | DoBlue;
1619
for (i=0; i<n_colors; i++) {
1620
intensity = (i*65535L) / (long) (n_colors-1);
1622
gray[i].red = intensity;
1623
gray[i].green = intensity;
1624
gray[i].blue = intensity;
1625
gray[i].flags = DoRed | DoGreen | DoBlue;
1628
whiteidx = gray[ maxcoloridx ].pixel;
1629
blackidx = gray[ 0 ].pixel;
1632
XStoreColors(xp->d,graycmap,gray,n_colors);
1637
fprintf( stderr, "Couldn't allocate colors in colormap\n" );
1647
AllocateColorMapColors(XParms xp)
1650
long intensity, rintensity, gintensity, bintensity;
1651
XColor *gray = ( XColor * ) NULL;
1655
/* get what we can, and remember it. we should get all since
1656
we created the colormap */
1658
gray = ( XColor * ) malloc(sizeof( XColor ) * xp->vinfo.colormap_size);
1659
if ( gray == ( XColor * ) NULL )
1661
fprintf( stderr, "Couldn't allocate XColor vector for XAllocColorCells\n" );
1666
#if defined(__cplusplus) || defined(c_plusplus)
1667
cclass = xp->vinfo.c_class;
1669
cclass = xp->vinfo.class;
1672
if ( cclass == DirectColor )
1674
SetDirectTrueColorStuff( xp, &n_colors );
1678
n_colors = xp->vinfo.colormap_size;
1679
xp->screenDepth = DepthFromLevels( n_colors );
1682
/* do a grey scale ramp */
1684
maxcoloridx = n_colors - 1;
1686
if ( cclass == DirectColor )
1688
for (i=0; i<n_colors; i++) {
1689
rintensity = ( (i*65535L) / (long) (n_colors-1) );
1690
gintensity = ( (i*65535L) / (long) (n_colors-1) );
1691
bintensity = ( (i*65535L) / (long) (n_colors-1) );
1692
gray[i].pixel = i * lowbit( DCRedMask );
1693
gray[i].pixel |= i * lowbit( DCGreenMask );
1694
gray[i].pixel |= i * lowbit( DCBlueMask );
1695
gray[i].red = rintensity;
1696
gray[i].green = gintensity;
1697
gray[i].blue = bintensity;
1698
gray[i].flags = DoRed | DoGreen | DoBlue;
1703
for (i=0; i<n_colors; i++) {
1704
intensity = (i*65535L) / (long) (n_colors-1);
1706
gray[i].red = intensity;
1707
gray[i].green = intensity;
1708
gray[i].blue = intensity;
1709
gray[i].flags = DoRed | DoGreen | DoBlue;
1714
XStoreColors(xp->d,colorcmap,gray,n_colors);
1719
fprintf( stderr, "Couldn't allocate colors in colormap\n" );
1729
SetDirectTrueColorStuff(XParms xp, int *n_colors )
1733
DCRedMask = xp->vinfo.red_mask;
1734
DCGreenMask = xp->vinfo.green_mask;
1735
DCBlueMask = xp->vinfo.blue_mask;
1737
mask = 1L << ( ( sizeof( long ) << 3 ) - 1 );
1738
rbits = gbits = bbits = 0;
1742
if ( mask & DCRedMask ) rbits+=1;
1743
else if ( mask & DCGreenMask ) gbits+=1;
1744
else if ( mask & DCBlueMask ) bbits+=1;
1747
xp->screenDepth = MIN( rbits, MIN( gbits, bbits ) );
1748
if ( xp->screenDepth == rbits && xp->screenDepth == gbits &&
1749
xp->screenDepth == bbits )
1751
xp->screenDepth = rbits + gbits + bbits;
1752
*n_colors = 1 << rbits;
1756
*n_colors = 1 << xp->screenDepth;
1762
GetWords(int argi, int argc, char **argv, char **wordsp, int *nump)
1769
while (argv[argi] && *(argv[argi]) != '-') {
1770
*wordsp++ = argv[argi];
1785
if ('0' <= *s && *s <= '9')
1787
else if ('a' <= *s && *s <= 'f')
1789
else if ('A' <= *s && *s <= 'F')
1798
GetNumbers(int argi, int argc, char **argv, int *intsp, int *nump)
1805
count = GetWords (argi, argc, argv, words, nump);
1806
for (i = 0; i < count; i++) {
1808
if (!strncmp (words[i], "~", 1)) {
1812
if (!strncmp (words[i], "0x", 2))
1813
intsp[i] = atox(words[i] + 2) ^ flip;
1815
intsp[i] = atoi (words[i]) ^ flip;
1822
SendTripleBandPlaneDataSequential(XParms xp, Parms p, int flo_id,
1823
XiePhotospace photospace, int element,
1824
char *data, int size,
1825
unsigned char pixel_stride[3],
1826
unsigned char left_pad[3],
1827
unsigned char scanline_pad[3],
1828
XieLTriplet width, XieLTriplet height )
1830
int band1, band2, band3;
1832
/* calculate band sizes */
1834
band1 = ( ( left_pad[ 0 ] >> 3 ) +
1835
( width[ 0 ] * ( pixel_stride[ 0 ] >> 3 ) ) ) * height[ 0 ];
1836
ScanlinePad( &band1, scanline_pad[ 0 ] );
1837
band2 = ( ( left_pad[ 1 ] >> 3 ) +
1838
( width[ 1 ] * ( pixel_stride[ 1 ] >> 3 ) ) ) * height[ 1 ];
1839
ScanlinePad( &band2, scanline_pad[ 1 ] );
1840
band3 = ( ( left_pad[ 2 ] >> 3 ) +
1841
( width[ 2 ] * ( pixel_stride[ 2 ] >> 3 ) ) ) * height[ 2 ];
1842
ScanlinePad( &band3, scanline_pad[ 0 ] );
1846
PumpTheClientData( xp, p, flo_id, photospace, element, data, band1, 0 );
1848
PumpTheClientData( xp, p, flo_id, photospace, element, data, band2, 1 );
1850
PumpTheClientData( xp, p, flo_id, photospace, element, data, band3, 2 );
1855
ScanlinePad(int *value, int pad)
1859
if ( !( *value == 0 || pad == 0 || pad == 1 ) )
1861
if ( ( *value % pad ) != 0 )
1870
while ( newval < *value )
1879
PumpTheClientData(XParms xp, Parms p, int flo_id, XiePhotospace photospace,
1880
int element, char *data, int size, int band_number )
1882
int bytes_left, final, nbytes;
1886
while (bytes_left > 0) {
1887
nbytes = (bytes_left > p->buffer_size) ?
1888
p->buffer_size: bytes_left;
1889
if (nbytes >= bytes_left)
1895
element, /* element */
1896
final, /* signal that this is all the data */
1897
band_number, /* 0 for all but triple band data
1898
BandByPlane, which then may be
1900
(unsigned char *) data,
1903
bytes_left -= nbytes;
1909
ReadNotifyExportData(XParms xp, Parms p, unsigned long namespace, int flo_id,
1910
XiePhototag element, unsigned int elementsz,
1911
unsigned int numels, char **data, int *done )
1914
Bool terminate = False;
1915
XieExportState new_state_ret;
1916
unsigned int nbytes;
1917
unsigned int nbytes_ret;
1918
Bool no_errors, reallocFlag;
1925
numels = WaitForXIEEvent( xp, xieEvnNoExportAvailable,
1926
flo_id, element, False );
1931
nbytes = numels * elementsz;
1934
reallocFlag = False;
1936
if ( *data == ( char * ) NULL )
1938
if ( ( *data = ( char * ) malloc( nbytes ) ) == ( char * ) NULL )
1940
fprintf( stderr, "ReadNotifyExportData: couldn't allocate data\n" );
1947
XieGetClientData ( xp->d, namespace, flo_id, element,
1948
bytes > 2048 ? 2048 : bytes, terminate, 0,
1949
&new_state_ret, (unsigned char **)&cp, &nbytes_ret );
1951
if ( nbytes_ret && reallocFlag )
1953
*data = realloc( *data, cnt + nbytes_ret );
1954
if ( *data == ( char * ) NULL )
1958
fprintf( stderr, "ReadNotifyExportData: realloc failed\n" );
1967
memcpy( ptr, cp, nbytes_ret * sizeof( char ) );
1968
ptr += nbytes_ret * sizeof( char );
1972
bytes -= nbytes_ret;
1973
if ( new_state_ret == xieValExportEmpty )
1974
WaitForXIEEvent( xp, xieEvnNoExportAvailable,
1975
flo_id, element, False );
1976
else if ( new_state_ret == xieValExportMore )
1984
else if ( new_state_ret == xieValExportDone )
1989
else if ( new_state_ret == xieValExportError )
1991
fprintf( stderr, "ReadNotifyExportData: xieValExportError received from XieGetClientData\n" );
1996
if ( bytes <= 0 && reallocFlag == False )
1998
/* if we get here, we didn't get an ExportDone,
1999
and we have no buffer space left. So turn on
2000
the realloc flag. Also, server could be not
2001
sending the ExportDone for some reason...
2002
if so XIE or xieperf or both may be broken. */
2008
if ( no_errors == False )
2016
ReadNotifyExportTripleData(XParms xp, Parms p, unsigned long namespace,
2017
int flo_id, XiePhototag element,
2018
unsigned int elementsz,
2019
unsigned int numels, char **data, int *done )
2022
Bool terminate = False;
2023
XieExportState new_state_ret;
2024
unsigned int nbytes;
2025
unsigned int nbytes_ret;
2026
Bool no_errors, reallocFlag;
2034
numels = WaitForXIEEvent( xp, xieEvnNoExportAvailable,
2035
flo_id, element, False );
2038
fprintf( stderr, "There are %d elements available\n", numels );
2041
nbytes = numels * elementsz;
2044
reallocFlag = False;
2046
if ( *data == ( char * ) NULL )
2048
if ( ( *data = ( char * ) malloc( nbytes ) ) == ( char * ) NULL )
2050
fprintf( stderr, "ReadNotifyExportTripleData: couldn't allocate data\n" );
2055
for ( band = 0; band < 3; band++ )
2059
XieGetClientData ( xp->d, namespace, flo_id, element,
2060
bytes > 2048 ? 2048 : bytes, terminate, band,
2061
&new_state_ret, (unsigned char **)&cp,
2064
if ( nbytes_ret && reallocFlag )
2066
*data = realloc( *data, cnt + nbytes_ret );
2067
if ( *data == ( char * ) NULL )
2071
fprintf( stderr, "ReadNotifyExportTripleData: realloc failed\n" );
2078
memcpy( ptr, cp, nbytes_ret * sizeof( char ) );
2079
ptr += nbytes_ret * sizeof( char );
2083
bytes -= nbytes_ret;
2084
if ( new_state_ret == xieValExportEmpty )
2085
WaitForXIEEvent( xp, xieEvnNoExportAvailable,
2086
flo_id, element, False );
2087
else if ( new_state_ret == xieValExportMore )
2093
else if ( new_state_ret == xieValExportDone )
2098
else if ( new_state_ret == xieValExportError )
2100
fprintf( stderr, "ReadNotifyExportTripleData: xieValExportError received from XieGetClientData\n" );
2104
if ( bytes <= 0 && reallocFlag == False )
2111
if ( no_errors == False )
2119
CheckSum(char *data, unsigned int size)
2121
unsigned int sum, i;
2124
for ( i = 0; i < size; i++ )
2132
GetXIEFAXPhotomap(XParms xp, Parms p, int which, Bool radiometric)
2134
XIEimage *image = ( XIEimage * ) NULL;
2135
XiePhotospace photospace;
2136
int flo_id, flo_notify;
2137
XiePhotoElement *flograph;
2138
XieDecodeG42DParam *g42d_decode_params=NULL;
2139
XieDecodeG32DParam *g32d_decode_params=NULL;
2140
XieDecodeG31DParam *g31d_decode_params=NULL;
2141
XieDecodeTIFF2Param *tiff2_decode_params=NULL;
2142
XieDecodeTIFFPackBitsParam *tiffpb_decode_params=NULL;
2143
char *decode_params;
2144
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
2145
char *encode_params=NULL;
2146
XieLTriplet width, height, levels;
2152
image = p->finfo.image1;
2155
else if ( which == 2 )
2157
image = p->finfo.image2;
2160
else if ( which == 3 )
2162
image = p->finfo.image3;
2164
else if ( which == 4 )
2166
image = p->finfo.image4;
2169
return( XiePhotomap ) NULL;
2171
if ( IsImageInCache( image ) == True )
2173
return( PhotomapOfImage( image ) );
2176
if ( !GetImageData( xp, p, which ) )
2177
return( ( XiePhotomap ) NULL );
2179
if ( TechniqueSupported( xp, xieValDecode, image->decode ) == False )
2180
return( XiePhotomap ) NULL;
2182
size = image->fsize;
2183
image->chksum = CheckSum( image->data, size );
2184
width[ 0 ] = image->width[ 0 ];
2185
height[ 0 ] = image->height[ 0 ];
2186
levels[ 0 ] = image->levels[ 0 ];
2188
/* create a photomap */
2190
tmp = XieCreatePhotomap(xp->d);
2192
/* get the data from the client into the photomap */
2194
photospace = XieCreatePhotospace(xp->d);
2196
if ( image->decode == xieValDecodeG42D ) {
2197
g42d_decode_params = XieTecDecodeG42D(
2202
decode_params = (char *) g42d_decode_params;
2204
else if ( image->decode == xieValDecodeG32D ) {
2205
g32d_decode_params = XieTecDecodeG32D(
2210
decode_params = (char *) g32d_decode_params;
2212
else if ( image->decode == xieValDecodeTIFF2 ) {
2213
tiff2_decode_params = XieTecDecodeTIFF2(
2218
decode_params = (char *) tiff2_decode_params;
2220
else if ( image->decode == xieValDecodeTIFFPackBits ) {
2221
tiffpb_decode_params = XieTecDecodeTIFFPackBits(
2225
decode_params = (char *) tiffpb_decode_params;
2227
else if ( image->decode == xieValDecodeG31D ) {
2228
g31d_decode_params = XieTecDecodeG31D(
2233
decode_params = (char *) g31d_decode_params;
2236
return( XiePhotomap ) NULL;
2239
flograph = XieAllocatePhotofloGraph(2);
2240
if ( flograph == ( XiePhotoElement * ) NULL )
2242
fprintf( stderr, "GetXIEFAXPhotomap: XieAllocatePhotofloGraph failed\n" );
2243
XieDestroyPhotomap( xp->d, tmp );
2244
if ( decode_params )
2245
XFree( decode_params );
2246
return( XiePhotomap ) NULL;
2249
XieFloImportClientPhoto(&flograph[0],
2251
width, height, levels,
2253
image->decode, (char *)decode_params
2256
XieFloExportPhotomap(&flograph[1],
2257
1, /* source phototag number */
2265
XieExecuteImmediate(xp->d, photospace,
2268
flograph, /* photoflo specification */
2269
2 /* number of elements */
2272
PumpTheClientData( xp, p, flo_id, photospace, 1, image->data, size, 0 );
2273
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2274
XieFreePhotofloGraph(flograph,2);
2275
XieDestroyPhotospace(xp->d, photospace);
2276
XFree( decode_params );
2277
AddToCache( image, tmp );
2282
GetXIETriplePhotomap(XParms xp, Parms p, int which)
2284
XIEimage *image = ( XIEimage * ) NULL;
2285
XiePhotospace photospace;
2286
int flo_id, flo_notify;
2287
XiePhotoElement *flograph;
2288
char *decode_params=NULL;
2289
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
2290
char *encode_params=NULL;
2291
XieLTriplet width, height, levels;
2292
unsigned char pixel_stride[ 3 ];
2293
unsigned char left_pad[ 3 ];
2294
unsigned char scanline_pad[ 3 ];
2300
image = p->finfo.image1;
2302
else if ( which == 2 )
2304
image = p->finfo.image2;
2306
else if ( which == 3 )
2308
image = p->finfo.image3;
2310
else if ( which == 4 )
2312
image = p->finfo.image4;
2315
return( XiePhotomap ) NULL;
2317
if ( IsImageInCache( image ) == True )
2319
TouchImage( image );
2320
return( PhotomapOfImage( image ) );
2323
if ( !GetImageData( xp, p, which ) )
2324
return( ( XiePhotomap ) NULL );
2326
if ( TechniqueSupported( xp, xieValDecode, image->decode ) == False )
2327
return( XiePhotomap ) NULL;
2329
size = image->fsize;
2330
image->chksum = CheckSum( image->data, size );
2332
/* create a photomap */
2334
tmp = XieCreatePhotomap(xp->d);
2336
/* get the data from the client into the photomap */
2338
photospace = XieCreatePhotospace(xp->d);
2340
width[ 0 ] = image->width[ 0 ];
2341
width[ 1 ] = image->width[ 1 ];
2342
width[ 2 ] = image->width[ 2 ];
2343
height[ 0 ] = image->height[ 0 ];
2344
height[ 1 ] = image->height[ 1 ];
2345
height[ 2 ] = image->height[ 2 ];
2346
levels[ 0 ] = image->levels[ 0 ];
2347
levels[ 1 ] = image->levels[ 1 ];
2348
levels[ 2 ] = image->levels[ 2 ];
2350
if ( image->decode == xieValDecodeUncompressedTriple )
2352
pixel_stride[ 0 ] = image->pixel_stride[ 0 ];
2353
pixel_stride[ 1 ] = image->pixel_stride[ 1 ];
2354
pixel_stride[ 2 ] = image->pixel_stride[ 2 ];
2355
left_pad[ 0 ] = image->left_pad[ 0 ];
2356
left_pad[ 1 ] = image->left_pad[ 1 ];
2357
left_pad[ 2 ] = image->left_pad[ 2 ];
2358
scanline_pad[ 0 ] = image->scanline_pad[ 0 ];
2359
scanline_pad[ 1 ] = image->scanline_pad[ 1 ];
2360
scanline_pad[ 2 ] = image->scanline_pad[ 2 ];
2362
decode_params = ( char * ) XieTecDecodeUncompressedTriple(
2372
else if ( image->decode == xieValDecodeJPEGBaseline )
2374
decode_params = ( char * ) XieTecDecodeJPEGBaseline(
2380
else if ( image->decode == xieValDecodeJPEGLossless )
2382
decode_params = ( char * ) XieTecDecodeJPEGLossless(
2389
fprintf( stderr, "GetXIETriplePhotomap: invalid decode technique\n" );
2390
XieDestroyPhotomap( xp->d, tmp );
2391
return( XiePhotomap ) NULL;
2394
flograph = XieAllocatePhotofloGraph(2);
2395
if ( flograph == ( XiePhotoElement * ) NULL )
2397
fprintf( stderr, "GetXIETriplePhotomap: XieAllocatePhotofloGraph failed\n" );
2398
XieDestroyPhotomap( xp->d, tmp );
2399
return( XiePhotomap ) NULL;
2402
XieFloImportClientPhoto(&flograph[0],
2404
width, height, levels,
2406
image->decode, (char *)decode_params
2409
XieFloExportPhotomap(&flograph[1],
2410
1, /* source phototag number */
2418
XieExecuteImmediate(xp->d, photospace,
2421
flograph, /* photoflo specification */
2422
2 /* number of elements */
2425
if ( image->interleave == xieValBandByPixel )
2427
PumpTheClientData( xp, p, flo_id, photospace,
2428
1, image->data, size, 0 );
2432
SendTripleBandPlaneDataSequential( xp, p, flo_id, photospace,
2433
1, image->data, size, pixel_stride,
2434
left_pad, scanline_pad, width, height );
2436
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2437
XieFreePhotofloGraph(flograph,2);
2438
XieDestroyPhotospace(xp->d, photospace);
2439
if ( decode_params )
2440
XFree( decode_params );
2441
AddToCache( image, tmp );
2446
GetXIEPhotomap(XParms xp, Parms p, int which)
2448
XIEimage *image = ( XIEimage * ) NULL;
2449
XiePhotospace photospace;
2450
int flo_id, flo_notify;
2451
XiePhotoElement *flograph;
2452
XieDecodeUncompressedSingleParam *decode_params=NULL;
2453
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
2454
char *encode_params=NULL;
2455
XieLTriplet width, height, levels;
2461
image = p->finfo.image1;
2463
else if ( which == 2 )
2465
image = p->finfo.image2;
2467
else if ( which == 3 )
2469
image = p->finfo.image3;
2471
else if ( which == 4 )
2473
image = p->finfo.image4;
2477
return( XiePhotomap ) NULL;
2479
if ( IsImageInCache( image ) == True )
2481
TouchImage( image );
2482
return( PhotomapOfImage( image ) );
2485
if ( !GetImageData( xp, p, which ) )
2486
return( ( XiePhotomap ) NULL );
2488
size = image->fsize;
2489
image->chksum = CheckSum( image->data, size );
2491
width[ 0 ] = width[ 1 ] = width[ 2 ] = image->width[ 0 ];
2492
height[ 0 ] = height[ 1 ] = height[ 2 ] = image->height[ 0 ];
2493
levels[ 0 ] = levels[ 1 ] = levels[ 2 ] = image->levels[ 0 ];
2495
/* create a photomap */
2497
tmp = XieCreatePhotomap(xp->d);
2499
/* get the data from the client into the photomap */
2501
photospace = XieCreatePhotospace(xp->d);
2503
decode_params = XieTecDecodeUncompressedSingle(
2506
image->pixel_stride[ 0 ],
2507
image->left_pad[ 0 ],
2508
image->scanline_pad[ 0 ]
2511
flograph = XieAllocatePhotofloGraph(2);
2512
if ( flograph == ( XiePhotoElement * ) NULL )
2514
fprintf( stderr, "GetXIEPhotomap: XieAllocatePhotofloGraph failed\n" );
2515
XieDestroyPhotomap( xp->d, tmp );
2516
return( XiePhotomap ) NULL;
2519
XieFloImportClientPhoto(&flograph[0],
2521
width, height, levels,
2523
image->decode, (char *)decode_params
2526
XieFloExportPhotomap(&flograph[1],
2527
1, /* source phototag number */
2535
XieExecuteImmediate(xp->d, photospace,
2538
flograph, /* photoflo specification */
2539
2 /* number of elements */
2542
PumpTheClientData( xp, p, flo_id, photospace, 1, image->data, size, 0 );
2543
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2544
XieFreePhotofloGraph(flograph,2);
2545
XieDestroyPhotospace(xp->d, photospace);
2546
if ( decode_params )
2547
XFree( decode_params );
2548
AddToCache( image, tmp );
2553
GetXIEPointPhotomap(XParms xp, Parms p, int which,
2554
int inlevels, Bool useLevels )
2556
XIEimage *image = ( XIEimage * ) NULL;
2557
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
2558
char *encode_params=NULL;
2559
XiePhotospace photospace;
2560
int flo_id, flo_notify;
2561
XiePhotoElement *flograph;
2562
XiePhotomap XIEPhotomap, tmp;
2564
XieProcessDomain domain;
2566
tmp = GetXIEPhotomap( xp, p, which );
2569
image = p->finfo.image1;
2570
else if ( which == 2 )
2571
image = p->finfo.image2;
2572
else if ( which == 3 )
2573
image = p->finfo.image3;
2574
else if ( which == 4 )
2575
image = p->finfo.image4;
2577
if ( tmp == ( XiePhotomap ) NULL )
2580
XIELut = CreatePointLut( xp, p, 1 << image->depth[ 0 ], inlevels,
2582
if ( XIELut == ( XieLut ) NULL )
2583
return( ( XiePhotomap ) NULL );
2585
XIEPhotomap = XieCreatePhotomap(xp->d);
2587
/* get the data from the client into the photomap */
2589
photospace = XieCreatePhotospace(xp->d);
2591
flograph = XieAllocatePhotofloGraph(4);
2592
if ( flograph == ( XiePhotoElement * ) NULL )
2594
fprintf( stderr, "GetXIEPointPhotomap: XieAllocatePhotofloGraph failed\n" );
2595
XieDestroyPhotomap( xp->d, XIEPhotomap );
2596
return( XiePhotomap ) NULL;
2599
XieFloImportPhotomap(&flograph[0],
2604
XieFloImportLUT(&flograph[1], XIELut );
2606
domain.offset_x = 0;
2607
domain.offset_y = 0;
2608
domain.phototag = 0;
2610
XieFloPoint(&flograph[2],
2617
XieFloExportPhotomap(&flograph[3],
2618
3, /* source phototag number */
2626
XieExecuteImmediate(xp->d, photospace,
2629
flograph, /* photoflo specification */
2630
4 /* number of elements */
2633
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2634
XieFreePhotofloGraph(flograph,4);
2635
XieDestroyPhotospace(xp->d, photospace);
2637
XieDestroyLUT( xp->d, XIELut );
2642
GetXIEGeometryPhotomap(XParms xp, Parms p, GeometryParms *geo, int which)
2644
XiePhotospace photospace;
2645
int flo_id, flo_notify;
2646
XiePhotoElement *flograph;
2648
static XieConstant constant = { 0.0, 0.0, 0.0 };
2649
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
2650
char *encode_params=NULL;
2652
XiePhotomap tmp, XIEPhotomap;
2654
tmp = GetXIEPhotomap( xp, p, which );
2656
/* create a photomap */
2658
XIEPhotomap = XieCreatePhotomap(xp->d);
2660
if ( XIEPhotomap == ( XiePhotomap ) NULL )
2661
return( ( XiePhotomap ) NULL );
2663
photospace = XieCreatePhotospace(xp->d);
2665
flograph = XieAllocatePhotofloGraph(3);
2666
if ( flograph == ( XiePhotoElement * ) NULL )
2668
fprintf( stderr, "GetXIEGeometryPhotomap: XieAllocatePhotofloGraph failed\n" );
2669
XieDestroyPhotomap( xp->d, XIEPhotomap );
2670
return( XiePhotomap ) NULL;
2673
XieFloImportPhotomap(&flograph[0],
2678
SetCoefficients( xp, p, 1, geo, coeffs );
2680
XieFloGeometry(&flograph[1],
2691
XieFloExportPhotomap(&flograph[2],
2692
2, /* source phototag number */
2700
XieExecuteImmediate(xp->d, photospace,
2703
flograph, /* photoflo specification */
2704
3 /* number of elements */
2707
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2708
XieFreePhotofloGraph(flograph,3);
2709
XieDestroyPhotospace(xp->d, photospace);
2714
GetXIEGeometryWindow(XParms xp, Parms p, Window w,
2715
GeometryParms *geo, int which )
2718
XiePhotospace photospace;
2719
int flo_id, flo_notify;
2720
XiePhotoElement *flograph;
2722
static XieConstant constant = { 0.0, 0.0, 0.0 };
2724
XieProcessDomain domain;
2730
image = p->finfo.image1;
2733
image = p->finfo.image2;
2736
image = p->finfo.image3;
2739
image = p->finfo.image4;
2742
fprintf( stderr, "Invalid image\n" );
2746
tmp = GetXIEPhotomap( xp, p, which );
2748
if ( ( XIELut = CreatePointLut( xp, p, 1 << image->depth[ 0 ],
2749
1 << xp->screenDepth, False ) ) == ( XieLut ) NULL )
2754
photospace = XieCreatePhotospace(xp->d);
2756
flograph = XieAllocatePhotofloGraph(5);
2757
if ( flograph == ( XiePhotoElement * ) NULL )
2759
fprintf( stderr, "GetXIEGeometryPhotomap: XieAllocatePhotofloGraph failed\n" );
2763
XieFloImportPhotomap(&flograph[0],
2768
SetCoefficients( xp, p, 1, geo, coeffs );
2770
XieFloGeometry(&flograph[1],
2781
XieFloImportLUT(&flograph[2], XIELut );
2783
domain.offset_x = 0;
2784
domain.offset_y = 0;
2785
domain.phototag = 0;
2787
XieFloPoint(&flograph[3],
2794
XieFloExportDrawable(&flograph[4],
2795
4, /* source phototag number */
2804
XieExecuteImmediate(xp->d, photospace,
2807
flograph, /* photoflo specification */
2808
5 /* number of elements */
2811
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2812
XieFreePhotofloGraph(flograph,5);
2813
XieDestroyPhotospace(xp->d, photospace);
2814
XieDestroyLUT( xp->d, XIELut );
2819
GetXIEPixmap(XParms xp, Parms p, Pixmap pixmap, int which)
2822
XiePhotospace photospace;
2823
int flo_elements, flo_id, flo_notify;
2824
XiePhotoElement *flograph;
2826
XiePhotomap XIEPhotomap;
2827
XieProcessDomain domain;
2829
XIEPhotomap = GetXIEPhotomap( xp, p, which );
2830
if ( XIEPhotomap == ( XiePhotomap ) NULL )
2836
image = p->finfo.image1;
2839
image = p->finfo.image2;
2842
image = p->finfo.image3;
2845
image = p->finfo.image4;
2848
image = ( XIEimage * ) NULL;
2852
if ( image == ( XIEimage * ) NULL )
2855
if ( ( XIELut = CreatePointLut( xp, p, 1 << image->depth[ 0 ],
2856
1 << xp->screenDepth, False ) ) == ( XieLut ) NULL )
2861
photospace = XieCreatePhotospace(xp->d);
2864
flograph = XieAllocatePhotofloGraph(flo_elements);
2865
if ( flograph == ( XiePhotoElement * ) NULL )
2867
fprintf( stderr, "GetXIEPixmap: XieAllocatePhotofloGraph failed\n" );
2869
XieDestroyLUT( xp->d, XIELut );
2873
XieFloImportPhotomap(&flograph[0],
2878
XieFloImportLUT(&flograph[1], XIELut );
2880
domain.offset_x = 0;
2881
domain.offset_y = 0;
2882
domain.phototag = 0;
2884
XieFloPoint(&flograph[2],
2891
XieFloExportDrawable(&flograph[flo_elements - 1],
2892
flo_elements - 1, /* source phototag number */
2895
0, /* x offset in window */
2896
0 /* y offset in window */
2901
XieExecuteImmediate(xp->d, photospace,
2904
flograph, /* photoflo specification */
2905
flo_elements /* number of elements */
2908
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
2909
XieFreePhotofloGraph(flograph,flo_elements);
2910
XieDestroyPhotospace( xp->d, photospace );
2912
XieDestroyLUT( xp->d, XIELut );
2917
GetXIEWindow(XParms xp, Parms p, Window window, int which)
2919
XiePhotospace photospace;
2920
int flo_elements, flo_id, flo_notify;
2921
XiePhotoElement *flograph;
2924
XiePhotomap XIEPhotomap;
2925
XieProcessDomain domain;
2930
image = p->finfo.image1;
2933
image = p->finfo.image2;
2936
image = p->finfo.image3;
2939
image = p->finfo.image4;
2942
image = ( XIEimage * ) NULL;
2946
XIEPhotomap = GetXIEPhotomap( xp, p, which );
2947
if ( XIEPhotomap == ( XiePhotomap ) NULL )
2950
if ( ( XIELut = CreatePointLut( xp, p, 1 << image->depth[ 0 ],
2951
1 << xp->screenDepth, False ) ) == ( XieLut ) NULL )
2956
photospace = XieCreatePhotospace(xp->d);
2960
flograph = XieAllocatePhotofloGraph(flo_elements);
2961
if ( flograph == ( XiePhotoElement * ) NULL )
2963
fprintf( stderr, "GetXIEWindow: XieAllocatePhotofloGraph failed\n" );
2965
XieDestroyLUT( xp->d, XIELut );
2969
XieFloImportPhotomap(&flograph[0],
2974
XieFloImportLUT(&flograph[1], XIELut );
2976
domain.offset_x = 0;
2977
domain.offset_y = 0;
2978
domain.phototag = 0;
2980
XieFloPoint(&flograph[2],
2987
XieFloExportDrawable(&flograph[3],
2988
3, /* source phototag number */
2991
0, /* x offset in window */
2992
0 /* y offset in window */
2997
XieExecuteImmediate(xp->d, photospace,
3000
flograph, /* photoflo specification */
3001
flo_elements /* number of elements */
3004
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3005
XieFreePhotofloGraph(flograph,flo_elements);
3006
XieDestroyPhotospace( xp->d, photospace );
3009
XieDestroyLUT( xp->d, XIELut );
3014
GetXIEDitheredWindow(XParms xp, Parms p, Window window, int which, int level)
3016
XiePhotospace photospace;
3017
int flo_id, flo_notify;
3018
XiePhotoElement *flograph;
3019
char *tech_parms=NULL;
3023
XieProcessDomain domain;
3029
image = p->finfo.image1;
3032
image = p->finfo.image2;
3035
image = p->finfo.image3;
3038
image = p->finfo.image4;
3042
tmp = GetXIEPhotomap( xp, p, which );
3043
if ( tmp == ( XiePhotomap ) NULL )
3046
photospace = XieCreatePhotospace(xp->d);
3048
flograph = XieAllocatePhotofloGraph(5);
3049
if ( flograph == ( XiePhotoElement * ) NULL )
3051
fprintf( stderr, "GetXIEDitheredWindow: XieAllocatePhotofloGraph failed\n" );
3055
if ( ( XIELut = CreatePointLut( xp, p, level,
3056
1 << xp->screenDepth, False ) ) == ( XieLut ) NULL )
3061
XieFloImportPhotomap(&flograph[0],
3066
levels[ 0 ] = level;
3070
tech_parms = ( char * ) NULL;
3072
XieFloDither(&flograph[ 1 ],
3076
xieValDitherDefault,
3080
XieFloImportLUT(&flograph[2], XIELut );
3082
domain.offset_x = 0;
3083
domain.offset_y = 0;
3084
domain.phototag = 0;
3086
XieFloPoint(&flograph[3],
3093
XieFloExportDrawable(&flograph[4],
3094
4, /* source phototag number */
3103
XieExecuteImmediate(xp->d, photospace,
3106
flograph, /* photoflo specification */
3107
5 /* number of elements */
3110
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3111
XieFreePhotofloGraph(flograph,5);
3112
XieDestroyLUT( xp->d, XIELut );
3117
GetXIEDitheredPhotomap(XParms xp, Parms p, int which, int level)
3119
XiePhotospace photospace;
3120
int flo_id, flo_notify;
3121
XiePhotoElement *flograph;
3122
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
3123
char *encode_params=NULL;
3125
char *tech_parms=NULL;
3126
XiePhotomap tmp, XIEPhotomap;
3128
tmp = GetXIEPhotomap( xp, p, which );
3129
if ( tmp == ( XiePhotomap ) NULL )
3130
return( ( XiePhotomap ) NULL );
3132
/* create a photomap */
3134
XIEPhotomap = XieCreatePhotomap(xp->d);
3136
/* get the data from the client into the photomap */
3138
photospace = XieCreatePhotospace(xp->d);
3140
flograph = XieAllocatePhotofloGraph(3);
3141
if ( flograph == ( XiePhotoElement * ) NULL )
3143
fprintf( stderr, "GetXIEDitheredPhotomap: XieAllocatePhotofloGraph failed\n" );
3144
XieDestroyPhotomap( xp->d, XIEPhotomap );
3145
return ( XiePhotomap ) NULL;
3148
XieFloImportPhotomap(&flograph[0],
3153
levels[ 0 ] = level;
3157
tech_parms = ( char * ) NULL;
3159
XieFloDither(&flograph[ 1 ],
3163
xieValDitherDefault,
3167
XieFloExportPhotomap(&flograph[2],
3168
2, /* source phototag number */
3176
XieExecuteImmediate(xp->d, photospace,
3179
flograph, /* photoflo specification */
3180
3 /* number of elements */
3183
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3184
XieFreePhotofloGraph(flograph,3);
3189
GetXIEDitheredTriplePhotomap(XParms xp, Parms p, int which, int ditherTech,
3190
int threshold, XieLTriplet levels)
3194
XiePhotospace photospace;
3195
XiePhotoElement *flograph;
3196
char *dithertech_parms=NULL;
3197
static XieEncodeTechnique encode_tech = xieValEncodeServerChoice;
3198
char *encode_param = ( char * ) NULL;
3199
int flo_id, flo_notify;
3201
if ( ( triple = GetXIETriplePhotomap( xp, p, which ) ) ==
3202
( XiePhotomap ) NULL )
3204
return( ( XiePhotomap ) NULL );
3207
/* create a photomap */
3209
tmp = XieCreatePhotomap(xp->d);
3210
if ( tmp == ( XiePhotomap ) NULL )
3212
XieDestroyPhotomap( xp->d, triple );
3213
return( ( XiePhotomap ) NULL );
3216
/* get the data from the client into the photomap */
3218
photospace = XieCreatePhotospace(xp->d);
3220
flograph = XieAllocatePhotofloGraph(3);
3221
if ( flograph == ( XiePhotoElement * ) NULL )
3223
fprintf( stderr, "GetXIEDitheredTriplePhotomap: XieAllocatePhotofloGraph failed\n" );
3224
XieDestroyPhotomap( xp->d, tmp );
3225
XieDestroyPhotomap( xp->d, triple );
3226
return ( XiePhotomap ) NULL;
3229
XieFloImportPhotomap(&flograph[0], triple, False);
3231
dithertech_parms = ( char * ) NULL;
3232
if ( ditherTech == xieValDitherOrdered )
3234
dithertech_parms = ( char * )
3235
XieTecDitherOrderedParam(threshold);
3236
if ( dithertech_parms == ( char * ) NULL )
3239
"Trouble loading dither technique parameters\n" );
3240
XieFreePhotofloGraph(flograph,3);
3241
XieDestroyPhotospace( xp->d, photospace );
3242
XieDestroyPhotomap( xp->d, tmp );
3243
XieDestroyPhotomap( xp->d, triple );
3248
XieFloDither( &flograph[ 1 ],
3256
XieFloExportPhotomap(&flograph[2],
3257
2, /* source phototag number */
3266
XieExecuteImmediate(xp->d, photospace,
3269
flograph, /* photoflo specification */
3270
3 /* number of elements */
3273
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3274
XieFreePhotofloGraph(flograph,3);
3275
XieDestroyPhotospace( xp->d, photospace );
3276
if ( dithertech_parms )
3277
XFree( dithertech_parms );
3282
GetXIEConstrainedPhotomap(XParms xp, Parms p, int which,
3283
XieLTriplet cliplevels, int cliptype,
3284
XieConstant in_low, XieConstant in_high,
3285
XieLTriplet out_low, XieLTriplet out_high )
3287
XiePhotospace photospace;
3288
int flo_id, flo_notify;
3289
XiePhotoElement *flograph;
3290
XieEncodeTechnique encode_tech=xieValEncodeServerChoice;
3291
char *encode_params=NULL;
3292
char *tech_parms=NULL;
3293
XiePhotomap tmp, XIEPhotomap;
3295
tmp = GetXIEPhotomap( xp, p, which );
3296
if ( tmp == ( XiePhotomap ) NULL )
3297
return( ( XiePhotomap ) NULL );
3299
/* create a photomap */
3301
XIEPhotomap = XieCreatePhotomap(xp->d);
3303
/* get the data from the client into the photomap */
3305
photospace = XieCreatePhotospace(xp->d);
3307
flograph = XieAllocatePhotofloGraph(3);
3308
if ( flograph == ( XiePhotoElement * ) NULL )
3310
fprintf( stderr, "GetXIEConstrainedPhotomap: XieAllocatePhotofloGraph failed\n" );
3311
XieDestroyPhotomap( xp->d, XIEPhotomap );
3312
return ( XiePhotomap ) NULL;
3315
XieFloImportPhotomap(&flograph[0],
3320
if ( cliptype == xieValConstrainHardClip )
3322
tech_parms = ( char * ) NULL;
3326
tech_parms = ( char * ) XieTecClipScale( in_low, in_high,
3328
if ( tech_parms == ( char * ) NULL )
3331
"GetXIEConstrainedPhotomap: Trouble loading ClipScale technique parameters\n" );
3332
fprintf( stderr, "Reverting to HardClip technique\n" );
3333
cliptype = xieValConstrainHardClip;
3337
XieFloConstrain( &flograph[1],
3344
XieFloExportPhotomap(&flograph[2],
3353
XieExecuteImmediate(xp->d, photospace,
3356
flograph, /* photoflo specification */
3357
3 /* number of elements */
3360
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3361
XieFreePhotofloGraph(flograph,3);
3363
XFree( tech_parms );
3368
GetXIEConstrainedTriplePhotomap(XParms xp, Parms p, int which,
3369
XieLTriplet cliplevels, int cliptype,
3370
XieConstant in_low, XieConstant in_high,
3371
XieLTriplet out_low, XieLTriplet out_high )
3373
XiePhotomap tmp, XIEPhotomap;
3374
XiePhotospace photospace;
3375
XiePhotoElement *flograph;
3376
char *tech_parms = ( char * ) NULL;
3377
static XieEncodeTechnique encode_tech = xieValEncodeServerChoice;
3378
char *encode_params = ( char * ) NULL;
3379
int flo_id, flo_notify;
3381
if ( ( tmp = GetXIETriplePhotomap( xp, p, which ) ) ==
3382
( XiePhotomap ) NULL )
3384
return( ( XiePhotomap ) NULL );
3387
/* create a photomap */
3389
XIEPhotomap = XieCreatePhotomap(xp->d);
3390
if ( XIEPhotomap == ( XiePhotomap ) NULL )
3392
return( ( XiePhotomap ) NULL );
3395
/* get the data from the client into the photomap */
3397
photospace = XieCreatePhotospace(xp->d);
3399
flograph = XieAllocatePhotofloGraph(3);
3400
if ( flograph == ( XiePhotoElement * ) NULL )
3402
fprintf( stderr, "GetXIEConstrainedTriplePhotomap: XieAllocatePhotofloGraph failed\n" );
3403
XieDestroyPhotomap( xp->d, XIEPhotomap );
3404
return ( XiePhotomap ) NULL;
3407
XieFloImportPhotomap(&flograph[0], tmp, False);
3409
if ( cliptype == xieValConstrainHardClip )
3411
tech_parms = ( char * ) NULL;
3415
tech_parms = ( char * ) XieTecClipScale( in_low, in_high,
3417
if ( tech_parms == ( char * ) NULL )
3420
"GetXIEConstrainedPhotomap: Trouble loading ClipScale technique parameters\n" );
3421
fprintf( stderr, "Reverting to HardClip technique\n" );
3422
cliptype = xieValConstrainHardClip;
3426
XieFloConstrain( &flograph[1],
3433
XieFloExportPhotomap(&flograph[2],
3434
2, /* source phototag number */
3443
XieExecuteImmediate(xp->d, photospace,
3446
flograph, /* photoflo specification */
3447
3 /* number of elements */
3450
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3451
XieFreePhotofloGraph(flograph,3);
3452
XieDestroyPhotospace( xp->d, photospace );
3454
XFree( tech_parms );
3459
GetXIEConstrainedGeometryTriplePhotomap(XParms xp, Parms p, int which,
3460
XieLTriplet cliplevels, int cliptype,
3462
XieConstant in_high,
3463
XieLTriplet out_low,
3464
XieLTriplet out_high,
3465
GeometryParms *geo )
3467
XiePhotomap tmp, XIEPhotomap;
3468
XiePhotospace photospace;
3469
XiePhotoElement *flograph;
3470
char *tech_parms = ( char * ) NULL;
3471
static XieEncodeTechnique encode_tech = xieValEncodeServerChoice;
3472
char *encode_params = ( char * ) NULL;
3473
int flo_id, flo_notify;
3475
static XieConstant constant = { 0.0, 0.0, 0.0 };
3477
if ( ( tmp = GetXIETriplePhotomap( xp, p, which ) ) ==
3478
( XiePhotomap ) NULL )
3480
return( ( XiePhotomap ) NULL );
3483
/* create a photomap */
3485
XIEPhotomap = XieCreatePhotomap(xp->d);
3486
if ( XIEPhotomap == ( XiePhotomap ) NULL )
3488
return( ( XiePhotomap ) NULL );
3491
/* get the data from the client into the photomap */
3493
photospace = XieCreatePhotospace(xp->d);
3495
flograph = XieAllocatePhotofloGraph(4);
3496
if ( flograph == ( XiePhotoElement * ) NULL )
3498
fprintf( stderr, "GetXIEConstrainedTriplePhotomap: XieAllocatePhotofloGraph failed\n" );
3499
XieDestroyPhotomap( xp->d, XIEPhotomap );
3500
return ( XiePhotomap ) NULL;
3503
XieFloImportPhotomap(&flograph[0], tmp, False);
3505
SetCoefficients( xp, p, 1, geo, coeffs );
3507
XieFloGeometry(&flograph[1],
3518
if ( cliptype == xieValConstrainHardClip )
3520
tech_parms = ( char * ) NULL;
3524
tech_parms = ( char * ) XieTecClipScale( in_low, in_high,
3526
if ( tech_parms == ( char * ) NULL )
3529
"GetXIEConstrainedPhotomap: Trouble loading ClipScale technique parameters\n" );
3530
fprintf( stderr, "Reverting to HardClip technique\n" );
3531
cliptype = xieValConstrainHardClip;
3535
XieFloConstrain( &flograph[2],
3542
XieFloExportPhotomap(&flograph[3],
3543
3, /* source phototag number */
3552
XieExecuteImmediate(xp->d, photospace,
3555
flograph, /* photoflo specification */
3556
4 /* number of elements */
3559
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3560
XieFreePhotofloGraph(flograph,4);
3561
XieDestroyPhotospace( xp->d, photospace );
3563
XFree( tech_parms );
3568
GetXIEGeometryTriplePhotomap(XParms xp, Parms p, int which,
3571
XiePhotomap tmp, XIEPhotomap;
3572
XiePhotospace photospace;
3573
XiePhotoElement *flograph;
3574
char *tech_parms = ( char * ) NULL;
3575
static XieEncodeTechnique encode_tech = xieValEncodeServerChoice;
3576
char *encode_params = ( char * ) NULL;
3577
int flo_id, flo_notify;
3579
static XieConstant constant = { 0.0, 0.0, 0.0 };
3581
if ( ( tmp = GetXIETriplePhotomap( xp, p, which ) ) ==
3582
( XiePhotomap ) NULL )
3584
return( ( XiePhotomap ) NULL );
3587
/* create a photomap */
3589
XIEPhotomap = XieCreatePhotomap(xp->d);
3590
if ( XIEPhotomap == ( XiePhotomap ) NULL )
3592
return( ( XiePhotomap ) NULL );
3595
/* get the data from the client into the photomap */
3597
photospace = XieCreatePhotospace(xp->d);
3599
flograph = XieAllocatePhotofloGraph(3);
3600
if ( flograph == ( XiePhotoElement * ) NULL )
3602
fprintf( stderr, "GetXIEGeometryTriplePhotomap: XieAllocatePhotofloGraph failed\n" );
3603
XieDestroyPhotomap( xp->d, XIEPhotomap );
3604
return ( XiePhotomap ) NULL;
3607
XieFloImportPhotomap(&flograph[0], tmp, False);
3609
SetCoefficients( xp, p, 1, geo, coeffs );
3611
XieFloGeometry(&flograph[1],
3622
XieFloExportPhotomap(&flograph[2],
3623
2, /* source phototag number */
3632
XieExecuteImmediate(xp->d, photospace,
3635
flograph, /* photoflo specification */
3636
3 /* number of elements */
3639
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3640
XieFreePhotofloGraph(flograph,3);
3641
XieDestroyPhotospace( xp->d, photospace );
3643
XFree( tech_parms );
3648
GetXIEDitheredTripleWindow(XParms xp, Parms p, Window w, int which,
3649
int ditherTech, int threshold, XieLTriplet levels )
3651
XiePhotomap ditheredPhoto;
3652
XiePhotospace photospace;
3653
XiePhotoElement *flograph;
3654
int flo_id, flo_notify;
3656
XWindowAttributes xwa;
3657
XieColorAllocAllParam *color_parm;
3658
int flo_elements, idx;
3661
color_parm = ( XieColorAllocAllParam * ) NULL;
3662
clist = ( XieColorList ) NULL;
3663
color_parm = XieTecColorAllocAll( 123 );
3664
if ( color_parm == ( XieColorAllocAllParam * ) NULL )
3669
if ( ( clist = XieCreateColorList( xp->d ) ) == ( XieColorList ) NULL )
3672
XFree( color_parm );
3676
if ( ( ditheredPhoto = GetXIEDitheredTriplePhotomap( xp, p, which,
3677
ditherTech, threshold, levels ) ) == ( XiePhotomap ) NULL )
3680
XieDestroyColorList( xp->d, clist );
3682
XFree( color_parm );
3686
photospace = XieCreatePhotospace(xp->d);
3688
flograph = XieAllocatePhotofloGraph(flo_elements);
3689
if ( flograph == ( XiePhotoElement * ) NULL )
3691
fprintf( stderr, "GetXIEDitheredTripleWindow: XieAllocatePhotofloGraph failed\n" );
3693
XFree( color_parm );
3695
XieDestroyColorList( xp->d, clist );
3700
XieFloImportPhotomap(&flograph[idx], ditheredPhoto, False);
3703
XGetWindowAttributes( xp->d, xp->w, &xwa );
3704
XieFloConvertToIndex(&flograph[idx],
3709
xieValColorAllocAll,
3714
XieFloExportDrawable(&flograph[idx],
3715
2, /* source phototag number */
3725
XieExecuteImmediate(xp->d, photospace,
3728
flograph, /* photoflo specification */
3729
flo_elements /* number of elements */
3732
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3733
XieFreePhotofloGraph(flograph,3);
3734
XieDestroyPhotospace( xp->d, photospace );
3737
XieDestroyColorList( xp->d, clist );
3739
XFree( color_parm );
3744
GetXIEDitheredStdTripleWindow(XParms xp, Parms p, Window w, int which,
3745
int ditherTech, int threshold,
3746
XieLTriplet levels, XStandardColormap *stdCmap)
3748
XiePhotomap ditheredPhoto;
3749
XiePhotospace photospace;
3750
XiePhotoElement *flograph;
3751
int flo_id, flo_notify;
3755
if ( ( ditheredPhoto = GetXIEDitheredTriplePhotomap( xp, p, which,
3756
ditherTech, threshold, levels ) ) == ( XiePhotomap ) NULL )
3761
photospace = XieCreatePhotospace(xp->d);
3763
flograph = XieAllocatePhotofloGraph(3);
3764
if ( flograph == ( XiePhotoElement * ) NULL )
3766
fprintf( stderr, "GetXIEDitheredStdTripleWindow: XieAllocatePhotofloGraph failed\n" );
3770
XieFloImportPhotomap(&flograph[0], ditheredPhoto, False);
3772
c1[ 0 ] = stdCmap->red_mult;
3773
c1[ 1 ] = stdCmap->green_mult;
3774
c1[ 2 ] = stdCmap->blue_mult;
3775
bias = ( float ) stdCmap->base_pixel;
3777
XieFloBandExtract( &flograph[1], 1, 1 << xp->vinfo.depth, bias, c1 );
3779
XieFloExportDrawable(&flograph[2],
3780
2, /* source phototag number */
3790
XieExecuteImmediate(xp->d, photospace,
3793
flograph, /* photoflo specification */
3794
3 /* number of elements */
3797
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3798
XieFreePhotofloGraph(flograph,3);
3799
XieDestroyPhotospace( xp->d, photospace );
3800
XieDestroyPhotomap( xp->d, ditheredPhoto );
3805
GetFileSize(char *path)
3808
struct stat _Stat_Buffer;
3809
#define file_size(path) ( stat(path,&_Stat_Buffer)== 0 ? \
3810
_Stat_Buffer.st_size : -1)
3814
if ( ( size = file_size( path ) ) < 0 )
3816
fprintf( stderr, "Couldn't stat %s\n", path );
3823
GetImageData(XParms xp, Parms p, int which)
3827
XIEimage *image = ( XIEimage * ) NULL;
3833
image = p->finfo.image1;
3835
else if ( which == 2 )
3837
image = p->finfo.image2;
3839
else if ( which == 3 )
3841
image = p->finfo.image3;
3843
else if ( which == 4 )
3845
image = p->finfo.image4;
3851
if ( p->buffer_size <= 0 )
3853
fprintf( stderr, "buffer_size is invalid\n" );
3857
size = &image->fsize;
3858
name = image->fname;
3859
sprintf( buf, "%s/%s", imagepath, name );
3861
*size = GetFileSize( buf );
3866
if ( ( fd = open( buf, O_RDONLY|O_BINARY ) ) == -1 )
3868
fprintf( stderr, "Couldn't open %s\n", buf );
3872
/* allocate the data buffer */
3874
if ( image->data == ( char * ) NULL )
3876
if ( ( image->data =
3877
(char *)malloc( *size ) ) == ( char * ) NULL )
3879
fprintf( stderr, "Couldn't allocate buffer\n" );
3886
if ( read( fd, image->data, *size ) != *size )
3888
fprintf( stderr, "Couldn't read data\n" );
3892
/* close the file */
3905
GetXIELut(XParms xp, Parms p, unsigned char *lut, int lutSize, int lutLevels)
3907
XiePhotospace photospace;
3908
int flo_id, flo_notify;
3909
XiePhotoElement *flograph;
3910
XieDataClass cclass;
3911
XieOrientation band_order;
3912
XieLTriplet length, levels;
3917
/* create a LUT for starters */
3919
tmp = XieCreateLUT(xp->d);
3921
photospace = XieCreatePhotospace(xp->d);
3923
flograph = XieAllocatePhotofloGraph(2);
3924
if ( flograph == ( XiePhotoElement * ) NULL )
3926
fprintf(stderr,"GetXIELut: XieAllocatePhotofloGraph failed\n");
3927
XieDestroyLUT( xp->d, tmp );
3928
return ( XieLut ) NULL;
3931
cclass = xieValSingleBand;
3932
band_order = xieValMSFirst;
3933
length[ 0 ] = lutSize;
3936
levels[ 0 ] = lutLevels;
3940
XieFloImportClientLUT(&flograph[0],
3952
XieFloExportLUT(&flograph[1],
3953
1, /* source phototag number */
3961
XieExecuteImmediate(xp->d, photospace,
3964
flograph, /* photoflo specification */
3965
2 /* number of elements */
3968
PumpTheClientData( xp, p, flo_id, photospace, 1, (char *)lut, lutSize,
3970
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
3971
XieFreePhotofloGraph(flograph,2);
3976
GetXIERoi(XParms xp, Parms p, XieRectangle *rects, int rectsSize)
3978
XiePhotospace photospace;
3979
int flo_id, flo_notify;
3980
XiePhotoElement *flograph;
3985
tmp = XieCreateROI(xp->d);
3987
photospace = XieCreatePhotospace(xp->d);
3989
flograph = XieAllocatePhotofloGraph(2);
3990
if ( flograph == ( XiePhotoElement * ) NULL )
3992
fprintf(stderr,"GetXIERoi: XieAllocatePhotofloGraph failed\n");
3993
XieDestroyROI( xp->d, tmp );
3994
return ( XieRoi ) NULL;
3997
XieFloImportClientROI(&flograph[0],
4001
XieFloExportROI(&flograph[1],
4002
1, /* source phototag number */
4008
XieExecuteImmediate(xp->d, photospace,
4011
flograph, /* photoflo specification */
4012
2 /* number of elements */
4015
PumpTheClientData( xp, p, flo_id, photospace, 1, (char *)rects,
4016
rectsSize * sizeof( XieRectangle ), 0 );
4017
WaitForXIEEvent( xp, xieEvnNoPhotofloDone, flo_id, 0, False );
4019
XieFreePhotofloGraph(flograph,2);
4024
EventOrErrorValid(unsigned short testcp)
4026
if ( IsEvent( testcp ) && runEvents == False )
4028
else if ( IsError( testcp ) && runErrors == False )
4036
return( IsDIS( capabilities ) );
4040
ServerIsCapable(unsigned short testcp)
4042
if ( IsFull( testcp ) && IsDIS( capabilities ) )
4048
TechniqueSupported(XParms xp, XieTechniqueGroup group, unsigned int tech)
4050
XieTechnique *techVector;
4055
if ( !XieQueryTechniques( xp->d, group, &numTech, &techVector ) )
4058
"TechniqueSupported: XieQueryTechniques failed\n" );
4064
for ( i = 0; i < numTech; i++ )
4066
if ( tech == techVector[ i ].number )
4070
if ( techVector[ i ].name )
4071
XFree( techVector[ i ].name );
4074
XFree( techVector );
4080
/* list all of the techniques supported. this isn't used by xieperf, but was
4081
used to validate TechniqueSupported() */
4091
XieTechniqueGroup group;
4092
struct _tech *techs;
4096
static struct _tech ColorAllocTechs[] = {
4097
{ "ColorAllocAll", xieValColorAllocAll },
4098
{ "ColorAllocMatch", xieValColorAllocMatch },
4099
{ "ColorAllocRequantize", xieValColorAllocRequantize } };
4101
static struct _tech ConstrainTechs[] = {
4102
{ "ConstrainClipScale", xieValConstrainClipScale },
4103
{ "ConstrainHardClip", xieValConstrainHardClip } };
4105
static struct _tech ConvolveTechs[] = {
4106
{ "ConvolveConstant", xieValConvolveConstant },
4107
{ "ConvolveReplicate", xieValConvolveReplicate } };
4109
static struct _tech DecodeTechs[] = {
4110
{ "DecodeUncompressedSingle", xieValDecodeUncompressedSingle },
4111
{ "DecodeUncompressedTriple", xieValDecodeUncompressedTriple },
4112
{ "DecodeG31D", xieValDecodeG31D },
4113
{ "DecodeG32D", xieValDecodeG32D },
4114
{ "DecodeG42D", xieValDecodeG42D },
4115
{ "DecodeJPEGBaseline", xieValDecodeJPEGBaseline },
4116
{ "DecodeJPEGLossless", xieValDecodeJPEGLossless },
4117
{ "DecodeTIFF2", xieValDecodeTIFF2 },
4118
{ "DecodeTIFFPackBits", xieValDecodeTIFFPackBits } };
4120
static struct _tech DitherTechs[] = {
4121
{ "DitherErrorDiffusion", xieValDitherErrorDiffusion },
4122
{ "DitherOrdered", xieValDitherOrdered } };
4124
static struct _tech ColorspaceTechs[] = {
4125
{ "CIELab", xieValCIELabToRGB },
4126
{ "CIEXYZ", xieValCIEXYZToRGB },
4127
{ "YCbCr", xieValYCbCrToRGB },
4128
{ "YCC", xieValYCCToRGB } };
4130
static struct _tech EncodeTechs[] = {
4131
{ "EncodeUncompressedSingle", xieValEncodeUncompressedSingle },
4132
{ "EncodeUncompressedTriple", xieValEncodeUncompressedTriple },
4133
{ "EncodeG31D", xieValEncodeG31D },
4134
{ "EncodeG32D", xieValEncodeG32D },
4135
{ "EncodeG42D", xieValEncodeG42D },
4136
{ "EncodeJPEGBaseline", xieValEncodeJPEGBaseline },
4137
{ "EncodeJPEGLossless", xieValEncodeJPEGLossless },
4138
{ "EncodeTIFF2", xieValEncodeTIFF2 },
4139
{ "EncodeTIFFPackBits", xieValEncodeTIFFPackBits } };
4141
static struct _tech GeometryTechs[] = {
4142
{ "GeometryAntialias", xieValGeomAntialias },
4143
{ "GeometryAntialiasByArea", xieValGeomAntialiasByArea },
4144
{ "GeometryAntialiasByLowpass", xieValGeomAntialiasByLPF },
4145
{ "GeometryBilinearInterpolation", xieValGeomBilinearInterp },
4146
{ "GeometryGaussian", xieValGeomGaussian },
4147
{ "GeometryNearestNeighbor", xieValGeomNearestNeighbor } };
4149
static struct _tech GamutTechs[] = {
4150
{ "GamutNone", xieValGamutNone },
4151
{ "GamutClipRGB", xieValGamutClipRGB } };
4153
static struct _tech HistogramTechs[] = {
4154
{ "HistogramFlat", xieValHistogramFlat },
4155
{ "HistogramGaussian", xieValHistogramGaussian },
4156
{ "HistogramHyperbolic", xieValHistogramHyperbolic } };
4158
static struct _tech WhiteAdjustTechs[] = {
4159
{ "WhiteAdjustNone", xieValWhiteAdjustNone },
4160
{ "WhiteAdjustCIELabShift", xieValWhiteAdjustCIELabShift } };
4162
static struct _class classes[] = {
4163
{ "ColorAlloc", True, xieValColorAlloc, ColorAllocTechs,
4164
sizeof( ColorAllocTechs ) / sizeof( struct _tech ) },
4165
{ "Constrain", True, xieValConstrain, ConstrainTechs,
4166
sizeof( ConstrainTechs ) / sizeof( struct _tech ) },
4167
{ "Convolve", True, xieValConvolve, ConvolveTechs,
4168
sizeof( ConvolveTechs ) / sizeof( struct _tech ) },
4169
{ "ConvertFromRGB", True, xieValConvertFromRGB, ColorspaceTechs,
4170
sizeof( ColorspaceTechs ) / sizeof( struct _tech ) },
4171
{ "ConvertToRGB", True, xieValConvertToRGB, ColorspaceTechs,
4172
sizeof( ColorspaceTechs ) / sizeof( struct _tech ) },
4173
{ "Decode", False, xieValDecode, DecodeTechs,
4174
sizeof( DecodeTechs ) / sizeof( struct _tech ) },
4175
{ "Dither", True, xieValDither, DitherTechs,
4176
sizeof( DitherTechs ) / sizeof( struct _tech ) },
4177
{ "Encode", False, xieValEncode, EncodeTechs,
4178
sizeof( EncodeTechs ) / sizeof( struct _tech ) },
4179
{ "Gamut", True, xieValGamut, GamutTechs,
4180
sizeof( GamutTechs ) / sizeof( struct _tech ) },
4181
{ "Geometry", False, xieValGeometry, GeometryTechs,
4182
sizeof( GeometryTechs ) / sizeof( struct _tech ) },
4183
{ "Histogram", True, xieValHistogram, HistogramTechs,
4184
sizeof( HistogramTechs ) / sizeof( struct _tech ) },
4185
{ "WhiteAdjust", True, xieValWhiteAdjust, WhiteAdjustTechs,
4186
sizeof( WhiteAdjustTechs ) / sizeof( struct _tech ) } };
4189
ListAllTechs(XParms xp)
4193
for ( i = 0; i < sizeof( classes ) / sizeof( struct _class ); i++ )
4195
printf( "Class name: %s\n", classes[ i ].name );
4196
for ( j = 0; j < classes[ i ].n; j++ )
4198
printf( "\tTechnique %s:", classes[ i ].techs[ j ].name );
4199
if (classes[ i ].full==True && IsDIS( capabilities ))
4201
printf( " is not supported\n" );
4203
else if ( TechniqueSupported( xp, classes[ i ].group,
4204
classes[ i ].techs[ j ].tech ) == True )
4206
printf( " is supported\n" );
4210
printf( " is not supported\n" );
4219
FillHisto(XieHistogramData histos[], int size, int levels)
4225
for ( i = 0; i < size; i++ )
4227
histos[ i ].value = i + 40;
4228
histos[ i ].count = i * sy;
4234
DrawHistogram(XParms xp, Window w, XieHistogramData histos[], int size,
4235
unsigned long levels)
4237
unsigned long maxcount;
4246
for ( i = 0; i < size; i++ )
4248
if ( histos[ i ].count > maxcount )
4249
maxcount = histos[ i ].count;
4250
if ( histos[ i ].value > levels )
4251
levels = histos[ i ].value;
4254
if ( maxcount == 0 )
4257
xadd = ( short ) ( ( float ) MONWIDTH * 0.15 );
4260
sx = ( float ) ( MONWIDTH - xadd ) / ( float ) ( levels + 1 );
4261
sy = ( float ) ( MONHEIGHT - yadd ) / ( float ) maxcount;
4263
XClearWindow( xp->d, w );
4267
XDrawImageString( xp->d, w, tgc, xadd,
4268
MONHEIGHT - 3, "0", 1 );
4269
sprintf( buf, "%ld", levels );
4270
XDrawImageString( xp->d, w, tgc, MONWIDTH -
4271
strlen( buf ) * 14, MONHEIGHT - 3, buf, strlen( buf ) );
4275
sprintf( buf, "%ld", maxcount );
4276
XDrawImageString( xp->d, w, tgc, 3,
4277
20, buf, strlen( buf ) );
4278
XDrawImageString( xp->d, w, tgc, 3,
4279
MONHEIGHT - yadd, "0", 1 );
4283
XDrawLine( xp->d, w, tgc, xadd, MONHEIGHT - yadd,
4288
XDrawLine( xp->d, w, tgc, xadd, MONHEIGHT - yadd,
4289
MONWIDTH, MONHEIGHT - yadd );
4291
rects = ( XRectangle * ) malloc( sizeof( XRectangle ) * size );
4292
if ( rects == ( XRectangle * ) NULL )
4295
/* create the rectangles */
4297
for ( i = 0; i < size; i++ )
4299
rects[ i ].width = ( short ) ceil( sx );
4300
rects[ i ].height = ( short ) ( sy * histos[ i ].count );
4301
rects[ i ].x = xadd + ( short ) ( sx * histos[ i ].value );
4302
rects[ i ].y = ( short ) MONHEIGHT - yadd - rects[ i ].height;
4307
XFillRectangles( xp->d, w, tgc, rects, size );
4314
GetStandardColormap(XParms xp, XStandardColormap *stdColormap, Atom atom)
4317
int numberColormaps;
4318
XStandardColormap *colormapsReturned;
4321
visualId = XVisualIDFromVisual( xp->vinfo.visual );
4322
if ( !XGetRGBColormaps(xp->d, RootWindow(xp->d, DefaultScreen( xp->d )),
4323
&colormapsReturned, &numberColormaps, atom ) )
4325
status = XmuLookupStandardColormap( xp->d,
4326
DefaultScreen( xp->d ),
4330
True, /* Don't replace existing cmap */
4334
status = XGetRGBColormaps( xp->d,
4335
RootWindow( xp->d, DefaultScreen( xp->d ) ),
4345
for ( i = 0; i < numberColormaps; i++ )
4347
if (visualId == colormapsReturned[i].visualid)
4349
memcpy( ( char * ) stdColormap,
4350
( char * ) &colormapsReturned[ i ],
4351
sizeof( XStandardColormap ) );
4352
XFree( colormapsReturned );
4353
if ( atom == XA_RGB_BEST_MAP )
4354
RGB_BESTStandardColormapObtained = True;
4358
XFree( colormapsReturned );
4363
#define SETLUT if ( lutCellSize == sizeof( char ) ) {\
4364
*( ( unsigned char * ) ptr ) = val; \
4365
ptr+=sizeof(char); } \
4366
else if ( lutCellSize == sizeof( short ) ) { \
4367
*( ( unsigned short * ) ptr ) = val; \
4368
ptr+=sizeof(short); } \
4369
else if ( lutCellSize == sizeof( int ) ) { \
4370
*( ( unsigned int * ) ptr ) = val; \
4371
ptr+=sizeof(int); } \
4373
*( ( unsigned long * ) ptr) = val; \
4374
ptr+=sizeof(long); }
4376
#define SETTDLUT if ( lutCellSize == sizeof( char ) ) {\
4377
*( ( unsigned char * ) ptr ) = val * lowbit( DCRedMask ); \
4378
*( ( unsigned char * ) ptr ) |= val * lowbit( DCGreenMask ); \
4379
*( ( unsigned char * ) ptr ) |= val * lowbit( DCBlueMask ); \
4380
ptr+=sizeof(char); } \
4381
else if ( lutCellSize == sizeof( short ) ) { \
4382
*( ( unsigned short * ) ptr ) = val * lowbit( DCRedMask ); \
4383
*( ( unsigned short * ) ptr ) |= val * lowbit( DCGreenMask ); \
4384
*( ( unsigned short * ) ptr ) |= val * lowbit( DCBlueMask ); \
4385
ptr+=sizeof(short); } \
4386
else if ( lutCellSize == sizeof( int ) ) { \
4387
*( ( unsigned int * ) ptr ) = val * lowbit( DCRedMask ); \
4388
*( ( unsigned int * ) ptr ) |= val * lowbit( DCGreenMask ); \
4389
*( ( unsigned int * ) ptr ) |= val * lowbit( DCBlueMask ); \
4390
ptr+=sizeof(int); } \
4392
*( ( unsigned long * ) ptr ) = val * lowbit( DCRedMask ); \
4393
*( ( unsigned long * ) ptr ) |= val * lowbit( DCGreenMask ); \
4394
*( ( unsigned long * ) ptr ) |= val * lowbit( DCBlueMask ); \
4395
ptr+=sizeof(long); }
4398
DepthFromLevels(int levels)
4403
bp = ( sizeof( int ) << 3 ) - 1;
4405
while ( mask && !( mask & levels ) )
4408
mask = ( ( mask >> 1 ) & ~mask );
4414
TDLutCellSize(XParms xp)
4419
bp = DepthFromLevels( DCRedMask );
4422
bp = DepthFromLevels( DCGreenMask );
4425
bp = DepthFromLevels( DCBlueMask );
4429
return( LutCellSize( max ) );
4433
LutCellSize(int depth)
4435
if ( depth >= 0 && depth <= 7 )
4437
else if ( depth > 8 && depth <= 15 )
4439
else if ( depth > 16 && depth <= 31 )
4441
return( ( depth + 7 ) >> 3 );
4445
CreatePointLut(XParms xp, Parms p, int inlevels, int outlevels,
4446
Bool computeLutFromLevels )
4448
unsigned char *lut, *ptr;
4451
int i, j, val, cclass;
4452
int step, increment;
4456
#if defined(__cplusplus) || defined(c_plusplus)
4457
cclass = xp->vinfo.c_class;
4459
cclass = xp->vinfo.class;
4463
outdepth = DepthFromLevels( outlevels );
4464
if ( ( cclass == DirectColor || cclass == TrueColor ) &&
4465
computeLutFromLevels == False )
4467
lutCellSize = TDLutCellSize( xp );
4471
lutCellSize = LutCellSize( outdepth );
4474
if ( lutCellSize != sizeof( char ) && lutCellSize != sizeof( short )
4475
&& lutCellSize != sizeof( int ) && lutCellSize != sizeof( long ) )
4477
fprintf( stderr, "CreatePointLut: cell size not supported\n" );
4478
return( ( XieLut ) NULL );
4481
if ( inlevels == outlevels )
4486
else if ( inlevels > outlevels )
4489
step = inlevels / outlevels;
4491
else /* outlevels > inlevels */
4493
increment = (outlevels - 1) / (inlevels - 1);
4497
lut = (unsigned char *) malloc( lutSize * lutCellSize );
4499
if ( lut == ( unsigned char * ) NULL )
4501
fprintf( stderr, "CreatePointLut: malloc failed allocating lut\n" );
4502
return( ( XieLut ) NULL );
4505
/* initialize the lut */
4509
for ( i = 0; i < lutSize; i++ )
4511
if ( cclass != DirectColor && cclass != TrueColor ) {
4524
if ( ( cclass == DirectColor || cclass == TrueColor ) &&
4525
computeLutFromLevels == False )
4527
outlevels = TrueOrDirectLevels( xp );
4530
retval = GetXIELut( xp, p, lut, lutSize * lutCellSize,
4537
TrueOrDirectLevels(XParms xp)
4539
int depth = xp->screenDepth;
4541
if ( rbits != gbits || gbits != bbits )
4543
return( 1 << ( rbits + gbits + bbits ) );
4547
return( 1 << depth );
4552
TripleTrueOrDirectLevels(XParms xp)
4554
int depth = xp->screenDepth;
4556
if ( rbits != gbits || gbits != bbits )
4558
return( 1 << depth );
4562
return( xp->vinfo.colormap_size );
4566
/* generate red_mult, green_mult, and blue_mult, and red_max, green_max,
4567
blue_max, like in StandardColormaps */
4570
CreateStandardColormap(XParms xp, XStandardColormap *stdCmap, int atom)
4572
XWindowAttributes xwa;
4575
int r_mask, g_mask, b_mask;
4577
#if defined(__cplusplus) || defined(c_plusplus)
4578
cclass = xp->vinfo.c_class;
4580
cclass = xp->vinfo.class;
4583
XGetWindowAttributes( xp->d, xp->w, &xwa );
4584
stdCmap->colormap = xwa.colormap;
4586
if ( IsTrueColorOrDirectColor( cclass ) )
4588
stdCmap->red_max = ( 1 << rbits ) - 1;
4589
stdCmap->green_max = ( 1 << gbits ) - 1;
4590
stdCmap->blue_max = ( 1 << bbits ) - 1;
4594
XmuGetColormapAllocation(&xp->vinfo, atom,
4596
&stdCmap->green_max,
4597
&stdCmap->blue_max);
4600
r_mask = xp->vinfo.red_mask;
4601
g_mask = xp->vinfo.green_mask;
4602
b_mask = xp->vinfo.blue_mask;
4607
while ( !( mask & r_mask ) ) { i+=1; mask = mask << 1; }
4608
stdCmap->red_mult = 1 << i;
4612
stdCmap->red_mult = 1;
4618
while ( !( mask & g_mask ) ) { i+=1; mask = mask << 1; }
4619
stdCmap->green_mult = 1 << i;
4623
stdCmap->green_mult = 1;
4629
while ( !( mask & b_mask ) ) { i+=1; mask = mask << 1; }
4630
stdCmap->blue_mult = 1 << i;
4634
stdCmap->blue_mult = 1;
4641
GetControlPlane(XParms xp, int which)
4644
XiePhotomap ControlPlane;
4646
ControlPlane = ( XiePhotomap ) NULL;
4647
p.finfo.image1 = GetImageStruct( which );
4648
p.buffer_size = 2048;
4649
if ( p.finfo.image1 != ( XIEimage * ) NULL )
4651
ControlPlane = GetXIEPointPhotomap( xp, &p, 1, 2, True );
4653
return( ControlPlane );
4657
* integer cube roots by Newton's method
4659
* Stephen Gildea, MIT X Consortium, July 1991
4662
/* Newton's Method: x_n+1 = x_n - ( f(x_n) / f'(x_n) ) */
4664
/* for cube roots, x^3 - a = 0, x_new = x - 1/3 (x - a/x^2) */
4667
* Quick and dirty cube roots. Nothing fancy here, just Newton's method.
4668
* Only works for positive integers (since that's all we need).
4669
* We actually return floor(cbrt(a)) because that's what we need here, too.
4673
icbrt_with_guess(int a, int guess)
4683
delta = (guess - a/(guess*guess))/3;
4685
} while (delta != 0);
4687
if (guess*guess*guess > a)
4694
icbrt_with_bits(int a,
4695
int bits) /* log 2 of a */
4698
return icbrt_with_guess(a, a>>2*bits/3);
4702
icbrt(int a) /* integer cube root */
4704
register int bits = 0;
4705
register unsigned n = a;
4712
return icbrt_with_bits(a, bits);