Пример #1
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height * 2];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = 0x0000;
                                pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 2] >> 3) << 11);
                                pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 1] >> 2) << 5);
                                pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 0] >> 3) << 0);
                                //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 2] * 0x1F / 0xFF) & 0x1F) << 11);
                                //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 1] * 0x3F / 0xFF) & 0x3F) << 5);
                                //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 0] * 0x1F / 0xFF) & 0x1F) << 0);

                                PTMethods.GetBytesBE(pixel).CopyTo(output, offset);
                                offset += 2;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #2
0
            public override byte[] Decompress(byte[] input, int DataOffset, VrPixelCodec PixelCodec, VrDataCodec DataCodec)
            {
                byte[] output     = new byte[BitConverter.ToUInt32(input, 0x00)];
                int SourcePointer = DataOffset;
                int DestPointer   = 0x00;
                int PixelSize     = (DataCodec.GetBpp(PixelCodec) / 8);

                // Copy the header
                if (DataOffset - 4 > 0)
                {
                    Array.Copy(input, 0x04, output, 0x00, DataOffset - 4);
                    DestPointer += (DataOffset - 4);
                }

                // Decompress
                while (SourcePointer < input.Length && DestPointer < output.Length)
                {
                    int amount = input[SourcePointer + PixelSize] + 1;
                    for (int i = 0; i < amount; i++)
                    {
                        Array.Copy(input, SourcePointer, output, DestPointer, PixelSize);
                        DestPointer += PixelSize;
                    }

                    SourcePointer += PixelSize + 1;
                }

                return output;
            }
Пример #3
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height * 2];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                int  loc   = ((y + y2) * width) + (x + x2);
                                byte entry = (byte)((0.30 * input[loc + 2]) + (0.59 * input[loc + 1]) + (0.11 * input[loc + 0]));

                                output[offset + 0] = input[loc + 3];
                                output[offset + 1] = entry;
                                offset            += 2;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #4
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset    = 0;
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                output[offset + 0]  = input[((((y + y2) * width) + (x + x2)) * 4) + 3];
                                output[offset + 1]  = input[((((y + y2) * width) + (x + x2)) * 4) + 2];
                                output[offset + 32] = input[((((y + y2) * width) + (x + x2)) * 4) + 1];
                                output[offset + 33] = input[((((y + y2) * width) + (x + x2)) * 4) + 0];

                                offset += 2;
                            }
                        }

                        offset += 32;
                    }
                }

                return output;
            }
Пример #5
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                int  loc   = ((y + y2) * width) + (x + x2);
                                byte entry = (byte)(((0.30 * input[loc + 2]) + (0.59 * input[loc + 1]) + (0.11 * input[loc + 0])) * 0x0F / 0xFF);
                                entry = (byte)(((((input[loc + 3]) * 0x0F / 0xFF) & 0x0F) << 4) | (entry & 0x0F));

                                output[offset] = entry;
                                offset++;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #6
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output     = new byte[(width * height) / 2];
                bool   IsSwizzled = (width >= 128 && height >= 128);

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int  offset = GetSwizzledOffset4(x, y, width, height);
                        byte entry  = (byte)(input[(y * width) + x] & 0x0F);
                        if (IsSwizzled)
                        {
                            entry = (byte)((output[offset] & (0x0F << ((y >> 1) & 0x01) * 4)) | (entry << ((~(y >> 1) & 0x01) * 4)));
                        }
                        else
                        {
                            entry = (byte)((output[offset] & (0x0F << (x & 0x01) * 4)) | (entry << ((~x & 0x01) * 4)));
                        }

                        output[GetSwizzledOffset4(x, y, width, height)] = entry;
                    }
                }

                return(output);
            }
Пример #7
0
            public override byte[] Decompress(byte[] input, int DataOffset, VrPixelCodec PixelCodec, VrDataCodec DataCodec)
            {
                byte[] output        = new byte[PTMethods.ToUInt32(input, 0x00, true)];
                int    SourcePointer = DataOffset;
                int    DestPointer   = 0x00;
                int    PixelSize     = (DataCodec.Bpp >> 3);

                // Copy the header
                if (DataOffset - 4 > 0)
                {
                    Array.Copy(input, 0x04, output, 0x00, DataOffset - 4);
                    DestPointer += (DataOffset - 4);
                }

                // Decompress
                while (SourcePointer < input.Length && DestPointer < output.Length)
                {
                    int amount = input[SourcePointer + PixelSize] + 1;
                    for (int i = 0; i < amount; i++)
                    {
                        Array.Copy(input, SourcePointer, output, DestPointer, PixelSize);
                        DestPointer += PixelSize;
                    }

                    SourcePointer += PixelSize + 1;
                }

                return(output);
            }
Пример #8
0
            public override byte[] Compress(byte[] input, int DataOffset, VrPixelCodec PixelCodec, VrDataCodec DataCodec)
            {
                // We can't compress 4-bit textures
                if (DataCodec.Bpp < 8)
                {
                    return(input);
                }

                MemoryStream output        = new MemoryStream();
                int          SourcePointer = DataOffset;
                int          DestPointer   = DataOffset + 4;
                int          PixelSize     = (DataCodec.Bpp >> 3);

                using (BinaryWriter Writer = new BinaryWriter(output))
                {
                    Writer.Write(input.Length);            // Decompressed filesize
                    Writer.Write(input, 0x00, DataOffset); // Header

                    while (SourcePointer < input.Length)
                    {
                        byte[] pixel = new byte[PixelSize];
                        Array.Copy(input, SourcePointer, pixel, 0x00, PixelSize);
                        Writer.Write(pixel);
                        SourcePointer += PixelSize;
                        DestPointer   += PixelSize;

                        int repeat = 0;
                        while (SourcePointer + PixelSize < input.Length && repeat < 255)
                        {
                            bool match = true;

                            for (int i = 0; i < PixelSize && match; i++)
                            {
                                if (input[SourcePointer + i] != pixel[i])
                                {
                                    match = false;
                                    break;
                                }
                            }

                            if (match)
                            {
                                repeat++;
                                SourcePointer += PixelSize;
                            }
                            else
                            {
                                break;
                            }
                        }

                        Writer.Write((byte)repeat);
                        DestPointer++;
                    }

                    Writer.Flush();
                }

                return(output.ToArray());
            }
Пример #9
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                output[offset + 0]  = input[((((y + y2) * width) + (x + x2)) * 4) + 3];
                                output[offset + 1]  = input[((((y + y2) * width) + (x + x2)) * 4) + 2];
                                output[offset + 32] = input[((((y + y2) * width) + (x + x2)) * 4) + 1];
                                output[offset + 33] = input[((((y + y2) * width) + (x + x2)) * 4) + 0];

                                offset += 2;
                            }
                        }

                        offset += 32;
                    }
                }

                return(output);
            }
Пример #10
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[(width * height) / 2];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                byte entry = (byte)(input[((y + y2) * width) + (x + x2)] & 0x0F);
                                entry = (byte)((output[offset] & (0x0F << (x2 & 0x01) * 4)) | (entry << ((~x2 & 0x01) * 4)));

                                output[offset] = entry;

                                if ((x2 & 0x01) != 0)
                                {
                                    offset++;
                                }
                            }
                        }
                    }
                }

                return(output);
            }
Пример #11
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];
                byte[,] clut  = ClutData;
                int ChunkSize = Math.Min(width, height);
                TwiddledMap TwiddledMap = new TwiddledMap(ChunkSize, GetBpp(PixelCodec));

                for (int y = 0; y < height; y += ChunkSize)
                {
                    for (int x = 0; x < width; x += ChunkSize)
                    {
                        int StartOffset = offset;

                        for (int y2 = 0; y2 < ChunkSize; y2++)
                        {
                            for (int x2 = 0; x2 < ChunkSize; x2++)
                            {
                                byte entry = input[StartOffset + TwiddledMap.GetTwiddledOffset(x2, y2)];
                                entry = (byte)((entry >> ((y2 & 0x01) * 4)) & 0x0F);

                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = clut[entry, 3];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = clut[entry, 2];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = clut[entry, 1];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = clut[entry, 0];

                                if ((x2 & 0x01) != 0)
                                    offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #12
0
            public override byte[] Compress(byte[] input, int DataOffset, VrPixelCodec PixelCodec, VrDataCodec DataCodec)
            {
                // We can't compress 4-bit textures
                if (DataCodec.Bpp < 8)
                    return input;

                MemoryStream output = new MemoryStream();
                int SourcePointer   = DataOffset;
                int DestPointer     = DataOffset + 4;
                int PixelSize = (DataCodec.Bpp >> 3);

                using (BinaryWriter Writer = new BinaryWriter(output))
                {
                    Writer.Write(input.Length); // Decompressed filesize
                    Writer.Write(input, 0x00, DataOffset); // Header

                    while (SourcePointer < input.Length)
                    {
                        byte[] pixel = new byte[PixelSize];
                        Array.Copy(input, SourcePointer, pixel, 0x00, PixelSize);
                        Writer.Write(pixel);
                        SourcePointer += PixelSize;
                        DestPointer   += PixelSize;

                        int repeat = 0;
                        while (SourcePointer + PixelSize < input.Length && repeat < 255)
                        {
                            bool match = true;

                            for (int i = 0; i < PixelSize && match; i++)
                            {
                                if (input[SourcePointer + i] != pixel[i])
                                {
                                    match = false;
                                    break;
                                }
                            }

                            if (match)
                            {
                                repeat++;
                                SourcePointer += PixelSize;
                            }
                            else
                                break;
                        }

                        Writer.Write((byte)repeat);
                        DestPointer++;
                    }

                    Writer.Flush();
                }

                return output.ToArray();
            }
Пример #13
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height * 2];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = 0x0000;

                                if (input[((((y + y2) * width) + (x + x2)) * 4) + 3] <= 0xDA) // Argb3444
                                {
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 3] >> 5) << 12);
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 2] >> 4) << 8);
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 1] >> 4) << 4);
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 0] >> 4) << 0);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 3] * 0x07 / 0xFF) & 0x07) << 12);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 2] * 0x0F / 0xFF) & 0x0F) << 8);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 1] * 0x0F / 0xFF) & 0x0F) << 4);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 0] * 0x0F / 0xFF) & 0x0F) << 0);
                                }
                                else // Rgb555
                                {
                                    pixel |= 0x8000;
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 2] >> 3) << 10);
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 1] >> 3) << 5);
                                    pixel |= (ushort)((input[((((y + y2) * width) + (x + x2)) * 4) + 0] >> 3) << 0);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 2] * 0x1F / 0xFF) & 0x1F) << 10);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 1] * 0x1F / 0xFF) & 0x1F) << 5);
                                    //pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 0] * 0x1F / 0xFF) & 0x1F) << 0);
                                }

                                PTMethods.GetBytesBE(pixel).CopyTo(output, offset);
                                offset += 2;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #14
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height];

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        byte entry = input[(y * width) + x];
                        entry = (byte)((entry & 0xE7) | ((entry & 0x10) >> 1) | ((entry & 0x08) << 1));

                        output[GetSwizzledOffset8(x, y, width, height)] = entry;
                    }
                }

                return(output);
            }
