@mapcatch/util 1.0.9 → 1.0.10

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.
Files changed (81) hide show
  1. package/.eslintrc.js +53 -0
  2. package/.prettierrc +4 -0
  3. package/CHANGELOG.md +8 -1
  4. package/debug/app.js +22 -0
  5. package/debug/index.html +52 -0
  6. package/debug/libs/vue.global.js +16159 -0
  7. package/debug/my_icon.png +0 -0
  8. package/docs/Catolog.md +24 -0
  9. package/docs/Constant.md +92 -0
  10. package/docs/Event.md +90 -0
  11. package/docs/Util.md +345 -0
  12. package/package.json +1 -2
  13. package/src/constants/bmap_types.js +2 -2
  14. package/src/constants/crs_types.js +22 -0
  15. package/src/constants/default_layers.js +9 -9
  16. package/src/constants/index.js +3 -2
  17. package/src/constants/layer_folders.js +4 -4
  18. package/src/constants/measurement_fields.js +198 -0
  19. package/src/gl-operations/shaders/fragment/convertDem.js +2 -2
  20. package/src/gl-operations/shaders/fragment/convolutionSmooth.js +2 -2
  21. package/src/gl-operations/shaders/fragment/diffCalc.js +2 -2
  22. package/src/gl-operations/shaders/fragment/drawResult.js +2 -2
  23. package/src/gl-operations/shaders/fragment/hillshading/hsAdvAmbientShadows.js +2 -2
  24. package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalBaselayer.js +2 -2
  25. package/src/gl-operations/shaders/fragment/hillshading/hsAdvNormals.js +2 -2
  26. package/src/gl-operations/shaders/fragment/hillshading/hsAdvSoftShadows.js +2 -2
  27. package/src/gl-operations/shaders/fragment/interpolateColor.js +2 -2
  28. package/src/gl-operations/shaders/fragment/interpolateColorOnly.js +2 -2
  29. package/src/gl-operations/shaders/fragment/interpolateValue.js +2 -2
  30. package/src/gl-operations/shaders/fragment/multiAnalyze1Calc.js +2 -2
  31. package/src/gl-operations/shaders/fragment/multiAnalyze2Calc.js +2 -2
  32. package/src/gl-operations/shaders/fragment/multiAnalyze3Calc.js +2 -2
  33. package/src/gl-operations/shaders/fragment/multiAnalyze4Calc.js +2 -2
  34. package/src/gl-operations/shaders/fragment/multiAnalyze5Calc.js +2 -2
  35. package/src/gl-operations/shaders/fragment/multiAnalyze6Calc.js +2 -2
  36. package/src/gl-operations/shaders/vertex/double.js +2 -2
  37. package/src/gl-operations/shaders/vertex/multi3.js +2 -2
  38. package/src/gl-operations/shaders/vertex/multi4.js +2 -2
  39. package/src/gl-operations/shaders/vertex/multi5.js +2 -2
  40. package/src/gl-operations/shaders/vertex/multi6.js +2 -2
  41. package/src/gl-operations/shaders/vertex/singleNotTransformed.js +2 -2
  42. package/src/index.js +0 -2
  43. package/src/util.js +31 -51
  44. package/vite.config.js +52 -0
  45. package/dist/catchUtil.min.esm.js +0 -17563
  46. package/dist/catchUtil.min.js +0 -284
  47. package/src/constants/map_view_mode.js +0 -10
  48. package/src/exif/exif.js +0 -37
  49. package/src/exif/gps_tags.js +0 -33
  50. package/src/exif/ifd1_tags.js +0 -22
  51. package/src/exif/index.js +0 -33
  52. package/src/exif/iptc_field_map.js +0 -12
  53. package/src/exif/parse_image.js +0 -445
  54. package/src/exif/string_values.js +0 -137
  55. package/src/exif/tags.js +0 -75
  56. package/src/exif/tiff_tags.js +0 -35
  57. package/src/exif/util.js +0 -108
  58. package/src/image-size/detector.js +0 -24
  59. package/src/image-size/fromFile.js +0 -55
  60. package/src/image-size/index.js +0 -2
  61. package/src/image-size/lookup.js +0 -37
  62. package/src/image-size/types/bmp.js +0 -10
  63. package/src/image-size/types/cur.js +0 -16
  64. package/src/image-size/types/dds.js +0 -10
  65. package/src/image-size/types/gif.js +0 -11
  66. package/src/image-size/types/heif.js +0 -35
  67. package/src/image-size/types/icns.js +0 -112
  68. package/src/image-size/types/ico.js +0 -74
  69. package/src/image-size/types/index.js +0 -43
  70. package/src/image-size/types/j2c.js +0 -11
  71. package/src/image-size/types/jp2.js +0 -22
  72. package/src/image-size/types/jpg.js +0 -157
  73. package/src/image-size/types/ktx.js +0 -18
  74. package/src/image-size/types/png.js +0 -36
  75. package/src/image-size/types/pnm.js +0 -74
  76. package/src/image-size/types/psd.js +0 -10
  77. package/src/image-size/types/svg.js +0 -100
  78. package/src/image-size/types/tga.js +0 -14
  79. package/src/image-size/types/tiff.js +0 -92
  80. package/src/image-size/types/utils.js +0 -83
  81. package/src/image-size/types/webp.js +0 -67
