예제 #1
0
        public override async Task ReadDomainObject(ByteArrayReader reader, DomainHeader header, DomainExportTableEntry export, bool skipProperties, bool skipParse)
        {
            await base.ReadDomainObject(reader, header, export, skipProperties, skipParse);

            if (skipParse)
            {
                return;
            }

            MipMapsCount = reader.ReadInt32();

            for (int i = 0; i < MipMapsCount; ++i)
            {
                await ProcessCompressedBulkData(reader, async bulkChunk => {
                    DomainMipMap mip = new DomainMipMap
                    {
                        Width  = reader.ReadInt32(),
                        Height = reader.ReadInt32()
                    };

                    if (mip.Width >= 4 || mip.Height >= 4)
                    {
                        mip.ImageData = (await bulkChunk.DecompressChunk(0))?.GetBytes();
                    }

                    MipMaps.Add(mip);
                });
            }

            Guid = await reader.ReadBytes(16);
        }
예제 #2
0
        public override async Task SaveObject(string filename)
        {
            if (MipMaps == null || !MipMaps.Any())
            {
                return;
            }

            ImageEngineFormat format;

            DomainMipMap mipMap = MipMaps.Where(mm => mm.ImageData != null && mm.ImageData.Length > 0).OrderByDescending(mm => mm.Width > mm.Height ? mm.Width : mm.Height).FirstOrDefault();

            if (mipMap == null)
            {
                return;
            }

            MemoryStream memory = buildDdsImage(MipMaps.IndexOf(mipMap), out format);

            if (memory == null)
            {
                return;
            }

            ImageEngineImage ddsImage = new ImageEngineImage(memory);

            FileStream stream = new FileStream(filename, FileMode.Create);

            await Task.Run(() => ddsImage.Save(stream, format, MipHandling.KeepTopOnly));

            stream.Close();

            memory.Close();
        }
        private Stream buildDdsImage(int mipMapIndex, out FileFormat imageFormat)
        {
            DomainPropertyByteValue formatProp = PropertyHeader.GetProperty("Format").FirstOrDefault()?.Value as DomainPropertyByteValue;

            imageFormat = FileFormat.Unknown;

            if (formatProp == null)
            {
                return(null);
            }

            string format = formatProp.PropertyString;

            DomainMipMap mipMap = MipMaps[mipMapIndex];

            imageFormat = DdsPixelFormat.ParseFileFormat(format);

            DdsHeader ddsHeader = new DdsHeader(new DdsSaveConfig(imageFormat, 0, 0, false, false), mipMap.Width, mipMap.Height);

            MemoryStream stream = new MemoryStream();

            BinaryWriter writer = new BinaryWriter(stream);

            ddsHeader.Write(writer);

            stream.Write(mipMap.ImageData, 0, mipMap.ImageData.Length);

            stream.Flush();

            stream.Position = 0;

            return(stream);
        }
예제 #4
0
        public override Stream GetObjectStream()
        {
            if (MipMaps == null || !MipMaps.Any())
            {
                return(null);
            }

            ImageEngineFormat format;

            DomainMipMap mipMap = MipMaps.Where(mm => mm.ImageData != null && mm.ImageData.Length > 0).OrderByDescending(mm => mm.Width > mm.Height ? mm.Width : mm.Height).FirstOrDefault();

            return(mipMap == null ? null : buildDdsImage(MipMaps.IndexOf(mipMap), out format));
        }
예제 #5
0
    public override async Task ReadDomainObject(ByteArrayReader reader, DomainHeader header, DomainExportTableEntry export, bool skipProperties, bool skipParse) {
      await base.ReadDomainObject(reader, header, export, skipProperties, skipParse);

      if (skipParse) return;

      MipMapsCount = reader.ReadInt32();

      for(int i = 0; i < MipMapsCount; ++i) {
        await ProcessCompressedBulkData(reader, async bulkChunk => {
          DomainMipMap mip = new DomainMipMap {
            Width  = reader.ReadInt32(),
            Height = reader.ReadInt32()
          };

          if (mip.Width >= 4 || mip.Height >= 4) mip.ImageData = (await bulkChunk.DecompressChunk(0))?.GetBytes();

          MipMaps.Add(mip);
        });
      }

      Guid = await reader.ReadBytes(16);
    }
        public override async Task SaveObject(string filename, object configuration)
        {
            if (MipMaps == null || !MipMaps.Any())
            {
                return;
            }

            DdsSaveConfig config = configuration as DdsSaveConfig ?? new DdsSaveConfig(FileFormat.Unknown, 0, 0, false, false);

            FileFormat format;

            DomainMipMap mipMap = MipMaps.Where(mm => mm.ImageData != null && mm.ImageData.Length > 0).OrderByDescending(mm => mm.Width > mm.Height ? mm.Width : mm.Height).FirstOrDefault();

            if (mipMap == null)
            {
                return;
            }

            Stream memory = buildDdsImage(MipMaps.IndexOf(mipMap), out format);

            if (memory == null)
            {
                return;
            }

            DdsFile ddsImage = new DdsFile(memory);

            FileStream ddsStream = new FileStream(filename, FileMode.Create);

            config.FileFormat = format;

            await Task.Run(() => ddsImage.Save(ddsStream, config));

            ddsStream.Close();

            memory.Close();
        }
예제 #7
0
        private MemoryStream buildDdsImage(int mipMapIndex, out ImageEngineFormat imageFormat)
        {
            DomainPropertyByteValue formatProp = PropertyHeader.GetProperty("Format").FirstOrDefault()?.Value as DomainPropertyByteValue;

            imageFormat = ImageEngineFormat.Unknown;

            if (formatProp == null)
            {
                return(null);
            }

            string format = formatProp.PropertyString.Replace("PF_", null);

            switch (format)
            {
            case "DXT1":
            {
                imageFormat = ImageEngineFormat.DDS_DXT1;

                break;
            }

            case "DXT5":
            {
                imageFormat = ImageEngineFormat.DDS_DXT5;

                break;
            }

            case "G8":
            {
                imageFormat = ImageEngineFormat.DDS_G8_L8;

                break;
            }

            case "A8R8G8B8":
            {
                imageFormat = ImageEngineFormat.DDS_ARGB;

                break;
            }

            default:
            {
                return(null);
            }
            }

            DomainMipMap mipMap = MipMaps[mipMapIndex];

            DDSGeneral.DDS_HEADER header = DDSGeneral.Build_DDS_Header(0, mipMap.Height, mipMap.Width, imageFormat);

            MemoryStream stream = new MemoryStream();

            BinaryWriter writer = new BinaryWriter(stream);

            DDSGeneral.Write_DDS_Header(header, writer);

            stream.Write(mipMap.ImageData, 0, mipMap.ImageData.Length);

            stream.Flush();

            stream.Position = 0;

            return(stream);
        }