Android Utililty Methods Color Convert

List of utility methods to do Color Convert

Description

The list of methods to do Color Convert are organized into topic(s).

Method

intRGBToColor(final float pRed, final float pGreen, final float pBlue)
RGB To Color
return Color.rgb((int) (pRed * COLOR_FLOAT_TO_INT_FACTOR),
        (int) (pGreen * COLOR_FLOAT_TO_INT_FACTOR),
        (int) (pBlue * COLOR_FLOAT_TO_INT_FACTOR));
int[]getArgb(int color)
Gets an ARGB int array from a provided color
final int a = (color >>> 24);
final int r = (color >> 16) & 0xFF;
final int g = (color >> 8) & 0xFF;
final int b = (color) & 0xFF;
return new int[] { ClippedColorPart(a), ClippedColorPart(r),
        ClippedColorPart(g), ClippedColorPart(b) };
intgetColorFromArgb(int[] argb)
Gets an int color from an int[4] containing argb values.
if (argb.length != 4) {
    throw new IllegalArgumentException(
            "ARGB int array must have a length of 4.");
return (ClippedColorPart(argb[0]) << 24)
        + (ClippedColorPart(argb[1]) << 16)
        + (ClippedColorPart(argb[2]) << 8)
        + (ClippedColorPart(argb[3]));
...
voiddecodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int height)
decode YUVSP
final int frameSize = width * height;
for (int j = 0, yp = 0; j < height; j++) {
    int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
    for (int i = 0; i < width; i++, yp++) {
        int y = (0xff & ((int) yuv420sp[yp])) - 16;
        if (y < 0)
            y = 0;
        if ((i & 1) == 0) {
...
voiddecodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int height)
decode YUVSP
final int frameSize = width * height;
for (int j = 0, yp = 0; j < height; j++) {
    int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
    for (int i = 0; i < width; i++, yp++) {
        int y = (0xff & ((int) yuv420sp[yp])) - 16;
        if (y < 0)
            y = 0;
        if ((i & 1) == 0) {
...
voiddecodeYUV420SPGrayscale(int[] rgb, byte[] yuv420sp, int width, int height)
decode YUVSP Grayscale
final int frameSize = width * height;
for (int pix = 0; pix < frameSize; pix++) {
    int pixVal = (0xff & ((int) yuv420sp[pix])) - 16;
    if (pixVal < 0)
        pixVal = 0;
    if (pixVal > 255)
        pixVal = 255;
    rgb[pix] = 0xff000000 | (pixVal << 16) | (pixVal << 8) | pixVal;
...
intrgbToGray(int pixels)
rgb To Gray
int _red = (pixels >> 16) & 0xFF;
int _green = (pixels >> 8) & 0xFF;
int _blue = (pixels) & 0xFF;
return (int) (0.3 * _red + 0.59 * _green + 0.11 * _blue);