OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /* Base class for image metadata parsers that only need to look at a short | 5 /* Base class for image metadata parsers that only need to look at a short |
6 fragment at the start of the file */ | 6 fragment at the start of the file */ |
7 function SimpleImageParser(parent, type, urlFilter, headerSize) { | 7 function SimpleImageParser(parent, type, urlFilter, headerSize) { |
8 ImageParser.call(this, parent, type, urlFilter); | 8 ImageParser.call(this, parent, type, urlFilter); |
9 this.headerSize = headerSize; | 9 this.headerSize = headerSize; |
10 } | 10 } |
11 | 11 |
12 SimpleImageParser.prototype = {__proto__: ImageParser.prototype}; | 12 SimpleImageParser.prototype = {__proto__: ImageParser.prototype}; |
13 | 13 |
14 SimpleImageParser.prototype.parse = function( | 14 SimpleImageParser.prototype.parse = function( |
15 file, metadata, callback, errorCallback) { | 15 file, metadata, callback, errorCallback) { |
16 var self = this; | 16 var self = this; |
17 util.readFileBytes(file, 0, this.headerSize, | 17 util.readFileBytes(file, 0, this.headerSize, |
18 function (file, br) { | 18 function(file, br) { |
19 try { | 19 try { |
20 self.parseHeader(metadata, br); | 20 self.parseHeader(metadata, br); |
21 callback(metadata); | 21 callback(metadata); |
22 } catch(e) { | 22 } catch (e) { |
23 errorCallback(e.toString()); | 23 errorCallback(e.toString()); |
24 } | 24 } |
25 }, | 25 }, |
26 errorCallback); | 26 errorCallback); |
27 }; | 27 }; |
28 | 28 |
29 | 29 |
30 function PngParser(parent) { | 30 function PngParser(parent) { |
31 SimpleImageParser.call(this, parent, 'png', /\.png$/i, 24); | 31 SimpleImageParser.call(this, parent, 'png', /\.png$/i, 24); |
32 } | 32 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 br.setByteOrder(ByteReader.LITTLE_ENDIAN); | 83 br.setByteOrder(ByteReader.LITTLE_ENDIAN); |
84 | 84 |
85 var signature = br.readString(6); | 85 var signature = br.readString(6); |
86 if (!signature.match(/GIF8(7|9)a/)) | 86 if (!signature.match(/GIF8(7|9)a/)) |
87 throw new Error('Invalid GIF signature: ' + signature); | 87 throw new Error('Invalid GIF signature: ' + signature); |
88 | 88 |
89 metadata.width = br.readScalar(2); | 89 metadata.width = br.readScalar(2); |
90 metadata.height = br.readScalar(2); | 90 metadata.height = br.readScalar(2); |
91 }; | 91 }; |
92 | 92 |
93 MetadataDispatcher.registerParserClass(GifParser); | 93 MetadataDispatcher.registerParserClass(GifParser); |
OLD | NEW |