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 = 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 = BFLIMHeader.orientation }; break; default: throw new NotSupportedException($"Unknown image format {sections.Header.magic}"); } Image = Common.Load(tex, Settings); } }
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}"); } } }
public static void WriteSections(this BinaryWriterX bw, NW4CSectionList sections) { bw.WriteStruct(sections.Header); foreach (var sec in sections) { bw.Write(Encoding.ASCII.GetBytes(sec.Magic)); // will need a magic->byte[] converter eventually bw.Write(sec.Data.Length + 8); bw.Write(sec.Data); } }
public static NW4CSectionList ReadSections(this BinaryReaderX br) { var lst = new NW4CSectionList { Header = br.ReadStruct <NW4CHeader>() }; lst.AddRange(from _ in Enumerable.Range(0, lst.Header.section_count) let magic1 = br.ReadStruct <String4>() let data = br.ReadBytes(br.ReadInt32() - 8) select new NW4CSection(magic1, data)); return(lst); }
public static NW4CSectionList readSections(BinaryReaderX br) { NW4CSectionList lst = new NW4CSectionList { Header = new NW4CHeader(br) }; lst.AddRange(from _ in Enumerable.Range(0, lst.Header.section_count) let magic1 = br.ReadString(4) let data = br.ReadBytes(br.ReadInt32() - 8) select new NW4CSection(magic1, data)); return(lst); }
public static NW4CSectionList ReadSections(this BinaryReaderX br) { br.BaseStream.Position += 4; br.ByteOrder = (ByteOrder)br.ReadUInt16(); br.BaseStream.Position -= 6; var lst = new NW4CSectionList { Header = br.ReadStruct <NW4CHeader>() }; lst.AddRange(from _ in Enumerable.Range(0, lst.Header.section_count) let magic1 = br.ReadStruct <String4>() let data = br.ReadBytes(br.ReadInt32()) select new NW4CSection(magic1, data)); return(lst); }
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 Kontract.Image.ImageSettings { Width = BCLIMHeader.width, Height = BCLIMHeader.height, Format = DSFormat[BCLIMHeader.format], Swizzle = new CTRSwizzle(BCLIMHeader.width, BCLIMHeader.height, BCLIMHeader.swizzleTileMode) }; Image = Kontract.Image.Common.Load(tex, Settings); break; case "FLIM": if (byteOrder == ByteOrder.LittleEndian) { BFLIMHeader = sections[0].Data.BytesToStruct <BFLIMImageHeader>(byteOrder); Settings = new Kontract.Image.ImageSettings { Width = BFLIMHeader.width, Height = BFLIMHeader.height, Format = DSFormat[BFLIMHeader.format], Swizzle = new CTRSwizzle(BFLIMHeader.width, BFLIMHeader.height, BFLIMHeader.swizzleTileMode) }; Image = Kontract.Image.Common.Load(tex, Settings); } else { BFLIMHeader = sections[0].Data.BytesToStruct <BFLIMImageHeader>(byteOrder); var format = WiiUFormat[BFLIMHeader.format]; var isBlockBased = new[] { 10, 11, 12, 13, 14, 15, 16, 17, 21, 22, 23 }.Contains(BFLIMHeader.format); // hax Settings = new Kontract.Image.ImageSettings { Width = BFLIMHeader.width, Height = BFLIMHeader.height, Format = format, Swizzle = new WiiUSwizzle(BFLIMHeader.swizzleTileMode, isBlockBased, format.BitDepth, BFLIMHeader.width, BFLIMHeader.height) }; // Uncomment the following line to use the padded width/height instead //(Settings.Width, Settings.Height) = (Settings.Swizzle.Width, Settings.Swizzle.Height); Image = Kontract.Image.Common.Load(tex, Settings); } break; default: throw new NotSupportedException($"Unknown image format {sections.Header.magic}"); } } }