@@ -1,137 +0,0 @@
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 DELETED
@@ -1,75 +0,0 @@
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
- };
@@ -1,35 +0,0 @@
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
- };
package/src/exif/util.js DELETED
@@ -1,108 +0,0 @@
1
- export default {
2
- imageHasData(img) {
3
- return !!(img.exifdata);
4
- },
5
- getStringFromDB(buffer, start, length) {
6
- var outstr = "";
7
- for (var n = start; n < start + length; n++) {
8
- outstr += String.fromCharCode(buffer.getUint8(n));
9
- }
10
- return outstr;
11
- },
12
- xml2Object(xml) {
13
- try {
14
- var obj = {};
15
- if (xml.children.length > 0) {
16
- for (var i = 0; i < xml.children.length; i++) {
17
- var item = xml.children.item(i);
18
- var attributes = item.attributes;
19
- for (var idx in attributes) {
20
- var itemAtt = attributes[idx];
21
- var dataKey = itemAtt.nodeName;
22
- var dataValue = itemAtt.nodeValue;
23
-
24
- if (dataKey !== undefined) {
25
- obj[dataKey] = dataValue;
26
- }
27
- }
28
- var nodeName = item.nodeName;
29
-
30
- if (typeof (obj[nodeName]) == "undefined") {
31
- obj[nodeName] = this.xml2json(item);
32
- } else {
33
- if (typeof (obj[nodeName].push) == "undefined") {
34
- var old = obj[nodeName];
35
-
36
- obj[nodeName] = [];
37
- obj[nodeName].push(old);
38
- }
39
- obj[nodeName].push(this.xml2json(item));
40
- }
41
- }
42
- } else {
43
- obj = xml.textContent;
44
- }
45
- return obj;
46
- } catch (e) {
47
- console.log(e.message);
48
- }
49
- },
50
- xml2json(xml) {
51
- var json = {};
52
-
53
- if (xml.nodeType == 1) { // element node
54
- if (xml.attributes.length > 0) {
55
- json['@attributes'] = {};
56
- for (var j = 0; j < xml.attributes.length; j++) {
57
- var attribute = xml.attributes.item(j);
58
- json['@attributes'][attribute.nodeName] = attribute.nodeValue;
59
- }
60
- }
61
- } else if (xml.nodeType == 3) { // text node
62
- return xml.nodeValue;
63
- }
64
-
65
- // deal with children
66
- if (xml.hasChildNodes()) {
67
- for (var i = 0; i < xml.childNodes.length; i++) {
68
- var child = xml.childNodes.item(i);
69
- var nodeName = child.nodeName;
70
- if (json[nodeName] == null) {
71
- json[nodeName] = this.xml2json(child);
72
- } else {
73
- if (json[nodeName].push == null) {
74
- var old = json[nodeName];
75
- json[nodeName] = [];
76
- json[nodeName].push(old);
77
- }
78
- json[nodeName].push(this.xml2json(child));
79
- }
80
- }
81
- }
82
-
83
- return json;
84
- },
85
- objectURLToBlob(url, callback) {
86
- var http = new XMLHttpRequest();
87
- http.open("GET", url, true);
88
- http.responseType = "blob";
89
- http.onload = function (e) {
90
- if (this.status == 200 || this.status === 0) {
91
- callback(this.response);
92
- }
93
- };
94
- http.send();
95
- },
96
- base64ToArrayBuffer(base64, contentType) {
97
- contentType = contentType || base64.match(/^data\:([^\;]+)\;base64,/mi)[1] || ''; // e.g. 'data:image/jpeg;base64,...' => 'image/jpeg'
98
- base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
99
- var binary = atob(base64);
100
- var len = binary.length;
101
- var buffer = new ArrayBuffer(len);
102
- var view = new Uint8Array(buffer);
103
- for (var i = 0; i < len; i++) {
104
- view[i] = binary.charCodeAt(i);
105
- }
106
- return buffer;
107
- }
108
- }
@@ -1,24 +0,0 @@
1
- import { typeHandlers, types } from './types/index'
2
-
3
- // This map helps avoid validating for every single image type
4
- const firstBytes = new Map([
5
- [0x38, 'psd'],
6
- [0x42, 'bmp'],
7
- [0x44, 'dds'],
8
- [0x47, 'gif'],
9
- [0x49, 'tiff'],
10
- [0x4d, 'tiff'],
11
- [0x52, 'webp'],
12
- [0x69, 'icns'],
13
- [0x89, 'png'],
14
- [0xff, 'jpg'],
15
- ])
16
-
17
- export function detector(input) {
18
- const byte = input[0]
19
- const type = firstBytes.get(byte)
20
- if (type && typeHandlers.get(type).validate(input)) {
21
- return type
22
- }
23
- return types.find((type) => typeHandlers.get(type).validate(input))
24
- }
@@ -1,55 +0,0 @@
1
- import * as fs from 'node:fs'
2
- import * as path from 'node:path'
3
-
4
- import { lookup } from './lookup'
5
-
6
- // Maximum input size, with a default of 512 kilobytes.
7
- // TO-DO: make this adaptive based on the initial signature of the image
8
- const MaxInputSize = 512 * 1024
9
-
10
- // This queue is for async `fs` operations, to avoid reaching file-descriptor limits
11
- const queue = []
12
-
13
- let concurrency = 100
14
- export const setConcurrency = (c) => {
15
- concurrency = c
16
- }
17
-
18
- const processQueue = async () => {
19
- const jobs = queue.splice(0, concurrency)
20
- const promises = jobs.map(async ({ filePath, resolve, reject }) => {
21
- let handle
22
- try {
23
- handle = await fs.promises.open(path.resolve(filePath), 'r')
24
- } catch (err) {
25
- return reject(err)
26
- }
27
- try {
28
- const { size } = await handle.stat()
29
- if (size <= 0) {
30
- throw new Error('Empty file')
31
- }
32
- const inputSize = Math.min(size, MaxInputSize)
33
- const input = new Uint8Array(inputSize)
34
- await handle.read(input, 0, inputSize, 0)
35
- resolve(lookup(input))
36
- } catch (err) {
37
- reject(err)
38
- } finally {
39
- await handle.close()
40
- }
41
- })
42
-
43
- await Promise.allSettled(promises)
44
-
45
- if (queue.length) setTimeout(processQueue, 100)
46
- }
47
-
48
- /**
49
- * @param {string} filePath - relative/absolute path of the image file
50
- */
51
- export const imageSize = async (filePath) =>
52
- new Promise<ISizeCalculationResult>((resolve, reject) => {
53
- queue.push({ filePath, resolve, reject })
54
- processQueue()
55
- })
@@ -1,2 +0,0 @@
1
- export { types } from './types'
2
- export { lookup as imageSize, disableTypes } from './lookup'
@@ -1,37 +0,0 @@
1
- import { typeHandlers } from './types/index'
2
- import { detector } from './detector'
3
-
4
- const globalOptions = {
5
- disabledTypes: [],
6
- }
7
-
8
- /**
9
- * Return size information based on an Uint8Array
10
- *
11
- * @param {Uint8Array} input
12
- * @returns {ISizeCalculationResult}
13
- */
14
- export function lookup(input) {
15
- // detect the file type... don't rely on the extension
16
- const type = detector(input)
17
-
18
- if (typeof type !== 'undefined') {
19
- if (globalOptions.disabledTypes.indexOf(type) > -1) {
20
- throw new TypeError('disabled file type: ' + type)
21
- }
22
-
23
- // find an appropriate handler for this file type
24
- const size = typeHandlers.get(type).calculate(input)
25
- if (size !== undefined) {
26
- size.type = size.type ?? type
27
- return size
28
- }
29
- }
30
-
31
- // throw up, if we don't understand the file
32
- throw new TypeError('unsupported file type: ' + type)
33
- }
34
-
35
- export const disableTypes = (types) => {
36
- globalOptions.disabledTypes = types
37
- }
@@ -1,10 +0,0 @@
1
- import { toUTF8String, readInt32LE, readUInt32LE } from './utils'
2
-
3
- export const BMP = {
4
- validate: (input) => toUTF8String(input, 0, 2) === 'BM',
5
-
6
- calculate: (input) => ({
7
- height: Math.abs(readInt32LE(input, 22)),
8
- width: readUInt32LE(input, 18),
9
- }),
10
- }
@@ -1,16 +0,0 @@
1
- import { ICO } from './ico'
2
- import { readUInt16LE } from './utils'
3
-
4
- const TYPE_CURSOR = 2
5
- export const CUR = {
6
- validate(input) {
7
- const reserved = readUInt16LE(input, 0)
8
- const imageCount = readUInt16LE(input, 4)
9
- if (reserved !== 0 || imageCount === 0) return false
10
-
11
- const imageType = readUInt16LE(input, 2)
12
- return imageType === TYPE_CURSOR
13
- },
14
-
15
- calculate: (input) => ICO.calculate(input),
16
- }
@@ -1,10 +0,0 @@
1
- import { readUInt32LE } from './utils'
2
-
3
- export const DDS = {
4
- validate: (input) => readUInt32LE(input, 0) === 0x20534444,
5
-
6
- calculate: (input) => ({
7
- height: readUInt32LE(input, 12),
8
- width: readUInt32LE(input, 16),
9
- }),
10
- }
@@ -1,11 +0,0 @@
1
- import { toUTF8String, readUInt16LE } from './utils'
2
-
3
- const gifRegexp = /^GIF8[79]a/
4
- export const GIF = {
5
- validate: (input) => gifRegexp.test(toUTF8String(input, 0, 6)),
6
-
7
- calculate: (input) => ({
8
- height: readUInt16LE(input, 8),
9
- width: readUInt16LE(input, 6),
10
- }),
11
- }
@@ -1,35 +0,0 @@
1
- import { findBox, readUInt32BE, toUTF8String } from './utils'
2
-
3
- const brandMap = {
4
- avif: 'avif',
5
- mif1: 'heif',
6
- msf1: 'heif', // hief-sequence
7
- heic: 'heic',
8
- heix: 'heic',
9
- hevc: 'heic', // heic-sequence
10
- hevx: 'heic', // heic-sequence
11
- }
12
-
13
- export const HEIF = {
14
- validate(buffer) {
15
- const ftype = toUTF8String(buffer, 4, 8)
16
- const brand = toUTF8String(buffer, 8, 12)
17
- return 'ftyp' === ftype && brand in brandMap
18
- },
19
-
20
- calculate(buffer) {
21
- // Based on https://nokiatech.github.io/heif/technical.html
22
- const metaBox = findBox(buffer, 'meta', 0)
23
- const iprpBox = metaBox && findBox(buffer, 'iprp', metaBox.offset + 12)
24
- const ipcoBox = iprpBox && findBox(buffer, 'ipco', iprpBox.offset + 8)
25
- const ispeBox = ipcoBox && findBox(buffer, 'ispe', ipcoBox.offset + 8)
26
- if (ispeBox) {
27
- return {
28
- height: readUInt32BE(buffer, ispeBox.offset + 16),
29
- width: readUInt32BE(buffer, ispeBox.offset + 12),
30
- type: toUTF8String(buffer, 8, 12),
31
- }
32
- }
33
- throw new TypeError('Invalid HEIF, no size found')
34
- }
35
- }
@@ -1,112 +0,0 @@
1
- import { toUTF8String, readUInt32BE } from './utils'
2
-
3
- /**
4
- * ICNS Header
5
- *
6
- * | Offset | Size | Purpose |
7
- * | 0 | 4 | Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73) |
8
- * | 4 | 4 | Length of file, in bytes, msb first. |
9
- *
10
- */
11
- const SIZE_HEADER = 4 + 4 // 8
12
- const FILE_LENGTH_OFFSET = 4 // MSB => BIG ENDIAN
13
-
14
- /**
15
- * Image Entry
16
- *
17
- * | Offset | Size | Purpose |
18
- * | 0 | 4 | Icon type, see OSType below. |
19
- * | 4 | 4 | Length of data, in bytes (including type and length), msb first. |
20
- * | 8 | n | Icon data |
21
- */
22
- const ENTRY_LENGTH_OFFSET = 4 // MSB => BIG ENDIAN
23
-
24
- const ICON_TYPE_SIZE = {
25
- ICON: 32,
26
- 'ICN#': 32,
27
- // m => 16 x 16
28
- 'icm#': 16,
29
- icm4: 16,
30
- icm8: 16,
31
- // s => 16 x 16
32
- 'ics#': 16,
33
- ics4: 16,
34
- ics8: 16,
35
- is32: 16,
36
- s8mk: 16,
37
- icp4: 16,
38
- // l => 32 x 32
39
- icl4: 32,
40
- icl8: 32,
41
- il32: 32,
42
- l8mk: 32,
43
- icp5: 32,
44
- ic11: 32,
45
- // h => 48 x 48
46
- ich4: 48,
47
- ich8: 48,
48
- ih32: 48,
49
- h8mk: 48,
50
- // . => 64 x 64
51
- icp6: 64,
52
- ic12: 32,
53
- // t => 128 x 128
54
- it32: 128,
55
- t8mk: 128,
56
- ic07: 128,
57
- // . => 256 x 256
58
- ic08: 256,
59
- ic13: 256,
60
- // . => 512 x 512
61
- ic09: 512,
62
- ic14: 512,
63
- // . => 1024 x 1024
64
- ic10: 1024,
65
- }
66
-
67
- function readImageHeader(
68
- input,
69
- imageOffset,
70
- ) {
71
- const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET
72
- return [
73
- toUTF8String(input, imageOffset, imageLengthOffset),
74
- readUInt32BE(input, imageLengthOffset),
75
- ]
76
- }
77
-
78
- function getImageSize(type) {
79
- const size = ICON_TYPE_SIZE[type]
80
- return { width: size, height: size, type }
81
- }
82
-
83
- export const ICNS = {
84
- validate: (input) => toUTF8String(input, 0, 4) === 'icns',
85
-
86
- calculate(input) {
87
- const inputLength = input.length
88
- const fileLength = readUInt32BE(input, FILE_LENGTH_OFFSET)
89
- let imageOffset = SIZE_HEADER
90
-
91
- let imageHeader = readImageHeader(input, imageOffset)
92
- let imageSize = getImageSize(imageHeader[0])
93
- imageOffset += imageHeader[1]
94
-
95
- if (imageOffset === fileLength) return imageSize
96
-
97
- const result = {
98
- height: imageSize.height,
99
- images: [imageSize],
100
- width: imageSize.width,
101
- }
102
-
103
- while (imageOffset < fileLength && imageOffset < inputLength) {
104
- imageHeader = readImageHeader(input, imageOffset)
105
- imageSize = getImageSize(imageHeader[0])
106
- imageOffset += imageHeader[1]
107
- result.images.push(imageSize)
108
- }
109
-
110
- return result
111
- },
112
- }