Example #1
0
            /// <inheritdoc />
            public override byte[] ConvertBytes(byte[] data, PixelFormatMask mask)
            {
                byte[] rgbTextureBytes = new byte[data.Length / 2 * 3];

                for (int i = 0, j = 0; i < data.Length; i += 2)
                {
                    short c = BitConverter.ToInt16(data, i);
                    rgbTextureBytes[j++] = (byte)(((c & mask.RedMask) >> 10) << 3);
                    rgbTextureBytes[j++] = (byte)(((c & mask.GreenMask) >> 5) << 3);
                    rgbTextureBytes[j++] = (byte)((c & mask.BlueMask) << 3);
                }

                return(rgbTextureBytes);
            }
Example #2
0
            /// <inheritdoc />
            public override byte[] ConvertBytes(byte[] inBytes, PixelFormatMask mask)
            {
                byte[] rgbTextureBytes = new byte[inBytes.Length / 2 * 3];

                for (int i = 0, j = 0; i < inBytes.Length; i += 2)
                {
                    short c = BitConverter.ToInt16(inBytes, i);
                    rgbTextureBytes[j++] = (byte)(((c & mask.RedMask) >> 8) << 4);
                    rgbTextureBytes[j++] = (byte)(((c & mask.GreenMask) >> 4) << 4);
                    rgbTextureBytes[j++] = (byte)(((c & mask.BlueMask)) << 4);
                }

                return(rgbTextureBytes);
            }
Example #3
0
        /// <inheritdoc />
        public void LoadTextureData(BinaryReader reader)
        {
            Width  = reader.ReadUInt16();
            Height = reader.ReadUInt16();

            reader.BaseStream.Seek(768, SeekOrigin.Current); //Empty Data

            ImageData = reader.DecodeRLE(Width, Height, 2);

            if (reader.ReadBytes(4).GetString() != "PFRM")
            {
                Debug.Log($"Wrong Image Type! PFRM Section not fount at position {reader.BaseStream.Position}");

                return;
            }

            _PixelFormatMask = reader.Read <PixelFormatMask>();
        }
Example #4
0
        /// <inheritdoc />
        public void LoadTextureData(BinaryReader reader, int width, int height)
        {
            Width  = width;
            Height = height;

            long filePosition = reader.BaseStream.Position - 18;

            if (reader.ReadBytes(4).GetString() != "LOFF")
            {
                Debug.LogError("LOFF not found!");
                return;
            }

            reader.ReadUInt32();
            uint offset = reader.ReadUInt32();

            _ImageData = reader.ReadBytes(width * height * 2);

            reader.BaseStream.Seek(offset + filePosition, SeekOrigin.Begin);

            string section = reader.ReadBytes(4).GetString();

            if (section != "PFRM")
            {
                if (section == "LVMP")
                {
                    reader.BaseStream.Seek(reader.ReadUInt32() + 6, SeekOrigin.Current); //At now we don't need mipmaps

#if false                                                                                // TODO: Fix mipmaps load
                    var mipmapCount = reader.ReadUInt32();
                    var w           = reader.ReadUInt32();
                    var h           = reader.ReadUInt32();
                    var bit         = reader.ReadUInt32();

                    if (bit == 2)
                    {
                        var mipmapsShorts = new List <ushort[]>();

                        for (int i = 0; i < mipmapCount; i++)
                        {
                            ushort[] data = new ushort[w * h];

                            for (int j = 0; j < data.Length; j++)
                            {
                                data[j] = reader.ReadUInt16();
                            }

                            data = data.Reverse().ToArray();
                            mipmapsShorts.Add(data);


                            w /= 2;
                            h /= 2;
                        }

                        mipmaps = new List <byte[]>();

                        for (int i = 0; i < mipmapCount; i++)
                        {
                            mipmaps.Add(new byte[mipmapsShorts[i].Length * 2]);
                            Buffer.BlockCopy(mipmapsShorts[i], 0, mipmaps[i], 0, mipmaps[i].Length);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < mipmapCount; i++)
                        {
                            byte[] data = new byte[w * h];

                            for (int j = 0; j < data.Length; j++)
                            {
                                data[j] = reader.ReadByte();
                            }

                            data = data.Reverse().ToArray();
                            mipmaps.Add(data);

                            w /= 2;
                            h /= 2;
                        }
                    }

                    reader.BaseStream.Seek(2, SeekOrigin.Current);
                    Debug.Log(reader.BaseStream.Position);
#endif
                }
                else
                {
                    Debug.Log($"PFRM not found at pos: {reader.BaseStream.Position}!");
                    return;
                }
            }

            _PixelFormatMask = reader.Read <PixelFormatMask>();
        }
Example #5
0
 /// <inheritdoc />
 public override byte[] ConvertBytes(byte[] inBytes, PixelFormatMask mask)
 {
     return(inBytes);
 }
Example #6
0
 public abstract byte[] ConvertBytes(byte[] inBytes, PixelFormatMask mask);