/// <summary> /// Reads range from IFF stream. /// </summary> public static ColorRange Serdes(int _, ColorRange c, ISerializer s) { c ??= new ColorRange(); s.Begin(); c._pad1 = s.UInt16BE(nameof(_pad1), c._pad1); c.Rate = s.UInt16BE(nameof(Rate), c.Rate); c.Flags = s.EnumU16BE(nameof(Flags), c.Flags); c.Low = s.UInt8(nameof(Low), c.Low); c.High = s.UInt8(nameof(High), c.High); s.End(); return(c); }
/// <summary> /// Reads range from IFF stream. /// </summary> public static ColorRange Serdes(int _, ColorRange c, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } c ??= new ColorRange(); c._pad1 = s.UInt16BE(nameof(_pad1), c._pad1); c.Rate = s.UInt16BE(nameof(Rate), c.Rate); c.Flags = s.EnumU16BE(nameof(Flags), c.Flags); c.Low = s.UInt8(nameof(Low), c.Low); c.High = s.UInt8(nameof(High), c.High); return(c); }
public static InterlacedBitmap Serdes(InterlacedBitmap img, ISerializer s) { img ??= new InterlacedBitmap(); s.Begin(); var formatChunk = IFFChunk.Serdes(0, new IFFChunk(IFFChunkType.Format, 0), s); if (formatChunk.TypeId != IFFChunkType.Format) { throw new NotSupportedException($"Invalid IFF header, expected \"FORM\", found \"{formatChunk.TypeId}\""); } var formatId = s.FixedLengthString("FormatId", IFFChunkType.PackedBitmap, 4); if (formatId != IFFChunkType.PackedBitmap) { throw new NotSupportedException($"Invalid IFF header, expected \"PBM \", found \"{formatId}\""); } if (s.Mode == SerializerMode.Reading) { int i = 0; while (s.BytesRemaining > 0) { var chunk = IFFChunk.Serdes(i, null, s); switch (chunk.TypeId) { case IFFChunkType.BitmapHeader: img.SerdesHeader(s, chunk.Length); break; case IFFChunkType.ColorMapping: img.SerdesPalette(s, chunk.Length); break; case IFFChunkType.Hotspot: img.SerdesHotspot(s, chunk.Length); break; case IFFChunkType.ColorRanges: img.ColorRanges ??= new List <ColorRange>(); img.ColorRanges.Add(ColorRange.Serdes(img.ColorRanges.Count, null, s)); break; case IFFChunkType.Thumbnail: img.SerdesThumbnail(s, chunk.Length); break; case IFFChunkType.Body: img.SerdesPixels(s, chunk.Length); break; default: s.ByteArray("Unk", null, chunk.Length); break; } s.Check(); i++; } } else { img.WriteChunk(s, IFFChunkType.BitmapHeader, (x, n) => img.SerdesHeader(x, n)); img.WriteChunk(s, IFFChunkType.ColorMapping, (x, n) => img.SerdesPalette(x, n)); img.WriteChunk(s, IFFChunkType.Hotspot, (x, n) => img.SerdesHotspot(x, n)); s.List(nameof(img.ColorRanges), img.ColorRanges, img.ColorRanges.Count, ColorRange.Serdes); img.WriteChunk(s, IFFChunkType.Thumbnail, (x, n) => img.SerdesThumbnail(x, n)); img.WriteChunk(s, IFFChunkType.Body, (x, n) => img.SerdesPixels(x, n)); } formatChunk.WriteLength(s); s.End(); return(img); }