OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 const EXIF_MARK_SOI = 0xffd8; // Start of image data. | 5 const EXIF_MARK_SOI = 0xffd8; // Start of image data. |
6 const EXIF_MARK_SOS = 0xffda; // Start of "stream" (the actual image data). | 6 const EXIF_MARK_SOS = 0xffda; // Start of "stream" (the actual image data). |
7 const EXIF_MARK_SOF = 0xffc0; // Start of "frame" | 7 const EXIF_MARK_SOF = 0xffc0; // Start of "frame" |
8 const EXIF_MARK_EXIF = 0xffe1; // Start of exif block. | 8 const EXIF_MARK_EXIF = 0xffe1; // Start of exif block. |
9 | 9 |
10 const EXIF_ALIGN_LITTLE = 0x4949; // Indicates little endian exif data. | 10 const EXIF_ALIGN_LITTLE = 0x4949; // Indicates little endian exif data. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 var mark = this.readMark(br); | 79 var mark = this.readMark(br); |
80 if (mark == EXIF_MARK_SOS) | 80 if (mark == EXIF_MARK_SOS) |
81 throw new Error('SOS marker found before SOF'); | 81 throw new Error('SOS marker found before SOF'); |
82 | 82 |
83 var markLength = this.readMarkLength(br); | 83 var markLength = this.readMarkLength(br); |
84 | 84 |
85 var nextSectionStart = br.tell() + markLength; | 85 var nextSectionStart = br.tell() + markLength; |
86 if (!br.canRead(markLength)) { | 86 if (!br.canRead(markLength)) { |
87 // Get the entire section. | 87 // Get the entire section. |
| 88 if (filePos + br.tell() + markLength > file.size) { |
| 89 throw new Error( |
| 90 'Invalid section length @' + (filePos + br.tell() - 2)); |
| 91 } |
88 reread(-4, markLength + 4); | 92 reread(-4, markLength + 4); |
89 return; | 93 return; |
90 } | 94 } |
91 | 95 |
92 if (mark == EXIF_MARK_EXIF) { | 96 if (mark == EXIF_MARK_EXIF) { |
93 this.parseExifSection(metadata, buf, br); | 97 this.parseExifSection(metadata, buf, br); |
94 } else if (mark == EXIF_MARK_SOF) { | 98 } else if ((mark & ~0xF) == EXIF_MARK_SOF) { |
95 // The most reliable size information is encoded in the SOF section. | 99 // The most reliable size information is encoded in the SOF section. |
| 100 // There are 16 variants of the SOF format distinguished by the last |
| 101 // hex digit of the mark, but the part we want is always the same. |
96 br.seek(1, ByteReader.SEEK_CUR); // Skip the precision byte. | 102 br.seek(1, ByteReader.SEEK_CUR); // Skip the precision byte. |
97 var height = br.readScalar(2); | 103 var height = br.readScalar(2); |
98 var width = br.readScalar(2); | 104 var width = br.readScalar(2); |
99 ExifParser.setImageSize(metadata, width, height); | 105 ExifParser.setImageSize(metadata, width, height); |
100 callback(metadata); // We are done! | 106 callback(metadata); // We are done! |
101 return; | 107 return; |
102 } | 108 } |
103 | 109 |
104 br.seek(nextSectionStart, ByteReader.SEEK_BEG); | 110 br.seek(nextSectionStart, ByteReader.SEEK_BEG); |
105 } | 111 } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 return { | 348 return { |
343 scaleX: ExifParser.SCALEX[index], | 349 scaleX: ExifParser.SCALEX[index], |
344 scaleY: ExifParser.SCALEY[index], | 350 scaleY: ExifParser.SCALEY[index], |
345 rotate90: ExifParser.ROTATE90[index] | 351 rotate90: ExifParser.ROTATE90[index] |
346 } | 352 } |
347 } | 353 } |
348 return null; | 354 return null; |
349 }; | 355 }; |
350 | 356 |
351 MetadataDispatcher.registerParserClass(ExifParser); | 357 MetadataDispatcher.registerParserClass(ExifParser); |
OLD | NEW |