use of java.awt.geom.NoninvertibleTransformException in project jdk8u_jdk by JetBrains.
the class ProxyGraphics2D method drawRenderableImage.
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
if (img == null) {
return;
}
AffineTransform pipeTransform = getTransform();
AffineTransform concatTransform = new AffineTransform(xform);
concatTransform.concatenate(pipeTransform);
AffineTransform reverseTransform;
RenderContext rc = new RenderContext(concatTransform);
try {
reverseTransform = pipeTransform.createInverse();
} catch (NoninvertibleTransformException nte) {
rc = new RenderContext(pipeTransform);
reverseTransform = new AffineTransform();
}
RenderedImage rendering = img.createRendering(rc);
drawRenderedImage(rendering, reverseTransform);
}
use of java.awt.geom.NoninvertibleTransformException in project gephi by gephi.
the class GradientSliderUI method paintTrack.
@Override
protected void paintTrack(Graphics2D g) {
Composite oldComposite = g.getComposite();
float alpha = slider.isEnabled() ? 1 : .5f;
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
Shape frame = getFrame();
boolean alwaysOpaque = getProperty(slider, "GradientSlider.showTranslucency", "true").equals("false");
if (alwaysOpaque == false) {
if (checkerPaint == null) {
createCheckerPaint();
}
g.setPaint(checkerPaint);
g.fill(frame);
}
TexturePaint tp = new TexturePaint(img, new Rectangle(trackRect.x, 0, img.getWidth(), 1));
g.setPaint(tp);
AffineTransform oldTransform = null;
oldTransform = g.getTransform();
AffineTransform transform = new AffineTransform();
if (slider.getOrientation() == GradientSlider.VERTICAL) {
if (slider.isInverted()) {
transform.rotate(Math.PI / 2, trackRect.x, trackRect.y);
} else {
transform.rotate(-Math.PI / 2, trackRect.x, trackRect.y + trackRect.height);
}
} else if (slider.isInverted()) {
//flip horizontal:
double x1 = trackRect.x;
double x2 = trackRect.x + trackRect.width;
//m00*x1+m02 = x2
//m00*x2+m02 = x1
double m00 = (x2 - x1) / (x1 - x2);
double m02 = x1 - m00 * x2;
transform.setTransform(m00, 0, 0, 1, m02, 0);
} else {
//no transform necessary
}
g.transform(transform);
try {
g.fill(transform.createInverse().createTransformedShape(trackRect));
} catch (NoninvertibleTransformException e) {
//this won't happen; unless a width/height
//is zero somewhere, in which case we have nothing to paint anyway.
}
if (oldTransform != null) {
g.setTransform(oldTransform);
}
if (getProperty(slider, "GradientSlider.useBevel", "false").equals("true")) {
PaintUtils.drawBevel(g, trackRect);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Shape oldClip = g.getClip();
int first, last;
Color[] colors = ((GradientSlider) slider).getColors();
float[] f = slider.getThumbPositions();
if ((slider.isInverted() == false && slider.getOrientation() == GradientSlider.HORIZONTAL) || (slider.isInverted() == true && slider.getOrientation() == GradientSlider.VERTICAL)) {
first = 0;
last = colors.length - 1;
while (f[first] < 0) {
first++;
}
while (f[last] > 1) {
last--;
}
} else {
last = 0;
first = colors.length - 1;
while (f[last] < 0) {
last++;
}
while (f[first] > 1) {
first--;
}
}
if (slider.getOrientation() == GradientSlider.HORIZONTAL) {
g.clip(frame);
g.setColor(colors[first]);
g.fillRect(0, 0, trackRect.x, slider.getHeight());
g.setColor(colors[last]);
g.fillRect(trackRect.x + trackRect.width, 0, slider.getWidth() - (trackRect.x + trackRect.width), slider.getHeight());
} else {
g.clip(frame);
g.setColor(colors[first]);
g.fillRect(0, 0, slider.getWidth(), trackRect.y);
g.setColor(colors[last]);
g.fillRect(0, trackRect.y + trackRect.height, slider.getWidth(), slider.getHeight() - (trackRect.y + trackRect.height));
}
g.setStroke(new BasicStroke(1));
g.setClip(oldClip);
g.setColor(new Color(0, 0, 0, 130));
g.draw(frame);
g.setColor(new Color(0, 0, 0, 130));
}
if (slider.isPaintTicks()) {
paintTick(g, .25f, 2);
paintTick(g, .5f, 2);
paintTick(g, .75f, 2);
paintTick(g, 0f, 2);
paintTick(g, 1f, 2);
}
g.setComposite(oldComposite);
}
use of java.awt.geom.NoninvertibleTransformException in project platform_frameworks_base by android.
the class Matrix_Delegate method native_invert.
@LayoutlibDelegate
static /*package*/
boolean native_invert(long native_object, long inverse) {
Matrix_Delegate d = sManager.getDelegate(native_object);
if (d == null) {
return false;
}
Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
if (inv_mtx == null) {
return false;
}
try {
AffineTransform affineTransform = d.getAffineTransform();
AffineTransform inverseTransform = affineTransform.createInverse();
inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
return true;
} catch (NoninvertibleTransformException e) {
return false;
}
}
use of java.awt.geom.NoninvertibleTransformException in project scriptographer by scriptographer.
the class AbstractGraphics2D method drawImage.
/**
* Renders an image, applying a transform from image space into user space
* before drawing.
* The transformation from user space into device space is done with
* the current <code>Transform</code> in the <code>Graphics2D</code>.
* The specified transformation is applied to the image before the
* transform attribute in the <code>Graphics2D</code> context is applied.
* The rendering attributes applied include the <code>Clip</code>,
* <code>Transform</code>, and <code>Composite</code> attributes.
* Note that no rendering is done if the specified transform is
* noninvertible.
* @param img the <code>Image</code> to be rendered
* @param xform the transformation from image space into user space
* @param obs the {@link ImageObserver}
* to be notified as more of the <code>Image</code>
* is converted
* @return <code>true</code> if the <code>Image</code> is
* fully loaded and completely rendered;
* <code>false</code> if the <code>Image</code> is still being loaded.
* @see #transform
* @see #setTransform
* @see #setComposite
* @see #clip
* @see #setClip(Shape)
*/
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
boolean retVal = true;
if (xform.getDeterminant() != 0) {
AffineTransform inverseTransform = null;
try {
inverseTransform = xform.createInverse();
} catch (NoninvertibleTransformException e) {
// matrix determinant
throw new Error(e.getMessage());
}
gc.transform(xform);
retVal = drawImage(img, 0, 0, null);
gc.transform(inverseTransform);
} else {
AffineTransform savTransform = new AffineTransform(gc.getTransform());
gc.transform(xform);
retVal = drawImage(img, 0, 0, null);
gc.setTransform(savTransform);
}
return retVal;
}
use of java.awt.geom.NoninvertibleTransformException in project jdk8u_jdk by JetBrains.
the class DrawImage method renderImageXform.
protected void renderImageXform(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) {
final AffineTransform itx;
try {
itx = tx.createInverse();
} catch (final NoninvertibleTransformException ignored) {
// Non-invertible transform means no output
return;
}
/*
* Find the maximum bounds on the destination that will be
* affected by the transformed source. First, transform all
* four corners of the source and then min and max the resulting
* destination coordinates of the transformed corners.
* Note that tx already has the offset to sx1,sy1 accounted
* for so we use the box (0, 0, sx2-sx1, sy2-sy1) as the
* source coordinates.
*/
final double[] coords = new double[8];
/* corner: UL UR LL LR */
/* index: 0 1 2 3 4 5 6 7 */
/* coord: (0, 0), (w, 0), (0, h), (w, h) */
coords[2] = coords[6] = sx2 - sx1;
coords[5] = coords[7] = sy2 - sy1;
tx.transform(coords, 0, coords, 0, 4);
double ddx1, ddy1, ddx2, ddy2;
ddx1 = ddx2 = coords[0];
ddy1 = ddy2 = coords[1];
for (int i = 2; i < coords.length; i += 2) {
double d = coords[i];
if (ddx1 > d)
ddx1 = d;
else if (ddx2 < d)
ddx2 = d;
d = coords[i + 1];
if (ddy1 > d)
ddy1 = d;
else if (ddy2 < d)
ddy2 = d;
}
Region clip = sg.getCompClip();
final int dx1 = Math.max((int) Math.floor(ddx1), clip.lox);
final int dy1 = Math.max((int) Math.floor(ddy1), clip.loy);
final int dx2 = Math.min((int) Math.ceil(ddx2), clip.hix);
final int dy2 = Math.min((int) Math.ceil(ddy2), clip.hiy);
if (dx2 <= dx1 || dy2 <= dy1) {
// empty destination means no output
return;
}
final SurfaceData dstData = sg.surfaceData;
SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
if (srcData == null) {
img = getBufferedImage(img);
srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
if (srcData == null) {
// REMIND: Is this correct? Can this happen?
return;
}
}
if (isBgOperation(srcData, bgColor)) {
// We cannot perform bg operations during transform so make
// an opaque temp image with the appropriate background
// and work from there.
img = makeBufferedImage(img, bgColor, BufferedImage.TYPE_INT_RGB, sx1, sy1, sx2, sy2);
// Temp image has appropriate subimage at 0,0 now.
sx2 -= sx1;
sy2 -= sy1;
sx1 = sy1 = 0;
srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
}
SurfaceType srcType = srcData.getSurfaceType();
TransformHelper helper = TransformHelper.getFromCache(srcType);
if (helper == null) {
/* We have no helper for this source image type.
* But we know that we do have helpers for both RGB and ARGB,
* so convert to one of those types depending on transparency.
* ARGB_PRE might be a better choice if the source image has
* alpha, but it may cause some recursion here since we only
* tend to have converters that convert to ARGB.
*/
int type = ((srcData.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB);
img = makeBufferedImage(img, null, type, sx1, sy1, sx2, sy2);
// Temp image has appropriate subimage at 0,0 now.
sx2 -= sx1;
sy2 -= sy1;
sx1 = sy1 = 0;
srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, null);
srcType = srcData.getSurfaceType();
helper = TransformHelper.getFromCache(srcType);
// assert(helper != null);
}
SurfaceType dstType = dstData.getSurfaceType();
if (sg.compositeState <= SunGraphics2D.COMP_ALPHA) {
/* NOTE: We either have, or we can make,
* a MaskBlit for any alpha composite type
*/
MaskBlit maskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre, sg.imageComp, dstType);
/* NOTE: We can only use the native TransformHelper
* func to go directly to the dest if both the helper
* and the MaskBlit are native.
* All helpers are native at this point, but some MaskBlit
* objects are implemented in Java, so we need to check.
*/
if (maskblit.getNativePrim() != 0) {
// We can render directly.
helper.Transform(maskblit, srcData, dstData, sg.composite, clip, itx, interpType, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, null, 0, 0);
return;
}
}
// We need to transform to a temp image and then copy
// just the pieces that are valid data to the dest.
final int w = dx2 - dx1;
final int h = dy2 - dy1;
BufferedImage tmpimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
SurfaceData tmpData = SurfaceData.getPrimarySurfaceData(tmpimg);
SurfaceType tmpType = tmpData.getSurfaceType();
MaskBlit tmpmaskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre, CompositeType.SrcNoEa, tmpType);
/*
* The helper function fills a temporary edges buffer
* for us with the bounding coordinates of each scanline
* in the following format:
*
* edges[0, 1] = [top y, bottom y)
* edges[2, 3] = [left x, right x) of top row
* ...
* edges[h*2, h*2+1] = [left x, right x) of bottom row
*
* all coordinates in the edges array will be relative to dx1, dy1
*
* edges thus has to be h*2+2 in length
*/
final int[] edges = new int[h * 2 + 2];
// It is important that edges[0]=edges[1]=0 when we call
// Transform in case it must return early and we would
// not want to render anything on an error condition.
helper.Transform(tmpmaskblit, srcData, tmpData, AlphaComposite.Src, null, itx, interpType, sx1, sy1, sx2, sy2, 0, 0, w, h, edges, dx1, dy1);
final Region region = Region.getInstance(dx1, dy1, dx2, dy2, edges);
clip = clip.getIntersection(region);
/* NOTE: We either have, or we can make,
* a Blit for any composite type, even Custom
*/
final Blit blit = Blit.getFromCache(tmpType, sg.imageComp, dstType);
blit.Blit(tmpData, dstData, sg.composite, clip, 0, 0, dx1, dy1, w, h);
}
Aggregations