Package Makelangelo

Examples of Makelangelo.C3


      return closest;
  }
 
  private void DitherDirection(BufferedImage img,int y,C3[] error,C3[] nexterror,int direction) throws IOException {
    int w = stepw;
    C3 oldPixel = new C3(0,0,0);
    C3 newPixel = new C3(0,0,0);
    C3 quant_error = new C3(0,0,0);
    int start, end, x;

    for(x=0;x<w;++x) nexterror[x].set(0,0,0);
   
    if(direction>0) {
      start=0;
      end=w;
    } else {
      start=w-1;
      end=-1;
    }
   
    // @TODO: make this a parameter
    boolean draw_filled=false;
   
    // for each x from left to right
    for(x=start;x!=end;x+=direction) {
      // oldpixel := pixel[x][y]
      //oldPixel.set( new C3(img.getRGB(x, y)).add(error[x]) );
      oldPixel.set( new C3(TakeImageSampleBlock(img,x*step4,y*step4,x*step4+step4,y*step4+step4)).add(error[x]) );
      // newpixel := find_closest_palette_color(oldpixel)
      newPixel = QuantizeColor(oldPixel);

      // pixel[x][y] := newpixel
      if(newPixel.diff(palette[palette_mask])==0) {
        // draw a circle.  the diameter is relative to the intensity.
        if(draw_filled) {
          MoveTo(out,x*step4+step2-step2,y*step4+step2-step2,true);
          MoveTo(out,x*step4+step2+step2,y*step4+step2-step2,false);
          MoveTo(out,x*step4+step2+step2,y*step4+step2+step2,false);
          MoveTo(out,x*step4+step2-step2,y*step4+step2+step2,false);
          MoveTo(out,x*step4+step2-step2,y*step4+step2-step2,false);
          MoveTo(out,x*step4+step2+step1,y*step4+step2-step1,false);
          MoveTo(out,x*step4+step2+step1,y*step4+step2+step1,false);
          MoveTo(out,x*step4+step2-step1,y*step4+step2+step1,false);
          MoveTo(out,x*step4+step2-step1,y*step4+step2-step1,false);
          MoveTo(out,x*step4+step2      ,y*step4+step2      ,false);
          MoveTo(out,x*step4+step2      ,y*step4+step2      ,true);
        } else {
          MoveTo(out,x*step4+step2-step1,y*step4+step2-step1,true);
          MoveTo(out,x*step4+step2+step1,y*step4+step2-step1,false);
          MoveTo(out,x*step4+step2+step1,y*step4+step2+step1,false);
          MoveTo(out,x*step4+step2-step1,y*step4+step2+step1,false);
          MoveTo(out,x*step4+step2-step1,y*step4+step2-step1,false);
          MoveTo(out,x*step4+step2-step1,y*step4+step2-step1,true);
        }
      }
     
      // quant_error := oldpixel - newpixel
      quant_error.set( oldPixel.sub( newPixel ) );
      // pixel[x+1][y  ] += 7/16 * quant_error
      // pixel[x-1][y+1] += 3/16 * quant_error
      // pixel[x  ][y+1] += 5/16 * quant_error
      // pixel[x+1][y+1] += 1/16 * quant_error
        nexterror[x          ].add(quant_error.mul(5.0/16.0));
      if(x+direction>=0 && x+direction < w) {
            error[x+direction].add(quant_error.mul(7.0/16.0));
        nexterror[x+direction].add(quant_error.mul(1.0/16.0));
      }
      if(x-direction>=0 && x-direction < w) {
        nexterror[x-direction].add(quant_error.mul(3.0/16.0));
      }
    }
  }
View Full Code Here


 
  // sample the pixels from x0,y0 (top left) to x1,y1 (bottom right)
  protected C3 TakeImageSampleBlock(BufferedImage img,int x0,int y0,int x1,int y1) {
    // point sampling
    C3 value = new C3(0,0,0);
    int sum=0;
   
    if(x0<0) x0=0;
    if(x1>image_width-1) x1 = image_width-1;
    if(y0<0) y0=0;
    if(y1>image_height-1) y1 = image_height-1;

    for(int y=y0;y<y1;++y) {
      for(int x=x0;x<x1;++x) {
        value.add(new C3(img.getRGB(x, y)));
        ++sum;
      }
    }

    if(sum==0) return new C3(255,255,255);
   
    return value.mul(1.0f/sum);
  }
View Full Code Here

    liftPen(out);

    int y;
   
    for(y=0;y<error.length;++y) {
      error[y] = new C3(0,0,0);
      nexterror[y] = new C3(0,0,0);
    }

    direction=1;
    for(y=0;y<steph;++y) {
      DitherDirection(img,y,error,nexterror,direction);
View Full Code Here

    new C3(0,0,255),
    new C3(255,255,255),
  };
 
  C3 QuantizeColor(C3 c) {
    C3 closest = palette[0];

      for (C3 n : palette)
        if (n.diff(c) < closest.diff(c))
          closest = n;

      return closest;
  }
View Full Code Here

      return closest;
  }
 
  private void DitherDirection(BufferedImage img,int y,C3[] error,C3[] nexterror,int direction) {
    int w = img.getWidth();
    C3 oldPixel = new C3(0,0,0);
    C3 newPixel = new C3(0,0,0);
    C3 quant_error = new C3(0,0,0);
    int start, end, x;

    for(x=0;x<w;++x) nexterror[x].set(0,0,0);
   
    if(direction>0) {
      start=0;
      end=w;
    } else {
      start=w-1;
      end=-1;
    }
   
    // for each x from left to right
    for(x=start;x!=end;x+=direction) {
      // oldpixel := pixel[x][y]
      oldPixel.set( new C3(img.getRGB(x, y)).add(error[x]) );
      // newpixel := find_closest_palette_color(oldpixel)
      newPixel = QuantizeColor(oldPixel);
      // pixel[x][y] := newpixel
      img.setRGB(x, y, newPixel.toInt());
      // quant_error := oldpixel - newpixel
      quant_error.set( oldPixel.sub( newPixel ) );
      // pixel[x+1][y  ] += 7/16 * quant_error
      // pixel[x-1][y+1] += 3/16 * quant_error
      // pixel[x  ][y+1] += 5/16 * quant_error
      // pixel[x+1][y+1] += 1/16 * quant_error
        nexterror[x          ].add(quant_error.mul(5.0/16.0));
      if(x+direction>=0 && x+direction < w) {
            error[x+direction].add(quant_error.mul(7.0/16.0));
        nexterror[x+direction].add(quant_error.mul(1.0/16.0));
      }
      if(x-direction>=0 && x-direction < w) {
        nexterror[x-direction].add(quant_error.mul(3.0/16.0));
      }
    }
  }
View Full Code Here

    int direction=1;
    C3 [] error=new C3[w];
    C3 [] nexterror=new C3[w];
   
    for(y=0;y<w;++y) {
      error[y] = new C3(0,0,0);
      nexterror[y] = new C3(0,0,0);
    }
   
    // for each y from top to bottom
    for(y=0;y<h;++y) {
      DitherDirection(img,y,error,nexterror,direction);
View Full Code Here

    }
    tool.WriteMoveTo(out, TX(x), TY(y));
  }
 
  C3 QuantizeColor(C3 c) {
    C3 closest = palette[0];

      for (C3 n : palette)
        if (n.diff(c) < closest.diff(c))
          closest = n;

      return closest;
  }
View Full Code Here

TOP

Related Classes of Makelangelo.C3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.