home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprogs / xgamma.icn < prev    next >
Text File  |  2000-07-29  |  4KB  |  134 lines

  1. ############################################################################
  2. #
  3. #    File:     xgamma.icn
  4. #
  5. #    Subject:  Program to configure X color correction
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     November 14, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Xgamma sets the root window properties that provide device-independent
  18. #  color under X windows.  Icon derives the default value of the "gamma"
  19. #  attribute from these properties.
  20. #
  21. #  Ideally, color properties would be set automatically based on 
  22. #  specifications provided by the manufacturer of the monitor.
  23. #  Lacking such specifications, xgamma synthesizes intensity ramps
  24. #  for an ideal monitor characterized by a given gamma value.
  25. #
  26. #  The phosphor colors, which must also be set, are set to those of a
  27. #  Sony Trinitron monitor based on values from the X11R5 distribution.
  28. #
  29. #  There are three ways to call xgamma:
  30. #  
  31. #    xgamma m.n    set color properties using gamma value m.n
  32. #    xgamma none    remove color properties
  33. #    xgamma        report gamma attribute inferred by Icon
  34. #
  35. #  A pipe to "xcmsdb" is opened, so that program must be in the current
  36. #  search path.
  37. #
  38. #  The default gamma attribute calculated by Icon does not always exactly
  39. #  match the value set by xgamma.  The reason for this is unclear.
  40. #
  41. ############################################################################
  42. #
  43. #  Requires:  Version 9 graphics under X11R5
  44. #
  45. ############################################################################
  46. #
  47. #  Links: wopen
  48. #
  49. ############################################################################
  50.  
  51. link wopen
  52.  
  53. global ofile
  54.  
  55. procedure main(args)
  56.    local gamma
  57.  
  58.    if *args = 0 then {
  59.       WOpen("canvas=hidden", "size=200,100") | stop("can't open window")
  60.       write(left(WAttrib("gamma") + 0.005, 4))
  61.       return
  62.       }
  63.  
  64.    if map(args[1]) == ("none" | "off" | "remove") then {
  65.       system("xcmsdb -remove")
  66.       return
  67.       }
  68.  
  69.    gamma := real(args[1]) | 2.5
  70.    ofile := open("xcmsdb", "wp") | stop("can't open pipe to xcmsdb")
  71.  
  72.    write(ofile, "SCREENDATA_BEGIN        0.3")
  73.    header()
  74.    matrices()
  75.    ramps(gamma)
  76.    write(ofile, )
  77.    write(ofile, "SCREENDATA_END")
  78. end
  79.  
  80.  
  81. procedure header()
  82.    every write(ofile, ![
  83.       "",
  84.       "    NAME                Unknown monitor",
  85.       "    PART_NUMBER         3",
  86.       "    MODEL               Unknown",
  87.       "    SCREEN_CLASS        VIDEO_RGB",
  88.       "    REVISION            2.0",
  89.       ])
  90. end
  91.  
  92.  
  93. procedure matrices()
  94.    # Trinitron specs from X11R5 contrib/clients/xcrtca/monitors
  95.    every write(ofile, "    ", \![
  96.       "COLORIMETRIC_BEGIN",
  97.       "    XYZtoRGB_MATRIX_BEGIN",
  98.       "         3.061645878834450   -1.278267953801873   -0.444951165661258",
  99.       "        -1.032702121385028    1.976844500877421    0.008133037520752",
  100.       "         0.057063919003669   -0.199057800043321    0.779596768525705",
  101.       "    XYZtoRGB_MATRIX_END",
  102.       "    RGBtoXYZ_MATRIX_BEGIN",
  103.       "         0.422396751969335    0.297093836421011    0.237981555762915",
  104.       "         0.220555266059938    0.660453956058605    0.118990777881458",
  105.       "         0.025397273061447    0.146890261130091    1.295677359153649",
  106.       "    RGBtoXYZ_MATRIX_END",
  107.       "COLORIMETRIC_END",
  108.       ])
  109. end
  110.  
  111.  
  112. procedure ramps(gamma)
  113.    write(ofile, "    INTENSITY_PROFILE_BEGIN 0 3")
  114.    every hue("RED" | "GREEN" | "BLUE", gamma)
  115.    write(ofile, "    INTENSITY_PROFILE_END")
  116. end
  117.  
  118.  
  119. procedure hue(c, gamma)
  120.    local i, x, v
  121.    static hextab
  122.    initial every put((hextab := []), !"0123456789abcdef" || !"0123456789abcdef")
  123.  
  124.    write(ofile, "    INTENSITY_TBL_BEGIN    ", c, "    256")
  125.    every i := 0 to 255 do {
  126.       x := hextab[i + 1]
  127.       v := (i / 255.0) ^ gamma
  128.       if v < 0.0001 then        # avoid "e" notation
  129.          v := 0.0
  130.       write(ofile, "            0x", x, x, " ", left(v, 8, "0"))
  131.       }
  132.    write(ofile, "    INTENSITY_TBL_END")
  133. end
  134.