• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jiangxincode / ApkToolBoxGUI / #1296

15 Nov 2025 11:02AM UTC coverage: 2.821% (-0.03%) from 2.849%
#1296

push

jiangxincode
[Feature ADD]add hex/value/percent convert in ColorConvert

0 of 85 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

248 of 8791 relevant lines covered (2.82%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.25
/src/main/java/edu/jiangxin/apktoolbox/convert/color/utils/ColorUtils.java
1
package edu.jiangxin.apktoolbox.convert.color.utils;
2

3
import edu.jiangxin.apktoolbox.convert.color.colorspace.CielabColorSpace;
4
import edu.jiangxin.apktoolbox.convert.color.colorspace.CmykColorSpace;
5
import edu.jiangxin.apktoolbox.convert.color.colorspace.HsbColorSpace;
6
import edu.jiangxin.apktoolbox.convert.color.colorspace.HslColorSpace;
7

8
import java.awt.*;
9
import java.awt.color.ColorSpace;
10

11
public class ColorUtils {
×
12
    public static int parseByteHex(String hex) {
NEW
13
        if (hex == null) {
×
NEW
14
            return -1;
×
15
        }
NEW
16
        String s = hex.trim();
×
NEW
17
        if (s.startsWith("0x") || s.startsWith("0X")) {
×
NEW
18
            s = s.substring(2);
×
NEW
19
        } else if (s.startsWith("#")) {
×
NEW
20
            s = s.substring(1);
×
21
        }
NEW
22
        if (s.length() != 2) {
×
NEW
23
            return -1;
×
24
        }
NEW
25
        if (!s.matches("[0-9a-fA-F]{2}")) {
×
NEW
26
            return -1;
×
27
        }
NEW
28
        return Integer.parseInt(s, 16);
×
29
    }
30

31
    public static Color hex2Color(String hexColor) {
32
        return Color.decode(hexColor);
1✔
33
    }
34

35
    public static String color2Hex(Color color) {
36
        return String.format("0x%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
1✔
37
    }
38

39
    public static Color hsb2Color(int hueI, int saturationI, int brightnessI) {
40
        float[] hsbVal = hsbInt2Float(new int[]{hueI, saturationI, brightnessI});
×
41
        ColorSpace colorSpace = HsbColorSpace.getInstance();
×
42
        float[] rgbVal = colorSpace.toRGB(hsbVal);
×
43
        return new Color(rgbVal[0], rgbVal[1], rgbVal[2]);
×
44
    }
45

46
    public static int[] color2Hsb(Color color) {
47
        float[] rgbVal = color.getRGBColorComponents(null);
×
48
        ColorSpace colorSpace = HsbColorSpace.getInstance();
×
49
        float[] hsbVal = colorSpace.fromRGB(rgbVal);
×
50
        return hsbFloat2Int(hsbVal);
×
51
    }
52

53
    public static Color hsl2Color(int hueI, int saturationI, int lightnessI) {
54
        float[] hslVal = hslInt2Float(new int[]{hueI, saturationI, lightnessI});
×
55
        ColorSpace colorSpace = HslColorSpace.getInstance();
×
56
        float[] rgbVal = colorSpace.toRGB(hslVal);
×
57
        return new Color(rgbVal[0], rgbVal[1], rgbVal[2]);
×
58
    }
59

60
    public static int[] color2Hsl(Color color) {
61
        float[] rgbVal = color.getRGBColorComponents(null);
×
62
        ColorSpace colorSpace = HslColorSpace.getInstance();
×
63
        float[] hslVal = colorSpace.fromRGB(rgbVal);
×
64
        return hslFloat2Int(hslVal);
×
65
    }
66

67
    public static Color cmyk2Color(int cyanI, int magentaI, int yellowI, int keyI) {
68
        float[] cmykVal = cmykInt2Float(new int[]{cyanI, magentaI, yellowI, keyI});
×
69
        ColorSpace colorSpace = CmykColorSpace.getInstance();
×
70
        float[] rgbVal = colorSpace.toRGB(cmykVal);
×
71
        return new Color(rgbVal[0], rgbVal[1], rgbVal[2]);
×
72
    }
73

74
    public static int[] color2Cmyk(Color color) {
75
        float[] rgbVal = color.getRGBColorComponents(null);
×
76
        ColorSpace colorSpace = CmykColorSpace.getInstance();
×
77
        float[] cmykVal = colorSpace.fromRGB(rgbVal);
×
78
        return cmykFloat2Int(cmykVal);
×
79
    }
80

81
    public static Color cielab2Color(int L, int a, int b) {
82
        float[] cieLabVal = cielabInt2Float(new int[]{L, a, b});
×
83
        ColorSpace colorSpace = CielabColorSpace.getInstance();
×
84
        float[] rgbVal = colorSpace.toRGB(cieLabVal);
×
85
        return new Color(rgbVal[0], rgbVal[1], rgbVal[2]);
×
86
    }
87

88
    public static int[] color2Cielab(Color color) {
89
        float[] rgbVal = color.getRGBColorComponents(null);
×
90
        ColorSpace colorSpace = CielabColorSpace.getInstance();
×
91
        float[] cieLabVal = colorSpace.fromRGB(rgbVal);
×
92
        return cielabFloat2Int(cieLabVal);
×
93
    }
94

95
    public static float[] rgbInt2Float(int[] value) {
96
        float red = value[0] / 255f;
×
97
        float green = value[1] / 255f;
×
98
        float blue = value[2] / 255f;
×
99
        return new float[]{red, green, blue};
×
100
    }
101

102
    public static int[] rgbFloat2Int(float[] value) {
103
        int red = (int) (value[0] * 255);
×
104
        int green = (int) (value[1] * 255);
×
105
        int blue = (int) (value[2] * 255);
×
106
        return new int[]{red, green, blue};
×
107
    }
108

109
    public static int[] hsbFloat2Int(float[] value) {
110
        int hue = (int) (value[0] * 360);
×
111
        int saturation = (int) (value[1] * 100);
×
112
        int brightness = (int) (value[2] * 100);
×
113
        return new int[]{hue, saturation, brightness};
×
114
    }
115

116
    public static float[] hsbInt2Float(int[] value) {
117
        float hue = value[0] / 360f;
×
118
        float saturation = value[1] / 100f;
×
119
        float brightness = value[2] / 100f;
×
120
        return new float[]{hue, saturation, brightness};
×
121
    }
122

123
    public static int[] hslFloat2Int(float[] value) {
124
        int hue = (int) (value[0] * 360);
×
125
        int saturation = (int) (value[1] * 100);
×
126
        int lightness = (int) (value[2] * 100);
×
127
        return new int[]{hue, saturation, lightness};
×
128
    }
129

130
    public static float[] hslInt2Float(int[] value) {
131
        float hue = value[0] / 360f;
×
132
        float saturation = value[1] / 100f;
×
133
        float lightness = value[2] / 100f;
×
134
        return new float[]{hue, saturation, lightness};
×
135
    }
136

137

138
    public static int[] cmykFloat2Int(float[] value) {
139
        int cyan = (int) (value[0] * 100);
×
140
        int magenta = (int) (value[1] * 100);
×
141
        int yellow = (int) (value[2] * 100);
×
142
        int key = (int) (value[3] * 100);
×
143
        return new int[]{cyan, magenta, yellow, key};
×
144
    }
145

146
    public static float[] cmykInt2Float(int[] value) {
147
        float cyan = value[0] / 100f;
×
148
        float magenta = value[1] / 100f;
×
149
        float yellow = value[2] / 100f;
×
150
        float key = value[3] / 100f;
×
151
        return new float[]{cyan, magenta, yellow, key};
×
152
    }
153

154

155
    public static int[] cielabFloat2Int(float[] value) {
156
        int L = (int) value[0];
×
157
        int a = (int) value[1];
×
158
        int b = (int) value[2];
×
159
        return new int[]{L, a, b};
×
160
    }
161

162
    public static float[] cielabInt2Float(int[] value) {
163
        float L = (float) value[0];
×
164
        float a = (float) value[1];
×
165
        float b = (float) value[2];
×
166
        return new float[]{L, a, b};
×
167
    }
168
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc