summaryrefslogtreecommitdiffstats
path: root/contrib/patch-mpeg4ip-colr.patch
blob: 105267b7c9f228eb92ed199273291a83b3ba9938 (plain)
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
216
217
218
219
220
221
222
223
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/Makefile.am mpeg4ip/lib/mp4v2/Makefile.am
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/Makefile.am	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/Makefile.am	2008-06-17 16:21:54.000000000 -0700
@@ -14,6 +14,7 @@
 	atom_amr.cpp \
 	atom_avc1.cpp \
 	atom_avcC.cpp \
+	atom_colr.cpp \
 	atom_d263.cpp \
 	atom_damr.cpp \
 	atom_dref.cpp \
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/Makefile.in mpeg4ip/lib/mp4v2/Makefile.in
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/Makefile.in	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/Makefile.in	2008-06-17 16:21:54.000000000 -0700
@@ -53,7 +53,7 @@
 LTLIBRARIES = $(lib_LTLIBRARIES)
 libmp4v2_la_LIBADD =
 am_libmp4v2_la_OBJECTS = 3gp.lo atom_amr.lo atom_avc1.lo atom_avcC.lo \
-	atom_d263.lo atom_damr.lo atom_dref.lo atom_elst.lo \
+	atom_colr.lo atom_d263.lo atom_damr.lo atom_dref.lo atom_elst.lo \
 	atom_enca.lo atom_encv.lo atom_free.lo atom_ftyp.lo \
 	atom_gmin.lo atom_text.lo atom_ac3.lo \
 	atom_hdlr.lo atom_hinf.lo atom_hnti.lo atom_href.lo \
@@ -76,6 +76,7 @@
 @AMDEP_TRUE@	./$(DEPDIR)/atom_ac3.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/atom_avc1.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/atom_avcC.Plo \
+@AMDEP_TRUE@	./$(DEPDIR)/atom_colr.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/atom_d263.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/atom_damr.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/atom_dref.Plo \
@@ -347,6 +348,7 @@
 	atom_amr.cpp \
 	atom_avc1.cpp \
 	atom_avcC.cpp \
+	atom_colr.cpp \
 	atom_d263.cpp \
 	atom_damr.cpp \
 	atom_dref.cpp \
@@ -503,6 +505,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_amr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_avc1.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_avcC.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_colr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_d263.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_damr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atom_dref.Plo@am__quote@
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/atom_colr.cpp mpeg4ip/lib/mp4v2/atom_colr.cpp
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/atom_colr.cpp	1969-12-31 16:00:00.000000000 -0800
+++ mpeg4ip/lib/mp4v2/atom_colr.cpp	2008-06-18 13:51:37.000000000 -0700
@@ -0,0 +1,45 @@
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (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/
+ * 
+ * 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.
+ * 
+ * The Original Code is MPEG4IP.
+ * 
+ * Contributer has declined to give copyright information, and gives
+ * it freely to the world.
+ * 
+ * Contributor(s): 
+ */
+
+#include "mp4common.h"
+
+MP4ColrAtom::MP4ColrAtom() 
+	: MP4Atom("colr") 
+{
+    MP4StringProperty* cpt = new MP4StringProperty("colorParameterType");
+    cpt->SetFixedLength(4);
+    AddProperty(cpt); /* 0 */
+
+	AddProperty( /* 1 */ new MP4Integer16Property("primariesIndex"));
+
+	AddProperty( /* 2 */ new MP4Integer16Property("transferFunctionIndex")); 
+
+	AddProperty( /* 3 */ new MP4Integer16Property("matrixIndex")); 
+}
+
+void MP4ColrAtom::Generate()
+{
+	MP4Atom::Generate();
+
+	((MP4StringProperty*)m_pProperties[0])->SetValue("nclc");
+    // default to ITU BT.709 values
+	((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
+	((MP4Integer16Property*)m_pProperties[2])->SetValue(1);
+	((MP4Integer16Property*)m_pProperties[3])->SetValue(1);
+}
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/atom_stsd.cpp mpeg4ip/lib/mp4v2/atom_stsd.cpp
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/atom_stsd.cpp	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/atom_stsd.cpp	2008-06-17 16:21:54.000000000 -0700
@@ -52,6 +52,7 @@
 	ExpectChildAtom("text", Optional, Many);
 	ExpectChildAtom("pasp", Optional, Many);
 	ExpectChildAtom("ac-3", Optional, Many);
+	ExpectChildAtom("colr", Optional, Many);
 }
 
 void MP4StsdAtom::Read() 
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/atoms.h mpeg4ip/lib/mp4v2/atoms.h
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/atoms.h	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/atoms.h	2008-06-17 16:21:54.000000000 -0700
@@ -406,4 +406,10 @@
     void Generate();
 };
 
+class MP4ColrAtom : public MP4Atom {
+ public:
+    MP4ColrAtom();
+    void Generate();
+};
+
 #endif /* __MP4_ATOMS_INCLUDED__ */
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4.cpp mpeg4ip/lib/mp4v2/mp4.cpp
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4.cpp	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/mp4.cpp	2008-06-17 16:21:54.000000000 -0700
@@ -1003,6 +1003,21 @@
 	return MP4_INVALID_TRACK_ID;
 }
 
