FileDocCategorySizeDatePackage
MetadataBlockDataPicture.javaAPI DocJaudiotagger 2.0.411999Wed Jun 08 11:59:18 BST 2011org.jaudiotagger.audio.flac.metadatablock

MetadataBlockDataPicture

public class MetadataBlockDataPicture extends Object implements MetadataBlockData, org.jaudiotagger.tag.TagField
Picture Block

This block is for storing pictures associated with the file, most commonly cover art from CDs. There may be more than one PICTURE block in a file. The picture format is similar to the APIC frame in ID3v2. The PICTURE block has a type, MIME type, and UTF-8 description like ID3v2, and supports external linking via URL (though this is discouraged). The differences are that there is no uniqueness constraint on the description field, and the MIME type is mandatory. The FLAC PICTURE block also includes the resolution, color depth, and palette size so that the client can search for a suitable picture without having to scan them all

Format: Info <32> The picture type according to the ID3v2 APIC frame: (There may only be one each of picture type 1 and 2 in a file) <32> The length of the MIME type string in bytes. The MIME type string, in printable ASCII characters 0x20-0x7e. The MIME type may also be --> to signify that the data part is a URL of the picture instead of the picture data itself. <32> The length of the description string in bytes. The description of the picture, in UTF-8. <32> The width of the picture in pixels. <32> The height of the picture in pixels. <32> The color depth of the picture in bits-per-pixel. <32> For indexed-color pictures (e.g. GIF), the number of colors used, or 0 for non-indexed pictures. <32> The length of the picture data in bytes. The binary picture data.

Fields Summary
public static final String
IMAGE_IS_URL
private int
pictureType
private String
mimeType
private String
description
private int
width
private int
height
private int
colourDepth
private int
indexedColouredCount
private byte[]
imageData
public static Logger
logger
Constructors Summary
public MetadataBlockDataPicture(ByteBuffer rawdata)
Initialize MetaBlockDataPicture from byteBuffer

param
rawdata
throws
IOException
throws
InvalidFrameException

        initFromByteBuffer(rawdata);
    
public MetadataBlockDataPicture(MetadataBlockHeader header, RandomAccessFile raf)
Construct picture block by reading from file, the header informs us how many bytes we should be reading from

param
header
param
raf
throws
java.io.IOException
throws
org.jaudiotagger.tag.InvalidFrameException

        ByteBuffer rawdata = ByteBuffer.allocate(header.getDataLength());
        int bytesRead = raf.getChannel().read(rawdata);
        if (bytesRead < header.getDataLength())
        {
            throw new IOException("Unable to read required number of databytes read:" + bytesRead + ":required:" + header.getDataLength());
        }
        rawdata.rewind();
        initFromByteBuffer(rawdata);


    
public MetadataBlockDataPicture(byte[] imageData, int pictureType, String mimeType, String description, int width, int height, int colourDepth, int indexedColouredCount)
Construct new MetadataPicture block

param
imageData
param
pictureType
param
mimeType
param
description
param
width
param
height
param
colourDepth
param
indexedColouredCount

        //Picture Type
        this.pictureType = pictureType;

        //MimeType
        this.mimeType = mimeType;

        //Description
        this.description = description;

        this.width = width;

        this.height = height;

        this.colourDepth = colourDepth;

        this.indexedColouredCount = indexedColouredCount;
        //ImageData
        this.imageData = imageData;
    
Methods Summary
public voidcopyContent(org.jaudiotagger.tag.TagField field)
This method copies the data of the given field to the current data.

param
field The field containing the data to be taken.

        throw new UnsupportedOperationException();
    
public byte[]getBytes()

        try
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            baos.write(Utils.getSizeBEInt32(pictureType));
            baos.write(Utils.getSizeBEInt32(mimeType.length()));
            baos.write(mimeType.getBytes("ISO-8859-1"));
            baos.write(Utils.getSizeBEInt32(description.length()));
            baos.write(description.getBytes("UTF-8"));
            baos.write(Utils.getSizeBEInt32(width));
            baos.write(Utils.getSizeBEInt32(height));
            baos.write(Utils.getSizeBEInt32(colourDepth));
            baos.write(Utils.getSizeBEInt32(indexedColouredCount));
            baos.write(Utils.getSizeBEInt32(imageData.length));
            baos.write(imageData);
            return baos.toByteArray();

        }
        catch (IOException ioe)
        {
            throw new RuntimeException(ioe.getMessage());
        }
    
