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

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.jpg
All Implemented Interfaces:
Handler

public final class jpg
extends AbstractImageHandler

Default handler for jpg file (MIME type image/jpeg).


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 EXIF
          Type of EXIF segment in JPEG.
private static int FILE_OVERHEAD
          Estimated JPEG overhead constant, ie what would a 0x0 JPEG file size be; non-negative.
private static int IPTC
          Type of IPTC segment in JPEG.
private static int MAX_VALUE_CHARS
          Longest value (chars) we will accept without discarding; strictly positive.
private static int maxJPEGQuality
          Max quality allowed in a JPEG montage or thumbnail.
private static int minJPEGQuality
          Min quality allowed in a JPEG montage or thumbnail.
private static int normalThumbnailJPEGQuality
          Normal/initial quality for a JPEG 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
jpg()
           
 
Method Summary
 boolean canMakeThumbnails()
          Returns true if this can make thumbnail/sample exhibits for this type.
protected  org.w3c.dom.Node extractSpecificImageMetaData(javax.imageio.metadata.IIOMetadata imageMetadata, Name.ExhibitFull exhibitName)
          Get specific (image) metadata for one particular image type; null if none.
 java.awt.Dimension get2DImageDimensions(java.io.InputStream is)
          Get dimensions X and Y of a JPEG 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 JPEG handler.
 
Methods inherited from class org.hd.d.pg2k.svrCore.MIME.AbstractImageHandler
_getEncoder, _reduceColoursQualityThreshold, _trimMetadata, decodeImage, estimateWorkingMemoryToCreateThumbnails, 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 2--4 is probably good.

See Also:
Constant Field Values

FILE_OVERHEAD

private static final int FILE_OVERHEAD
Estimated JPEG overhead constant, ie what would a 0x0 JPEG 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

maxJPEGQuality

private static final int maxJPEGQuality
Max quality allowed in a JPEG montage or thumbnail. We don't go to 100%, since that might inflate the image and gives hardly any image improvement.

See Also:
Constant Field Values

normalThumbnailJPEGQuality

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

A quality of 75% is the default for the JPEG encoder.

A value from 50--90 is probably good; 85 has worked well in the past.

See Also:
Constant Field Values

minJPEGQuality

private static final int minJPEGQuality
Min quality allowed in a JPEG montage or thumbnail. We don't go to 0%, since the image would be unusable.

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-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

thumbnailParams

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


EXIF

private static final int EXIF
Type of EXIF segment in JPEG.

See Also:
Constant Field Values

IPTC

private static final int IPTC
Type of IPTC segment in JPEG.

See Also:
Constant Field Values

MAX_VALUE_CHARS

private static final int MAX_VALUE_CHARS
Longest value (chars) we will accept without discarding; strictly positive.

See Also:
Constant Field Values
Constructor Detail

jpg

public jpg()
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 JPEG 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)

canMakeThumbnails

public boolean canMakeThumbnails()
Returns true if this can make thumbnail/sample exhibits for this type. Returns true because we can make JPEG thumbnails.

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

getThumbnailParams

public Handler.ThumbnailParams getThumbnailParams()
Get ThumbnailParameters for JPEG handler.

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

extractSpecificImageMetaData

protected org.w3c.dom.Node extractSpecificImageMetaData(javax.imageio.metadata.IIOMetadata imageMetadata,
                                                        Name.ExhibitFull exhibitName)
Get specific (image) metadata for one particular image type; null if none. This does not have to be provided, but if so enables such things as EXIF and IPTC extraction from JPEG images.

We trim and normalise values shown a little, and discard any huge values, since this data is intended for a human to read. If they need more detail then they can download the image and open it in a decent Photoshop-like app.

This may be a mix of stream and image/frame metadata.

Overrides:
extractSpecificImageMetaData in class AbstractImageHandler
Parameters:
imageMetadata - imageio portable metadata for this exhibit; never null
exhibitName - full exhibit name (primarily to help with debugging); never null

DHD Multimedia Gallery V1.57.21

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