| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.heif.boxes; |
| 22 |
|
| 23 |
import com.drew.lang.Charsets; |
| 24 |
import com.drew.lang.SequentialByteArrayReader; |
| 25 |
import com.drew.lang.SequentialReader; |
| 26 |
import com.drew.metadata.heif.HeifDirectory; |
| 27 |
|
| 28 |
import java.io.IOException; |
| 29 |
import java.util.HashMap; |
| 30 |
import java.util.Map; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class ItemInfoBox extends FullBox |
| 36 |
{ |
| 37 |
long entryCount; |
| 38 |
Map<Long, ItemInfoEntry> entries; |
| 39 |
|
| 40 |
public ItemInfoBox(SequentialReader reader, Box box) throws IOException |
| 41 |
{ |
| 42 |
super(reader, box); |
| 43 |
|
| 44 |
if (version == 0) { |
| 45 |
entryCount = reader.getUInt16(); |
| 46 |
} else { |
| 47 |
entryCount = reader.getUInt32(); |
| 48 |
} |
| 49 |
entries = new HashMap<Long, ItemInfoEntry>(); |
| 50 |
for (int i = 1; i <= entryCount; i++) |
| 51 |
{ |
| 52 |
Box entryBox = new Box(reader); |
| 53 |
SequentialByteArrayReader byteReader = new SequentialByteArrayReader(reader.getBytes((int)entryBox.size - 8)); |
| 54 |
ItemInfoEntry itemInfoEntry = new ItemInfoEntry(byteReader, entryBox); |
| 55 |
entries.put(itemInfoEntry.itemID, itemInfoEntry); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public static class ItemInfoEntry extends FullBox |
| 60 |
{ |
| 61 |
long itemID; |
| 62 |
long itemProtectionIndex; |
| 63 |
String itemName; |
| 64 |
String contentType; |
| 65 |
String contentEncoding; |
| 66 |
String extensionType; |
| 67 |
String itemType; |
| 68 |
String itemUriType; |
| 69 |
|
| 70 |
public ItemInfoEntry(SequentialReader reader, Box box) throws IOException |
| 71 |
{ |
| 72 |
super(reader, box); |
| 73 |
|
| 74 |
|
| 75 |
int headerLength = 8; |
| 76 |
|
| 77 |
if ((version == 0) || (version == 1)) { |
| 78 |
itemID = reader.getUInt16(); |
| 79 |
itemProtectionIndex = reader.getUInt16(); |
| 80 |
itemName = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); |
| 81 |
contentType = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); |
| 82 |
if (box.size - reader.getPosition() - headerLength > 0) { |
| 83 |
extensionType = reader.getNullTerminatedString((int) (box.size - reader.getPosition() - headerLength), Charsets.UTF_8); |
| 84 |
} |
| 85 |
} |
| 86 |
if (version == 1) { |
| 87 |
if (box.size - 28 >= 4) { |
| 88 |
contentEncoding = reader.getString(4); |
| 89 |
} |
| 90 |
} |
| 91 |
if (version >= 2) { |
| 92 |
if (version == 2) { |
| 93 |
itemID = reader.getUInt16(); |
| 94 |
} else if (version == 3) { |
| 95 |
itemID = reader.getUInt32(); |
| 96 |
} |
| 97 |
itemProtectionIndex = reader.getUInt16(); |
| 98 |
itemType = reader.getString(4); |
| 99 |
|
| 100 |
itemName = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); |
| 101 |
if (itemType.equals("mime")) { |
| 102 |
contentType = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); |
| 103 |
if (box.size - reader.getPosition() - headerLength > 0) { |
| 104 |
contentEncoding = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); |
| 105 |
} |
| 106 |
} else if (itemType.equals("uri ")) { |
| 107 |
itemUriType = reader.getString((int)(box.size - reader.getPosition() - headerLength)); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
public String getItemType() { |
| 113 |
return itemType; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
public void addMetadata(HeifDirectory directory) |
| 118 |
{ |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
public ItemInfoEntry getEntry(final long id) { |
| 123 |
return entries.get(id); |
| 124 |
} |
| 125 |
} |