Пример #1
0
        public static PngFile ReadFile(ParsedPath pngFileName)
        {
            PngFile pngFile = new PngFile();

            ImageSurface image = new ImageSurface(pngFileName);

            if (image.Format != Format.ARGB32)
                throw new NotSupportedException("Only PNG's in ARGB32 format currently supported");

            pngFile.Width = image.Width;
            pngFile.Height = image.Height;
            pngFile.RgbaData = GetRgbaData(image);

            return pngFile;
        }
Пример #2
0
        public static PngFile ReadFile(ParsedPath pngFileName)
        {
            PngFile pngFile = new PngFile();

            ImageSurface image = new ImageSurface(pngFileName);

            if (image.Format != Format.ARGB32)
            {
                throw new NotSupportedException("Only PNG's in ARGB32 format currently supported");
            }

            pngFile.Width    = image.Width;
            pngFile.Height   = image.Height;
            pngFile.RgbaData = GetRgbaData(image);

            return(pngFile);
        }
Пример #3
0
        public static void ExportPngToDxt(ParsedPath pngFileName, ParsedPath dxtFileName)
        {
            PngFile      pngFile      = PngFileReader.ReadFile(pngFileName);
            SquishMethod?squishMethod = null;

            switch (dxtFileName.Extension)
            {
            case ".dxt1":
                squishMethod = SquishMethod.Dxt1;
                break;

            case ".dxt3":
                squishMethod = SquishMethod.Dxt3;
                break;

            case ".dxt5":
                squishMethod = SquishMethod.Dxt5;
                break;

            default:
                break;
            }

            byte[] rgbaData;

            if (squishMethod.HasValue)
            {
                rgbaData = Squish.CompressImage(
                    pngFile.RgbaData, pngFile.Width, pngFile.Height,
                    squishMethod.Value, SquishFit.IterativeCluster, SquishMetric.Default, SquishExtra.None);
            }
            else
            {
                rgbaData = null;
            }

            using (BinaryWriter writer = new BinaryWriter(new FileStream(dxtFileName, FileMode.Create)))
            {
                writer.Write(pngFile.Width);
                writer.Write(pngFile.Height);
                writer.Write(rgbaData);
            }
        }