• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 The Android Open Source Project
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 package android.hardware;
17 
18 import android.annotation.FlaggedApi;
19 import android.annotation.IntDef;
20 import android.view.SurfaceControl;
21 
22 import com.android.graphics.flags.Flags;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 
27 /**
28  * DataSpace identifies three components of colors - standard (primaries), transfer and range.
29  *
30  * <p>A DataSpace describes how buffer data, such as from an {@link android.media.Image Image}
31  * or a {@link android.hardware.HardwareBuffer HardwareBuffer}
32  * should be interpreted by both applications and typical hardware.</p>
33  *
34  * <p>As buffer information is not guaranteed to be representative of color information,
35  * while DataSpace is typically used to describe three aspects of interpreting colors,
36  * some DataSpaces may describe other typical interpretations of buffer data
37  * such as depth information.</p>
38  *
39  * <p>Note that while {@link android.graphics.ColorSpace ColorSpace} and {@code DataSpace}
40  * are similar concepts, they are not equivalent. Not all ColorSpaces,
41  * such as {@link android.graphics.ColorSpace.Named#ACES ColorSpace.Named.ACES},
42  * are able to be understood by typical hardware blocks so they cannot be DataSpaces.</p>
43  *
44  * <h3>Standard aspect</h3>
45  *
46  * <p>Defines the chromaticity coordinates of the source primaries in terms of
47  * the CIE 1931 definition of x and y specified in ISO 11664-1.</p>
48  *
49  * <h3>Transfer aspect</h3>
50  *
51  * <p>Transfer characteristics are the opto-electronic transfer characteristic
52  * at the source as a function of linear optical intensity (luminance).</p>
53  *
54  * <p>For digital signals, E corresponds to the recorded value. Normally, the
55  * transfer function is applied in RGB space to each of the R, G and B
56  * components independently. This may result in color shift that can be
57  * minized by applying the transfer function in Lab space only for the L
58  * component. Implementation may apply the transfer function in RGB space
59  * for all pixel formats if desired.</p>
60  *
61  * <h3>Range aspect</h3>
62  *
63  * <p>Defines the range of values corresponding to the unit range of {@code 0-1}.</p>
64  */
65 
66 public final class DataSpace {
67     /** @hide */
68     @Retention(RetentionPolicy.SOURCE)
69     @IntDef(flag = true, value = {
70         STANDARD_UNSPECIFIED,
71         STANDARD_BT709,
72         STANDARD_BT601_625,
73         STANDARD_BT601_625_UNADJUSTED,
74         STANDARD_BT601_525,
75         STANDARD_BT601_525_UNADJUSTED,
76         STANDARD_BT2020,
77         STANDARD_BT2020_CONSTANT_LUMINANCE,
78         STANDARD_BT470M,
79         STANDARD_FILM,
80         STANDARD_DCI_P3,
81         STANDARD_ADOBE_RGB
82     })
83     public @interface DataSpaceStandard {};
84 
85     private static final int STANDARD_MASK = 63 << 16;
86 
87     /**
88      * Chromacity coordinates are unknown or are determined by the application.
89      */
90     public static final int STANDARD_UNSPECIFIED  = 0 << 16;
91     /**
92      * Use the unadjusted {@code KR = 0.2126}, {@code KB = 0.0722} luminance interpretation
93      * for RGB conversion.
94      *
95      * <pre>
96      * Primaries:       x       y
97      *  green           0.300   0.600
98      *  blue            0.150   0.060
99      *  red             0.640   0.330
100      *  white (D65)     0.3127  0.3290 </pre>
101      */
102     public static final int STANDARD_BT709 = 1 << 16;
103     /**
104      * Use the adjusted {@code KR = 0.299}, {@code KB = 0.114} luminance interpretation
105      * for RGB conversion from the one purely determined by the primaries
106      * to minimize the color shift into RGB space that uses BT.709
107      * primaries.
108      *
109      * <pre>
110      * Primaries:       x       y
111      *  green           0.290   0.600
112      *  blue            0.150   0.060
113      *  red             0.640   0.330
114      *  white (D65)     0.3127  0.3290 </pre>
115      */
116     public static final int STANDARD_BT601_625 = 2 << 16;
117     /**
118      * Use the unadjusted {@code KR = 0.222}, {@code KB = 0.071} luminance interpretation
119      * for RGB conversion.
120      *
121      * <pre>
122      * Primaries:       x       y
123      *  green           0.290   0.600
124      *  blue            0.150   0.060
125      *  red             0.640   0.330
126      *  white (D65)     0.3127  0.3290 </pre>
127      */
128     public static final int STANDARD_BT601_625_UNADJUSTED = 3 << 16;
129     /**
130      * Use the adjusted {@code KR = 0.299}, {@code KB = 0.114} luminance interpretation
131      * for RGB conversion from the one purely determined by the primaries
132      * to minimize the color shift into RGB space that uses BT.709
133      * primaries.
134      *
135      * <pre>
136      * Primaries:       x       y
137      *  green           0.310   0.595
138      *  blue            0.155   0.070
139      *  red             0.630   0.340
140      *  white (D65)     0.3127  0.3290 </pre>
141      */
142     public static final int STANDARD_BT601_525 = 4 << 16;
143     /**
144      * Use the unadjusted {@code KR = 0.212}, {@code KB = 0.087} luminance interpretation
145      * for RGB conversion (as in SMPTE 240M).
146      *
147      * <pre>
148      * Primaries:       x       y
149      *  green           0.310   0.595
150      *  blue            0.155   0.070
151      *  red             0.630   0.340
152      *  white (D65)     0.3127  0.3290 </pre>
153      */
154     public static final int STANDARD_BT601_525_UNADJUSTED = 5 << 16;
155     /**
156      * Use the unadjusted {@code KR = 0.2627}, {@code KB = 0.0593} luminance interpretation
157      * for RGB conversion.
158      *
159      * <pre>
160      * Primaries:       x       y
161      *  green           0.170   0.797
162      *  blue            0.131   0.046
163      *  red             0.708   0.292
164      *  white (D65)     0.3127  0.3290 </pre>
165      */
166     public static final int STANDARD_BT2020 = 6 << 16;
167     /**
168      * Use the unadjusted {@code KR = 0.2627}, {@code KB = 0.0593} luminance interpretation
169      * for RGB conversion using the linear domain.
170      *
171      * <pre>
172      * Primaries:       x       y
173      *  green           0.170   0.797
174      *  blue            0.131   0.046
175      *  red             0.708   0.292
176      *  white (D65)     0.3127  0.3290 </pre>
177      */
178     public static final int STANDARD_BT2020_CONSTANT_LUMINANCE = 7 << 16;
179     /**
180      * Use the unadjusted {@code KR = 0.30}, {@code KB = 0.11} luminance interpretation
181      * for RGB conversion.
182      *
183      * <pre>
184      * Primaries:       x      y
185      *  green           0.21   0.71
186      *  blue            0.14   0.08
187      *  red             0.67   0.33
188      *  white (C)       0.310  0.316 </pre>
189      */
190     public static final int STANDARD_BT470M = 8 << 16;
191     /**
192      * Use the unadjusted {@code KR = 0.254}, {@code KB = 0.068} luminance interpretation
193      * for RGB conversion.
194      *
195      * <pre>
196      * Primaries:       x       y
197      *  green           0.243   0.692
198      *  blue            0.145   0.049
199      *  red             0.681   0.319
200      *  white (C)       0.310   0.316 </pre>
201      */
202     public static final int STANDARD_FILM = 9 << 16;
203     /**
204      * SMPTE EG 432-1 and SMPTE RP 431-2.
205      *
206      * <pre>
207      * Primaries:       x       y
208      *  green           0.265   0.690
209      *  blue            0.150   0.060
210      *  red             0.680   0.320
211      *  white (D65)     0.3127  0.3290 </pre>
212      */
213     public static final int STANDARD_DCI_P3 = 10 << 16;
214     /**
215      * Adobe RGB primaries.
216      *
217      * <pre>
218      * Primaries:       x       y
219      *  green           0.210   0.710
220      *  blue            0.150   0.060
221      *  red             0.640   0.330
222      *  white (D65)     0.3127  0.3290 </pre>
223      */
224     public static final int STANDARD_ADOBE_RGB = 11 << 16;
225 
226     /** @hide */
227     @Retention(RetentionPolicy.SOURCE)
228     @IntDef(flag = true, value = {
229         TRANSFER_UNSPECIFIED,
230         TRANSFER_LINEAR,
231         TRANSFER_SRGB,
232         TRANSFER_SMPTE_170M,
233         TRANSFER_GAMMA2_2,
234         TRANSFER_GAMMA2_6,
235         TRANSFER_GAMMA2_8,
236         TRANSFER_ST2084,
237         TRANSFER_HLG
238     })
239     public @interface DataSpaceTransfer {};
240 
241     private static final int TRANSFER_MASK = 31 << 22;
242 
243     /**
244      * Transfer characteristics are unknown or are determined by the
245      * application.
246      */
247     public static final int TRANSFER_UNSPECIFIED = 0 << 22;
248     /**
249      * Linear transfer.
250      *
251      * <pre>{@code
252      * Transfer characteristic curve:
253      *  E = L
254      *      L - luminance of image 0 <= L <= 1 for conventional colorimetry
255      *      E - corresponding electrical signal}</pre>
256      */
257     public static final int TRANSFER_LINEAR = 1 << 22;
258     /**
259      * sRGB transfer.
260      *
261      * <pre>{@code
262      * Transfer characteristic curve:
263      * E = 1.055 * L^(1/2.4) - 0.055  for 0.0031308 <= L <= 1
264      *   = 12.92 * L                  for 0 <= L < 0.0031308
265      *     L - luminance of image 0 <= L <= 1 for conventional colorimetry
266      *     E - corresponding electrical signal}</pre>
267      *
268      * Use for RGB formats.
269      */
270     public static final int TRANSFER_SRGB = 2 << 22;
271     /**
272      * SMPTE 170M transfer.
273      *
274      * <pre>{@code
275      * Transfer characteristic curve:
276      * E = 1.099 * L ^ 0.45 - 0.099  for 0.018 <= L <= 1
277      *   = 4.500 * L                 for 0 <= L < 0.018
278      *     L - luminance of image 0 <= L <= 1 for conventional colorimetry
279      *     E - corresponding electrical signal}</pre>
280      *
281      * Use for YCbCr formats.
282      */
283     public static final int TRANSFER_SMPTE_170M = 3 << 22;
284     /**
285      * Display gamma 2.2.
286      *
287      * <pre>{@code
288      * Transfer characteristic curve:
289      * E = L ^ (1/2.2)
290      *     L - luminance of image 0 <= L <= 1 for conventional colorimetry
291      *     E - corresponding electrical signal}</pre>
292      */
293     public static final int TRANSFER_GAMMA2_2 = 4 << 22;
294     /**
295      *  Display gamma 2.6.
296      *
297      * <pre>{@code
298      * Transfer characteristic curve:
299      * E = L ^ (1/2.6)
300      *     L - luminance of image 0 <= L <= 1 for conventional colorimetry
301      *     E - corresponding electrical signal}</pre>
302      */
303     public static final int TRANSFER_GAMMA2_6 = 5 << 22;
304     /**
305      *  Display gamma 2.8.
306      *
307      * <pre>{@code
308      * Transfer characteristic curve:
309      * E = L ^ (1/2.8)
310      *     L - luminance of image 0 <= L <= 1 for conventional colorimetry
311      *     E - corresponding electrical signal}</pre>
312      */
313     public static final int TRANSFER_GAMMA2_8 = 6 << 22;
314     /**
315      * SMPTE ST 2084 (Dolby Perceptual Quantizer).
316      *
317      * <pre>{@code
318      * Transfer characteristic curve:
319      * E = ((c1 + c2 * L^n) / (1 + c3 * L^n)) ^ m
320      * c1 = c3 - c2 + 1 = 3424 / 4096 = 0.8359375
321      * c2 = 32 * 2413 / 4096 = 18.8515625
322      * c3 = 32 * 2392 / 4096 = 18.6875
323      * m = 128 * 2523 / 4096 = 78.84375
324      * n = 0.25 * 2610 / 4096 = 0.1593017578125
325      *     L - luminance of image 0 <= L <= 1 for HDR colorimetry.
326      *         L = 1 corresponds to 10000 cd/m2
327      *     E - corresponding electrical signal}</pre>
328      */
329     public static final int TRANSFER_ST2084 = 7 << 22;
330     /**
331      * ARIB STD-B67 Hybrid Log Gamma.
332      *
333      * <pre>{@code
334      * Transfer characteristic curve:
335      * E = r * L^0.5                 for 0 <= L <= 1
336      *   = a * ln(L - b) + c         for 1 < L
337      * a = 0.17883277
338      * b = 0.28466892
339      * c = 0.55991073
340      * r = 0.5
341      *     L - luminance of image 0 <= L for HDR colorimetry. L = 1 corresponds
342      *         to reference white level of 100 cd/m2
343      *     E - corresponding electrical signal}</pre>
344      */
345     public static final int TRANSFER_HLG = 8 << 22;
346 
347     /** @hide */
348     @Retention(RetentionPolicy.SOURCE)
349     @IntDef(flag = true, value = {
350         RANGE_UNSPECIFIED,
351         RANGE_FULL,
352         RANGE_LIMITED,
353         RANGE_EXTENDED
354     })
355     public @interface DataSpaceRange {};
356 
357     private static final int RANGE_MASK = 7 << 27;
358 
359     /**
360      * Range characteristics are unknown or are determined by the application.
361      */
362     public static final int RANGE_UNSPECIFIED = 0 << 27;
363     /**
364      * Full range uses all values for Y, Cb and Cr from
365      * {@code 0} to {@code 2^b-1}, where b is the bit depth of the color format.
366      */
367     public static final int RANGE_FULL = 1 << 27;
368     /**
369      * Limited range uses values {@code 16/256*2^b} to {@code 235/256*2^b} for Y, and
370      * {@code 1/16*2^b} to {@code 15/16*2^b} for Cb, Cr, R, G and B, where b is the bit depth of
371      * the color format.
372      *
373      * <p>E.g. For 8-bit-depth formats:
374      * Luma (Y) samples should range from 16 to 235, inclusive
375      * Chroma (Cb, Cr) samples should range from 16 to 240, inclusive
376      *
377      * For 10-bit-depth formats:
378      * Luma (Y) samples should range from 64 to 940, inclusive
379      * Chroma (Cb, Cr) samples should range from 64 to 960, inclusive. </p>
380      */
381     public static final int RANGE_LIMITED = 2 << 27;
382     /**
383      * Extended range can be used in combination with FP16 to communicate scRGB or with
384      * {@link android.view.SurfaceControl.Transaction#setExtendedRangeBrightness(SurfaceControl, float, float)}
385      * to indicate an HDR range.
386      *
387      * <p>When used with floating point pixel formats and #STANDARD_BT709 then [0.0 - 1.0] is the
388      * standard sRGB space and values outside the range [0.0 - 1.0] can encode
389      * color outside the sRGB gamut. [-0.5, 7.5] is the standard scRGB range.
390      * Used to blend/merge multiple dataspaces on a single display.</p>
391      *
392      * <p>As of {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} this may be combined with
393      * {@link android.view.SurfaceControl.Transaction#setExtendedRangeBrightness(SurfaceControl, float, float)}
394      * and other formats such as {@link HardwareBuffer#RGBA_8888} or
395      * {@link HardwareBuffer#RGBA_1010102} to communicate a variable HDR brightness range</p>
396      */
397     public static final int RANGE_EXTENDED = 3 << 27;
398 
399     /**
400      * Depth.
401      *
402      * This value is valid with formats HAL_PIXEL_FORMAT_Y16 and HAL_PIXEL_FORMAT_BLOB.
403      */
404     public static final int DATASPACE_DEPTH = 4096;
405 
406     /**
407      * ISO 16684-1:2011(E) Dynamic Depth.
408      *
409      * Embedded depth metadata following the dynamic depth specification.
410      */
411     public static final int DATASPACE_DYNAMIC_DEPTH = 4098;
412 
413     /**
414      * High Efficiency Image File Format (HEIF).
415      *
416      * <p>This value is valid with {@link android.hardware.HardwareBuffer#BLOB HardwareBuffer.BLOB}
417      * format. The combination is an HEIC image encoded by HEIC or HEVC encoder according to
418      * ISO/IEC 23008-12.</p>
419      */
420     public static final int DATASPACE_HEIF = 4100;
421 
422     /**
423      * Ultra HDR
424      *
425      * JPEG image with embedded HDR gain map following the Ultra HDR specification and
426      * starting with Android version {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM V}
427      * ISO/CD 21496‐1
428      *
429      * <p>This value is valid with formats:</p>
430      * <ul>
431      *    <li>HAL_PIXEL_FORMAT_BLOB: JPEG image encoded by Jpeg/R encoder according to
432      *    ISO/CD 21496‐1</li>
433      * </ul>
434      * <p>
435      * The image contains a standard SDR JPEG and a gain map. Ultra HDR decoders can use the
436      * gain map to boost the brightness of the rendered image.</p>
437      */
438      public static final int DATASPACE_JPEG_R = 4101;
439 
440     /**
441      * ISO/IEC 23008-12:2024
442      *
443      * High Efficiency Image File Format (HEIF) with embedded HDR gain map
444      *
445      * <p>This value is valid with formats:</p>
446      * <ul>
447      *    <li>HAL_PIXEL_FORMAT_BLOB: A HEIC image encoded by HEVC encoder
448      *    according to ISO/IEC 23008-12:2024 that includes an HDR gain map and
449      *    metadata according to ISO/CD 21496‐1.</li>
450      * </ul>
451      */
452     @FlaggedApi(com.android.internal.camera.flags.Flags.FLAG_CAMERA_HEIF_GAINMAP)
453     public static final int DATASPACE_HEIF_ULTRAHDR = 4102;
454 
455     /** @hide */
456     @Retention(RetentionPolicy.SOURCE)
457     @IntDef(flag = true, value = {
458         DATASPACE_UNKNOWN,
459         DATASPACE_SCRGB_LINEAR,
460         DATASPACE_SRGB,
461         DATASPACE_SCRGB,
462         DATASPACE_DISPLAY_P3,
463         DATASPACE_BT2020_HLG,
464         DATASPACE_BT2020_PQ,
465         DATASPACE_ADOBE_RGB,
466         DATASPACE_JFIF,
467         DATASPACE_BT601_625,
468         DATASPACE_BT601_525,
469         DATASPACE_BT2020,
470         DATASPACE_BT709,
471         DATASPACE_DCI_P3,
472         DATASPACE_SRGB_LINEAR
473     })
474     public @interface ColorDataSpace {};
475 
476     /**
477      * Default-assumption data space, when not explicitly specified.
478      *
479      * <p>It is safest to assume a buffer is an image with sRGB primaries and
480      * encoding ranges, but the consumer and/or the producer of the data may
481      * simply be using defaults. No automatic gamma transform should be
482      * expected, except for a possible display gamma transform when drawn to a
483      * screen.</p>
484      */
485     public static final int DATASPACE_UNKNOWN = 0;
486     /**
487      * scRGB linear encoding.
488      *
489      * <p>Composed of the following -</p>
490      * <pre>
491      *   Primaries: STANDARD_BT709
492      *   Transfer: TRANSFER_LINEAR
493      *   Range: RANGE_EXTENDED</pre>
494      *
495      * The values are floating point.
496      * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits.
497      * Values beyond the range [0.0 - 1.0] would correspond to other colors
498      * spaces and/or HDR content.
499      */
500     public static final int DATASPACE_SCRGB_LINEAR = 406913024;
501     /**
502      * sRGB gamma encoding.
503      *
504      * <p>Composed of the following -</p>
505      * <pre>
506      *   Primaries: STANDARD_BT709
507      *   Transfer: TRANSFER_SRGB
508      *   Range: RANGE_FULL</pre>
509      *
510      * When written, the inverse transformation is performed.
511      *
512      * The alpha component, if present, is always stored in linear space and
513      * is left unmodified when read or written.
514      */
515     public static final int DATASPACE_SRGB = 142671872;
516     /**
517      * scRGB gamma encoding.
518      *
519      * <p>Composed of the following -</p>
520      * <pre>
521      *   Primaries: STANDARD_BT709
522      *   Transfer: TRANSFER_SRGB
523      *   Range: RANGE_EXTENDED</pre>
524      *
525      * The values are floating point.
526      *
527      * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits.
528      * Values beyond the range [0.0 - 1.0] would correspond to other colors
529      * spaces and/or HDR content.
530      */
531     public static final int DATASPACE_SCRGB = 411107328;
532     /**
533      * Display P3 encoding.
534      *
535      * <p>Composed of the following -</p>
536      * <pre>
537      *   Primaries: STANDARD_DCI_P3
538      *   Transfer: TRANSFER_SRGB
539      *   Range: RANGE_FULL</pre>
540      */
541     public static final int DATASPACE_DISPLAY_P3 = 143261696;
542 
543     /**
544      * Hybrid Log Gamma encoding.
545      *
546      * <p>Composed of the following -</p>
547      * <pre>
548      *   Primaries: STANDARD_BT2020
549      *   Transfer: TRANSFER_HLG
550      *   Range: RANGE_FULL</pre>
551      */
552     public static final int DATASPACE_BT2020_HLG = 168165376;
553 
554     /**
555      * Perceptual Quantizer encoding.
556      *
557      * <p>Composed of the following -</p>
558      * <pre>
559      *   Primaries: STANDARD_BT2020
560      *   Transfer: TRANSFER_ST2084
561      *   Range: RANGE_FULL</pre>
562      */
563     public static final int DATASPACE_BT2020_PQ = 163971072;
564     /**
565      * Adobe RGB encoding.
566      *
567      * <p>Composed of the following -</p>
568      * <pre>
569      *   Primaries: STANDARD_ADOBE_RGB
570      *   Transfer: TRANSFER_GAMMA2_2
571      *   Range: RANGE_FULL</pre>
572      *
573      * Note: Application is responsible for gamma encoding the data.
574      */
575     public static final int DATASPACE_ADOBE_RGB = 151715840;
576     /**
577      * JPEG File Interchange Format (JFIF).
578      *
579      * <p>Composed of the following -</p>
580      * <pre>
581      *   Primaries: STANDARD_BT601_625
582      *   Transfer: TRANSFER_SMPTE_170M
583      *   Range: RANGE_FULL</pre>
584      *
585      * Same model as BT.601-625, but all values (Y, Cb, Cr) range from {@code 0} to {@code 255}
586      */
587     public static final int DATASPACE_JFIF = 146931712;
588     /**
589      * ITU-R Recommendation 601 (BT.601) - 525-line
590      *
591      * Standard-definition television, 525 Lines (NTSC).
592      *
593      * <p>Composed of the following -</p>
594      * <pre>
595      *   Primaries: STANDARD_BT601_625
596      *   Transfer: TRANSFER_SMPTE_170M
597      *   Range: RANGE_LIMITED</pre>
598      */
599     public static final int DATASPACE_BT601_625 = 281149440;
600     /**
601      * ITU-R Recommendation 709 (BT.709)
602      *
603      * High-definition television.
604      *
605      * <p>Composed of the following -</p>
606      * <pre>
607      *   Primaries: STANDARD_BT601_525
608      *   Transfer: TRANSFER_SMPTE_170M
609      *   Range: RANGE_LIMITED</pre>
610      */
611     public static final int DATASPACE_BT601_525 = 281280512;
612     /**
613      * ITU-R Recommendation 2020 (BT.2020)
614      *
615      * Ultra High-definition television.
616      *
617      * <p>Composed of the following -</p>
618      * <pre>
619      *   Primaries: STANDARD_BT2020
620      *   Transfer: TRANSFER_SMPTE_170M
621      *   Range: RANGE_FULL</pre>
622      */
623     public static final int DATASPACE_BT2020 = 147193856;
624     /**
625      * ITU-R Recommendation 709 (BT.709)
626      *
627      * High-definition television.
628      *
629      * <p>Composed of the following -</p>
630      * <pre>
631      *   Primaries: STANDARD_BT709
632      *   Transfer: TRANSFER_SMPTE_170M
633      *   Range: RANGE_LIMITED</pre>
634      */
635     public static final int DATASPACE_BT709 = 281083904;
636     /**
637      * SMPTE EG 432-1 and SMPTE RP 431-2
638      *
639      * Digital Cinema DCI-P3.
640      *
641      * <p>Composed of the following -</p>
642      * <pre>
643      *   Primaries: STANDARD_DCI_P3
644      *   Transfer: TRANSFER_GAMMA2_6
645      *   Range: RANGE_FULL</pre>
646      *
647      * Note: Application is responsible for gamma encoding the data as
648      * a 2.6 gamma encoding is not supported in HW.
649      */
650     public static final int DATASPACE_DCI_P3 = 155844608;
651     /**
652      * sRGB linear encoding.
653      *
654      * <p>Composed of the following -</p>
655      * <pre>
656      *   Primaries: STANDARD_BT709
657      *   Transfer: TRANSFER_LINEAR
658      *   Range: RANGE_FULL</pre>
659      *
660      * The values are encoded using the full range ([0,255] for 8-bit) for all
661      * components.
662      */
663     public static final int DATASPACE_SRGB_LINEAR = 138477568;
664 
665     /**
666      * Display BT. 2020 encoding.
667      *
668      * <p>Composed of the following -</p>
669      * <pre>
670      *   Primaries: STANDARD_BT2020
671      *   Transfer: TRANSFER_SRGB
672      *   Range: RANGE_FULL</pre>
673      */
674     @FlaggedApi(Flags.FLAG_DISPLAY_BT2020_COLORSPACE)
675     public static final int DATASPACE_DISPLAY_BT2020 = 142999552;
676 
677     /** @hide */
678     @Retention(RetentionPolicy.SOURCE)
679     @IntDef(flag = true, value = {
680         DATASPACE_DEPTH,
681         DATASPACE_DYNAMIC_DEPTH,
682         DATASPACE_HEIF,
683         DATASPACE_HEIF_ULTRAHDR,
684         DATASPACE_JPEG_R,
685         DATASPACE_UNKNOWN,
686         DATASPACE_SCRGB_LINEAR,
687         DATASPACE_SRGB,
688         DATASPACE_SCRGB,
689         DATASPACE_DISPLAY_P3,
690         DATASPACE_BT2020_HLG,
691         DATASPACE_BT2020_PQ,
692         DATASPACE_ADOBE_RGB,
693         DATASPACE_JFIF,
694         DATASPACE_BT601_625,
695         DATASPACE_BT601_525,
696         DATASPACE_BT2020,
697         DATASPACE_BT709,
698         DATASPACE_DCI_P3,
699         DATASPACE_SRGB_LINEAR,
700         DATASPACE_DISPLAY_BT2020
701     })
702     public @interface NamedDataSpace {};
703 
DataSpace()704     private DataSpace() {}
705 
706     /**
707      * Pack the dataSpace value using standard, transfer and range field value.
708      * Field values should be in the correct bits place.
709      *
710      * @param standard Chromaticity coordinates of source primaries
711      * @param transfer Opto-electronic transfer characteristic at the source
712      * @param range The range of values
713      *
714      * @return The int dataspace packed by standard, transfer and range value
715      */
pack(@ataSpaceStandard int standard, @DataSpaceTransfer int transfer, @DataSpaceRange int range)716     public static @ColorDataSpace int pack(@DataSpaceStandard int standard,
717                                         @DataSpaceTransfer int transfer,
718                                         @DataSpaceRange int range) {
719         if ((standard & STANDARD_MASK) != standard) {
720             throw new IllegalArgumentException("Invalid standard " + standard);
721         }
722         if ((transfer & TRANSFER_MASK) != transfer) {
723             throw new IllegalArgumentException("Invalid transfer " + transfer);
724         }
725         if ((range & RANGE_MASK) != range) {
726             throw new IllegalArgumentException("Invalid range " + range);
727         }
728         return standard | transfer | range;
729     }
730 
731     /**
732      * Unpack the standard field value from the packed dataSpace value.
733      *
734      * @param dataSpace The packed dataspace value
735      *
736      * @return The standard aspect
737      */
getStandard(@olorDataSpace int dataSpace)738     public static @DataSpaceStandard int getStandard(@ColorDataSpace int dataSpace) {
739         @DataSpaceStandard int standard = dataSpace & STANDARD_MASK;
740         return standard;
741     }
742 
743     /**
744      * Unpack the transfer field value from the packed dataSpace value
745      *
746      * @param dataSpace The packed dataspace value
747      *
748      * @return The transfer aspect
749      */
getTransfer(@olorDataSpace int dataSpace)750     public static @DataSpaceTransfer int getTransfer(@ColorDataSpace int dataSpace) {
751         @DataSpaceTransfer int transfer = dataSpace & TRANSFER_MASK;
752         return transfer;
753     }
754 
755     /**
756      * Unpack the range field value from the packed dataSpace value
757      *
758      * @param dataSpace The packed dataspace value
759      *
760      * @return The range aspect
761      */
getRange(@olorDataSpace int dataSpace)762     public static @DataSpaceRange int getRange(@ColorDataSpace int dataSpace) {
763         @DataSpaceRange int range = dataSpace & RANGE_MASK;
764         return range;
765     }
766 }
767