Example #1
0
 public void run(ImageProcessor ip) {
   if (enlarge && gd.wasOKed())
     synchronized (this) {
       if (!isEnlarged) {
         enlargeCanvas();
         isEnlarged = true;
       }
     }
   if (isEnlarged) { // enlarging may have made the ImageProcessor invalid, also for the parallel
                     // threads
     int slice = pfr.getSliceNumber();
     if (imp.getStackSize() == 1) ip = imp.getProcessor();
     else ip = imp.getStack().getProcessor(slice);
   }
   ip.setInterpolationMethod(interpolationMethod);
   if (fillWithBackground) {
     Color bgc = Toolbar.getBackgroundColor();
     if (bitDepth == 8) ip.setBackgroundValue(ip.getBestIndex(bgc));
     else if (bitDepth == 24) ip.setBackgroundValue(bgc.getRGB());
   } else ip.setBackgroundValue(0);
   ip.rotate(angle);
   if (!gd.wasOKed()) drawGridLines(gridLines);
   if (isEnlarged && imp.getStackSize() == 1) {
     imp.changes = true;
     imp.updateAndDraw();
     Undo.setup(Undo.COMPOUND_FILTER_DONE, imp);
   }
 }
  /**
   * Compute a contrasting background color to draw the label's outline.
   *
   * @param color Label color.
   * @return A color that contrasts with {@code color}.
   */
  protected Color computeBackgroundColor(Color color) {
    float[] colorArray = new float[4];
    Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), colorArray);

    if (colorArray[2] > 0.5) return new Color(0, 0, 0, 0.7f);
    else return new Color(1, 1, 1, 0.7f);
  }
Example #3
0
 public void addPlot(String name, int[] data) {
   plot_names.add(name);
   plot_data.add(data);
   int new_max = getMax(plot_data.size() - 1);
   if (new_max > MAX_Y) {
     MAX_Y = new_max;
   }
   if (data.length > MAX_X) {
     MAX_X = data.length;
   }
   int i = plot_data.size();
   Color c =
       new Color(
           (i * COLOR_RATIO) % 255,
           ((i + 2) * COLOR_RATIO) % 255,
           ((i + 3) * COLOR_RATIO) % 255,
           255);
   plot_colors.add(c);
   for (int j = 0; j < plot_colors.size(); j++) {
     Color color = plot_colors.get(j);
     Color new_color =
         new Color(
             color.getRed(), color.getBlue(), color.getGreen(), 127 / plot_colors.size() + 128);
     plot_colors.set(j, new_color);
   }
 }
  /**
   * Draw labels for picking.
   *
   * @param dc Current draw context.
   * @param pickSupport the PickSupport instance to be used.
   */
  protected void doPick(DrawContext dc, PickSupport pickSupport) {
    GL gl = dc.getGL();

    Angle heading = this.rotation;

    double headingDegrees;
    if (heading != null) headingDegrees = heading.degrees;
    else headingDegrees = 0;

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    boolean matrixPushed = false;
    try {
      if (headingDegrees != 0) {
        gl.glPushMatrix();
        matrixPushed = true;

        gl.glTranslated(x, y, 0);
        gl.glRotated(headingDegrees, 0, 0, 1);
        gl.glTranslated(-x, -y, 0);
      }

      for (int i = 0; i < this.lines.length; i++) {
        Rectangle2D bounds = this.lineBounds[i];
        double width = bounds.getWidth();
        double height = bounds.getHeight();

        x = this.screenPoint.x;
        if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0);
        else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width;
        y -= this.lineHeight;

        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false);
        pickSupport.addPickableObject(po);

        // Draw line rectangle
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());

        try {
          gl.glBegin(GL.GL_POLYGON);
          gl.glVertex3d(x, y, 0);
          gl.glVertex3d(x + width - 1, y, 0);
          gl.glVertex3d(x + width - 1, y + height - 1, 0);
          gl.glVertex3d(x, y + height - 1, 0);
          gl.glVertex3d(x, y, 0);
        } finally {
          gl.glEnd();
        }

        y -= this.lineSpacing;
      }
    } finally {
      if (matrixPushed) {
        gl.glPopMatrix();
      }
    }
  }
Example #5
0
 /**
  * Sets the fillColor and defines the outline color to be a non-transparent version of the fill
  * color
  */
 public void setColor(Color fillColor) {
   m_fillColor = fillColor;
   m_outlineColor =
       new Color(
           fillColor.getRed() < 255 ? 0.0f : 1.0f,
           fillColor.getGreen() < 255 ? 0.0f : 1.0f,
           fillColor.getBlue() < 255 ? 0.0f : 1.0f);
 }
