Java Code Examples for java.awt.geom.AffineTransform#getRotateInstance()

The following examples show how to use java.awt.geom.AffineTransform#getRotateInstance() . 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: AttrStringUtils.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the attributed string at <code>(textX, textY)</code>, rotated by 
 * the specified angle about <code>(rotateX, rotateY)</code>.
 * 
 * @param text  the attributed string (<code>null</code> not permitted).
 * @param g2  the graphics output target.
 * @param textX  the x-coordinate for the text.
 * @param textY  the y-coordinate for the text.
 * @param angle  the rotation angle (in radians).
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the y-coordinate for the rotation point.
 * 
 * @since 1.0.16
 */
public static void drawRotatedString(AttributedString text, Graphics2D g2, 
        float textX, float textY, double angle, float rotateX, 
        float rotateY) {
    ParamChecks.nullNotPermitted(text, "text");

    AffineTransform saved = g2.getTransform();
    AffineTransform rotate = AffineTransform.getRotateInstance(angle, 
            rotateX, rotateY);
    g2.transform(rotate);
    TextLayout tl = new TextLayout(text.getIterator(),
                g2.getFontRenderContext());
    tl.draw(g2, textX, textY);
    
    g2.setTransform(saved);        
}
 
Example 2
Source File: Cardumen_0080_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a rectangle that encloses the axis label.  This is typically 
 * used for layout purposes (it gives the maximum dimensions of the label).
 *
 * @param g2  the graphics device.
 * @param edge  the edge of the plot area along which the axis is measuring.
 *
 * @return The enclosing rectangle.
 */
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {

    Rectangle2D result = new Rectangle2D.Double();
    String axisLabel = getLabel();
    if (axisLabel != null && !axisLabel.equals("")) {
        FontMetrics fm = g2.getFontMetrics(getLabelFont());
        Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
        RectangleInsets insets = getLabelInsets();
        bounds = insets.createOutsetRectangle(bounds);
        double angle = getLabelAngle();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
            angle = angle - Math.PI / 2.0;
        }
        double x = bounds.getCenterX();
        double y = bounds.getCenterY();
        AffineTransform transformer 
            = AffineTransform.getRotateInstance(angle, x, y);
        Shape labelBounds = transformer.createTransformedShape(bounds);
        result = labelBounds.getBounds2D();
    }

    return result;

}
 
Example 3
Source File: TextUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a shape that represents the bounds of the string after the 
 * specified rotation has been applied.
 * 
 * @param text  the text (<code>null</code> permitted).
 * @param g2  the graphics device.
 * @param textX  the x coordinate for the text.
 * @param textY  the y coordinate for the text.
 * @param angle  the angle.
 * @param rotateX  the x coordinate for the rotation point.
 * @param rotateY  the y coordinate for the rotation point.
 * 
 * @return The bounds (<code>null</code> if <code>text</code> is 
 *         </code>null</code> or has zero length).
 */
public static Shape calculateRotatedStringBounds(String text,
        Graphics2D g2, float textX, float textY,
        double angle, float rotateX, float rotateY) {

    if ((text == null) || (text.equals(""))) {
        return null;
    }
    FontMetrics fm = g2.getFontMetrics();
    Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm);
    AffineTransform translate = AffineTransform.getTranslateInstance(
            textX, textY);
    Shape translatedBounds = translate.createTransformedShape(bounds);
    AffineTransform rotate = AffineTransform.getRotateInstance(
            angle, rotateX, rotateY);
    Shape result = rotate.createTransformedShape(translatedBounds);
    return result;

}
 
Example 4
Source File: GeometryUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Shape getArrowShape(Line2D line, Point2D intersectionPoint) {
  final double deltaY = line.getP2().getY() - line.getP1().getY();
  final double length = Math.sqrt(Math.pow(deltaY, 2) + Math.pow(line.getP2().getX() - line.getP1().getX(), 2));

  double theta = Math.asin(deltaY / length);

  if (line.getP1().getX() > line.getP2().getX()) {
    theta = Math.PI - theta;
  }

  AffineTransform rotate = AffineTransform.getRotateInstance(theta, myArrowSize, myArrowSize / 2);
  Shape polygon = rotate.createTransformedShape(myArrowPolygon);

  AffineTransform move = AffineTransform.getTranslateInstance(intersectionPoint.getX() - myArrowSize, intersectionPoint.getY() - myArrowSize /2);
  polygon = move.createTransformedShape(polygon);
  return polygon;
}
 
