コード例 #1
0
        public override bool Parse(JpegParser dataReader)
        {
            if (!base.Parse(dataReader))
            {
                return(false);
            }

            JpegParser jpegDataReader = dataReader as JpegParser;

            jpegDataReader.GetUShort(Attribute.Length, "{0:X4}");
            jpegDataReader.GetFourCC(Attribute.Identifier);
            jpegDataReader.DataReader.GetByte();                // =0
            jpegDataReader.GetUShort(Attribute.Version, "{0:X4}");
            jpegDataReader.GetByte(Attribute.Units);
            jpegDataReader.GetUShort(Attribute.XDensity);
            jpegDataReader.GetUShort(Attribute.YDensity);
            int xThumbnail = jpegDataReader.GetByte(Attribute.XThumbnail);
            int yThumbnail = jpegDataReader.GetByte(Attribute.YThumbnail);

            // The following parameter shows that data from previous parameters can
            // be used to calculate other parameters, such as header lengths etc.
            int rgbLength = 3 * xThumbnail * yThumbnail;

            // As the actual byte data might be large, a placeholder string is used instead
            Attributes.Add(new FormattedAttribute <Attribute, string>(Attribute.RGBn, "<RGB values for thumbnail>"));

            // Increment the Position for the packed RGB values of the thumbnail
            jpegDataReader.DataReader.Position += rgbLength;

            return(this.Valid);
        }
コード例 #2
0
        /// <summary>
        /// Search for headers in the data and store the results.
        /// </summary>
        /// <param name="dataReader">the data to read the bytes and bits from</param>
        public IResultNode DetectData(IDataReader dataReader, IDetectionProperties properties)
        {
            JpegHeader root = new JpegHeader(this);

            using (JpegParser parser = new JpegParser(dataReader))
            {
                JpegHeader previousHeader = root;
                ushort     marker;

                while ((marker = parser.NextMarker()) != 0)
                {
                    JpegHeader header = HeaderForMarker(marker, previousHeader);

                    if (header != null && header.HeaderName == JpegHeaderName.StartOfImage && root.Children.Count > 0)
                    {
                        root.Children.Clear();
                    }
                    if (header != null && parser.Parse(header))
                    {
                        previousHeader = header;

                        if (IsFullFile(root))
                        {
                            break;
                        }
                    }
                    else
                    {
                        parser.DataReader.Position++;
                    }
                }
            }

            if (dataReader.State == DataReaderState.Cancelled || !IsFullFile(root))
            {
                root = null;
            }
            else
            {
                properties.DataFormat = CodecID.Jpeg;
                properties.IsFullFile = true;
            }
            return(root);
        }