Пример #15
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height / 2];

                byte[] subBlock;
                byte[] result;

                result   = new byte[32];
                subBlock = new byte[64];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2 += 4)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 4)
                            {
                                int i = 0;

                                for (int y3 = 0; y3 < 4; y3++)
                                {
                                    for (int x3 = 0; x3 < 4; x3++)
                                    {
                                        subBlock[i + 3] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 3];
                                        subBlock[i + 2] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 2];
                                        subBlock[i + 1] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 1];
                                        subBlock[i + 0] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 0];

                                        i += 4;
                                    }
                                }

                                ConvertBlockToQuaterCmpr(subBlock).CopyTo(output, offset);
                                offset += 8;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #16
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;

                byte[] output = new byte[width * height];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                output[offset] = input[((y + y2) * width) + (x + x2)];
                                offset++;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #17
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[]   output = new byte[width * height * 4];
                byte[][] clut   = palette;

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                byte entry = (byte)((input[offset] >> ((~x2 & 0x01) * 4)) & 0x0F);

                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = clut[entry][3];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = clut[entry][2];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = clut[entry][1];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = clut[entry][0];

                                if ((x2 & 0x01) != 0)
                                {
                                    offset++;
                                }
                            }
                        }
                    }
                }

                return(output);
            }
Пример #18
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height];

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        byte entry = input[(y * width) + x];
                        entry      = (byte)((entry & 0xE7) | ((entry & 0x10) >> 1) | ((entry & 0x08) << 1));

                        output[GetSwizzledOffset8(x, y, width, height)] = entry;
                    }
                }

                return output;
            }
Пример #19
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * (GetBpp(PixelCodec) / 8)];

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        byte[] palette = PixelCodec.CreatePixelPalette(input, (((y * width) + x) * 4));
                        palette.CopyTo(output, GetSwizzledOffset(x, y, width, height, GetBpp(PixelCodec)));
                    }
                }

                return output;
            }
Пример #20
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output   = new byte[width * height * 4];
                int StartOffset = offset;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        byte[] palette = PixelCodec.GetPixelPalette(input, StartOffset + GetSwizzledOffset(x, y, width, height, GetBpp(PixelCodec)));

                        output[(((y * width) + x) * 4) + 3] = palette[3];
                        output[(((y * width) + x) * 4) + 2] = palette[2];
                        output[(((y * width) + x) * 4) + 1] = palette[1];
                        output[(((y * width) + x) * 4) + 0] = palette[0];

                        offset += (GetBpp(PixelCodec) / 8);
                    }
                }

                return output;
            }
Пример #21
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;
                byte[] output = new byte[width * height / 2];

                byte[] subBlock;
                byte[] result;

                result = new byte[32];
                subBlock = new byte[64];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2 += 4)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 4)
                            {
                                int i = 0;

                                for (int y3 = 0; y3 < 4; y3++)
                                {
                                    for (int x3 = 0; x3 < 4; x3++)
                                    {
                                        subBlock[i + 3] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 3];
                                        subBlock[i + 2] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 2];
                                        subBlock[i + 1] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 1];
                                        subBlock[i + 0] = input[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 0];

                                        i += 4;
                                    }
                                }

                                ConvertBlockToQuaterCmpr(subBlock).CopyTo(output, offset);
                                offset += 8;
                            }
                        }
                    }
                }

                return output;
            }
