Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. package processpathtest;
  2.  
  3. import java.awt.*;
  4. import java.awt.geom.*;
  5. import java.awt.image.*;
  6. import java.io.File;
  7. import javax.imageio.ImageIO;
  8. import sun.java2d.loops.*;
  9. import sun.java2d.pipe.*;
  10. import sun.java2d.*;
  11.  
  12. public class ProcessPathTest {
  13.    
  14.     public static void main(String[] args) throws Exception {
  15.         //prepare output image
  16.         BufferedImage bimg = new BufferedImage(256, 256, BufferedImage.TYPE_INT_BGR);
  17.         Graphics2D g2d = (Graphics2D) bimg.getGraphics();
  18.         g2d.setColor(Color.WHITE);
  19.         g2d.fillRect(0, 0, bimg.getWidth(), bimg.getHeight());
  20.         g2d.setColor(Color.BLACK);
  21.        
  22.         // create test geometry
  23.         Rectangle2D rect = new Rectangle2D.Double();
  24.         rect.setRect(0.5, 0.50, 24, 24);  
  25.         Path2D.Float floatPath = new Path2D.Float(rect);
  26.        
  27.         //call test routines
  28.         testProcessPath(floatPath, g2d);
  29.         testShapeSpanIterator(floatPath, g2d);
  30.  
  31.         ImageIO.write(bimg, "png", new File("res.png"));
  32.     }
  33.    
  34.      private static void testShapeSpanIterator(Path2D.Float floatPath, Graphics2D g2d) {
  35.              ShapeSpanIterator ssi = LoopPipe.getFillSSI((SunGraphics2D) g2d);
  36.         ssi.setOutputArea(new Rectangle(0, 0, 1024, 1024));
  37.         PathIterator pi = floatPath.getPathIterator(AffineTransform.getTranslateInstance(0, 0));
  38.      
  39.         ssi.appendPath(pi);
  40.         int[] spanBox = new int[4];
  41.             while (ssi.nextSpan(spanBox)) {
  42.                 int x = spanBox[0] + 10;
  43.                 int y = spanBox[1] + 50;
  44.                 int width =  spanBox[2] - spanBox[0];
  45.                 int height = spanBox[3] - spanBox[1];
  46.                
  47.                 System.out.println("span: "+x+"/"+y+ " - "+width+"/"+height);
  48.                 g2d.fillRect(x, y, width, height);
  49.             }
  50.      }
  51.      
  52.      private static void testProcessPath(Path2D.Float floatPath, final Graphics2D g2d) {
  53.                 ProcessPath.fillPath(new ProcessPath.DrawHandler(0, 0, 1024, 1024) {
  54.                    
  55.                 void validate(SunGraphics2D sg2d) {
  56.                     Region clip = sg2d.getCompClip();
  57.                     setBounds(clip.getLoX(), clip.getLoY(),
  58.                               clip.getHiX(), clip.getHiY(), sg2d.strokeHint);
  59.                 }
  60.  
  61.                 public void drawLine(int x1, int y1, int x2, int y2) {
  62.                     System.out.println("drawline: "+x1+"/"+y1+ " - "+x2+"/"+y2);
  63.                     g2d.drawLine(x1, y1, x2, y2);
  64.                 }
  65.  
  66.                 public void drawPixel(int x, int y) {
  67.                     System.out.println("drawpixel: "+x+"/"+y);
  68.                     g2d.fillRect(x, y, 1, 1);
  69.                 }
  70.  
  71.                 public void drawScanline(int x1, int x2, int y) {
  72.                     System.out.println("drawscanline: "+x1+"/"+x2+ " - "+y);
  73.                     g2d.fillRect(x1, y, x2 - x1 + 1, 1);
  74.                 }
  75.             }, floatPath, 10, 10);
  76.      }  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement