示例#1
0
        /// <summary>
        /// Constructor which takes an existing MNGChunk object and
        /// verifies that its type matches that which is expected
        /// </summary>
        /// <param name="chunk">The MNGChunk to copy</param>
        /// <param name="expectedType">The input MNGChunk expected type</param>
        public MNGChunk(MNGChunk chunk, String expectedType)
        {
            // Copy the existing chunks members
            chunkLength = chunk.chunkLength;
            chunkType   = chunk.chunkType;
            chunkData   = chunk.chunkData;
            chunkCRC    = chunk.chunkCRC;

            // Verify the chunk type is as expected
            if (ChunkType != expectedType)
            {
                throw new ArgumentException(
                          String.Format("Specified chunk type is not {0} as expected", expectedType));
            }

            // Parse the chunk's data
            ParseData(chunkData);
        }
示例#2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public MENDChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public IDATChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#4
0
        private uint yLocation; //4 bytes

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
        public DEFIChunk(MNGChunk chunk)
            : base(chunk, NAME)
        {
        }
示例#5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public BKGDChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public BACKChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public BKGDChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#8
0
        /// <summary>
        /// Attempts to load an MNG from the specified file name
        /// </summary>
        /// <param name="filename">Name of the MNG file to load</param>
        public bool Load(string filename)
        {
            chunks = new List<MNGChunk>();
            pngs = new List<PNG>();
            offsets = new List<Point>();

            // Open the file for reading
            Stream stream = File.OpenRead(filename);

            // Create a new header (should be 1 per file) and
            // read it from the stream
            MNGHeader header = new MNGHeader();
            try
            {
                header.Read(stream);
            }
            catch (Exception)
            {
                stream.Close();
                return false;
                //throw;
            }

            MNGChunk chunk;
            PNG png = null;
            PLTEChunk globalPLTE = null;

            // Read chunks from the stream until we reach the MEND chunk
            do
            {
                // Read a generic Chunk
                chunk = new MNGChunk();
                try
                {
                    chunk.Read(stream);
                }
                catch (Exception)
                {
                    stream.Close();
                    return false;
                    //throw;
                }

                // Take a look at the chunk type and decide what derived class to
                // use to create a specific chunk
                switch (chunk.ChunkType)
                {
                    case MHDRChunk.NAME:
                        if (headerChunk != null)
                            throw new ApplicationException(String.Format(
                                "Only one chunk of type {0} is allowed", chunk.ChunkType));
                        chunk = headerChunk = new MHDRChunk(chunk);

                        break;
                    case MENDChunk.NAME:
                        chunk = new MENDChunk(chunk);
                        break;
                    case TERMChunk.NAME:
                        chunk = new TERMChunk(chunk);
                        break;
                    case BACKChunk.NAME:
                        chunk = new BACKChunk(chunk);
                        break;
                    case BKGDChunk.NAME:
                        chunk = new BKGDChunk(chunk);
                        break;
                    case PLTEChunk.NAME:
                        chunk = new PLTEChunk(chunk);
                        // We can get an PLTE chunk w/o having gotten
                        // an IHDR
                        if (png != null)
                        {
                            png.PLTE = chunk as PLTEChunk;
                            if (png.PLTE.IsEmpty())
                            {
                                if (globalPLTE == null)
                                    throw new ApplicationException(String.Format(
                                        "An empty PLTE chunk was found inside a IHDR/IEND pair but no 'global' PLTE chunk was found"));
                                png.PLTE = globalPLTE;
                            }
                        }
                        else
                            globalPLTE = chunk as PLTEChunk;
                        break;
                    case DEFIChunk.NAME:
                        DEFIChunk dchunk = new DEFIChunk(chunk);
                        Point p = new Point();
                        p.X = (int)dchunk.XLocation;
                        p.Y = (int)dchunk.YLocation;
                        offsets.Add(p);
                        break;
                    case IHDRChunk.NAME:
                        chunk = new IHDRChunk(chunk);
                        // This is the beginning of a new embedded PNG
                        png = new PNG();
                        png.IHDR = chunk as IHDRChunk;
                        break;
                    case IDATChunk.NAME:
                        chunk = new IDATChunk(chunk);
                        // We shouldn't get an IDAT chunk if we haven't yet
                        // gotten an IHDR chunk
                        if (png == null)
                            throw new ArgumentNullException("png");
                        png.IDAT = chunk as IDATChunk;
                        break;
                    case IENDChunk.NAME:
                        chunk = new IENDChunk(chunk);
                        // We can get an IEND chunk w/o having gotten
                        // an IHDR
                        if (png != null)
                        {
                            // However, if we've gotten an IHDR chunk then
                            // this is the end of the embedded PNG
                            png.IEND = chunk as IENDChunk;
                            pngs.Add(png);
                            png = null;
                        }
                        break;
                    default:
                        break;
                }
                // Add the chunk to our list of chunks
                chunks.Add(chunk);
            }
            while (chunk.ChunkType != MENDChunk.NAME);
            return true;
        }
示例#9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public MHDRChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public IENDChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public IDATChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public PLTEChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#13
0
        private uint bottomClip; //4 bytes

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
        public DEFIChunk(MNGChunk chunk)
            : base(chunk, NAME)
        {
        }
