Package org.openpdf.renderer
Class PDFImage
java.lang.Object
org.openpdf.renderer.PDFImage
Encapsulates a PDF Image
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classA wrapper for ComponentColorSpace which normalizes based on the decode array.private classDecodes jpeg data, possibly attempting a manual YCCK decode if requested.(package private) static classA wrapper for ComponentColorSpace which normalizes based on the decode array. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intthe number of bits per sample componentprivate int[]color key mask.private PDFColorSpacethe colorspace to interpret the samples inprivate float[]the decode arrayprivate static int[][]private intthe height of this image in pixelsprivate booleanwhether this image is a mask or notprivate final PDFObjectthe actual image dataprivate final booleantrue if the image is in encoded in JPEGprivate PDFImagethe SMask image, if anyprivate intthe width of this image in pixels -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate BufferedImagebiColorToGrayscale(WritableRaster raster, byte[] ncc) Creates a new image of typeTYPE_BYTE_GRAYwhich represents the given rasterprivate BufferedImageconvertGreyscaleToArgb(byte[] data, BufferedImage bi) private ColorModelget a Java ColorModel consistent with the current color space, number of bits per component and decode arrayprivate static int[]createGreyToArgbMap(int numBits) Create a map from all bit-patterns of a certain depth greyscale to the corresponding sRGB values via the ICC colorr converter.static PDFImagecreateImage(PDFObject obj, Map<String, PDFObject> resources, boolean useAsSMask) Read a PDFImage from an image dictionary and streamprotected intGet the number of bits per component sampleprivate ColorModelget a Java ColorModel consistent with the current color space, number of bits per component and decode arrayprotected PDFColorSpaceGet the colorspace associated with this image, or null if there isn't oneprotected float[]Get the decode arrayprivate static int[]getGreyToArgbMap(int numBits) intGet the image's heightgetImage()Get the image that this PDFImage generates.getSMask()Return the soft mask associated with this imageintgetWidth()Get the image's widthprivate booleanisGreyscale(ColorSpace aCs) booleanReturn whether or not this is an image maskprivate float[]normalize(byte[] pixels, float[] normComponents, int normOffset) Normalize an array of values to match the decode arrayprotected BufferedImageparseData(byte[] data, ByteBuffer jpegData) Parse the image stream into a buffered image.private BufferedImagescaleSMaskImage(PDFImage sMaskImage) Scale the softmask image to the size of the actual imageprotected voidsetBitsPerComponent(int bpc) Set the number of bits per component sampleprivate voidsetColorKeyMask(PDFObject maskArrayObject) set the color key mask.protected voidsetColorSpace(PDFColorSpace colorSpace) Set the colorspace associated with this imageprotected voidsetDecode(float[] decode) Set the decode arrayprotected voidsetHeight(int height) Set the image's heightvoidsetImageMask(boolean imageMask) Set whether or not this is an image maskprotected voidSet the soft mask imageprotected voidsetWidth(int width) Set the image's width
-
Field Details
-
GREY_TO_ARGB
private static int[][] GREY_TO_ARGB -
colorKeyMask
private int[] colorKeyMaskcolor key mask. Array of start/end pairs of ranges of color components to mask out. If a component falls within any of the ranges it is clear. -
width
private int widththe width of this image in pixels -
height
private int heightthe height of this image in pixels -
colorSpace
the colorspace to interpret the samples in -
bpc
private int bpcthe number of bits per sample component -
imageMask
private boolean imageMaskwhether this image is a mask or not -
sMask
the SMask image, if any -
decode
private float[] decodethe decode array -
imageObj
the actual image data -
jpegDecode
private final boolean jpegDecodetrue if the image is in encoded in JPEG
-
-
Constructor Details
-
PDFImage
Create an instance of a PDFImage- Throws:
IOException- ifPDFDecoderthrows one while evaluating if the image is a Jpeg
-
-
Method Details
-
createImage
public static PDFImage createImage(PDFObject obj, Map<String, PDFObject> resources, boolean useAsSMask) throws IOExceptionRead a PDFImage from an image dictionary and stream- Parameters:
obj- the PDFObject containing the image's dictionary and streamresources- the current resourcesuseAsSMask- - flag for switching colors in case image is used as sMask internally this is needed for handling transparency in smask images.- Throws:
IOException
-
getImage
Get the image that this PDFImage generates.- Returns:
- a buffered image containing the decoded image data
- Throws:
PDFImageParseException
-
parseData
Parse the image stream into a buffered image. Note that this is guaranteed to be called after all the other setXXX methods have been called.
NOTE: the color convolving is extremely slow on large images. It would be good to see if it could be moved out into the rendering phases, where we might be able to scale the image down first. </p
- Parameters:
data- the data when already completely filtered and uncompressedjpegData- a byte buffer if data still requiring the DCDTecode filter is being used- Throws:
IOException
-
scaleSMaskImage
Scale the softmask image to the size of the actual image- Parameters:
sMaskImage-- Returns:
- Throws:
PDFImageParseException
-
isGreyscale
-
convertGreyscaleToArgb
-
getGreyToArgbMap
private static int[] getGreyToArgbMap(int numBits) -
createGreyToArgbMap
private static int[] createGreyToArgbMap(int numBits) Create a map from all bit-patterns of a certain depth greyscale to the corresponding sRGB values via the ICC colorr converter.- Parameters:
numBits- the number of greyscale bits- Returns:
- a 2^bits array of standard 32-bit ARGB fits for each greyscale value at that bitdepth
-
biColorToGrayscale
Creates a new image of typeTYPE_BYTE_GRAYwhich represents the given raster- Parameters:
raster- Raster of an image with just two colors, bitwise encodedncc- Array with two entries that describe the corresponding gray values
-
getWidth
public int getWidth()Get the image's width -
setWidth
protected void setWidth(int width) Set the image's width -
getHeight
public int getHeight()Get the image's height -
setHeight
protected void setHeight(int height) Set the image's height -
setColorKeyMask
set the color key mask. It is an array of start/end entries to indicate ranges of color indicies that should be masked out.- Parameters:
maskArrayObject-- Throws:
IOException
-
getColorSpace
Get the colorspace associated with this image, or null if there isn't one -
setColorSpace
Set the colorspace associated with this image -
getBitsPerComponent
protected int getBitsPerComponent()Get the number of bits per component sample -
setBitsPerComponent
protected void setBitsPerComponent(int bpc) Set the number of bits per component sample -
isImageMask
public boolean isImageMask()Return whether or not this is an image mask -
setImageMask
public void setImageMask(boolean imageMask) Set whether or not this is an image mask -
getSMask
Return the soft mask associated with this image -
setSMask
Set the soft mask image -
getDecode
protected float[] getDecode()Get the decode array -
setDecode
protected void setDecode(float[] decode) Set the decode array -
getColorModel
get a Java ColorModel consistent with the current color space, number of bits per component and decode array- Parameters:
bpc- the number of bits per component
-
normalize
private float[] normalize(byte[] pixels, float[] normComponents, int normOffset) Normalize an array of values to match the decode array -
createColorModel
get a Java ColorModel consistent with the current color space, number of bits per component and decode array- Parameters:
bpc- the number of bits per component
-