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