Пример #22
0
 public override int GetBpp(VrPixelCodec PixelCodec)
 {
     return PixelCodec.GetBpp();
 }
Пример #23
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output   = new byte[width * height * 4];
                byte[,] clut    = ClutData;
                int StartOffset = offset;
                bool IsSwizzled = (width >= 128 && height >= 128);

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        // We use width = height for swizzling. This is for rectangle textures
                        // as they require that. Square textures already are width = height.
                        // Most significant bits first
                        byte entry = input[StartOffset + GetSwizzledOffset4(x, y, width, height)];
                        if (IsSwizzled)
                            entry = (byte)((entry >> ((y >> 1) & 0x01) * 4) & 0x0F);
                        else
                            entry = (byte)((entry >> (x & 0x01) * 4) & 0x0F);

                        output[(((y * width) + x) * 4) + 3] = clut[entry, 3];
                        output[(((y * width) + x) * 4) + 2] = clut[entry, 2];
                        output[(((y * width) + x) * 4) + 1] = clut[entry, 1];
                        output[(((y * width) + x) * 4) + 0] = clut[entry, 0];

                        if ((x & 0x01) != 0)
                            offset++;
                    }
                }

                return output;
            }
Пример #24
0
        private PvrPixelFormat pixelFormat; // Pixel format

        #endregion Fields

        #region Constructors

        internal PvpPaletteEncoder(byte[][] palette, ushort numColors, PvrPixelFormat pixelFormat, VrPixelCodec pixelCodec)
            : base(palette, numColors, pixelCodec)
        {
            this.pixelFormat = pixelFormat;
        }
Пример #25
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output   = new byte[width * height * 4];
                byte[,] clut    = ClutData;
                int StartOffset = offset;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        byte entry = input[StartOffset + GetSwizzledOffset8(x, y, width, height)];
                        entry      = (byte)((entry & 0xE7) | ((entry & 0x10) >> 1) | ((entry & 0x08) << 1));

                        output[(((y * width) + x) * 4) + 3] = clut[entry, 3];
                        output[(((y * width) + x) * 4) + 2] = clut[entry, 2];
                        output[(((y * width) + x) * 4) + 1] = clut[entry, 1];
                        output[(((y * width) + x) * 4) + 0] = clut[entry, 0];

                        offset++;
                    }
                }

                return output;
            }
Пример #26
0
 public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
 {
     return null;
 }
Пример #27
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = input[offset];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = input[offset];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = input[offset];

                                offset++;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #28
0
 public abstract byte[] Compress(byte[] input, int DataOffset, VrPixelCodec PixelCodec, VrDataCodec DataCodec);
Пример #29
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = PTMethods.ToUInt16BE(input, offset);

                                //output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                //output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 11) & 0x1F) << 11);
                                //output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5) & 0x3F) << 10);
                                //output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x1F) << 11);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 11) & 0x1F) * 0xFF / 0x1F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5)  & 0x3F) * 0xFF / 0x3F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0)  & 0x1F) * 0xFF / 0x1F);

                                offset += 2;
                            }
                        }
                    }
                }

                return output;
            }
Пример #30
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                // Palette for each 4x4 block
                byte[][] palette = new byte[4][];
                palette[0] = new byte[4];
                palette[1] = new byte[4];
                palette[2] = new byte[4];
                palette[3] = new byte[4];

                // The two colors that determine the palette
                ushort[] pixel = new ushort[2];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2 += 4)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 4)
                            {
                                // Get the first two colors
                                pixel[0] = PTMethods.ToUInt16BE(input, offset);
                                pixel[1] = PTMethods.ToUInt16BE(input, offset + 2);

                                palette[0][3] = 0xFF;
                                palette[0][2] = (byte)(((pixel[0] >> 11) & 0x1F) * 0xFF / 0x1F);
                                palette[0][1] = (byte)(((pixel[0] >> 5) & 0x3F) * 0xFF / 0x3F);
                                palette[0][0] = (byte)(((pixel[0] >> 0) & 0x1F) * 0xFF / 0x1F);

                                palette[1][3] = 0xFF;
                                palette[1][2] = (byte)(((pixel[1] >> 11) & 0x1F) * 0xFF / 0x1F);
                                palette[1][1] = (byte)(((pixel[1] >> 5) & 0x3F) * 0xFF / 0x3F);
                                palette[1][0] = (byte)(((pixel[1] >> 0) & 0x1F) * 0xFF / 0x1F);

                                // Determine the next two colors based on how the first two are stored
                                if (pixel[0] > pixel[1])
                                {
                                    palette[2][3] = 0xFF;
                                    palette[2][2] = (byte)(((palette[0][2] * 2) + palette[1][2]) / 3);
                                    palette[2][1] = (byte)(((palette[0][1] * 2) + palette[1][1]) / 3);
                                    palette[2][0] = (byte)(((palette[0][0] * 2) + palette[1][0]) / 3);

                                    palette[3][3] = 0xFF;
                                    palette[3][2] = (byte)(((palette[1][2] * 2) + palette[0][2]) / 3);
                                    palette[3][1] = (byte)(((palette[1][1] * 2) + palette[0][1]) / 3);
                                    palette[3][0] = (byte)(((palette[1][0] * 2) + palette[0][0]) / 3);
                                }
                                else
                                {
                                    palette[2][3] = 0xFF;
                                    palette[2][2] = (byte)((palette[0][2] + palette[1][2]) / 2);
                                    palette[2][1] = (byte)((palette[0][1] + palette[1][1]) / 2);
                                    palette[2][0] = (byte)((palette[0][0] + palette[1][0]) / 2);

                                    palette[3][3] = 0x00;
                                    palette[3][2] = 0x00;
                                    palette[3][1] = 0x00;
                                    palette[3][0] = 0x00;
                                }

                                offset += 4;

                                for (int y3 = 0; y3 < 4; y3++)
                                {
                                    for (int x3 = 0; x3 < 4; x3++)
                                    {
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 3] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][3];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 2] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][2];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 1] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][1];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 0] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][0];
                                    }

                                    offset++;
                                }
                            }
                        }
                    }
                }

                return(output);
            }
Пример #31
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = SwapUShort(BitConverter.ToUInt16(input, offset));

                                if ((pixel & 0x8000) != 0) // Rgb555
                                {
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 10) & 0x1F) * 0xFF / 0x1F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5)  & 0x1F) * 0xFF / 0x1F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0)  & 0x1F) * 0xFF / 0x1F);
                                }
                                else // Argb3444
                                {
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 3] = (byte)(((pixel >> 12) & 0x07) * 0xFF / 0x07);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 8)  & 0x0F) * 0xFF / 0x0F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 4)  & 0x0F) * 0xFF / 0x0F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0)  & 0x0F) * 0xFF / 0x0F);
                                }

                                offset += 2;
                            }
                        }
                    }
                }

                return output;
            }
Пример #32
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[(width * height) / 2];
                bool IsSwizzled = (width >= 128 && height >= 128);

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int offset = GetSwizzledOffset4(x, y, width, height);
                        byte entry = (byte)(input[(y * width) + x] & 0x0F);
                        if (IsSwizzled)
                            entry = (byte)((output[offset] & (0x0F << ((y >> 1) & 0x01) * 4)) | (entry << ((~(y >> 1) & 0x01) * 4)));
                        else
                            entry = (byte)((output[offset] & (0x0F << (x & 0x01) * 4)) | (entry << ((~x & 0x01) * 4)));

                        output[GetSwizzledOffset4(x, y, width, height)] = entry;
                    }
                }

                return output;
            }
Пример #33
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                // Palette for each 4x4 block
                byte[][] palette = new byte[4][];
                palette[0] = new byte[4];
                palette[1] = new byte[4];
                palette[2] = new byte[4];
                palette[3] = new byte[4];

                // The two colors that determine the palette
                ushort[] pixel = new ushort[2];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2 += 4)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 4)
                            {
                                // Get the first two colors
                                pixel[0] = PTMethods.ToUInt16BE(input, offset);
                                pixel[1] = PTMethods.ToUInt16BE(input, offset + 2);

                                palette[0][3] = 0xFF;
                                palette[0][2] = (byte)(((pixel[0] >> 11) & 0x1F) * 0xFF / 0x1F);
                                palette[0][1] = (byte)(((pixel[0] >> 5)  & 0x3F) * 0xFF / 0x3F);
                                palette[0][0] = (byte)(((pixel[0] >> 0)  & 0x1F) * 0xFF / 0x1F);

                                palette[1][3] = 0xFF;
                                palette[1][2] = (byte)(((pixel[1] >> 11) & 0x1F) * 0xFF / 0x1F);
                                palette[1][1] = (byte)(((pixel[1] >> 5)  & 0x3F) * 0xFF / 0x3F);
                                palette[1][0] = (byte)(((pixel[1] >> 0)  & 0x1F) * 0xFF / 0x1F);

                                // Determine the next two colors based on how the first two are stored
                                if (pixel[0] > pixel[1])
                                {
                                    palette[2][3] = 0xFF;
                                    palette[2][2] = (byte)(((palette[0][2] * 2) + palette[1][2]) / 3);
                                    palette[2][1] = (byte)(((palette[0][1] * 2) + palette[1][1]) / 3);
                                    palette[2][0] = (byte)(((palette[0][0] * 2) + palette[1][0]) / 3);

                                    palette[3][3] = 0xFF;
                                    palette[3][2] = (byte)(((palette[1][2] * 2) + palette[0][2]) / 3);
                                    palette[3][1] = (byte)(((palette[1][1] * 2) + palette[0][1]) / 3);
                                    palette[3][0] = (byte)(((palette[1][0] * 2) + palette[0][0]) / 3);
                                }
                                else
                                {
                                    palette[2][3] = 0xFF;
                                    palette[2][2] = (byte)((palette[0][2] + palette[1][2]) / 2);
                                    palette[2][1] = (byte)((palette[0][1] + palette[1][1]) / 2);
                                    palette[2][0] = (byte)((palette[0][0] + palette[1][0]) / 2);

                                    palette[3][3] = 0x00;
                                    palette[3][2] = 0x00;
                                    palette[3][1] = 0x00;
                                    palette[3][0] = 0x00;
                                }

                                offset += 4;

                                for (int y3 = 0; y3 < 4; y3++)
                                {
                                    for (int x3 = 0; x3 < 4; x3++)
                                    {
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 3] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][3];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 2] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][2];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 1] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][1];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 0] = palette[((input[offset] >> (6 - (x3 * 2))) & 0x03)][0];
                                    }

                                    offset++;
                                }
                            }
                        }
                    }
                }

                return output;
            }
