Exemple #1
0
 public ImageFormatDecoder(IBinaryStream file, ImageFormat format, ImageMetaData info)
 {
     m_file       = file;
     SourceFormat = format;
     Info         = info;
 }
Exemple #2
0
 protected BinaryImageDecoder(IBinaryStream input, ImageMetaData info)
 {
     m_input = input;
     Info    = info;
 }
Exemple #3
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.ReadUInt32();
            if (file.ReadUInt32() != 0x0a1a0a0d)
            {
                return(null);
            }
            uint chunk_size = Binary.BigEndian(file.ReadUInt32());

            byte[] chunk_type = file.ReadBytes(4);
            if (!Binary.AsciiEqual(chunk_type, "IHDR"))
            {
                return(null);
            }

            var meta = new ImageMetaData();

            meta.Width  = Binary.BigEndian(file.ReadUInt32());
            meta.Height = Binary.BigEndian(file.ReadUInt32());
            int bpp = file.ReadByte();

            if (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8 && bpp != 16)
            {
                return(null);
            }
            int color_type = file.ReadByte();

            switch (color_type)
            {
            case 2: meta.BPP = bpp * 3; break;

            case 3: meta.BPP = 24; break;

            case 4: meta.BPP = bpp * 2; break;

            case 6: meta.BPP = bpp * 4; break;

            case 0: meta.BPP = bpp; break;

            default: return(null);
            }
            SkipBytes(file, 7);

            for (;;)
            {
                chunk_size = Binary.BigEndian(file.ReadUInt32());
                file.Read(chunk_type, 0, 4);
                if (Binary.AsciiEqual(chunk_type, "IDAT") || Binary.AsciiEqual(chunk_type, "IEND"))
                {
                    break;
                }
                if (Binary.AsciiEqual(chunk_type, "oFFs"))
                {
                    int x = Binary.BigEndian(file.ReadInt32());
                    int y = Binary.BigEndian(file.ReadInt32());
                    if (0 == file.ReadByte())
                    {
                        meta.OffsetX = x;
                        meta.OffsetY = y;
                    }
                    break;
                }
                SkipBytes(file, chunk_size + 4);
            }
            return(meta);
        }
Exemple #4
0
 public abstract ImageData Read(IBinaryStream file, ImageMetaData info);
Exemple #5
0
 public static ImageData Create(ImageMetaData info, PixelFormat format, BitmapPalette palette,
                                Array pixel_data)
 {
     return(Create(info, format, palette, pixel_data, (int)info.Width * ((format.BitsPerPixel + 7) / 8)));
 }
Exemple #6
0
 public ImageData(BitmapSource data, ImageMetaData meta)
 {
     m_bitmap = data;
     OffsetX  = meta.OffsetX;
     OffsetY  = meta.OffsetY;
 }
Exemple #7
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            ImageMetaData meta = null;
            var           file = new ArcView.Reader(stream);

            try
            {
                file.ReadUInt32();
                if (file.ReadUInt32() != 0x0a1a0a0d)
                {
                    return(null);
                }
                uint   chunk_size = Binary.BigEndian(file.ReadUInt32());
                char[] chunk_type = new char[4];
                file.Read(chunk_type, 0, 4);
                if (!chunk_type.SequenceEqual("IHDR"))
                {
                    return(null);
                }

                meta        = new ImageMetaData();
                meta.Width  = Binary.BigEndian(file.ReadUInt32());
                meta.Height = Binary.BigEndian(file.ReadUInt32());
                int bpp        = file.ReadByte();
                int color_type = file.ReadByte();
                switch (color_type)
                {
                case 2: meta.BPP = bpp * 3; break;

                case 3: meta.BPP = 24; break;

                case 4: meta.BPP = bpp * 2; break;

                case 6: meta.BPP = bpp * 4; break;

                default: meta.BPP = bpp; break;
                }
                SkipBytes(file, 7);

                for (;;)
                {
                    chunk_size = Binary.BigEndian(file.ReadUInt32());
                    file.Read(chunk_type, 0, 4);
                    if (chunk_type.SequenceEqual("IDAT") || chunk_type.SequenceEqual("IEND"))
                    {
                        break;
                    }
                    if (chunk_type.SequenceEqual("oFFs"))
                    {
                        int x = Binary.BigEndian(file.ReadInt32());
                        int y = Binary.BigEndian(file.ReadInt32());
                        if (0 == file.ReadByte())
                        {
                            meta.OffsetX = x;
                            meta.OffsetY = y;
                        }
                        break;
                    }
                    SkipBytes(file, chunk_size + 4);
                }
            }
            catch
            {
                meta = null;
            }
            finally
            {
                file.Dispose();
                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }
            }
            return(meta);
        }