Example 5
Source File: ShapeUtilities.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a shape with the specified rotation about <code>(x, y)</code>.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param shape  the shape (<code>null</code> not permitted).
 * @param angle  the angle (in radians).
 * @param x  the x coordinate for the rotation point.
 * @param y  the y coordinate for the rotation point.
 */
public static void drawRotatedShape(final Graphics2D g2, final Shape shape,
                                    final double angle,
                                    final float x, final float y) {

    final AffineTransform saved = g2.getTransform();
    final AffineTransform rotate = AffineTransform.getRotateInstance(
            angle, x, y);
    g2.transform(rotate);
    g2.draw(shape);
    g2.setTransform(saved);

}
 
Example 6
Source File: TestRotateMethods.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static AffineTransform makeAT(Mode mode, Point2D txpt,
                                     double vx, double vy)
{
    AffineTransform at;
    double tx = (txpt == null) ? 0.0 : txpt.getX();
    double ty = (txpt == null) ? 0.0 : txpt.getY();
    switch (mode) {
    case GET:
        if (txpt != null) {
            at = AffineTransform.getRotateInstance(vx, vy, tx, ty);
        } else {
            at = AffineTransform.getRotateInstance(vx, vy);
        }
        break;
    case SET:
        at = makeRandomAT();
        if (txpt != null) {
            at.setToRotation(vx, vy, tx, ty);
        } else {
            at.setToRotation(vx, vy);
        }
        break;
    case MOD:
        at = makeRandomAT();
        at.setToIdentity();
        if (txpt != null) {
            at.rotate(vx, vy, tx, ty);
        } else {
            at.rotate(vx, vy);
        }
        break;
    default:
        throw new InternalError("unrecognized mode: "+mode);
    }

    return at;
}
 
Example 7
Source File: BasicProgressBarUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints the progress string.
 *
 * @param g Graphics used for drawing.
 * @param x x location of bounding box
 * @param y y location of bounding box
 * @param width width of bounding box
 * @param height height of bounding box
 * @param fillStart start location, in x or y depending on orientation,
 *        of the filled portion of the progress bar.
 * @param amountFull size of the fill region, either width or height
 *        depending upon orientation.
 * @param b Insets of the progress bar.
 */
private void paintString(Graphics g, int x, int y, int width, int height,
                         int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D)g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        g2.setColor(getSelectionBackground());
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(fillStart, y, amountFull, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        g2.setColor(getSelectionBackground());
        AffineTransform rotate =
                AffineTransform.getRotateInstance(Math.PI/2);
        g2.setFont(progressBar.getFont().deriveFont(rotate));
        renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(x, fillStart, width, amountFull);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
}
 
Example 8
Source File: BasicProgressBarUI.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Paints the progress string.
 *
 * @param g Graphics used for drawing.
 * @param x x location of bounding box
 * @param y y location of bounding box
 * @param width width of bounding box
 * @param height height of bounding box
 * @param fillStart start location, in x or y depending on orientation,
 *        of the filled portion of the progress bar.
 * @param amountFull size of the fill region, either width or height
 *        depending upon orientation.
 * @param b Insets of the progress bar.
 */
private void paintString(Graphics g, int x, int y, int width, int height,
                         int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D)g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        g2.setColor(getSelectionBackground());
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(fillStart, y, amountFull, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        g2.setColor(getSelectionBackground());
        AffineTransform rotate =
                AffineTransform.getRotateInstance(Math.PI/2);
        g2.setFont(progressBar.getFont().deriveFont(rotate));
        renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(x, fillStart, width, amountFull);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
}
 
Example 9
Source File: PointStrUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static String rotatePoints(String ptsStr, double theta) throws PointParseException {
	List<Point> pts = parsePoints(ptsStr);
	
	AffineTransform rotT = AffineTransform.getRotateInstance(theta);
	for (Point p : pts) {
		rotT.transform(p, p);
	}
	
	return pointsToString(pts);		
}
 
Example 10
Source File: BasicProgressBarUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints the progress string.
 *
 * @param g Graphics used for drawing.
 * @param x x location of bounding box
 * @param y y location of bounding box
 * @param width width of bounding box
 * @param height height of bounding box
 * @param fillStart start location, in x or y depending on orientation,
 *        of the filled portion of the progress bar.
 * @param amountFull size of the fill region, either width or height
 *        depending upon orientation.
 * @param b Insets of the progress bar.
 */
private void paintString(Graphics g, int x, int y, int width, int height,
                         int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D)g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        g2.setColor(getSelectionBackground());
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(fillStart, y, amountFull, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        g2.setColor(getSelectionBackground());
        AffineTransform rotate =
                AffineTransform.getRotateInstance(Math.PI/2);
        g2.setFont(progressBar.getFont().deriveFont(rotate));
        renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(x, fillStart, width, amountFull);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
}
 