Пример #34
0
 public abstract byte[] Decompress(byte[] input, int DataOffset, VrPixelCodec PixelCodec, VrDataCodec DataCodec);
Пример #35
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;
                byte[] output = new byte[width * height];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                output[offset] = input[((y + y2) * width) + (x + x2)];
                                offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #36
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2 += 4)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 4)
                            {
                                // Determine the colors for the 4x4 clut
                                byte[,] Clut   = new byte[4, 4];
                                ushort[] pixel = new ushort[2];

                                // Get the first two colors
                                pixel[0] = SwapUShort(BitConverter.ToUInt16(input, offset));
                                pixel[1] = SwapUShort(BitConverter.ToUInt16(input, offset + 2));

                                Clut[0, 3] = 0xFF;
                                Clut[0, 2] = (byte)(((pixel[0] >> 11) & 0x1F) * 0xFF / 0x1F);
                                Clut[0, 1] = (byte)(((pixel[0] >> 5)  & 0x3F) * 0xFF / 0x3F);
                                Clut[0, 0] = (byte)(((pixel[0] >> 0)  & 0x1F) * 0xFF / 0x1F);

                                Clut[1, 3] = 0xFF;
                                Clut[1, 2] = (byte)(((pixel[1] >> 11) & 0x1F) * 0xFF / 0x1F);
                                Clut[1, 1] = (byte)(((pixel[1] >> 5)  & 0x3F) * 0xFF / 0x3F);
                                Clut[1, 0] = (byte)(((pixel[1] >> 0)  & 0x1F) * 0xFF / 0x1F);

                                // Determine the next two colors based on how the first two are stored
                                if (pixel[0] > pixel[1])
                                {
                                    Clut[2, 3] = 0xFF;
                                    Clut[2, 2] = (byte)(((Clut[0, 2] * 2) + Clut[1, 2]) / 3);
                                    Clut[2, 1] = (byte)(((Clut[0, 1] * 2) + Clut[1, 1]) / 3);
                                    Clut[2, 0] = (byte)(((Clut[0, 0] * 2) + Clut[1, 0]) / 3);

                                    Clut[3, 3] = 0xFF;
                                    Clut[3, 2] = (byte)(((Clut[1, 2] * 2) + Clut[0, 2]) / 3);
                                    Clut[3, 1] = (byte)(((Clut[1, 1] * 2) + Clut[0, 1]) / 3);
                                    Clut[3, 0] = (byte)(((Clut[1, 0] * 2) + Clut[0, 0]) / 3);
                                }
                                else
                                {
                                    Clut[2, 3] = 0xFF;
                                    Clut[2, 2] = (byte)((Clut[0, 2] + Clut[1, 2]) / 2);
                                    Clut[2, 1] = (byte)((Clut[0, 1] + Clut[1, 1]) / 2);
                                    Clut[2, 0] = (byte)((Clut[0, 0] + Clut[1, 0]) / 2);

                                    Clut[3, 3] = 0x00;
                                    Clut[3, 2] = 0x00;
                                    Clut[3, 1] = 0x00;
                                    Clut[3, 0] = 0x00;
                                }

                                offset += 4;

                                for (int y3 = 0; y3 < 4; y3++)
                                {
                                    for (int x3 = 0; x3 < 4; x3++)
                                    {
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 3] = Clut[((input[offset] >> (6 - (x3 * 2))) & 0x03), 3];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 2] = Clut[((input[offset] >> (6 - (x3 * 2))) & 0x03), 2];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 1] = Clut[((input[offset] >> (6 - (x3 * 2))) & 0x03), 1];
                                        output[((((y + y2 + y3) * width) + (x + x2 + x3)) * 4) + 0] = Clut[((input[offset] >> (6 - (x3 * 2))) & 0x03), 0];
                                    }

                                    offset++;
                                }
                            }
                        }
                    }
                }

                return output;
            }
