colormap.scm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ;; Copyright (c) 2001-2003 by David Frese
  2. (define-record-type color :color
  3. (make-color pixel red green blue)
  4. color?
  5. (pixel color:pixel set-color:pixel!)
  6. (red color:red set-color:red!)
  7. (green color:green set-color:green!)
  8. (blue color:blue set-color:blue!))
  9. (define-exported-binding "scx-color" :color)
  10. (define-enumerated-type colormap-state :colormap-state
  11. colormap-state? colormap-states colormap-state-name colormap-state-index
  12. (uninstalled installed))
  13. (define-exported-binding "scx-colormap-state" :colormap-state)
  14. (define-exported-binding "scx-colormap-states" colormap-states)
  15. ;; *** create, copy, or destroy colormaps ****************************
  16. (define-enumerated-type colormap-alloc :colormap-alloc
  17. colormap-alloc? colormap-allocs colormap-alloc-name colormap-alloc-index
  18. (none all))
  19. (define-exported-binding "scx-colormap-alloc" :colormap-alloc)
  20. (import-xlib-function create-colormap (display window visual alloc)
  21. "scx_Create_Colormap")
  22. (import-xlib-function copy-colormap-and-free (display colormap)
  23. "scx_Copy_Colormap_And_Free")
  24. (import-xlib-function free-colormap (display colormap)
  25. "scx_Free_Colormap")
  26. ;; *** allocate and free colors **************************************
  27. (import-xlib-function alloc-color! (display colormap color)
  28. "scx_Alloc_Color")
  29. ;; red, green and blue can be a number between 0 (inclusive) and 1
  30. ;; (exclusive), or #f
  31. (define (alloc-color display colormap red green blue)
  32. (let ((color (make-color 0 red green blue)))
  33. (and (alloc-color! display colormap color)
  34. (color:pixel color))))
  35. (import-xlib-function %alloc-named-color (display colormap color-name)
  36. "scx_Alloc_Named_Color")
  37. ;; returns a pair (screen-color exact-color) or #f
  38. (define alloc-named-color/exact %alloc-named-color)
  39. ;; returns a color or #f
  40. (define (alloc-named-color display colormap color-name)
  41. (let ((res (alloc-named-color/exact display colormap color-name)))
  42. (and res (car res))))
  43. ;; returns a pair of two lists (plane-masks . pixels) or #f
  44. (import-xlib-function alloc-color-cells/planes
  45. (display colormap contig? nplanes npixels)
  46. "scx_Alloc_Color_Cells")
  47. (define (alloc-color-cells display colormap contig? npixels)
  48. (let ((r (alloc-color-cells/planes display colormap contig? 0 npixels)))
  49. (and r (cdr r))))
  50. ;; returns a list of lists (pixels redmask greenmask bluemask) or #f
  51. (import-xlib-function alloc-color-planes
  52. (display colormap contig? ncolors nreds ngreens nblues)
  53. "scx_Alloc_Color_Planes")
  54. (import-xlib-function free-colors (display colormap pixels planes)
  55. "scx_Free_Colors")
  56. ;; *** obtain color values *******************************************
  57. (import-xlib-function query-colors! (display colormap colors)
  58. "scx_Query_Colors")
  59. (define (query-colors display colormap pixels)
  60. (let ((colors (map (lambda (pixel) (make-color pixel #f #f #f)) pixels)))
  61. (query-colors! display colormap colors)
  62. colors))
  63. (define (query-color! display colormap color)
  64. (query-colors! display colormap (list color)))
  65. (define (query-color display colormap pixel)
  66. (car (query-colors display colormap (list pixel))))
  67. (import-xlib-function lookup-color (display colormap color-name)
  68. "scx_Lookup_Color")
  69. (import-xlib-function parse-color (display colormap spec)
  70. "scx_Parse_Color")
  71. ;; *** set colors ****************************************************
  72. (import-xlib-function store-colors (display colormap colors)
  73. "scx_Store_Colors")
  74. (define (store-color display colormap color)
  75. (store-colors display colormap (list color)))
  76. (import-xlib-function %store-named-color
  77. (display colormap color-name pixel do-red do-green do-blue)
  78. "scx_Store_Named_Color")
  79. (define (store-named-color display colormap color-name pixel . args)
  80. (let ((flags (cond
  81. ((null? args) '(#f #f #f))
  82. ((= 3 (length args)) args)
  83. (else (error "invalid optional arguments" args))))) ;;TODO??
  84. (%store-named-color display colormap color-name pixel
  85. (car flags) (cadr flags) (caddr flags))))