Exemplo n.º 1
0
    void WriteChunk(ISerializer s, string chunkType, Action <ISerializer, int> serdes)
    {
        var chunk = IFFChunk.Serdes(0, new IFFChunk(chunkType, 0), s);

        serdes(s, chunk.Length);
        chunk.WriteLength(s);
    }
Exemplo n.º 2
0
 public static IFFChunk Serdes(int _, IFFChunk c, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     c ??= new IFFChunk();
     c.TypeId        = s.FixedLengthString(nameof(TypeId), c.TypeId, 4);
     c._lengthOffset = s.Offset;
     c.Length        = s.Int32BE(nameof(Length), c.Length);
     return(c);
 }
Exemplo n.º 3
0
 public ThumChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document)
     : base(reader, parent, document)
 {
 }
Exemplo n.º 4
0
 public FormChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document)
     : base(reader, parent, document)
 {
     // Nothing
 }
Exemplo n.º 5
0
 public AnnotationChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document)
     : base(reader, parent, document)
 {
 }
Exemplo n.º 6
0
 public TextChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document)
     : base(reader, parent, document)
 {
 }
Exemplo n.º 7
0
 public AnnotationChunk(DjvuReader reader, IFFChunk parent, DjvuDocument document)
     : base(reader, parent, document)
 {
 }
Exemplo n.º 8
0
    public static InterlacedBitmap Serdes(InterlacedBitmap img, ISerializer s)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        img ??= new InterlacedBitmap();

        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.IsReading())
        {
            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.Bytes("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);
        return(img);
    }