Example #6
0
  /**
   * Esta funcion se usa para inicializar los colores del tema segun los argumentos que se le pasen.
   */
  static NimRODTheme iniCustomColors(
      NimRODTheme nt,
      String selection,
      String background,
      String p1,
      String p2,
      String p3,
      String s1,
      String s2,
      String s3,
      String w,
      String b,
      String opMenu,
      String opFrame) {
    if (selection != null) {
      nt.setPrimary(Color.decode(selection));
    }
    if (background != null) {
      nt.setSecondary(Color.decode(background));
    }

    if (p1 != null) {
      nt.setPrimary1(Color.decode(p1));
    }
    if (p2 != null) {
      nt.setPrimary2(Color.decode(p2));
    }
    if (p3 != null) {
      nt.setPrimary3(Color.decode(p3));
    }

    if (s1 != null) {
      nt.setSecondary1(Color.decode(s1));
    }
    if (s2 != null) {
      nt.setSecondary2(Color.decode(s2));
    }
    if (s3 != null) {
      nt.setSecondary3(Color.decode(s3));
    }

    if (w != null) {
      nt.setWhite(Color.decode(w));
    }
    if (b != null) {
      nt.setBlack(Color.decode(b));
    }

    if (opMenu != null) {
      nt.setMenuOpacity(Integer.parseInt(opMenu));
    }
    if (opFrame != null) {
      nt.setFrameOpacity(Integer.parseInt(opFrame));
    }

    return nt;
  }
Example #7
0
 /**
  * Gets the stroke paint for the specified figure based on the attributes STROKE_GRADIENT,
  * STROKE_OPACITY, STROKE_PAINT and the bounds of the figure. Returns null if the figure is not
  * filled.
  */
 public static Paint getStrokePaint(Figure f) {
   double opacity = STROKE_OPACITY.get(f);
   if (STROKE_GRADIENT.get(f) != null) {
     return STROKE_GRADIENT.get(f).getPaint(f, opacity);
   }
   Color color = STROKE_COLOR.get(f);
   if (color != null) {
     if (opacity != 1) {
       color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true);
     }
   }
   return color;
 }
