public static UnpackColor ( PixelFormat pf, |
||
pf | PixelFormat | Pixelformat in which to read the color |
src | Source memory location | |
return |
private void Unpack(ref ColorEx dst, int x, int y, int z, PixelFormat format, BufferBase src, PixelBox srcbox, int elemsize) { var data = src + (elemsize * ((x) + (y) * srcbox.RowPitch + (z) * srcbox.SlicePitch)); dst = PixelConverter.UnpackColor(format, data); }
private void _unpackDXTColor(PixelFormat pf, DXTColorBlock block, ColorEx[] pCol) { // Note - we assume all values have already been endian swapped // Colour lookup table var derivedColours = new ColorEx[4]; using (var src = BufferBase.Wrap(block.colour_0, 1)) { derivedColours[0] = PixelConverter.UnpackColor(PixelFormat.R5G6B5, src); } using (var src = BufferBase.Wrap(block.colour_1, 1)) { derivedColours[1] = PixelConverter.UnpackColor(PixelFormat.R5G6B5, src); } if (pf == PixelFormat.DXT1 && block.colour_0 <= block.colour_1) { // 1-bit alpha // one intermediate colour, half way between the other two derivedColours[2] = (derivedColours[0] + derivedColours[1]) / 2; // transparent colour derivedColours[3] = new ColorEx(0, 0, 0, 0); } else { // first interpolated colour, 1/3 of the way along derivedColours[2] = (derivedColours[0] * 2 + derivedColours[1]) / 3; // second interpolated colour, 2/3 of the way along derivedColours[3] = (derivedColours[0] + derivedColours[1] * 2) / 3; } // Process 4x4 block of texels for (var row = 0; row < 4; ++row) { for (var x = 0; x < 4; ++x) { // LSB come first var colIdx = (byte)block.indexRow[row] >> (x * 2) & 0x3; if (pf == PixelFormat.DXT1) { // Overwrite entire colour pCol[(row * 4) + x] = derivedColours[colIdx]; } else { // alpha has already been read (alpha precedes colour) var col = pCol[(row * 4) + x]; col.r = derivedColours[colIdx].r; col.g = derivedColours[colIdx].g; col.b = derivedColours[colIdx].b; } } } }