示例#14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public BACKChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public MHDRChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#16
0
        /// <summary>
        /// Attempts to load an MNG from the specified file name
        /// </summary>
        /// <param name="filename">Name of the MNG file to load</param>
        public bool Load(string filename)
        {
            chunks  = new List <MNGChunk>();
            pngs    = new List <PNG>();
            offsets = new List <Point>();

            // Open the file for reading
            Stream stream = File.OpenRead(filename);

            // Create a new header (should be 1 per file) and
            // read it from the stream
            MNGHeader header = new MNGHeader();

            try
            {
                header.Read(stream);
            }
            catch (Exception)
            {
                stream.Close();
                return(false);
                //throw;
            }

            MNGChunk  chunk;
            PNG       png        = null;
            PLTEChunk globalPLTE = null;

            // Read chunks from the stream until we reach the MEND chunk
            do
            {
                // Read a generic Chunk
                chunk = new MNGChunk();
                try
                {
                    chunk.Read(stream);
                }
                catch (Exception)
                {
                    stream.Close();
                    return(false);
                    //throw;
                }

                // Take a look at the chunk type and decide what derived class to
                // use to create a specific chunk
                switch (chunk.ChunkType)
                {
                case MHDRChunk.NAME:
                    if (headerChunk != null)
                    {
                        throw new ApplicationException(String.Format(
                                                           "Only one chunk of type {0} is allowed", chunk.ChunkType));
                    }
                    chunk = headerChunk = new MHDRChunk(chunk);

                    break;

                case MENDChunk.NAME:
                    chunk = new MENDChunk(chunk);
                    break;

                case TERMChunk.NAME:
                    chunk = new TERMChunk(chunk);
                    break;

                case BACKChunk.NAME:
                    chunk = new BACKChunk(chunk);
                    break;

                case BKGDChunk.NAME:
                    chunk = new BKGDChunk(chunk);
                    break;

                case PLTEChunk.NAME:
                    chunk = new PLTEChunk(chunk);
                    // We can get an PLTE chunk w/o having gotten
                    // an IHDR
                    if (png != null)
                    {
                        png.PLTE = chunk as PLTEChunk;
                        if (png.PLTE.IsEmpty())
                        {
                            if (globalPLTE == null)
                            {
                                throw new ApplicationException(String.Format(
                                                                   "An empty PLTE chunk was found inside a IHDR/IEND pair but no 'global' PLTE chunk was found"));
                            }
                            png.PLTE = globalPLTE;
                        }
                    }
                    else
                    {
                        globalPLTE = chunk as PLTEChunk;
                    }
                    break;

                case DEFIChunk.NAME:
                    DEFIChunk dchunk = new DEFIChunk(chunk);
                    Point     p      = new Point();
                    p.X = (int)dchunk.XLocation;
                    p.Y = (int)dchunk.YLocation;
                    offsets.Add(p);
                    break;

                case IHDRChunk.NAME:
                    chunk = new IHDRChunk(chunk);
                    // This is the beginning of a new embedded PNG
                    png      = new PNG();
                    png.IHDR = chunk as IHDRChunk;
                    break;

                case IDATChunk.NAME:
                    chunk = new IDATChunk(chunk);
                    // We shouldn't get an IDAT chunk if we haven't yet
                    // gotten an IHDR chunk
                    if (png == null)
                    {
                        throw new ArgumentNullException("png");
                    }
                    png.IDAT = chunk as IDATChunk;
                    break;

                case IENDChunk.NAME:
                    chunk = new IENDChunk(chunk);
                    // We can get an IEND chunk w/o having gotten
                    // an IHDR
                    if (png != null)
                    {
                        // However, if we've gotten an IHDR chunk then
                        // this is the end of the embedded PNG
                        png.IEND = chunk as IENDChunk;
                        pngs.Add(png);
                        png = null;
                    }
                    break;

                default:
                    break;
                }
                // Add the chunk to our list of chunks
                chunks.Add(chunk);
            }while (chunk.ChunkType != MENDChunk.NAME);
            return(true);
        }
示例#17
0
        /// <summary>
        /// Constructor which takes an existing MNGChunk object and
        /// verifies that its type matches that which is expected
        /// </summary>
        /// <param name="chunk">The MNGChunk to copy</param>
        /// <param name="expectedType">The input MNGChunk expected type</param>
        public MNGChunk(MNGChunk chunk, String expectedType)
        {
            // Copy the existing chunks members
            chunkLength = chunk.chunkLength;
            chunkType = chunk.chunkType;
            chunkData = chunk.chunkData;
            chunkCRC = chunk.chunkCRC;

            // Verify the chunk type is as expected
            if (ChunkType != expectedType)
                throw new ArgumentException(
                    String.Format("Specified chunk type is not {0} as expected", expectedType));

            // Parse the chunk's data
            ParseData(chunkData);
        }
示例#18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public TERMChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public PLTEChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }
示例#20
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chunk">The MNG chunk containing the data for this specific chunk</param>
 public TERMChunk(MNGChunk chunk)
     : base(chunk, NAME)
 {
 }