@@ -43,12 +43,16 @@ public static final class Builder {
4343 private @ C .ColorRange int colorRange ;
4444 private @ C .ColorTransfer int colorTransfer ;
4545 @ Nullable private byte [] hdrStaticInfo ;
46+ private int lumaBitdepth ;
47+ private int chromaBitdepth ;
4648
4749 /** Creates a new instance with default values. */
4850 public Builder () {
4951 colorSpace = Format .NO_VALUE ;
5052 colorRange = Format .NO_VALUE ;
5153 colorTransfer = Format .NO_VALUE ;
54+ lumaBitdepth = Format .NO_VALUE ;
55+ chromaBitdepth = Format .NO_VALUE ;
5256 }
5357
5458 /** Creates a new instance to build upon the provided {@link ColorInfo}. */
@@ -57,6 +61,8 @@ private Builder(ColorInfo colorInfo) {
5761 this .colorRange = colorInfo .colorRange ;
5862 this .colorTransfer = colorInfo .colorTransfer ;
5963 this .hdrStaticInfo = colorInfo .hdrStaticInfo ;
64+ this .lumaBitdepth = colorInfo .lumaBitdepth ;
65+ this .chromaBitdepth = colorInfo .chromaBitdepth ;
6066 }
6167
6268 /**
@@ -116,19 +122,44 @@ public Builder setHdrStaticInfo(@Nullable byte[] hdrStaticInfo) {
116122 return this ;
117123 }
118124
125+ /**
126+ * Sets the luma bit depth.
127+ *
128+ * @param lumaBitdepth The lumaBitdepth. The default value is {@link Format#NO_VALUE}.
129+ * @return The builder.
130+ */
131+ @ CanIgnoreReturnValue
132+ public Builder setLumaBitdepth (int lumaBitdepth ) {
133+ this .lumaBitdepth = lumaBitdepth ;
134+ return this ;
135+ }
136+
137+ /**
138+ * Sets chroma bit depth.
139+ *
140+ * @param chromaBitdepth The chromaBitdepth. The default value is {@link Format#NO_VALUE}.
141+ * @return The builder.
142+ */
143+ @ CanIgnoreReturnValue
144+ public Builder setChromaBitdepth (int chromaBitdepth ) {
145+ this .chromaBitdepth = chromaBitdepth ;
146+ return this ;
147+ }
148+
119149 /** Builds a new {@link ColorInfo} instance. */
120150 public ColorInfo build () {
121- return new ColorInfo (colorSpace , colorRange , colorTransfer , hdrStaticInfo );
151+ return new ColorInfo (
152+ colorSpace , colorRange , colorTransfer , hdrStaticInfo , lumaBitdepth , chromaBitdepth );
122153 }
123154 }
124155
125156 /** Color info representing SDR BT.709 limited range, which is a common SDR video color format. */
126157 public static final ColorInfo SDR_BT709_LIMITED =
127- new ColorInfo (
128- C .COLOR_SPACE_BT709 ,
129- C .COLOR_RANGE_LIMITED ,
130- C .COLOR_TRANSFER_SDR ,
131- /* hdrStaticInfo= */ null );
158+ new ColorInfo . Builder ()
159+ . setColorSpace ( C .COLOR_SPACE_BT709 )
160+ . setColorRange ( C .COLOR_RANGE_LIMITED )
161+ . setColorTransfer ( C .COLOR_TRANSFER_SDR )
162+ . build ( );
132163
133164 /**
134165 * Color info representing SDR sRGB in accordance with {@link
@@ -213,6 +244,12 @@ public static boolean isTransferHdr(@Nullable ColorInfo colorInfo) {
213244 /** HdrStaticInfo as defined in CTA-861.3, or null if none specified. */
214245 @ Nullable public final byte [] hdrStaticInfo ;
215246
247+ /** The bit depth of the luma samples of the video. */
248+ public final int lumaBitdepth ;
249+
250+ /** The bit depth of the chroma samples of the video. It may differ from the luma bit depth. */
251+ public final int chromaBitdepth ;
252+
216253 // Lazily initialized hashcode.
217254 private int hashCode ;
218255
@@ -231,10 +268,34 @@ public ColorInfo(
231268 @ C .ColorRange int colorRange ,
232269 @ C .ColorTransfer int colorTransfer ,
233270 @ Nullable byte [] hdrStaticInfo ) {
271+ this (colorSpace , colorRange , colorTransfer , hdrStaticInfo , Format .NO_VALUE , Format .NO_VALUE );
272+ }
273+
274+ /**
275+ * Constructs the ColorInfo.
276+ *
277+ * @param colorSpace The color space of the video.
278+ * @param colorRange The color range of the video.
279+ * @param colorTransfer The color transfer characteristics of the video.
280+ * @param hdrStaticInfo HdrStaticInfo as defined in CTA-861.3, or null if none specified.
281+ * @param lumaBitdepth The bit depth of the luma samples of the video.
282+ * @param chromaBitdepth The bit depth of the chroma samples of the video.
283+ * @deprecated Use {@link Builder}.
284+ */
285+ @ Deprecated
286+ public ColorInfo (
287+ @ C .ColorSpace int colorSpace ,
288+ @ C .ColorRange int colorRange ,
289+ @ C .ColorTransfer int colorTransfer ,
290+ @ Nullable byte [] hdrStaticInfo ,
291+ int lumaBitdepth ,
292+ int chromaBitdepth ) {
234293 this .colorSpace = colorSpace ;
235294 this .colorRange = colorRange ;
236295 this .colorTransfer = colorTransfer ;
237296 this .hdrStaticInfo = hdrStaticInfo ;
297+ this .lumaBitdepth = lumaBitdepth ;
298+ this .chromaBitdepth = chromaBitdepth ;
238299 }
239300
240301 /** Returns a {@link Builder} initialized with the values of this instance. */
@@ -245,9 +306,27 @@ public Builder buildUpon() {
245306 /**
246307 * Returns whether this instance is valid.
247308 *
248- * <p>This instance is valid if no members are {@link Format#NO_VALUE} .
309+ * <p>This instance is valid if at least one between bitdepths and DataSpace info are valid .
249310 */
250311 public boolean isValid () {
312+ return isBitdepthValid () || isDataSpaceValid ();
313+ }
314+
315+ /**
316+ * Returns whether this instance has valid bitdepths.
317+ *
318+ * <p>This instance has valid bitdepths if none of them is {@link Format#NO_VALUE}.
319+ */
320+ public boolean isBitdepthValid () {
321+ return lumaBitdepth != Format .NO_VALUE && chromaBitdepth != Format .NO_VALUE ;
322+ }
323+
324+ /**
325+ * Returns whether this instance has valid DataSpace members.
326+ *
327+ * <p>This instance is valid if no DataSpace members are {@link Format#NO_VALUE}.
328+ */
329+ public boolean isDataSpaceValid () {
251330 return colorSpace != Format .NO_VALUE
252331 && colorRange != Format .NO_VALUE
253332 && colorTransfer != Format .NO_VALUE ;
@@ -259,15 +338,16 @@ public boolean isValid() {
259338 * @see Format#toLogString(Format)
260339 */
261340 public String toLogString () {
262- if (!isValid ()) {
263- return "NA" ;
264- }
265-
266- return Util .formatInvariant (
267- "%s/%s/%s" ,
268- colorSpaceToString (colorSpace ),
269- colorRangeToString (colorRange ),
270- colorTransferToString (colorTransfer ));
341+ String dataspaceString =
342+ isDataSpaceValid ()
343+ ? Util .formatInvariant (
344+ "%s/%s/%s" ,
345+ colorSpaceToString (colorSpace ),
346+ colorRangeToString (colorRange ),
347+ colorTransferToString (colorTransfer ))
348+ : "NA/NA/NA" ;
349+ String bitdepthsString = isBitdepthValid () ? lumaBitdepth + "/" + chromaBitdepth : "NA/NA" ;
350+ return dataspaceString + "/" + bitdepthsString ;
271351 }
272352
273353 @ Override
@@ -282,7 +362,24 @@ public boolean equals(@Nullable Object obj) {
282362 return colorSpace == other .colorSpace
283363 && colorRange == other .colorRange
284364 && colorTransfer == other .colorTransfer
285- && Arrays .equals (hdrStaticInfo , other .hdrStaticInfo );
365+ && Arrays .equals (hdrStaticInfo , other .hdrStaticInfo )
366+ && lumaBitdepth == other .lumaBitdepth
367+ && chromaBitdepth == other .chromaBitdepth ;
368+ }
369+
370+ @ Override
371+ public int hashCode () {
372+ if (hashCode == 0 ) {
373+ int result = 17 ;
374+ result = 31 * result + colorSpace ;
375+ result = 31 * result + colorRange ;
376+ result = 31 * result + colorTransfer ;
377+ result = 31 * result + Arrays .hashCode (hdrStaticInfo );
378+ result = 31 * result + lumaBitdepth ;
379+ result = 31 * result + chromaBitdepth ;
380+ hashCode = result ;
381+ }
382+ return hashCode ;
286383 }
287384
288385 @ Override
@@ -295,9 +392,21 @@ public String toString() {
295392 + colorTransferToString (colorTransfer )
296393 + ", "
297394 + (hdrStaticInfo != null )
395+ + ", "
396+ + lumaBitdepthToString (lumaBitdepth )
397+ + ", "
398+ + chromaBitdepthToString (chromaBitdepth )
298399 + ")" ;
299400 }
300401
402+ private static String lumaBitdepthToString (int val ) {
403+ return val != Format .NO_VALUE ? val + "bit Luma" : "NA" ;
404+ }
405+
406+ private static String chromaBitdepthToString (int val ) {
407+ return val != Format .NO_VALUE ? val + "bit Chroma" : "NA" ;
408+ }
409+
301410 private static String colorSpaceToString (@ C .ColorSpace int colorSpace ) {
302411 // LINT.IfChange(color_space)
303412 switch (colorSpace ) {
@@ -350,25 +459,14 @@ private static String colorRangeToString(@C.ColorRange int colorRange) {
350459 }
351460 }
352461
353- @ Override
354- public int hashCode () {
355- if (hashCode == 0 ) {
356- int result = 17 ;
357- result = 31 * result + colorSpace ;
358- result = 31 * result + colorRange ;
359- result = 31 * result + colorTransfer ;
360- result = 31 * result + Arrays .hashCode (hdrStaticInfo );
361- hashCode = result ;
362- }
363- return hashCode ;
364- }
365-
366462 // Bundleable implementation
367463
368464 private static final String FIELD_COLOR_SPACE = Util .intToStringMaxRadix (0 );
369465 private static final String FIELD_COLOR_RANGE = Util .intToStringMaxRadix (1 );
370466 private static final String FIELD_COLOR_TRANSFER = Util .intToStringMaxRadix (2 );
371467 private static final String FIELD_HDR_STATIC_INFO = Util .intToStringMaxRadix (3 );
468+ private static final String FIELD_LUMA_BITDEPTH = Util .intToStringMaxRadix (4 );
469+ private static final String FIELD_CHROMA_BITDEPTH = Util .intToStringMaxRadix (5 );
372470
373471 @ Override
374472 public Bundle toBundle () {
@@ -377,6 +475,8 @@ public Bundle toBundle() {
377475 bundle .putInt (FIELD_COLOR_RANGE , colorRange );
378476 bundle .putInt (FIELD_COLOR_TRANSFER , colorTransfer );
379477 bundle .putByteArray (FIELD_HDR_STATIC_INFO , hdrStaticInfo );
478+ bundle .putInt (FIELD_LUMA_BITDEPTH , lumaBitdepth );
479+ bundle .putInt (FIELD_CHROMA_BITDEPTH , chromaBitdepth );
380480 return bundle ;
381481 }
382482
@@ -386,5 +486,7 @@ public Bundle toBundle() {
386486 bundle .getInt (FIELD_COLOR_SPACE , Format .NO_VALUE ),
387487 bundle .getInt (FIELD_COLOR_RANGE , Format .NO_VALUE ),
388488 bundle .getInt (FIELD_COLOR_TRANSFER , Format .NO_VALUE ),
389- bundle .getByteArray (FIELD_HDR_STATIC_INFO ));
489+ bundle .getByteArray (FIELD_HDR_STATIC_INFO ),
490+ bundle .getInt (FIELD_LUMA_BITDEPTH , Format .NO_VALUE ),
491+ bundle .getInt (FIELD_CHROMA_BITDEPTH , Format .NO_VALUE ));
390492}
0 commit comments