Пример #37
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;
                byte[] output = new byte[(width * height) / 2];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                int loc    = ((y + y2) * width) + (x + x2);
                                byte entry = (byte)(((0.30 * input[loc + 2]) + (0.59 * input[loc + 1]) + (0.11 * input[loc + 0])) * 0x0F / 0xFF);
                                entry      = (byte)((output[offset] & (0x0F << (x2 & 0x01) * 4)) | (entry << ((~x2 & 0x01) * 4)));

                                output[offset] = entry;

                                if ((x2 & 0x01) != 0)
                                    offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #38
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];
                byte[,] clut  = ClutData;

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = clut[input[offset], 3];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = clut[input[offset], 2];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = clut[input[offset], 1];
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = clut[input[offset], 0];

                                offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #39
0
            public override byte[] DecodeMipmap(byte[] input, int offset, int mipmap, int width, int height, VrPixelCodec PixelCodec)
            {
                // Get the width of the mipmap and go to the correct offset
                int MipmapWidth = width;
                for (int i = 0; i < mipmap; i++)
                    MipmapWidth >>= 1;

                for (int i = 1; i < MipmapWidth; i <<= 1)
                    offset += (Math.Max(i * i, 4) >> 2);

                return Decode(input, offset, MipmapWidth, MipmapWidth, PixelCodec);
            }
Пример #40
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 8)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                byte entry = (byte)((input[offset] >> ((~x2 & 0x01) * 4)) & 0x0F);

                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(entry * 0xFF / 0x0F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(entry * 0xFF / 0x0F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(entry * 0xFF / 0x0F);

                                if ((x2 & 0x01) != 0)
                                    offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #41
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = (byte)(((input[offset] >> 4) & 0x0F) * 0xFF / 0x0F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)((input[offset] & 0x0F) * 0xFF / 0x0F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)((input[offset] & 0x0F) * 0xFF / 0x0F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)((input[offset] & 0x0F) * 0xFF / 0x0F);

                                offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #42
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;
                byte[] output = new byte[width * height * 2];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                int loc    = ((y + y2) * width) + (x + x2);
                                byte entry = (byte)((0.30 * input[loc + 2]) + (0.59 * input[loc + 1]) + (0.11 * input[loc + 0]));

                                output[offset + 0] = input[loc + 3];
                                output[offset + 1] = entry;
                                offset += 2;
                            }
                        }
                    }
                }

                return output;
            }
Пример #43
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[]   output      = new byte[width * height * 4];
                byte[][] clut        = palette;
                int      StartOffset = offset;
                bool     IsSwizzled  = (width >= 128 && height >= 128);

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        // We use width = height for swizzling. This is for rectangle textures
                        // as they require that. Square textures already are width = height.
                        // Most significant bits first
                        byte entry = input[StartOffset + GetSwizzledOffset4(x, y, width, height)];
                        if (IsSwizzled)
                        {
                            entry = (byte)((entry >> ((y >> 1) & 0x01) * 4) & 0x0F);
                        }
                        else
                        {
                            entry = (byte)((entry >> (x & 0x01) * 4) & 0x0F);
                        }

                        output[(((y * width) + x) * 4) + 3] = clut[entry][3];
                        output[(((y * width) + x) * 4) + 2] = clut[entry][2];
                        output[(((y * width) + x) * 4) + 1] = clut[entry][1];
                        output[(((y * width) + x) * 4) + 0] = clut[entry][0];

                        if ((x & 0x01) != 0)
                        {
                            offset++;
                        }
                    }
                }

                return(output);
            }
Пример #44
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset = 0;
                byte[] output = new byte[width * height];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                int loc    = ((y + y2) * width) + (x + x2);
                                byte entry = (byte)(((0.30 * input[loc + 2]) + (0.59 * input[loc + 1]) + (0.11 * input[loc + 0])) * 0x0F / 0xFF);
                                entry      = (byte)(((((input[loc + 3]) * 0x0F / 0xFF) & 0x0F) << 4) | (entry & 0x0F));

                                output[offset] = entry;
                                offset++;
                            }
                        }
                    }
                }

                return output;
            }
