Beispiel #1
0
        public void Save(Stream output)
        {
            using (var bw = new BinaryWriterX(output, byteOrder))
            {
                byte[] texture;

                switch (sections.Header.magic)
                {
                case "CLIM":
                    Settings.Width   = Image.Width;
                    Settings.Height  = Image.Height;
                    Settings.Swizzle = new CTRSwizzle(Image.Width, Image.Height, BCLIMHeader.swizzleTileMode);

                    texture = Kontract.Image.Common.Save(Image, Settings);
                    bw.Write(texture);

                    // We can now change the image width/height/filesize!
                    BCLIMHeader.width    = (short)Image.Width;
                    BCLIMHeader.height   = (short)Image.Height;
                    BCLIMHeader.datasize = texture.Length;

                    sections[0].Data          = BCLIMHeader.StructToBytes(byteOrder);
                    sections.Header.file_size = texture.Length + 40;

                    bw.WriteSections(sections);
                    break;

                case "FLIM":
                    Settings.Width  = Image.Width;
                    Settings.Height = Image.Height;
                    if (byteOrder == ByteOrder.LittleEndian)
                    {
                        Settings.Swizzle = new CTRSwizzle(Image.Width, Image.Height, BFLIMHeader.swizzleTileMode);
                    }
                    else
                    {
                        var isBlockBased = new[] { 10, 11, 12, 13, 14, 15, 16, 17, 21, 22, 23 }.Contains(BFLIMHeader.format);     // hax
                        Settings.Swizzle = new WiiUSwizzle(BFLIMHeader.swizzleTileMode, isBlockBased, Settings.Format.BitDepth, Image.Width, Image.Height);
                    }

                    texture = Kontract.Image.Common.Save(Image, Settings);
                    bw.Write(texture);

                    // We can now change the image width/height/filesize!
                    BFLIMHeader.width    = (short)Image.Width;
                    BFLIMHeader.height   = (short)Image.Height;
                    BFLIMHeader.datasize = texture.Length;

                    sections[0].Data          = BFLIMHeader.StructToBytes(byteOrder);
                    sections.Header.file_size = texture.Length + 40;

                    bw.WriteSections(sections);
                    break;

                default:
                    throw new NotSupportedException($"Unknown image format {sections.Header.magic}");
                }
            }
        }
Beispiel #2
0
        public void Save(Stream output)
        {
            using (var bw = new BinaryWriterX(output))
            {
                var    settings = new ImageSettings();
                byte[] texture;

                switch (sections.Header.magic)
                {
                case "CLIM":
                    settings.Width       = BCLIMHeader.width;
                    settings.Height      = BCLIMHeader.height;
                    settings.Orientation = BCLIMHeader.orientation;
                    settings.Format      = ImageSettings.ConvertFormat(BCLIMHeader.format);
                    texture = Common.Save(Image, settings);
                    bw.Write(texture);

                    // We can now change the image width/height/filesize!
                    var modifiedBCLIMHeader = BCLIMHeader;
                    modifiedBCLIMHeader.width    = (short)Image.Width;
                    modifiedBCLIMHeader.height   = (short)Image.Height;
                    modifiedBCLIMHeader.datasize = texture.Length;
                    BCLIMHeader               = modifiedBCLIMHeader;
                    sections[0].Data          = BCLIMHeader.StructToBytes();
                    sections.Header.file_size = texture.Length + 40;
                    bw.WriteSections(sections);
                    break;

                case "FLIM":
                    settings.Width       = BFLIMHeader.width;
                    settings.Height      = BFLIMHeader.height;
                    settings.Orientation = BFLIMHeader.orientation;
                    settings.Format      = ImageSettings.ConvertFormat(BFLIMHeader.format);
                    texture = Common.Save(Image, settings);
                    bw.Write(texture);

                    // We can now change the image width/height/filesize!
                    var modifiedBFLIMHeader = BFLIMHeader;
                    modifiedBFLIMHeader.width    = (short)Image.Width;
                    modifiedBFLIMHeader.height   = (short)Image.Height;
                    modifiedBFLIMHeader.datasize = texture.Length;
                    BFLIMHeader               = modifiedBFLIMHeader;
                    sections[0].Data          = BFLIMHeader.StructToBytes();
                    sections.Header.file_size = texture.Length + 40;
                    bw.WriteSections(sections);
                    break;

                default:
                    throw new NotSupportedException($"Unknown image format {sections.Header.magic}");
                }
            }
        }