List of usage examples for java.awt Color getRed
public int getRed()
From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java
private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes) throws IOException { /*//from w ww . j av a 2 s . co m * Remove NaN entries from the List */ List<Double> listWithoutNaN = new ArrayList<Double>(); for (Double d : evacuationTimes.values()) if (!d.isNaN()) listWithoutNaN.add(d); /* * If trip with significant to high evacuation times should be cut off */ if (limitMaxEvacuationTime) { double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor; ListIterator<Double> iter = listWithoutNaN.listIterator(); while (iter.hasNext()) { double value = iter.next(); if (value > cutOffValue) iter.remove(); } } double[] array = new double[listWithoutNaN.size()]; int i = 0; for (double d : listWithoutNaN) array[i++] = d; JFreeChart chart = createHistogramChart(transportMode, array); BufferedImage chartImage = chart.createBufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT); BufferedImage image = new BufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT, BufferedImage.TYPE_4BYTE_ABGR); // clone image and set alpha value for (int x = 0; x < OVERALLHISTOGRAMWIDTH; x++) { for (int y = 0; y < OVERALLHISTOGRAMHEIGHT; y++) { int rgb = chartImage.getRGB(x, y); Color c = new Color(rgb); int r = c.getRed(); int b = c.getBlue(); int g = c.getGreen(); int argb = 225 << 24 | r << 16 | g << 8 | b; // 225 as transparency value image.setRGB(x, y, argb); } } byte[] imageBytes = bufferedImageToByteArray(image); this.kmzWriter.addNonKMLFile(imageBytes, transportMode + OVERALLHISTROGRAM); ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType(); LinkType icon = kmlObjectFactory.createLinkType(); icon.setHref(transportMode + OVERALLHISTROGRAM); overlay.setIcon(icon); overlay.setName("Histogram " + transportMode); // place the image top right Vec2Type overlayXY = kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(1.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.98); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); return overlay; }
From source file:de._13ducks.cor.graphics.GraphicsComponent.java
protected void calcColoredMaps(Color[] colors) { // Berechnet die eingefrbten Texturen, z.B. fr Gebude ArrayList<CoRImage> tList = new ArrayList<CoRImage>(); tList.addAll(coloredImgMap.values()); coloredImgMap.clear();//from w w w . j a va 2s .c o m for (int i = 0; i < tList.size(); i++) { BufferedImage im = (BufferedImage) tList.get(i).getImage(); for (int playerId = 0; playerId < colors.length; playerId++) { BufferedImage preImg = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < im.getWidth(); x++) { for (int y = 0; y < im.getHeight(); y++) { // Das ganze Raster durchgehen und Farben ersetzen // Ersetzfarbe da? int rgb = im.getRGB(x, y); float[] col = Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, null); if (col[0] >= 0.8583333f && col[0] <= 0.8666666f) { // Ja, ersetzen Color tc = colors[playerId]; int targetC = Color.HSBtoRGB( Color.RGBtoHSB(tc.getRed(), tc.getGreen(), tc.getBlue(), null)[0], 1.0f, col[2]); int a = (rgb >> 24) & 0xff; targetC = (targetC & (~(0xff << 24)) | (a << 24)); preImg.setRGB(x, y, targetC); } else { preImg.setRGB(x, y, im.getRGB(x, y)); } } } // Bild berechnet, einfgen CoRImage newImg = new CoRImage(preImg); newImg.setImageName(tList.get(i).getImageName()); coloredImgMap.put(newImg.getImageName() + playerId, newImg); } } }
From source file:org.apache.fop.render.pcl.PCLGenerator.java
/** * Convert a Color value to a PCL shade value (0-100). * @param col the color//w w w. j a v a 2s.c o m * @return the PCL shade value (100=black) */ public final int convertToPCLShade(Color col) { float gray = convertToGray(col.getRed(), col.getGreen(), col.getBlue()) / 255f; return (int) (100 - (gray * 100f)); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private Component createGraphicPanel() { depthSerie = new XYSeries(DiveProfileChartFactory.SERIE_DEPTH); XYSeriesCollection depthCollection = new XYSeriesCollection(); depthCollection.addSeries(depthSerie); chart = ChartFactory.createXYAreaChart(null, getDomainLegend(), getRangeLegend(), depthCollection, PlotOrientation.VERTICAL, false, true, false); xyp = chart.getXYPlot();//from www. j a v a 2s. c o m Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f, UIAgent.getInstance().getColorWaterSurface(), false); xyp.setBackgroundPaint(p); xyp.setDomainGridlinePaint(UIAgent.getInstance().getColorWaterGrid()); xyp.setRangeGridlinePaint(UIAgent.getInstance().getColorWaterGrid()); xyp.setDomainCrosshairVisible(true); xyp.setRangeCrosshairVisible(true); xyp.setRangeCrosshairPaint(UIAgent.getInstance().getColorWaterCrossHair()); xyp.setDomainCrosshairPaint(UIAgent.getInstance().getColorWaterCrossHair()); xyp.setRangeCrosshairLockedOnData(true); xyp.setDomainCrosshairLockedOnData(true); ((NumberAxis) xyp.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat()); XYAreaRenderer renderer0 = new XYAreaRenderer(); renderer0.setOutline(true); renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorWaterBottom()); Color baseColor = UIAgent.getInstance().getColorBaseBackground(); renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50)); xyp.setRenderer(0, renderer0); createDecoWarningCollection(); createAscentTooFastCollection(); createRemainBottomTimeCollection(); createDecoEntriesCollection(); createGazMixCollection(); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(null); chartPanel.setOpaque(false); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent arg0) { } @Override public void chartMouseClicked(ChartMouseEvent evt) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { double x = xyp.getDomainCrosshairValue(); double y = xyp.getRangeCrosshairValue(); Calendar cal = new GregorianCalendar(0, 0, 0, 0, 0, (int) x); instantTimeTf.setText(new SimpleDateFormat("HH:mm:ss").format(cal.getTime())); instantDepthTf.setText(StringManipulator.formatFixedDecimalNumber(y, UIAgent.PRECISION_DEPTH, UIAgent.NUMBER_DECIMAL_CHAR)); } }); } }); return chartPanel; }
From source file:architecture.common.util.TextUtils.java
/** * Convert Color to html hex string. (#012345) * //from w w w . j av a 2 s . c o m * @param c * the Color to convert * @return A string with a hexadecimal RGB encoding */ public final static String colorToHex(java.awt.Color c) { String r = Integer.toHexString(c.getRed()); String g = Integer.toHexString(c.getGreen()); String b = Integer.toHexString(c.getBlue()); if (r.length() < 2) { r = '0' + r; } if (g.length() < 2) { g = '0' + g; } if (b.length() < 2) { b = '0' + b; } return '#' + r + g + b; }
From source file:edu.ku.brc.af.prefs.AppPreferences.java
/** * @param name/*from ww w .j av a 2s.co m*/ * @param color */ public void putColor(final String name, final Color color) { put(name, String.format("%d, %d, %d", color.getRed(), color.getGreen(), color.getBlue())); //$NON-NLS-1$ }
From source file:com.jaspersoft.studio.utils.ModelUtils.java
public static org.eclipse.swt.graphics.Color getSWTColorFromAWT(java.awt.Color awtColor) { return new org.eclipse.swt.graphics.Color(null, awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue()); }
From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java
/** * Draw a filled arc representing a single feature. The thickness and height of the arc are proportional to the * depth of coverage. Some of this gets a bit arcane -- the result of lots of visual tweaking. * * @param pixelFeatureStart the starting position of the feature, whether on-screen or not * @param pixelFeatureEnd the ending position of the feature, whether on-screen or not * @param pixelJunctionStart the starting position of the junction, whether on-screen or not * @param pixelJunctionEnd the ending position of the junction, whether on-screen or not * @param depth coverage depth * @param trackRectangle// www. java2s . c o m * @param context * @param strand * @param junctionFeature * @param shouldHighlight * @param featureColor the color specified for this feature. May be null. */ protected void drawFeature(int pixelFeatureStart, int pixelFeatureEnd, int pixelJunctionStart, int pixelJunctionEnd, float depth, Rectangle trackRectangle, RenderContext context, Strand strand, SpliceJunctionFeature junctionFeature, boolean shouldHighlight, Color featureColor, boolean shouldShowFlankingRegions) { boolean isPositiveStrand = true; // Get the feature's direction, color appropriately if (strand != null && strand.equals(Strand.NEGATIVE)) isPositiveStrand = false; //If the feature color is specified, use it, except that we set our own alpha depending on whether //the feature is highlighted. Otherwise default based on strand and highlight. Color color; if (featureColor != null) { int r = featureColor.getRed(); int g = featureColor.getGreen(); int b = featureColor.getBlue(); int alpha = shouldHighlight ? 255 : 140; color = new Color(r, g, b, alpha); } else { if (isPositiveStrand) color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS; else color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG; } Graphics2D g2D = context.getGraphic2DForColor(color); if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) { g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } //Height of top of an arc of maximum depth int maxPossibleArcHeight = (trackRectangle.height - 1) / 2; if (shouldShowFlankingRegions) { if (junctionFeature.hasFlankingRegionDepthArrays()) { //draw a wigglegram of the splice junction flanking region depth of coverage int startFlankingRegionPixelLength = pixelJunctionStart - pixelFeatureStart; int endFlankingRegionPixelLength = pixelFeatureEnd - pixelJunctionEnd; drawFlankingRegion(g2D, pixelFeatureStart, startFlankingRegionPixelLength, junctionFeature.getStartFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); drawFlankingRegion(g2D, pixelJunctionEnd + 1, endFlankingRegionPixelLength, junctionFeature.getEndFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle, isPositiveStrand); } else { //Draw rectangles indicating the overlap on each side of the junction int overlapRectHeight = 3; int overlapRectTopX = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -2 : 0); if (pixelFeatureStart < pixelJunctionStart) { g2D.fillRect(pixelFeatureStart, overlapRectTopX, pixelJunctionStart - pixelFeatureStart, overlapRectHeight); } if (pixelJunctionEnd < pixelFeatureEnd) { g2D.fillRect(pixelJunctionEnd, overlapRectTopX, pixelFeatureEnd - pixelJunctionEnd, overlapRectHeight); } } } //Create a path describing the arc, using Bezier curves. The Bezier control points for the top and //bottom arcs are based on the boundary points of the rectangles containing the arcs //proportion of the maximum arc height used by a minimum-height arc double minArcHeightProportion = 0.33; int innerArcHeight = (int) (maxPossibleArcHeight * minArcHeightProportion); float depthProportionOfMax = Math.min(1, depth / maxDepth); int arcWidth = Math.max(1, (int) ((1 - minArcHeightProportion) * maxPossibleArcHeight * depthProportionOfMax)); int outerArcHeight = innerArcHeight + arcWidth; //Height of bottom of the arc int arcBeginY = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -1 : 1); int outerArcPeakY = isPositiveStrand ? arcBeginY - outerArcHeight : arcBeginY + outerArcHeight; int innerArcPeakY = isPositiveStrand ? arcBeginY - innerArcHeight : arcBeginY + innerArcHeight; //dhmay: I don't really understand Bezier curves. For some reason I have to put the Bezier control //points farther up or down than I want the arcs to extend. This multiplier seems about right int outerBezierY = arcBeginY + (int) (1.3 * (outerArcPeakY - arcBeginY)); int innerBezierY = arcBeginY + (int) (1.3 * (innerArcPeakY - arcBeginY)); //Putting the Bezier control points slightly off to the sides of the arc int bezierXPad = Math.max(1, (pixelJunctionEnd - pixelJunctionStart) / 30); GeneralPath arcPath = new GeneralPath(); arcPath.moveTo(pixelJunctionStart, arcBeginY); arcPath.curveTo(pixelJunctionStart - bezierXPad, outerBezierY, //Bezier 1 pixelJunctionEnd + bezierXPad, outerBezierY, //Bezier 2 pixelJunctionEnd, arcBeginY); //Arc end arcPath.curveTo(pixelJunctionEnd + bezierXPad, innerBezierY, //Bezier 1 pixelJunctionStart - bezierXPad, innerBezierY, //Bezier 2 pixelJunctionStart, arcBeginY); //Arc end //Draw the arc, to ensure outline is drawn completely (fill won't do it, necessarily). This will also //give the arc a darker outline g2D.draw(arcPath); //Fill the arc g2D.fill(arcPath); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); }
From source file:org.mrgeo.colorscale.ColorScale.java
/** * Find the color band that this value falls in and assign that color. * * @param v/* w ww. jav a 2s . com*/ * @param color */ final private void absoluteValue(final double v, final int[] color) { final double search; switch (scaling) { case Absolute: search = v; break; case MinMax: search = (v - min) / (max - min); break; case Modulo: search = v % (max - min); break; default: search = 0; break; } final Map.Entry<Double, Color> lower = floorEntry(search); Color c; if (lower == null) { c = entrySet().iterator().next().getValue(); } else { c = lower.getValue(); } color[R] = c.getRed(); color[G] = c.getGreen(); color[B] = c.getBlue(); color[A] = c.getAlpha(); }
From source file:org.kurento.test.base.BrowserTest.java
public String ocr(BufferedImage imgBuff) { String parsedOut = null;/*from ww w . j a v a2 s . c o m*/ try { // Color image to pure black and white for (int x = 0; x < imgBuff.getWidth(); x++) { for (int y = 0; y < imgBuff.getHeight(); y++) { Color color = new Color(imgBuff.getRGB(x, y)); int red = color.getRed(); int green = color.getBlue(); int blue = color.getGreen(); if (red + green + blue > OCR_COLOR_THRESHOLD) { red = green = blue = 0; // Black } else { red = green = blue = 255; // White } Color col = new Color(red, green, blue); imgBuff.setRGB(x, y, col.getRGB()); } } // OCR recognition ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(imgBuff, "png", baos); byte[] imageBytes = baos.toByteArray(); TessBaseAPI api = new TessBaseAPI(); api.Init(null, "eng"); ByteBuffer imgBB = ByteBuffer.wrap(imageBytes); PIX image = pixReadMem(imgBB, imageBytes.length); api.SetImage(image); // Get OCR result BytePointer outText = api.GetUTF8Text(); // Destroy used object and release memory api.End(); api.close(); outText.deallocate(); pixDestroy(image); // OCR corrections parsedOut = outText.getString().replaceAll("l", "1").replaceAll("Z", "2").replaceAll("O", "0") .replaceAll("B", "8").replaceAll("G", "6").replaceAll("S", "8").replaceAll("'", "") .replaceAll("", "").replaceAll("\\.", ":").replaceAll("E", "8").replaceAll("o", "0") .replaceAll("", "0").replaceAll("?", "6").replaceAll("", "5").replaceAll("I", "1") .replaceAll("T", "7").replaceAll("", "").replaceAll("U", "0").replaceAll("D", "0"); if (parsedOut.length() > 7) { parsedOut = parsedOut.substring(0, 7) + ":" + parsedOut.substring(8, parsedOut.length()); } parsedOut = parsedOut.replaceAll("::", ":"); // Remove last part (number of frames) int iSpace = parsedOut.lastIndexOf(" "); if (iSpace != -1) { parsedOut = parsedOut.substring(0, iSpace); } } catch (IOException e) { log.warn("IOException in OCR", e); } return parsedOut; }