@mapcatch/util 1.0.9 → 1.0.10-a
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/CHANGELOG.md +8 -1
- package/dist/catchUtil.min.esm.js +9906 -10852
- package/dist/catchUtil.min.js +25 -27
- package/package.json +1 -2
- package/src/constants/bmap_types.js +2 -2
- package/src/constants/crs_types.js +22 -0
- package/src/constants/default_layers.js +9 -9
- package/src/constants/index.js +3 -2
- package/src/constants/layer_folders.js +4 -4
- package/src/constants/measurement_fields.js +198 -0
- package/src/gl-operations/shaders/fragment/convertDem.js +2 -2
- package/src/gl-operations/shaders/fragment/convolutionSmooth.js +2 -2
- package/src/gl-operations/shaders/fragment/diffCalc.js +2 -2
- package/src/gl-operations/shaders/fragment/drawResult.js +2 -2
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvAmbientShadows.js +2 -2
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalBaselayer.js +2 -2
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvNormals.js +2 -2
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvSoftShadows.js +2 -2
- package/src/gl-operations/shaders/fragment/interpolateColor.js +2 -2
- package/src/gl-operations/shaders/fragment/interpolateColorOnly.js +2 -2
- package/src/gl-operations/shaders/fragment/interpolateValue.js +2 -2
- package/src/gl-operations/shaders/fragment/multiAnalyze1Calc.js +2 -2
- package/src/gl-operations/shaders/fragment/multiAnalyze2Calc.js +2 -2
- package/src/gl-operations/shaders/fragment/multiAnalyze3Calc.js +2 -2
- package/src/gl-operations/shaders/fragment/multiAnalyze4Calc.js +2 -2
- package/src/gl-operations/shaders/fragment/multiAnalyze5Calc.js +2 -2
- package/src/gl-operations/shaders/fragment/multiAnalyze6Calc.js +2 -2
- package/src/gl-operations/shaders/vertex/double.js +2 -2
- package/src/gl-operations/shaders/vertex/multi3.js +2 -2
- package/src/gl-operations/shaders/vertex/multi4.js +2 -2
- package/src/gl-operations/shaders/vertex/multi5.js +2 -2
- package/src/gl-operations/shaders/vertex/multi6.js +2 -2
- package/src/gl-operations/shaders/vertex/singleNotTransformed.js +2 -2
- package/src/index.js +0 -2
- package/src/util.js +31 -51
- package/src/constants/map_view_mode.js +0 -10
- package/src/exif/exif.js +0 -37
- package/src/exif/gps_tags.js +0 -33
- package/src/exif/ifd1_tags.js +0 -22
- package/src/exif/index.js +0 -33
- package/src/exif/iptc_field_map.js +0 -12
- package/src/exif/parse_image.js +0 -445
- package/src/exif/string_values.js +0 -137
- package/src/exif/tags.js +0 -75
- package/src/exif/tiff_tags.js +0 -35
- package/src/exif/util.js +0 -108
- package/src/image-size/detector.js +0 -24
- package/src/image-size/fromFile.js +0 -55
- package/src/image-size/index.js +0 -2
- package/src/image-size/lookup.js +0 -37
- package/src/image-size/types/bmp.js +0 -10
- package/src/image-size/types/cur.js +0 -16
- package/src/image-size/types/dds.js +0 -10
- package/src/image-size/types/gif.js +0 -11
- package/src/image-size/types/heif.js +0 -35
- package/src/image-size/types/icns.js +0 -112
- package/src/image-size/types/ico.js +0 -74
- package/src/image-size/types/index.js +0 -43
- package/src/image-size/types/j2c.js +0 -11
- package/src/image-size/types/jp2.js +0 -22
- package/src/image-size/types/jpg.js +0 -157
- package/src/image-size/types/ktx.js +0 -18
- package/src/image-size/types/png.js +0 -36
- package/src/image-size/types/pnm.js +0 -74
- package/src/image-size/types/psd.js +0 -10
- package/src/image-size/types/svg.js +0 -100
- package/src/image-size/types/tga.js +0 -14
- package/src/image-size/types/tiff.js +0 -92
- package/src/image-size/types/utils.js +0 -83
- package/src/image-size/types/webp.js +0 -67
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { readUInt16LE } from './utils'
|
|
2
|
-
|
|
3
|
-
const TYPE_ICON = 1
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ICON Header
|
|
7
|
-
*
|
|
8
|
-
* | Offset | Size | Purpose |
|
|
9
|
-
* | 0 | 2 | Reserved. Must always be 0. |
|
|
10
|
-
* | 2 | 2 | Image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid. |
|
|
11
|
-
* | 4 | 2 | Number of images in the file. |
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
const SIZE_HEADER = 2 + 2 + 2 // 6
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Image Entry
|
|
18
|
-
*
|
|
19
|
-
* | Offset | Size | Purpose |
|
|
20
|
-
* | 0 | 1 | Image width in pixels. Can be any number between 0 and 255. Value 0 means width is 256 pixels. |
|
|
21
|
-
* | 1 | 1 | Image height in pixels. Can be any number between 0 and 255. Value 0 means height is 256 pixels. |
|
|
22
|
-
* | 2 | 1 | Number of colors in the color palette. Should be 0 if the image does not use a color palette. |
|
|
23
|
-
* | 3 | 1 | Reserved. Should be 0. |
|
|
24
|
-
* | 4 | 2 | ICO format: Color planes. Should be 0 or 1. |
|
|
25
|
-
* | | | CUR format: The horizontal coordinates of the hotspot in number of pixels from the left. |
|
|
26
|
-
* | 6 | 2 | ICO format: Bits per pixel. |
|
|
27
|
-
* | | | CUR format: The vertical coordinates of the hotspot in number of pixels from the top. |
|
|
28
|
-
* | 8 | 4 | The size of the image's data in bytes |
|
|
29
|
-
* | 12 | 4 | The offset of BMP or PNG data from the beginning of the ICO/CUR file |
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
const SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4 // 16
|
|
33
|
-
|
|
34
|
-
function getSizeFromOffset(input, offset) {
|
|
35
|
-
const value = input[offset]
|
|
36
|
-
return value === 0 ? 256 : value
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getImageSize(input, imageIndex) {
|
|
40
|
-
const offset = SIZE_HEADER + imageIndex * SIZE_IMAGE_ENTRY
|
|
41
|
-
return {
|
|
42
|
-
height: getSizeFromOffset(input, offset + 1),
|
|
43
|
-
width: getSizeFromOffset(input, offset),
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const ICO = {
|
|
48
|
-
validate(input) {
|
|
49
|
-
const reserved = readUInt16LE(input, 0)
|
|
50
|
-
const imageCount = readUInt16LE(input, 4)
|
|
51
|
-
if (reserved !== 0 || imageCount === 0) return false
|
|
52
|
-
|
|
53
|
-
const imageType = readUInt16LE(input, 2)
|
|
54
|
-
return imageType === TYPE_ICON
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
calculate(input) {
|
|
58
|
-
const nbImages = readUInt16LE(input, 4)
|
|
59
|
-
const imageSize = getImageSize(input, 0)
|
|
60
|
-
|
|
61
|
-
if (nbImages === 1) return imageSize
|
|
62
|
-
|
|
63
|
-
const imgs = [imageSize]
|
|
64
|
-
for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) {
|
|
65
|
-
imgs.push(getImageSize(input, imageIndex))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
height: imageSize.height,
|
|
70
|
-
images: imgs,
|
|
71
|
-
width: imageSize.width,
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// load all available handlers explicitely for browserify support
|
|
2
|
-
import { BMP } from './bmp'
|
|
3
|
-
import { CUR } from './cur'
|
|
4
|
-
import { DDS } from './dds'
|
|
5
|
-
import { GIF } from './gif'
|
|
6
|
-
import { HEIF } from './heif'
|
|
7
|
-
import { ICNS } from './icns'
|
|
8
|
-
import { ICO } from './ico'
|
|
9
|
-
import { J2C } from './j2c'
|
|
10
|
-
import { JP2 } from './jp2'
|
|
11
|
-
import { JPG } from './jpg'
|
|
12
|
-
import { KTX } from './ktx'
|
|
13
|
-
import { PNG } from './png'
|
|
14
|
-
import { PNM } from './pnm'
|
|
15
|
-
import { PSD } from './psd'
|
|
16
|
-
import { SVG } from './svg'
|
|
17
|
-
import { TGA } from './tga'
|
|
18
|
-
import { TIFF } from './tiff'
|
|
19
|
-
import { WEBP } from './webp'
|
|
20
|
-
|
|
21
|
-
export const typeHandlers = new Map([
|
|
22
|
-
['bmp', BMP],
|
|
23
|
-
['cur', CUR],
|
|
24
|
-
['dds', DDS],
|
|
25
|
-
['gif', GIF],
|
|
26
|
-
['heif', HEIF],
|
|
27
|
-
['icns', ICNS],
|
|
28
|
-
['ico', ICO],
|
|
29
|
-
['j2c', J2C],
|
|
30
|
-
['jp2', JP2],
|
|
31
|
-
['jpg', JPG],
|
|
32
|
-
['ktx', KTX],
|
|
33
|
-
['png', PNG],
|
|
34
|
-
['pnm', PNM],
|
|
35
|
-
['psd', PSD],
|
|
36
|
-
['svg', SVG],
|
|
37
|
-
['tga', TGA],
|
|
38
|
-
['tiff', TIFF],
|
|
39
|
-
['webp', WEBP],
|
|
40
|
-
])
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export const types = Array.from(typeHandlers.keys())
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { toHexString, readUInt32BE } from './utils'
|
|
2
|
-
|
|
3
|
-
export const J2C = {
|
|
4
|
-
// TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC
|
|
5
|
-
validate: (input) => toHexString(input, 0, 4) === 'ff4fff51',
|
|
6
|
-
|
|
7
|
-
calculate: (input) => ({
|
|
8
|
-
height: readUInt32BE(input, 12),
|
|
9
|
-
width: readUInt32BE(input, 8),
|
|
10
|
-
}),
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { readUInt32BE, findBox } from './utils'
|
|
2
|
-
|
|
3
|
-
export const JP2 = {
|
|
4
|
-
validate(input) {
|
|
5
|
-
if (readUInt32BE(input, 4) !== 0x6a502020 || readUInt32BE(input, 0) < 1) return false
|
|
6
|
-
const ftypBox = findBox(input, 'ftyp', 0)
|
|
7
|
-
if (!ftypBox) return false
|
|
8
|
-
return readUInt32BE(input, ftypBox.offset + 4) === 0x66747970
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
calculate(input) {
|
|
12
|
-
const jp2hBox = findBox(input, 'jp2h', 0)
|
|
13
|
-
const ihdrBox = jp2hBox && findBox(input, 'ihdr', jp2hBox.offset + 8)
|
|
14
|
-
if (ihdrBox) {
|
|
15
|
-
return {
|
|
16
|
-
height: readUInt32BE(input, ihdrBox.offset + 8),
|
|
17
|
-
width: readUInt32BE(input, ihdrBox.offset + 12),
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
throw new TypeError('Unsupported JPEG 2000 format')
|
|
21
|
-
},
|
|
22
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// NOTE: we only support baseline and progressive JPGs here
|
|
2
|
-
// due to the structure of the loader class, we only get a buffer
|
|
3
|
-
// with a maximum size of 4096 bytes. so if the SOF marker is outside
|
|
4
|
-
// if this range we can't detect the file size correctly.
|
|
5
|
-
import { readUInt, readUInt16BE, toHexString } from './utils'
|
|
6
|
-
|
|
7
|
-
const EXIF_MARKER = '45786966'
|
|
8
|
-
const APP1_DATA_SIZE_BYTES = 2
|
|
9
|
-
const EXIF_HEADER_BYTES = 6
|
|
10
|
-
const TIFF_BYTE_ALIGN_BYTES = 2
|
|
11
|
-
const BIG_ENDIAN_BYTE_ALIGN = '4d4d'
|
|
12
|
-
const LITTLE_ENDIAN_BYTE_ALIGN = '4949'
|
|
13
|
-
|
|
14
|
-
// Each entry is exactly 12 bytes
|
|
15
|
-
const IDF_ENTRY_BYTES = 12
|
|
16
|
-
const NUM_DIRECTORY_ENTRIES_BYTES = 2
|
|
17
|
-
|
|
18
|
-
function isEXIF(input) {
|
|
19
|
-
return toHexString(input, 2, 6) === EXIF_MARKER
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function extractSize(input, index) {
|
|
23
|
-
return {
|
|
24
|
-
height: readUInt16BE(input, index),
|
|
25
|
-
width: readUInt16BE(input, index + 2),
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function extractOrientation(exifBlock, isBigEndian) {
|
|
30
|
-
// TODO: assert that this contains 0x002A
|
|
31
|
-
// let STATIC_MOTOROLA_TIFF_HEADER_BYTES = 2
|
|
32
|
-
// let TIFF_IMAGE_FILE_DIRECTORY_BYTES = 4
|
|
33
|
-
|
|
34
|
-
// TODO: derive from TIFF_IMAGE_FILE_DIRECTORY_BYTES
|
|
35
|
-
const idfOffset = 8
|
|
36
|
-
|
|
37
|
-
// IDF osset works from right after the header bytes
|
|
38
|
-
// (so the offset includes the tiff byte align)
|
|
39
|
-
const offset = EXIF_HEADER_BYTES + idfOffset
|
|
40
|
-
|
|
41
|
-
const idfDirectoryEntries = readUInt(exifBlock, 16, offset, isBigEndian)
|
|
42
|
-
|
|
43
|
-
for (
|
|
44
|
-
let directoryEntryNumber = 0;
|
|
45
|
-
directoryEntryNumber < idfDirectoryEntries;
|
|
46
|
-
directoryEntryNumber++
|
|
47
|
-
) {
|
|
48
|
-
const start =
|
|
49
|
-
offset +
|
|
50
|
-
NUM_DIRECTORY_ENTRIES_BYTES +
|
|
51
|
-
directoryEntryNumber * IDF_ENTRY_BYTES
|
|
52
|
-
const end = start + IDF_ENTRY_BYTES
|
|
53
|
-
|
|
54
|
-
// Skip on corrupt EXIF blocks
|
|
55
|
-
if (start > exifBlock.length) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const block = exifBlock.slice(start, end)
|
|
60
|
-
const tagNumber = readUInt(block, 16, 0, isBigEndian)
|
|
61
|
-
|
|
62
|
-
// 0x0112 (decimal: 274) is the `orientation` tag ID
|
|
63
|
-
if (tagNumber === 274) {
|
|
64
|
-
const dataFormat = readUInt(block, 16, 2, isBigEndian)
|
|
65
|
-
if (dataFormat !== 3) {
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// unsinged int has 2 bytes per component
|
|
70
|
-
// if there would more than 4 bytes in total it's a pointer
|
|
71
|
-
const numberOfComponents = readUInt(block, 32, 4, isBigEndian)
|
|
72
|
-
if (numberOfComponents !== 1) {
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return readUInt(block, 16, 8, isBigEndian)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function validateExifBlock(input, index) {
|
|
82
|
-
// Skip APP1 Data Size
|
|
83
|
-
const exifBlock = input.slice(APP1_DATA_SIZE_BYTES, index)
|
|
84
|
-
|
|
85
|
-
// Consider byte alignment
|
|
86
|
-
const byteAlign = toHexString(
|
|
87
|
-
exifBlock,
|
|
88
|
-
EXIF_HEADER_BYTES,
|
|
89
|
-
EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
// Ignore Empty EXIF. Validate byte alignment
|
|
93
|
-
const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN
|
|
94
|
-
const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN
|
|
95
|
-
|
|
96
|
-
if (isBigEndian || isLittleEndian) {
|
|
97
|
-
return extractOrientation(exifBlock, isBigEndian)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function validateInput(input, index) {
|
|
102
|
-
// index should be within buffer limits
|
|
103
|
-
if (index > input.length) {
|
|
104
|
-
throw new TypeError('Corrupt JPG, exceeded buffer limits')
|
|
105
|
-
}
|
|
106
|
-
// Every JPEG block must begin with a 0xFF
|
|
107
|
-
if (input[index] !== 0xff) {
|
|
108
|
-
throw new TypeError('Invalid JPG, marker table corrupted')
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export const JPG = {
|
|
113
|
-
validate: (input) => toHexString(input, 0, 2) === 'ffd8',
|
|
114
|
-
|
|
115
|
-
calculate(input) {
|
|
116
|
-
// Skip 4 chars, they are for signature
|
|
117
|
-
input = input.slice(4)
|
|
118
|
-
|
|
119
|
-
let orientation
|
|
120
|
-
let next
|
|
121
|
-
while (input.length) {
|
|
122
|
-
// read length of the next block
|
|
123
|
-
const i = readUInt16BE(input, 0)
|
|
124
|
-
|
|
125
|
-
if (isEXIF(input)) {
|
|
126
|
-
orientation = validateExifBlock(input, i)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// ensure correct format
|
|
130
|
-
validateInput(input, i)
|
|
131
|
-
|
|
132
|
-
// 0xFFC0 is baseline standard(SOF)
|
|
133
|
-
// 0xFFC1 is baseline optimized(SOF)
|
|
134
|
-
// 0xFFC2 is progressive(SOF2)
|
|
135
|
-
next = input[i + 1]
|
|
136
|
-
if (next === 0xc0 || next === 0xc1 || next === 0xc2) {
|
|
137
|
-
const size = extractSize(input, i + 5)
|
|
138
|
-
|
|
139
|
-
// TODO: is orientation=0 a valid answer here?
|
|
140
|
-
if (!orientation) {
|
|
141
|
-
return size
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
height: size.height,
|
|
146
|
-
orientation,
|
|
147
|
-
width: size.width,
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// move to the next block
|
|
152
|
-
input = input.slice(i + 2)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
throw new TypeError('Invalid JPG, no size found')
|
|
156
|
-
},
|
|
157
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { toUTF8String, readUInt32LE } from './utils'
|
|
2
|
-
|
|
3
|
-
export const KTX = {
|
|
4
|
-
validate: (input) => {
|
|
5
|
-
const signature = toUTF8String(input, 1, 7)
|
|
6
|
-
return ['KTX 11', 'KTX 20'].includes(signature)
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
calculate: (input) => {
|
|
10
|
-
const type = input[5] === 0x31 ? 'ktx' : 'ktx2'
|
|
11
|
-
const offset = type === 'ktx' ? 36 : 20
|
|
12
|
-
return ({
|
|
13
|
-
height: readUInt32LE(input, offset + 4),
|
|
14
|
-
width: readUInt32LE(input, offset),
|
|
15
|
-
type,
|
|
16
|
-
})
|
|
17
|
-
},
|
|
18
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { toUTF8String, readUInt32BE } from './utils'
|
|
2
|
-
|
|
3
|
-
const pngSignature = 'PNG\r\n\x1a\n'
|
|
4
|
-
const pngImageHeaderChunkName = 'IHDR'
|
|
5
|
-
|
|
6
|
-
// Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
|
|
7
|
-
const pngFriedChunkName = 'CgBI'
|
|
8
|
-
|
|
9
|
-
export const PNG = {
|
|
10
|
-
validate(input) {
|
|
11
|
-
if (pngSignature === toUTF8String(input, 1, 8)) {
|
|
12
|
-
let chunkName = toUTF8String(input, 12, 16)
|
|
13
|
-
if (chunkName === pngFriedChunkName) {
|
|
14
|
-
chunkName = toUTF8String(input, 28, 32)
|
|
15
|
-
}
|
|
16
|
-
if (chunkName !== pngImageHeaderChunkName) {
|
|
17
|
-
throw new TypeError('Invalid PNG')
|
|
18
|
-
}
|
|
19
|
-
return true
|
|
20
|
-
}
|
|
21
|
-
return false
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
calculate(input) {
|
|
25
|
-
if (toUTF8String(input, 12, 16) === pngFriedChunkName) {
|
|
26
|
-
return {
|
|
27
|
-
height: readUInt32BE(input, 36),
|
|
28
|
-
width: readUInt32BE(input, 32),
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
height: readUInt32BE(input, 20),
|
|
33
|
-
width: readUInt32BE(input, 16),
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { toUTF8String } from './utils'
|
|
2
|
-
|
|
3
|
-
const PNMTypes = {
|
|
4
|
-
P1: 'pbm/ascii',
|
|
5
|
-
P2: 'pgm/ascii',
|
|
6
|
-
P3: 'ppm/ascii',
|
|
7
|
-
P4: 'pbm',
|
|
8
|
-
P5: 'pgm',
|
|
9
|
-
P6: 'ppm',
|
|
10
|
-
P7: 'pam',
|
|
11
|
-
PF: 'pfm',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const handlers = {
|
|
15
|
-
default: (lines) => {
|
|
16
|
-
let dimensions = []
|
|
17
|
-
|
|
18
|
-
while (lines.length > 0) {
|
|
19
|
-
const line = lines.shift()
|
|
20
|
-
if (line[0] === '#') {
|
|
21
|
-
continue
|
|
22
|
-
}
|
|
23
|
-
dimensions = line.split(' ')
|
|
24
|
-
break
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (dimensions.length === 2) {
|
|
28
|
-
return {
|
|
29
|
-
height: parseInt(dimensions[1], 10),
|
|
30
|
-
width: parseInt(dimensions[0], 10),
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
throw new TypeError('Invalid PNM')
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
pam: (lines) => {
|
|
37
|
-
const size = {}
|
|
38
|
-
while (lines.length > 0) {
|
|
39
|
-
const line = lines.shift()
|
|
40
|
-
if (line.length > 16 || line.charCodeAt(0) > 128) {
|
|
41
|
-
continue
|
|
42
|
-
}
|
|
43
|
-
const [key, value] = line.split(' ')
|
|
44
|
-
if (key && value) {
|
|
45
|
-
size[key.toLowerCase()] = parseInt(value, 10)
|
|
46
|
-
}
|
|
47
|
-
if (size.height && size.width) {
|
|
48
|
-
break
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (size.height && size.width) {
|
|
53
|
-
return {
|
|
54
|
-
height: size.height,
|
|
55
|
-
width: size.width,
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
throw new TypeError('Invalid PAM')
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const PNM = {
|
|
64
|
-
validate: (input) => toUTF8String(input, 0, 2) in PNMTypes,
|
|
65
|
-
|
|
66
|
-
calculate(input) {
|
|
67
|
-
const signature = toUTF8String(input, 0, 2)
|
|
68
|
-
const type = PNMTypes[signature]
|
|
69
|
-
// TODO: this probably generates garbage. move to a stream based parser
|
|
70
|
-
const lines = toUTF8String(input, 3).split(/[\r\n]+/)
|
|
71
|
-
const handler = handlers[type] || handlers.default
|
|
72
|
-
return handler(lines)
|
|
73
|
-
},
|
|
74
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { toUTF8String } from './utils'
|
|
2
|
-
|
|
3
|
-
const svgReg = /<svg\s([^>"']|"[^"]*"|'[^']*')*>/
|
|
4
|
-
|
|
5
|
-
const extractorRegExps = {
|
|
6
|
-
height: /\sheight=(['"])([^%]+?)\1/,
|
|
7
|
-
root: svgReg,
|
|
8
|
-
viewbox: /\sviewBox=(['"])(.+?)\1/i,
|
|
9
|
-
width: /\swidth=(['"])([^%]+?)\1/,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const INCH_CM = 2.54
|
|
13
|
-
const units = {
|
|
14
|
-
in: 96,
|
|
15
|
-
cm: 96 / INCH_CM,
|
|
16
|
-
em: 16,
|
|
17
|
-
ex: 8,
|
|
18
|
-
m: (96 / INCH_CM) * 100,
|
|
19
|
-
mm: 96 / INCH_CM / 10,
|
|
20
|
-
pc: 96 / 72 / 12,
|
|
21
|
-
pt: 96 / 72,
|
|
22
|
-
px: 1,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const unitsReg = new RegExp(
|
|
26
|
-
`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join('|')})?$`,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
function parseLength(len) {
|
|
30
|
-
const m = unitsReg.exec(len)
|
|
31
|
-
if (!m) {
|
|
32
|
-
return undefined
|
|
33
|
-
}
|
|
34
|
-
return Math.round(Number(m[1]) * (units[m[2]] || 1))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function parseViewbox(viewbox) {
|
|
38
|
-
const bounds = viewbox.split(' ')
|
|
39
|
-
return {
|
|
40
|
-
height: parseLength(bounds[3]),
|
|
41
|
-
width: parseLength(bounds[2]),
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function parseAttributes(root) {
|
|
46
|
-
const width = root.match(extractorRegExps.width)
|
|
47
|
-
const height = root.match(extractorRegExps.height)
|
|
48
|
-
const viewbox = root.match(extractorRegExps.viewbox)
|
|
49
|
-
return {
|
|
50
|
-
height: height && (parseLength(height[2])),
|
|
51
|
-
viewbox: viewbox && (parseViewbox(viewbox[2])),
|
|
52
|
-
width: width && (parseLength(width[2])),
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function calculateByDimensions(attrs) {
|
|
57
|
-
return {
|
|
58
|
-
height: attrs.height,
|
|
59
|
-
width: attrs.width,
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function calculateByViewbox(attrs, viewbox) {
|
|
64
|
-
const ratio = (viewbox.width) / (viewbox.height)
|
|
65
|
-
if (attrs.width) {
|
|
66
|
-
return {
|
|
67
|
-
height: Math.floor(attrs.width / ratio),
|
|
68
|
-
width: attrs.width,
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (attrs.height) {
|
|
72
|
-
return {
|
|
73
|
-
height: attrs.height,
|
|
74
|
-
width: Math.floor(attrs.height * ratio),
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
height: viewbox.height,
|
|
79
|
-
width: viewbox.width,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const SVG = {
|
|
84
|
-
// Scan only the first kilo-byte to speed up the check on larger files
|
|
85
|
-
validate: (input) => svgReg.test(toUTF8String(input, 0, 1000)),
|
|
86
|
-
|
|
87
|
-
calculate(input) {
|
|
88
|
-
const root = toUTF8String(input).match(extractorRegExps.root)
|
|
89
|
-
if (root) {
|
|
90
|
-
const attrs = parseAttributes(root[0])
|
|
91
|
-
if (attrs.width && attrs.height) {
|
|
92
|
-
return calculateByDimensions(attrs)
|
|
93
|
-
}
|
|
94
|
-
if (attrs.viewbox) {
|
|
95
|
-
return calculateByViewbox(attrs, attrs.viewbox)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
throw new TypeError('Invalid SVG')
|
|
99
|
-
},
|
|
100
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { readUInt16LE } from './utils'
|
|
2
|
-
|
|
3
|
-
export const TGA = {
|
|
4
|
-
validate(input) {
|
|
5
|
-
return readUInt16LE(input, 0) === 0 && readUInt16LE(input, 4) === 0
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
calculate(input) {
|
|
9
|
-
return {
|
|
10
|
-
height: readUInt16LE(input, 14),
|
|
11
|
-
width: readUInt16LE(input, 12),
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// based on http://www.compix.com/fileformattif.htm
|
|
2
|
-
// TO-DO: support big-endian as well
|
|
3
|
-
import { readUInt, toHexString, toUTF8String } from './utils'
|
|
4
|
-
|
|
5
|
-
// Read IFD (image-file-directory) into a buffer
|
|
6
|
-
function readIFD(input, isBigEndian) {
|
|
7
|
-
const ifdOffset = readUInt(input, 32, 4, isBigEndian)
|
|
8
|
-
return input.slice(ifdOffset + 2)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// TIFF values seem to be messed up on Big-Endian, this helps
|
|
12
|
-
function readValue(input, isBigEndian) {
|
|
13
|
-
const low = readUInt(input, 16, 8, isBigEndian)
|
|
14
|
-
const high = readUInt(input, 16, 10, isBigEndian)
|
|
15
|
-
return (high << 16) + low
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// move to the next tag
|
|
19
|
-
function nextTag(input) {
|
|
20
|
-
if (input.length > 24) {
|
|
21
|
-
return input.slice(12)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Extract IFD tags from TIFF metadata
|
|
26
|
-
function extractTags(input, isBigEndian) {
|
|
27
|
-
const tags = {}
|
|
28
|
-
|
|
29
|
-
let temp = input
|
|
30
|
-
while (temp && temp.length) {
|
|
31
|
-
const code = readUInt(temp, 16, 0, isBigEndian)
|
|
32
|
-
const type = readUInt(temp, 16, 2, isBigEndian)
|
|
33
|
-
const length = readUInt(temp, 32, 4, isBigEndian)
|
|
34
|
-
|
|
35
|
-
// 0 means end of IFD
|
|
36
|
-
if (code === 0) {
|
|
37
|
-
break
|
|
38
|
-
} else {
|
|
39
|
-
// 256 is width, 257 is height
|
|
40
|
-
// if (code === 256 || code === 257) {
|
|
41
|
-
if (length === 1 && (type === 3 || type === 4)) {
|
|
42
|
-
tags[code] = readValue(temp, isBigEndian)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// move to the next tag
|
|
46
|
-
temp = nextTag(temp)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return tags
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Test if the TIFF is Big Endian or Little Endian
|
|
54
|
-
function determineEndianness(input) {
|
|
55
|
-
const signature = toUTF8String(input, 0, 2)
|
|
56
|
-
if ('II' === signature) {
|
|
57
|
-
return 'LE'
|
|
58
|
-
} else if ('MM' === signature) {
|
|
59
|
-
return 'BE'
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const signatures = [
|
|
64
|
-
// '492049', // currently not supported
|
|
65
|
-
'49492a00', // Little endian
|
|
66
|
-
'4d4d002a', // Big Endian
|
|
67
|
-
// '4d4d002a', // BigTIFF > 4GB. currently not supported
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
export const TIFF = {
|
|
71
|
-
validate: (input) => signatures.includes(toHexString(input, 0, 4)),
|
|
72
|
-
|
|
73
|
-
calculate(input) {
|
|
74
|
-
// Determine BE/LE
|
|
75
|
-
const isBigEndian = determineEndianness(input) === 'BE'
|
|
76
|
-
|
|
77
|
-
// read the IFD
|
|
78
|
-
const ifdBuffer = readIFD(input, isBigEndian)
|
|
79
|
-
|
|
80
|
-
// extract the tags from the IFD
|
|
81
|
-
const tags = extractTags(ifdBuffer, isBigEndian)
|
|
82
|
-
|
|
83
|
-
const width = tags[256]
|
|
84
|
-
const height = tags[257]
|
|
85
|
-
|
|
86
|
-
if (!width || !height) {
|
|
87
|
-
throw new TypeError('Invalid Tiff. Missing tags')
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return { height, width }
|
|
91
|
-
},
|
|
92
|
-
}
|