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);
        }
示例#2
0
        public FileFormat GetFormat()
        {
            GpkByteProperty formatProp = objectExport.GetProperty("Format") as GpkByteProperty;

            if (formatProp == null)
            {
                return(FileFormat.Unknown);
            }

            string format = formatProp.nameValue;

            return(DdsPixelFormat.ParseFileFormat(format));
        }
示例#3
0
        public void SaveFormat(GpkExport export)
        {
            GpkByteProperty formatProp = export.GetProperty("Format") as GpkByteProperty;

            if (formatProp == null)
            {
                parsedImageFormat = FileFormat.Unknown;
            }
            else
            {
                string format = formatProp.nameValue;
                parsedImageFormat = DdsPixelFormat.ParseFileFormat(format);
            }
        }
        public override async Task SetObject(string filename, List <DomainNameTableEntry> nameTable, object configuration)
        {
            DdsSaveConfig config = configuration as DdsSaveConfig ?? new DdsSaveConfig(FileFormat.Unknown, 0, 0, false, false);

            DdsFile image = await Task.Run(() => new DdsFile(filename));

            bool skipFirstMip = false;

            int width  = image.Width;
            int height = image.Height;

            if (MipMaps[0].ImageData == null || MipMaps[0].ImageData.Length == 0)
            {
                width  *= 2;
                height *= 2;

                skipFirstMip = true;
            }

            DomainPropertyIntValue sizeX = PropertyHeader.GetProperty("SizeX").FirstOrDefault()?.Value as DomainPropertyIntValue;
            DomainPropertyIntValue sizeY = PropertyHeader.GetProperty("SizeY").FirstOrDefault()?.Value as DomainPropertyIntValue;

            sizeX?.SetPropertyValue(skipFirstMip ? width * 2 : width);
            sizeY?.SetPropertyValue(skipFirstMip ? height * 2 : height);

            DomainPropertyIntValue mipTailBaseIdx = PropertyHeader.GetProperty("MipTailBaseIdx").FirstOrDefault()?.Value as DomainPropertyIntValue;

            int indexSize = width > height ? width : height;

            mipTailBaseIdx?.SetPropertyValue((int)Math.Log(skipFirstMip ? indexSize * 2 : indexSize, 2));

            DomainPropertyStringValue filePath = PropertyHeader.GetProperty("SourceFilePath").FirstOrDefault()?.Value as DomainPropertyStringValue;
            DomainPropertyStringValue fileTime = PropertyHeader.GetProperty("SourceFileTimestamp").FirstOrDefault()?.Value as DomainPropertyStringValue;

            filePath?.SetPropertyValue(filename);
            fileTime?.SetPropertyValue(File.GetLastWriteTime(filename).ToString("yyyy-MM-dd hh:mm:ss"));

            DomainPropertyByteValue pfFormat = PropertyHeader.GetProperty("Format").FirstOrDefault()?.Value as DomainPropertyByteValue;

            FileFormat imageFormat = FileFormat.Unknown;

            if (pfFormat != null)
            {
                imageFormat = DdsPixelFormat.ParseFileFormat(pfFormat.PropertyString);
            }

            if (imageFormat == FileFormat.Unknown)
            {
                throw new Exception($"Unknown DDS File Format ({pfFormat?.PropertyString ?? "Unknown"}).");
            }

            config.FileFormat = imageFormat;

            MipMaps.Clear();

            if (skipFirstMip)
            {
                MipMaps.Add(new DomainMipMap {
                    ImageData = null,
                    Width     = width,
                    Height    = height
                });
            }

            image.GenerateMipMaps(4, 4);

            foreach (DdsMipMap mipMap in image.MipMaps.OrderByDescending(mip => mip.Width))
            {
                MipMaps.Add(new DomainMipMap {
                    ImageData = image.WriteMipMap(mipMap, config),
                    Width     = mipMap.Width,
                    Height    = mipMap.Height
                });
            }
        }