Debian Codegraph @

src/com/drew/metadata/mov/atoms/SubtitleSampleDescriptionAtom.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.mov.atoms;
22
23 import com.drew.lang.SequentialReader;
24 import com.drew.lang.annotations.NotNull;
25 import com.drew.metadata.mov.media.QuickTimeSubtitleDirectory;
26
27 import java.io.IOException;
28
29 /**
30 * https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP40000939-CH205-SW80
31 *
32 * @author Payton Garland
33 */
34 public class SubtitleSampleDescriptionAtom extends SampleDescriptionAtom<SubtitleSampleDescriptionAtom.SubtitleSampleDescription>
35 {
36 public SubtitleSampleDescriptionAtom(SequentialReader reader, Atom atom) throws IOException
37 {
38 super(reader, atom);
39 }
40
41 @NotNull
42 @Override
43 SubtitleSampleDescription getSampleDescription(SequentialReader reader) throws IOException
44 {
45 return new SubtitleSampleDescription(reader);
46 }
47
48 static class SubtitleSampleDescription extends SampleDescription
49 {
50 int displayFlags;
51 long defaultTextBox;
52 int fontIdentifier;
53 int fontFace;
54 int fontSize;
55 int[] foregroundColor;
56
57 public SubtitleSampleDescription(SequentialReader reader) throws IOException
58 {
59 super(reader);
60
61 displayFlags = reader.getInt32();
62 reader.skip(1); // Reserved
63 reader.skip(1); // Reserved
64 reader.skip(4); // Reserved
65 defaultTextBox = reader.getInt64();
66 reader.skip(4); // Reserved
67 fontIdentifier = reader.getInt16();
68 fontFace = reader.getInt8();
69 fontSize = reader.getInt8();
70 foregroundColor = new int[]{reader.getUInt16(), reader.getUInt16(), reader.getUInt16()};
71 // font table atom 'ftab' not currently parsed
72 }
73 }
74
75 public void addMetadata(QuickTimeSubtitleDirectory directory)
76 {
77 if (sampleDescriptions.size() == 0) {
78 return;
79 }
80
81 SubtitleSampleDescription description = sampleDescriptions.get(0);
82
83 directory.setBoolean(QuickTimeSubtitleDirectory.TAG_VERTICAL_PLACEMENT, (description.displayFlags & 0x20000000) == 0x20000000);
84 directory.setBoolean(QuickTimeSubtitleDirectory.TAG_SOME_SAMPLES_FORCED, (description.displayFlags & 0x40000000) == 0x40000000);
85 directory.setBoolean(QuickTimeSubtitleDirectory.TAG_ALL_SAMPLES_FORCED, (description.displayFlags & 0xC0000000) == 0xC0000000);
86
87 directory.setLong(QuickTimeSubtitleDirectory.TAG_DEFAULT_TEXT_BOX, description.defaultTextBox);
88 directory.setInt(QuickTimeSubtitleDirectory.TAG_FONT_IDENTIFIER, description.fontIdentifier);
89 switch (description.fontFace) {
90 case (1):
91 directory.setString(QuickTimeSubtitleDirectory.TAG_FONT_FACE, "Bold");
92 break;
93 case (2):
94 directory.setString(QuickTimeSubtitleDirectory.TAG_FONT_FACE, "Italic");
95 break;
96 case (4):
97 directory.setString(QuickTimeSubtitleDirectory.TAG_FONT_FACE, "Underline");
98 break;
99 }
100 directory.setInt(QuickTimeSubtitleDirectory.TAG_FONT_SIZE, description.fontSize);
101 directory.setIntArray(QuickTimeSubtitleDirectory.TAG_FOREGROUND_COLOR, description.foregroundColor);
102 }
103 }