org.pdfbox.pdmodel.graphics.predictor

Class PredictorAlgorithm

Known Direct Subclasses:
Average, None, Paeth, Sub, Up, Uptimum

public abstract class PredictorAlgorithm
extends java.lang.Object

Implements different PNG predictor algorithms that is used in PDF files.
Version:
$Revision: 1.3 $
Author:
xylifyx@yahoo.co.uk
See Also:
PNG Filters

Method Summary

int
aboveLeftPixel(byte[] buf, int offset, int dy, int x)
Get the above-left pixel from the buffer.
int
abovePixel(byte[] buf, int offset, int dy, int x)
Get the above pixel from the buffer.
void
checkBufsiz(byte[] src, byte[] dest)
check that buffer sizes matches width,height,bpp.
void
decode(byte[] src, byte[] dest)
decode a byte array full of image data using the filter that this object implements.
abstract void
decodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset, int destDy, int destOffset)
decode line of pixel data in src from src_offset and width*bpp bytes forward, put the decoded bytes into dest.
void
encode(byte[] src, byte[] dest)
encode a byte array full of image data using the filter that this object implements.
abstract void
encodeLine(byte[] src, byte[] dest, int srcDy, int srcOffset, int destDy, int destOffset)
encode line of pixel data in src from srcOffset and width*bpp bytes forward, put the decoded bytes into dest.
int
getBpp()
static PredictorAlgorithm
getFilter(int predictor)
int
getHeight()
int
getWidth()
int
leftPixel(byte[] buf, int offset, int dy, int x)
Get the left pixel from the buffer.
static void
main(String[] args)
Simple command line program to test the algorithm.
void
setBpp(int newBpp)
void
setHeight(int newHeight)
void
setWidth(int newWidth)

Method Details

aboveLeftPixel

public int aboveLeftPixel(byte[] buf,
                          int offset,
                          int dy,
                          int x)
Get the above-left pixel from the buffer.
Parameters:
buf - The buffer.
offset - The offset into the buffer.
dy - The dy value.
x - The x value.
Returns:
The above-left pixel.

abovePixel

public int abovePixel(byte[] buf,
                      int offset,
                      int dy,
                      int x)
Get the above pixel from the buffer.
Parameters:
buf - The buffer.
offset - The offset into the buffer.
dy - The dy value.
x - The x value.
Returns:
The above pixel.

checkBufsiz

public void checkBufsiz(byte[] src,
                        byte[] dest)
check that buffer sizes matches width,height,bpp. This implementation is used by most of the filters, but not Uptimum.
Parameters:
src - The source buffer.
dest - The destination buffer.

decode

public void decode(byte[] src,
                   byte[] dest)
decode a byte array full of image data using the filter that this object implements.
Parameters:
src - buffer
dest - buffer

decodeLine

public abstract void decodeLine(byte[] src,
                                byte[] dest,
                                int srcDy,
                                int srcOffset,
                                int destDy,
                                int destOffset)
decode line of pixel data in src from src_offset and width*bpp bytes forward, put the decoded bytes into dest.
Parameters:
src - encoded image data
dest - raw data
srcDy - byte offset between lines
srcOffset - beginning of line data
destDy - byte offset between lines
destOffset - beginning of line data

encode

public void encode(byte[] src,
                   byte[] dest)
encode a byte array full of image data using the filter that this object implements.
Parameters:
src - buffer
dest - buffer

encodeLine

public abstract void encodeLine(byte[] src,
                                byte[] dest,
                                int srcDy,
                                int srcOffset,
                                int destDy,
                                int destOffset)
encode line of pixel data in src from srcOffset and width*bpp bytes forward, put the decoded bytes into dest.
Parameters:
src - raw image data
dest - encoded data
srcDy - byte offset between lines
srcOffset - beginning of line data
destDy - byte offset between lines
destOffset - beginning of line data

getBpp

public int getBpp()
Returns:
Returns the bpp.

getFilter

public static PredictorAlgorithm getFilter(int predictor)
Parameters:
predictor -
  • 1 No prediction (the default value)
  • 2 TIFF Predictor 2
  • 10 PNG prediction (on encoding, PNG None on all rows)
  • 11 PNG prediction (on encoding, PNG Sub on all rows)
  • 12 PNG prediction (on encoding, PNG Up on all rows)
  • 13 PNG prediction (on encoding, PNG Average on all rows)
  • 14 PNG prediction (on encoding, PNG Paeth on all rows)
  • 15 PNG prediction (on encoding, PNG optimum)
Returns:
The predictor class based on the predictor code.

getHeight

public int getHeight()
Returns:
Returns the height.

getWidth

public int getWidth()
Returns:
Returns the width.

leftPixel

public int leftPixel(byte[] buf,
                     int offset,
                     int dy,
                     int x)
Get the left pixel from the buffer.
Parameters:
buf - The buffer.
offset - The offset into the buffer.
dy - The dy value.
x - The x value.
Returns:
The left pixel.

main

public static void main(String[] args)
Simple command line program to test the algorithm.
Parameters:
args - The command line arguments.

setBpp

public void setBpp(int newBpp)
Parameters:
newBpp - The bpp to set.

setHeight

public void setHeight(int newHeight)
Parameters:
newHeight - The height to set.

setWidth

public void setWidth(int newWidth)
Parameters:
newWidth - The width to set.