org.hd.d.pg2k.svrCore.mediahandler
Class png

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.MIME.AbstractHandler
      extended by org.hd.d.pg2k.svrCore.MIME.AbstractImageHandler
          extended by org.hd.d.pg2k.svrCore.mediahandler.png
All Implemented Interfaces:
Handler

public final class png
extends AbstractImageHandler

Default handler for png file (MIME type image/png). Relies on Java Advanced Imaging extension JAI 1.1.2 or newer (javax.media.jai.*) for some functionality (eg making thumbnails); may not be able to run (or possibly even load) without it, though we try to ensure that basic functionality is available anyway.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.hd.d.pg2k.svrCore.MIME.Handler
Handler.ThumbnailParams
 
Field Summary
private static int EST_BYTES_PER_IMAGE_PIXEL_IN_MEMORY
          Estimated (maximum) bytes per pixel of a decoded image in memory.
private static int FILE_OVERHEAD
          Estimated file overhead constant, ie what would a 0x0 file size be; non-negative.
private static int maxThumbnailQuality
          Maximum quality allowed in a thumbnail; taken to be total colour depth.
private static int minThumbnailQuality
          Maximum quality allowed in a thumbnail; taken to be total colour depth.
private static int normalThumbnailQuality
          Normal/initial quality for a thumbnail.
private static int TARGET_BPP
          Target bits-per-pixel for thumbnail images; strictly positive.
private static Handler.ThumbnailParams thumbnailParams
          Gather together thumbnail parameters.
 
Fields inherited from interface org.hd.d.pg2k.svrCore.MIME.Handler
TAG_NAME_METADATA_TOP
 
Constructor Summary
png()
           
 
Method Summary
protected  int _reduceColoursQualityThreshold()
          Guide colour-reduction to reduce quality and size of lossless image formats.
 boolean canMakeThumbnails()
          Returns true because handler can make thumbnails for this type.
 java.awt.Dimension get2DImageDimensions(java.io.InputStream is)
          Get dimensions X and Y of a PNG exhibit, else null if dimensions cannot be computed.
 ExhibitMIME.ExhibitTypeParameters getExhibitType()
          Get internal type of ExhibitMIME type; never null.
 Handler.ThumbnailParams getThumbnailParams()
          Get ThumbnailParameters for a particular handler.
 
Methods inherited from class org.hd.d.pg2k.svrCore.MIME.AbstractImageHandler
_getEncoder, _trimMetadata, decodeImage, estimateWorkingMemoryToCreateThumbnails, extractSpecificImageMetaData, getMetadata, makeImageBinary, makeSizeConstrainedEncodedImage, makeThumbnailImage, makeThumbnails, makeThumbnails
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TARGET_BPP

private static final int TARGET_BPP
Target bits-per-pixel for thumbnail images; strictly positive. Does not need to leave all images perfect, but most should be OK. Note that we'll be limited from above by the absolute size limits of thumbnails in general.

A value in the range 4--8 is probably good.

See Also:
Constant Field Values

FILE_OVERHEAD

private static final int FILE_OVERHEAD
Estimated file overhead constant, ie what would a 0x0 file size be; non-negative. This factor helps avoid penalising small images by having the overhead eat into the bits that should be being used by the image.

One byte less than a 1x1 white image produced by PSP7.

See Also:
Constant Field Values

EST_BYTES_PER_IMAGE_PIXEL_IN_MEMORY

private static final int EST_BYTES_PER_IMAGE_PIXEL_IN_MEMORY
Estimated (maximum) bytes per pixel of a decoded image in memory. This assumes that a 24/32-bit RGB or ARGB format is the most expensive we will run across. (The other main possibility is an 8-bit greyscale.)

See Also:
Constant Field Values

maxThumbnailQuality

private static final int maxThumbnailQuality
Maximum quality allowed in a thumbnail; taken to be total colour depth. Assume that this is the same as the maximum number of bits in memory we expect an image to take.

See Also:
Constant Field Values

normalThumbnailQuality

private static final int normalThumbnailQuality
Normal/initial quality for a thumbnail. This is reasonable for most images, though erring slightly on the side of retention of image quality at cost of download speed.

See Also:
Constant Field Values

minThumbnailQuality

private static final int minThumbnailQuality
Maximum quality allowed in a thumbnail; taken to be total colour depth. Must be positive and can be as little as monochrome, ie one bit.

See Also:
Constant Field Values

thumbnailParams

private static final Handler.ThumbnailParams thumbnailParams
Gather together thumbnail parameters.

Constructor Detail

png

public png()
Method Detail

getExhibitType

public ExhibitMIME.ExhibitTypeParameters getExhibitType()
Get internal type of ExhibitMIME type; never null.


get2DImageDimensions

public java.awt.Dimension get2DImageDimensions(java.io.InputStream is)
                                        throws java.io.IOException
Get dimensions X and Y of a PNG exhibit, else null if dimensions cannot be computed. This reads the opening bytes of the exhibit directly to extract the dimensions, rather than loading and interpreting the whole image.

This input stream must be of the correct type, eg the magic number already checked.

This does not close its input stream when done.

Specified by:
get2DImageDimensions in interface Handler
Overrides:
get2DImageDimensions in class AbstractImageHandler
Parameters:
is - the exhibit as a binary data stream
Throws:
java.io.IOException - in case of problems with corrupt data (or a broken exhibit)

getThumbnailParams

public Handler.ThumbnailParams getThumbnailParams()
Description copied from class: AbstractHandler
Get ThumbnailParameters for a particular handler. A handler that does not build thumbnails (ie canMakeThumbnails() returns false) may return null for this, which is the default, but otherwise this should return non-null.

This is assumed to be fast, ie to return a fixed static instance for each handler.

This is protected, since only the support routines in this base class need access this data.

Specified by:
getThumbnailParams in interface Handler
Overrides:
getThumbnailParams in class AbstractHandler

canMakeThumbnails

public boolean canMakeThumbnails()
Returns true because handler can make thumbnails for this type.

Specified by:
canMakeThumbnails in interface Handler
Overrides:
canMakeThumbnails in class AbstractImageHandler

_reduceColoursQualityThreshold

protected int _reduceColoursQualityThreshold()
Description copied from class: AbstractImageHandler
Guide colour-reduction to reduce quality and size of lossless image formats. Defaults to -1, implying that the image format is a lossy format for which the ImageWriteParam.setCompressionQuality() mechanism is enough to trade encoded image size for quality.

Else this is a positive value n, typically 8 or 24, which sets a quality level at/below which the number of colours in the image is reduced to (capped at) 2^n, and the image representation may be tweaked too (eg converted to a palette/indexed format) as a strong hint to the encoder.

Overrides:
_reduceColoursQualityThreshold in class AbstractImageHandler

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.