Example 11
Source File: BufferedImageLuminanceSource.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
@Override
public LuminanceSource rotateCounterClockwise45() {
	int width = getWidth();
	int height = getHeight();

	int oldCenterX = left + width / 2;
	int oldCenterY = top + height / 2;

	// Rotate 45 degrees counterclockwise.
	AffineTransform transform = AffineTransform.getRotateInstance(MINUS_45_IN_RADIANS, oldCenterX, oldCenterY);

	int sourceDimension = Math.max(image.getWidth(), image.getHeight());
	BufferedImage rotatedImage = new BufferedImage(sourceDimension, sourceDimension, BufferedImage.TYPE_BYTE_GRAY);

	// Draw the original image into rotated, via transformation
	Graphics2D g = rotatedImage.createGraphics();
	g.drawImage(image, transform, null);
	g.dispose();

	int halfDimension = Math.max(width, height) / 2;
	int newLeft = Math.max(0, oldCenterX - halfDimension);
	int newTop = Math.max(0, oldCenterY - halfDimension);
	int newRight = Math.min(sourceDimension - 1, oldCenterX + halfDimension);
	int newBottom = Math.min(sourceDimension - 1, oldCenterY + halfDimension);

	return new BufferedImageLuminanceSource(rotatedImage, newLeft, newTop, newRight - newLeft, newBottom - newTop);
}
 
Example 12
Source File: Skew.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initTransients (Sheet sheet)
{
    angle = Math.atan(slope);

    // Rotation for deskew
    final double deskewAngle = -angle;
    at = AffineTransform.getRotateInstance(deskewAngle);

    // Origin translation for deskew
    final int w = sheet.getWidth();
    final int h = sheet.getHeight();
    final Point2D topRight = at.transform(new Point2D.Double(w, 0), null);
    final Point2D bottomLeft = at.transform(new Point2D.Double(0, h), null);
    final Point2D bottomRight = at.transform(new Point2D.Double(w, h), null);
    double dx = 0;
    double dy = 0;

    if (deskewAngle <= 0) { // Counter-clockwise deskew
        deskewedWidth = bottomRight.getX();
        dy = -topRight.getY();
        deskewedHeight = bottomLeft.getY() + dy;
    } else { // Clockwise deskew
        dx = -bottomLeft.getX();
        deskewedWidth = topRight.getX() + dx;
        deskewedHeight = bottomRight.getY();
    }

    at.translate(dx, dy);
}
 
Example 13
Source File: SpiralTransition2D.java    From pumpernickel with MIT License 5 votes vote down vote up
public Shape getShape(float progress) {
	if (sprawl) {
		double theta = (1 - progress) * 3 * Math.PI;
		AffineTransform rotate = AffineTransform.getRotateInstance(theta,
				30, 30);
		return rotate.createTransformedShape(spiral);
	}
	return spiral;
}
 
Example 14
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
protected StarburstIcon() {
  double agl = 0d;
  double add = Math.PI / VC;
  Path2D p = new Path2D.Double();
  p.moveTo(R2, 0d);
  for (int i = 0; i < VC * 2 - 1; i++) {
    agl += add;
    int r = i % 2 == 0 ? R1 : R2;
    p.lineTo(r * Math.cos(agl), r * Math.sin(agl));
  }
  p.closePath();
  AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 2d, R2, 0d);
  star = new Path2D.Double(p, at);
}
 
Example 15
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
protected StarIcon1() {
  double agl = 0d;
  double add = 2d * Math.PI / 5d;
  Path2D p = new Path2D.Double();
  p.moveTo(R, 0d);
  for (int i = 0; i < 5; i++) {
    p.lineTo(R * Math.cos(agl), R * Math.sin(agl));
    agl += add + add;
  }
  p.closePath();
  AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 2d, R, 0d);
  star = new Path2D.Double(p, at);
}
 
Example 16
Source File: GUITile.java    From Rails with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Provides the image of the tile based on the zoomStep.
 * tileScale is not considered for producing this image.
 */
