internal PapaEncodingTexture(BinaryReader br)
        {
            this.NameIndex = br.ReadInt16();
            this.Format    = (PapaTextureFormat)br.ReadByte();

            byte bits = br.ReadByte();

            this.MipCount = (byte)(bits & 0b01111111);
            this.IsSrgb   = ((bits >> 7) & 1) == 1;

            this.Width      = br.ReadUInt16();
            this.Height     = br.ReadUInt16();
            this.DataSize   = br.ReadUInt64();
            this.DataOffset = br.ReadInt64();
            this.Image      = null;

            long returnOffset = br.BaseStream.Position;

            if (this.DataOffset > 0)
            {
                br.BaseStream.Seek(this.DataOffset, SeekOrigin.Begin);

                byte[]       imageData    = br.ReadBytes((int)this.DataSize);
                MemoryStream simulatedDds = SimulateDdsFile(imageData);
                this.Image = Pfim.Pfim.FromStream(simulatedDds);
            }

            br.BaseStream.Seek(returnOffset, SeekOrigin.Begin);
        }
Exemple #2
0
        public DDSImage(Stream stream)
        {
            if (stream == null)
            {
                throw new Exception($"DDSImage ctor: {nameof(stream)} is null");
            }

            _ddsImageFile = Dds.Create(stream, new PfimConfig(decompress: true));
        }
Exemple #3
0
        public void InitFromDDSImage(Pfim.IImage image)
        {
            Width  = (ushort)image.Width;
            Height = (ushort)image.Height;
            Mipmap = image.MipMaps.Length;


            Pitch = Width * 4;
        }
Exemple #4
0
        private void Save <T>(Pfim.IImage dds, string path) where T : struct, IPixel <T>
        {
            using var i = Image.LoadPixelData <T>(dds.Data, dds.Width, dds.Height);

            /*
             * if (this.Flags == 0)
             * {
             *  i.Mutate(p =>
             *  {
             *      p.Flip(FlipMode.Vertical);
             *  });
             * }
             */
            i.Save(path);
        }
Exemple #5
0
 public DDSImage(string file)
 {
     _ddsImageFile = Pfim.Pfim.FromFile(file, new PfimConfig(decompress: true));
 }
 internal void CopyDataFromTexture(PapaTexture texture)
 {
     this.Image = texture.Image;
 }
 internal PapaTexture(ICollection <string> strings, PapaEncodingTexture texture)
 {
     this.Name  = strings.ElementAtOrDefault(texture.NameIndex);
     this.Image = texture.Image;
 }