1. currentrgbcolor

Returns current color as RGB values.

1.1. Syntax

– currentrgbcolor → red green blue

1.2. Stack Effects

Table 1. Before
Level Object

(empty)

Table 2. After
Level Object

2

red (0.0 to 1.0)

1

green (0.0 to 1.0)

0

blue (0.0 to 1.0)

1.3. Description

currentrgbcolor returns the current color in the graphics state according to the red-green-blue color model.

  • If the current color space is DeviceRGB, currentrgbcolor returns the color values most recently specified to setrgbcolor or [setcolor] (or transformed values specified to sethsbcolor) .

  • If the current color space is DeviceGray or DeviceCMYK, currentrgbcolor converts the current color to RGB.

  • For any other color space, currentrgbcolor returns 0.0 0.0 0.0 (black).

Each returned value is in the range 0.0 (no intensity) to 1.0 (full intensity).

1.4. PostScript Level

Level 1 and later

1.5. Examples

Querying current RGB color
1 0 0 setrgbcolor  % Red
currentrgbcolor
% Stack: 1.0 0.0 0.0
Saving and restoring color
currentrgbcolor           % Save current
/blue exch def
/green exch def
/red exch def

0.5 0.5 0 setrgbcolor     % Change to olive
drawShape

red green blue setrgbcolor % Restore
Converting from gray
0.5 setgray
currentrgbcolor
% Stack: 0.5 0.5 0.5
Color manipulation
currentrgbcolor
3 -1 roll              % Rotate R to top
0.5 mul                % Darken red
3 1 roll               % Rotate back
setrgbcolor

1.6. Common Use Cases

1.6.1. Color State Preservation

/SaveColor {
  currentrgbcolor
  /savedBlue exch def
  /savedGreen exch def
  /savedRed exch def
} def

/RestoreColor {
  savedRed savedGreen savedBlue setrgbcolor
} def

1.6.2. Color Modification

/DarkenColor {
  currentrgbcolor
  0.5 mul 3 1 roll
  0.5 mul 3 1 roll
  0.5 mul 3 1 roll
  setrgbcolor
} def

1.6.3. Complementary Colors

/SetComplementary {
  currentrgbcolor
  1 exch sub 3 1 roll
  1 exch sub 3 1 roll
  1 exch sub 3 1 roll
  setrgbcolor
} def

1.6.4. Color Component Access

/GetRedComponent {
  currentrgbcolor
  pop pop  % Remove green and blue
} def

/GetGreenComponent {
  currentrgbcolor
  3 1 roll pop pop  % Remove red and blue
} def

1.7. Common Pitfalls

Color Space Conversion - Converting from CMYK to RGB may not preserve exact colors.
0 1 1 0 setcmykcolor  % Cyan in CMYK
currentrgbcolor       % Converted to RGB
setrgbcolor           % Now in RGB space
% May not match original cyan exactly
Returns Black for Unknown Spaces - Pattern and other color spaces return 0 0 0.
/Pattern setcolorspace
myPattern setcolor
currentrgbcolor        % Returns 0 0 0
Stack Order - Remember RGB order: red at level 2, blue at level 0.
currentrgbcolor
% Stack (bottom to top): red green blue
% Pop order: blue, green, red
Use Array for Storage - Simplifies color management.
[ currentrgbcolor ] /myColor exch def
myColor aload pop setrgbcolor

1.8. Error Conditions

Error Condition

[stackoverflow]

Fewer than 3 free stack positions

1.9. Implementation Notes

  • Fast query operation

  • No modification to graphics state

  • Values always in range 0.0 to 1.0

  • Conversion preserves visual appearance

  • Widely supported (Level 1)

1.10. Color Conversion

When converting from other color spaces:

Gray to RGB
red = green = blue = grayValue
CMYK to RGB (simplified)
red   = (1 - cyan) × (1 - black)
green = (1 - magenta) × (1 - black)
blue  = (1 - yellow) × (1 - black)
HSB to RGB
(Internal conversion - HSB is just RGB entry method)
Other Spaces
red = green = blue = 0.0

1.11. RGB Color Model

The RGB color model is additive:

Red   + Green = Yellow
Red   + Blue  = Magenta
Green + Blue  = Cyan
R + G + B     = White
No components = Black

1.12. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.