-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlurayPGSParser.Types.pas
215 lines (161 loc) · 8.29 KB
/
BlurayPGSParser.Types.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
{*
* URUWorks Blu-ray PGS Parser Types
*
* The contents of this file are used with permission, subject to
* the Mozilla Public License Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.mozilla.org/MPL/2.0.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2023-2024 URUWorks, [email protected].
*
* INFO: https://blog.thescorpius.com/index.php/2017/07/15/presentation-graphic-stream-sup-files-bluray-subtitle-format/
*
*}
unit BlurayPGSParser.Types;
interface
uses
FGL;
type
{ TPGS }
TPGS = packed record // Presentation Graphic Stream
PG : array[0..1] of Byte; // $50 $47 (Magic Word)
PTS : array[0..3] of Byte; // PTS (Presentation Timestamp) // Divide decimal value by 90 and the result is the value you are looking for in milliseconds
DTS : array[0..3] of Byte; // DTS (Decoding Timestamp) // Normally zero
SegmentType : Byte; // Segment Type (see Values below)
SegmentSize : array[0..1] of Byte; // Size of the segment
end;
const
// Magic Word
mwPG = $5047;
mwP = $50;
mwG = $47;
// SegmentType
stfPDS = $14;
stfODS = $15;
stfPCS = $16;
stfWDS = $17;
stfEND = $80;
type
{ TPCS }
TPCS = packed record // Presentation Composition Segment
VideoWidth : array[0..1] of Byte; // in pixels (ex. 0x780 = 1920)
VideoHeight : array[0..1] of Byte; // in pixels (ex. 0x438 = 1080)
FrameRate : Byte; // Always 0x10? (Can be ignored)
CompositionNumber : array[0..1] of Byte; // Number of this specific composition (It is incremented by one every time a graphics update occurs)
CompositionState : Byte; // Type of this composition (see Values below)
PaletteUpdateFlag : Byte; // Indicates if this PCS describes a Palette only Display Update (see Values below)
PaletteID : Byte; // ID of the palette to be used in the Palette only Display Update
NumberOfCompositionObjects : Byte; // Number of composition objects defined in this segment
end;
const
// FrameRate
frf23976 = $10; // Default
frf24 = $20;
frf25 = $30;
frf2997 = $40;
frf30 = $50;
frf50 = $60;
frf5994 = $70;
// CompositionState
csfNormal = $00; // This defines a display update, and contains only functional segments with elements that are different from the preceding composition. It’s mostly used to stop displaying objects on the screen by defining a composition with no composition objects (a value of zero in the Number of Composition Objects flag) but also used to define a new composition with new objects and objects defined since the Epoch Start.
csfAcquisitionPoint = $40; // This defines a display refresh. This is used to compose in the middle of the Epoch. It includes functional segments with new objects to be used in a new composition, replacing old objects with the same Object ID.
csfEpochStart = $80; // This defines a new display. The Epoch Start contains all functional segments needed to display a new composition on the screen.
// PaletteUpdateFlag
pufFalse = $00;
pufTrue = $80;
type
{ TCO }
TCO = packed record // Composition objects
ObjectID : array[0..1] of Byte; // ID of the ODS segment that defines the image to be shown
WindowID : Byte; // Id of the WDS segment to which the image is allocated in the PCS. Up to two images may be assigned to one window
ObjectCroppedFlag : Byte; // see Values below
ObjectHorizontalPosition : array[0..1] of Byte; // X offset from the top left pixel of the image on the screen
ObjectVerticalPosition : array[0..1] of Byte; // Y offset from the top left pixel of the image on the screen
end;
TCOCropped = packed record // Composition objects cropped
ObjectCroppingHorizontalPosition : array[0..1] of Byte; // X offset from the top left pixel of the cropped object in the screen. Only used when the Object Cropped Flag is set to $40
ObjectCroppingVerticalPosition : array[0..1] of Byte; // Y offset from the top left pixel of the cropped object in the screen. Only used when the Object Cropped Flag is set to $40
ObjectCroppingWidth : array[0..1] of Byte; // Width of the cropped object in the screen. Only used when the Object Cropped Flag is set to $40
ObjectCroppingHeightPosition : array[0..1] of Byte; // Height of the cropped object in the screen. Only used when the Object Cropped Flag is set to $40
end;
const
// ObjectCroppedFlag
ocfOff = $00; // Off
ocfForceDisplay = $40; // Force display of the cropped image object
type
{ TWDS }
TWDSNumberOfWindows = Byte; // Number of windows defined in this segment
TWDSEntry = packed record // Window Definition Segment Entry
WindowID : Byte; // ID of this window
WindowHorizontalPosition : array[0..1] of Byte; // X offset from the top left pixel of the window in the screen
WindowVerticalPosition : array[0..1] of Byte; // Y offset from the top left pixel of the window in the screen
WindowWidth : array[0..1] of Byte; // Width of the window
WindowHeight : array[0..1] of Byte; // Height of the window
end;
{ TPDS }
TPDS = packed record // Palette Definition Segment
PaletteID : Byte; // ID of the palette
PaletteVersionNumber : Byte; // Version of this palette within the Epoch
end;
TPDSEntry = packed record // Palette Definition Segment Entry
PaletteEntryID : Byte; // Entry number of the palette
Luminance : Byte; // Luminance (Y value)
ColorDifferenceRed : Byte; // Color Difference Red (Cr value)
ColorDifferenceBlue : Byte; // Color Difference Blue (Cb value)
Transparency : Byte; // Transparency (Alpha value)
end;
{ TODS }
TODS = packed record // Object Definition Segment
ObjectID : array[0..1] of Byte; // ID of this object
ObjectVersionNumber : Byte; // Version of this object
LastInSequenceFlag : Byte; // If the image is split into a series of consecutive fragments, the last fragment has this flag set (see Values below)
end;
TODSEntry = packed record // Object Definition Segment Entry
ObjectDataLength : array[0..2] of Byte; // The length of the Run-length Encoding (RLE) data buffer with the compressed image data +4
Width : array[0..1] of Byte; // Width of the image
Height : array[0..1] of Byte; // Height of the image
end;
TODSObjectData = array of Byte; // This is the image data compressed using Run-length Encoding (RLE). The size of the data is defined in the Object Data Length field -4
const
// LastInSequenceFlag
lsfLast = $40; // Last in sequence
lsfFirst = $80; // First in sequence
lsfFirstAndLast = $C0; // First and last in sequence
type
{ TDisplaySet }
TPictureBuffer = packed record
Offset : Int64;
Size : Integer;
end;
TPDSEntries = array of TPDSEntry;
TPaletteItem = packed record
ID : Byte;
Entries : TPDSEntries;
end;
TPictures = array of TPictureBuffer;
TPalettes = array of TPaletteItem;
PDisplaySet = ^TDisplaySet;
TDisplaySet = packed record
InCue,
OutCue : Integer;
X, Y,
Width,
Height : Integer;
PaletteId : Byte;
Palettes : TPalettes;
Pictures : TPictures;
Completed : Boolean;
IsForced : Boolean;
Text : String;
end;
TDisplaySetList = specialize TFPGList<PDisplaySet>;
//------------------------------------------------------------------------------
implementation
//------------------------------------------------------------------------------
end.