Beispiel #1
0
        public BXLIM(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                var tex = br.ReadBytes((int)br.BaseStream.Length - 40);
                sections  = br.ReadSections();
                byteOrder = br.ByteOrder;
                switch (sections.Header.magic)
                {
                case "CLIM":
                    BCLIMHeader = sections[0].Data.BytesToStruct <BCLIMImageHeader>(byteOrder);
                    Settings    = new ImageSettings
                    {
                        Width       = BCLIMHeader.width,
                        Height      = BCLIMHeader.height,
                        Format      = ImageSettings.ConvertFormat(BCLIMHeader.format),
                        Orientation = ImageSettings.ConvertOrientation(BCLIMHeader.orientation)
                    };
                    Image = Common.Load(tex, Settings);
                    break;

                case "FLIM":
                    if (byteOrder == ByteOrder.LittleEndian)
                    {
                        BFLIMHeaderLE = sections[0].Data.BytesToStruct <BFLIMImageHeaderLE>(byteOrder);
                        Settings      = new ImageSettings
                        {
                            Width       = BFLIMHeaderLE.width,
                            Height      = BFLIMHeaderLE.height,
                            Format      = ImageSettings.ConvertFormat(BFLIMHeaderLE.format),
                            Orientation = ImageSettings.ConvertOrientation(BFLIMHeaderLE.orientation),
                        };
                        Image = Common.Load(tex, Settings);
                    }
                    else
                    {
                        BFLIMHeaderBE = sections[0].Data.BytesToStruct <BFLIMImageHeaderBE>(byteOrder);
                        var padWidth  = 2 << (int)Math.Log(BFLIMHeaderBE.width - 1, 2);
                        var padHeight = 2 << (int)Math.Log(BFLIMHeaderBE.height - 1, 2);
                        Settings = new ImageSettings
                        {
                            Width         = padWidth,
                            Height        = padHeight,
                            Format        = ImageSettings.ConvertFormat(BFLIMHeaderBE.format),
                            Orientation   = Cetera.Image.Orientation.Default,
                            PadToPowerOf2 = true,
                            ZOrder        = (br.ByteOrder == ByteOrder.LittleEndian) ? true : false
                        };
                        Image = SwizzleTiles(Common.Load(tex, Settings), padWidth, padHeight, BFLIMHeaderBE.width, BFLIMHeaderBE.height, 8, BFLIMHeaderBE.tileMode);
                    }
                    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 = ImageSettings.ConvertOrientation(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!
                    BCLIMHeader.width         = (short)Image.Width;
                    BCLIMHeader.height        = (short)Image.Height;
                    BCLIMHeader.datasize      = texture.Length;
                    sections[0].Data          = BCLIMHeader.StructToBytes();
                    sections.Header.file_size = texture.Length + 40;
                    bw.WriteSections(sections);
                    break;

                case "FLIM":
                    if (byteOrder == ByteOrder.LittleEndian)
                    {
                        settings.Width       = BFLIMHeaderLE.width;
                        settings.Height      = BFLIMHeaderLE.height;
                        settings.Orientation = ImageSettings.ConvertOrientation(BFLIMHeaderLE.orientation);
                        settings.Format      = ImageSettings.ConvertFormat(BFLIMHeaderLE.format);
                        texture = Common.Save(Image, settings);
                        bw.Write(texture);

                        // We can now change the image width/height/filesize!
                        BFLIMHeaderLE.width       = (short)Image.Width;
                        BFLIMHeaderLE.height      = (short)Image.Height;
                        BFLIMHeaderLE.datasize    = texture.Length;
                        sections[0].Data          = BFLIMHeaderLE.StructToBytes();
                        sections.Header.file_size = texture.Length + 40;
                        bw.WriteSections(sections);
                    }
                    else
                    {
                        throw new NotSupportedException($"Big Endian FLIM isn't savable yet!");
                    }
                    break;

                default:
                    throw new NotSupportedException($"Unknown image format {sections.Header.magic}");
                }
            }
        }
Beispiel #3
0
        public BXLIM(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                var tex = br.ReadBytes((int)br.BaseStream.Length - 40);
                sections = br.ReadSections();
                switch (sections.Header.magic)
                {
                case "CLIM":
                    BCLIMHeader = sections[0].Data.BytesToStruct <BCLIMImageHeader>(br.ByteOrder);
                    Settings    = new ImageSettings
                    {
                        Width       = BCLIMHeader.width,
                        Height      = BCLIMHeader.height,
                        Format      = ImageSettings.ConvertFormat(BCLIMHeader.format),
                        Orientation = ImageSettings.ConvertOrientation(BCLIMHeader.orientation)
                    };
                    break;

                case "FLIM":
                    BFLIMHeader = sections[0].Data.BytesToStruct <BFLIMImageHeader>(br.ByteOrder);
                    Settings    = new ImageSettings
                    {
                        Width       = BFLIMHeader.width,
                        Height      = BFLIMHeader.height,
                        Format      = ImageSettings.ConvertFormat(BFLIMHeader.format),
                        Orientation = ImageSettings.ConvertOrientation(BFLIMHeader.orientation)
                    };
                    break;

                default:
                    throw new NotSupportedException($"Unknown image format {sections.Header.magic}");
                }
                Image = Common.Load(tex, Settings);
            }
        }