public static BufferedImage getTileImage(Tile tile, HexSide rotation, int zoomStep) {

    // STEP 1: GET IMAGE FROM SVG
    // image not centered as there will be a bottom border to assign square bounds to the image

    String picId = tile.getPictureId();

    ImageLoader imageLoader = ImageLoader.getInstance();
    BufferedImage uncenteredTileImage = imageLoader.getTile(picId, zoomStep);

    if (uncenteredTileImage == null) return null;

    //svg always in NS orientation, hence wide diagonal can be directly taken from image size
    int wideDiagonal = uncenteredTileImage.getWidth();

    //narrow diagonal cannot be taken from image height due to the bottom border
    int narrowDiagonal = (int)Math.round( wideDiagonal * 0.5 * Math.sqrt(3) );

    int border = wideDiagonal - narrowDiagonal;

    // STEP 2: CENTER TILE IN IMAGE
    // apply the bottom border also the left / top / right

    //center tile by translation
    AffineTransform centeringAT = AffineTransform.getTranslateInstance( border, border );
    AffineTransformOp centeringATOp = new AffineTransformOp(centeringAT, GUIGlobals.getRenderingHints());

    //centered tile image create manually since it also needs a border on the right
    BufferedImage centeredTileImage = new BufferedImage(
            uncenteredTileImage.getWidth() + border * 2,
            uncenteredTileImage.getHeight() + border,
            uncenteredTileImage.getType());

    centeringATOp.filter(uncenteredTileImage, centeredTileImage);

    // STEP 3: ROTATE TILE IMAGE
    // feasible only now since there are enough margins to ensure tile won't exceed bounds

    double radians = MapOrientation.rotationInRadians(tile, rotation);
    int xCenter = Math.round(centeredTileImage.getWidth() / 2.0f );
    int yCenter = Math.round(centeredTileImage.getHeight() / 2.0f );

    AffineTransform af = AffineTransform.getRotateInstance(radians, xCenter, yCenter);
    AffineTransformOp aop = new AffineTransformOp(af, GUIGlobals.getRenderingHints());

    BufferedImage rotatedTileImage = aop.filter(centeredTileImage, null);

    // STEP 4: CROP ROTATED TILE IMAGE
    // rotation result will have additional borders on the right/bottom as a result of the AOP

    int croppedWidth, croppedHeight;
    if (MapOrientation.get(tile) == MapOrientation.NS) {
        //tile in NS orientation after rotation
        croppedWidth = wideDiagonal;
        croppedHeight = narrowDiagonal;
    } else  {
        //tile in EW orientation after rotation
        croppedWidth = narrowDiagonal;
        croppedHeight = wideDiagonal;
    }

    BufferedImage croppedTileImage = rotatedTileImage.getSubimage(
            xCenter - croppedWidth / 2,
            yCenter - croppedHeight / 2,
            croppedWidth,
            croppedHeight );

    return croppedTileImage;
}
 
