Java Code Examples for java.awt.geom.AffineTransform#getTranslateX()
The following examples show how to use
java.awt.geom.AffineTransform#getTranslateX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerspectiveTransform.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
/** * Sets this transform to a given AffineTransform. * * @throws IllegalArgumentException if Tx is null */ public void setTransform(AffineTransform Tx) { if (Tx == null) { throw new IllegalArgumentException(JaiI18N.getString("Generic0")); } m00 = Tx.getScaleX(); m01 = Tx.getShearX(); m02 = Tx.getTranslateX(); m10 = Tx.getShearY(); m11 = Tx.getScaleY(); m12 = Tx.getTranslateY(); m20 = 0.0; m21 = 0.0; m22 = 1.0; }
Example 2
Source File: PerspectiveTransform.java From pumpernickel with MIT License | 6 votes |
/** * Constructs a new PerspectiveTransform with the same effect as an existing * AffineTransform. * * @throws IllegalArgumentException * if transform is null */ public PerspectiveTransform(AffineTransform transform) { if (transform == null) { throw new IllegalArgumentException(JaiI18N.getString("Generic0")); } m00 = transform.getScaleX(); m01 = transform.getShearX(); m02 = transform.getTranslateX(); m10 = transform.getShearY(); m11 = transform.getScaleY(); m12 = transform.getTranslateY(); m20 = 0.0; m21 = 0.0; m22 = 1.0; }
Example 3
Source File: AttributeValues.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private static AffineTransform extractRotation(Point2D.Double pt, AffineTransform tx, boolean andTranslation) { tx.deltaTransform(pt, pt); AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y); try { AffineTransform rtxi = rtx.createInverse(); double dx = tx.getTranslateX(); double dy = tx.getTranslateY(); tx.preConcatenate(rtxi); if (andTranslation) { if (dx != 0 || dy != 0) { tx.setTransform(tx.getScaleX(), tx.getShearY(), tx.getShearX(), tx.getScaleY(), 0, 0); rtx.setTransform(rtx.getScaleX(), rtx.getShearY(), rtx.getShearX(), rtx.getScaleY(), dx, dy); } } } catch (NoninvertibleTransformException e) { return null; } return rtx; }
Example 4
Source File: Font2D.java From Bytecoder with Apache License 2.0 | 6 votes |
public FontStrike getStrike(Font font, FontRenderContext frc) { AffineTransform at = frc.getTransform(); double ptSize = font.getSize2D(); at.scale(ptSize, ptSize); if (font.isTransformed()) { at.concatenate(font.getTransform()); if (at.getTranslateX() != 0 || at.getTranslateY() != 0) { at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), 0.0, 0.0); } } int aa = FontStrikeDesc.getAAHintIntVal(this, font, frc); int fm = FontStrikeDesc.getFMHintIntVal(frc.getFractionalMetricsHint()); FontStrikeDesc desc = new FontStrikeDesc(frc.getTransform(), at, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 5
Source File: AttributeValues.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static AffineTransform extractRotation(Point2D.Double pt, AffineTransform tx, boolean andTranslation) { tx.deltaTransform(pt, pt); AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y); try { AffineTransform rtxi = rtx.createInverse(); double dx = tx.getTranslateX(); double dy = tx.getTranslateY(); tx.preConcatenate(rtxi); if (andTranslation) { if (dx != 0 || dy != 0) { tx.setTransform(tx.getScaleX(), tx.getShearY(), tx.getShearX(), tx.getScaleY(), 0, 0); rtx.setTransform(rtx.getScaleX(), rtx.getShearY(), rtx.getShearX(), rtx.getScaleY(), dx, dy); } } } catch (NoninvertibleTransformException e) { return null; } return rtx; }
Example 6
Source File: PixelToParallelogramConverter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void fillRectangle(SunGraphics2D sg2d, double rx, double ry, double rw, double rh) { double px, py; double dx1, dy1, dx2, dy2; AffineTransform txform = sg2d.transform; dx1 = txform.getScaleX(); dy1 = txform.getShearY(); dx2 = txform.getShearX(); dy2 = txform.getScaleY(); px = rx * dx1 + ry * dx2 + txform.getTranslateX(); py = rx * dy1 + ry * dy2 + txform.getTranslateY(); dx1 *= rw; dy1 *= rw; dx2 *= rh; dy2 *= rh; if (adjustfill && sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM && sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE) { double newx = normalize(px); double newy = normalize(py); dx1 = normalize(px + dx1) - newx; dy1 = normalize(py + dy1) - newy; dx2 = normalize(px + dx2) - newx; dy2 = normalize(py + dy2) - newy; px = newx; py = newy; } outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh, px, py, dx1, dy1, dx2, dy2); }
Example 7
Source File: SunGraphics2D.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Returns true if the given AffineTransform is an integer * translation. */ private static boolean isIntegerTranslation(AffineTransform xform) { if (xform.isIdentity()) { return true; } if (xform.getType() == AffineTransform.TYPE_TRANSLATION) { double tx = xform.getTranslateX(); double ty = xform.getTranslateY(); return (tx == (int)tx && ty == (int)ty); } return false; }
Example 8
Source File: Font2D.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm) { /* Create the descriptor which is used to identify a strike * in the strike cache/map. A strike is fully described by * the attributes of this descriptor. */ /* REMIND: generating garbage and doing computation here in order * to include pt size in the tx just for a lookup! Figure out a * better way. */ double ptSize = font.getSize2D(); AffineTransform glyphTx = (AffineTransform)devTx.clone(); glyphTx.scale(ptSize, ptSize); if (font.isTransformed()) { glyphTx.concatenate(font.getTransform()); } if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) { glyphTx.setTransform(glyphTx.getScaleX(), glyphTx.getShearY(), glyphTx.getShearX(), glyphTx.getScaleY(), 0.0, 0.0); } FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 9
Source File: TransformingPathConsumer2D.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static PathConsumer2D transformConsumer(PathConsumer2D out, AffineTransform at) { if (at == null) { return out; } float Mxx = (float) at.getScaleX(); float Mxy = (float) at.getShearX(); float Mxt = (float) at.getTranslateX(); float Myx = (float) at.getShearY(); float Myy = (float) at.getScaleY(); float Myt = (float) at.getTranslateY(); if (Mxy == 0f && Myx == 0f) { if (Mxx == 1f && Myy == 1f) { if (Mxt == 0f && Myt == 0f) { return out; } else { return new TranslateFilter(out, Mxt, Myt); } } else { if (Mxt == 0f && Myt == 0f) { return new DeltaScaleFilter(out, Mxx, Myy); } else { return new ScaleFilter(out, Mxx, Myy, Mxt, Myt); } } } else if (Mxt == 0f && Myt == 0f) { return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy); } else { return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt); } }
Example 10
Source File: TexturePaintContext.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
TexturePaintContext(ColorModel cm, AffineTransform xform, int bWidth, int bHeight, int maxw) { this.colorModel = getInternedColorModel(cm); this.bWidth = bWidth; this.bHeight = bHeight; this.maxWidth = maxw; try { xform = xform.createInverse(); } catch (NoninvertibleTransformException e) { xform.setToScale(0, 0); } this.incXAcross = mod(xform.getScaleX(), bWidth); this.incYAcross = mod(xform.getShearY(), bHeight); this.incXDown = mod(xform.getShearX(), bWidth); this.incYDown = mod(xform.getScaleY(), bHeight); this.xOrg = xform.getTranslateX(); this.yOrg = xform.getTranslateY(); this.colincx = (int) incXAcross; this.colincy = (int) incYAcross; this.colincxerr = fractAsInt(incXAcross); this.colincyerr = fractAsInt(incYAcross); this.rowincx = (int) incXDown; this.rowincy = (int) incYDown; this.rowincxerr = fractAsInt(incXDown); this.rowincyerr = fractAsInt(incYDown); }
Example 11
Source File: Font2D.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm) { /* Create the descriptor which is used to identify a strike * in the strike cache/map. A strike is fully described by * the attributes of this descriptor. */ /* REMIND: generating garbage and doing computation here in order * to include pt size in the tx just for a lookup! Figure out a * better way. */ double ptSize = font.getSize2D(); AffineTransform glyphTx = (AffineTransform)devTx.clone(); glyphTx.scale(ptSize, ptSize); if (font.isTransformed()) { glyphTx.concatenate(font.getTransform()); } if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) { glyphTx.setTransform(glyphTx.getScaleX(), glyphTx.getShearY(), glyphTx.getShearX(), glyphTx.getScaleY(), 0.0, 0.0); } FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 12
Source File: SunGraphics2D.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns true if the given AffineTransform is an integer * translation. */ private static boolean isIntegerTranslation(AffineTransform xform) { if (xform.isIdentity()) { return true; } if (xform.getType() == AffineTransform.TYPE_TRANSLATION) { double tx = xform.getTranslateX(); double ty = xform.getTranslateY(); return (tx == (int)tx && ty == (int)ty); } return false; }
Example 13
Source File: PixelToParallelogramConverter.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public void drawRectangle(SunGraphics2D sg2d, double rx, double ry, double rw, double rh, double lw) { double px, py; double dx1, dy1, dx2, dy2; double lw1, lw2; AffineTransform txform = sg2d.transform; dx1 = txform.getScaleX(); dy1 = txform.getShearY(); dx2 = txform.getShearX(); dy2 = txform.getScaleY(); px = rx * dx1 + ry * dx2 + txform.getTranslateX(); py = rx * dy1 + ry * dy2 + txform.getTranslateY(); // lw along dx1,dy1 scale by transformed length of dx2,dy2 vectors // and vice versa lw1 = len(dx1, dy1) * lw; lw2 = len(dx2, dy2) * lw; dx1 *= rw; dy1 *= rw; dx2 *= rh; dy2 *= rh; if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM && sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE) { double newx = normalize(px); double newy = normalize(py); dx1 = normalize(px + dx1) - newx; dy1 = normalize(py + dy1) - newy; dx2 = normalize(px + dx2) - newx; dy2 = normalize(py + dy2) - newy; px = newx; py = newy; } lw1 = Math.max(lw1, minPenSize); lw2 = Math.max(lw2, minPenSize); double len1 = len(dx1, dy1); double len2 = len(dx2, dy2); if (lw1 >= len1 || lw2 >= len2) { // The line widths are large enough to consume the // entire hole in the middle of the parallelogram // so we can just fill the outer parallelogram. fillOuterParallelogram(sg2d, rx, ry, rx+rw, ry+rh, px, py, dx1, dy1, dx2, dy2, len1, len2, lw1, lw2); } else { outrenderer.drawParallelogram(sg2d, rx, ry, rx+rw, ry+rh, px, py, dx1, dy1, dx2, dy2, lw1 / len1, lw2 / len2); } }
Example 14
Source File: PSPathGraphics.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
protected void drawString(String str, float x, float y, Font font, FontRenderContext frc, float w) { if (str.length() == 0) { return; } /* If the Font has layout attributes we need to delegate to TextLayout. * TextLayout renders text as GlyphVectors. We try to print those * using printer fonts - ie using Postscript text operators so * we may be reinvoked. In that case the "!printingGlyphVector" test * prevents us recursing and instead sends us into the body of the * method where we can safely ignore layout attributes as those * are already handled by TextLayout. */ if (font.hasLayoutAttributes() && !printingGlyphVector) { TextLayout layout = new TextLayout(str, font, frc); layout.draw(this, x, y); return; } Font oldFont = getFont(); if (!oldFont.equals(font)) { setFont(font); } else { oldFont = null; } boolean drawnWithPS = false; float translateX = 0f, translateY = 0f; boolean fontisTransformed = getFont().isTransformed(); if (fontisTransformed) { AffineTransform fontTx = getFont().getTransform(); int transformType = fontTx.getType(); /* TYPE_TRANSLATION is a flag bit but we can do "==" here * because we want to detect when its just that bit set and * */ if (transformType == AffineTransform.TYPE_TRANSLATION) { translateX = (float)(fontTx.getTranslateX()); translateY = (float)(fontTx.getTranslateY()); if (Math.abs(translateX) < 0.00001) translateX = 0f; if (Math.abs(translateY) < 0.00001) translateY = 0f; fontisTransformed = false; } } boolean directToPS = !fontisTransformed; if (!PSPrinterJob.shapeTextProp && directToPS) { PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob(); if (psPrinterJob.setFont(getFont())) { /* Set the text color. * We should not be in this shape printing path * if the application is drawing with non-solid * colors. We should be in the raster path. Because * we are here in the shape path, the cast of the * paint to a Color should be fine. */ try { psPrinterJob.setColor((Color)getPaint()); } catch (ClassCastException e) { if (oldFont != null) { setFont(oldFont); } throw new IllegalArgumentException( "Expected a Color instance"); } psPrinterJob.setTransform(getTransform()); psPrinterJob.setClip(getClip()); drawnWithPS = psPrinterJob.textOut(this, str, x+translateX, y+translateY, font, frc, w); } } /* The text could not be converted directly to PS text * calls so decompose the text into a shape. */ if (drawnWithPS == false) { if (oldFont != null) { setFont(oldFont); oldFont = null; } super.drawString(str, x, y, font, frc, w); } if (oldFont != null) { setFont(oldFont); } }
Example 15
Source File: PSPathGraphics.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
protected void drawString(String str, float x, float y, Font font, FontRenderContext frc, float w) { if (str.length() == 0) { return; } /* If the Font has layout attributes we need to delegate to TextLayout. * TextLayout renders text as GlyphVectors. We try to print those * using printer fonts - ie using Postscript text operators so * we may be reinvoked. In that case the "!printingGlyphVector" test * prevents us recursing and instead sends us into the body of the * method where we can safely ignore layout attributes as those * are already handled by TextLayout. */ if (font.hasLayoutAttributes() && !printingGlyphVector) { TextLayout layout = new TextLayout(str, font, frc); layout.draw(this, x, y); return; } Font oldFont = getFont(); if (!oldFont.equals(font)) { setFont(font); } else { oldFont = null; } boolean drawnWithPS = false; float translateX = 0f, translateY = 0f; boolean fontisTransformed = getFont().isTransformed(); if (fontisTransformed) { AffineTransform fontTx = getFont().getTransform(); int transformType = fontTx.getType(); /* TYPE_TRANSLATION is a flag bit but we can do "==" here * because we want to detect when its just that bit set and * */ if (transformType == AffineTransform.TYPE_TRANSLATION) { translateX = (float)(fontTx.getTranslateX()); translateY = (float)(fontTx.getTranslateY()); if (Math.abs(translateX) < 0.00001) translateX = 0f; if (Math.abs(translateY) < 0.00001) translateY = 0f; fontisTransformed = false; } } boolean directToPS = !fontisTransformed; if (!PSPrinterJob.shapeTextProp && directToPS) { PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob(); if (psPrinterJob.setFont(getFont())) { /* Set the text color. * We should not be in this shape printing path * if the application is drawing with non-solid * colors. We should be in the raster path. Because * we are here in the shape path, the cast of the * paint to a Color should be fine. */ try { psPrinterJob.setColor((Color)getPaint()); } catch (ClassCastException e) { if (oldFont != null) { setFont(oldFont); } throw new IllegalArgumentException( "Expected a Color instance"); } psPrinterJob.setTransform(getTransform()); psPrinterJob.setClip(getClip()); drawnWithPS = psPrinterJob.textOut(this, str, x+translateX, y+translateY, font, frc, w); } } /* The text could not be converted directly to PS text * calls so decompose the text into a shape. */ if (drawnWithPS == false) { if (oldFont != null) { setFont(oldFont); oldFont = null; } super.drawString(str, x, y, font, frc, w); } if (oldFont != null) { setFont(oldFont); } }
Example 16
Source File: PSPathGraphics.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
protected void drawString(String str, float x, float y, Font font, FontRenderContext frc, float w) { if (str.length() == 0) { return; } /* If the Font has layout attributes we need to delegate to TextLayout. * TextLayout renders text as GlyphVectors. We try to print those * using printer fonts - ie using Postscript text operators so * we may be reinvoked. In that case the "!printingGlyphVector" test * prevents us recursing and instead sends us into the body of the * method where we can safely ignore layout attributes as those * are already handled by TextLayout. */ if (font.hasLayoutAttributes() && !printingGlyphVector) { TextLayout layout = new TextLayout(str, font, frc); layout.draw(this, x, y); return; } Font oldFont = getFont(); if (!oldFont.equals(font)) { setFont(font); } else { oldFont = null; } boolean drawnWithPS = false; float translateX = 0f, translateY = 0f; boolean fontisTransformed = getFont().isTransformed(); if (fontisTransformed) { AffineTransform fontTx = getFont().getTransform(); int transformType = fontTx.getType(); /* TYPE_TRANSLATION is a flag bit but we can do "==" here * because we want to detect when its just that bit set and * */ if (transformType == AffineTransform.TYPE_TRANSLATION) { translateX = (float)(fontTx.getTranslateX()); translateY = (float)(fontTx.getTranslateY()); if (Math.abs(translateX) < 0.00001) translateX = 0f; if (Math.abs(translateY) < 0.00001) translateY = 0f; fontisTransformed = false; } } boolean directToPS = !fontisTransformed; if (!PSPrinterJob.shapeTextProp && directToPS) { PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob(); if (psPrinterJob.setFont(getFont())) { /* Set the text color. * We should not be in this shape printing path * if the application is drawing with non-solid * colors. We should be in the raster path. Because * we are here in the shape path, the cast of the * paint to a Color should be fine. */ try { psPrinterJob.setColor((Color)getPaint()); } catch (ClassCastException e) { if (oldFont != null) { setFont(oldFont); } throw new IllegalArgumentException( "Expected a Color instance"); } psPrinterJob.setTransform(getTransform()); psPrinterJob.setClip(getClip()); drawnWithPS = psPrinterJob.textOut(this, str, x+translateX, y+translateY, font, frc, w); } } /* The text could not be converted directly to PS text * calls so decompose the text into a shape. */ if (drawnWithPS == false) { if (oldFont != null) { setFont(oldFont); oldFont = null; } super.drawString(str, x, y, font, frc, w); } if (oldFont != null) { setFont(oldFont); } }
Example 17
Source File: PSPathGraphics.java From Bytecoder with Apache License 2.0 | 4 votes |
protected void drawString(String str, float x, float y, Font font, FontRenderContext frc, float w) { if (str.length() == 0) { return; } /* If the Font has layout attributes we need to delegate to TextLayout. * TextLayout renders text as GlyphVectors. We try to print those * using printer fonts - ie using Postscript text operators so * we may be reinvoked. In that case the "!printingGlyphVector" test * prevents us recursing and instead sends us into the body of the * method where we can safely ignore layout attributes as those * are already handled by TextLayout. */ if (font.hasLayoutAttributes() && !printingGlyphVector) { TextLayout layout = new TextLayout(str, font, frc); layout.draw(this, x, y); return; } Font oldFont = getFont(); if (!oldFont.equals(font)) { setFont(font); } else { oldFont = null; } boolean drawnWithPS = false; float translateX = 0f, translateY = 0f; boolean fontisTransformed = getFont().isTransformed(); if (fontisTransformed) { AffineTransform fontTx = getFont().getTransform(); int transformType = fontTx.getType(); /* TYPE_TRANSLATION is a flag bit but we can do "==" here * because we want to detect when its just that bit set and * */ if (transformType == AffineTransform.TYPE_TRANSLATION) { translateX = (float)(fontTx.getTranslateX()); translateY = (float)(fontTx.getTranslateY()); if (Math.abs(translateX) < 0.00001) translateX = 0f; if (Math.abs(translateY) < 0.00001) translateY = 0f; fontisTransformed = false; } } boolean directToPS = !fontisTransformed; if (!PSPrinterJob.shapeTextProp && directToPS) { PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob(); if (psPrinterJob.setFont(getFont())) { /* Set the text color. * We should not be in this shape printing path * if the application is drawing with non-solid * colors. We should be in the raster path. Because * we are here in the shape path, the cast of the * paint to a Color should be fine. */ try { psPrinterJob.setColor((Color)getPaint()); } catch (ClassCastException e) { if (oldFont != null) { setFont(oldFont); } throw new IllegalArgumentException( "Expected a Color instance"); } psPrinterJob.setTransform(getTransform()); psPrinterJob.setClip(getClip()); drawnWithPS = psPrinterJob.textOut(this, str, x+translateX, y+translateY, font, frc, w); } } /* The text could not be converted directly to PS text * calls so decompose the text into a shape. */ if (drawnWithPS == false) { if (oldFont != null) { setFont(oldFont); oldFont = null; } super.drawString(str, x, y, font, frc, w); } if (oldFont != null) { setFont(oldFont); } }
Example 18
Source File: BufferedPaints.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * We use OpenGL's texture coordinate generator to automatically * map the TexturePaint image to the geometry being rendered. The * generator uses two separate plane equations that take the (x,y) * location (in device space) of the fragment being rendered to * calculate (u,v) texture coordinates for that fragment: * u = Ax + By + Cz + Dw * v = Ex + Fy + Gz + Hw * * Since we use a 2D orthographic projection, we can assume that z=0 * and w=1 for any fragment. So we need to calculate appropriate * values for the plane equation constants (A,B,D) and (E,F,H) such * that {u,v}=0 for the top-left of the TexturePaint's anchor * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle. * We can easily make the texture image repeat for {u,v} values * outside the range [0,1] by specifying the GL_REPEAT texture wrap * mode. * * Calculating the plane equation constants is surprisingly simple. * We can think of it as an inverse matrix operation that takes * device space coordinates and transforms them into user space * coordinates that correspond to a location relative to the anchor * rectangle. First, we translate and scale the current user space * transform by applying the anchor rectangle bounds. We then take * the inverse of this affine transform. The rows of the resulting * inverse matrix correlate nicely to the plane equation constants * we were seeking. */ private static void setTexturePaint(RenderQueue rq, SunGraphics2D sg2d, TexturePaint paint, boolean useMask) { BufferedImage bi = paint.getImage(); SurfaceData dstData = sg2d.surfaceData; SurfaceData srcData = dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null); boolean filter = (sg2d.interpolationType != AffineTransformOp.TYPE_NEAREST_NEIGHBOR); // calculate plane equation constants AffineTransform at = (AffineTransform)sg2d.transform.clone(); Rectangle2D anchor = paint.getAnchorRect(); at.translate(anchor.getX(), anchor.getY()); at.scale(anchor.getWidth(), anchor.getHeight()); double xp0, xp1, xp3, yp0, yp1, yp3; try { at.invert(); xp0 = at.getScaleX(); xp1 = at.getShearX(); xp3 = at.getTranslateX(); yp0 = at.getShearY(); yp1 = at.getScaleY(); yp3 = at.getTranslateY(); } catch (java.awt.geom.NoninvertibleTransformException e) { xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0; } // assert rq.lock.isHeldByCurrentThread(); rq.ensureCapacityAndAlignment(68, 12); RenderBuffer buf = rq.getBuffer(); buf.putInt(SET_TEXTURE_PAINT); buf.putInt(useMask ? 1 : 0); buf.putInt(filter ? 1 : 0); buf.putLong(srcData.getNativeOps()); buf.putDouble(xp0).putDouble(xp1).putDouble(xp3); buf.putDouble(yp0).putDouble(yp1).putDouble(yp3); }
Example 19
Source File: BufferedPaints.java From dragonwell8_jdk with GNU General Public License v2.0 | 2 votes |
/** * Note: This code is factored out into a separate static method * so that it can be shared by both the Gradient and LinearGradient * implementations. LinearGradient uses this code (for the * two-color sRGB case only) because it can be much faster than the * equivalent implementation that uses fragment shaders. * * We use OpenGL's texture coordinate generator to automatically * apply a smooth gradient (either cyclic or acyclic) to the geometry * being rendered. This technique is almost identical to the one * described in the comments for BufferedPaints.setTexturePaint(), * except the calculations take place in one dimension instead of two. * Instead of an anchor rectangle in the TexturePaint case, we use * the vector between the two GradientPaint end points in our * calculations. The generator uses a single plane equation that * takes the (x,y) location (in device space) of the fragment being * rendered to calculate a (u) texture coordinate for that fragment: * u = Ax + By + Cz + Dw * * The gradient renderer uses a two-pixel 1D texture where the first * pixel contains the first GradientPaint color, and the second pixel * contains the second GradientPaint color. (Note that we use the * GL_CLAMP_TO_EDGE wrapping mode for acyclic gradients so that we * clamp the colors properly at the extremes.) The following diagram * attempts to show the layout of the texture containing the two * GradientPaint colors (C1 and C2): * * +-----------------+ * | C1 | C2 | * | | | * +-----------------+ * u=0 .25 .5 .75 1 * * We calculate our plane equation constants (A,B,D) such that u=0.25 * corresponds to the first GradientPaint end point in user space and * u=0.75 corresponds to the second end point. This is somewhat * non-obvious, but since the gradient colors are generated by * interpolating between C1 and C2, we want the pure color at the * end points, and we will get the pure color only when u correlates * to the center of a texel. The following chart shows the expected * color for some sample values of u (where C' is the color halfway * between C1 and C2): * * u value acyclic (GL_CLAMP) cyclic (GL_REPEAT) * ------- ------------------ ------------------ * -0.25 C1 C2 * 0.0 C1 C' * 0.25 C1 C1 * 0.5 C' C' * 0.75 C2 C2 * 1.0 C2 C' * 1.25 C2 C1 * * Original inspiration for this technique came from UMD's Agile2D * project (GradientManager.java). */ private static void setGradientPaint(RenderQueue rq, AffineTransform at, Color c1, Color c2, Point2D pt1, Point2D pt2, boolean isCyclic, boolean useMask) { // convert gradient colors to IntArgbPre format PixelConverter pc = PixelConverter.ArgbPre.instance; int pixel1 = pc.rgbToPixel(c1.getRGB(), null); int pixel2 = pc.rgbToPixel(c2.getRGB(), null); // calculate plane equation constants double x = pt1.getX(); double y = pt1.getY(); at.translate(x, y); // now gradient point 1 is at the origin x = pt2.getX() - x; y = pt2.getY() - y; double len = Math.sqrt(x * x + y * y); at.rotate(x, y); // now gradient point 2 is on the positive x-axis at.scale(2*len, 1); // now gradient point 2 is at (0.5, 0) at.translate(-0.25, 0); // now gradient point 1 is at (0.25, 0), point 2 is at (0.75, 0) double p0, p1, p3; try { at.invert(); p0 = at.getScaleX(); p1 = at.getShearX(); p3 = at.getTranslateX(); } catch (java.awt.geom.NoninvertibleTransformException e) { p0 = p1 = p3 = 0.0; } // assert rq.lock.isHeldByCurrentThread(); rq.ensureCapacityAndAlignment(44, 12); RenderBuffer buf = rq.getBuffer(); buf.putInt(SET_GRADIENT_PAINT); buf.putInt(useMask ? 1 : 0); buf.putInt(isCyclic ? 1 : 0); buf.putDouble(p0).putDouble(p1).putDouble(p3); buf.putInt(pixel1).putInt(pixel2); }
Example 20
Source File: BufferedPaints.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * Note: This code is factored out into a separate static method * so that it can be shared by both the Gradient and LinearGradient * implementations. LinearGradient uses this code (for the * two-color sRGB case only) because it can be much faster than the * equivalent implementation that uses fragment shaders. * * We use OpenGL's texture coordinate generator to automatically * apply a smooth gradient (either cyclic or acyclic) to the geometry * being rendered. This technique is almost identical to the one * described in the comments for BufferedPaints.setTexturePaint(), * except the calculations take place in one dimension instead of two. * Instead of an anchor rectangle in the TexturePaint case, we use * the vector between the two GradientPaint end points in our * calculations. The generator uses a single plane equation that * takes the (x,y) location (in device space) of the fragment being * rendered to calculate a (u) texture coordinate for that fragment: * u = Ax + By + Cz + Dw * * The gradient renderer uses a two-pixel 1D texture where the first * pixel contains the first GradientPaint color, and the second pixel * contains the second GradientPaint color. (Note that we use the * GL_CLAMP_TO_EDGE wrapping mode for acyclic gradients so that we * clamp the colors properly at the extremes.) The following diagram * attempts to show the layout of the texture containing the two * GradientPaint colors (C1 and C2): * * +-----------------+ * | C1 | C2 | * | | | * +-----------------+ * u=0 .25 .5 .75 1 * * We calculate our plane equation constants (A,B,D) such that u=0.25 * corresponds to the first GradientPaint end point in user space and * u=0.75 corresponds to the second end point. This is somewhat * non-obvious, but since the gradient colors are generated by * interpolating between C1 and C2, we want the pure color at the * end points, and we will get the pure color only when u correlates * to the center of a texel. The following chart shows the expected * color for some sample values of u (where C' is the color halfway * between C1 and C2): * * u value acyclic (GL_CLAMP) cyclic (GL_REPEAT) * ------- ------------------ ------------------ * -0.25 C1 C2 * 0.0 C1 C' * 0.25 C1 C1 * 0.5 C' C' * 0.75 C2 C2 * 1.0 C2 C' * 1.25 C2 C1 * * Original inspiration for this technique came from UMD's Agile2D * project (GradientManager.java). */ private static void setGradientPaint(RenderQueue rq, AffineTransform at, Color c1, Color c2, Point2D pt1, Point2D pt2, boolean isCyclic, boolean useMask) { // convert gradient colors to IntArgbPre format PixelConverter pc = PixelConverter.ArgbPre.instance; int pixel1 = pc.rgbToPixel(c1.getRGB(), null); int pixel2 = pc.rgbToPixel(c2.getRGB(), null); // calculate plane equation constants double x = pt1.getX(); double y = pt1.getY(); at.translate(x, y); // now gradient point 1 is at the origin x = pt2.getX() - x; y = pt2.getY() - y; double len = Math.sqrt(x * x + y * y); at.rotate(x, y); // now gradient point 2 is on the positive x-axis at.scale(2*len, 1); // now gradient point 2 is at (0.5, 0) at.translate(-0.25, 0); // now gradient point 1 is at (0.25, 0), point 2 is at (0.75, 0) double p0, p1, p3; try { at.invert(); p0 = at.getScaleX(); p1 = at.getShearX(); p3 = at.getTranslateX(); } catch (java.awt.geom.NoninvertibleTransformException e) { p0 = p1 = p3 = 0.0; } // assert rq.lock.isHeldByCurrentThread(); rq.ensureCapacityAndAlignment(44, 12); RenderBuffer buf = rq.getBuffer(); buf.putInt(SET_GRADIENT_PAINT); buf.putInt(useMask ? 1 : 0); buf.putInt(isCyclic ? 1 : 0); buf.putDouble(p0).putDouble(p1).putDouble(p3); buf.putInt(pixel1).putInt(pixel2); }