| 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; |
| 22 |
|
| 23 |
import com.drew.imaging.heif.HeifHandler; |
| 24 |
import com.drew.lang.SequentialByteArrayReader; |
| 25 |
import com.drew.lang.SequentialReader; |
| 26 |
import com.drew.lang.annotations.NotNull; |
| 27 |
import com.drew.metadata.Metadata; |
| 28 |
import com.drew.metadata.heif.boxes.*; |
| 29 |
|
| 30 |
import java.io.IOException; |
| 31 |
import java.util.Arrays; |
| 32 |
import java.util.List; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class HeifBoxHandler extends HeifHandler<HeifDirectory> |
| 38 |
{ |
| 39 |
HandlerBox handlerBox; |
| 40 |
|
| 41 |
private HeifHandlerFactory handlerFactory = new HeifHandlerFactory(this); |
| 42 |
|
| 43 |
public HeifBoxHandler(Metadata metadata) |
| 44 |
{ |
| 45 |
super(metadata); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
protected HeifDirectory getDirectory() |
| 50 |
{ |
| 51 |
return new HeifDirectory(); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public boolean shouldAcceptBox(@NotNull Box box) |
| 56 |
{ |
| 57 |
List<String> boxes = Arrays.asList(HeifBoxTypes.BOX_FILE_TYPE, |
| 58 |
HeifBoxTypes.BOX_HANDLER, |
| 59 |
HeifBoxTypes.BOX_HVC1); |
| 60 |
|
| 61 |
return boxes.contains(box.type); |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public boolean shouldAcceptContainer(@NotNull Box box) |
| 66 |
{ |
| 67 |
return box.type.equals(HeifContainerTypes.BOX_METADATA) |
| 68 |
|| box.type.equals(HeifContainerTypes.BOX_IMAGE_PROPERTY) |
| 69 |
|| box.type.equals(HeifContainerTypes.BOX_ITEM_PROPERTY); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public HeifHandler<?> processBox(@NotNull Box box, @NotNull byte[] payload) throws IOException |
| 74 |
{ |
| 75 |
if (payload != null) { |
| 76 |
SequentialReader reader = new SequentialByteArrayReader(payload); |
| 77 |
if (box.type.equals(HeifBoxTypes.BOX_FILE_TYPE)) { |
| 78 |
processFileType(reader, box); |
| 79 |
} else if (box.type.equals(HeifBoxTypes.BOX_HANDLER)) { |
| 80 |
handlerBox = new HandlerBox(reader, box); |
| 81 |
return handlerFactory.getHandler(handlerBox, metadata); |
| 82 |
} |
| 83 |
} |
| 84 |
return this; |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public void processContainer(@NotNull Box box, @NotNull SequentialReader reader) throws IOException |
| 89 |
{ |
| 90 |
if (box.type.equals(HeifContainerTypes.BOX_METADATA)) { |
| 91 |
new FullBox(reader, box); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
private void processFileType(@NotNull SequentialReader reader, @NotNull Box box) throws IOException |
| 96 |
{ |
| 97 |
FileTypeBox fileTypeBox = new FileTypeBox(reader, box); |
| 98 |
fileTypeBox.addMetadata(directory); |
| 99 |
if (!fileTypeBox.getCompatibleBrands().contains("mif1")) { |
| 100 |
directory.addError("File Type Box does not contain required brand, mif1"); |
| 101 |
} |
| 102 |
} |
| 103 |
} |