1
/* $Xorg: loadData.c,v 1.4 2000/08/17 19:54:13 cpqbld Exp $ */
4
* (c) Copyright 1990 Tektronix Inc.
7
* Permission to use, copy, modify, and distribute this software and its
8
* documentation for any purpose and without fee is hereby granted,
9
* provided that the above copyright notice appear in all copies and that
10
* both that copyright notice and this permission notice appear in
11
* supporting documentation, and that the name of Tektronix not be used
12
* in advertising or publicity pertaining to distribution of the software
13
* without specific, written prior permission.
15
* Tektronix disclaims all warranties with regard to this software, including
16
* all implied warranties of merchantability and fitness, in no event shall
17
* Tektronix be liable for any special, indirect or consequential damages or
18
* any damages whatsoever resulting from loss of use, data or profits,
19
* whether in an action of contract, negligence or other tortious action,
20
* arising out of or in connection with the use or performance of this
28
* TekCMS API routine that reads screen data from a file
29
* and then loads the data on the root window of the screen.
34
/* $XFree86: xc/programs/xcmsdb/loadData.c,v 3.3 2001/07/25 15:05:18 dawes Exp $ */
45
#include <X11/Xatom.h>
51
* External declarations required locally to this package
52
* that are not already declared in any of the included header
53
* files (external includes or internal includes).
60
* typedefs local to this package (for use with local vars).
64
typedef struct _DefineEntry {
73
static int linenum = 0;
75
static DefineEntry KeyTbl[] = {
76
{ SC_BEGIN_KEYWORD, SC_BEGIN },
77
{ SC_END_KEYWORD, SC_END },
78
{ COMMENT_KEYWORD, COMMENT },
79
{ NAME_KEYWORD, NAME },
80
{ MODEL_KEYWORD, MODEL },
81
{ PART_NUMBER_KEYWORD, PART_NUMBER },
82
{ SERIAL_NUMBER_KEYWORD, SERIAL_NUMBER },
83
{ REVISION_KEYWORD, REVISION },
84
{ SCREEN_CLASS_KEYWORD, SCREEN_CLASS },
85
{ COLORIMETRIC_BEGIN_KEYWORD, COLORIMETRIC_BEGIN },
86
{ COLORIMETRIC_END_KEYWORD, COLORIMETRIC_END },
87
{ XYZTORGBMAT_BEGIN_KEYWORD, XYZTORGBMAT_BEGIN },
88
{ XYZTORGBMAT_END_KEYWORD, XYZTORGBMAT_END },
89
{ WHITEPT_XYZ_BEGIN_KEYWORD, WHITEPT_XYZ_BEGIN },
90
{ WHITEPT_XYZ_END_KEYWORD, WHITEPT_XYZ_END },
91
{ RGBTOXYZMAT_BEGIN_KEYWORD, RGBTOXYZMAT_BEGIN },
92
{ RGBTOXYZMAT_END_KEYWORD, RGBTOXYZMAT_END },
93
{ IPROFILE_BEGIN_KEYWORD, IPROFILE_BEGIN },
94
{ IPROFILE_END_KEYWORD, IPROFILE_END },
95
{ ITBL_BEGIN_KEYWORD, ITBL_BEGIN },
96
{ ITBL_END_KEYWORD, ITBL_END },
100
static DefineEntry ScrnClassTbl[] = {
101
{ VIDEO_RGB_KEYWORD, VIDEO_RGB },
103
{ VIDEO_GRAY_KEYWORD, VIDEO_GRAY },
108
#define KEY_VISUALID 1
111
#define KEY_RED_MASK 4
112
#define KEY_GREEN_MASK 5
113
#define KEY_BLUE_MASK 6
114
#define KEY_COLORMAP_SIZE 7
115
#define KEY_BITS_PER_RGB 8
117
static DefineEntry VisualOptKeyTbl[] = {
118
{ "visualid", KEY_VISUALID },
119
{ "depth", KEY_DEPTH },
120
{ "class", KEY_CLASS },
121
{ "red_mask", KEY_RED_MASK },
122
{ "green_mask", KEY_GREEN_MASK },
123
{ "blue_mask", KEY_BLUE_MASK },
124
{ "colormap_size", KEY_COLORMAP_SIZE },
125
{ "bits_per_rgb", KEY_BITS_PER_RGB },
128
static DefineEntry VisualClassTbl[] = {
129
{ "StaticGray", StaticGray },
130
{ "GrayScale", GrayScale },
131
{ "StaticColor", StaticColor },
132
{ "PseudoColor", PseudoColor },
133
{ "TrueColor", TrueColor },
134
{ "DirectColor", DirectColor },
139
/************************************************************************
143
************************************************************************/
147
* StrToDefine - convert a string to a define
152
StrToDefine(DefineEntry pde[], /* IN: table of X string-define pairs */
153
/* last entry must contain pair "", 0 */
154
char *pstring) /* IN: string to be looked up in that table */
157
* Converts a string to an integer define.
159
* Looks up the string in the table and returns the integer
160
* associated with the string.
162
* Later may need similar function for unsigned long define.
167
* The int equivalent of the defined string.
168
* -1 if the string is not found in table
172
while( strcmp(pde->pString,"") != 0 ){
173
if( strcmp(pde->pString,pstring) == 0){
188
DefineToStr(DefineEntry pde[], /* IN: table of X string-define pairs */
189
/* last entry must contain pair "", 0 */
190
int id) /* IN: id to be looked up in that table */
193
* Converts a string to an integer define.
195
* Looks up the string in the table and returns the integer
196
* associated with the string.
198
* Later may need similar function for unsigned long define.
203
* The int equivalent of the defined string.
204
* -1 if the string is not found in table
208
while(pde->define != -1) {
209
if (pde->define == id) {
210
return(pde->pString);
219
* SCKeyOf - convert keyword into key ID
224
SCKeyOf(char *string)
227
* Converts a string to an integer define.
229
* Looks up the string in the table and returns the integer
230
* associated with the string.
232
* Later may need similar function for unsigned long define.
237
* The int equivalent of the defined string.
238
* -1 if the string is not found in table
242
return(StrToDefine(KeyTbl, string));
248
* SCScrnClassOf - convert screen class string into class ID
253
SCScrnClassOf(char *string)
256
* Converts a string to an integer define.
258
* Looks up the string in the table and returns the integer
259
* associated with the string.
261
* Later may need similar function for unsigned long define.
266
* The int equivalent of the defined string.
267
* -1 if the string is not found in table
271
return(StrToDefine(ScrnClassTbl, string));
277
* SCScrnClassStringOf - convert screen class id into class string
282
SCScrnClassStringOf(int id)
285
* Converts a id to astring
288
* Pointer to string if found; otherwise NULL.
292
return(DefineToStr(ScrnClassTbl, id));
295
/* close the stream and return any memory allocated. */
298
closeS(FILE *stream, XDCCC_Correction *pCorrection)
300
XDCCC_Correction* pNext;
304
while (pCorrection) {
305
pNext = pCorrection->next;
312
* Get a line of text from the stream.
315
nextline(char *buf, int maxch, FILE *stream)
318
return (fgets(buf, maxch, stream));
323
ProcessColorimetric(FILE *stream, XDCCC_Matrix *pMatrix, int VisualFlag)
326
char keyword[BUFSIZ];
327
char token[BUFSIZ], *ptoken;
329
unsigned int matrices_processed = 0;
330
/* bit 0 for XYZtoRGB matrix */
331
/* bit 1 for RGBtoXYZ matrix */
333
/* 0 -- looking for matrix */
334
/* 1 -- processing data from matrix */
335
/* 2 -- both matrices processed */
336
/* Note: the order of the matrices is not important. */
338
XcmsFloat *pElement = NULL;
340
while ((nextline(buf, BUFSIZ, stream)) != NULL) {
341
if ((ntok = sscanf(buf, "%s %s", keyword, token)) > 0) {
342
switch (SCKeyOf(keyword)) {
343
case XYZTORGBMAT_BEGIN :
344
if (VisualFlag != VIDEO_RGB) {
346
"Line %d: Keyword XYZTORGBMAT_BEGIN mismatch for visual %s.\n",
347
linenum, SCScrnClassStringOf(VisualFlag));
352
"Line %d: Extraneous keyword %s.\n",
358
pElement = (XcmsFloat *) pMatrix->XYZtoRGBmatrix;
360
case XYZTORGBMAT_END :
361
if (VisualFlag != VIDEO_RGB) {
363
"Line %d: Keyword XYZTORGBMAT_END mismatch for visual %s.\n",
364
linenum, SCScrnClassStringOf(VisualFlag));
367
if ((state != 1) || (count != 9)) {
369
"Line %d: Incomplete XYZtoRGB matrix -- Premature %s\n",
373
matrices_processed |= 0x1;
374
if (matrices_processed == 3) {
380
case RGBTOXYZMAT_BEGIN :
381
if (VisualFlag != VIDEO_RGB) {
383
"Line %d: Keyword RGBTOXYZMAT_BEGIN mismatch for visual %s.\n",
384
linenum, SCScrnClassStringOf(VisualFlag));
388
fprintf(stderr, "Line %d: Extraneous keyword %s.\n",
394
pElement = (XcmsFloat *) pMatrix->RGBtoXYZmatrix;
396
case RGBTOXYZMAT_END :
397
if (VisualFlag != VIDEO_RGB) {
399
"Line %d: Keyword RGBTOXYZMAT_END mismatch for visual %s.\n",
400
linenum, SCScrnClassStringOf(VisualFlag));
403
if ((state != 1) || (count != 9)) {
405
"Line %d: Incomplete RGBtoXYZ matrix -- Premature %s\n",
409
matrices_processed |= 0x2;
410
if (matrices_processed == 3) {
417
case WHITEPT_XYZ_BEGIN :
418
if (VisualFlag != VIDEO_GRAY) {
420
"Line %d: Keyword WHITEPT_XYZ_BEGIN mismatch for visual %s.\n",
421
linenum, SCScrnClassStringOf(VisualFlag));
426
"Line %d: Extraneous keyword %s.\n",
432
pElement = (XcmsFloat *) pMatrix->XYZtoRGBmatrix;
434
case WHITEPT_XYZ_END :
435
if (VisualFlag != VIDEO_GRAY) {
437
"Line %d: Keyword WHITEPT_XYZ_END mismatch for visual %s.\n",
438
linenum, SCScrnClassStringOf(VisualFlag));
441
if ((state != 1) || (count != 3)) {
443
"Line %d: Incomplete white point -- Premature %s\n",
451
for (ptoken = strtok(buf, DATA_DELIMS); ptoken != NULL;
452
ptoken = strtok(NULL, DATA_DELIMS)) {
453
if (sscanf(ptoken, "%lf", pElement) != 1) {
454
if (VisualFlag == VIDEO_RGB) {
456
"Line %d: Invalid matrix value %s.",
460
"Line %d: Invalid CIEXYZ value %s.\n",
466
if (VisualFlag == VIDEO_RGB) {
469
"Line %d: Extra matrix value %s\n",
476
"Line %d: Extra CIEXYZ value %s.\n",
483
case COLORIMETRIC_BEGIN :
485
"Line %d: Extraneous keyword %s.\n",
488
/* NOTREACHED */break;
489
case COLORIMETRIC_END :
492
"Line %d: Incomplete Colorimetric data -- Premature %s\n",
498
/* Currently, do nothing. */
502
"Line %d: Unexpected keyword %s\n",
505
/* NOTREACHED */break;
507
} else if (ntok < 0) {
509
fprintf(stderr, "Line %d: Unrecognized keyword\n", linenum);
511
/* NOTREACHED */break;
518
ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection)
522
char *tableStr, *sizeStr, *ptoken;
525
/************************************************
526
* 0 -- Looking for Intensity Table(s) *
527
* 1 -- Processing Intensity Table(s) *
528
************************************************/
531
IntensityRec *pIRec = NULL;
533
while ((nextline(buf, BUFSIZ, stream)) != NULL) {
534
ptoken = keyword = strtok(buf, DATA_DELIMS);
535
if (keyword != (char*)NULL) {
536
switch (SCKeyOf(keyword)) {
539
fprintf(stderr,"Line %d: unexpected keyword %s\n",
543
tableStr = strtok((char*)NULL, DATA_DELIMS);
544
sizeStr = strtok((char*)NULL, DATA_DELIMS);
545
if ((sizeStr == (char*)NULL) ||
546
sscanf(sizeStr, "%d", &size) != 1) {
548
"Line %d: invalid Intensity Table size, %s.\n",
554
"Line %d: count %d < 0 for Intensity Table.\n",
558
if (strcmp(tableStr, "GREEN") == 0) {
559
if (pCorrection->nTables != 3) {
560
fprintf(stderr,"Line %d: incorrect number of tables\n",
564
if (pCorrection->pGreenTbl->pBase != NULL) {
566
"Line %d: multiple GREEN Intensity Profiles\n",
570
pCorrection->pGreenTbl->nEntries = size;
571
pCorrection->pGreenTbl->pBase =
572
(IntensityRec *) calloc (size, sizeof(IntensityRec));
573
if (!pCorrection->pGreenTbl->pBase) {
575
"Line %d: Unable to allocate space for GREEN Intensity Profile\n", linenum);
578
pIRec = pCorrection->pGreenTbl->pBase;
579
} else if (strcmp(tableStr, "BLUE") == 0) {
580
if (pCorrection->nTables != 3) {
582
"Line %d: incorrect number of tables\n",
586
if (pCorrection->pBlueTbl->pBase != NULL) {
588
"Line %d: multiple BLUE Intensity Profiles\n",
592
pCorrection->pBlueTbl->nEntries = size;
593
pCorrection->pBlueTbl->pBase =
594
(IntensityRec *) calloc (size, sizeof(IntensityRec));
595
if (!pCorrection->pBlueTbl->pBase) {
597
"Line %d: Unable to allocate space for BLUE Intensity Profile\n", linenum);
600
pIRec = pCorrection->pBlueTbl->pBase;
602
if (!strcmp(tableStr, "RGB") && pCorrection->nTables != 1) {
603
fprintf(stderr,"Line %d: multiple RGB Intensity Tables",
607
if (pCorrection->pRedTbl->pBase != NULL) {
609
"Line %d: multiple RED or GREEN or BLUE Intensity Tables\n",
613
pCorrection->pRedTbl->nEntries = size;
614
pCorrection->pRedTbl->pBase =
615
(IntensityRec *) calloc (size, sizeof(IntensityRec));
616
if (!pCorrection->pRedTbl->pBase) {
618
"Line %d: Unable to allocate space for intensity table\n", linenum);
621
pIRec = pCorrection->pRedTbl->pBase;
627
if ((state != 1) || (count != size)) {
629
"Line %d: incomplete Intensity Table -- Premature %s\n",
638
/********************************************************
639
* Note: tableType should only be 0 or 1 at this point.
640
* 0 indicates value and intensity stored.
641
* 1 indicates only intensity stored.
642
********************************************************/
643
if (pCorrection->tableType) {
644
if (sscanf(ptoken, "%lf", &pIRec->intensity) != 1) {
646
"Line %d: invalid Intensity Profile value %s\n",
650
/* With tableType 1 only store the intensity. */
654
/* Note ansi C can handle 0x preceeding hex number */
655
if (sscanf(ptoken, "%hi", &tmp) != 1) {
657
"Line %d: invalid Intensity Profile value %s\n",
662
if ((ptoken = strtok(NULL, DATA_DELIMS)) == NULL) {
664
"Line %d: missing Intensity Profile value\n",
668
if (sscanf(ptoken, "%lf", &pIRec->intensity) != 1) {
670
"Line %d: invalid Intensity Profile intensity %s\n",
674
/* With tableType 0 only store both value & intensity*/
677
if (++count > size) {
679
"Line %d: extra Intensity value %s\n",
683
ptoken = strtok(NULL, DATA_DELIMS);
684
} while(ptoken != NULL);
686
case IPROFILE_BEGIN :
687
fprintf(stderr,"Line %d: extraneous keyword %s\n",
690
/* NOTREACHED */break;
692
if ((state != 0) || (nTbl != pCorrection->nTables)) {
694
"Line %d: incomplete Intensity Profile data -- Premature %s\n",
703
fprintf(stderr,"Line %d: unexpected keyword %s\n",
706
/* NOTREACHED */break;
708
} /* else its was just a blank line */
714
PutTableType0Card8(IntensityTbl *pTbl, unsigned char **pCard8)
720
count = pTbl->nEntries;
721
**pCard8 = count - 1;
723
for (; count; count--, pIRec++) {
724
**pCard8 = pIRec->value >> 8;
726
**pCard8 = pIRec->intensity * 255.0;
732
PutTableType1Card8(IntensityTbl *pTbl, unsigned char **pCard8)
738
count = pTbl->nEntries;
739
**pCard8 = count - 1;
741
for (; count; count--, pIRec++) {
742
**pCard8 = pIRec->intensity * 255.0;
748
PutTableType0Card16(IntensityTbl *pTbl, unsigned short **pCard16)
754
count = pTbl->nEntries;
755
**pCard16 = count - 1;
757
for (; count; count--, pIRec++) {
758
**pCard16 = pIRec->value;
760
**pCard16 = pIRec->intensity * 65535.0;
766
PutTableType1Card16(IntensityTbl *pTbl, unsigned short **pCard16)
772
count = pTbl->nEntries;
773
**pCard16 = count - 1;
775
for (; count; count--, pIRec++) {
776
**pCard16 = pIRec->intensity * 65535.0;
782
PutTableType0Card32(IntensityTbl *pTbl, unsigned long **pCard32)
788
count = pTbl->nEntries;
789
**pCard32 = count - 1;
791
for (; count; count--, pIRec++) {
792
**pCard32 = pIRec->value;
794
**pCard32 = pIRec->intensity * 4294967295.0;
800
PutTableType1Card32(IntensityTbl *pTbl, unsigned long **pCard32)
806
count = pTbl->nEntries;
807
**pCard32 = count - 1;
809
for (; count; count--, pIRec++) {
810
**pCard32 = pIRec->intensity * 4294967295.0;
817
LoadMatrix(Display *pDpy, Window root, XDCCC_Matrix *pMatrix)
820
unsigned long *pCard32;
821
unsigned long Card32Array[18];
826
* Store the XDCCC_LINEAR_RGB_MATRICES
828
pCard32 = Card32Array;
829
pValue = (XcmsFloat *)pMatrix->XYZtoRGBmatrix;
830
for (count = 0; count < 9; count++) {
831
*pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER);
833
pValue = (XcmsFloat *)pMatrix->RGBtoXYZmatrix;
834
for (count = 0; count < 9; count++) {
835
*pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER);
837
MatricesAtom = XInternAtom (pDpy, XDCCC_MATRIX_ATOM_NAME, False);
838
XChangeProperty (pDpy, root, MatricesAtom, XA_INTEGER, 32,
839
PropModeReplace, (unsigned char *)Card32Array, 18);
844
LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection,
847
unsigned char *pCard8;
848
unsigned char *pCard8Array = (unsigned char *)NULL;
849
unsigned short *pCard16;
850
unsigned short *pCard16Array = (unsigned short *)NULL;
851
unsigned long *pCard32;
852
unsigned long *pCard32Array = (unsigned long *)NULL;
858
* Store each XDCCC_CORRECTION into XDCCC_LINEAR_RGB_CORRECTION property
860
CorrectAtom = XInternAtom (pDpy, XDCCC_CORRECT_ATOM_NAME, False);
862
for (i = 0; pCorrection; i++, pCorrection = pCorrection->next) {
863
if ((pCorrection->tableType != 0) && (pCorrection->tableType != 1)) {
864
if (pCorrection->visual_info.visualid) {
865
fprintf(stderr,"RGB Correction for visualid %ld: Invalid intensity table type %d.\n",
866
pCorrection->visual_info.visualid,
867
pCorrection->tableType);
869
fprintf(stderr,"Global RGB Correction: Invalid intensity table type %d.\n",
870
pCorrection->tableType);
875
if (pCorrection->nTables != 1 && pCorrection->nTables != 3) {
876
if (pCorrection->visual_info.visualid) {
877
fprintf(stderr,"RGB Correction for visualid %ld: %d invalid number of tables.\n",
878
pCorrection->visual_info.visualid,
879
pCorrection->nTables);
881
fprintf(stderr,"Global RGB Correction: %d invalid number of tables.\n",
882
pCorrection->nTables);
887
if (pCorrection->nTables == 1) {
888
if (pCorrection->pRedTbl->nEntries < 2) {
889
if (pCorrection->visual_info.visualid) {
890
fprintf(stderr,"RGB Correction for visualid %ld: Illegal number of entries in table\n",
891
pCorrection->visual_info.visualid);
893
fprintf(stderr,"Global RGB Correction: Illegal number of entries in table\n");
897
switch (targetFormat) {
899
total = 7 + (pCorrection->pRedTbl->nEntries *
900
(pCorrection->tableType == 0 ? 2 : 1));
901
if ((pCard8 = pCard8Array = (unsigned char *) calloc (total,
902
sizeof (unsigned char))) == NULL) {
903
fprintf(stderr,"Unable allocate array of ints\n");
906
*pCard8++ = (pCorrection->visual_info.visualid >> 24) & 0xFF;
907
*pCard8++ = (pCorrection->visual_info.visualid >> 16) & 0xFF;
908
*pCard8++ = (pCorrection->visual_info.visualid >> 8) & 0xFF;
909
*pCard8++ = (pCorrection->visual_info.visualid) & 0xFF;
910
*pCard8++ = pCorrection->tableType; /* type */
911
*pCard8++ = 1; /* number of tables = 1 */
912
if (pCorrection->tableType == 0) {
913
PutTableType0Card8(pCorrection->pRedTbl, &pCard8);
915
PutTableType1Card8(pCorrection->pRedTbl, &pCard8);
917
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 8,
918
i ? PropModeAppend : PropModeReplace,
919
(unsigned char *)pCard8Array, total);
923
total = 5 + (pCorrection->pRedTbl->nEntries *
924
(pCorrection->tableType == 0 ? 2 : 1));
925
if ((pCard16 = pCard16Array = (unsigned short *) calloc (total,
926
sizeof (unsigned short))) == NULL) {
927
fprintf(stderr,"Unable allocate array of ints\n");
930
*pCard16++ = (pCorrection->visual_info.visualid >> 16) & 0xFFFF;
931
*pCard16++ = (pCorrection->visual_info.visualid) & 0xFFFF;
932
*pCard16++ = pCorrection->tableType; /* type */
933
*pCard16++ = 1; /* number of tables = 1 */
934
if (pCorrection->tableType == 0) {
935
PutTableType0Card16(pCorrection->pRedTbl, &pCard16);
937
PutTableType1Card16(pCorrection->pRedTbl, &pCard16);
939
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 16,
940
i ? PropModeAppend : PropModeReplace,
941
(unsigned char *)pCard16Array, total);
945
total = 4 + (pCorrection->pRedTbl->nEntries *
946
(pCorrection->tableType == 0 ? 2 : 1));
947
if ((pCard32 = pCard32Array =
948
(unsigned long *) calloc (total,
949
sizeof (unsigned long))) == NULL) {
950
fprintf(stderr,"Unable allocate array of ints\n");
953
*pCard32++ = pCorrection->visual_info.visualid;
954
*pCard32++ = pCorrection->tableType; /* type */
955
*pCard32++ = 1; /* number of tables = 1 */
956
if (pCorrection->tableType == 0) {
957
PutTableType0Card32(pCorrection->pRedTbl, &pCard32);
959
PutTableType1Card32(pCorrection->pRedTbl, &pCard32);
961
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 32,
962
i ? PropModeAppend : PropModeReplace,
963
(unsigned char *)pCard32Array, total);
967
if (pCorrection->visual_info.visualid) {
968
fprintf(stderr,"RGB Correction for visualid %ld: Invalid property format\n",
969
pCorrection->visual_info.visualid);
971
fprintf(stderr,"Global RGB Correction: Invalid property format\n");
975
} else { /* pCorrection->nTables == 3 */
976
if ((pCorrection->pRedTbl->nEntries < 2) ||
977
(pCorrection->pGreenTbl->nEntries < 2) ||
978
(pCorrection->pBlueTbl->nEntries < 2)) {
979
if (pCorrection->visual_info.visualid) {
980
fprintf(stderr,"RGB Correction for visualid %ld: Illegal number of entries in table\n",
981
pCorrection->visual_info.visualid);
983
fprintf(stderr,"Global RGB Correction: Illegal number of entries in table\n");
987
switch (targetFormat) {
989
total = 9 + /* visualID, type, and 3 lengths */
990
(pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) +
991
(pCorrection->pGreenTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) +
992
(pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1));
993
if ((pCard8 = pCard8Array =
994
(unsigned char *) calloc (total,
995
sizeof (unsigned char))) == NULL) {
996
fprintf(stderr,"Unable allocate array of ints\n");
999
*pCard8++ = (pCorrection->visual_info.visualid >> 24) & 0xFF;
1000
*pCard8++ = (pCorrection->visual_info.visualid >> 16) & 0xFF;
1001
*pCard8++ = (pCorrection->visual_info.visualid >> 8) & 0xFF;
1002
*pCard8++ = (pCorrection->visual_info.visualid) & 0xFF;
1003
*pCard8++ = pCorrection->tableType; /* type */
1004
*pCard8++ = 3; /* number of tables = 3 */
1005
if (pCorrection->tableType == 0) {
1006
PutTableType0Card8(pCorrection->pRedTbl, &pCard8);
1007
PutTableType0Card8(pCorrection->pGreenTbl, &pCard8);
1008
PutTableType0Card8(pCorrection->pBlueTbl, &pCard8);
1010
PutTableType1Card8(pCorrection->pRedTbl, &pCard8);
1011
PutTableType1Card8(pCorrection->pGreenTbl, &pCard8);
1012
PutTableType1Card8(pCorrection->pBlueTbl, &pCard8);
1014
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 8,
1015
i ? PropModeAppend : PropModeReplace,
1016
(unsigned char *)pCard8Array, total);
1020
total = 7 + /* visualID, type, and 3 lengths */
1021
(pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) +
1022
(pCorrection->pGreenTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) +
1023
(pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1));
1024
if ((pCard16 = pCard16Array =
1025
(unsigned short *) calloc (total,
1026
sizeof (unsigned short))) == NULL) {
1027
fprintf(stderr,"Unable allocate array of ints\n");
1030
*pCard16++ = (pCorrection->visual_info.visualid >> 16) & 0xFFFF;
1031
*pCard16++ = (pCorrection->visual_info.visualid) & 0xFFFF;
1032
*pCard16++ = pCorrection->tableType; /* type = 0 */
1033
*pCard16++ = 3; /* number of tables = 3 */
1034
if (pCorrection->tableType == 0) {
1035
PutTableType0Card16(pCorrection->pRedTbl, &pCard16);
1036
PutTableType0Card16(pCorrection->pGreenTbl, &pCard16);
1037
PutTableType0Card16(pCorrection->pBlueTbl, &pCard16);
1039
PutTableType1Card16(pCorrection->pRedTbl, &pCard16);
1040
PutTableType1Card16(pCorrection->pGreenTbl, &pCard16);
1041
PutTableType1Card16(pCorrection->pBlueTbl, &pCard16);
1043
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 16,
1044
i ? PropModeAppend : PropModeReplace,
1045
(unsigned char *)pCard16Array, total);
1049
total = 6 + /* visualID, type, and 3 lengths */
1050
(pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) +
1051
(pCorrection->pGreenTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) +
1052
(pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1));
1053
if ((pCard32 = pCard32Array =
1054
(unsigned long *) calloc (total,
1055
sizeof (unsigned long))) == NULL) {
1056
fprintf(stderr,"Unable allocate array of ints\n");
1059
*pCard32++ = pCorrection->visual_info.visualid;
1060
*pCard32++ = pCorrection->tableType; /* type */
1061
*pCard32++ = 3; /* number of tables = 3 */
1062
if (pCorrection->tableType == 0) {
1063
PutTableType0Card32(pCorrection->pRedTbl, &pCard32);
1064
PutTableType0Card32(pCorrection->pGreenTbl, &pCard32);
1065
PutTableType0Card32(pCorrection->pBlueTbl, &pCard32);
1067
PutTableType1Card32(pCorrection->pRedTbl, &pCard32);
1068
PutTableType1Card32(pCorrection->pGreenTbl, &pCard32);
1069
PutTableType1Card32(pCorrection->pBlueTbl, &pCard32);
1071
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 32,
1072
i ? PropModeAppend : PropModeReplace,
1073
(unsigned char *)pCard32Array, total);
1077
if (pCorrection->visual_info.visualid) {
1078
fprintf(stderr,"RGB Correction for visualid %ld: Invalid property format\n",
1079
pCorrection->visual_info.visualid);
1081
fprintf(stderr,"Global RGB Correction: Invalid property format\n");
1094
LoadDataGray(Display *pDpy, window root, int tableType,
1095
LINEAR_RGB_SCCData *pScreenData, int targetFormat)
1097
unsigned char *ret_prop;
1100
unsigned char *pCard8;
1101
unsigned char *pCard8Array = (unsigned char *)NULL;
1102
unsigned short *pCard16;
1103
unsigned short *pCard16Array = (unsigned short *)NULL;
1104
unsigned long *pCard32;
1105
unsigned long *pCard32Array = (unsigned long *)NULL;
1106
unsigned long Card32Array[18];
1108
unsigned long ret_len, ret_after;
1109
Atom MatricesAtom, CorrectAtom, ret_atom;
1113
/* Now store the XDCCC_SCREENWHITEPT */
1114
pCard32 = Card32Array;
1115
pValue = (XcmsFloat *)pScreenData->XYZtoRGBmatrix;
1116
for (count = 0; count < 3; count++) {
1117
*pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER);
1119
MatricesAtom = XInternAtom (pDpy,XDCCC_SCREENWHITEPT_ATOM_NAME,False);
1120
XChangeProperty (pDpy, root, MatricesAtom, XA_INTEGER, 32,
1121
PropModeReplace, (unsigned char *)Card32Array, 3);
1123
/* Now store the XDCCC_GRAY_CORRECTION */
1124
CorrectAtom = XInternAtom (pDpy, XDCCC_GRAY_CORRECT_ATOM_NAME, False);
1126
if (tableType == CORR_TYPE_NONE) {
1127
XGetWindowProperty (pDpy, root, CorrectAtom,
1128
0, 5, False, XA_INTEGER,
1129
&ret_atom, &ret_format, &ret_len, &ret_after,
1131
if (ret_format != 0) {
1132
XDeleteProperty (pDpy, root, CorrectAtom);
1133
XFree ((char *)ret_prop);
1137
nLevels = pScreenData->pRedTbl->nEntries;
1139
fprintf(stderr,"Illegal number of entries in table\n");
1142
switch (targetFormat) {
1144
total = 6 /* visualID, type, length */
1145
+ (nLevels * (tableType == 0 ? 2 : 1));
1146
if ((pCard8 = pCard8Array = (unsigned char *)
1147
calloc (total, sizeof (unsigned char))) == NULL) {
1148
fprintf(stderr,"Unable allocate array of Card8\n");
1151
*pCard8++ = 0; /* VisualID = 0 */
1152
*pCard8++ = 0; /* VisualID = 0 */
1153
*pCard8++ = 0; /* VisualID = 0 */
1154
*pCard8++ = 0; /* VisualID = 0 */
1155
*pCard8++ = tableType; /* type */
1156
if (tableType == 0) {
1157
PutTableType0Card8(pScreenData->pRedTbl, &pCard8);
1158
} else { /* tableType == 1 */
1159
PutTableType1Card8(pScreenData->pRedTbl, &pCard8);
1161
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 8,
1162
PropModeReplace, (unsigned char *)pCard8Array,
1167
total = 4 /* visualID, type, length */
1168
+ (nLevels * (tableType == 0 ? 2 : 1));
1169
if ((pCard16 = pCard16Array = (unsigned short *)
1170
calloc (total, sizeof (unsigned short))) == NULL) {
1171
fprintf(stderr,"Unable allocate array of Card16\n");
1174
*pCard16++ = 0; /* VisualID = 0 */
1175
*pCard16++ = 0; /* VisualID = 0 */
1176
*pCard16++ = tableType; /* type */
1177
if (tableType == 0) {
1178
PutTableType0Card16(pScreenData->pRedTbl, &pCard16);
1179
} else { /* tableType == 1 */
1180
PutTableType1Card16(pScreenData->pRedTbl, &pCard16);
1182
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 16,
1183
PropModeReplace, (unsigned char *)pCard16Array,
1185
free (pCard16Array);
1188
total = 3 /* visualID, type, length */
1189
+ (nLevels * (tableType == 0 ? 2 : 1));
1190
if ((pCard32 = pCard32Array = (unsigned long *)
1191
calloc (total, sizeof (unsigned long))) == NULL) {
1192
fprintf(stderr,"Unable allocate array of Card32\n");
1195
*pCard32++ = 0; /* VisualID = 0 */
1196
*pCard32++ = tableType; /* type */
1197
if (tableType == 0) {
1198
PutTableType0Card32(pScreenData->pRedTbl, &pCard32);
1199
} else { /* tableType == 1 */
1200
PutTableType1Card32(pScreenData->pRedTbl, &pCard32);
1202
XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 32,
1203
PropModeReplace, (unsigned char *)pCard32Array,
1205
free (pCard32Array);
1208
fprintf(stderr,"Invalid property format\n");
1217
PrintVisualOptions(XDCCC_Correction *pCorrection)
1219
if (pCorrection->visual_info_mask & VisualIDMask) {
1220
fprintf(stderr, "\t%s:0x%lx\n",
1221
DefineToStr(VisualOptKeyTbl, KEY_VISUALID),
1222
(unsigned long)pCorrection->visual_info.visualid);
1224
if (pCorrection->visual_info_mask & VisualDepthMask) {
1225
fprintf(stderr, "\t%s:%d\n",
1226
DefineToStr(VisualOptKeyTbl, KEY_DEPTH),
1227
pCorrection->visual_info.depth);
1229
if (pCorrection->visual_info_mask & VisualClassMask) {
1230
fprintf(stderr, "\t%s:%s\n",
1231
DefineToStr(VisualOptKeyTbl, KEY_CLASS),
1232
DefineToStr(VisualClassTbl, pCorrection->visual_info.class));
1234
if (pCorrection->visual_info_mask & VisualRedMaskMask) {
1235
fprintf(stderr, "\t%s:0x%lx\n",
1236
DefineToStr(VisualOptKeyTbl, KEY_RED_MASK),
1237
pCorrection->visual_info.red_mask);
1239
if (pCorrection->visual_info_mask & VisualGreenMaskMask) {
1240
fprintf(stderr, "\t%s:0x%lx\n",
1241
DefineToStr(VisualOptKeyTbl, KEY_GREEN_MASK),
1242
pCorrection->visual_info.green_mask);
1244
if (pCorrection->visual_info_mask & VisualBlueMaskMask) {
1245
fprintf(stderr, "\t%s:0x%lx\n",
1246
DefineToStr(VisualOptKeyTbl, KEY_BLUE_MASK),
1247
pCorrection->visual_info.blue_mask);
1249
if (pCorrection->visual_info_mask & VisualColormapSizeMask) {
1250
fprintf(stderr, "\t%s:0x%x\n",
1251
DefineToStr(VisualOptKeyTbl, KEY_COLORMAP_SIZE),
1252
pCorrection->visual_info.colormap_size);
1254
if (pCorrection->visual_info_mask & VisualBitsPerRGBMask) {
1255
fprintf(stderr, "\t%s:%d\n",
1256
DefineToStr(VisualOptKeyTbl, KEY_BITS_PER_RGB),
1257
pCorrection->visual_info.bits_per_rgb);
1263
ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf)
1271
strcpy(delims, DATA_DELIMS);
1272
strcat(delims, ":");
1273
pCorrection->visual_info_mask = VisualNoMask;
1274
key = strtok(pbuf, delims);
1277
value = strtok((char*)NULL, delims);
1278
if ((key == (char*)NULL) || (value == (char*)NULL)) {
1281
switch (StrToDefine(VisualOptKeyTbl, key)) {
1283
if (sscanf(value, "%li", &tmp) != 1) {
1285
"Line %d: invalid VisualID specified, %s\n",
1289
pCorrection->visual_info.visualid = tmp;
1290
pCorrection->visual_info_mask |= VisualIDMask;
1293
if (sscanf(value, "%i", &pCorrection->visual_info.depth) != 1) {
1295
"Line %d: invalid depth specified, %s\n",
1299
pCorrection->visual_info_mask |= VisualDepthMask;
1302
switch (pCorrection->visual_info.class =
1303
StrToDefine(VisualClassTbl, value)) {
1313
/* invalid, fall through */
1315
/* invalid, fall through */
1318
"Line %d: invalid Visual Class -- %s\n",
1322
pCorrection->visual_info_mask |= VisualClassMask;
1325
if (sscanf(value, "%li", &tmp) != 1) {
1327
"Line %d: invalid red_mask specified -- %s\n",
1331
pCorrection->visual_info.red_mask = tmp;
1332
pCorrection->visual_info_mask |= VisualRedMaskMask;
1334
case KEY_GREEN_MASK:
1335
if (sscanf(value, "%li", &tmp) != 1) {
1337
"Line %d: invalid green_mask specified -- %s\n",
1341
pCorrection->visual_info.green_mask = tmp;
1342
pCorrection->visual_info_mask |= VisualGreenMaskMask;
1345
if (sscanf(value, "%li", &tmp) != 1) {
1347
"Line %d: invalid blue_mask specified -- %s\n",
1351
pCorrection->visual_info.blue_mask = tmp;
1352
pCorrection->visual_info_mask |= VisualBlueMaskMask;
1354
case KEY_COLORMAP_SIZE:
1355
if (sscanf(value, "%i", &pCorrection->visual_info.colormap_size) != 1) {
1357
"Line %d: invalid colormap_size specified -- %s\n",
1361
pCorrection->visual_info_mask |= VisualColormapSizeMask;
1363
case KEY_BITS_PER_RGB:
1364
if (sscanf(value, "%i", &pCorrection->visual_info.bits_per_rgb) != 1) {
1366
"Line %d: invalid bits_per_rgb specified -- %s\n",
1370
pCorrection->visual_info_mask |= VisualBitsPerRGBMask;
1374
"Line %d: invalid keyword %s\n", linenum, key);
1377
key = strtok((char*)NULL, delims);
1378
} while (key != (char *)NULL);
1380
vinfo = XGetVisualInfo(pDpy,
1381
pCorrection->visual_info_mask,
1382
&pCorrection->visual_info,
1386
fprintf(stderr, "Line %d: Cannot find visual matching ...\n", linenum);
1387
PrintVisualOptions(pCorrection);
1388
fprintf(stderr, "\n");
1391
if (n_matches > 1) {
1392
fprintf(stderr, "Line %d: Found more than one visual matching ...\n", linenum);
1393
PrintVisualOptions(pCorrection);
1394
fprintf(stderr, " Using VisualId 0x%lx\n", (unsigned long)vinfo->visualid);
1396
memcpy((char*)&pCorrection->visual_info, (char*)vinfo,
1397
sizeof(XVisualInfo));
1402
/************************************************************************
1406
************************************************************************/
1410
* LoadSCCData - Read and store the screen data
1415
LoadSCCData(Display *pDpy, int screenNumber, char *filename, int targetFormat)
1419
* Using the X Device Color Characterization Convention (XDCCC)
1420
* read the screen data and store it on the root window of the
1424
* Returns 0 if failed; otherwise 1.
1431
char *keyword, *token1, *token2, *token3;
1433
int VisualFlag = -2;
1435
XDCCC_Matrix matrix;
1436
XDCCC_Correction* CorrectionTail = (XDCCC_Correction*)NULL;
1437
XDCCC_Correction* CorrectionHead = (XDCCC_Correction*)NULL;
1438
XDCCC_Correction* pCurrent;
1440
if (screenNumber < 0) {
1441
fprintf(stderr,"Invalid Screen Number %d\n", screenNumber);
1444
root = RootWindow(pDpy, screenNumber);
1447
/* if no root window is available then return an error */
1448
fprintf(stderr,"Could not open root window supplied.\n ");
1452
* Open the file, determine its size, then read it into memory.
1454
if (filename == NULL) {
1457
} else if ((stream = fopen(filename, "r")) == NULL) {
1458
fprintf(stderr,"Could not open file %s.\n", filename);
1463
* Advance to starting keyword
1464
* Anything before this keyword is just treated as comments.
1467
while((pStr = nextline(buf, BUFSIZ, stream)) != NULL) {
1468
keyword = strtok(buf, DATA_DELIMS);
1469
if (keyword != (char *)NULL &&
1470
(strcmp(keyword, SC_BEGIN_KEYWORD) == 0)) {
1472
} /* else ignore the line */
1476
fprintf(stderr,"File %s is missing %s\n", filename, SC_BEGIN_KEYWORD);
1477
closeS (stream, CorrectionHead);
1481
token1 = strtok((char*)NULL, DATA_DELIMS);
1482
if ((strcmp(token1, TXT_FORMAT_VERSION) != 0) &&
1483
(strcmp(token1, "0.3") != 0)) {
1485
"Screen data format version mismatch in file %s-- expected %s, found %s\n",
1486
filename, TXT_FORMAT_VERSION, token1);
1487
closeS (stream, CorrectionHead);
1491
while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) {
1492
token1 = token2 = token3 = (char*)NULL;
1493
keyword = strtok(buf, DATA_DELIMS);
1494
if (keyword != (char*)NULL) {
1495
switch (SCKeyOf(keyword)) {
1500
case SERIAL_NUMBER :
1505
token1 = strtok((char*)NULL, DATA_DELIMS);
1506
token2 = strtok((char*)NULL, DATA_DELIMS);
1507
if ((token1 == (char*)NULL)
1508
|| ((VisualFlag = SCScrnClassOf(token1)) == -1)) {
1509
closeS (stream, CorrectionHead);
1512
/*include code to handle screen number input*/
1513
if (token2 != (char*)NULL) {
1514
screenNumber = atoi(token2);
1516
if (screenNumber < 0) {
1517
fprintf(stderr,"Invalid Screen Number %d\n",
1521
root = RootWindow(pDpy, screenNumber);
1523
/* if no root window is available then return an error */
1525
"Could not open root window supplied.\n ");
1531
case COLORIMETRIC_BEGIN :
1532
if (VisualFlag == -2) {
1533
closeS (stream, CorrectionHead);
1536
if (!ProcessColorimetric(stream,
1537
&matrix, VisualFlag)) {
1538
closeS (stream, CorrectionHead);
1543
case IPROFILE_BEGIN :
1544
if (VisualFlag == -2) {
1545
closeS (stream, CorrectionHead);
1548
token1 = strtok((char*)NULL, DATA_DELIMS);
1549
token2 = strtok((char*)NULL, DATA_DELIMS);
1550
if ((token1 == (char*)NULL) || (token2 == (char*)NULL)) {
1552
"Line %d: Intensity profile missing TableType and/or nTables.",
1554
closeS (stream, CorrectionHead);
1558
if ((pCurrent = (XDCCC_Correction *)
1559
calloc(1, sizeof(XDCCC_Correction))) ==NULL) {
1561
"Line %d: Could not allocate memory for intensity profile.",
1563
closeS (stream, CorrectionHead);
1567
if (sscanf(token1, "%d", &pCurrent->tableType) != 1 ||
1568
(pCurrent->tableType < 0 || pCurrent->tableType > 1)) {
1570
"Line %d: invalid table type specified -- %s\n",
1572
closeS (stream, CorrectionHead);
1576
if ((VisualFlag == VIDEO_RGB) && (token2 == (char *)NULL)) {
1578
"Line %d: invalid number of tables specified -- %s\n",
1580
closeS (stream, CorrectionHead);
1584
if (VisualFlag == VIDEO_RGB) {
1585
if (sscanf(token2, "%d", &pCurrent->nTables) != 1 ||
1586
(pCurrent->nTables != 0 && pCurrent->nTables != 1
1587
&& pCurrent->nTables != 3)) {
1589
"Line %d: invalid number of tables (must be 0, 1, or 3)\n",
1591
closeS (stream, CorrectionHead);
1595
pCurrent->nTables = 0;
1598
token3 = strtok((char*)NULL, "\n");
1599
if (token3 != (char*)NULL) {
1600
if (!ParseVisualOptions(pDpy, pCurrent, token3)) {
1601
goto ByPassThisIProfile;
1605
switch (pCurrent->nTables) {
1607
if (!(pCurrent->pRedTbl = (IntensityTbl *)
1608
calloc (1, sizeof (IntensityTbl)))) {
1610
"Line %d: Could not allocate Red Intensity Table\n",
1612
closeS (stream, CorrectionHead);
1615
if (!(pCurrent->pGreenTbl = (IntensityTbl *)
1616
calloc (1, sizeof (IntensityTbl)))) {
1618
"Line %d: Could not allocate Green Intensity Table\n",
1620
closeS (stream, CorrectionHead);
1623
if (!(pCurrent->pBlueTbl = (IntensityTbl *)
1624
calloc (1, sizeof (IntensityTbl)))) {
1626
"Line %d: Could not allocate Blue Intensity Table",
1628
closeS (stream, CorrectionHead);
1631
if (!ProcessIProfile(stream, pCurrent)) {
1632
goto ByPassThisIProfile;
1636
if (!(pCurrent->pRedTbl = (IntensityTbl *)
1637
calloc (1, sizeof (IntensityTbl)))) {
1639
"Line %d: Could not allocate Red Intensity Table",
1641
closeS (stream, CorrectionHead);
1644
pCurrent->pGreenTbl = pCurrent->pRedTbl;
1645
pCurrent->pBlueTbl = pCurrent->pRedTbl;
1646
if (!ProcessIProfile(stream, pCurrent)) {
1647
goto ByPassThisIProfile;
1655
if (CorrectionHead == NULL) {
1656
CorrectionHead = CorrectionTail = pCurrent;
1658
CorrectionTail->next = pCurrent;
1659
CorrectionTail = pCurrent;
1664
/* read till INTENSITY_PROFILE_END */
1665
while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) {
1666
keyword = strtok(buf, DATA_DELIMS);
1667
if (keyword != (char*)NULL) {
1668
switch (SCKeyOf(keyword)) {
1675
goto IProfileProcessed;
1677
closeS (stream, CorrectionHead);
1687
if (!(state & 0x02)) {
1689
"File %s is missing Colorimetric data.\n",
1691
closeS (stream, CorrectionHead);
1694
if (!(state & 0x04)) {
1696
"File %s is missing Intensity Profile Data.\n",
1699
if (VisualFlag == VIDEO_RGB) {
1700
LoadMatrix(pDpy, root, &matrix);
1701
if (!LoadCorrections(pDpy, root, CorrectionHead,
1703
closeS (stream, CorrectionHead);
1707
} else if (VisualFlag == VIDEO_GRAY) {
1708
if (!LoadDataGray(pDpy, root,
1709
pCurrent->tableType, pScreenData, targetFormat)) {
1710
closeS (stream, CorrectionHead);
1715
fprintf(stderr,"File %s Visual missing.", filename);
1717
closeS (stream, CorrectionHead);
1719
/* NOTREACHED */ break;
1721
fprintf(stderr,"Line %d: extraneous keyword %s\n",
1723
closeS (stream, CorrectionHead);
1727
} /* else it was just a blank line */
1729
closeS (stream, CorrectionHead);