MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / doColor

Method doColor

ij/src/main/java/ij/macro/Functions.java:8589–8644  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8587 }
8588
8589 private Variable doColor() {
8590 interp.getToken();
8591 if (interp.token!='.')
8592 interp.error("'.' expected");
8593 interp.getToken();
8594 if (!(interp.token==WORD||interp.token==PREDEFINED_FUNCTION||interp.token==STRING_FUNCTION))
8595 interp.error("Function name expected: ");
8596 String name = interp.tokenString;
8597 if (name.equals("set")) {
8598 setColor();
8599 return null;
8600 } else if (name.equals("foreground")) {
8601 interp.getParens();
8602 Color color = Toolbar.getForegroundColor();
8603 return new Variable(Colors.colorToString(color));
8604 } else if (name.equals("background")) {
8605 interp.getParens();
8606 Color color = Toolbar.getBackgroundColor();
8607 return new Variable(Colors.colorToString(color));
8608 } else if (name.equals("setForeground")) {
8609 return setForegroundOrBackground(true);
8610 } else if (name.equals("setBackground")) {
8611 return setForegroundOrBackground(false);
8612 } else if (name.equals("setForegroundValue")) {
8613 Toolbar.setForegroundValue(getArg());
8614 return null;
8615 } else if (name.equals("setBackgroundValue")) {
8616 Toolbar.setBackgroundValue(getArg());
8617 return null;
8618 } else if (name.equals("toString")) {
8619 int red = (int)getFirstArg();
8620 int green = (int)getNextArg();
8621 int blue = (int)getLastArg();
8622 Color color = Colors.toColor(red, green, blue);
8623 return new Variable(Colors.colorToString(color));
8624 } else if (name.equals("toArray")) {
8625 String color = getStringArg();
8626 int rgb = Colors.decode(color, Color.black).getRGB();
8627 Variable[] array = new Variable[3];
8628 array[0] = new Variable((rgb&0xff0000)>>16);
8629 array[1] = new Variable((rgb&0xff00)>>8);
8630 array[2] = new Variable(rgb&0xff);
8631 return new Variable(array);
8632 } else if (name.equals("setLut")) {
8633 setLut();
8634 return null;
8635 } else if (name.equals("getLut")) {
8636 getLut();
8637 return null;
8638 } else if (name.equals("wavelengthToColor")) {
8639 Color c = Colors.wavelengthToColor(getArg());
8640 return new Variable(Colors.colorToString(c));
8641 } else
8642 interp.error("Unrecognized Color function");
8643 return null;
8644 }
8645
8646 private Variable setForegroundOrBackground(boolean foreground) {

Callers 1

getVariableFunctionMethod · 0.95

Calls 15

setColorMethod · 0.95
getForegroundColorMethod · 0.95
colorToStringMethod · 0.95
getBackgroundColorMethod · 0.95
setForegroundValueMethod · 0.95
getArgMethod · 0.95
setBackgroundValueMethod · 0.95
getFirstArgMethod · 0.95
getNextArgMethod · 0.95
getLastArgMethod · 0.95
toColorMethod · 0.95

Tested by

no test coverage detected