1
/* $Xorg: pctrgb.c,v 1.4 2001/02/09 02:04:22 xorgcvs Exp $ */
2
/**** module pctrgb.c ****/
3
/******************************************************************************
5
Copyright 1993, 1994, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
30
This software is being provided by AGE Logic, Inc. under the
31
following license. By obtaining, using and/or copying this software,
32
you agree that you have read, understood, and will comply with these
35
Permission to use, copy, modify, distribute and sell this
36
software and its documentation for any purpose and without
37
fee or royalty and to grant others any or all rights granted
38
herein is hereby granted, provided that you agree to comply
39
with the following copyright notice and statements, including
40
the disclaimer, and that the same appears on all copies and
41
derivative works of the software and documentation you make.
43
"Copyright 1993, 1994 by AGE Logic, Inc."
45
THIS SOFTWARE IS PROVIDED "AS IS". AGE LOGIC MAKES NO
46
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way of
47
example, but not limitation, AGE LOGIC MAKE NO
48
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
49
FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
50
INFRINGE THIRD-PARTY PROPRIETARY RIGHTS. AGE LOGIC
51
SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE. IN NO
52
EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
53
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
54
OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
55
ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
56
BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
57
HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
60
The name of AGE Logic, Inc. may not be used in
61
advertising or publicity pertaining to this software without
62
specific, written prior permission from AGE Logic.
64
Title to this software shall at all times remain with AGE
66
*****************************************************************************
68
pctrgb.c -- DIXIE routines for managing the ConvertToRGB element
70
Dean Verheiden -- AGE Logic, Inc. August 1993
72
*****************************************************************************/
73
/* $XFree86: xc/programs/Xserver/XIE/dixie/process/pctrgb.c,v 3.6 2001/12/14 19:58:05 dawes Exp $ */
103
* routines internal to this module
105
static Bool PrepPConvertToRGB(floDefPtr flo, peDefPtr ped);
108
* dixie element entry points
110
static diElemVecRec pConvertToRGBVec = {
111
PrepPConvertToRGB /* prepare for analysis and execution */
114
/*------------------------------------------------------------------------
115
------------------ routine: make a ConvertToRBG element ----------------
116
------------------------------------------------------------------------*/
117
peDefPtr MakeConvertToRGB(floDefPtr flo, xieTypPhototag tag, xieFlo *pe)
120
ELEMENT(xieFloConvertToRGB);
121
ELEMENT_AT_LEAST_SIZE(xieFloConvertToRGB);
122
ELEMENT_NEEDS_1_INPUT(src);
124
if(!(ped = MakePEDef(1, (CARD32)stuff->elemLength<<2, 0)))
125
FloAllocError(flo,tag,xieElemConvertToRGB, return(NULL)) ;
127
ped->diVec = &pConvertToRGBVec;
129
ped->flags.process = TRUE;
130
raw = (xieFloConvertToRGB *)ped->elemRaw;
132
* copy the client element parameters (swap if necessary)
134
if( flo->reqClient->swapped ) {
135
raw->elemType = stuff->elemType;
136
raw->elemLength = stuff->elemLength;
137
cpswaps(stuff->src, raw->src);
138
cpswaps(stuff->convert, raw->convert);
139
cpswaps(stuff->lenParams, raw->lenParams);
141
memcpy((char *)raw, (char *)stuff, sizeof(xieFloConvertToRGB));
143
* copy technique data (if any)
145
if(!(ped->techVec = FindTechnique(xieValConvertToRGB, raw->convert)) ||
146
!(ped->techVec->copyfnc(flo, ped, &stuff[1], &raw[1], raw->lenParams, 0)))
147
TechniqueError(flo,ped,xieValConvertToRGB,raw->convert,raw->lenParams,
151
* assign phototag to inFlo
153
ped->inFloLst[SRCtag].srcTag = raw->src;
156
} /* end MakePConvertToRGB */
158
/*------------------------------------------------------------------------
159
------ routine: copy routine for CIELab and CIEXYZ techniques -----------
160
------------------------------------------------------------------------*/
163
#define sparms ((xieTecCIELabToRGB *)sParms)
165
#define rparms ((xieTecCIELabToRGB *)rParms)
167
Bool CopyPConvertToRGBCIE(TECHNQ_COPY_ARGS)
169
pTecCIEToRGBDefPtr pvt;
171
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, FALSE);
173
if (!(ped->techPvt = (pointer )XieMalloc(sizeof(pTecCIEToRGBDefRec))))
174
FloAllocError(flo, ped->phototag,xieElemConvertToRGB, return(TRUE));
176
pvt = (pTecCIEToRGBDefPtr)ped->techPvt;
178
if( flo->reqClient->swapped ) {
179
swap_floats(&pvt->matrix[0], &sparms->matrix00, 9);
180
cpswaps(sparms->whiteAdjusted, pvt->whiteAdjusted);
181
cpswaps(sparms->lenWhiteParams, pvt->lenWhiteParams);
182
cpswaps(sparms->gamutCompress, pvt->gamutCompress);
183
cpswaps(sparms->lenGamutParams, pvt->lenGamutParams);
185
copy_floats(&pvt->matrix[0], &sparms->matrix00, 9);
186
pvt->whiteAdjusted = sparms->whiteAdjusted;
187
pvt->lenWhiteParams = sparms->lenWhiteParams;
188
pvt->gamutCompress = sparms->gamutCompress;
189
pvt->lenGamutParams = sparms->lenGamutParams;
192
if(!(pvt->whiteTec = FindTechnique(xieValWhiteAdjust, pvt->whiteAdjusted)) ||
193
!(TECH_WADJ_FUNC(pvt->whiteTec)(flo, ped, &sparms[1], pvt->whitePoint,
194
pvt->whiteTec, pvt->lenWhiteParams,
195
pvt->whiteAdjusted == xieValDefault)))
196
TechniqueError(flo,ped,xieValWhiteAdjust,
197
pvt->whiteAdjusted,pvt->lenWhiteParams, return(TRUE));
199
if(!(pvt->gamutTec = FindTechnique(xieValGamut, pvt->gamutCompress)) ||
200
!(TECH_GAMU_FUNC(pvt->gamutTec)(pvt->lenGamutParams)))
201
TechniqueError(flo,ped,xieValGamut,
202
pvt->gamutCompress,pvt->lenGamutParams, return(TRUE));
207
/*------------------------------------------------------------------------
208
---------- routine: copy routine for YCbCr and YCC techniques ------------
209
------------------------------------------------------------------------*/
212
#define sparms ((xieTecYCbCrToRGB *)sParms)
214
#define rparms ((xieTecYCbCrToRGB *)rParms)
216
Bool CopyPConvertToRGBYCbCr(TECHNQ_COPY_ARGS)
218
pTecYCbCrToRGBDefPtr pvt;
220
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, FALSE);
222
if (!(ped->techPvt = (pointer )XieMalloc(sizeof(pTecYCbCrToRGBDefRec))))
223
FloAllocError(flo, ped->phototag,xieElemConvertToRGB, return(TRUE));
225
pvt = (pTecYCbCrToRGBDefPtr)ped->techPvt;
227
if( flo->reqClient->swapped ) {
228
cpswapl(sparms->levels0, pvt->levels0);
229
cpswapl(sparms->levels1, pvt->levels1);
230
cpswapl(sparms->levels2, pvt->levels2);
231
swap_floats(&pvt->red, &sparms->lumaRed, 3);
232
swap_floats(&pvt->bias0, &sparms->bias0, 3);
233
cpswaps(sparms->gamutCompress, pvt->gamutCompress);
234
cpswaps(sparms->lenGamutParams, pvt->lenGamutParams);
236
pvt->levels0 = sparms->levels0;
237
pvt->levels1 = sparms->levels1;
238
pvt->levels2 = sparms->levels2;
239
copy_floats(&pvt->red, &sparms->lumaRed, 3);
240
copy_floats(&pvt->bias0, &sparms->bias0, 3);
241
pvt->gamutCompress = sparms->gamutCompress;
242
pvt->lenGamutParams = sparms->lenGamutParams;
245
if(!(pvt->gamutTec = FindTechnique(xieValGamut, pvt->gamutCompress)) ||
246
!(TECH_GAMU_FUNC(pvt->gamutTec)(pvt->lenGamutParams)))
247
TechniqueError(flo,ped,xieValGamut,
248
pvt->gamutCompress,pvt->lenGamutParams, return(TRUE));
254
#define sparms ((xieTecYCCToRGB *)sParms)
256
#define rparms ((xieTecYCCToRGB *)rParms)
258
Bool CopyPConvertToRGBYCC(TECHNQ_COPY_ARGS)
260
pTecYCCToRGBDefPtr pvt;
262
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, FALSE);
264
if (!(ped->techPvt = (pointer )XieMalloc(sizeof(pTecYCCToRGBDefRec))))
265
FloAllocError(flo, ped->phototag,xieElemConvertToRGB, return(TRUE));
267
pvt = (pTecYCCToRGBDefPtr)ped->techPvt;
269
if( flo->reqClient->swapped ) {
270
cpswapl(sparms->levels0, pvt->levels0);
271
cpswapl(sparms->levels1, pvt->levels1);
272
cpswapl(sparms->levels2, pvt->levels2);
273
swap_floats(&pvt->red, &sparms->lumaRed, 3);
274
pvt->scale = ConvertFromIEEE(lswapl(sparms->scale));
275
cpswaps(sparms->gamutCompress, pvt->gamutCompress);
276
cpswaps(sparms->lenGamutParams, pvt->lenGamutParams);
278
pvt->levels0 = sparms->levels0;
279
pvt->levels1 = sparms->levels1;
280
pvt->levels2 = sparms->levels2;
281
copy_floats(&pvt->red, &sparms->lumaRed, 3);
282
pvt->scale = ConvertFromIEEE(sparms->scale);
283
pvt->gamutCompress = sparms->gamutCompress;
284
pvt->lenGamutParams = sparms->lenGamutParams;
287
if(!(pvt->gamutTec = FindTechnique(xieValGamut, pvt->gamutCompress)) ||
288
!(TECH_GAMU_FUNC(pvt->gamutTec)(pvt->lenGamutParams)))
289
TechniqueError(flo,ped,xieValGamut,
290
pvt->gamutCompress,pvt->lenGamutParams, return(TRUE));
298
/*------------------------------------------------------------------------
299
-- routine: copy routine for White Adjust None technique ----------
300
------------------------------------------------------------------------*/
301
Bool CopyPWhiteAdjustNone(
313
/*------------------------------------------------------------------------
314
-- routine: copy routine for White Adjust CIELabShift technique ----------
315
------------------------------------------------------------------------*/
316
Bool CopyPWhiteAdjustCIELabShift(
319
xieTecWhiteAdjustCIELabShift *sparms,
325
VALIDATE_TECHNIQUE_SIZE(tv, tsize, isDefault);
327
if( flo->reqClient->swapped ) {
328
swap_floats(pvtf, &sparms->whitePoint0, 3);
330
copy_floats(pvtf, &sparms->whitePoint0, 3);
336
/*------------------------------------------------------------------------
337
----------- routine: copy routine for Gamut techniques -------------------
338
------------------------------------------------------------------------*/
339
Bool CopyPGamut(CARD16 tsize)
344
/*------------------------------------------------------------------------
345
-- routine: prep routine for RGB to CIElab and CIEXYZ techniques ---------
346
------------------------------------------------------------------------*/
347
Bool PrepPConvertToRGBCIE(
350
xieFloConvertToRGB *raw,
351
xieTecCIELabToRGB *tec) /* same as xieTecCIEXYZToRGB */
353
pTecCIEToRGBDefPtr pvt = (pTecCIEToRGBDefPtr)ped->techPvt;
354
inFloPtr inf = &ped->inFloLst[SRCtag];
355
outFloPtr src = &inf->srcDef->outFlo;
356
outFloPtr dst = &ped->outFlo;
359
/* grab a copy of the src attributes and propagate them to our input */
360
dst->bands = inf->bands = src->bands;
361
for(b = 0; b < src->bands; b++) {
362
if (IsConstrained(src->format[0].class))
363
return FALSE; /* must be floats */
364
/* Since we know its floats, structure copy sufficient */
365
dst->format[b] = inf->format[b] = src->format[b];
368
return(pvt->whiteTec->prepfnc(flo,ped,pvt->whitePoint));
371
/*------------------------------------------------------------------------
372
-- routine: prep routine for RGB to YCbCr and YCC techniques -------------
373
------------------------------------------------------------------------*/
374
Bool PrepPConvertToRGBYCbCr(
377
xieFloConvertToRGB *raw,
378
xieTecYCbCrToRGB *tec)
380
inFloPtr inf = &ped->inFloLst[SRCtag];
381
outFloPtr src = &inf->srcDef->outFlo;
382
outFloPtr dst = &ped->outFlo;
383
pTecYCbCrToRGBDefPtr pvt = (pTecYCbCrToRGBDefPtr)ped->techPvt;
384
CARD32 *levels = &(pvt->levels0);
387
/* grab a copy of the src attributes and propagate them to our input */
388
dst->bands = inf->bands = src->bands;
389
for(b = 0; b < src->bands; b++) {
390
dst->format[b] = inf->format[b] = src->format[b];
391
if (IsConstrained(dst->format[b].class))
392
dst->format[b].levels = *(levels+b);
395
/* Set depth, class, stride, and pitch */
396
if (IsConstrained(dst->format[0].class)) {
397
if (UpdateFormatfromLevels(ped) == FALSE)
398
MatchError(flo,ped, return(FALSE));
399
} /* else the structure copy was sufficient */
404
Bool PrepPConvertToRGBYCC(
407
xieFloConvertToRGB *raw,
410
inFloPtr inf = &ped->inFloLst[SRCtag];
411
outFloPtr src = &inf->srcDef->outFlo;
412
outFloPtr dst = &ped->outFlo;
413
pTecYCCToRGBDefPtr pvt = (pTecYCCToRGBDefPtr)ped->techPvt;
414
CARD32 *levels = &(pvt->levels0);
417
/* grab a copy of the src attributes and propagate them to our input */
418
dst->bands = inf->bands = src->bands;
419
for(b = 0; b < src->bands; b++) {
420
dst->format[b] = inf->format[b] = src->format[b];
421
if (IsConstrained(dst->format[b].class))
422
dst->format[b].levels = *(levels+b);
425
/* Set depth, class, stride, and pitch */
426
if (IsConstrained(dst->format[0].class)) {
427
if (UpdateFormatfromLevels(ped) == FALSE)
428
MatchError(flo,ped, return(FALSE));
429
} /* else the structure copy was sufficient */
431
if (pvt->scale < .001) { /* should be about 1.35 or 1.4 */
432
ValueError(flo, ped, tec->scale, return(FALSE));
438
/*------------------------------------------------------------------------
439
------ routine: prep routine for White Adjust none technique -------------
440
------------------------------------------------------------------------*/
441
Bool PrepPWhiteAdjustNone(
449
/*------------------------------------------------------------------------
450
-- routine: prep routine for White Adjust CIELabShift technique ----------
451
------------------------------------------------------------------------*/
452
Bool PrepPWhiteAdjustCIELabShift(
460
/*------------------------------------------------------------------------
461
------------ routine: prep routine for gamut techniques ------------------
462
------------------------------------------------------------------------*/
463
Bool PrepPGamut(void)
468
/*------------------------------------------------------------------------
469
---------------- routine: prepare for analysis and execution -------------
470
------------------------------------------------------------------------*/
472
static Bool PrepPConvertToRGB(floDefPtr flo, peDefPtr ped)
474
inFloPtr inf = &ped->inFloLst[SRCtag];
475
outFloPtr src = &inf->srcDef->outFlo;
476
xieFloConvertToRGB *raw = (xieFloConvertToRGB *)ped->elemRaw;
478
/* Input must be triple band and dimensions must match */
479
if (IsntCanonic(src->format[0].class) ||
481
src->format[0].width != src->format[1].width ||
482
src->format[1].width != src->format[2].width ||
483
src->format[0].height != src->format[1].height ||
484
src->format[1].height != src->format[2].height)
485
MatchError(flo,ped, return(FALSE));
489
** Technique Prep routine will complete the normal propagation of src
490
** attributes, and setup of destination attributes.
493
if (!(ped->techVec->prepfnc(flo, ped, raw, &raw[1])))
494
TechniqueError(flo,ped,xieValConvertToRGB,
495
raw->convert,raw->lenParams, return(FALSE));
501
/*------------------------------------------------------------------------
502
---------------------- utility routines for parameters -------------------
503
------------------------------------------------------------------------*/
508
xieTypFloat *funny_floats_in,
512
for (m = 0; m < cnt; m++)
513
doubles_out[m] = ConvertFromIEEE(lswapl(funny_floats_in[m]));
519
xieTypFloat *funny_floats_in,
523
for (m = 0; m < cnt; m++)
524
doubles_out[m] = ConvertFromIEEE(funny_floats_in[m]);
527
/* end module pctrgb.c */