public intgetColourDepth()

        return colourDepth;
    
public java.lang.StringgetDescription()

        return description;
    
public intgetHeight()

        return height;
    
public java.lang.StringgetId()
Returns the Id of the represented tag field.
This value should uniquely identify a kind of tag data, like title. {@link org.jaudiotagger.audio.generic.AbstractTag} will use the "id" to summarize multiple fields.

return
Unique identifier for the fields type. (title, artist...)

        return FieldKey.COVER_ART.name();
    
public byte[]getImageData()

        return imageData;
    
public java.lang.StringgetImageUrl()

return
the image url if there is otherwise return an empty String

        if (isImageUrl())
        {
            return Utils.getString(getImageData(), 0, getImageData().length, TextEncoding.CHARSET_ISO_8859_1);
        }
        else
        {
            return "";
        }
    
public intgetIndexedColourCount()

        return indexedColouredCount;
    
public intgetLength()

        return getBytes().length;
    
public java.lang.StringgetMimeType()

        return mimeType;
    
public intgetPictureType()

        return pictureType;
    
public byte[]getRawContent()
This method delivers the binary representation of the fields data in order to be directly written to the file.

return
Binary data representing the current tag field.
throws
java.io.UnsupportedEncodingException Most tag data represents text. In some cases the underlying implementation will need to convert the text data in java to a specific charset encoding. In these cases an {@link java.io.UnsupportedEncodingException} may occur.

        return getBytes();
    
private java.lang.StringgetString(java.nio.ByteBuffer rawdata, int length, java.lang.String charset)

        byte[] tempbuffer = new byte[length];
        rawdata.get(tempbuffer);
        return new String(tempbuffer, charset);
    
public intgetWidth()

        return width;
    
private voidinitFromByteBuffer(java.nio.ByteBuffer rawdata)


          
    
        //Picture Type
        pictureType = rawdata.getInt();
        if (pictureType >= PictureTypes.getInstanceOf().getSize())
        {
            throw new InvalidFrameException("PictureType was:" + pictureType + "but the maximum allowed is " + (PictureTypes.getInstanceOf().getSize() - 1));
        }

        //MimeType
        int mimeTypeSize = rawdata.getInt();
        mimeType = getString(rawdata, mimeTypeSize, "ISO-8859-1");

        //Description
        int descriptionSize = rawdata.getInt();
        description = getString(rawdata, descriptionSize, "UTF-8");

        //Image width
        width = rawdata.getInt();

        //Image height
        height = rawdata.getInt();

        //Colour Depth
        colourDepth = rawdata.getInt();

        //Indexed Colour Count
        indexedColouredCount = rawdata.getInt();

        //ImageData
        int rawdataSize = rawdata.getInt();
        imageData = new byte[rawdataSize];
        rawdata.get(imageData);

        logger.config("Read image:" + this.toString());
    
public booleanisBinary()
Determines whether the represented field contains (is made up of) binary data, instead of text data.
Software can identify fields to be displayed because they are human readable if this method returns false.

return
true if field represents binary data (not human readable).

        return true;
    
public voidisBinary(boolean b)
This method will set the field to represent binary data.

Some implementations may support conversions.
As of now (Octobre 2005) there is no implementation really using this method to perform useful operations.

param
b true, if the field contains binary data.
deprecated
As for now is of no use. Implementations should use another way of setting this property.

        //Do nothing, always true
    
public booleanisCommon()
Identifies a field to be of common use.

Some software may differ between common and not common fields. A common one is for sure the title field. A web link may not be of common use for tagging. However some file formats, or future development of users expectations will make more fields common than now can be known.

return
true if the field is of common use.

        return true;
    
public booleanisEmpty()
Determines whether the content of the field is empty.

return
true if no data is stored (or empty String).

        return false;
    
public booleanisImageUrl()

return
true if imagedata is held as a url rather than actually being imagedata

        return getMimeType().equals(IMAGE_IS_URL);
    
public java.lang.StringtoString()

        return PictureTypes.getInstanceOf().getValueForId(pictureType) + ":" + mimeType + ":" + description + ":" + "width:" + width + ":height:" + height + ":colourdepth:" + colourDepth + ":indexedColourCount:" + indexedColouredCount + ":image size in bytes:" + imageData.length;