1 /* 2 * Copyright (C) 2024 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 com.android.internal.widget.remotecompose.core.operations.utilities; 17 18 /** 19 * These are tools to use long Color as variables long colors are stored a 0xXXXXXXXX XXXXXX?? in 20 * SRGB the colors are stored 0xAARRGGBB,00000000 SRGB color sapce is color space 0 Our Color will 21 * use color float with a Current android supports SRGB, LINEAR_SRGB, EXTENDED_SRGB, 22 * LINEAR_EXTENDED_SRGB, BT709, BT2020, DCI_P3, DISPLAY_P3, NTSC_1953, SMPTE_C, ADOBE_RGB, 23 * PRO_PHOTO_RGB, ACES, ACESCG, CIE_XYZ, CIE_LAB, BT2020_HLG, BT2020_PQ 0..17 respectively 24 * 25 * <p>Our color space will be 62 (MAX_ID-1). (0x3E) Storing the default value in SRGB format and 26 * having the id of the color between the ARGB values and the 62 i.e. 0xAARRGGBB 00 00 00 3E 27 */ 28 public class ColorUtils { 29 public static int RC_COLOR = 62; 30 packRCColor(int defaultARGB, int id)31 long packRCColor(int defaultARGB, int id) { 32 long l = defaultARGB; 33 return (l << 32) | id << 8 | RC_COLOR; 34 } 35 isRCColor(long color)36 boolean isRCColor(long color) { 37 return ((color & 0x3F) == 62); 38 } 39 getID(long color)40 int getID(long color) { 41 if (isRCColor(color)) { 42 return (int) ((color & 0xFFFFFF00) >> 8); 43 } 44 return -1; 45 } 46 47 /** 48 * get default color from long color 49 * 50 * @param color 51 * @return 52 */ getDefaultColor(long color)53 public int getDefaultColor(long color) { 54 if (isRCColor(color)) { 55 return (int) (color >> 32); 56 } 57 if (((color & 0xFF) == 0)) { 58 return (int) (color >> 32); 59 } 60 return 0; 61 } 62 63 /** 64 * Utility function to create a color as an int 65 * 66 * @param r red 67 * @param g green 68 * @param b blue 69 * @param a alpha 70 * @return int packed color 71 */ createColor(int r, int g, int b, int a)72 public static int createColor(int r, int g, int b, int a) { 73 return (a << 24) | (r << 16) | (g << 8) | b; 74 } 75 } 76