| 1 | package org.farng.mp3.id3; |
| 2 | |
| 3 | import org.farng.mp3.InvalidTagException; |
| 4 | import org.farng.mp3.object.ObjectByteArraySizeTerminated; |
| 5 | import org.farng.mp3.object.ObjectNumberHashMap; |
| 6 | import org.farng.mp3.object.ObjectStringNullTerminated; |
| 7 | |
| 8 | import java.io.IOException; |
| 9 | import java.io.RandomAccessFile; |
| 10 | |
| 11 | /** |
| 12 | * <h3>4.15. Attached picture</h3> |
| 13 | * <p/> |
| 14 | * <p class=t> This frame contains a picture directly related to the audio file. Image format is preferably "<a |
| 15 | * href="#png">PNG</a>" or "<a href="#jfif">JPG</a>". <i>Since JPG has the best lossy compression and PNG the best |
| 16 | * lossless compression and both are free I don't see much room for other formats. I didn't want to forbid other formats |
| 17 | * though, since there might pop up better ones in the future. Some people will probably think it is neat with ICO |
| 18 | * pictures as well.</i> Description is a short description of the picture, represented as a terminated textstring. The |
| 19 | * description has a maximum length of 64 characters, but may be empty. There may be several pictures attached to one |
| 20 | * file, each in their individual "PIC" frame, but only one with the same content descriptor. There may only be one |
| 21 | * picture with the picture type declared as picture type $01 and $02 respectively. There is a possibility to put only a |
| 22 | * link to the image file by using the 'image format' "-->" and having a complete URL instead of picture data. The |
| 23 | * use of linked files should however be used restrictively since there is the risk of separation of files. |
| 24 | * <p/> |
| 25 | * </p> |
| 26 | * <p/> |
| 27 | * <p><center> <table border=0> <tr><td nowrap>Attached picture</td><td rowspan=7> </td><td |
| 28 | * width="100%">"PIC"</td></tr> <tr><td>Frame size</td><td>$xx xx xx</td></tr> <tr><td>Text |
| 29 | * encoding</td><td>$xx</td></tr> |
| 30 | * <p/> |
| 31 | * <tr><td>Image format</td><td>$xx xx xx</td></tr> <tr><td>Picture type</td><td>$xx</td></tr> |
| 32 | * <tr><td>Description</td><td><textstring> $00 (00)</td></tr> <tr><td>Picture data</td><td><binary |
| 33 | * data></td></tr> |
| 34 | * <p/> |
| 35 | * </table> </center> |
| 36 | * <p/> |
| 37 | * <p><center> <table border=0> <tr valign=top><td rowspan=21 nowrap>Picture type: </td><td width="100%">$00 |
| 38 | * Other</td></tr> <tr><td>$01 32x32 pixels 'file icon' (<a href="#png">PNG</a> only)</td></tr> |
| 39 | * <p/> |
| 40 | * <tr><td>$02 Other file icon</td></tr> <tr><td>$03 Cover (front)</td></tr> <tr><td>$04 Cover |
| 41 | * (back)</td></tr> <tr><td>$05 Leaflet page</td></tr> |
| 42 | * <p/> |
| 43 | * <tr><td>$06 Media (e.g. lable side of CD)</td></tr> <tr><td>$07 Lead artist/lead |
| 44 | * performer/soloist</td></tr> <tr><td>$08 Artist/performer</td></tr> <tr><td>$09 Conductor</td></tr> |
| 45 | * <p/> |
| 46 | * <tr><td>$0A Band/Orchestra</td></tr> <tr><td>$0B Composer</td></tr> <tr><td>$0C Lyricist/text |
| 47 | * writer</td></tr> <tr><td>$0D Recording Location</td></tr> |
| 48 | * <p/> |
| 49 | * <tr><td>$0E During recording</td></tr> <tr><td>$0F During performance</td></tr> <tr><td>$10 |
| 50 | * Movie/video screen capture</td></tr> <tr><td>$11 A bright coloured fish</td></tr> |
| 51 | * <p/> |
| 52 | * <tr><td>$12 Illustration</td></tr> <tr><td>$13 Band/artist logotype</td></tr> <tr><td>$14 |
| 53 | * Publisher/Studio logotype</td></tr> </table> |
| 54 | * <p/> |
| 55 | * </center> |
| 56 | * |
| 57 | * @author Eric Farng |
| 58 | * @version $Revision: 1.4 $ |
| 59 | */ |
| 60 | public class FrameBodyPIC extends AbstractID3v2FrameBody { |
| 61 | |
| 62 | /** |
| 63 | * Creates a new FrameBodyPIC object. |
| 64 | */ |
| 65 | public FrameBodyPIC() { |
| 66 | super(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Creates a new FrameBodyPIC object. |
| 71 | */ |
| 72 | public FrameBodyPIC(final FrameBodyPIC body) { |
| 73 | super(body); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Creates a new FrameBodyPIC object. |
| 78 | */ |
| 79 | public FrameBodyPIC(final byte textEncoding, |
| 80 | final String imageFormat, |
| 81 | final byte pictureType, |
| 82 | final String description, |
| 83 | final byte[] data) { |
| 84 | setObject("Text Encoding", new Byte(textEncoding)); |
| 85 | setObject("Image Format", imageFormat); |
| 86 | setObject("Picture Type", new Byte(pictureType)); |
| 87 | setObject("Description", description); |
| 88 | setObject("Picture Data", data); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Creates a new FrameBodyPIC object. |
| 93 | */ |
| 94 | public FrameBodyPIC(final RandomAccessFile file) throws IOException, InvalidTagException { |
| 95 | this.read(file); |
| 96 | } |
| 97 | |
| 98 | public void setDescription(final String description) { |
| 99 | setObject("Description", description); |
| 100 | } |
| 101 | |
| 102 | public String getDescription() { |
| 103 | return (String) getObject("Description"); |
| 104 | } |
| 105 | |
| 106 | public String getIdentifier() { |
| 107 | return "PIC" + ((char) 0) + getDescription(); |
| 108 | } |
| 109 | |
| 110 | protected void setupObjectList() { |
| 111 | appendToObjectList(new ObjectNumberHashMap(ObjectNumberHashMap.TEXT_ENCODING, 1)); |
| 112 | appendToObjectList(new ObjectStringNullTerminated("Image Format")); |
| 113 | appendToObjectList(new ObjectNumberHashMap(ObjectNumberHashMap.PICTURE_TYPE, 3)); |
| 114 | appendToObjectList(new ObjectStringNullTerminated("Description")); |
| 115 | appendToObjectList(new ObjectByteArraySizeTerminated("Picture Data")); |
| 116 | } |
| 117 | } |