Package net.sourceforge.jiu.color.dithering

# Class ClusteredDotDither

java.lang.Object
net.sourceforge.jiu.ops.Operation
net.sourceforge.jiu.ops.ImageToImageOperation
net.sourceforge.jiu.color.dithering.ClusteredDotDither

public class ClusteredDotDither extends ImageToImageOperation
Apply a clustered dot ordered dither to a grayscale image, converting it to a bilevel image in the process. Works with `GrayIntegerImage` objects as input and `BilevelImage` objects as output. Resolution of both must be the same. Use one of the predefined dither matrices or have one compiled from a spot function (given by an object of a class implementing `SpotFunction`). There are a couple of classes implementing that spot function interface in the dithering package. If no matrix is specified, `process()` creates a default matrix by calling `setOrder3DitherMatrix()`.

### Usage example

     ClusteredDotDither dither = new ClusteredDotDither();
     dither.setInputImage(image); // some GrayIntegerImage
     dither.setDitherMatrix(8, 8, new DiamondSpotFunction());
     dither.process();
     PixelImage ditheredImage = dither.getOutputImage();

### Credits

The predefined dither matrices were taken from Netpbm's `pgmtopbm` program (the matrices are stored in the file `dithers.h`).

I learned about spot functions and their use from Austin Donnelly's GIMP plugin newsprint - it has extensive comments, and the newsprint website explains the theoretical background.

Since:
  0.9.0
Author:
  Marco Schmidt

## Field Summary

Fields
Modifier and Type
Field
Description
`private int[]`
`ditherData`
`private int`
`ditherHeight`
`private int`
`ditherWidth`

## Constructor Summary

Constructors
Constructor
Description
`ClusteredDotDither()`

## Method Summary

Modifier and Type
Method
Description
`void`
`process()`
This method does the actual work of the operation.
`private void`
`process(GrayIntegerImage in, BilevelImage out)`
`private void`
`setDefaults()`
`void`
`setDitherMatrix(int width, int height, int[] data)`
Sets the dither matrix to be used in this operation.
`void`
`setDitherMatrix(int width, int height, SpotFunction f)`
Creates and sets a dither matrix of user-defined size and compiles it from a spot function.
`void`
`setOrder3DitherMatrix()`
Sets a 6 times 6 elements matrix to be used for dithering.
`void`
`setOrder4DitherMatrix()`
Sets an 8 times 8 elements matrix to be used for dithering.
`void`
`setOrder8DitherMatrix()`
Sets a 16 times 16 elements matrix to be used for dithering.

### Methods inherited from class net.sourceforge.jiu.ops.ImageToImageOperation

`canInputAndOutputBeEqual, ensureImagesHaveSameResolution, ensureInputImageIsAvailable, ensureOutputImageResolution, getInputImage, getOutputImage, setCanInputAndOutputBeEqual, setInputImage, setOutputImage`

### Methods inherited from class net.sourceforge.jiu.ops.Operation

`addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ditherHeight

private int ditherHeight

### ditherWidth

private int ditherWidth

### ditherData

private int[] ditherData

## Constructor Details

### ClusteredDotDither

public ClusteredDotDither()

## Method Details

### process

public void process() throws MissingParameterException, WrongParameterException
Description copied from class: `Operation`
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.

Overrides:
  `process` in class `Operation`
Throws:
  `MissingParameterException` - if any mandatory parameter was not given to the operation
  `WrongParameterException` - if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)

### process

private void process(GrayIntegerImage in, BilevelImage out)

### setDefaults

private void setDefaults()

### setDitherMatrix

public void setDitherMatrix(int width, int height, int[] data)
Sets the dither matrix to be used in this operation.

Parameters:
  `width` - number of entries in horizontal direction
  `height` - number of entries in vertical direction
  `data` - matrix entries, in order top to bottom, and in each row left to right
Throws:
  `IllegalArgumentException` - if width or height are smaller than one or data is `null` or has not at least width times height entries

### setDitherMatrix

public void setDitherMatrix(int width, int height, SpotFunction f)
Creates and sets a dither matrix of user-defined size and compiles it from a spot function. Creates a matrix from the spot function and calls `setDitherMatrix(int, int, int[])`.

Parameters:
  `width` - width of matrix, must be one or larger
  `height` - height of matrix, must be one or larger
  `f` - the spot function to be used for compiling the matrix

### setOrder3DitherMatrix

public void setOrder3DitherMatrix()
Sets a 6 times 6 elements matrix to be used for dithering.

### setOrder4DitherMatrix

public void setOrder4DitherMatrix()
Sets an 8 times 8 elements matrix to be used for dithering.

### setOrder8DitherMatrix

public void setOrder8DitherMatrix()
Sets a 16 times 16 elements matrix to be used for dithering.