Skip to content

Commit

Permalink
Switched to a legit ditherering implementation which is much, much fa…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
dren-dk committed Jul 10, 2016
1 parent 2feafb5 commit b9eadc0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 107 deletions.
11 changes: 9 additions & 2 deletions host/shiver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>0.9.2</dropwizard.version>
<twelve.version>3.2.1</twelve.version>
</properties>

<dependencies>
<dependency>
<!-- https://mvnrepository.com/artifact/com.twelvemonkeys.common/common-image -->
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
Expand Down Expand Up @@ -107,7 +109,12 @@
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
</dependency>


<dependency>
<groupId>com.twelvemonkeys.common</groupId>
<artifactId>common-image</artifactId>
<version>${twelve.version}</version>
</dependency>
</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;

import com.twelvemonkeys.image.DiffusionDither;
import dk.osaa.psaw.config.AxisConstraints;
import dk.osaa.psaw.config.PhotonSawMachineConfig;
import dk.osaa.psaw.core.Line;
import dk.osaa.psaw.job.*;
import lombok.val;
import lombok.extern.java.Log;

import javax.imageio.ImageIO;

/**
* This is the great big lump of code that takes care of collecting all the RasterNodes in the job and merging the transformed rasters
* into fewer, ideally one, large raster, then outputs the merged raster lines to the render target.
Expand All @@ -23,6 +32,10 @@
*/
@Log
public class Rasterizer {
private static final byte[] BLACK_AND_WHITE = new byte[]{(byte)Color.BLACK.getRed(), (byte)Color.WHITE.getRed()};
private static final IndexColorModel ONE_BIT = new IndexColorModel(1, 2, BLACK_AND_WHITE,BLACK_AND_WHITE,BLACK_AND_WHITE);

private static DiffusionDither ditherer = new DiffusionDither();

/**
*
Expand Down Expand Up @@ -141,17 +154,19 @@ private static BufferedImage combinedOneBitRaster(RasterGroup eg, double linePit
*/

log.info("Starting dither of image "+ri.getWidth()+" x "+ri.getHeight()+" pixels at "+eg.bb.getMinX()+","+eg.bb.getMinY()+" w/h: "+eg.bb.getWidth()+"/"+eg.bb.getHeight());
BufferedImage onebit = DitherFloydSteinberg.dither(ri);
log.info("Done with dither");

/*
try {
File outputfile = new File("/tmp/onebit.png");
ImageIO.write(onebit, "png", outputfile);
} catch (IOException e) {
log.log(Level.SEVERE, "Fail!", e);
}
*/
BufferedImage onebit = ditherer.filter(ri, ditherer.createCompatibleDestImage(ri, ONE_BIT));
log.info("Done with dither");

/*
try {
File outputfile = new File("/tmp/onebit.png");
ImageIO.write(onebit, "png", outputfile);
} catch (IOException e) {
log.log(Level.SEVERE, "Fail!", e);
}
*/
return onebit;
}


}

0 comments on commit b9eadc0

Please sign in to comment.