public int encodeColor(int value, CColorFormat format) { int[] res = format.getResolution(); int rgb = 0; int shift = 0; int length = res.Length / 2; for (int i = 0; i < length; i++) { int mode = res[length - i - 1]; int nshift = res[length * 2 - i - 1]; int mult = shiftList[nshift][1]; int and = shiftList[nshift][0]; int n = 0; switch (mode) { case 0: // '\0' n = value >> 24 & 0xff; break; case 1: // '\001' n = value >> 16 & 0xff; break; case 2: // '\002' n = value >> 8 & 0xff; break; case 3: // '\003' n = value & 0xff; break; case 4: // '\004' n = value & 0xff; break; } rgb |= (n / mult & and) << shift; shift += nshift; } return(rgb); }
public int decodeColor(int value, CColorFormat format) { int[] res = format.getResolution(); int rgb = Convert.ToInt32(0xff000000); int shift = 0; int length = res.Length / 2; for (int i = 0; i < length; i++) { int mode = res[length - i - 1]; int nshift = res[length * 2 - i - 1]; int mult = shiftList[nshift][1]; int and = shiftList[nshift][0]; int n = (value >> shift & and) * mult; switch (mode) { case 0: // '\0' rgb |= n << 24; break; case 1: // '\001' rgb |= n << 16; break; case 2: // '\002' rgb |= n << 8; break; case 3: // '\003' rgb |= n; break; case 4: // '\004' rgb = n << 16 | n << 8 | n; break; } shift += nshift; } return(rgb); }