home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / xcmstest / TekCMSutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-31  |  8.3 KB  |  371 lines

  1. /* $XConsortum: TekCMSutil.c,v 1.1 91/02/11 19:40:54 dave Exp $ */
  2.  
  3. /*
  4.  * (c) Copyright 1990, Tektronix Inc.
  5.  *     All Rights Reserved
  6.  *
  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.
  14.  *
  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
  21.  * software.
  22.  *
  23.  *    NAME
  24.  *        TekCMSutil.c
  25.  *
  26.  *    DESCRIPTION
  27.  *        Utility routines for the TekCMS testing interface.
  28.  */
  29.  
  30. /*
  31.  *      EXTERNAL INCLUDES
  32.  *              Include files that must be exported to any package or
  33.  *              program using this package.
  34.  */
  35. #include <stdio.h>
  36.  
  37. /*
  38.  *      INTERNAL INCLUDES
  39.  *              Include files that need NOT be exported to any package or
  40.  *              program using this package.
  41.  */
  42. #include <X11/Xlib.h>
  43. #include <X11/Xutil.h>
  44. #include <X11/Xatom.h>
  45. #include <X11/Xcms.h>
  46. #include "LibTest.h"
  47.  
  48. #ifdef AUTOHEADER
  49. #include "TekCMSglob.ah"
  50. #else
  51. #include "TekCMSglob.h"
  52. #endif
  53.  
  54. /*
  55.  *    DEFINES
  56.  *        Declarations that are local to this module.
  57.  *        (ignored by 'autohdr').
  58.  */
  59.  
  60. /*
  61.  *    EXTERNALS
  62.  *        Declarations that are needed by calling modules.
  63.  *        When using 'autohdr', these declaration will be placed
  64.  *        in the resulting header file.
  65.  */
  66.  
  67.  
  68. /************************************************************************
  69.  *                                    *
  70.  *             PUBLIC ROUTINES                *
  71.  *                                    *
  72.  ************************************************************************/
  73.  
  74. /*
  75.  *    NAME
  76.  *        fPrintXcmsColorSpec - Print a XcmsColorSpec
  77.  *
  78.  *    SYNOPSIS
  79.  */
  80. void
  81. fPrintXcmsColorSpec(fp, pColor)
  82.     FILE *fp;
  83.     XcmsColor *pColor;
  84. /*
  85.  *    DESCRIPTION
  86.  *        Prints one XcmsColor to the specified file.
  87.  *
  88.  *    RETURNS
  89.  *        void
  90.  *
  91.  */
  92. {
  93.     switch (pColor->format) {
  94.       case XcmsRGBiFormat:
  95.     fprintf(fp, "\t    format = XcmsRGBiFormat\n");
  96.     fprintf(fp, "\t    spec.RGBi.red   = %f\n", pColor->spec.RGBi.red);
  97.     fprintf(fp, "\t    spec.RGBi.green = %f\n", pColor->spec.RGBi.green);
  98.     fprintf(fp, "\t    spec.RGBi.blue  = %f\n", pColor->spec.RGBi.blue);
  99.     break;
  100.       case XcmsRGBFormat:
  101.     fprintf(fp, "\t    format = XcmsRGBFormat\n");
  102.     fprintf(fp, "\t    spec.RGB.red   = 0x%x\n", pColor->spec.RGB.red);
  103.     fprintf(fp, "\t    spec.RGB.green = 0x%x\n", pColor->spec.RGB.green);
  104.     fprintf(fp, "\t    spec.RGB.blue  = 0x%x\n", pColor->spec.RGB.blue);
  105.     break;
  106.       case XcmsUndefinedFormat:
  107.     fprintf(fp, "\t    format = XcmsUndefinedFormat\n");
  108.     fprintf(fp, "\t    spec.UND.U = %f\n", pColor->spec.CIEXYZ.X);
  109.     fprintf(fp, "\t    spec.UND.N = %f\n", pColor->spec.CIEXYZ.Y);
  110.     fprintf(fp, "\t    spec.UND.D = %f\n", pColor->spec.CIEXYZ.Z);
  111.     break;
  112.       case XcmsCIEXYZFormat:
  113.     fprintf(fp, "\t    format = XcmsCIEXYZFormat\n");
  114.     fprintf(fp, "\t    spec.CIEXYZ.X = %f\n", pColor->spec.CIEXYZ.X);
  115.     fprintf(fp, "\t    spec.CIEXYZ.Y = %f\n", pColor->spec.CIEXYZ.Y);
  116.     fprintf(fp, "\t    spec.CIEXYZ.Z = %f\n", pColor->spec.CIEXYZ.Z);
  117.     break;
  118.       case XcmsCIExyYFormat:
  119.     fprintf(fp, "\t    format = XcmsCIExyYFormat\n");
  120.     fprintf(fp, "\t    spec.CIExyY.x = %f\n", pColor->spec.CIExyY.x);
  121.     fprintf(fp, "\t    spec.CIExyY.y = %f\n", pColor->spec.CIExyY.y);
  122.     fprintf(fp, "\t    spec.CIExyY.Y = %f\n", pColor->spec.CIExyY.Y);
  123.     break;
  124.       case XcmsCIEuvYFormat:
  125.     fprintf(fp, "\t    format = XcmsCIEuvYFormat\n");
  126.     fprintf(fp, "\t    spec.CIEuvY.u_prime = %f\n", pColor->spec.CIEuvY.u_prime);
  127.     fprintf(fp, "\t    spec.CIEuvY.v_prime = %f\n", pColor->spec.CIEuvY.v_prime);
  128.     fprintf(fp, "\t    spec.CIEuvY.Y = %f\n", pColor->spec.CIEuvY.Y);
  129.     break;
  130.       case XcmsCIELabFormat:
  131.     fprintf(fp, "\t    format = XcmsCIELabFormat\n");
  132.     fprintf(fp, "\t    spec.CIELab.L_star = %f\n", pColor->spec.CIELab.L_star);
  133.     fprintf(fp, "\t    spec.CIELab.a_star = %f\n", pColor->spec.CIELab.a_star);
  134.     fprintf(fp, "\t    spec.CIELab.b_star = %f\n", pColor->spec.CIELab.b_star);
  135.     break;
  136.     case XcmsCIELuvFormat:
  137.     fprintf(fp, "\t    format = XcmsCIELuvFormat\n");
  138.     fprintf(fp, "\t    spec.CIELuv.L_star = %f\n", pColor->spec.CIELuv.L_star);
  139.     fprintf(fp, "\t    spec.CIELuv.u_star = %f\n", pColor->spec.CIELuv.u_star);
  140.     fprintf(fp, "\t    spec.CIELuv.v_star = %f\n", pColor->spec.CIELuv.v_star);
  141.     break;
  142.       case XcmsTekHVCFormat:
  143.     fprintf(fp, "\t    format = XcmsTekHVCFormat\n");
  144.     fprintf(fp, "\t    spec.TekHVC.H = %f\n", pColor->spec.TekHVC.H);
  145.     fprintf(fp, "\t    spec.TekHVC.V = %f\n", pColor->spec.TekHVC.V);
  146.     fprintf(fp, "\t    spec.TekHVC.C = %f\n", pColor->spec.TekHVC.C);
  147.     break;
  148.       default:
  149.     fprintf(fp, "\t    format = Invalid format\n");
  150.     }
  151. }
  152.  
  153.  
  154. /*
  155.  *    NAME
  156.  *        fPrintXcmsColorSpecs -- Print a XcmsColor
  157.  *
  158.  *    SYNOPSIS
  159.  */
  160. void
  161. fPrintXcmsColorSpecs(fp,pColors, nColors)
  162.     FILE *fp;
  163.     XcmsColor *pColors;
  164.     int nColors;
  165. /*
  166.  *    DESCRIPTION
  167.  *        Prints the spec component of the XcmsColor structures
  168.  *        to the specified file.
  169.  *
  170.  *    RETURNS
  171.  *        void
  172.  *
  173.  */
  174. {
  175.     register int i;
  176.     for (i = 0; i < nColors; i++, pColors++) {
  177.     if (nColors > 1) {
  178.         fprintf(fp, "\tcolor[%3d]:\n", i);
  179.     }
  180.     fPrintXcmsColorSpec(fp, pColors);
  181.     }
  182. }
  183.  
  184.  
  185. /*
  186.  *    NAME
  187.  *        fPrintXcmsColors -- Print a XcmsColor
  188.  *
  189.  *    SYNOPSIS
  190.  */
  191. void
  192. fPrintXcmsColors(fp, pColors, nColors)
  193.     FILE *fp;
  194.     XcmsColor *pColors;
  195.     int nColors;
  196. /*
  197.  *    DESCRIPTION
  198.  *        Prints a number of  XcmsColor's to the specified file.
  199.  *
  200.  *    RETURNS
  201.  *        void
  202.  *
  203.  */
  204. {
  205.     register int i;
  206.     for (i = 0; i < nColors; i++, pColors++) {
  207.     if (nColors > 1) {
  208.         fprintf(fp, "\tcolor[%3d]:\n", i);
  209.     }
  210.     fprintf(fp, "\t    pixel = %lu\n", pColors->pixel);
  211.     fPrintXcmsColorSpec(fp, pColors);
  212.     }
  213. }
  214.  
  215.  
  216.  
  217. /*
  218.  *    NAME
  219.  *        fPrintXcmsColorsWithComp -- Print a XcmsColor
  220.  *
  221.  *    SYNOPSIS
  222.  */
  223. void
  224. fPrintXcmsColorsWithComp(fp, pColors, nColors, pCompressed)
  225.     FILE *fp;
  226.     XcmsColor *pColors;
  227.     int nColors;
  228.     Bool *pCompressed;
  229. /*
  230.  *    DESCRIPTION
  231.  *        Prints an number of XcmsColor's to the specified file, and
  232.  *        also the compression flags.
  233.  *
  234.  *    RETURNS
  235.  *        void
  236.  *
  237.  */
  238. {
  239.     register int i;
  240.     for (i = 0; i < nColors; i++, pColors++) {
  241.     if (nColors > 1) {
  242.         fprintf(fp, "\tcolor[%3d]:\n", i);
  243.     }
  244.     fprintf(fp, "\t    pixel = %lu\n", pColors->pixel);
  245.     fPrintXcmsColorSpec(fp, pColors);
  246.     fprintf(fp, "\t    Compressed = %s\n",
  247.         *pCompressed == True ? "YES" : "no");
  248.     }
  249. }
  250.  
  251.  
  252. /*
  253.  *    NAME
  254.  *        PrintXcmsColors -- Print a XcmsColor
  255.  *
  256.  *    SYNOPSIS
  257.  */
  258. void
  259. PrintXcmsColors(pColors, nColors)
  260.     XcmsColor *pColors;
  261.     int nColors;
  262. /*
  263.  *    DESCRIPTION
  264.  *        Prints a number of  XcmsColor's to the standard out.
  265.  *        
  266.  *
  267.  *    RETURNS
  268.  *        void
  269.  *
  270.  */
  271. {
  272.     fPrintXcmsColors(stdout, pColors, nColors);
  273. }
  274.  
  275.  
  276. /*
  277.  *    NAME
  278.  *        PrintXcmsColorsWithComp -- Print a XcmsColor
  279.  *
  280.  *    SYNOPSIS
  281.  */
  282. void
  283. PrintXcmsColorsWithComp(pColors, nColors, pCompressed)
  284.     XcmsColor *pColors;
  285.     int nColors;
  286.     Bool *pCompressed;
  287. /*
  288.  *    DESCRIPTION
  289.  *        Prints an number of XcmsColor's to standard out, and
  290.  *        also the compression flags.
  291.  *
  292.  *    RETURNS
  293.  *        void
  294.  *
  295.  */
  296. {
  297.     fPrintXcmsColorsWithComp(stdout, pColors, nColors, pCompressed);
  298. }
  299.  
  300.  
  301. /*
  302.  *    NAME
  303.  *        PrintXcmsColor -- Print a XcmsColor
  304.  *
  305.  *    SYNOPSIS
  306.  */
  307. void
  308. PrintXcmsColor(pColors)
  309.     XcmsColor *pColors;
  310. /*
  311.  *    DESCRIPTION
  312.  *        Prints one XcmsColor to standard out.
  313.  *        
  314.  *
  315.  *    RETURNS
  316.  *        void
  317.  *
  318.  */
  319. {
  320.     fPrintXcmsColors(stdout, pColors, 1);
  321. }
  322.  
  323.  
  324. /*
  325.  *    NAME
  326.  *        PrintXcmsColorSpecs -- Print a XcmsColor
  327.  *
  328.  *    SYNOPSIS
  329.  */
  330. void
  331. PrintXcmsColorSpecs(pColors, nColors)
  332.     XcmsColor *pColors;
  333.     int nColors;
  334. /*
  335.  *    DESCRIPTION
  336.  *        Prints the spec component of the XcmsColor structures
  337.  *        to standard out.
  338.  *        
  339.  *
  340.  *    RETURNS
  341.  *        void
  342.  *
  343.  */
  344. {
  345.     fPrintXcmsColorSpecs(stdout, pColors, nColors);
  346. }
  347.  
  348.  
  349. /*
  350.  *    NAME
  351.  *        PrintXcmsColorSpec -- Print a XcmsColor
  352.  *
  353.  *    SYNOPSIS
  354.  */
  355. void
  356. PrintXcmsColorSpec(pColors)
  357.     XcmsColor *pColors;
  358. /*
  359.  *    DESCRIPTION
  360.  *        Prints the spec component of one XcmsColor structure
  361.  *        to standard out.
  362.  *        
  363.  *
  364.  *    RETURNS
  365.  *        void
  366.  *
  367.  */
  368. {
  369.     fPrintXcmsColorSpecs(stdout, pColors, 1);
  370. }
  371.