mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-01 22:54:26 +02:00
fix hex color decoding
This commit is contained in:
parent
193a9b66ee
commit
75d6ed704b
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.reandroid.arsc.decoder;
|
package com.reandroid.arsc.decoder;
|
||||||
|
|
||||||
import com.reandroid.arsc.util.HexUtil;
|
|
||||||
import com.reandroid.arsc.value.ValueType;
|
import com.reandroid.arsc.value.ValueType;
|
||||||
|
|
||||||
public class ColorUtil {
|
public class ColorUtil {
|
||||||
@ -24,25 +23,42 @@ public class ColorUtil {
|
|||||||
if(valueType == null){
|
if(valueType == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int index;
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append('#');
|
||||||
switch (valueType){
|
switch (valueType){
|
||||||
case INT_COLOR_RGB4:
|
case INT_COLOR_RGB4:
|
||||||
index = 5;
|
builder.append(byteToHex(data >> 16));
|
||||||
|
builder.append(byteToHex(data >> 8));
|
||||||
|
builder.append(byteToHex(data));
|
||||||
break;
|
break;
|
||||||
case INT_COLOR_ARGB4:
|
case INT_COLOR_ARGB4:
|
||||||
index = 4;
|
builder.append(byteToHex(data >> 24));
|
||||||
|
builder.append(byteToHex(data >> 16));
|
||||||
|
builder.append(byteToHex(data >> 8));
|
||||||
|
builder.append(byteToHex(data));
|
||||||
break;
|
break;
|
||||||
case INT_COLOR_RGB8:
|
case INT_COLOR_RGB8:
|
||||||
index = 2;
|
builder.append(byteToHex(data >> 20));
|
||||||
|
builder.append(byteToHex(data >> 16));
|
||||||
|
builder.append(byteToHex(data >> 12));
|
||||||
|
builder.append(byteToHex(data >> 8));
|
||||||
|
builder.append(byteToHex(data >> 4));
|
||||||
|
builder.append(byteToHex(data));
|
||||||
break;
|
break;
|
||||||
case INT_COLOR_ARGB8:
|
case INT_COLOR_ARGB8:
|
||||||
index = 0;
|
builder.append(byteToHex(data >> 28));
|
||||||
|
builder.append(byteToHex(data >> 24));
|
||||||
|
builder.append(byteToHex(data >> 20));
|
||||||
|
builder.append(byteToHex(data >> 16));
|
||||||
|
builder.append(byteToHex(data >> 12));
|
||||||
|
builder.append(byteToHex(data >> 8));
|
||||||
|
builder.append(byteToHex(data >> 4));
|
||||||
|
builder.append(byteToHex(data));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String hex = HexUtil.toHexNoPrefix8(data);
|
return builder.toString();
|
||||||
return "#" + hex.substring(index);
|
|
||||||
}
|
}
|
||||||
public static ValueDecoder.EncodeResult encode(String hexColor){
|
public static ValueDecoder.EncodeResult encode(String hexColor){
|
||||||
int[] values = hexToIntegers(hexColor);
|
int[] values = hexToIntegers(hexColor);
|
||||||
@ -56,11 +72,11 @@ public class ColorUtil {
|
|||||||
if (len == 4) {
|
if (len == 4) {
|
||||||
valueType = ValueType.INT_COLOR_RGB4;
|
valueType = ValueType.INT_COLOR_RGB4;
|
||||||
color |= 0xFF000000;
|
color |= 0xFF000000;
|
||||||
color |= values[1] << 20;
|
color |= (values[1] << 20);
|
||||||
color |= values[1] << 16;
|
color |= (values[1] << 16);
|
||||||
color |= values[2] << 12;
|
color |= (values[2] << 12);
|
||||||
color |= values[2] << 8;
|
color |= (values[2] << 8);
|
||||||
color |= values[3] << 4;
|
color |= (values[3] << 4);
|
||||||
color |= values[3];
|
color |= values[3];
|
||||||
} else if (len == 5) {
|
} else if (len == 5) {
|
||||||
valueType = ValueType.INT_COLOR_ARGB4;
|
valueType = ValueType.INT_COLOR_ARGB4;
|
||||||
@ -96,6 +112,14 @@ public class ColorUtil {
|
|||||||
}
|
}
|
||||||
return new ValueDecoder.EncodeResult(valueType, color);
|
return new ValueDecoder.EncodeResult(valueType, color);
|
||||||
}
|
}
|
||||||
|
private static char byteToHex(int i){
|
||||||
|
i = i & 0xf;
|
||||||
|
if(i < 0xa){
|
||||||
|
return (char) ('0' + i);
|
||||||
|
}
|
||||||
|
i = i - 0xa;
|
||||||
|
return (char) ('a' + i);
|
||||||
|
}
|
||||||
private static int[] hexToIntegers(String hexColor){
|
private static int[] hexToIntegers(String hexColor){
|
||||||
if(hexColor == null){
|
if(hexColor == null){
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user