+extern "C" MP4TrackId MP4AddColr(
+	MP4FileHandle hFile, MP4TrackId refTrackId, u_int16_t pri, u_int16_t tran, u_int16_t mat)
+{
+	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
+		try {
+			return ((MP4File*)hFile)->AddColr(refTrackId, pri, tran, mat);
+		}
+		catch (MP4Error* e) {
+			PRINT_ERROR(e);
+			delete e;
+		}
+	}
+	return MP4_INVALID_TRACK_ID;
+}
+
 
 extern "C" MP4TrackId MP4CloneTrack(
 	MP4FileHandle srcFile, 
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4.h mpeg4ip/lib/mp4v2/mp4.h
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4.h	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/mp4.h	2008-06-18 14:03:17.000000000 -0700
@@ -559,6 +559,13 @@
     u_int32_t hSpacing,
     u_int32_t vSpacing);
 
+MP4TrackId MP4AddColr(
+	MP4FileHandle hFile, 
+	MP4TrackId refTrackId,
+    u_int16_t primary,
+    u_int16_t transfer,
+    u_int16_t matrix);
+
 MP4TrackId MP4CloneTrack(
 	MP4FileHandle srcFile, 
 	MP4TrackId srcTrackId,
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4atom.cpp mpeg4ip/lib/mp4v2/mp4atom.cpp
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4atom.cpp	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/mp4atom.cpp	2008-06-17 16:21:54.000000000 -0700
@@ -90,6 +90,8 @@
     case 'c':
       if (ATOMID(type) == ATOMID("chap")) {
 	pAtom = new MP4TrefTypeAtom(type);
+      } else if (ATOMID(type) == ATOMID("colr")) {
+	pAtom = new MP4ColrAtom();
 	  }
 	  break;
 
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4file.cpp mpeg4ip/lib/mp4v2/mp4file.cpp
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4file.cpp	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/mp4file.cpp	2008-06-17 16:21:54.000000000 -0700
@@ -2000,6 +2000,33 @@
 	return trackId;
 }
 
+MP4TrackId MP4File::AddColr(MP4TrackId trackId,
+                            u_int16_t primariesIndex,
+                            u_int16_t transferFunctionIndex,
+                            u_int16_t matrixIndex)
+{
+	// validate reference track id
+  (void)FindTrackIndex(trackId);
+    const char *format = GetTrackMediaDataName (trackId);
+    
+    if (!strcasecmp(format, "avc1"))
+    {
+        AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.avc1"), "colr");
+        SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.colr.primariesIndex", primariesIndex);
+        SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.colr.transferFunctionIndex", transferFunctionIndex);
+        SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.colr.matrixIndex", matrixIndex);
+    }
+    else if (!strcasecmp(format, "mp4v"))
+    {
+        AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.mp4v"), "colr");
+        SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.colr.primariesIndex", primariesIndex);
+        SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.colr.transferFunctionIndex", transferFunctionIndex);
+        SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.colr.matrixIndex", matrixIndex);
+    }
+
+	return trackId;
+}
+
 void MP4File::DeleteTrack(MP4TrackId trackId)
 {
 	ProtectWriteOperation("MP4DeleteTrack");
diff -Nur -x Makefile -x config.log -x config.status -x libtool -x '*.Plo' -x '*.lo' ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4file.h mpeg4ip/lib/mp4v2/mp4file.h
--- ../handbrake/contrib/mpeg4ip/lib/mp4v2/mp4file.h	2008-06-13 11:22:55.000000000 -0700
+++ mpeg4ip/lib/mp4v2/mp4file.h	2008-06-17 16:21:54.000000000 -0700
@@ -305,6 +305,7 @@
 	MP4TrackId AddChapterTextTrack(MP4TrackId refTrackId);
 
 	MP4TrackId AddPixelAspectRatio(MP4TrackId trackId, u_int32_t hSpacing, u_int32_t vSpacing);
+	MP4TrackId AddColr(MP4TrackId trackId, u_int16_t pri, u_int16_t tran, u_int16_t mat);
 
 	MP4SampleId GetTrackNumberOfSamples(MP4TrackId trackId);