Example #8
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in RED, GREEN, or BLUE mode, then this method converts these values to RGB
   * coordinates and calls <code>setRGB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param h the hue value of the selected color.
   * @param s the saturation value of the selected color.
   * @param b the brightness value of the selected color.
   */
  public void setHSB(float h, float s, float b) {
    if (Float.isInfinite(h) || Float.isNaN(h))
      throw new IllegalArgumentException("The hue value (" + h + ") is not a valid number.");
    // hue is cyclic, so it can be any value:
    while (h < 0) h++;
    while (h > 1) h--;

    if (s < 0 || s > 1)
      throw new IllegalArgumentException("The saturation value (" + s + ") must be between [0,1]");
    if (b < 0 || b > 1)
      throw new IllegalArgumentException("The brightness value (" + b + ") must be between [0,1]");

    if (hue != h || sat != s || bri != b) {
      if (mode == ColorPicker.HUE || mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
        float lastHue = hue;
        float lastBri = bri;
        float lastSat = sat;
        hue = h;
        sat = s;
        bri = b;
        if (mode == ColorPicker.HUE) {
          if (lastHue != hue) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.SAT) {
          if (lastSat != sat) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BRI) {
          if (lastBri != bri) {
            regenerateImage();
          }
        }
      } else {

        Color c = new Color(Color.HSBtoRGB(h, s, b));
        setRGB(c.getRed(), c.getGreen(), c.getBlue());
        return;
      }

      Color c = new Color(Color.HSBtoRGB(hue, sat, bri));
      red = c.getRed();
      green = c.getGreen();
      blue = c.getBlue();

      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
  private Color getThreadBlockColor(BumpThread bt) {
    if (bt == null) return Color.BLACK;

    synchronized (thread_colors) {
      Color c = thread_colors.get(bt);
      if (c == null) {
        double v;
        int ct = thread_colors.size();
        if (ct == 0) v = 0;
        else if (ct == 1) v = 1;
        else {
          v = 0.5;
          int p0 = ct - 1;
          int p1 = 1;
          for (int p = p0; p > 1; p /= 2) {
            v /= 2.0;
            p0 -= p1;
            p1 *= 2;
          }
          if ((p0 & 1) == 0) p0 = 2 * p1 - p0 + 1;
          v = v * p0;
        }
        float h = (float) (v * 0.8);
        float s = 0.7f;
        float b = 1.0f;
        int rgb = Color.HSBtoRGB(h, s, b);
        rgb |= 0xc0000000;
        c = new Color(rgb, true);
        thread_colors.put(bt, c);
      }
      return c;
    }
  }
Example #10
0
    @Override
    public int getColor(VisualItem item) {

      // get value for target attr in item
      if (item.canGetString(colorAttrName)) {
        String attrVal = item.getString(colorAttrName);
        Color attrValColor = catToColorMap.get(attrVal);
        if (attrValColor == null) {
          return Color.CYAN.getRGB();
        }
        return attrValColor.getRGB();
      }

      Color white = Color.WHITE;
      return white.getRGB();
    }
Example #11
0
  /*
  ****************** CHECKLIST ******************************
  [x] manipulate every Pixel in the Picture
  [x] The value of amount MUST control the amount of the effect

  */
  public void changeWhole(double amount) {
    int yMax = this.getHeight();
    int xMax = this.getWidth();

    Color p;

    for (int i = 0; i < xMax - 1; i++) {
      for (int j = 0; j < yMax - 1; j++) {
        p = this.getPixel(i, j).getColor();
        int R = (int) (p.getRed() * amount);
        int G = (int) (p.getBlue() * (amount));
        int B = (int) (p.getGreen() * (amount));
        Color C = new Color(G, B, R);
        this.getPixel(i, j).setColor((C));
      }
    }
  }
Example #12
0
 /**
  * 指定した属性でJDGradientPaintを構築します.
  *
  * @param p1 ユーザー空間で最初に指定されたPoint<br>
  *     p2 ユーザー空間で2番目に指定されたPoint<br>
  *     ; c1 ポイントp1のカラー<br>
  *     c2 ポイントp2のカラー<br>
  *     cp p1からp2間の制御点 cols 制御点のカラー gTyp 塗りのタイプ
  */
 public JDGradientPaint(
     Point2D p1, Point2D p2, Color c1, Color c2, float[] cp, Color[] cols, int gType) {
   this.p1 = p1;
   this.p2 = p2;
   this.c1 = c1;
   this.c2 = c2;
   this.controlPoints = cp;
   this.colors = cols;
   this.gType = gType;
   dx = (float) (p2.getX() - p1.getX());
   dy = (float) (p2.getY() - p1.getY());
   distance = (float) Math.sqrt(dx * dx + dy * dy);
   startC = new float[4];
   endC = new float[4];
   startC = c1.getComponents(startC);
   endC = c2.getComponents(endC);
 }
Example #13
0
 /**
  * WhiteboardShapeLine constructor.
  *
  * @param id String that uniquely identifies this WhiteboardObject.
  * @param t number of pixels that this object (or its border) should be thick.
  * @param c WhiteboardShapeLine's color (or rather it's border)
  * @param startPoint the start coordinates of this line.
  * @param endPoint the end coordinates of this line.
  */
 public WhiteboardShapeLine(
     String id, int t, Color c, WhiteboardPoint startPoint, WhiteboardPoint endPoint) {
   super(id);
   this.setThickness(t);
   setColor(c);
   setColor(c.getRGB());
   this.endPoint = endPoint;
   this.startPoint = startPoint;
 }
  /**
   * Render the label interior as a filled rectangle.
   *
   * @param dc Current draw context.
   */
  protected void drawInterior(DrawContext dc) {
    GL gl = dc.getGL();

    double width = this.bounds.getWidth();
    double height = this.bounds.getHeight();

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    // Adjust x to account for text alignment
    int xAligned = x;
    if (AVKey.CENTER.equals(textAlign)) xAligned = x - (int) (width / 2);
    else if (AVKey.RIGHT.equals(textAlign)) xAligned = x - (int) width;

    // We draw text top-down, so adjust y to compensate.
    int yAligned = (int) (y - height);

    // Apply insets
    Insets insets = this.getInsets();
    xAligned -= insets.left;
    width = width + insets.left + insets.right;
    yAligned -= insets.bottom;
    height = height + insets.bottom + insets.top;

    if (!dc.isPickingMode()) {
      // Apply the frame background color and opacity if we're in normal rendering mode.
      Color color = this.computeBackgroundColor(this.getMaterial().getDiffuse());
      gl.glColor4ub(
          (byte) color.getRed(),
          (byte) color.getGreen(),
          (byte) color.getBlue(),
          (byte) (this.interiorOpacity < 1 ? (int) (this.interiorOpacity * 255 + 0.5) : 255));
    }

    try {
      // Draw a quad
      gl.glPushMatrix();
      gl.glTranslated(xAligned, yAligned, 0);
      gl.glScaled(width, height, 1.0);
      dc.drawUnitQuad();
    } finally {
      gl.glPopMatrix();
    }
  }
  /**
   * Draw the label's text. This method assumes that the text renderer context has already been set
   * up.
   *
   * @param textRenderer renderer to use.
   */
  protected void doDrawText(TextRenderer textRenderer) {
    Color color = this.material.getDiffuse();
    Color backgroundColor = this.computeBackgroundColor(color);
    float opacity = (float) this.getOpacity();

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    float[] compArray = new float[3];
    if (AVKey.TEXT_EFFECT_SHADOW.equals(this.effect) && backgroundColor != null) {
      backgroundColor.getRGBColorComponents(compArray);

      textRenderer.setColor(compArray[0], compArray[1], compArray[2], opacity);
      this.drawMultiLineText(textRenderer, x + 1, y - 1);
    }

    color.getRGBColorComponents(compArray);
    textRenderer.setColor(compArray[0], compArray[1], compArray[2], opacity);
    this.drawMultiLineText(textRenderer, x, y);
  }
Example #16
0
 protected void setDrawingColor(int ox, int oy, boolean setBackground) {
   // IJ.log("setDrawingColor: "+setBackground+this);
   int type = imp.getType();
   int[] v = imp.getPixel(ox, oy);
   switch (type) {
     case ImagePlus.GRAY8:
       {
         if (setBackground) setBackgroundColor(getColor(v[0]));
         else setForegroundColor(getColor(v[0]));
         break;
       }
     case ImagePlus.GRAY16:
     case ImagePlus.GRAY32:
       {
         double min = imp.getProcessor().getMin();
         double max = imp.getProcessor().getMax();
         double value = (type == ImagePlus.GRAY32) ? Float.intBitsToFloat(v[0]) : v[0];
         int index = (int) (255.0 * ((value - min) / (max - min)));
         if (index < 0) index = 0;
         if (index > 255) index = 255;
         if (setBackground) setBackgroundColor(getColor(index));
         else setForegroundColor(getColor(index));
         break;
       }
     case ImagePlus.COLOR_RGB:
     case ImagePlus.COLOR_256:
       {
         Color c = new Color(v[0], v[1], v[2]);
         if (setBackground) setBackgroundColor(c);
         else setForegroundColor(c);
         break;
       }
   }
   Color c;
   if (setBackground) c = Toolbar.getBackgroundColor();
   else {
     c = Toolbar.getForegroundColor();
     imp.setColor(c);
   }
   IJ.showStatus("(" + c.getRed() + ", " + c.getGreen() + ", " + c.getBlue() + ")");
 }
Example #17
0
 /**
  * selectClickable -- a recursive function which searches the game board for game balls of the
  * same color as the one selected, and 'selects' them as well.
  */
 public void selectClickable(int m, int n) {
   Color home = balls[m][n].getColor();
   balls[m][n].select();
   scount += 1;
   if ((n - 1) >= 0) {
     Color north = balls[m][n - 1].getColor();
     if ((home.equals(north)) && !(balls[m][n - 1].isSelected())) selectClickable(m, (n - 1));
   }
   if ((m - 1) >= 0) {
     Color west = balls[m - 1][n].getColor();
     if ((home.equals(west)) && !(balls[m - 1][n].isSelected())) selectClickable((m - 1), n);
   }
   if ((n + 1) < B_HEIGHT) {
     Color south = balls[m][n + 1].getColor();
     if ((home.equals(south)) && !(balls[m][n + 1].isSelected())) selectClickable(m, (n + 1));
   }
   if ((m + 1) < B_WIDTH) {
     Color east = balls[m + 1][n].getColor();
     if ((home.equals(east)) && !(balls[m + 1][n].isSelected())) selectClickable((m + 1), n);
   }
 }
Example #18
0
  public static void main(String[] args) {
    int x = 500, y = 80;
    DrawingKit dk = new DrawingKit("Daffodils", 800, 800);
    BufferedImage pict = dk.loadPicture("daffodils.jpg");

    // get pixel value at location (500, 80)
    int encodedPixelColor = pict.getRGB(x, y);
    Color pixelColor = new Color(encodedPixelColor);
    System.out.println(pixelColor);
    int red = pixelColor.getRed();
    int green = pixelColor.getGreen();
    int blue = pixelColor.getBlue();
    // change the color of the pixel to be pure red
    red = 255;
    green = 0;
    blue = 0;

    // update the pixel color in picture
    Color newPixelColor = new Color(red, green, blue);
    int newRgbvalue = newPixelColor.getRGB();
    pict.setRGB(x, y, newRgbvalue);
    // display the approximate location of the pixel
    dk.drawPicture(pict, 0, 0);
    BasicStroke s = new BasicStroke(3);
    dk.setStroke(s);
    Ellipse2D.Float e = new Ellipse2D.Float(x - 3, y - 3, 8, 8);
    dk.draw(e);
    dk.drawString("(600, 150)", x - 3, y - 5);
  }
Example #19
0
  public void actionMouseClicked(InputEventInfo event) {
    if (event.getAction() == InputEventInfo.ACTION_PRESSED) {
      super.onMouseDown();
    } else if (event.getAction() == InputEventInfo.ACTION_RELEASED && isPressed) {
      // Networking.send(CalicoPacket.getPacket(NetworkCommand.CANVAS_REDO, cuid));
      Calico.logger.debug("Pressed Color button " + color.toString());
      CalicoDataStore.PenColor = color;
      CalicoDataStore.LastDrawingColor = color;

      if (CalicoDataStore.Mode != CInputMode.ARROW) CalicoDataStore.set_Mode(CInputMode.EXPERT);
      CCanvasController.redrawMenuBars();
      isPressed = false;
    }
  }
Example #20
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in HUE, SAT, or BRI mode, then this method converts these values to HSB
   * coordinates and calls <code>setHSB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param r the red value of the selected color.
   * @param g the green value of the selected color.
   * @param b the blue value of the selected color.
   */
  public void setRGB(int r, int g, int b) {
    if (r < 0 || r > 255)
      throw new IllegalArgumentException("The red value (" + r + ") must be between [0,255].");
    if (g < 0 || g > 255)
      throw new IllegalArgumentException("The green value (" + g + ") must be between [0,255].");
    if (b < 0 || b > 255)
      throw new IllegalArgumentException("The blue value (" + b + ") must be between [0,255].");

    if (red != r || green != g || blue != b) {
      if (mode == ColorPicker.RED || mode == ColorPicker.GREEN || mode == ColorPicker.BLUE) {
        int lastR = red;
        int lastG = green;
        int lastB = blue;
        red = r;
        green = g;
        blue = b;

        if (mode == ColorPicker.RED) {
          if (lastR != r) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.GREEN) {
          if (lastG != g) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BLUE) {
          if (lastB != b) {
            regenerateImage();
          }
        }
      } else {
        float[] hsb = new float[3];
        Color.RGBtoHSB(r, g, b, hsb);
        setHSB(hsb[0], hsb[1], hsb[2]);
        return;
      }
      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
Example #21
0
  /**
   * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla
   * en todas partes...
   */
  static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    Color oldColor = g.getColor();

    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();

    if (menuItem.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
    }

    if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected())
        || model.isArmed()) {
      RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
      boton.x = 1;
      boton.y = 0;
      boton.width = menuWidth - 3;
      boton.height = menuHeight - 1;
      boton.arcwidth = 8;
      boton.archeight = 8;

      GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu());

      Graphics2D g2D = (Graphics2D) g;
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(bgColor);
      g2D.fill(boton);

      g.setColor(bgColor.darker());
      g2D.draw(boton);

      g2D.setPaint(grad);
      g2D.fill(boton);

      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    }

    g.setColor(oldColor);
  }
