private static Size DecodeJfif(BinaryReader binaryReader) { while (binaryReader.ReadByte() == 0xff) { byte marker = binaryReader.ReadByte(); short chunkLength = ByteHelper.ReadInt16BE(binaryReader); if (marker == 0xc0 || marker == 0xc2) // c2: progressive { binaryReader.ReadByte(); int height = ByteHelper.ReadInt16BE(binaryReader); int width = ByteHelper.ReadInt16BE(binaryReader); return(new Size(width, height)); } if (chunkLength < 0) { ushort uchunkLength = (ushort)chunkLength; binaryReader.ReadBytes(uchunkLength - 2); } else { binaryReader.ReadBytes(chunkLength - 2); } } return(Size.Empty); }
private static Size DecodeTiffBE(BinaryReader binaryReader) { int idfStart = ByteHelper.ReadInt32BE(binaryReader); binaryReader.BaseStream.Seek(idfStart, SeekOrigin.Begin); int numberOfIDF = ByteHelper.ReadInt16BE(binaryReader); int width = -1; int height = -1; for (int i = 0; i < numberOfIDF; i++) { short field = ByteHelper.ReadInt16BE(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.ReadInt32BE(binaryReader); break; case 257: // image length binaryReader.ReadBytes(6); height = ByteHelper.ReadInt32BE(binaryReader); break; } if (width != -1 && height != -1) { return(new Size(width, height)); } } return(Size.Empty); }