Exemplo n.º 1
0
        private static Size DecodeTiffLE(BinaryReader binaryReader)
        {
            if (binaryReader.ReadByte() != 0)
            {
                return(Size.Empty);
            }

            int idfStart = ByteHelper.ReadInt32LE(binaryReader);

            binaryReader.BaseStream.Seek(idfStart, SeekOrigin.Begin);

            int numberOfIDF = ByteHelper.ReadInt16LE(binaryReader);

            int width  = -1;
            int height = -1;

            for (int i = 0; i < numberOfIDF; i++)
            {
                short field = ByteHelper.ReadInt16LE(binaryReader);

                switch (field)
                {
                // https://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
                default:
                    binaryReader.ReadBytes(10);
                    break;

                case 256:     // image width
                    binaryReader.ReadBytes(6);
                    width = ByteHelper.ReadInt32LE(binaryReader);
                    break;

                case 257:     // image length
                    binaryReader.ReadBytes(6);
                    height = ByteHelper.ReadInt32LE(binaryReader);
                    break;
                }
                if (width != -1 && height != -1)
                {
                    return(new Size(width, height));
                }
            }
            return(Size.Empty);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the dimensions of an image.
        /// </summary>
        /// <param name="path">The path of the image to get the dimensions of.</param>
        /// <returns>The dimensions of the specified image.</returns>
        /// <exception cref="ArgumentException">The image was of an unrecognised format.</exception>
        public static Size GetDimensions(BinaryReader binaryReader)
        {
            byte[] magicBytes = new byte[MAX_MAGIC_BYTE_LENGTH];

            for (int i = 0; i < MAX_MAGIC_BYTE_LENGTH; i += 1)
            {
                magicBytes[i] = binaryReader.ReadByte();

                foreach (KeyValuePair <byte[], Func <BinaryReader, Size> > kvPair in Image_Format_Decoders)
                {
                    if (ByteHelper.StartsWith(magicBytes, kvPair.Key))
                    {
                        return(kvPair.Value(binaryReader));
                    }
                }
            }

            return(Size.Empty);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Checks if param 2 starts with param 1.
 /// </summary>
 /// <returns>True if param 2 starts with param 1.</returns>
 public static bool StartsWith(this byte[] thisBytes, byte[] thatBytes)
 {
     return(ByteHelper.StartsWith(thatBytes, thisBytes));
 }