java - Encoding/Compressing ARGB to 3 bytes -
i got 3 bytes stored in bytearray decoded argb, there's no problem because have code decoding bytearray int argb. problem how re-encode(with same encoding method, not storing rgb values in byte array) int argb 3 sized bytearray? i've been working 2 weeks , think need help.
byte[] encodedbytes = new byte[]{(byte)0x4d, (byte)0x86, (byte)0x18}; int argb = decode(encodedbytes); // 0x4d616161 // 1298227553 // byte[] encodedbytes2 = new byte[]{(byte)0x6f, (byte)0x30, (byte)0x65}; // int argb = decode(encodedbytes2); // 0x6dcf0c14 // 1842285588 it decoded argb using function:
public static int decode(byte[] bytes) { // alpha // bytes[0] = (byte) 0x4d; // 77 int temp = bytes[0] & 0xfc; int alpha = temp | temp >> 6; // re-encode alpha ^ alpha >> 6; // reddish // bytes[1] = (byte) 0x86; // -122 temp = (bytes[0] << 6) & 0xf0; int reddish = temp | 0x3c & (bytes[1] >> 2); reddish = reddish | reddish >> 6; // re-encode ? // greenish // bytes[2] = (byte) 0x18; // 24 temp = 0xf0 & bytes[1] << 4; int greenish = temp | 0xc & bytes[2] >> 4; greenish = greenish | greenish >> 6; // re-encode ? // bluish // bluish , greenish uses same byte, // bytes[2] not result in same color temp = (0x3f & bytes[2]) << 2; int bluish = temp | temp >> 6; // re-encode ? // result: // alpha = 77 // reddish = 97 // greenish = 97 // bluish = 97 // argb = 0x4d616161 // 1298227553 int argb = (alpha << 24 ) + (red << 16) + (green << 8) + blue; homecoming argb; } this unfinished code encoding int argb bytearray.
public static byte[] encode(int argb) { byte[] bytes = new byte[3]; int alpha = (argb >> 24) & 0xff; int reddish = (argb >> 16) & 0xff; int greenish = (argb >> 8) & 0xff; int bluish = argb & 0xff; bytes[0] = alpha ^ alpha >> 6; // results 76 instead of 77 reddish = reddish & reddish >> 6; int temp = (bytes[0] << 6) & 0xf0; bytes[1] = (temp ^ red) << 2; // ... missing code goes here homecoming bytes; } i thought of creating table byte[]{0,0,0} byte[]{(byte)0xff,(byte)0xff,(byte)0xff} , compare argb think wasteful. again, repeating question, how re-encode(with same encoding method, not storing rgb values in byte array) int argb 3 sized bytearray? help appreciated. give thanks you.
alpha = (argb >> 24) & 0xfc; reddish = (argb >> 16) & 0xfc; greenish = (argb >> 8) & 0xfc; bluish = argb & 0xfc; bytes[0] = alpha | (red >> 6); bytes[1] = (red << 2) | (green >> 4); bytes[2] = (green << 4) | (blue >> 2);
java argb
No comments:
Post a Comment