Debian Codegraph @

src/com/drew/metadata/heif/HeifBoxHandler.java

raw symbols SCIP
1 /*
2 * Copyright 2002-2019 Drew Noakes and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
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 * @author Payton Garland
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 }