Пример #45
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = PTMethods.ToUInt16BE(input, offset);

                                //output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                //output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 11) & 0x1F) << 11);
                                //output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5) & 0x3F) << 10);
                                //output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x1F) << 11);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 11) & 0x1F) * 0xFF / 0x1F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5) & 0x3F) * 0xFF / 0x3F);
                                output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x1F) * 0xFF / 0x1F);

                                offset += 2;
                            }
                        }
                    }
                }

                return(output);
            }
Пример #46
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset    = 0;
                byte[] output = new byte[width * height * 2];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = 0x0000;
                                pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 2] * 0x1F / 0xFF) & 0x1F) << 11);
                                pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 1] * 0x3F / 0xFF) & 0x3F) << 5);
                                pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 0] * 0x1F / 0xFF) & 0x1F) << 0);

                                BitConverter.GetBytes(SwapUShort(pixel)).CopyTo(output, offset);
                                offset += 2;
                            }
                        }
                    }
                }

                return output;
            }
Пример #47
0
 public override int GetBpp(VrPixelCodec PixelCodec)
 {
     return 16;
 }
Пример #48
0
            public override byte[] Encode(byte[] input, int width, int height, VrPixelCodec PixelCodec)
            {
                int offset    = 0;
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = 0x0000;

                                if (input[((((y + y2) * width) + (x + x2)) * 4) + 3] <= 0xDA) // Argb3444
                                {
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 3] * 0x07 / 0xFF) & 0x07) << 12);
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 2] * 0x0F / 0xFF) & 0x0F) << 8);
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 1] * 0x0F / 0xFF) & 0x0F) << 4);
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 0] * 0x0F / 0xFF) & 0x0F) << 0);
                                }
                                else // Rgb555
                                {
                                    pixel |= 0x8000;
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 2] * 0x1F / 0xFF) & 0x1F) << 10);
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 1] * 0x1F / 0xFF) & 0x1F) << 5);
                                    pixel |= (ushort)(((input[((((y + y2) * width) + (x + x2)) * 4) + 0] * 0x1F / 0xFF) & 0x1F) << 0);
                                }

                                BitConverter.GetBytes(SwapUShort(pixel)).CopyTo(output, offset);
                                offset += 2;
                            }
                        }
                    }
                }

                return output;
            }
Пример #49
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[]   output      = new byte[width * height * 4];
                byte[][] clut        = palette;
                int      StartOffset = offset;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        byte entry = input[StartOffset + GetSwizzledOffset8(x, y, width, height)];
                        entry = (byte)((entry & 0xE7) | ((entry & 0x10) >> 1) | ((entry & 0x08) << 1));

                        output[(((y * width) + x) * 4) + 3] = clut[entry][3];
                        output[(((y * width) + x) * 4) + 2] = clut[entry][2];
                        output[(((y * width) + x) * 4) + 1] = clut[entry][1];
                        output[(((y * width) + x) * 4) + 0] = clut[entry][0];

                        offset++;
                    }
                }

                return(output);
            }
Пример #50
0
        private PvrPixelFormat pixelFormat; // Pixel format
        #endregion

        #region Constructors & Initalizers
        internal PvpPaletteEncoder(byte[][] palette, ushort numColors, PvrPixelFormat pixelFormat, VrPixelCodec pixelCodec)
            : base(palette, numColors, pixelCodec)
        {
            this.pixelFormat = pixelFormat;
        }
Пример #51
0
            public override byte[] Decode(byte[] input, int offset, int width, int height, VrPixelCodec PixelCodec)
            {
                byte[] output = new byte[width * height * 4];

                for (int y = 0; y < height; y += 4)
                {
                    for (int x = 0; x < width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort pixel = PTMethods.ToUInt16BE(input, offset);

                                if ((pixel & 0x8000) != 0) // Rgb555
                                {
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 10) & 0x1F) * 0xFF / 0x1F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5) & 0x1F) * 0xFF / 0x1F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x1F) * 0xFF / 0x1F);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 3] = 0xFF;
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 10) & 0x1F) << 11);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 5) & 0x1F) << 11);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x1F) << 11);
                                }
                                else // Argb3444
                                {
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 3] = (byte)(((pixel >> 12) & 0x07) * 0xFF / 0x07);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 8) & 0x0F) * 0xFF / 0x0F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 4) & 0x0F) * 0xFF / 0x0F);
                                    output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x0F) * 0xFF / 0x0F);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 3] = (byte)(((pixel >> 12) & 0x07) << 13);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 2] = (byte)(((pixel >> 8) & 0x0F) << 12);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 1] = (byte)(((pixel >> 4) & 0x0F) << 12);
                                    //output[((((y + y2) * width) + (x + x2)) * 4) + 0] = (byte)(((pixel >> 0) & 0x0F) << 12);
                                }

                                offset += 2;
                            }
                        }
                    }
                }

                return(output);
            }