2
* @author : Paul Taylor
5
* Version @version:$Id: FrameBodyPIC.java,v 1.20 2009/11/12 15:42:56 paultaylor Exp $
7
* MusicTag Copyright (C)2003,2004
9
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
10
* General Public License as published by the Free Software Foundation; either version 2.1 of the License,
11
* or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License along with this library; if not,
18
* you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
package org.jaudiotagger.tag.id3.framebody;
26
import org.jaudiotagger.tag.InvalidTagException;
27
import org.jaudiotagger.tag.datatype.*;
28
import org.jaudiotagger.tag.id3.ID3v22Frames;
29
import org.jaudiotagger.tag.id3.valuepair.ImageFormats;
30
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
31
import org.jaudiotagger.tag.reference.PictureTypes;
33
import java.io.ByteArrayOutputStream;
34
import java.nio.ByteBuffer;
37
* ID3v22 Attached Picture
39
* <p> This frame contains a picture directly related to the audio file.
40
* Image format is preferably "PNG" [PNG] or "JPG" [JFIF]. Description
41
* is a short description of the picture, represented as a terminated
42
* textstring. The description has a maximum length of 64 characters,
43
* but may be empty. There may be several pictures attached to one file,
44
* each in their individual "PIC" frame, but only one with the same
45
* ontent descriptor. There may only be one picture with the picture
46
* type declared as picture type $01 and $02 respectively. There is a
47
* possibility to put only a link to the image file by using the 'image
48
* format' "-->" and having a complete URL [URL] instead of picture data.
49
* The use of linked files should however be used restrictively since
50
* there is the risk of separation of files.
52
* Attached picture "PIC"
53
* Frame size $xx xx xx
55
* Image format $xx xx xx
57
* Description <textstring> $00 (00)
58
* Picture data <binary data>
61
* Picture type: $00 Other
62
* $01 32x32 pixels 'file icon' (PNG only)
67
* $06 Media (e.g. lable side of CD)
68
* $07 Lead artist/lead performer/soloist
69
* $08 Artist/performer
73
* $0C Lyricist/text writer
74
* $0D Recording Location
75
* $0E During recording
76
* $0F During performance
77
* $10 Movie/video screen capture
78
* $11 A bright coloured fish
80
* $13 Band/artist logotype
81
* $14 Publisher/Studio logotype
83
public class FrameBodyPIC extends AbstractID3v2FrameBody implements ID3v22FrameBody
85
public static final String IMAGE_IS_URL = "-->";
88
* Creates a new FrameBodyPIC datatype.
92
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
95
public FrameBodyPIC(FrameBodyPIC body)
101
* Creates a new FrameBodyPIC datatype.
103
* @param textEncoding
109
public FrameBodyPIC(byte textEncoding, String imageFormat, byte pictureType, String description, byte[] data)
111
this.setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
112
this.setObjectValue(DataTypes.OBJ_IMAGE_FORMAT, imageFormat);
113
this.setPictureType(pictureType);
114
this.setDescription(description);
115
this.setImageData(data);
119
* Conversion from v2 PIC to v3/v4 APIC
122
public FrameBodyPIC(FrameBodyAPIC body)
124
this.setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding());
125
this.setObjectValue(DataTypes.OBJ_IMAGE_FORMAT, ImageFormats.getFormatForMimeType((String) body.getObjectValue(DataTypes.OBJ_MIME_TYPE)));
126
this.setObjectValue(DataTypes.OBJ_PICTURE_DATA, body.getObjectValue(DataTypes.OBJ_PICTURE_DATA));
127
this.setDescription(body.getDescription());
128
this.setImageData(body.getImageData());
132
* Creates a new FrameBodyPIC datatype.
136
* @throws InvalidTagException if unable to create framebody from buffer
138
public FrameBodyPIC(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
140
super(byteBuffer, frameSize);
144
* Set a description of the image
146
* @param description of the image
148
public void setDescription(String description)
150
setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
154
* Get a description of the image
156
* @return a description of the image
158
public String getDescription()
160
return (String) getObjectValue(DataTypes.OBJ_DESCRIPTION);
168
public void setImageData(byte[] imageData)
170
setObjectValue(DataTypes.OBJ_PICTURE_DATA, imageData);
178
public byte[] getImageData()
180
return (byte[]) getObjectValue(DataTypes.OBJ_PICTURE_DATA);
188
public void setPictureType(byte pictureType)
190
setObjectValue(DataTypes.OBJ_PICTURE_TYPE, pictureType);
194
* @return picturetype
196
public int getPictureType()
198
return ((Long) getObjectValue(DataTypes.OBJ_PICTURE_TYPE)).intValue();
203
* The ID3v2 frame identifier
205
* @return the ID3v2 frame identifier for this frame type
207
public String getIdentifier()
209
return ID3v22Frames.FRAME_ID_V2_ATTACHED_PICTURE;
214
* If the description cannot be encoded using current encoder, change the encoder
216
public void write(ByteArrayOutputStream tagBuffer)
218
if (!((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded())
220
this.setTextEncoding(TextEncoding.UTF_16);
222
super.write(tagBuffer);
226
* Get a description of the image
228
* @return a description of the image
230
public String getFormatType()
232
return (String) getObjectValue(DataTypes.OBJ_IMAGE_FORMAT);
235
public boolean isImageUrl()
237
return getFormatType() != null && getFormatType().equals(IMAGE_IS_URL);
243
protected void setupObjectList()
245
objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
246
objectList.add(new StringFixedLength(DataTypes.OBJ_IMAGE_FORMAT, this, 3));
247
objectList.add(new NumberHashMap(DataTypes.OBJ_PICTURE_TYPE, this, PictureTypes.PICTURE_TYPE_FIELD_SIZE));
248
objectList.add(new StringNullTerminated(DataTypes.OBJ_DESCRIPTION, this));
249
objectList.add(new ByteArraySizeTerminated(DataTypes.OBJ_PICTURE_DATA, this));
2
* @author : Paul Taylor
5
* Version @version:$Id: FrameBodyPIC.java 836 2009-11-12 15:44:07Z paultaylor $
7
* MusicTag Copyright (C)2003,2004
9
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
10
* General Public License as published by the Free Software Foundation; either version 2.1 of the License,
11
* or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
* See the GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License along with this library; if not,
18
* you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
package org.jaudiotagger.tag.id3.framebody;
26
import org.jaudiotagger.tag.InvalidTagException;
27
import org.jaudiotagger.tag.datatype.*;
28
import org.jaudiotagger.tag.id3.ID3v22Frames;
29
import org.jaudiotagger.tag.id3.valuepair.ImageFormats;
30
import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
31
import org.jaudiotagger.tag.reference.PictureTypes;
33
import java.io.ByteArrayOutputStream;
34
import java.nio.ByteBuffer;
37
* ID3v22 Attached Picture
39
* <p> This frame contains a picture directly related to the audio file.
40
* Image format is preferably "PNG" [PNG] or "JPG" [JFIF]. Description
41
* is a short description of the picture, represented as a terminated
42
* textstring. The description has a maximum length of 64 characters,
43
* but may be empty. There may be several pictures attached to one file,
44
* each in their individual "PIC" frame, but only one with the same
45
* ontent descriptor. There may only be one picture with the picture
46
* type declared as picture type $01 and $02 respectively. There is a
47
* possibility to put only a link to the image file by using the 'image
48
* format' "-->" and having a complete URL [URL] instead of picture data.
49
* The use of linked files should however be used restrictively since
50
* there is the risk of separation of files.
52
* Attached picture "PIC"
53
* Frame size $xx xx xx
55
* Image format $xx xx xx
57
* Description <textstring> $00 (00)
58
* Picture data <binary data>
61
* Picture type: $00 Other
62
* $01 32x32 pixels 'file icon' (PNG only)
67
* $06 Media (e.g. lable side of CD)
68
* $07 Lead artist/lead performer/soloist
69
* $08 Artist/performer
73
* $0C Lyricist/text writer
74
* $0D Recording Location
75
* $0E During recording
76
* $0F During performance
77
* $10 Movie/video screen capture
78
* $11 A bright coloured fish
80
* $13 Band/artist logotype
81
* $14 Publisher/Studio logotype
83
public class FrameBodyPIC extends AbstractID3v2FrameBody implements ID3v22FrameBody
85
public static final String IMAGE_IS_URL = "-->";
88
* Creates a new FrameBodyPIC datatype.
92
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
95
public FrameBodyPIC(FrameBodyPIC body)
101
* Creates a new FrameBodyPIC datatype.
103
* @param textEncoding
109
public FrameBodyPIC(byte textEncoding, String imageFormat, byte pictureType, String description, byte[] data)
111
this.setObjectValue(DataTypes.OBJ_TEXT_ENCODING, textEncoding);
112
this.setObjectValue(DataTypes.OBJ_IMAGE_FORMAT, imageFormat);
113
this.setPictureType(pictureType);
114
this.setDescription(description);
115
this.setImageData(data);
119
* Conversion from v2 PIC to v3/v4 APIC
122
public FrameBodyPIC(FrameBodyAPIC body)
124
this.setObjectValue(DataTypes.OBJ_TEXT_ENCODING, body.getTextEncoding());
125
this.setObjectValue(DataTypes.OBJ_IMAGE_FORMAT, ImageFormats.getFormatForMimeType((String) body.getObjectValue(DataTypes.OBJ_MIME_TYPE)));
126
this.setObjectValue(DataTypes.OBJ_PICTURE_DATA, body.getObjectValue(DataTypes.OBJ_PICTURE_DATA));
127
this.setDescription(body.getDescription());
128
this.setImageData(body.getImageData());
132
* Creates a new FrameBodyPIC datatype.
136
* @throws InvalidTagException if unable to create framebody from buffer
138
public FrameBodyPIC(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException
140
super(byteBuffer, frameSize);
144
* Set a description of the image
146
* @param description of the image
148
public void setDescription(String description)
150
setObjectValue(DataTypes.OBJ_DESCRIPTION, description);
154
* Get a description of the image
156
* @return a description of the image
158
public String getDescription()
160
return (String) getObjectValue(DataTypes.OBJ_DESCRIPTION);
168
public void setImageData(byte[] imageData)
170
setObjectValue(DataTypes.OBJ_PICTURE_DATA, imageData);
178
public byte[] getImageData()
180
return (byte[]) getObjectValue(DataTypes.OBJ_PICTURE_DATA);
188
public void setPictureType(byte pictureType)
190
setObjectValue(DataTypes.OBJ_PICTURE_TYPE, pictureType);
194
* @return picturetype
196
public int getPictureType()
198
return ((Long) getObjectValue(DataTypes.OBJ_PICTURE_TYPE)).intValue();
203
* The ID3v2 frame identifier
205
* @return the ID3v2 frame identifier for this frame type
207
public String getIdentifier()
209
return ID3v22Frames.FRAME_ID_V2_ATTACHED_PICTURE;
214
* If the description cannot be encoded using current encoder, change the encoder
216
public void write(ByteArrayOutputStream tagBuffer)
218
if (!((AbstractString) getObject(DataTypes.OBJ_DESCRIPTION)).canBeEncoded())
220
this.setTextEncoding(TextEncoding.UTF_16);
222
super.write(tagBuffer);
226
* Get a description of the image
228
* @return a description of the image
230
public String getFormatType()
232
return (String) getObjectValue(DataTypes.OBJ_IMAGE_FORMAT);
235
public boolean isImageUrl()
237
return getFormatType() != null && getFormatType().equals(IMAGE_IS_URL);
243
protected void setupObjectList()
245
objectList.add(new NumberHashMap(DataTypes.OBJ_TEXT_ENCODING, this, TextEncoding.TEXT_ENCODING_FIELD_SIZE));
246
objectList.add(new StringFixedLength(DataTypes.OBJ_IMAGE_FORMAT, this, 3));
247
objectList.add(new NumberHashMap(DataTypes.OBJ_PICTURE_TYPE, this, PictureTypes.PICTURE_TYPE_FIELD_SIZE));
248
objectList.add(new StringNullTerminated(DataTypes.OBJ_DESCRIPTION, this));
249
objectList.add(new ByteArraySizeTerminated(DataTypes.OBJ_PICTURE_DATA, this));