@mapcatch/util 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +53 -0
- package/.prettierrc +4 -0
- package/CHANGELOG.md +0 -0
- package/README.md +44 -0
- package/docs/Catolog.md +24 -0
- package/docs/Util.md +170 -0
- package/package.json +30 -0
- package/src/constants/cameras.js +5 -0
- package/src/constants/index.js +1 -0
- package/src/event.js +205 -0
- package/src/exif/exif.js +37 -0
- package/src/exif/gps_tags.js +33 -0
- package/src/exif/ifd1_tags.js +22 -0
- package/src/exif/index.js +16 -0
- package/src/exif/iptc_field_map.js +12 -0
- package/src/exif/parse_image.js +446 -0
- package/src/exif/string_values.js +137 -0
- package/src/exif/tags.js +75 -0
- package/src/exif/tiff_tags.js +35 -0
- package/src/exif/util.js +108 -0
- package/src/gl-operations/constants.js +11 -0
- package/src/gl-operations/default_options.js +98 -0
- package/src/gl-operations/index.js +594 -0
- package/src/gl-operations/reglCommands/contours.js +27 -0
- package/src/gl-operations/reglCommands/default.js +44 -0
- package/src/gl-operations/reglCommands/hillshading.js +332 -0
- package/src/gl-operations/reglCommands/index.js +6 -0
- package/src/gl-operations/reglCommands/multiLayers.js +301 -0
- package/src/gl-operations/reglCommands/transitions.js +109 -0
- package/src/gl-operations/reglCommands/util.js +71 -0
- package/src/gl-operations/renderer.js +193 -0
- package/src/gl-operations/shaders/fragment/convertDem.js +26 -0
- package/src/gl-operations/shaders/fragment/convolutionSmooth.js +55 -0
- package/src/gl-operations/shaders/fragment/diffCalc.js +34 -0
- package/src/gl-operations/shaders/fragment/drawResult.js +42 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvAmbientShadows.js +79 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvDirect.js +55 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalBaselayer.js +31 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalColorscale.js +56 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvMergeAndScaleTiles.js +27 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvNormals.js +26 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvSmooth.js +54 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvSoftShadows.js +81 -0
- package/src/gl-operations/shaders/fragment/hillshading/hsPregen.js +50 -0
- package/src/gl-operations/shaders/fragment/interpolateColor.js +63 -0
- package/src/gl-operations/shaders/fragment/interpolateColorOnly.js +47 -0
- package/src/gl-operations/shaders/fragment/interpolateValue.js +124 -0
- package/src/gl-operations/shaders/fragment/multiAnalyze1Calc.js +36 -0
- package/src/gl-operations/shaders/fragment/multiAnalyze2Calc.js +46 -0
- package/src/gl-operations/shaders/fragment/multiAnalyze3Calc.js +54 -0
- package/src/gl-operations/shaders/fragment/multiAnalyze4Calc.js +62 -0
- package/src/gl-operations/shaders/fragment/multiAnalyze5Calc.js +70 -0
- package/src/gl-operations/shaders/fragment/multiAnalyze6Calc.js +78 -0
- package/src/gl-operations/shaders/fragment/single.js +88 -0
- package/src/gl-operations/shaders/transform.js +22 -0
- package/src/gl-operations/shaders/util/computeColor.glsl +84 -0
- package/src/gl-operations/shaders/util/getTexelValue.glsl +10 -0
- package/src/gl-operations/shaders/util/isCloseEnough.glsl +9 -0
- package/src/gl-operations/shaders/util/rgbaToFloat.glsl +18 -0
- package/src/gl-operations/shaders/vertex/double.js +17 -0
- package/src/gl-operations/shaders/vertex/multi3.js +20 -0
- package/src/gl-operations/shaders/vertex/multi4.js +23 -0
- package/src/gl-operations/shaders/vertex/multi5.js +26 -0
- package/src/gl-operations/shaders/vertex/multi6.js +29 -0
- package/src/gl-operations/shaders/vertex/single.js +13 -0
- package/src/gl-operations/shaders/vertex/singleNotTransformed.js +12 -0
- package/src/gl-operations/texture_manager.js +141 -0
- package/src/gl-operations/util.js +336 -0
- package/src/index.js +10 -0
- package/src/util.js +332 -0
- package/vite.config.js +52 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import util from './util'
|
|
2
|
+
import TiffTags from './tiff_tags'
|
|
3
|
+
import ExifTags from './tags'
|
|
4
|
+
import StringValues from './string_values'
|
|
5
|
+
import GPSTags from './gps_tags'
|
|
6
|
+
import IptcFieldMap from './iptc_field_map'
|
|
7
|
+
|
|
8
|
+
var isXmpEnabled = false
|
|
9
|
+
|
|
10
|
+
export const getData = function (img, callback) {
|
|
11
|
+
if (((self.Image && img instanceof self.Image)
|
|
12
|
+
|| (self.HTMLImageElement && img instanceof self.HTMLImageElement))
|
|
13
|
+
&& !img.complete) {
|
|
14
|
+
callback(null, new Error('不支持的格式'))
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if (!util.imageHasData(img)) {
|
|
20
|
+
getImageData(img, callback);
|
|
21
|
+
} else {
|
|
22
|
+
if (callback) {
|
|
23
|
+
callback.call(img);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getImageData(img, callback) {
|
|
30
|
+
function handleBinaryFile(binFile) {
|
|
31
|
+
try {
|
|
32
|
+
var data = findEXIFinJPEG(binFile);
|
|
33
|
+
img.exifdata = data || {};
|
|
34
|
+
// var iptcdata = findIPTCinJPEG(binFile);
|
|
35
|
+
// img.iptcdata = iptcdata || {};
|
|
36
|
+
if (isXmpEnabled) {
|
|
37
|
+
var xmpdata = findXMPinJPEG(binFile);
|
|
38
|
+
img.xmpdata = xmpdata || {};
|
|
39
|
+
}
|
|
40
|
+
if (callback) {
|
|
41
|
+
callback.call(img);
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
callback(null, err)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (img.src) {
|
|
49
|
+
if (/^data\:/i.test(img.src)) { // Data URI
|
|
50
|
+
var arrayBuffer = util.base64ToArrayBuffer(img.src);
|
|
51
|
+
handleBinaryFile(arrayBuffer);
|
|
52
|
+
|
|
53
|
+
} else if (/^blob\:/i.test(img.src)) { // Object URL
|
|
54
|
+
var fileReader = new FileReader();
|
|
55
|
+
fileReader.onload = function (e) {
|
|
56
|
+
handleBinaryFile(e.target.result);
|
|
57
|
+
};
|
|
58
|
+
util.objectURLToBlob(img.src, function (blob) {
|
|
59
|
+
fileReader.readAsArrayBuffer(blob);
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
var http = new XMLHttpRequest();
|
|
63
|
+
http.onload = function () {
|
|
64
|
+
if (this.status == 200 || this.status === 0) {
|
|
65
|
+
handleBinaryFile(http.response);
|
|
66
|
+
} else {
|
|
67
|
+
throw "Could not load image";
|
|
68
|
+
}
|
|
69
|
+
http = null;
|
|
70
|
+
};
|
|
71
|
+
http.open("GET", img.src, true);
|
|
72
|
+
http.responseType = "arraybuffer";
|
|
73
|
+
http.send(null);
|
|
74
|
+
}
|
|
75
|
+
} else if (self.FileReader && (img instanceof self.Blob || img instanceof self.File)) {
|
|
76
|
+
var fileReader = new FileReader();
|
|
77
|
+
fileReader.onload = function (e) {
|
|
78
|
+
handleBinaryFile(e.target.result);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
fileReader.readAsArrayBuffer(img);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function findEXIFinJPEG(file) {
|
|
86
|
+
var dataView = new DataView(file);
|
|
87
|
+
|
|
88
|
+
if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) {
|
|
89
|
+
return false; // not a valid jpeg
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var offset = 2,
|
|
93
|
+
length = file.byteLength,
|
|
94
|
+
marker;
|
|
95
|
+
|
|
96
|
+
while (offset < length) {
|
|
97
|
+
if (dataView.getUint8(offset) != 0xFF) {
|
|
98
|
+
return false; // not a valid marker, something is wrong
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
marker = dataView.getUint8(offset + 1);
|
|
102
|
+
|
|
103
|
+
// we could implement handling for other markers here,
|
|
104
|
+
// but we're only looking for 0xFFE1 for EXIF data
|
|
105
|
+
|
|
106
|
+
if (marker == 225) {
|
|
107
|
+
|
|
108
|
+
return readEXIFData(dataView, offset + 4, dataView.getUint16(offset + 2) - 2);
|
|
109
|
+
|
|
110
|
+
// offset += 2 + file.getShortAt(offset+2, true);
|
|
111
|
+
|
|
112
|
+
} else {
|
|
113
|
+
offset += 2 + dataView.getUint16(offset + 2);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function findIPTCinJPEG(file) {
|
|
121
|
+
var dataView = new DataView(file);
|
|
122
|
+
|
|
123
|
+
if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) {
|
|
124
|
+
return false; // not a valid jpeg
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var offset = 2,
|
|
128
|
+
length = file.byteLength;
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
var isFieldSegmentStart = function (dataView, offset) {
|
|
132
|
+
return (
|
|
133
|
+
dataView.getUint8(offset) === 0x38 &&
|
|
134
|
+
dataView.getUint8(offset + 1) === 0x42 &&
|
|
135
|
+
dataView.getUint8(offset + 2) === 0x49 &&
|
|
136
|
+
dataView.getUint8(offset + 3) === 0x4D &&
|
|
137
|
+
dataView.getUint8(offset + 4) === 0x04 &&
|
|
138
|
+
dataView.getUint8(offset + 5) === 0x04
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
while (offset < length) {
|
|
143
|
+
|
|
144
|
+
if (isFieldSegmentStart(dataView, offset)) {
|
|
145
|
+
|
|
146
|
+
// Get the length of the name header (which is padded to an even number of bytes)
|
|
147
|
+
var nameHeaderLength = dataView.getUint8(offset + 7);
|
|
148
|
+
if (nameHeaderLength % 2 !== 0) nameHeaderLength += 1;
|
|
149
|
+
// Check for pre photoshop 6 format
|
|
150
|
+
if (nameHeaderLength === 0) {
|
|
151
|
+
// Always 4
|
|
152
|
+
nameHeaderLength = 4;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var startOffset = offset + 8 + nameHeaderLength;
|
|
156
|
+
var sectionLength = dataView.getUint16(offset + 6 + nameHeaderLength);
|
|
157
|
+
|
|
158
|
+
return readIPTCData(file, startOffset, sectionLength);
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
// Not the marker, continue searching
|
|
162
|
+
offset++;
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function findXMPinJPEG(file) {
|
|
168
|
+
|
|
169
|
+
if (!('DOMParser' in self)) {
|
|
170
|
+
// console.warn('XML parsing not supported without DOMParser');
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
var dataView = new DataView(file);
|
|
174
|
+
|
|
175
|
+
if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) {
|
|
176
|
+
return false; // not a valid jpeg
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var offset = 2,
|
|
180
|
+
length = file.byteLength,
|
|
181
|
+
dom = new DOMParser();
|
|
182
|
+
|
|
183
|
+
while (offset < (length - 4)) {
|
|
184
|
+
if (util.getStringFromDB(dataView, offset, 4) == "http") {
|
|
185
|
+
var startOffset = offset - 1;
|
|
186
|
+
var sectionLength = dataView.getUint16(offset - 2) - 1;
|
|
187
|
+
var xmpString = util.getStringFromDB(dataView, startOffset, sectionLength)
|
|
188
|
+
var xmpEndIndex = xmpString.indexOf('xmpmeta>') + 8;
|
|
189
|
+
xmpString = xmpString.substring(xmpString.indexOf('<x:xmpmeta'), xmpEndIndex);
|
|
190
|
+
|
|
191
|
+
var indexOfXmp = xmpString.indexOf('x:xmpmeta') + 10
|
|
192
|
+
//Many custom written programs embed xmp/xml without any namespace. Following are some of them.
|
|
193
|
+
//Without these namespaces, XML is thought to be invalid by parsers
|
|
194
|
+
xmpString = xmpString.slice(0, indexOfXmp)
|
|
195
|
+
+ 'xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" '
|
|
196
|
+
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
|
|
197
|
+
+ 'xmlns:tiff="http://ns.adobe.com/tiff/1.0/" '
|
|
198
|
+
+ 'xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus" '
|
|
199
|
+
+ 'xmlns:ext="http://www.gettyimages.com/xsltExtension/1.0" '
|
|
200
|
+
+ 'xmlns:exif="http://ns.adobe.com/exif/1.0/" '
|
|
201
|
+
+ 'xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" '
|
|
202
|
+
+ 'xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" '
|
|
203
|
+
+ 'xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" '
|
|
204
|
+
+ 'xmlns:xapGImg="http://ns.adobe.com/xap/1.0/g/img/" '
|
|
205
|
+
+ 'xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/" '
|
|
206
|
+
+ xmpString.slice(indexOfXmp)
|
|
207
|
+
|
|
208
|
+
var domDocument = dom.parseFromString(xmpString, 'text/xml');
|
|
209
|
+
return util.xml2Object(domDocument);
|
|
210
|
+
} else {
|
|
211
|
+
offset++;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function readEXIFData(file, start) {
|
|
217
|
+
if (util.getStringFromDB(file, start, 4) != "Exif") {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var bigEnd,
|
|
222
|
+
tags, tag,
|
|
223
|
+
exifData, gpsData,
|
|
224
|
+
tiffOffset = start + 6;
|
|
225
|
+
|
|
226
|
+
// test for TIFF validity and endianness
|
|
227
|
+
if (file.getUint16(tiffOffset) == 0x4949) {
|
|
228
|
+
bigEnd = false;
|
|
229
|
+
} else if (file.getUint16(tiffOffset) == 0x4D4D) {
|
|
230
|
+
bigEnd = true;
|
|
231
|
+
} else {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (file.getUint16(tiffOffset + 2, !bigEnd) != 0x002A) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
var firstIFDOffset = file.getUint32(tiffOffset + 4, !bigEnd);
|
|
240
|
+
|
|
241
|
+
if (firstIFDOffset < 0x00000008) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
tags = readTags(file, tiffOffset, tiffOffset + firstIFDOffset, TiffTags, bigEnd);
|
|
246
|
+
|
|
247
|
+
if (tags.ExifIFDPointer) {
|
|
248
|
+
exifData = readTags(file, tiffOffset, tiffOffset + tags.ExifIFDPointer, ExifTags, bigEnd);
|
|
249
|
+
for (tag in exifData) {
|
|
250
|
+
switch (tag) {
|
|
251
|
+
case "LightSource":
|
|
252
|
+
case "Flash":
|
|
253
|
+
case "MeteringMode":
|
|
254
|
+
case "ExposureProgram":
|
|
255
|
+
case "SensingMethod":
|
|
256
|
+
case "SceneCaptureType":
|
|
257
|
+
case "SceneType":
|
|
258
|
+
case "CustomRendered":
|
|
259
|
+
case "WhiteBalance":
|
|
260
|
+
case "GainControl":
|
|
261
|
+
case "Contrast":
|
|
262
|
+
case "Saturation":
|
|
263
|
+
case "Sharpness":
|
|
264
|
+
case "SubjectDistanceRange":
|
|
265
|
+
case "FileSource":
|
|
266
|
+
exifData[tag] = StringValues[tag][exifData[tag]];
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case "ExifVersion":
|
|
270
|
+
case "FlashpixVersion":
|
|
271
|
+
exifData[tag] = String.fromCharCode(exifData[tag][0], exifData[tag][1], exifData[tag][2], exifData[tag][3]);
|
|
272
|
+
break;
|
|
273
|
+
|
|
274
|
+
case "ComponentsConfiguration":
|
|
275
|
+
exifData[tag] =
|
|
276
|
+
StringValues.Components[exifData[tag][0]] +
|
|
277
|
+
StringValues.Components[exifData[tag][1]] +
|
|
278
|
+
StringValues.Components[exifData[tag][2]] +
|
|
279
|
+
StringValues.Components[exifData[tag][3]];
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
tags[tag] = exifData[tag];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (tags.GPSInfoIFDPointer) {
|
|
287
|
+
gpsData = readTags(file, tiffOffset, tiffOffset + tags.GPSInfoIFDPointer, GPSTags, bigEnd);
|
|
288
|
+
for (tag in gpsData) {
|
|
289
|
+
switch (tag) {
|
|
290
|
+
case "GPSVersionID":
|
|
291
|
+
gpsData[tag] = gpsData[tag][0] +
|
|
292
|
+
"." + gpsData[tag][1] +
|
|
293
|
+
"." + gpsData[tag][2] +
|
|
294
|
+
"." + gpsData[tag][3];
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
tags[tag] = gpsData[tag];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// extract thumbnail
|
|
302
|
+
//tags['thumbnail'] = readThumbnailImage(file, tiffOffset, firstIFDOffset, bigEnd);
|
|
303
|
+
|
|
304
|
+
return tags;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function readTags(file, tiffStart, dirStart, strings, bigEnd) {
|
|
308
|
+
var entries = file.getUint16(dirStart, !bigEnd),
|
|
309
|
+
tags = {},
|
|
310
|
+
entryOffset, tag,
|
|
311
|
+
i;
|
|
312
|
+
|
|
313
|
+
for (i = 0; i < entries; i++) {
|
|
314
|
+
entryOffset = dirStart + i * 12 + 2;
|
|
315
|
+
tag = strings[file.getUint16(entryOffset, !bigEnd)];
|
|
316
|
+
tags[tag] = readTagValue(file, entryOffset, tiffStart, dirStart, bigEnd);
|
|
317
|
+
}
|
|
318
|
+
return tags;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function readTagValue(file, entryOffset, tiffStart, dirStart, bigEnd) {
|
|
322
|
+
var type = file.getUint16(entryOffset + 2, !bigEnd),
|
|
323
|
+
numValues = file.getUint32(entryOffset + 4, !bigEnd),
|
|
324
|
+
valueOffset = file.getUint32(entryOffset + 8, !bigEnd) + tiffStart,
|
|
325
|
+
offset,
|
|
326
|
+
vals, val, n,
|
|
327
|
+
numerator, denominator;
|
|
328
|
+
|
|
329
|
+
switch (type) {
|
|
330
|
+
case 1: // byte, 8-bit unsigned int
|
|
331
|
+
case 7: // undefined, 8-bit byte, value depending on field
|
|
332
|
+
if (numValues == 1) {
|
|
333
|
+
return file.getUint8(entryOffset + 8, !bigEnd);
|
|
334
|
+
} else {
|
|
335
|
+
offset = numValues > 4 ? valueOffset : (entryOffset + 8);
|
|
336
|
+
vals = [];
|
|
337
|
+
for (n = 0; n < numValues; n++) {
|
|
338
|
+
vals[n] = file.getUint8(offset + n);
|
|
339
|
+
}
|
|
340
|
+
return vals;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
case 2: // ascii, 8-bit byte
|
|
344
|
+
offset = numValues > 4 ? valueOffset : (entryOffset + 8);
|
|
345
|
+
return util.getStringFromDB(file, offset, numValues - 1);
|
|
346
|
+
|
|
347
|
+
case 3: // short, 16 bit int
|
|
348
|
+
if (numValues == 1) {
|
|
349
|
+
return file.getUint16(entryOffset + 8, !bigEnd);
|
|
350
|
+
} else {
|
|
351
|
+
offset = numValues > 2 ? valueOffset : (entryOffset + 8);
|
|
352
|
+
vals = [];
|
|
353
|
+
for (n = 0; n < numValues; n++) {
|
|
354
|
+
vals[n] = file.getUint16(offset + 2 * n, !bigEnd);
|
|
355
|
+
}
|
|
356
|
+
return vals;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
case 4: // long, 32 bit int
|
|
360
|
+
if (numValues == 1) {
|
|
361
|
+
return file.getUint32(entryOffset + 8, !bigEnd);
|
|
362
|
+
} else {
|
|
363
|
+
vals = [];
|
|
364
|
+
for (n = 0; n < numValues; n++) {
|
|
365
|
+
vals[n] = file.getUint32(valueOffset + 4 * n, !bigEnd);
|
|
366
|
+
}
|
|
367
|
+
return vals;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
case 5: // rational = two long values, first is numerator, second is denominator
|
|
371
|
+
if (numValues == 1) {
|
|
372
|
+
numerator = file.getUint32(valueOffset, !bigEnd);
|
|
373
|
+
denominator = file.getUint32(valueOffset + 4, !bigEnd);
|
|
374
|
+
val = new Number(numerator / denominator);
|
|
375
|
+
val.numerator = numerator;
|
|
376
|
+
val.denominator = denominator;
|
|
377
|
+
return val;
|
|
378
|
+
} else {
|
|
379
|
+
vals = [];
|
|
380
|
+
for (n = 0; n < numValues; n++) {
|
|
381
|
+
numerator = file.getUint32(valueOffset + 8 * n, !bigEnd);
|
|
382
|
+
denominator = file.getUint32(valueOffset + 4 + 8 * n, !bigEnd);
|
|
383
|
+
vals[n] = new Number(numerator / denominator);
|
|
384
|
+
vals[n].numerator = numerator;
|
|
385
|
+
vals[n].denominator = denominator;
|
|
386
|
+
}
|
|
387
|
+
return vals;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
case 9: // slong, 32 bit signed int
|
|
391
|
+
if (numValues == 1) {
|
|
392
|
+
return file.getInt32(entryOffset + 8, !bigEnd);
|
|
393
|
+
} else {
|
|
394
|
+
vals = [];
|
|
395
|
+
for (n = 0; n < numValues; n++) {
|
|
396
|
+
vals[n] = file.getInt32(valueOffset + 4 * n, !bigEnd);
|
|
397
|
+
}
|
|
398
|
+
return vals;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
case 10: // signed rational, two slongs, first is numerator, second is denominator
|
|
402
|
+
if (numValues == 1) {
|
|
403
|
+
return file.getInt32(valueOffset, !bigEnd) / file.getInt32(valueOffset + 4, !bigEnd);
|
|
404
|
+
} else {
|
|
405
|
+
vals = [];
|
|
406
|
+
for (n = 0; n < numValues; n++) {
|
|
407
|
+
vals[n] = file.getInt32(valueOffset + 8 * n, !bigEnd) / file.getInt32(valueOffset + 4 + 8 * n, !bigEnd);
|
|
408
|
+
}
|
|
409
|
+
return vals;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function readIPTCData(file, startOffset, sectionLength) {
|
|
415
|
+
var dataView = new DataView(file);
|
|
416
|
+
var data = {};
|
|
417
|
+
var fieldValue, fieldName, dataSize, segmentType, segmentSize;
|
|
418
|
+
var segmentStartPos = startOffset;
|
|
419
|
+
while (segmentStartPos < startOffset + sectionLength) {
|
|
420
|
+
if (dataView.getUint8(segmentStartPos) === 0x1C && dataView.getUint8(segmentStartPos + 1) === 0x02) {
|
|
421
|
+
segmentType = dataView.getUint8(segmentStartPos + 2);
|
|
422
|
+
if (segmentType in IptcFieldMap) {
|
|
423
|
+
dataSize = dataView.getInt16(segmentStartPos + 3);
|
|
424
|
+
segmentSize = dataSize + 5;
|
|
425
|
+
fieldName = IptcFieldMap[segmentType];
|
|
426
|
+
fieldValue = util.getStringFromDB(dataView, segmentStartPos + 5, dataSize);
|
|
427
|
+
// Check if we already stored a value with this name
|
|
428
|
+
if (data.hasOwnProperty(fieldName)) {
|
|
429
|
+
// Value already stored with this name, create multivalue field
|
|
430
|
+
if (data[fieldName] instanceof Array) {
|
|
431
|
+
data[fieldName].push(fieldValue);
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
data[fieldName] = [data[fieldName], fieldValue];
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
data[fieldName] = fieldValue;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
}
|
|
443
|
+
segmentStartPos++;
|
|
444
|
+
}
|
|
445
|
+
return data;
|
|
446
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
ExposureProgram: {
|
|
3
|
+
0: "Not defined",
|
|
4
|
+
1: "Manual",
|
|
5
|
+
2: "Normal program",
|
|
6
|
+
3: "Aperture priority",
|
|
7
|
+
4: "Shutter priority",
|
|
8
|
+
5: "Creative program",
|
|
9
|
+
6: "Action program",
|
|
10
|
+
7: "Portrait mode",
|
|
11
|
+
8: "Landscape mode"
|
|
12
|
+
},
|
|
13
|
+
MeteringMode: {
|
|
14
|
+
0: "Unknown",
|
|
15
|
+
1: "Average",
|
|
16
|
+
2: "CenterWeightedAverage",
|
|
17
|
+
3: "Spot",
|
|
18
|
+
4: "MultiSpot",
|
|
19
|
+
5: "Pattern",
|
|
20
|
+
6: "Partial",
|
|
21
|
+
255: "Other"
|
|
22
|
+
},
|
|
23
|
+
LightSource: {
|
|
24
|
+
0: "Unknown",
|
|
25
|
+
1: "Daylight",
|
|
26
|
+
2: "Fluorescent",
|
|
27
|
+
3: "Tungsten (incandescent light)",
|
|
28
|
+
4: "Flash",
|
|
29
|
+
9: "Fine weather",
|
|
30
|
+
10: "Cloudy weather",
|
|
31
|
+
11: "Shade",
|
|
32
|
+
12: "Daylight fluorescent (D 5700 - 7100K)",
|
|
33
|
+
13: "Day white fluorescent (N 4600 - 5400K)",
|
|
34
|
+
14: "Cool white fluorescent (W 3900 - 4500K)",
|
|
35
|
+
15: "White fluorescent (WW 3200 - 3700K)",
|
|
36
|
+
17: "Standard light A",
|
|
37
|
+
18: "Standard light B",
|
|
38
|
+
19: "Standard light C",
|
|
39
|
+
20: "D55",
|
|
40
|
+
21: "D65",
|
|
41
|
+
22: "D75",
|
|
42
|
+
23: "D50",
|
|
43
|
+
24: "ISO studio tungsten",
|
|
44
|
+
255: "Other"
|
|
45
|
+
},
|
|
46
|
+
Flash: {
|
|
47
|
+
0x0000: "Flash did not fire",
|
|
48
|
+
0x0001: "Flash fired",
|
|
49
|
+
0x0005: "Strobe return light not detected",
|
|
50
|
+
0x0007: "Strobe return light detected",
|
|
51
|
+
0x0009: "Flash fired, compulsory flash mode",
|
|
52
|
+
0x000D: "Flash fired, compulsory flash mode, return light not detected",
|
|
53
|
+
0x000F: "Flash fired, compulsory flash mode, return light detected",
|
|
54
|
+
0x0010: "Flash did not fire, compulsory flash mode",
|
|
55
|
+
0x0018: "Flash did not fire, auto mode",
|
|
56
|
+
0x0019: "Flash fired, auto mode",
|
|
57
|
+
0x001D: "Flash fired, auto mode, return light not detected",
|
|
58
|
+
0x001F: "Flash fired, auto mode, return light detected",
|
|
59
|
+
0x0020: "No flash function",
|
|
60
|
+
0x0041: "Flash fired, red-eye reduction mode",
|
|
61
|
+
0x0045: "Flash fired, red-eye reduction mode, return light not detected",
|
|
62
|
+
0x0047: "Flash fired, red-eye reduction mode, return light detected",
|
|
63
|
+
0x0049: "Flash fired, compulsory flash mode, red-eye reduction mode",
|
|
64
|
+
0x004D: "Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",
|
|
65
|
+
0x004F: "Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",
|
|
66
|
+
0x0059: "Flash fired, auto mode, red-eye reduction mode",
|
|
67
|
+
0x005D: "Flash fired, auto mode, return light not detected, red-eye reduction mode",
|
|
68
|
+
0x005F: "Flash fired, auto mode, return light detected, red-eye reduction mode"
|
|
69
|
+
},
|
|
70
|
+
SensingMethod: {
|
|
71
|
+
1: "Not defined",
|
|
72
|
+
2: "One-chip color area sensor",
|
|
73
|
+
3: "Two-chip color area sensor",
|
|
74
|
+
4: "Three-chip color area sensor",
|
|
75
|
+
5: "Color sequential area sensor",
|
|
76
|
+
7: "Trilinear sensor",
|
|
77
|
+
8: "Color sequential linear sensor"
|
|
78
|
+
},
|
|
79
|
+
SceneCaptureType: {
|
|
80
|
+
0: "Standard",
|
|
81
|
+
1: "Landscape",
|
|
82
|
+
2: "Portrait",
|
|
83
|
+
3: "Night scene"
|
|
84
|
+
},
|
|
85
|
+
SceneType: {
|
|
86
|
+
1: "Directly photographed"
|
|
87
|
+
},
|
|
88
|
+
CustomRendered: {
|
|
89
|
+
0: "Normal process",
|
|
90
|
+
1: "Custom process"
|
|
91
|
+
},
|
|
92
|
+
WhiteBalance: {
|
|
93
|
+
0: "Auto white balance",
|
|
94
|
+
1: "Manual white balance"
|
|
95
|
+
},
|
|
96
|
+
GainControl: {
|
|
97
|
+
0: "None",
|
|
98
|
+
1: "Low gain up",
|
|
99
|
+
2: "High gain up",
|
|
100
|
+
3: "Low gain down",
|
|
101
|
+
4: "High gain down"
|
|
102
|
+
},
|
|
103
|
+
Contrast: {
|
|
104
|
+
0: "Normal",
|
|
105
|
+
1: "Soft",
|
|
106
|
+
2: "Hard"
|
|
107
|
+
},
|
|
108
|
+
Saturation: {
|
|
109
|
+
0: "Normal",
|
|
110
|
+
1: "Low saturation",
|
|
111
|
+
2: "High saturation"
|
|
112
|
+
},
|
|
113
|
+
Sharpness: {
|
|
114
|
+
0: "Normal",
|
|
115
|
+
1: "Soft",
|
|
116
|
+
2: "Hard"
|
|
117
|
+
},
|
|
118
|
+
SubjectDistanceRange: {
|
|
119
|
+
0: "Unknown",
|
|
120
|
+
1: "Macro",
|
|
121
|
+
2: "Close view",
|
|
122
|
+
3: "Distant view"
|
|
123
|
+
},
|
|
124
|
+
FileSource: {
|
|
125
|
+
3: "DSC"
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
Components: {
|
|
129
|
+
0: "",
|
|
130
|
+
1: "Y",
|
|
131
|
+
2: "Cb",
|
|
132
|
+
3: "Cr",
|
|
133
|
+
4: "R",
|
|
134
|
+
5: "G",
|
|
135
|
+
6: "B"
|
|
136
|
+
}
|
|
137
|
+
};
|
package/src/exif/tags.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
|
|
3
|
+
// version tags
|
|
4
|
+
0x9000: "ExifVersion", // EXIF version
|
|
5
|
+
0xA000: "FlashpixVersion", // Flashpix format version
|
|
6
|
+
|
|
7
|
+
// colorspace tags
|
|
8
|
+
0xA001: "ColorSpace", // Color space information tag
|
|
9
|
+
|
|
10
|
+
// image configuration
|
|
11
|
+
0xA002: "PixelXDimension", // Valid width of meaningful image
|
|
12
|
+
0xA003: "PixelYDimension", // Valid height of meaningful image
|
|
13
|
+
0x9101: "ComponentsConfiguration", // Information about channels
|
|
14
|
+
0x9102: "CompressedBitsPerPixel", // Compressed bits per pixel
|
|
15
|
+
|
|
16
|
+
// user information
|
|
17
|
+
//0x927C: "MakerNote", // Any desired information written by the manufacturer
|
|
18
|
+
//0x9286: "UserComment", // Comments by user
|
|
19
|
+
|
|
20
|
+
// related file
|
|
21
|
+
0xA004: "RelatedSoundFile", // Name of related sound file
|
|
22
|
+
|
|
23
|
+
// date and time
|
|
24
|
+
0x9003: "DateTimeOriginal", // Date and time when the original image was generated
|
|
25
|
+
0x9004: "DateTimeDigitized", // Date and time when the image was stored digitally
|
|
26
|
+
0x9290: "SubsecTime", // Fractions of seconds for DateTime
|
|
27
|
+
0x9291: "SubsecTimeOriginal", // Fractions of seconds for DateTimeOriginal
|
|
28
|
+
0x9292: "SubsecTimeDigitized", // Fractions of seconds for DateTimeDigitized
|
|
29
|
+
|
|
30
|
+
// picture-taking conditions
|
|
31
|
+
0x829A: "ExposureTime", // Exposure time (in seconds)
|
|
32
|
+
0x829D: "FNumber", // F number
|
|
33
|
+
0x8822: "ExposureProgram", // Exposure program
|
|
34
|
+
0x8824: "SpectralSensitivity", // Spectral sensitivity
|
|
35
|
+
0x8827: "ISOSpeedRatings", // ISO speed rating
|
|
36
|
+
0x8828: "OECF", // Optoelectric conversion factor
|
|
37
|
+
0x9201: "ShutterSpeedValue", // Shutter speed
|
|
38
|
+
0x9202: "ApertureValue", // Lens aperture
|
|
39
|
+
0x9203: "BrightnessValue", // Value of brightness
|
|
40
|
+
0x9204: "ExposureBias", // Exposure bias
|
|
41
|
+
0x9205: "MaxApertureValue", // Smallest F number of lens
|
|
42
|
+
0x9206: "SubjectDistance", // Distance to subject in meters
|
|
43
|
+
0x9207: "MeteringMode", // Metering mode
|
|
44
|
+
0x9208: "LightSource", // Kind of light source
|
|
45
|
+
0x9209: "Flash", // Flash status
|
|
46
|
+
0x9214: "SubjectArea", // Location and area of main subject
|
|
47
|
+
0x920A: "FocalLength", // Focal length of the lens in mm
|
|
48
|
+
0xA20B: "FlashEnergy", // Strobe energy in BCPS
|
|
49
|
+
0xA20C: "SpatialFrequencyResponse", //
|
|
50
|
+
0xA20E: "FocalPlaneXResolution", // Number of pixels in width direction per FocalPlaneResolutionUnit
|
|
51
|
+
0xA20F: "FocalPlaneYResolution", // Number of pixels in height direction per FocalPlaneResolutionUnit
|
|
52
|
+
0xA210: "FocalPlaneResolutionUnit", // Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution
|
|
53
|
+
0xA214: "SubjectLocation", // Location of subject in image
|
|
54
|
+
0xA215: "ExposureIndex", // Exposure index selected on camera
|
|
55
|
+
0xA217: "SensingMethod", // Image sensor type
|
|
56
|
+
0xA300: "FileSource", // Image source (3 == DSC)
|
|
57
|
+
0xA301: "SceneType", // Scene type (1 == directly photographed)
|
|
58
|
+
0xA302: "CFAPattern", // Color filter array geometric pattern
|
|
59
|
+
0xA401: "CustomRendered", // Special processing
|
|
60
|
+
0xA402: "ExposureMode", // Exposure mode
|
|
61
|
+
0xA403: "WhiteBalance", // 1 = auto white balance, 2 = manual
|
|
62
|
+
0xA404: "DigitalZoomRation", // Digital zoom ratio
|
|
63
|
+
0xA405: "FocalLengthIn35mmFilm", // Equivalent foacl length assuming 35mm film camera (in mm)
|
|
64
|
+
0xA406: "SceneCaptureType", // Type of scene
|
|
65
|
+
0xA407: "GainControl", // Degree of overall image gain adjustment
|
|
66
|
+
0xA408: "Contrast", // Direction of contrast processing applied by camera
|
|
67
|
+
0xA409: "Saturation", // Direction of saturation processing applied by camera
|
|
68
|
+
0xA40A: "Sharpness", // Direction of sharpness processing applied by camera
|
|
69
|
+
0xA40B: "DeviceSettingDescription", //
|
|
70
|
+
0xA40C: "SubjectDistanceRange", // Distance to subject
|
|
71
|
+
|
|
72
|
+
// other tags
|
|
73
|
+
0xA005: "InteroperabilityIFDPointer",
|
|
74
|
+
0xA420: "ImageUniqueID" // Identifier assigned uniquely to each image
|
|
75
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
0x0100: "ImageWidth",
|
|
3
|
+
0x0101: "ImageHeight",
|
|
4
|
+
0x8769: "ExifIFDPointer",
|
|
5
|
+
0x8825: "GPSInfoIFDPointer",
|
|
6
|
+
0xA005: "InteroperabilityIFDPointer",
|
|
7
|
+
0x0102: "BitsPerSample",
|
|
8
|
+
0x0103: "Compression",
|
|
9
|
+
0x0106: "PhotometricInterpretation",
|
|
10
|
+
0x0112: "Orientation",
|
|
11
|
+
0x0115: "SamplesPerPixel",
|
|
12
|
+
0x011C: "PlanarConfiguration",
|
|
13
|
+
0x0212: "YCbCrSubSampling",
|
|
14
|
+
0x0213: "YCbCrPositioning",
|
|
15
|
+
0x011A: "XResolution",
|
|
16
|
+
0x011B: "YResolution",
|
|
17
|
+
0x0128: "ResolutionUnit",
|
|
18
|
+
0x0111: "StripOffsets",
|
|
19
|
+
0x0116: "RowsPerStrip",
|
|
20
|
+
0x0117: "StripByteCounts",
|
|
21
|
+
0x0201: "JPEGInterchangeFormat",
|
|
22
|
+
0x0202: "JPEGInterchangeFormatLength",
|
|
23
|
+
0x012D: "TransferFunction",
|
|
24
|
+
0x013E: "WhitePoint",
|
|
25
|
+
0x013F: "PrimaryChromaticities",
|
|
26
|
+
0x0211: "YCbCrCoefficients",
|
|
27
|
+
0x0214: "ReferenceBlackWhite",
|
|
28
|
+
0x0132: "DateTime",
|
|
29
|
+
0x010E: "ImageDescription",
|
|
30
|
+
0x010F: "Make",
|
|
31
|
+
0x0110: "Model",
|
|
32
|
+
0x0131: "Software",
|
|
33
|
+
0x013B: "Artist",
|
|
34
|
+
0x8298: "Copyright"
|
|
35
|
+
};
|