Big-endian binary reader
Esempio n. 1
0
        public bool TryParseJFIF(byte[] data)
        {
            FluxJpeg.Core.IO.BinaryReader binaryReader = new FluxJpeg.Core.IO.BinaryReader(new MemoryStream(data));
            int num = data.Length + 2;

            if (num < JFIF_FIXED_LENGTH)
            {
                return(false);
            }
            byte[] array = new byte[5];
            binaryReader.Read(array, 0, array.Length);
            if (array[0] != 74 || array[1] != 70 || array[2] != 73 || array[3] != 70 || array[4] != 0)
            {
                return(false);
            }
            majorVersion = binaryReader.ReadByte();
            minorVersion = binaryReader.ReadByte();
            if (majorVersion != 1 || (majorVersion == 1 && minorVersion > 2))
            {
                return(false);
            }
            Units = (UnitType)binaryReader.ReadByte();
            if (Units != 0 && Units != UnitType.Inches && Units != UnitType.Centimeters)
            {
                return(false);
            }
            XDensity   = binaryReader.ReadShort();
            YDensity   = binaryReader.ReadShort();
            Xthumbnail = binaryReader.ReadByte();
            Ythumbnail = binaryReader.ReadByte();
            int num2 = 3 * Xthumbnail * Ythumbnail;

            if (num > JFIF_FIXED_LENGTH && num2 != num - JFIF_FIXED_LENGTH)
            {
                return(false);
            }
            if (num2 > 0)
            {
                thumbnail = new byte[num2];
                if (binaryReader.Read(thumbnail, 0, num2) != num2)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private bool TryParseJFIF(byte[] data)
        {
            FluxJpeg.Core.IO.BinaryReader reader = new FluxJpeg.Core.IO.BinaryReader(new MemoryStream(data));
            int num = data.Length + 2;

            if (num < JFIF_FIXED_LENGTH)
            {
                return(false);
            }
            byte[] buffer = new byte[5];
            reader.Read(buffer, 0, buffer.Length);
            if ((((buffer[0] != 0x4a) || (buffer[1] != 70)) || ((buffer[2] != 0x49) || (buffer[3] != 70))) || (buffer[4] != 0))
            {
                return(false);
            }
            this.majorVersion = reader.ReadByte();
            this.minorVersion = reader.ReadByte();
            if ((this.majorVersion != 1) || ((this.majorVersion == 1) && (this.minorVersion > 2)))
            {
                return(false);
            }
            this.Units = (UnitType)reader.ReadByte();
            if (((this.Units != UnitType.None) && (this.Units != UnitType.Inches)) && (this.Units != UnitType.Centimeters))
            {
                return(false);
            }
            this.XDensity   = reader.ReadShort();
            this.YDensity   = reader.ReadShort();
            this.Xthumbnail = reader.ReadByte();
            this.Ythumbnail = reader.ReadByte();
            int count = (3 * this.Xthumbnail) * this.Ythumbnail;

            if ((num > JFIF_FIXED_LENGTH) && (count != (num - JFIF_FIXED_LENGTH)))
            {
                return(false);
            }
            if (count > 0)
            {
                this.thumbnail = new byte[count];
                if (reader.Read(this.thumbnail, 0, count) != count)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 3
0
 private bool TryParseJFIF(byte[] data)
 {
     FluxJpeg.Core.IO.BinaryReader reader = new FluxJpeg.Core.IO.BinaryReader(new MemoryStream(data));
     int num = data.Length + 2;
     if (num < JFIF_FIXED_LENGTH)
     {
         return false;
     }
     byte[] buffer = new byte[5];
     reader.Read(buffer, 0, buffer.Length);
     if ((((buffer[0] != 0x4a) || (buffer[1] != 70)) || ((buffer[2] != 0x49) || (buffer[3] != 70))) || (buffer[4] != 0))
     {
         return false;
     }
     this.majorVersion = reader.ReadByte();
     this.minorVersion = reader.ReadByte();
     if ((this.majorVersion != 1) || ((this.majorVersion == 1) && (this.minorVersion > 2)))
     {
         return false;
     }
     this.Units = (UnitType) reader.ReadByte();
     if (((this.Units != UnitType.None) && (this.Units != UnitType.Inches)) && (this.Units != UnitType.Centimeters))
     {
         return false;
     }
     this.XDensity = reader.ReadShort();
     this.YDensity = reader.ReadShort();
     this.Xthumbnail = reader.ReadByte();
     this.Ythumbnail = reader.ReadByte();
     int count = (3 * this.Xthumbnail) * this.Ythumbnail;
     if ((num > JFIF_FIXED_LENGTH) && (count != (num - JFIF_FIXED_LENGTH)))
     {
         return false;
     }
     if (count > 0)
     {
         this.thumbnail = new byte[count];
         if (reader.Read(this.thumbnail, 0, count) != count)
         {
             return false;
         }
     }
     return true;
 }