FileDocCategorySizeDatePackage
ImageFormats.javaAPI DocJaudiotagger 2.0.48639Wed Mar 30 16:12:04 BST 2011org.jaudiotagger.tag.id3.valuepair

ImageFormats

public class ImageFormats extends Object
Represents common image formats support by ID3 and provides a mapping between the format field supported in ID3v22 and the mimetype field supported by ID3v23/ID3v24. Note only JPG and PNG are mentioned specifically in the ID3 v22 Spec but it only says 'Image Format is preferably PNG or JPG' , not mandatory. In the jaudiotagger library we also consider GIF as a portable format, and we recognise BMP,PDF and TIFF but do not consider these formats as portable.

Fields Summary
public static final String
V22_JPG_FORMAT
public static final String
V22_PNG_FORMAT
public static final String
V22_GIF_FORMAT
public static final String
V22_BMP_FORMAT
public static final String
V22_TIF_FORMAT
public static final String
V22_PDF_FORMAT
public static final String
V22_PIC_FORMAT
public static final String
MIME_TYPE_JPEG
public static final String
MIME_TYPE_PNG
public static final String
MIME_TYPE_GIF
public static final String
MIME_TYPE_BMP
public static final String
MIME_TYPE_TIFF
public static final String
MIME_TYPE_PDF
public static final String
MIME_TYPE_PICT
public static final String
MIME_TYPE_JPG
Sometimes this is used for jpg instead :or have I made this up
private static Map
imageFormatsToMimeType
private static Map
imageMimeTypeToFormat
Constructors Summary
Methods Summary
public static booleanbinaryDataIsBmpFormat(byte[] data)
Is this binary data a bmp image

param
data
return
true if binary data matches expected header for a bmp

        //Read signature
        return (0x42 == (data[0] & 0xff)) && (0x4d == (data[1] & 0xff));
    
public static booleanbinaryDataIsGifFormat(byte[] data)
Is this binary data a gif image

param
data
return
true if binary data matches expected header for a gif

        if(data.length<3)
        {
            return false;
        }
        //Read signature
        return (0x47 == (data[0] & 0xff)) && (0x49 == (data[1] & 0xff)) && (0x46 == (data[2] & 0xff));
    
public static booleanbinaryDataIsJpgFormat(byte[] data)
Is this binary data a jpg image

param
data
return
true if binary data matches expected header for a jpg Some details http://www.obrador.com/essentialjpeg/headerinfo.htm

        if(data.length<4)
        {
            return false;
        }
        //Read signature
        //Can be FF D8 FF E0 or FF D8 FF E1
        //FF D8 is SOI Marker, FFE0 or FFE1 is JFIF Marker
        return (0xff == (data[0] & 0xff)) && (0xd8 == (data[1] & 0xff)) && (0xff == (data[2] & 0xff)) && (0xe0 <= (data[3] & 0xff));
    
public static booleanbinaryDataIsPdfFormat(byte[] data)
Is this binary data a pdf image Details at http://en.wikipedia.org/wiki/Magic_number_%28programming%29

param
data
return
true if binary data matches expected header for a pdf

        //Read signature
        return (0x25 == (data[0] & 0xff)) && (0x50 == (data[1] & 0xff)) && (0x44 == (data[2] & 0xff)) && (0x46 == (data[3] & 0xff));
    
public static booleanbinaryDataIsPngFormat(byte[] data)
Is this binary data a png image

param
data
return
true if binary data matches expected header for a png

        //Read signature
        if(data.length<4)
        {
            return false;
        }
        return (0x89 == (data[0] & 0xff)) && (0x50 == (data[1] & 0xff)) && (0x4E == (data[2] & 0xff)) && (0x47 == (data[3] & 0xff));
    
public static booleanbinaryDataIsTiffFormat(byte[] data)
is this binary data a tiff image Details at http://en.wikipedia.org/wiki/Magic_number_%28programming%29

param
data
return
true if binary data matches expected header for a tiff

        //Read signature Intel
        return (
                ((0x49 == (data[0] & 0xff)) && (0x49 == (data[1] & 0xff)) && (0x2a == (data[2] & 0xff)) && (0x00 == (data[3] & 0xff)))
                ||
                ((0x4d == (data[0] & 0xff)) && (0x4d == (data[1] & 0xff)) && (0x00 == (data[2] & 0xff)) && (0x2a == (data[3] & 0xff)))
                );
    
public static java.lang.StringgetFormatForMimeType(java.lang.String mimeType)
Get v2.2 format from v2.3 mimetype

param
mimeType
return

        return imageMimeTypeToFormat.get(mimeType);
    
public static java.lang.StringgetMimeTypeForBinarySignature(byte[] data)

param
data
return
correct mimetype for the image data represented by this byte data

        if(binaryDataIsPngFormat(data))
        {
            return MIME_TYPE_PNG;
        }
        else if(binaryDataIsJpgFormat(data))
        {
            return MIME_TYPE_JPEG;
        }
        else if(binaryDataIsGifFormat(data))
        {
            return MIME_TYPE_GIF;
        }
        else if(binaryDataIsBmpFormat(data))
        {
            return MIME_TYPE_BMP;
        }
        else if(binaryDataIsPdfFormat(data))
        {
            return MIME_TYPE_PDF;
        }
        else if(binaryDataIsTiffFormat(data))
        {
            return MIME_TYPE_TIFF;
        }
        else
        {
            return null;
        }
    
public static java.lang.StringgetMimeTypeForFormat(java.lang.String format)
Get v2.3 mimetype from v2.2 format

param
format
return


    
    
        imageFormatsToMimeType.put(V22_JPG_FORMAT, MIME_TYPE_JPEG);
        imageFormatsToMimeType.put(V22_PNG_FORMAT, MIME_TYPE_PNG);
        imageFormatsToMimeType.put(V22_GIF_FORMAT, MIME_TYPE_GIF);
        imageFormatsToMimeType.put(V22_BMP_FORMAT, MIME_TYPE_BMP);
        imageFormatsToMimeType.put(V22_TIF_FORMAT, MIME_TYPE_TIFF);
        imageFormatsToMimeType.put(V22_PDF_FORMAT, MIME_TYPE_PDF);
        imageFormatsToMimeType.put(V22_PIC_FORMAT, MIME_TYPE_PICT);

        String value;
        for (String key : imageFormatsToMimeType.keySet())
        {
            value = imageFormatsToMimeType.get(key);
            imageMimeTypeToFormat.put(value, key);
        }

        //The mapping isn't one-one lets add other mimetypes
        imageMimeTypeToFormat.put(MIME_TYPE_JPG, V22_JPG_FORMAT);
    
        return imageFormatsToMimeType.get(format);
    
public static booleanisPortableFormat(byte[] data)

param
data
return
true if the image format is a portable format recognised across operating systems

        return binaryDataIsPngFormat(data) ||  binaryDataIsJpgFormat(data) ||  binaryDataIsGifFormat(data);