static public void CompressBlock(byte4[] Colors, ref DXT5.AlphaColorBlock Block) { var MinColor = default(byte4); var MaxColor = default(byte4); Console.WriteLine(Colors.Select(Color => (ARGB_Rev)(Y_CO_CG_A)Color).ToStringArray()); GetMinMaxYCoCg(Colors, out MinColor, out MaxColor); Console.WriteLine("-"); Console.WriteLine((ARGB_Rev)MinColor); Console.WriteLine((ARGB_Rev)MaxColor); ScaleYCoCg(Colors, ref MinColor, ref MaxColor); Console.WriteLine("-"); Console.WriteLine((ARGB_Rev)MinColor); Console.WriteLine((ARGB_Rev)MaxColor); InsetYCoCgBBox(ref MinColor, ref MaxColor); Console.WriteLine("-"); Console.WriteLine((ARGB_Rev)MinColor); Console.WriteLine((ARGB_Rev)MaxColor); SelectYCoCgDiagonal(Colors, ref MinColor, ref MaxColor); Console.WriteLine("-"); Console.WriteLine((ARGB_Rev)MinColor); Console.WriteLine((ARGB_Rev)MaxColor); }
/* * void EmitAlphaIndices(byte* colorBlock, byte minAlpha, byte maxAlpha) * { * * int i; * //assert( maxAlpha >= minAlpha ); * * const int ALPHA_RANGE = 7; * * byte mid, ab1, ab2, ab3, ab4, ab5, ab6, ab7; * var indexes = stackalloc byte[16]; * * mid = (byte)((maxAlpha - minAlpha) / (2 * ALPHA_RANGE)); * * ab1 = (byte)(minAlpha + mid); * ab2 = (byte)((6 * maxAlpha + 1 * minAlpha) / ALPHA_RANGE + mid); * ab3 = (byte)((5 * maxAlpha + 2 * minAlpha) / ALPHA_RANGE + mid); * ab4 = (byte)((4 * maxAlpha + 3 * minAlpha) / ALPHA_RANGE + mid); * ab5 = (byte)((3 * maxAlpha + 4 * minAlpha) / ALPHA_RANGE + mid); * ab6 = (byte)((2 * maxAlpha + 5 * minAlpha) / ALPHA_RANGE + mid); * ab7 = (byte)((1 * maxAlpha + 6 * minAlpha) / ALPHA_RANGE + mid); * * for (i = 0; i < 16; i++) * { * byte a = colorBlock[i * 4 + 3]; * int b1 = (a <= ab1) ? 1 : 0; * int b2 = (a <= ab2) ? 1 : 0; * int b3 = (a <= ab3) ? 1 : 0; * int b4 = (a <= ab4) ? 1 : 0; * int b5 = (a <= ab5) ? 1 : 0; * int b6 = (a <= ab6) ? 1 : 0; * int b7 = (a <= ab7) ? 1 : 0; * int index = (b1 + b2 + b3 + b4 + b5 + b6 + b7 + 1) & 7; * indexes[i] = (byte)(index ^ ((2 > index) ? 1 : 0)); * } * * EmitByte((byte)((indexes[0] >> 0) | (indexes[1] << 3) | (indexes[2] << 6))); * EmitByte((byte)((indexes[2] >> 2) | (indexes[3] << 1) | (indexes[4] << 4) | (indexes[5] << 7))); * EmitByte((byte)((indexes[5] >> 1) | (indexes[6] << 2) | (indexes[7] << 5))); * * EmitByte((byte)((indexes[8] >> 0) | (indexes[9] << 3) | (indexes[10] << 6))); * EmitByte((byte)((indexes[10] >> 2) | (indexes[11] << 1) | (indexes[12] << 4) | (indexes[13] << 7))); * EmitByte((byte)((indexes[13] >> 1) | (indexes[14] << 2) | (indexes[15] << 5))); * } * * void EmitColorIndices(byte* colorBlock, byte* minColor, byte* maxColor) * { * var colors = new ushort[4, 4]; * int i; * uint result = 0; * * colors[0, 0] = (ushort)((maxColor[0] & C565_5_MASK) | (maxColor[0] >> 5)); * colors[0, 1] = (ushort)((maxColor[1] & C565_6_MASK) | (maxColor[1] >> 6)); * colors[0, 2] = (ushort)((maxColor[2] & C565_5_MASK) | (maxColor[2] >> 5)); * colors[0, 3] = (ushort)(0); * colors[1, 0] = (ushort)((minColor[0] & C565_5_MASK) | (minColor[0] >> 5)); * colors[1, 1] = (ushort)((minColor[1] & C565_6_MASK) | (minColor[1] >> 6)); * colors[1, 2] = (ushort)((minColor[2] & C565_5_MASK) | (minColor[2] >> 5)); * colors[1, 3] = (ushort)(0); * colors[2, 0] = (ushort)((2 * colors[0, 0] + 1 * colors[1, 0]) / 3); * colors[2, 1] = (ushort)((2 * colors[0, 1] + 1 * colors[1, 1]) / 3); * colors[2, 2] = (ushort)((2 * colors[0, 2] + 1 * colors[1, 2]) / 3); * colors[2, 3] = (ushort)(0); * colors[3, 0] = (ushort)((1 * colors[0, 0] + 2 * colors[1, 0]) / 3); * colors[3, 1] = (ushort)((1 * colors[0, 1] + 2 * colors[1, 1]) / 3); * colors[3, 2] = (ushort)((1 * colors[0, 2] + 2 * colors[1, 2]) / 3); * colors[3, 3] = (ushort)(0); * * for (i = 15; i >= 0; i--) * { * int c0, c1, d0, d1, d2, d3; * * c0 = colorBlock[i * 4 + 0]; * c1 = colorBlock[i * 4 + 1]; * * d0 = Math.Abs(colors[0, 0] - c0) + Math.Abs(colors[0, 1] - c1); * d1 = Math.Abs(colors[1, 0] - c0) + Math.Abs(colors[1, 1] - c1); * d2 = Math.Abs(colors[2, 0] - c0) + Math.Abs(colors[2, 1] - c1); * d3 = Math.Abs(colors[3, 0] - c0) + Math.Abs(colors[3, 1] - c1); * * int b0 = (d0 > d3) ? 1 : 0; * int b1 = (d1 > d2) ? 1 : 0; * int b2 = (d0 > d2) ? 1 : 0; * int b3 = (d1 > d3) ? 1 : 0; * int b4 = (d2 > d3) ? 1 : 0; * * int x0 = b1 & b2; * int x1 = b0 & b3; * int x2 = b0 & b4; * * result |= (uint)((x2 | ((x0 | x1) << 1)) << (i << 1)); * } * * EmitDoubleWord(result); * } */ static public void CompressBlock(ARGB_Rev[] Colors, ref DXT5.AlphaColorBlock Block) { var ColorsCoGg = new byte4[16]; Console.WriteLine(Colors.ToStringArray()); for (int n = 0; n < 16; n++) { ColorsCoGg[n] = (byte4)Colors[n]; } CompressBlock(ColorsCoGg, ref Block); }