Example #22
0
 void initGraphics(Graphics g, Color textColor, Color defaultColor) {
   if (smallFont == null) {
     smallFont = new Font("SansSerif", Font.PLAIN, 9);
     largeFont = new Font("SansSerif", Font.PLAIN, 12);
   }
   if (textColor != null) {
     labelColor = textColor;
     if (overlay != null && overlay.getDrawBackgrounds())
       bgColor =
           new Color(
               255 - labelColor.getRed(), 255 - labelColor.getGreen(), 255 - labelColor.getBlue());
     else bgColor = null;
   } else {
     int red = defaultColor.getRed();
     int green = defaultColor.getGreen();
     int blue = defaultColor.getBlue();
     if ((red + green + blue) / 3 < 128) labelColor = Color.white;
     else labelColor = Color.black;
     bgColor = defaultColor;
   }
   this.defaultColor = defaultColor;
   g.setColor(defaultColor);
 }
Example #23
0
  /** Regenerates the image. */
  private synchronized void regenerateImage() {
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
      float bri2 = this.bri;
      float sat2 = this.sat;
      float radius = ((float) size) / 2f;
      float hue2;
      float k = 1.2f; // the number of pixels to antialias
      for (int y = 0; y < size; y++) {
        float y2 = (y - size / 2f);
        for (int x = 0; x < size; x++) {
          float x2 = (x - size / 2f);
          double theta = Math.atan2(y2, x2) - 3 * Math.PI / 2.0;
          if (theta < 0) theta += 2 * Math.PI;

          double r = Math.sqrt(x2 * x2 + y2 * y2);
          if (r <= radius) {
            if (mode == ColorPicker.BRI) {
              hue2 = (float) (theta / (2 * Math.PI));
              sat2 = (float) (r / radius);
            } else { // SAT
              hue2 = (float) (theta / (2 * Math.PI));
              bri2 = (float) (r / radius);
            }
            row[x] = Color.HSBtoRGB(hue2, sat2, bri2);
            if (r > radius - k) {
              int alpha = (int) (255 - 255 * (r - radius + k) / k);
              if (alpha < 0) alpha = 0;
              if (alpha > 255) alpha = 255;
              row[x] = row[x] & 0xffffff + (alpha << 24);
            }
          } else {
            row[x] = 0x00000000;
          }
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    } else if (mode == ColorPicker.HUE) {
      float hue2 = this.hue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          row[x] = Color.HSBtoRGB(hue2, x2, y2);
        }
        image.getRaster().setDataElements(0, y, image.getWidth(), 1, row);
      }
    } else { // mode is RED, GREEN, or BLUE
      int red2 = red;
      int green2 = green;
      int blue2 = blue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          if (mode == ColorPicker.RED) {
            green2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else if (mode == ColorPicker.GREEN) {
            red2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else {
            red2 = (int) (x2 * 255 + .49);
            green2 = (int) (y2 * 255 + .49);
          }
          row[x] = 0xFF000000 + (red2 << 16) + (green2 << 8) + blue2;
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    }
    repaint();
  }
  public int getColorComp(Color c) {
    float[] compArray = new float[4];
    c.getColorComponents(compArray);

    return (int) (compArray[mode.ordinal()] * 255);
  }
Example #25
0
  public BufferedImage getBufferedImage(int type, Color c) {

    BufferedImage image = null;
    float[] colComp = new float[3];
    c.getRGBColorComponents(colComp);
    double red = (double) colComp[0];
    double green = (double) colComp[1];
    double blue = (double) colComp[2];
    // System.out.println("blue, green, red = "+ blue +", " + green + ", " + red);

    double x = 0.0;
    double x2;
    switch (type) {
      case ScalarImage.TYPE_BYTE_RANDOM:
        {
          int numCol = 256;
          byte[] bBuf = new byte[numCol * 3];
          blue *= 255 * 4.;
          green *= 255 * 4.;
          red *= 255 * 4.;
          double delta = 1.0 / (double) (numCol + 1);
          int j = 0;
          for (int i = 0; i < numCol; i++) {
            if (i % 5 == 0) x = 0.7 * Math.random() + 0.3 * x;
            x2 = x * x;
            bBuf[j++] = (byte) clamp((510 - red) * x2 + (red - 255) * x);
            bBuf[j++] = (byte) clamp((510 - green) * x2 + (green - 255) * x);
            bBuf[j++] = (byte) clamp((510 - blue) * x2 + (blue - 255) * x);
            // x += delta;
          }
          IndexColorModel cm = new IndexColorModel(8, numCol, bBuf, 0, false);
          // image = new
          // BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,cm);
          byte[] idxBuffer = new byte[size];
          for (int i = 0; i < size; i++) {
            idxBuffer[i] = (byte) (clamp(f[i] * 255.));
          }
          DataBufferByte dataBuffer = new DataBufferByte(idxBuffer, size);
          int idxOffset[] = {0};
          int idxBits[] = {8};
          try {
            ComponentSampleModel idxSampleModel =
                new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, idxOffset);
            WritableRaster rasterIdx =
                java.awt.image.Raster.createWritableRaster(
                    idxSampleModel, dataBuffer, new Point(0, 0));
            image = new BufferedImage(cm, rasterIdx, false, null);
          } catch (Exception e) {
            System.out.println("Exception caught while acquiring image:");
            System.out.println(e.getMessage());
          }
        }
        break;
      case BufferedImage.TYPE_BYTE_INDEXED:
        {
          int numCol = 256;
          byte[] bBuf = new byte[numCol * 3];
          blue *= 255 * 4.;
          green *= 255 * 4.;
          red *= 255 * 4.;
          double delta = 1.0 / (double) (numCol + 1);
          int j = 0;
          for (int i = 0; i < numCol; i++) {
            x2 = x * x;
            bBuf[j++] = (byte) clamp((510 - red) * x2 + (red - 255) * x);
            bBuf[j++] = (byte) clamp((510 - green) * x2 + (green - 255) * x);
            bBuf[j++] = (byte) clamp((510 - blue) * x2 + (blue - 255) * x);
            x += delta;
          }
          IndexColorModel cm = new IndexColorModel(8, numCol, bBuf, 0, false);
          // image = new
          // BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,cm);
          byte[] idxBuffer = new byte[size];
          for (int i = 0; i < size; i++) {
            idxBuffer[i] = (byte) (clamp(f[i] * 255.));
          }
          DataBufferByte dataBuffer = new DataBufferByte(idxBuffer, size);
          int idxOffset[] = {0};
          int idxBits[] = {8};
          try {
            ComponentSampleModel idxSampleModel =
                new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, idxOffset);
            WritableRaster rasterIdx =
                java.awt.image.Raster.createWritableRaster(
                    idxSampleModel, dataBuffer, new Point(0, 0));
            image = new BufferedImage(cm, rasterIdx, false, null);
          } catch (Exception e) {
            System.out.println("Exception caught while acquiring image:");
            System.out.println(e.getMessage());
          }
        }
        break;
      case BufferedImage.TYPE_BYTE_GRAY:
        break;
      case BufferedImage.TYPE_3BYTE_BGR:
      default:
        byte[] byteBuffer = new byte[size * 3];
        blue *= 255 * 4.;
        green *= 255 * 4.;
        red *= 255 * 4.;

        int j = 0;
        for (int i = 0; i < size; i++) {
          x = f[i];
          x2 = x * x;
          /*
          byteBuffer[j++] = (byte)clamp( ( 2 * 255 - 4 * red ) * x * x + ( 4 * red - 255 ) * x);
          byteBuffer[j++] = (byte)clamp( ( 2 * 255 - 4 * green ) * x * x + ( 4 * green - 255 ) * x);
          byteBuffer[j++] = (byte)clamp( ( 2 * 255 - 4 * blue ) * x * x + ( 4 * blue - 255 ) * x);
          */
          byteBuffer[j++] = (byte) clamp((510 - red) * x2 + (red - 255) * x);
          byteBuffer[j++] = (byte) clamp((510 - green) * x2 + (green - 255) * x);
          byteBuffer[j++] = (byte) clamp((510 - blue) * x2 + (blue - 255) * x);
        }
        DataBufferByte dataBuffer = new DataBufferByte(byteBuffer, size * 3);
        int componentOffset[] = {0, 1, 2};
        int componentBits[] = {8, 8, 8};
        try {
          WritableRaster raster =
              java.awt.image.Raster.createWritableRaster(
                  new PixelInterleavedSampleModel(
                      DataBuffer.TYPE_BYTE, width, height, 3, width * 3, componentOffset),
                  dataBuffer,
                  new Point(0, 0));
          image =
              new BufferedImage(
                  new ComponentColorModel(
                      ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
                      componentBits,
                      false,
                      false,
                      ColorModel.OPAQUE,
                      DataBuffer.TYPE_BYTE),
                  raster,
                  false,
                  null);

        } catch (Exception e) {
          System.out.println("Exception caught while acquiring image:");
          System.out.println(e.getMessage());
        }
        break;
    }
    return image;
  }
  protected void hitOrDraw(Graphics2D graphics, DrawInfo2D info, Bag putInHere) {
    final Grid2D field = (Grid2D) (this.field);
    if (field == null) return;

    // first question: determine the range in which we need to draw.
    final int maxX = field.getWidth();
    final int maxY = field.getHeight();
    if (maxX == 0 || maxY == 0) return;

    final double divideByX =
        ((maxX % 2 == 0) ? (3.0 * maxX / 2.0 + 0.5) : (3.0 * maxX / 2.0 + 2.0));
    final double divideByY = (1.0 + 2.0 * maxY);

    final double xScale = info.draw.width / divideByX;
    final double yScale = info.draw.height / divideByY;
    int startx = (int) (((info.clip.x - info.draw.x) / xScale - 0.5) / 1.5) - 2;
    int starty = (int) ((info.clip.y - info.draw.y) / (yScale * 2.0)) - 2;
    int endx = /*startx +*/
        (int) (((info.clip.x - info.draw.x + info.clip.width) / xScale - 0.5) / 1.5)
            + 4; // with rounding, width be as much as 1 off
    int endy = /*starty +*/
        (int) ((info.clip.y - info.draw.y + info.clip.height) / (yScale * 2.0))
            + 4; // with rounding, height be as much as 1 off

    //
    //
    // CAUTION!
    //
    // At some point we should triple check the math for rounding such
    // that the margins are drawn properly
    //
    //

    // next we determine if this is a DoubleGrid2D or an IntGrid2D

    //        final Rectangle clip = (graphics==null ? null : graphics.getClipBounds());

    final boolean isDoubleGrid2D = (field instanceof DoubleGrid2D);
    final double[][] doubleField = (isDoubleGrid2D ? ((DoubleGrid2D) field).field : null);
    final int[][] intField = (isDoubleGrid2D ? null : ((IntGrid2D) field).field);

    double xyC_x, xyC_y, xyC_ulx, xyC_uly, xyC_upx, xyC_upy, xyC_urx, xyC_ury, x0, y0, tx, ty;

    if (startx < 0) startx = 0;
    if (starty < 0) starty = 0;
    if (endx > maxX) endx = maxX;
    if (endy > maxY) endy = maxY;

    for (int y = starty; y < endy; y++)
      for (int x = startx; x < endx; x++) {
        // getxyC( x, y, xScale, yScale, info.draw.x, info.draw.y, xyC );
        // getxyC( field.ulx(x,y), field.uly(x,y), xScale, yScale, info.draw.x, info.draw.y, xyC_ul
        // );
        // getxyC( field.upx(x,y), field.upy(x,y), xScale, yScale, info.draw.x, info.draw.y, xyC_up
        // );
        // getxyC( field.urx(x,y), field.ury(x,y), xScale, yScale, info.draw.x, info.draw.y, xyC_ur
        // );

        x0 = x;
        y0 = y;
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_x = tx + xScale * (1.5 * x0 + 1);
        xyC_y = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        x0 = field.ulx(x, y);
        y0 = field.uly(x, y);
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_ulx = tx + xScale * (1.5 * x0 + 1);
        xyC_uly = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        x0 = field.upx(x, y);
        y0 = field.upy(x, y);
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_upx = tx + xScale * (1.5 * x0 + 1);
        xyC_upy = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        x0 = field.urx(x, y);
        y0 = field.ury(x, y);
        tx = info.draw.x;
        ty = info.draw.y;
        xyC_urx = tx + xScale * (1.5 * x0 + 1);
        xyC_ury = ty + yScale * (1.0 + 2.0 * y0 + (x0 < 0 ? (-x0) % 2 : x0 % 2));

        xPoints[0] = (int) (xyC_urx - 0.5 * xScale);
        yPoints[0] = (int) (xyC_ury + yScale);
        xPoints[1] = (int) (xyC_upx + 0.5 * xScale);
        yPoints[1] = (int) (xyC_upy + yScale);
        xPoints[2] = (int) (xyC_upx - 0.5 * xScale);
        yPoints[2] = (int) (xyC_upy + yScale);
        xPoints[3] = (int) (xyC_ulx + 0.5 * xScale);
        yPoints[3] = (int) (xyC_uly + yScale);
        xPoints[4] = (int) (xyC_x - 0.5 * xScale);
        yPoints[4] = (int) (xyC_y + yScale);
        xPoints[5] = (int) (xyC_x + 0.5 * xScale);
        yPoints[5] = (int) (xyC_y + yScale);

        if (graphics == null) {
          generalPath.reset();
          generalPath.moveTo(xPoints[0], yPoints[0]);
          for (int i = 1; i < 6; i++) generalPath.lineTo(xPoints[i], yPoints[i]);
          generalPath.closePath();
          Area area = new Area(generalPath);
          if (area.intersects(info.clip.x, info.clip.y, info.clip.width, info.clip.height)) {
            valueToPass.val = isDoubleGrid2D ? doubleField[x][y] : intField[x][y];
            putInHere.add(getWrapper(valueToPass.val, x, y));
          }
        } else {
          Color c = map.getColor(isDoubleGrid2D ? doubleField[x][y] : intField[x][y]);
          if (c.getAlpha() == 0) continue;
          graphics.setColor(c);

          // MacOS X 10.3 Panther has a bug which resets the clip, YUCK
          //                    graphics.setClip(clip);
          graphics.fillPolygon(xPoints, yPoints, 6);
        }
      }
  }
Example #27
0
 public int getTransparency() {
   int a1 = c1.getAlpha();
   int a2 = c2.getAlpha();
   return (((a1 & a2) == 0xff) ? OPAQUE : TRANSLUCENT);
 }
Example #28
0
 static ColorUIResource getColorTercio(Color a, Color b) {
   return new ColorUIResource(
       propInt(a.getRed(), b.getRed(), 3),
       propInt(a.getGreen(), b.getGreen(), 3),
       propInt(a.getBlue(), b.getBlue(), 3));
 }
Example #29
0
 static Color getColorMedio(Color a, Color b) {
   return new Color(
       propInt(a.getRed(), b.getRed(), 2),
       propInt(a.getGreen(), b.getGreen(), 2),
       propInt(a.getBlue(), b.getBlue(), 2));
 }
Example #30
0
 static Color getColorAlfa(Color col, int alfa) {
   return new Color(col.getRed(), col.getGreen(), col.getBlue(), alfa);
 }