Example 17
Source File: ImagingOpsNoExceptionsTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main (String[] args) {
    thresholdOp(low, high);
    int i = 1;
    RescaleOp resop = new RescaleOp(1.0f, 0, null);
    biop[i] = resop;
    rop[i] = resop;
    i++;

    byte invert[] = new byte[256];
    byte ordered[] = new byte[256];
    for (int j = 0; j < 256 ; j++) {
        invert[j] = (byte) (256-j);
        ordered[j] = (byte) j;
    }
    LookupOp lop = new LookupOp(new ByteLookupTable(0,invert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;

    byte[][] yellowInvert = new byte[][] { invert, invert, ordered };
    lop = new LookupOp(new ByteLookupTable(0,yellowInvert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;
    int dim[][] = {{3,3}, {3,3}, {3,3}, {5,5}};
    float data[][] = { {0.1f, 0.1f, 0.1f,              // 3x3 blur
                        0.1f, 0.2f, 0.1f,
                        0.1f, 0.1f, 0.1f},
                       {-1.0f, -1.0f, -1.0f,           // 3x3 sharpen
                        -1.0f, 9.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f},
                       { 0.f, -1.f,  0.f,                  // 3x3 edge
                         -1.f,  5.f, -1.f,
                         0.f, -1.f,  0.f},
                       {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  // 5x5 edge
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, 24.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}};
    for (int j = 0; j < data.length; j++, i++) {
        ConvolveOp cop = new ConvolveOp(new Kernel(dim[j][0],dim[j][1],data[j]));
        biop[i] = cop;
        rop[i] = cop;
    }

    ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorSpace cs2 = ColorSpace.getInstance(ColorSpace.CS_PYCC);
    ColorConvertOp ccop = new ColorConvertOp(cs1, cs2, null);
    biop[i] = ccop;
    rop[i] = ccop;
    i++;

    AffineTransform at =
        AffineTransform.getRotateInstance(0.5*Math.PI, SIZE/2, SIZE/2);
    AffineTransformOp atOp =
        new AffineTransformOp(at, null);
    biop[i] = atOp;
    rop[i] = atOp;

    runTest();
}
 
Example 18
Source File: HexDrawUtilities.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
private static AffineTransform getHRU(int facing) {
    return AffineTransform.getRotateInstance(Math.toRadians(facing*60), HEX_CTR.x, HEX_CTR.y);
}
 
Example 19
Source File: ImagingOpsNoExceptionsTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main (String[] args) {
    thresholdOp(low, high);
    int i = 1;
    RescaleOp resop = new RescaleOp(1.0f, 0, null);
    biop[i] = resop;
    rop[i] = resop;
    i++;

    byte invert[] = new byte[256];
    byte ordered[] = new byte[256];
    for (int j = 0; j < 256 ; j++) {
        invert[j] = (byte) (256-j);
        ordered[j] = (byte) j;
    }
    LookupOp lop = new LookupOp(new ByteLookupTable(0,invert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;

    byte[][] yellowInvert = new byte[][] { invert, invert, ordered };
    lop = new LookupOp(new ByteLookupTable(0,yellowInvert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;
    int dim[][] = {{3,3}, {3,3}, {3,3}, {5,5}};
    float data[][] = { {0.1f, 0.1f, 0.1f,              // 3x3 blur
                        0.1f, 0.2f, 0.1f,
                        0.1f, 0.1f, 0.1f},
                       {-1.0f, -1.0f, -1.0f,           // 3x3 sharpen
                        -1.0f, 9.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f},
                       { 0.f, -1.f,  0.f,                  // 3x3 edge
                         -1.f,  5.f, -1.f,
                         0.f, -1.f,  0.f},
                       {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  // 5x5 edge
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, 24.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}};
    for (int j = 0; j < data.length; j++, i++) {
        ConvolveOp cop = new ConvolveOp(new Kernel(dim[j][0],dim[j][1],data[j]));
        biop[i] = cop;
        rop[i] = cop;
    }

    ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorSpace cs2 = ColorSpace.getInstance(ColorSpace.CS_PYCC);
    ColorConvertOp ccop = new ColorConvertOp(cs1, cs2, null);
    biop[i] = ccop;
    rop[i] = ccop;
    i++;

    AffineTransform at =
        AffineTransform.getRotateInstance(0.5*Math.PI, SIZE/2, SIZE/2);
    AffineTransformOp atOp =
        new AffineTransformOp(at, null);
    biop[i] = atOp;
    rop[i] = atOp;

    runTest();
}
 
Example 20
Source File: ImagingOpsNoExceptionsTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main (String[] args) {
    thresholdOp(low, high);
    int i = 1;
    RescaleOp resop = new RescaleOp(1.0f, 0, null);
    biop[i] = resop;
    rop[i] = resop;
    i++;

    byte invert[] = new byte[256];
    byte ordered[] = new byte[256];
    for (int j = 0; j < 256 ; j++) {
        invert[j] = (byte) (256-j);
        ordered[j] = (byte) j;
    }
    LookupOp lop = new LookupOp(new ByteLookupTable(0,invert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;

    byte[][] yellowInvert = new byte[][] { invert, invert, ordered };
    lop = new LookupOp(new ByteLookupTable(0,yellowInvert), null);
    biop[i] = lop;
    rop[i] = lop;
    i++;
    int dim[][] = {{3,3}, {3,3}, {3,3}, {5,5}};
    float data[][] = { {0.1f, 0.1f, 0.1f,              // 3x3 blur
                        0.1f, 0.2f, 0.1f,
                        0.1f, 0.1f, 0.1f},
                       {-1.0f, -1.0f, -1.0f,           // 3x3 sharpen
                        -1.0f, 9.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f},
                       { 0.f, -1.f,  0.f,                  // 3x3 edge
                         -1.f,  5.f, -1.f,
                         0.f, -1.f,  0.f},
                       {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f,  // 5x5 edge
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, 24.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
                        -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}};
    for (int j = 0; j < data.length; j++, i++) {
        ConvolveOp cop = new ConvolveOp(new Kernel(dim[j][0],dim[j][1],data[j]));
        biop[i] = cop;
        rop[i] = cop;
    }

    ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorSpace cs2 = ColorSpace.getInstance(ColorSpace.CS_PYCC);
    ColorConvertOp ccop = new ColorConvertOp(cs1, cs2, null);
    biop[i] = ccop;
    rop[i] = ccop;
    i++;

    AffineTransform at =
        AffineTransform.getRotateInstance(0.5*Math.PI, SIZE/2, SIZE/2);
    AffineTransformOp atOp =
        new AffineTransformOp(at, null);
    biop[i] = atOp;
    rop[i] = atOp;

    runTest();
}