mirage2d 1.1.2 → 1.1.4
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/dist/MirageHttp.es.js +5268 -0
- package/dist/MirageHttp.es.js.map +1 -0
- package/dist/MirageHttp.umd.js +2 -0
- package/dist/MirageHttp.umd.js.map +1 -0
- package/dist/assets/js/basedecoder-fa2b8e8d.js +107 -0
- package/dist/assets/js/decoder-f19e05cf.js +6 -0
- package/dist/assets/js/deflate-adb9a67b.js +8 -0
- package/dist/{js/dist/_html2canvas@1.4.1@html2canvas.e8006fee.js → assets/js/html2canvas.esm-3dd231c5.js} +0 -0
- package/dist/assets/js/index-3263db85.js +1 -0
- package/dist/assets/js/index-a9db46a5.js +212968 -0
- package/dist/{js/lib/_canvg@3.0.10@canvg.bd557ac8.js → assets/js/index.es-38f73a27.js} +2179 -351
- package/dist/assets/js/jpeg-3bf23728.js +835 -0
- package/dist/{js/_lerc@3.0.0@lerc/_lerc@3.0.0@lerc.dc2ff398.js → assets/js/lerc-4c39f39b.js} +26 -1
- package/dist/assets/js/lzw-d0cad8af.js +123 -0
- package/dist/assets/js/packbits-d75b4cce.js +25 -0
- package/dist/{js/_pako@2.0.4@pako/_pako@2.0.4@pako.52d6b320.js → assets/js/pako.esm-49deb4d7.js} +0 -0
- package/dist/{js/dist/_dompurify@2.4.0@dompurify.e7ba523e.js → assets/js/purify.es-1915dfae.js} +0 -0
- package/dist/assets/js/raw-9656f9cc.js +7 -0
- package/dist/assets/js/webimage-edb7156c.js +27 -0
- package/package.json +1 -1
- package/dist/js/_@babel_runtime@7.18.9@@babel/_@babel_runtime@7.18.9@@babel.e0126ca2.js +0 -51
- package/dist/js/_@petamoriken_float16@3.6.6@@petamoriken/_@petamoriken_float16@3.6.6@@petamoriken.c5188241.js +0 -217
- package/dist/js/_@turf_along@6.5.0@@turf/_@turf_along@6.5.0@@turf.18dbc1a3.js +0 -31
- package/dist/js/_@turf_angle@6.5.0@@turf/_@turf_angle@6.5.0@@turf.554ac9bf.js +0 -1
- package/dist/js/_@turf_area@6.5.0@@turf/_@turf_area@6.5.0@@turf.6cbf0cc1.js +0 -74
- package/dist/js/_@turf_bbox-clip@6.5.0@@turf/_@turf_bbox-clip@6.5.0@@turf.e491cb90.js +0 -1
- package/dist/js/_@turf_bbox-polygon@6.5.0@@turf/_@turf_bbox-polygon@6.5.0@@turf.523f1c20.js +0 -19
- package/dist/js/_@turf_bbox@6.5.0@@turf/_@turf_bbox@6.5.0@@turf.4c59feee.js +0 -48
- package/dist/js/_@turf_bearing@6.5.0@@turf/_@turf_bearing@6.5.0@@turf.f2555a09.js +0 -25
- package/dist/js/_@turf_bezier-spline@6.5.0@@turf/_@turf_bezier-spline@6.5.0@@turf.fa7991dd.js +0 -137
- package/dist/js/_@turf_boolean-clockwise@6.5.0@@turf/_@turf_boolean-clockwise@6.5.0@@turf.4031f280.js +0 -1
- package/dist/js/_@turf_boolean-contains@6.5.0@@turf/_@turf_boolean-contains@6.5.0@@turf.836d55d8.js +0 -191
- package/dist/js/_@turf_boolean-crosses@6.5.0@@turf/_@turf_boolean-crosses@6.5.0@@turf.c5f65a28.js +0 -125
- package/dist/js/_@turf_boolean-disjoint@6.5.0@@turf/_@turf_boolean-disjoint@6.5.0@@turf.bbd60872.js +0 -122
- package/dist/js/_@turf_boolean-equal@6.5.0@@turf/_@turf_boolean-equal@6.5.0@@turf.341ffa01.js +0 -1
- package/dist/js/_@turf_boolean-intersects@6.5.0@@turf/_@turf_boolean-intersects@6.5.0@@turf.05fc28b3.js +0 -15
- package/dist/js/_@turf_boolean-overlap@6.5.0@@turf/_@turf_boolean-overlap@6.5.0@@turf.a519db25.js +0 -53
- package/dist/js/_@turf_boolean-parallel@6.5.0@@turf/_@turf_boolean-parallel@6.5.0@@turf.dbf2bc2d.js +0 -1
- package/dist/js/_@turf_boolean-point-in-polygon@6.5.0@@turf/_@turf_boolean-point-in-polygon@6.5.0@@turf.62a2d48a.js +0 -65
- package/dist/js/_@turf_boolean-point-on-line@6.5.0@@turf/_@turf_boolean-point-on-line@6.5.0@@turf.3cf3aaa1.js +0 -69
- package/dist/js/_@turf_boolean-within@6.5.0@@turf/_@turf_boolean-within@6.5.0@@turf.d70d6bfc.js +0 -172
- package/dist/js/_@turf_buffer@6.5.0@@turf/_@turf_buffer@6.5.0@@turf.88330dfe.js +0 -99
- package/dist/js/_@turf_center-mean@6.5.0@@turf/_@turf_center-mean@6.5.0@@turf.b3d7c917.js +0 -1
- package/dist/js/_@turf_center-median@6.5.0@@turf/_@turf_center-median@6.5.0@@turf.44c4669e.js +0 -1
- package/dist/js/_@turf_center-of-mass@6.5.0@@turf/_@turf_center-of-mass@6.5.0@@turf.63ce279e.js +0 -1
- package/dist/js/_@turf_center@6.5.0@@turf/_@turf_center@6.5.0@@turf.a45495b5.js +0 -12
- package/dist/js/_@turf_centroid@6.5.0@@turf/_@turf_centroid@6.5.0@@turf.0a5be869.js +0 -17
- package/dist/js/_@turf_circle@6.5.0@@turf/_@turf_circle@6.5.0@@turf.0166b8c2.js +0 -16
- package/dist/js/_@turf_clean-coords@6.5.0@@turf/_@turf_clean-coords@6.5.0@@turf.8c76bd63.js +0 -111
- package/dist/js/_@turf_clone@6.5.0@@turf/_@turf_clone@6.5.0@@turf.cd05b1f8.js +0 -100
- package/dist/js/_@turf_clusters-dbscan@6.5.0@@turf/_@turf_clusters-dbscan@6.5.0@@turf.6bbee7e9.js +0 -1
- package/dist/js/_@turf_clusters-kmeans@6.5.0@@turf/_@turf_clusters-kmeans@6.5.0@@turf.505415df.js +0 -1
- package/dist/js/_@turf_clusters@6.5.0@@turf/_@turf_clusters@6.5.0@@turf.84cb9680.js +0 -1
- package/dist/js/_@turf_collect@6.5.0@@turf/_@turf_collect@6.5.0@@turf.93e41b5f.js +0 -1
- package/dist/js/_@turf_combine@6.5.0@@turf/_@turf_combine@6.5.0@@turf.33ee6336.js +0 -1
- package/dist/js/_@turf_concave@6.5.0@@turf/_@turf_concave@6.5.0@@turf.6fb6a8be.js +0 -179
- package/dist/js/_@turf_convex@6.5.0@@turf/_@turf_convex@6.5.0@@turf.24600ac2.js +0 -1
- package/dist/js/_@turf_destination@6.5.0@@turf/_@turf_destination@6.5.0@@turf.2621651e.js +0 -18
- package/dist/js/_@turf_difference@6.5.0@@turf/_@turf_difference@6.5.0@@turf.70df5e79.js +0 -18
- package/dist/js/_@turf_dissolve@6.5.0@@turf/_@turf_dissolve@6.5.0@@turf.edb28fc1.js +0 -1
- package/dist/js/_@turf_distance-weight@6.5.0@@turf/_@turf_distance-weight@6.5.0@@turf.e168af7f.js +0 -1
- package/dist/js/_@turf_distance@6.5.0@@turf/_@turf_distance@6.5.0@@turf.0c7b8aea.js +0 -22
- package/dist/js/_@turf_ellipse@6.5.0@@turf/_@turf_ellipse@6.5.0@@turf.37986056.js +0 -1
- package/dist/js/_@turf_envelope@6.5.0@@turf/_@turf_envelope@6.5.0@@turf.599c5772.js +0 -1
- package/dist/js/_@turf_explode@6.5.0@@turf/_@turf_explode@6.5.0@@turf.5c768db5.js +0 -24
- package/dist/js/_@turf_flatten@6.5.0@@turf/_@turf_flatten@6.5.0@@turf.57e9114c.js +0 -1
- package/dist/js/_@turf_flip@6.5.0@@turf/_@turf_flip@6.5.0@@turf.1f02101f.js +0 -1
- package/dist/js/_@turf_great-circle@6.5.0@@turf/_@turf_great-circle@6.5.0@@turf.2ca021a8.js +0 -1
- package/dist/js/_@turf_helpers@6.5.0@@turf/_@turf_helpers@6.5.0@@turf.f1480aa1.js +0 -364
- package/dist/js/_@turf_hex-grid@6.5.0@@turf/_@turf_hex-grid@6.5.0@@turf.a6a45778.js +0 -99
- package/dist/js/_@turf_interpolate@6.5.0@@turf/_@turf_interpolate@6.5.0@@turf.4d39bd8c.js +0 -1
- package/dist/js/_@turf_intersect@6.5.0@@turf/_@turf_intersect@6.5.0@@turf.34082cdf.js +0 -17
- package/dist/js/_@turf_invariant@6.5.0@@turf/_@turf_invariant@6.5.0@@turf.0ef69f8c.js +0 -71
- package/dist/js/_@turf_isobands@6.5.0@@turf/_@turf_isobands@6.5.0@@turf.def019df.js +0 -3109
- package/dist/js/_@turf_isolines@6.5.0@@turf/_@turf_isolines@6.5.0@@turf.da623b25.js +0 -1
- package/dist/js/_@turf_kinks@6.5.0@@turf/_@turf_kinks@6.5.0@@turf.ee61685b.js +0 -87
- package/dist/js/_@turf_length@6.5.0@@turf/_@turf_length@6.5.0@@turf.f73f6c98.js +0 -12
- package/dist/js/_@turf_line-arc@6.5.0@@turf/_@turf_line-arc@6.5.0@@turf.3dc57055.js +0 -37
- package/dist/js/_@turf_line-chunk@6.5.0@@turf/_@turf_line-chunk@6.5.0@@turf.1867af48.js +0 -43
- package/dist/js/_@turf_line-intersect@6.5.0@@turf/_@turf_line-intersect@6.5.0@@turf.c4d81948.js +0 -73
- package/dist/js/_@turf_line-offset@6.5.0@@turf/_@turf_line-offset@6.5.0@@turf.e6846793.js +0 -116
- package/dist/js/_@turf_line-overlap@6.5.0@@turf/_@turf_line-overlap@6.5.0@@turf.addba9a5.js +0 -76
- package/dist/js/_@turf_line-segment@6.5.0@@turf/_@turf_line-segment@6.5.0@@turf.18ce3010.js +0 -55
- package/dist/js/_@turf_line-slice-along@6.5.0@@turf/_@turf_line-slice-along@6.5.0@@turf.2b802464.js +0 -57
- package/dist/js/_@turf_line-slice@6.5.0@@turf/_@turf_line-slice@6.5.0@@turf.6423a053.js +0 -23
- package/dist/js/_@turf_line-split@6.5.0@@turf/_@turf_line-split@6.5.0@@turf.2022f104.js +0 -125
- package/dist/js/_@turf_line-to-polygon@6.5.0@@turf/_@turf_line-to-polygon@6.5.0@@turf.83f5e69f.js +0 -1
- package/dist/js/_@turf_mask@6.5.0@@turf/_@turf_mask@6.5.0@@turf.96cd5a94.js +0 -1
- package/dist/js/_@turf_meta@6.5.0@@turf/_@turf_meta@6.5.0@@turf.1b9d5da5.js +0 -611
- package/dist/js/_@turf_midpoint@6.5.0@@turf/_@turf_midpoint@6.5.0@@turf.67c14f94.js +0 -1
- package/dist/js/_@turf_moran-index@6.5.0@@turf/_@turf_moran-index@6.5.0@@turf.2ad5365a.js +0 -1
- package/dist/js/_@turf_nearest-point-on-line@6.5.0@@turf/_@turf_nearest-point-on-line@6.5.0@@turf.095c8c0d.js +0 -57
- package/dist/js/_@turf_nearest-point-to-line@6.5.0@@turf/_@turf_nearest-point-to-line@6.5.0@@turf.68484097.js +0 -1
- package/dist/js/_@turf_nearest-point@6.5.0@@turf/_@turf_nearest-point@6.5.0@@turf.e0d2f509.js +0 -24
- package/dist/js/_@turf_planepoint@6.5.0@@turf/_@turf_planepoint@6.5.0@@turf.56fc70b3.js +0 -1
- package/dist/js/_@turf_point-grid@6.5.0@@turf/_@turf_point-grid@6.5.0@@turf.2d278644.js +0 -42
- package/dist/js/_@turf_point-on-feature@6.5.0@@turf/_@turf_point-on-feature@6.5.0@@turf.0c740874.js +0 -1
- package/dist/js/_@turf_point-to-line-distance@6.5.0@@turf/_@turf_point-to-line-distance@6.5.0@@turf.33105d82.js +0 -1
- package/dist/js/_@turf_points-within-polygon@6.5.0@@turf/_@turf_points-within-polygon@6.5.0@@turf.659cd335.js +0 -35
- package/dist/js/_@turf_polygon-smooth@6.5.0@@turf/_@turf_polygon-smooth@6.5.0@@turf.43a7c33e.js +0 -1
- package/dist/js/_@turf_polygon-tangents@6.5.0@@turf/_@turf_polygon-tangents@6.5.0@@turf.a2c3a7b6.js +0 -1
- package/dist/js/_@turf_polygon-to-line@6.5.0@@turf/_@turf_polygon-to-line@6.5.0@@turf.3177cfb1.js +0 -48
- package/dist/js/_@turf_polygonize@6.5.0@@turf/_@turf_polygonize@6.5.0@@turf.f7cc4910.js +0 -1
- package/dist/js/_@turf_projection@6.5.0@@turf/_@turf_projection@6.5.0@@turf.ffdd3321.js +0 -1
- package/dist/js/_@turf_random@6.5.0@@turf/_@turf_random@6.5.0@@turf.f65251e4.js +0 -130
- package/dist/js/_@turf_rectangle-grid@6.5.0@@turf/_@turf_rectangle-grid@6.5.0@@turf.7e8b1a1f.js +0 -49
- package/dist/js/_@turf_rewind@6.5.0@@turf/_@turf_rewind@6.5.0@@turf.5d137ee9.js +0 -1
- package/dist/js/_@turf_rhumb-bearing@6.5.0@@turf/_@turf_rhumb-bearing@6.5.0@@turf.fb8f6ade.js +0 -30
- package/dist/js/_@turf_rhumb-destination@6.5.0@@turf/_@turf_rhumb-destination@6.5.0@@turf.dc0e4753.js +0 -36
- package/dist/js/_@turf_rhumb-distance@6.5.0@@turf/_@turf_rhumb-distance@6.5.0@@turf.94e475b8.js +0 -30
- package/dist/js/_@turf_sample@6.5.0@@turf/_@turf_sample@6.5.0@@turf.7181d7a7.js +0 -1
- package/dist/js/_@turf_sector@6.5.0@@turf/_@turf_sector@6.5.0@@turf.04ffddfe.js +0 -39
- package/dist/js/_@turf_shortest-path@6.5.0@@turf/_@turf_shortest-path@6.5.0@@turf.0c1b62a8.js +0 -367
- package/dist/js/_@turf_simplify@6.5.0@@turf/_@turf_simplify@6.5.0@@turf.46703d2e.js +0 -1
- package/dist/js/_@turf_square-grid@6.5.0@@turf/_@turf_square-grid@6.5.0@@turf.38bd2eaa.js +0 -8
- package/dist/js/_@turf_square@6.5.0@@turf/_@turf_square@6.5.0@@turf.2705289a.js +0 -27
- package/dist/js/_@turf_standard-deviational-ellipse@6.5.0@@turf/_@turf_standard-deviational-ellipse@6.5.0@@turf.7094e432.js +0 -1
- package/dist/js/_@turf_tag@6.5.0@@turf/_@turf_tag@6.5.0@@turf.cb60b0c1.js +0 -1
- package/dist/js/_@turf_tesselate@6.5.0@@turf/_@turf_tesselate@6.5.0@@turf.330e4aae.js +0 -1
- package/dist/js/_@turf_tin@6.5.0@@turf/_@turf_tin@6.5.0@@turf.077204c4.js +0 -173
- package/dist/js/_@turf_transform-rotate@6.5.0@@turf/_@turf_transform-rotate@6.5.0@@turf.6d350d36.js +0 -1
- package/dist/js/_@turf_transform-scale@6.5.0@@turf/_@turf_transform-scale@6.5.0@@turf.d6f65671.js +0 -90
- package/dist/js/_@turf_transform-translate@6.5.0@@turf/_@turf_transform-translate@6.5.0@@turf.9296b81a.js +0 -1
- package/dist/js/_@turf_triangle-grid@6.5.0@@turf/_@turf_triangle-grid@6.5.0@@turf.939f94ab.js +0 -107
- package/dist/js/_@turf_truncate@6.5.0@@turf/_@turf_truncate@6.5.0@@turf.ed70ebcb.js +0 -33
- package/dist/js/_@turf_turf@6.4.0@@turf/_@turf_turf@6.4.0@@turf.34fde8ec.js +0 -1
- package/dist/js/_@turf_union@6.5.0@@turf/_@turf_union@6.5.0@@turf.386ee2eb.js +0 -1
- package/dist/js/_@turf_unkink-polygon@6.5.0@@turf/_@turf_unkink-polygon@6.5.0@@turf.cb446e47.js +0 -1
- package/dist/js/_@turf_voronoi@6.5.0@@turf/_@turf_voronoi@6.5.0@@turf.c30d929e.js +0 -30
- package/dist/js/_call-bind@1.0.2@call-bind/_call-bind@1.0.2@call-bind.3811d387.js +0 -53
- package/dist/js/_concaveman@1.2.1@concaveman/_concaveman@1.2.1@concaveman.e747f731.js +0 -1
- package/dist/js/_core-js@3.25.0@core-js/_core-js@3.25.0@core-js.003355ed.js +0 -5029
- package/dist/js/_crypto-js@4.1.1@crypto-js/_crypto-js@4.1.1@crypto-js.e2f7f158.js +0 -1823
- package/dist/js/_d3-array@1.2.4@d3-array/_d3-array@1.2.4@d3-array.d606df6b.js +0 -58
- package/dist/js/_d3-geo@1.7.1@d3-geo/_d3-geo@1.7.1@d3-geo.7d357be1.js +0 -1094
- package/dist/js/_d3-voronoi@1.1.2@d3-voronoi/_d3-voronoi@1.1.2@d3-voronoi.072f12a6.js +0 -816
- package/dist/js/_deep-equal@1.1.1@deep-equal/_deep-equal@1.1.1@deep-equal.98576c17.js +0 -108
- package/dist/js/_define-properties@1.1.4@define-properties/_define-properties@1.1.4@define-properties.647c3367.js +0 -40
- package/dist/js/_density-clustering@1.3.0@density-clustering/_density-clustering@1.3.0@density-clustering.a07fc6ae.js +0 -1
- package/dist/js/_earcut@2.2.4@earcut/_earcut@2.2.4@earcut.972ebfd3.js +0 -1
- package/dist/js/_echarts-gl@1.1.2@echarts-gl/_echarts-gl@1.1.2@echarts-gl.1e3964b9.js +0 -36533
- package/dist/js/_echarts@4.9.0@echarts/_echarts@4.9.0@echarts.7d74ba77.js +0 -44219
- package/dist/js/_fflate@0.4.8@fflate/_fflate@0.4.8@fflate.d8111196.js +0 -571
- package/dist/js/_function-bind@1.1.1@function-bind/_function-bind@1.1.1@function-bind.de3cf11d.js +0 -46
- package/dist/js/_functions-have-names@1.2.3@functions-have-names/_functions-have-names@1.2.3@functions-have-names.7def2408.js +0 -27
- package/dist/js/_geojson-equality@0.1.6@geojson-equality/_geojson-equality@0.1.6@geojson-equality.09ffa121.js +0 -133
- package/dist/js/_geojson-path-finder@1.5.3@geojson-path-finder/_geojson-path-finder@1.5.3@geojson-path-finder.7a10eb99.js +0 -348
- package/dist/js/_geojson-rbush@3.2.0@geojson-rbush/_geojson-rbush@3.2.0@geojson-rbush.2adaeedb.js +0 -93
- package/dist/js/_geotiff@2.0.4@geotiff/_geotiff@2.0.4@geotiff.5b08f79e.js +0 -3663
- package/dist/js/_get-intrinsic@1.1.2@get-intrinsic/_get-intrinsic@1.1.2@get-intrinsic.a633bd68.js +0 -291
- package/dist/js/_has-property-descriptors@1.0.0@has-property-descriptors/_has-property-descriptors@1.0.0@has-property-descriptors.6bd2d302.js +0 -26
- package/dist/js/_has-symbols@1.0.3@has-symbols/_has-symbols@1.0.3@has-symbols.70406077.js +0 -63
- package/dist/js/_has-tostringtag@1.0.0@has-tostringtag/_has-tostringtag@1.0.0@has-tostringtag.2d502422.js +0 -6
- package/dist/js/_has@1.0.3@has/_has@1.0.3@has.ddd2eb68.js +0 -4
- package/dist/js/_ieee754@1.2.1@ieee754/_ieee754@1.2.1@ieee754.56426503.js +0 -80
- package/dist/js/_is-arguments@1.1.1@is-arguments/_is-arguments@1.1.1@is-arguments.7d77e24a.js +0 -23
- package/dist/js/_is-date-object@1.0.5@is-date-object/_is-date-object@1.0.5@is-date-object.08cc2543.js +0 -20
- package/dist/js/_is-regex@1.1.4@is-regex/_is-regex@1.1.4@is-regex.6417e007.js +0 -47
- package/dist/js/_jspdf@2.5.1@jspdf/_jspdf@2.5.1@jspdf.e927dbd8.js +0 -8494
- package/dist/js/_kml-geojson@1.2.0@kml-geojson/_kml-geojson@1.2.0@kml-geojson.f1ae86e4.js +0 -7858
- package/dist/js/_lru-cache@6.0.0@lru-cache/_lru-cache@6.0.0@lru-cache.dd72cc1b.js +0 -263
- package/dist/js/_mgrs@1.0.0@mgrs/_mgrs@1.0.0@mgrs.12d1da3e.js +0 -432
- package/dist/js/_object-assign@4.1.1@object-assign/_object-assign@4.1.1@object-assign.e4009c1c.js +0 -69
- package/dist/js/_object-is@1.1.5@object-is/_object-is@1.1.5@object-is.e47f5d65.js +0 -45
- package/dist/js/_object-keys@1.1.1@object-keys/_object-keys@1.1.1@object-keys.4b1d0a99.js +0 -151
- package/dist/js/_ol-echarts@2.0.6@ol-echarts/_ol-echarts@2.0.6@ol-echarts.658aaf82.js +0 -841
- package/dist/js/_ol-ext@3.2.30@ol-ext/_ol-ext@3.2.30@ol-ext.b94220dd.js +0 -4614
- package/dist/js/_ol-mapbox-style@8.2.1@ol-mapbox-style/_ol-mapbox-style@8.2.1@ol-mapbox-style.795310f3.js +0 -1
- package/dist/js/_ol@6.15.1@ol/_ol@6.15.1@ol.8fd0cbb5.js +0 -31823
- package/dist/js/_pbf@3.2.1@pbf/_pbf@3.2.1@pbf.330acf55.js +0 -647
- package/dist/js/_performance-now@2.1.0@performance-now/_performance-now@2.1.0@performance-now.a51379c2.js +0 -34
- package/dist/js/_point-in-polygon@1.1.0@point-in-polygon/_point-in-polygon@1.1.0@point-in-polygon.2cc4306e.js +0 -1
- package/dist/js/_polygon-clipping@0.15.3@polygon-clipping/_polygon-clipping@0.15.3@polygon-clipping.c0e9ec57.js +0 -1363
- package/dist/js/_proj4@2.8.0@proj4/_proj4@2.8.0@proj4.1600352c.js +0 -4885
- package/dist/js/_quickselect@1.1.1@quickselect/_quickselect@1.1.1@quickselect.8afce154.js +0 -1
- package/dist/js/_quickselect@2.0.0@quickselect/_quickselect@2.0.0@quickselect.9f5c1e48.js +0 -51
- package/dist/js/_raf@3.4.1@raf/_raf@3.4.1@raf.ac0d6c66.js +0 -60
- package/dist/js/_rbush@2.0.2@rbush/_rbush@2.0.2@rbush.7149e620.js +0 -1
- package/dist/js/_rbush@3.0.1@rbush/_rbush@3.0.1@rbush.57d33d95.js +0 -402
- package/dist/js/_regexp.prototype.flags@1.4.3@regexp.prototype.flags/_regexp.prototype.flags@1.4.3@regexp.prototype.flags.8b6921c6.js +0 -102
- package/dist/js/_rgbcolor@1.0.1@rgbcolor/_rgbcolor@1.0.1@rgbcolor.dd87e013.js +0 -272
- package/dist/js/_robust-predicates@2.0.4@robust-predicates/_robust-predicates@2.0.4@robust-predicates.564bf2f8.js +0 -1
- package/dist/js/_skmeans@0.9.7@skmeans/_skmeans@0.9.7@skmeans.933c6a76.js +0 -1
- package/dist/js/_splaytree@3.1.1@splaytree/_splaytree@3.1.1@splaytree.6cb55ed3.js +0 -671
- package/dist/js/_stackblur-canvas@2.5.0@stackblur-canvas/_stackblur-canvas@2.5.0@stackblur-canvas.dd883d14.js +0 -214
- package/dist/js/_svg-pathdata@6.0.3@svg-pathdata/_svg-pathdata@6.0.3@svg-pathdata.7e858a5f.js +0 -441
- package/dist/js/_tinyqueue@2.0.3@tinyqueue/_tinyqueue@2.0.3@tinyqueue.78918532.js +0 -73
- package/dist/js/_topojson-client@3.1.0@topojson-client/_topojson-client@3.1.0@topojson-client.aef4e2d5.js +0 -238
- package/dist/js/_topojson-server@3.0.1@topojson-server/_topojson-server@3.0.1@topojson-server.b521a412.js +0 -662
- package/dist/js/_turf-jsts@1.2.3@turf-jsts/_turf-jsts@1.2.3@turf-jsts.6ef42696.js +0 -18934
- package/dist/js/_web-worker@1.2.0@web-worker/_web-worker@1.2.0@web-worker.43288df7.js +0 -2
- package/dist/js/_wkt-parser@1.3.2@wkt-parser/_wkt-parser@1.3.2@wkt-parser.0e1cf374.js +0 -461
- package/dist/js/_xml-utils@1.2.0@xml-utils/_xml-utils@1.2.0@xml-utils.2a8ae655.js +0 -126
- package/dist/js/_yallist@4.0.0@yallist/_yallist@4.0.0@yallist.8350aafe.js +0 -363
- package/dist/js/_zrender@4.3.2@zrender/_zrender@4.3.2@zrender.1feea14d.js +0 -12455
- package/dist/mirage2d.es.js +0 -15894
|
@@ -1,3663 +0,0 @@
|
|
|
1
|
-
import { f as findTagsByName, g as getAttribute } from "../_xml-utils@1.2.0@xml-utils/_xml-utils@1.2.0@xml-utils.2a8ae655.js";
|
|
2
|
-
import { g as getFloat16 } from "../_@petamoriken_float16@3.6.6@@petamoriken/_@petamoriken_float16@3.6.6@@petamoriken.c5188241.js";
|
|
3
|
-
import { _ as _lruCache_6_0_0_lruCache } from "../_lru-cache@6.0.0@lru-cache/_lru-cache@6.0.0@lru-cache.dd72cc1b.js";
|
|
4
|
-
import { i as inflate_1 } from "../_pako@2.0.4@pako/_pako@2.0.4@pako.52d6b320.js";
|
|
5
|
-
import { L as Lerc } from "../_lerc@3.0.0@lerc/_lerc@3.0.0@lerc.dc2ff398.js";
|
|
6
|
-
import { b as browser } from "../_web-worker@1.2.0@web-worker/_web-worker@1.2.0@web-worker.43288df7.js";
|
|
7
|
-
const fieldTagNames = {
|
|
8
|
-
315: "Artist",
|
|
9
|
-
258: "BitsPerSample",
|
|
10
|
-
265: "CellLength",
|
|
11
|
-
264: "CellWidth",
|
|
12
|
-
320: "ColorMap",
|
|
13
|
-
259: "Compression",
|
|
14
|
-
33432: "Copyright",
|
|
15
|
-
306: "DateTime",
|
|
16
|
-
338: "ExtraSamples",
|
|
17
|
-
266: "FillOrder",
|
|
18
|
-
289: "FreeByteCounts",
|
|
19
|
-
288: "FreeOffsets",
|
|
20
|
-
291: "GrayResponseCurve",
|
|
21
|
-
290: "GrayResponseUnit",
|
|
22
|
-
316: "HostComputer",
|
|
23
|
-
270: "ImageDescription",
|
|
24
|
-
257: "ImageLength",
|
|
25
|
-
256: "ImageWidth",
|
|
26
|
-
271: "Make",
|
|
27
|
-
281: "MaxSampleValue",
|
|
28
|
-
280: "MinSampleValue",
|
|
29
|
-
272: "Model",
|
|
30
|
-
254: "NewSubfileType",
|
|
31
|
-
274: "Orientation",
|
|
32
|
-
262: "PhotometricInterpretation",
|
|
33
|
-
284: "PlanarConfiguration",
|
|
34
|
-
296: "ResolutionUnit",
|
|
35
|
-
278: "RowsPerStrip",
|
|
36
|
-
277: "SamplesPerPixel",
|
|
37
|
-
305: "Software",
|
|
38
|
-
279: "StripByteCounts",
|
|
39
|
-
273: "StripOffsets",
|
|
40
|
-
255: "SubfileType",
|
|
41
|
-
263: "Threshholding",
|
|
42
|
-
282: "XResolution",
|
|
43
|
-
283: "YResolution",
|
|
44
|
-
326: "BadFaxLines",
|
|
45
|
-
327: "CleanFaxData",
|
|
46
|
-
343: "ClipPath",
|
|
47
|
-
328: "ConsecutiveBadFaxLines",
|
|
48
|
-
433: "Decode",
|
|
49
|
-
434: "DefaultImageColor",
|
|
50
|
-
269: "DocumentName",
|
|
51
|
-
336: "DotRange",
|
|
52
|
-
321: "HalftoneHints",
|
|
53
|
-
346: "Indexed",
|
|
54
|
-
347: "JPEGTables",
|
|
55
|
-
285: "PageName",
|
|
56
|
-
297: "PageNumber",
|
|
57
|
-
317: "Predictor",
|
|
58
|
-
319: "PrimaryChromaticities",
|
|
59
|
-
532: "ReferenceBlackWhite",
|
|
60
|
-
339: "SampleFormat",
|
|
61
|
-
340: "SMinSampleValue",
|
|
62
|
-
341: "SMaxSampleValue",
|
|
63
|
-
559: "StripRowCounts",
|
|
64
|
-
330: "SubIFDs",
|
|
65
|
-
292: "T4Options",
|
|
66
|
-
293: "T6Options",
|
|
67
|
-
325: "TileByteCounts",
|
|
68
|
-
323: "TileLength",
|
|
69
|
-
324: "TileOffsets",
|
|
70
|
-
322: "TileWidth",
|
|
71
|
-
301: "TransferFunction",
|
|
72
|
-
318: "WhitePoint",
|
|
73
|
-
344: "XClipPathUnits",
|
|
74
|
-
286: "XPosition",
|
|
75
|
-
529: "YCbCrCoefficients",
|
|
76
|
-
531: "YCbCrPositioning",
|
|
77
|
-
530: "YCbCrSubSampling",
|
|
78
|
-
345: "YClipPathUnits",
|
|
79
|
-
287: "YPosition",
|
|
80
|
-
37378: "ApertureValue",
|
|
81
|
-
40961: "ColorSpace",
|
|
82
|
-
36868: "DateTimeDigitized",
|
|
83
|
-
36867: "DateTimeOriginal",
|
|
84
|
-
34665: "Exif IFD",
|
|
85
|
-
36864: "ExifVersion",
|
|
86
|
-
33434: "ExposureTime",
|
|
87
|
-
41728: "FileSource",
|
|
88
|
-
37385: "Flash",
|
|
89
|
-
40960: "FlashpixVersion",
|
|
90
|
-
33437: "FNumber",
|
|
91
|
-
42016: "ImageUniqueID",
|
|
92
|
-
37384: "LightSource",
|
|
93
|
-
37500: "MakerNote",
|
|
94
|
-
37377: "ShutterSpeedValue",
|
|
95
|
-
37510: "UserComment",
|
|
96
|
-
33723: "IPTC",
|
|
97
|
-
34675: "ICC Profile",
|
|
98
|
-
700: "XMP",
|
|
99
|
-
42112: "GDAL_METADATA",
|
|
100
|
-
42113: "GDAL_NODATA",
|
|
101
|
-
34377: "Photoshop",
|
|
102
|
-
33550: "ModelPixelScale",
|
|
103
|
-
33922: "ModelTiepoint",
|
|
104
|
-
34264: "ModelTransformation",
|
|
105
|
-
34735: "GeoKeyDirectory",
|
|
106
|
-
34736: "GeoDoubleParams",
|
|
107
|
-
34737: "GeoAsciiParams",
|
|
108
|
-
50674: "LercParameters"
|
|
109
|
-
};
|
|
110
|
-
const fieldTags = {};
|
|
111
|
-
for (const key in fieldTagNames) {
|
|
112
|
-
if (fieldTagNames.hasOwnProperty(key)) {
|
|
113
|
-
fieldTags[fieldTagNames[key]] = parseInt(key, 10);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const arrayFields = [
|
|
117
|
-
fieldTags.BitsPerSample,
|
|
118
|
-
fieldTags.ExtraSamples,
|
|
119
|
-
fieldTags.SampleFormat,
|
|
120
|
-
fieldTags.StripByteCounts,
|
|
121
|
-
fieldTags.StripOffsets,
|
|
122
|
-
fieldTags.StripRowCounts,
|
|
123
|
-
fieldTags.TileByteCounts,
|
|
124
|
-
fieldTags.TileOffsets,
|
|
125
|
-
fieldTags.SubIFDs
|
|
126
|
-
];
|
|
127
|
-
const fieldTypeNames = {
|
|
128
|
-
1: "BYTE",
|
|
129
|
-
2: "ASCII",
|
|
130
|
-
3: "SHORT",
|
|
131
|
-
4: "LONG",
|
|
132
|
-
5: "RATIONAL",
|
|
133
|
-
6: "SBYTE",
|
|
134
|
-
7: "UNDEFINED",
|
|
135
|
-
8: "SSHORT",
|
|
136
|
-
9: "SLONG",
|
|
137
|
-
10: "SRATIONAL",
|
|
138
|
-
11: "FLOAT",
|
|
139
|
-
12: "DOUBLE",
|
|
140
|
-
13: "IFD",
|
|
141
|
-
16: "LONG8",
|
|
142
|
-
17: "SLONG8",
|
|
143
|
-
18: "IFD8"
|
|
144
|
-
};
|
|
145
|
-
const fieldTypes = {};
|
|
146
|
-
for (const key in fieldTypeNames) {
|
|
147
|
-
if (fieldTypeNames.hasOwnProperty(key)) {
|
|
148
|
-
fieldTypes[fieldTypeNames[key]] = parseInt(key, 10);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const photometricInterpretations = {
|
|
152
|
-
WhiteIsZero: 0,
|
|
153
|
-
BlackIsZero: 1,
|
|
154
|
-
RGB: 2,
|
|
155
|
-
Palette: 3,
|
|
156
|
-
TransparencyMask: 4,
|
|
157
|
-
CMYK: 5,
|
|
158
|
-
YCbCr: 6,
|
|
159
|
-
CIELab: 8,
|
|
160
|
-
ICCLab: 9
|
|
161
|
-
};
|
|
162
|
-
const ExtraSamplesValues = {
|
|
163
|
-
Unspecified: 0,
|
|
164
|
-
Assocalpha: 1,
|
|
165
|
-
Unassalpha: 2
|
|
166
|
-
};
|
|
167
|
-
const LercParameters = {
|
|
168
|
-
Version: 0,
|
|
169
|
-
AddCompression: 1
|
|
170
|
-
};
|
|
171
|
-
const LercAddCompression = {
|
|
172
|
-
None: 0,
|
|
173
|
-
Deflate: 1
|
|
174
|
-
};
|
|
175
|
-
const geoKeyNames = {
|
|
176
|
-
1024: "GTModelTypeGeoKey",
|
|
177
|
-
1025: "GTRasterTypeGeoKey",
|
|
178
|
-
1026: "GTCitationGeoKey",
|
|
179
|
-
2048: "GeographicTypeGeoKey",
|
|
180
|
-
2049: "GeogCitationGeoKey",
|
|
181
|
-
2050: "GeogGeodeticDatumGeoKey",
|
|
182
|
-
2051: "GeogPrimeMeridianGeoKey",
|
|
183
|
-
2052: "GeogLinearUnitsGeoKey",
|
|
184
|
-
2053: "GeogLinearUnitSizeGeoKey",
|
|
185
|
-
2054: "GeogAngularUnitsGeoKey",
|
|
186
|
-
2055: "GeogAngularUnitSizeGeoKey",
|
|
187
|
-
2056: "GeogEllipsoidGeoKey",
|
|
188
|
-
2057: "GeogSemiMajorAxisGeoKey",
|
|
189
|
-
2058: "GeogSemiMinorAxisGeoKey",
|
|
190
|
-
2059: "GeogInvFlatteningGeoKey",
|
|
191
|
-
2060: "GeogAzimuthUnitsGeoKey",
|
|
192
|
-
2061: "GeogPrimeMeridianLongGeoKey",
|
|
193
|
-
2062: "GeogTOWGS84GeoKey",
|
|
194
|
-
3072: "ProjectedCSTypeGeoKey",
|
|
195
|
-
3073: "PCSCitationGeoKey",
|
|
196
|
-
3074: "ProjectionGeoKey",
|
|
197
|
-
3075: "ProjCoordTransGeoKey",
|
|
198
|
-
3076: "ProjLinearUnitsGeoKey",
|
|
199
|
-
3077: "ProjLinearUnitSizeGeoKey",
|
|
200
|
-
3078: "ProjStdParallel1GeoKey",
|
|
201
|
-
3079: "ProjStdParallel2GeoKey",
|
|
202
|
-
3080: "ProjNatOriginLongGeoKey",
|
|
203
|
-
3081: "ProjNatOriginLatGeoKey",
|
|
204
|
-
3082: "ProjFalseEastingGeoKey",
|
|
205
|
-
3083: "ProjFalseNorthingGeoKey",
|
|
206
|
-
3084: "ProjFalseOriginLongGeoKey",
|
|
207
|
-
3085: "ProjFalseOriginLatGeoKey",
|
|
208
|
-
3086: "ProjFalseOriginEastingGeoKey",
|
|
209
|
-
3087: "ProjFalseOriginNorthingGeoKey",
|
|
210
|
-
3088: "ProjCenterLongGeoKey",
|
|
211
|
-
3089: "ProjCenterLatGeoKey",
|
|
212
|
-
3090: "ProjCenterEastingGeoKey",
|
|
213
|
-
3091: "ProjCenterNorthingGeoKey",
|
|
214
|
-
3092: "ProjScaleAtNatOriginGeoKey",
|
|
215
|
-
3093: "ProjScaleAtCenterGeoKey",
|
|
216
|
-
3094: "ProjAzimuthAngleGeoKey",
|
|
217
|
-
3095: "ProjStraightVertPoleLongGeoKey",
|
|
218
|
-
3096: "ProjRectifiedGridAngleGeoKey",
|
|
219
|
-
4096: "VerticalCSTypeGeoKey",
|
|
220
|
-
4097: "VerticalCitationGeoKey",
|
|
221
|
-
4098: "VerticalDatumGeoKey",
|
|
222
|
-
4099: "VerticalUnitsGeoKey"
|
|
223
|
-
};
|
|
224
|
-
function fromWhiteIsZero(raster, max) {
|
|
225
|
-
const { width, height } = raster;
|
|
226
|
-
const rgbRaster = new Uint8Array(width * height * 3);
|
|
227
|
-
let value;
|
|
228
|
-
for (let i = 0, j = 0; i < raster.length; ++i, j += 3) {
|
|
229
|
-
value = 256 - raster[i] / max * 256;
|
|
230
|
-
rgbRaster[j] = value;
|
|
231
|
-
rgbRaster[j + 1] = value;
|
|
232
|
-
rgbRaster[j + 2] = value;
|
|
233
|
-
}
|
|
234
|
-
return rgbRaster;
|
|
235
|
-
}
|
|
236
|
-
function fromBlackIsZero(raster, max) {
|
|
237
|
-
const { width, height } = raster;
|
|
238
|
-
const rgbRaster = new Uint8Array(width * height * 3);
|
|
239
|
-
let value;
|
|
240
|
-
for (let i = 0, j = 0; i < raster.length; ++i, j += 3) {
|
|
241
|
-
value = raster[i] / max * 256;
|
|
242
|
-
rgbRaster[j] = value;
|
|
243
|
-
rgbRaster[j + 1] = value;
|
|
244
|
-
rgbRaster[j + 2] = value;
|
|
245
|
-
}
|
|
246
|
-
return rgbRaster;
|
|
247
|
-
}
|
|
248
|
-
function fromPalette(raster, colorMap) {
|
|
249
|
-
const { width, height } = raster;
|
|
250
|
-
const rgbRaster = new Uint8Array(width * height * 3);
|
|
251
|
-
const greenOffset = colorMap.length / 3;
|
|
252
|
-
const blueOffset = colorMap.length / 3 * 2;
|
|
253
|
-
for (let i = 0, j = 0; i < raster.length; ++i, j += 3) {
|
|
254
|
-
const mapIndex = raster[i];
|
|
255
|
-
rgbRaster[j] = colorMap[mapIndex] / 65536 * 256;
|
|
256
|
-
rgbRaster[j + 1] = colorMap[mapIndex + greenOffset] / 65536 * 256;
|
|
257
|
-
rgbRaster[j + 2] = colorMap[mapIndex + blueOffset] / 65536 * 256;
|
|
258
|
-
}
|
|
259
|
-
return rgbRaster;
|
|
260
|
-
}
|
|
261
|
-
function fromCMYK(cmykRaster) {
|
|
262
|
-
const { width, height } = cmykRaster;
|
|
263
|
-
const rgbRaster = new Uint8Array(width * height * 3);
|
|
264
|
-
for (let i = 0, j = 0; i < cmykRaster.length; i += 4, j += 3) {
|
|
265
|
-
const c = cmykRaster[i];
|
|
266
|
-
const m = cmykRaster[i + 1];
|
|
267
|
-
const y = cmykRaster[i + 2];
|
|
268
|
-
const k = cmykRaster[i + 3];
|
|
269
|
-
rgbRaster[j] = 255 * ((255 - c) / 256) * ((255 - k) / 256);
|
|
270
|
-
rgbRaster[j + 1] = 255 * ((255 - m) / 256) * ((255 - k) / 256);
|
|
271
|
-
rgbRaster[j + 2] = 255 * ((255 - y) / 256) * ((255 - k) / 256);
|
|
272
|
-
}
|
|
273
|
-
return rgbRaster;
|
|
274
|
-
}
|
|
275
|
-
function fromYCbCr(yCbCrRaster) {
|
|
276
|
-
const { width, height } = yCbCrRaster;
|
|
277
|
-
const rgbRaster = new Uint8ClampedArray(width * height * 3);
|
|
278
|
-
for (let i = 0, j = 0; i < yCbCrRaster.length; i += 3, j += 3) {
|
|
279
|
-
const y = yCbCrRaster[i];
|
|
280
|
-
const cb = yCbCrRaster[i + 1];
|
|
281
|
-
const cr = yCbCrRaster[i + 2];
|
|
282
|
-
rgbRaster[j] = y + 1.402 * (cr - 128);
|
|
283
|
-
rgbRaster[j + 1] = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128);
|
|
284
|
-
rgbRaster[j + 2] = y + 1.772 * (cb - 128);
|
|
285
|
-
}
|
|
286
|
-
return rgbRaster;
|
|
287
|
-
}
|
|
288
|
-
const Xn = 0.95047;
|
|
289
|
-
const Yn = 1;
|
|
290
|
-
const Zn = 1.08883;
|
|
291
|
-
function fromCIELab(cieLabRaster) {
|
|
292
|
-
const { width, height } = cieLabRaster;
|
|
293
|
-
const rgbRaster = new Uint8Array(width * height * 3);
|
|
294
|
-
for (let i = 0, j = 0; i < cieLabRaster.length; i += 3, j += 3) {
|
|
295
|
-
const L = cieLabRaster[i + 0];
|
|
296
|
-
const a_ = cieLabRaster[i + 1] << 24 >> 24;
|
|
297
|
-
const b_ = cieLabRaster[i + 2] << 24 >> 24;
|
|
298
|
-
let y = (L + 16) / 116;
|
|
299
|
-
let x = a_ / 500 + y;
|
|
300
|
-
let z = y - b_ / 200;
|
|
301
|
-
let r;
|
|
302
|
-
let g;
|
|
303
|
-
let b;
|
|
304
|
-
x = Xn * (x * x * x > 8856e-6 ? x * x * x : (x - 16 / 116) / 7.787);
|
|
305
|
-
y = Yn * (y * y * y > 8856e-6 ? y * y * y : (y - 16 / 116) / 7.787);
|
|
306
|
-
z = Zn * (z * z * z > 8856e-6 ? z * z * z : (z - 16 / 116) / 7.787);
|
|
307
|
-
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
308
|
-
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
309
|
-
b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
310
|
-
r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : 12.92 * r;
|
|
311
|
-
g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : 12.92 * g;
|
|
312
|
-
b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : 12.92 * b;
|
|
313
|
-
rgbRaster[j] = Math.max(0, Math.min(1, r)) * 255;
|
|
314
|
-
rgbRaster[j + 1] = Math.max(0, Math.min(1, g)) * 255;
|
|
315
|
-
rgbRaster[j + 2] = Math.max(0, Math.min(1, b)) * 255;
|
|
316
|
-
}
|
|
317
|
-
return rgbRaster;
|
|
318
|
-
}
|
|
319
|
-
const registry = /* @__PURE__ */ new Map();
|
|
320
|
-
function addDecoder(cases, importFn) {
|
|
321
|
-
if (!Array.isArray(cases)) {
|
|
322
|
-
cases = [cases];
|
|
323
|
-
}
|
|
324
|
-
cases.forEach((c) => registry.set(c, importFn));
|
|
325
|
-
}
|
|
326
|
-
async function getDecoder(fileDirectory) {
|
|
327
|
-
const importFn = registry.get(fileDirectory.Compression);
|
|
328
|
-
if (!importFn) {
|
|
329
|
-
throw new Error(`Unknown compression method identifier: ${fileDirectory.Compression}`);
|
|
330
|
-
}
|
|
331
|
-
const Decoder = await importFn();
|
|
332
|
-
return new Decoder(fileDirectory);
|
|
333
|
-
}
|
|
334
|
-
addDecoder([void 0, 1], () => Promise.resolve().then(function() {
|
|
335
|
-
return raw;
|
|
336
|
-
}).then((m) => m.default));
|
|
337
|
-
addDecoder(5, () => Promise.resolve().then(function() {
|
|
338
|
-
return lzw;
|
|
339
|
-
}).then((m) => m.default));
|
|
340
|
-
addDecoder(6, () => {
|
|
341
|
-
throw new Error("old style JPEG compression is not supported.");
|
|
342
|
-
});
|
|
343
|
-
addDecoder(7, () => Promise.resolve().then(function() {
|
|
344
|
-
return jpeg;
|
|
345
|
-
}).then((m) => m.default));
|
|
346
|
-
addDecoder([8, 32946], () => Promise.resolve().then(function() {
|
|
347
|
-
return deflate;
|
|
348
|
-
}).then((m) => m.default));
|
|
349
|
-
addDecoder(32773, () => Promise.resolve().then(function() {
|
|
350
|
-
return packbits;
|
|
351
|
-
}).then((m) => m.default));
|
|
352
|
-
addDecoder(34887, () => Promise.resolve().then(function() {
|
|
353
|
-
return lerc;
|
|
354
|
-
}).then((m) => m.default));
|
|
355
|
-
addDecoder(50001, () => Promise.resolve().then(function() {
|
|
356
|
-
return webimage;
|
|
357
|
-
}).then((m) => m.default));
|
|
358
|
-
function copyNewSize(array, width, height, samplesPerPixel = 1) {
|
|
359
|
-
return new (Object.getPrototypeOf(array)).constructor(width * height * samplesPerPixel);
|
|
360
|
-
}
|
|
361
|
-
function resampleNearest(valueArrays, inWidth, inHeight, outWidth, outHeight) {
|
|
362
|
-
const relX = inWidth / outWidth;
|
|
363
|
-
const relY = inHeight / outHeight;
|
|
364
|
-
return valueArrays.map((array) => {
|
|
365
|
-
const newArray = copyNewSize(array, outWidth, outHeight);
|
|
366
|
-
for (let y = 0; y < outHeight; ++y) {
|
|
367
|
-
const cy = Math.min(Math.round(relY * y), inHeight - 1);
|
|
368
|
-
for (let x = 0; x < outWidth; ++x) {
|
|
369
|
-
const cx = Math.min(Math.round(relX * x), inWidth - 1);
|
|
370
|
-
const value = array[cy * inWidth + cx];
|
|
371
|
-
newArray[y * outWidth + x] = value;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return newArray;
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
function lerp(v0, v1, t) {
|
|
378
|
-
return (1 - t) * v0 + t * v1;
|
|
379
|
-
}
|
|
380
|
-
function resampleBilinear(valueArrays, inWidth, inHeight, outWidth, outHeight) {
|
|
381
|
-
const relX = inWidth / outWidth;
|
|
382
|
-
const relY = inHeight / outHeight;
|
|
383
|
-
return valueArrays.map((array) => {
|
|
384
|
-
const newArray = copyNewSize(array, outWidth, outHeight);
|
|
385
|
-
for (let y = 0; y < outHeight; ++y) {
|
|
386
|
-
const rawY = relY * y;
|
|
387
|
-
const yl = Math.floor(rawY);
|
|
388
|
-
const yh = Math.min(Math.ceil(rawY), inHeight - 1);
|
|
389
|
-
for (let x = 0; x < outWidth; ++x) {
|
|
390
|
-
const rawX = relX * x;
|
|
391
|
-
const tx = rawX % 1;
|
|
392
|
-
const xl = Math.floor(rawX);
|
|
393
|
-
const xh = Math.min(Math.ceil(rawX), inWidth - 1);
|
|
394
|
-
const ll = array[yl * inWidth + xl];
|
|
395
|
-
const hl = array[yl * inWidth + xh];
|
|
396
|
-
const lh = array[yh * inWidth + xl];
|
|
397
|
-
const hh = array[yh * inWidth + xh];
|
|
398
|
-
const value = lerp(
|
|
399
|
-
lerp(ll, hl, tx),
|
|
400
|
-
lerp(lh, hh, tx),
|
|
401
|
-
rawY % 1
|
|
402
|
-
);
|
|
403
|
-
newArray[y * outWidth + x] = value;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return newArray;
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
function resample(valueArrays, inWidth, inHeight, outWidth, outHeight, method = "nearest") {
|
|
410
|
-
switch (method.toLowerCase()) {
|
|
411
|
-
case "nearest":
|
|
412
|
-
return resampleNearest(valueArrays, inWidth, inHeight, outWidth, outHeight);
|
|
413
|
-
case "bilinear":
|
|
414
|
-
case "linear":
|
|
415
|
-
return resampleBilinear(valueArrays, inWidth, inHeight, outWidth, outHeight);
|
|
416
|
-
default:
|
|
417
|
-
throw new Error(`Unsupported resampling method: '${method}'`);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
function resampleNearestInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples) {
|
|
421
|
-
const relX = inWidth / outWidth;
|
|
422
|
-
const relY = inHeight / outHeight;
|
|
423
|
-
const newArray = copyNewSize(valueArray, outWidth, outHeight, samples);
|
|
424
|
-
for (let y = 0; y < outHeight; ++y) {
|
|
425
|
-
const cy = Math.min(Math.round(relY * y), inHeight - 1);
|
|
426
|
-
for (let x = 0; x < outWidth; ++x) {
|
|
427
|
-
const cx = Math.min(Math.round(relX * x), inWidth - 1);
|
|
428
|
-
for (let i = 0; i < samples; ++i) {
|
|
429
|
-
const value = valueArray[cy * inWidth * samples + cx * samples + i];
|
|
430
|
-
newArray[y * outWidth * samples + x * samples + i] = value;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return newArray;
|
|
435
|
-
}
|
|
436
|
-
function resampleBilinearInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples) {
|
|
437
|
-
const relX = inWidth / outWidth;
|
|
438
|
-
const relY = inHeight / outHeight;
|
|
439
|
-
const newArray = copyNewSize(valueArray, outWidth, outHeight, samples);
|
|
440
|
-
for (let y = 0; y < outHeight; ++y) {
|
|
441
|
-
const rawY = relY * y;
|
|
442
|
-
const yl = Math.floor(rawY);
|
|
443
|
-
const yh = Math.min(Math.ceil(rawY), inHeight - 1);
|
|
444
|
-
for (let x = 0; x < outWidth; ++x) {
|
|
445
|
-
const rawX = relX * x;
|
|
446
|
-
const tx = rawX % 1;
|
|
447
|
-
const xl = Math.floor(rawX);
|
|
448
|
-
const xh = Math.min(Math.ceil(rawX), inWidth - 1);
|
|
449
|
-
for (let i = 0; i < samples; ++i) {
|
|
450
|
-
const ll = valueArray[yl * inWidth * samples + xl * samples + i];
|
|
451
|
-
const hl = valueArray[yl * inWidth * samples + xh * samples + i];
|
|
452
|
-
const lh = valueArray[yh * inWidth * samples + xl * samples + i];
|
|
453
|
-
const hh = valueArray[yh * inWidth * samples + xh * samples + i];
|
|
454
|
-
const value = lerp(
|
|
455
|
-
lerp(ll, hl, tx),
|
|
456
|
-
lerp(lh, hh, tx),
|
|
457
|
-
rawY % 1
|
|
458
|
-
);
|
|
459
|
-
newArray[y * outWidth * samples + x * samples + i] = value;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return newArray;
|
|
464
|
-
}
|
|
465
|
-
function resampleInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples, method = "nearest") {
|
|
466
|
-
switch (method.toLowerCase()) {
|
|
467
|
-
case "nearest":
|
|
468
|
-
return resampleNearestInterleaved(
|
|
469
|
-
valueArray,
|
|
470
|
-
inWidth,
|
|
471
|
-
inHeight,
|
|
472
|
-
outWidth,
|
|
473
|
-
outHeight,
|
|
474
|
-
samples
|
|
475
|
-
);
|
|
476
|
-
case "bilinear":
|
|
477
|
-
case "linear":
|
|
478
|
-
return resampleBilinearInterleaved(
|
|
479
|
-
valueArray,
|
|
480
|
-
inWidth,
|
|
481
|
-
inHeight,
|
|
482
|
-
outWidth,
|
|
483
|
-
outHeight,
|
|
484
|
-
samples
|
|
485
|
-
);
|
|
486
|
-
default:
|
|
487
|
-
throw new Error(`Unsupported resampling method: '${method}'`);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function sum(array, start, end) {
|
|
491
|
-
let s = 0;
|
|
492
|
-
for (let i = start; i < end; ++i) {
|
|
493
|
-
s += array[i];
|
|
494
|
-
}
|
|
495
|
-
return s;
|
|
496
|
-
}
|
|
497
|
-
function arrayForType(format, bitsPerSample, size) {
|
|
498
|
-
switch (format) {
|
|
499
|
-
case 1:
|
|
500
|
-
if (bitsPerSample <= 8) {
|
|
501
|
-
return new Uint8Array(size);
|
|
502
|
-
} else if (bitsPerSample <= 16) {
|
|
503
|
-
return new Uint16Array(size);
|
|
504
|
-
} else if (bitsPerSample <= 32) {
|
|
505
|
-
return new Uint32Array(size);
|
|
506
|
-
}
|
|
507
|
-
break;
|
|
508
|
-
case 2:
|
|
509
|
-
if (bitsPerSample === 8) {
|
|
510
|
-
return new Int8Array(size);
|
|
511
|
-
} else if (bitsPerSample === 16) {
|
|
512
|
-
return new Int16Array(size);
|
|
513
|
-
} else if (bitsPerSample === 32) {
|
|
514
|
-
return new Int32Array(size);
|
|
515
|
-
}
|
|
516
|
-
break;
|
|
517
|
-
case 3:
|
|
518
|
-
switch (bitsPerSample) {
|
|
519
|
-
case 16:
|
|
520
|
-
case 32:
|
|
521
|
-
return new Float32Array(size);
|
|
522
|
-
case 64:
|
|
523
|
-
return new Float64Array(size);
|
|
524
|
-
}
|
|
525
|
-
break;
|
|
526
|
-
}
|
|
527
|
-
throw Error("Unsupported data format/bitsPerSample");
|
|
528
|
-
}
|
|
529
|
-
function needsNormalization(format, bitsPerSample) {
|
|
530
|
-
if ((format === 1 || format === 2) && bitsPerSample <= 32 && bitsPerSample % 8 === 0) {
|
|
531
|
-
return false;
|
|
532
|
-
} else if (format === 3 && (bitsPerSample === 16 || bitsPerSample === 32 || bitsPerSample === 64)) {
|
|
533
|
-
return false;
|
|
534
|
-
}
|
|
535
|
-
return true;
|
|
536
|
-
}
|
|
537
|
-
function normalizeArray(inBuffer, format, planarConfiguration, samplesPerPixel, bitsPerSample, tileWidth, tileHeight) {
|
|
538
|
-
const view = new DataView(inBuffer);
|
|
539
|
-
const outSize = planarConfiguration === 2 ? tileHeight * tileWidth : tileHeight * tileWidth * samplesPerPixel;
|
|
540
|
-
const samplesToTransfer = planarConfiguration === 2 ? 1 : samplesPerPixel;
|
|
541
|
-
const outArray = arrayForType(format, bitsPerSample, outSize);
|
|
542
|
-
const bitMask = parseInt("1".repeat(bitsPerSample), 2);
|
|
543
|
-
if (format === 1) {
|
|
544
|
-
let pixelBitSkip;
|
|
545
|
-
if (planarConfiguration === 1) {
|
|
546
|
-
pixelBitSkip = samplesPerPixel * bitsPerSample;
|
|
547
|
-
} else {
|
|
548
|
-
pixelBitSkip = bitsPerSample;
|
|
549
|
-
}
|
|
550
|
-
let bitsPerLine = tileWidth * pixelBitSkip;
|
|
551
|
-
if ((bitsPerLine & 7) !== 0) {
|
|
552
|
-
bitsPerLine = bitsPerLine + 7 & ~7;
|
|
553
|
-
}
|
|
554
|
-
for (let y = 0; y < tileHeight; ++y) {
|
|
555
|
-
const lineBitOffset = y * bitsPerLine;
|
|
556
|
-
for (let x = 0; x < tileWidth; ++x) {
|
|
557
|
-
const pixelBitOffset = lineBitOffset + x * samplesToTransfer * bitsPerSample;
|
|
558
|
-
for (let i = 0; i < samplesToTransfer; ++i) {
|
|
559
|
-
const bitOffset = pixelBitOffset + i * bitsPerSample;
|
|
560
|
-
const outIndex = (y * tileWidth + x) * samplesToTransfer + i;
|
|
561
|
-
const byteOffset = Math.floor(bitOffset / 8);
|
|
562
|
-
const innerBitOffset = bitOffset % 8;
|
|
563
|
-
if (innerBitOffset + bitsPerSample <= 8) {
|
|
564
|
-
outArray[outIndex] = view.getUint8(byteOffset) >> 8 - bitsPerSample - innerBitOffset & bitMask;
|
|
565
|
-
} else if (innerBitOffset + bitsPerSample <= 16) {
|
|
566
|
-
outArray[outIndex] = view.getUint16(byteOffset) >> 16 - bitsPerSample - innerBitOffset & bitMask;
|
|
567
|
-
} else if (innerBitOffset + bitsPerSample <= 24) {
|
|
568
|
-
const raw2 = view.getUint16(byteOffset) << 8 | view.getUint8(byteOffset + 2);
|
|
569
|
-
outArray[outIndex] = raw2 >> 24 - bitsPerSample - innerBitOffset & bitMask;
|
|
570
|
-
} else {
|
|
571
|
-
outArray[outIndex] = view.getUint32(byteOffset) >> 32 - bitsPerSample - innerBitOffset & bitMask;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return outArray.buffer;
|
|
578
|
-
}
|
|
579
|
-
class GeoTIFFImage {
|
|
580
|
-
constructor(fileDirectory, geoKeys, dataView, littleEndian, cache, source) {
|
|
581
|
-
this.fileDirectory = fileDirectory;
|
|
582
|
-
this.geoKeys = geoKeys;
|
|
583
|
-
this.dataView = dataView;
|
|
584
|
-
this.littleEndian = littleEndian;
|
|
585
|
-
this.tiles = cache ? {} : null;
|
|
586
|
-
this.isTiled = !fileDirectory.StripOffsets;
|
|
587
|
-
const planarConfiguration = fileDirectory.PlanarConfiguration;
|
|
588
|
-
this.planarConfiguration = typeof planarConfiguration === "undefined" ? 1 : planarConfiguration;
|
|
589
|
-
if (this.planarConfiguration !== 1 && this.planarConfiguration !== 2) {
|
|
590
|
-
throw new Error("Invalid planar configuration.");
|
|
591
|
-
}
|
|
592
|
-
this.source = source;
|
|
593
|
-
}
|
|
594
|
-
getFileDirectory() {
|
|
595
|
-
return this.fileDirectory;
|
|
596
|
-
}
|
|
597
|
-
getGeoKeys() {
|
|
598
|
-
return this.geoKeys;
|
|
599
|
-
}
|
|
600
|
-
getWidth() {
|
|
601
|
-
return this.fileDirectory.ImageWidth;
|
|
602
|
-
}
|
|
603
|
-
getHeight() {
|
|
604
|
-
return this.fileDirectory.ImageLength;
|
|
605
|
-
}
|
|
606
|
-
getSamplesPerPixel() {
|
|
607
|
-
return typeof this.fileDirectory.SamplesPerPixel !== "undefined" ? this.fileDirectory.SamplesPerPixel : 1;
|
|
608
|
-
}
|
|
609
|
-
getTileWidth() {
|
|
610
|
-
return this.isTiled ? this.fileDirectory.TileWidth : this.getWidth();
|
|
611
|
-
}
|
|
612
|
-
getTileHeight() {
|
|
613
|
-
if (this.isTiled) {
|
|
614
|
-
return this.fileDirectory.TileLength;
|
|
615
|
-
}
|
|
616
|
-
if (typeof this.fileDirectory.RowsPerStrip !== "undefined") {
|
|
617
|
-
return Math.min(this.fileDirectory.RowsPerStrip, this.getHeight());
|
|
618
|
-
}
|
|
619
|
-
return this.getHeight();
|
|
620
|
-
}
|
|
621
|
-
getBlockWidth() {
|
|
622
|
-
return this.getTileWidth();
|
|
623
|
-
}
|
|
624
|
-
getBlockHeight(y) {
|
|
625
|
-
if (this.isTiled || (y + 1) * this.getTileHeight() <= this.getHeight()) {
|
|
626
|
-
return this.getTileHeight();
|
|
627
|
-
} else {
|
|
628
|
-
return this.getHeight() - y * this.getTileHeight();
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
getBytesPerPixel() {
|
|
632
|
-
let bytes = 0;
|
|
633
|
-
for (let i = 0; i < this.fileDirectory.BitsPerSample.length; ++i) {
|
|
634
|
-
bytes += this.getSampleByteSize(i);
|
|
635
|
-
}
|
|
636
|
-
return bytes;
|
|
637
|
-
}
|
|
638
|
-
getSampleByteSize(i) {
|
|
639
|
-
if (i >= this.fileDirectory.BitsPerSample.length) {
|
|
640
|
-
throw new RangeError(`Sample index ${i} is out of range.`);
|
|
641
|
-
}
|
|
642
|
-
return Math.ceil(this.fileDirectory.BitsPerSample[i] / 8);
|
|
643
|
-
}
|
|
644
|
-
getReaderForSample(sampleIndex) {
|
|
645
|
-
const format = this.fileDirectory.SampleFormat ? this.fileDirectory.SampleFormat[sampleIndex] : 1;
|
|
646
|
-
const bitsPerSample = this.fileDirectory.BitsPerSample[sampleIndex];
|
|
647
|
-
switch (format) {
|
|
648
|
-
case 1:
|
|
649
|
-
if (bitsPerSample <= 8) {
|
|
650
|
-
return DataView.prototype.getUint8;
|
|
651
|
-
} else if (bitsPerSample <= 16) {
|
|
652
|
-
return DataView.prototype.getUint16;
|
|
653
|
-
} else if (bitsPerSample <= 32) {
|
|
654
|
-
return DataView.prototype.getUint32;
|
|
655
|
-
}
|
|
656
|
-
break;
|
|
657
|
-
case 2:
|
|
658
|
-
if (bitsPerSample <= 8) {
|
|
659
|
-
return DataView.prototype.getInt8;
|
|
660
|
-
} else if (bitsPerSample <= 16) {
|
|
661
|
-
return DataView.prototype.getInt16;
|
|
662
|
-
} else if (bitsPerSample <= 32) {
|
|
663
|
-
return DataView.prototype.getInt32;
|
|
664
|
-
}
|
|
665
|
-
break;
|
|
666
|
-
case 3:
|
|
667
|
-
switch (bitsPerSample) {
|
|
668
|
-
case 16:
|
|
669
|
-
return function(offset, littleEndian) {
|
|
670
|
-
return getFloat16(this, offset, littleEndian);
|
|
671
|
-
};
|
|
672
|
-
case 32:
|
|
673
|
-
return DataView.prototype.getFloat32;
|
|
674
|
-
case 64:
|
|
675
|
-
return DataView.prototype.getFloat64;
|
|
676
|
-
}
|
|
677
|
-
break;
|
|
678
|
-
}
|
|
679
|
-
throw Error("Unsupported data format/bitsPerSample");
|
|
680
|
-
}
|
|
681
|
-
getSampleFormat(sampleIndex = 0) {
|
|
682
|
-
return this.fileDirectory.SampleFormat ? this.fileDirectory.SampleFormat[sampleIndex] : 1;
|
|
683
|
-
}
|
|
684
|
-
getBitsPerSample(sampleIndex = 0) {
|
|
685
|
-
return this.fileDirectory.BitsPerSample[sampleIndex];
|
|
686
|
-
}
|
|
687
|
-
getArrayForSample(sampleIndex, size) {
|
|
688
|
-
const format = this.getSampleFormat(sampleIndex);
|
|
689
|
-
const bitsPerSample = this.getBitsPerSample(sampleIndex);
|
|
690
|
-
return arrayForType(format, bitsPerSample, size);
|
|
691
|
-
}
|
|
692
|
-
async getTileOrStrip(x, y, sample, poolOrDecoder, signal) {
|
|
693
|
-
const numTilesPerRow = Math.ceil(this.getWidth() / this.getTileWidth());
|
|
694
|
-
const numTilesPerCol = Math.ceil(this.getHeight() / this.getTileHeight());
|
|
695
|
-
let index;
|
|
696
|
-
const { tiles } = this;
|
|
697
|
-
if (this.planarConfiguration === 1) {
|
|
698
|
-
index = y * numTilesPerRow + x;
|
|
699
|
-
} else if (this.planarConfiguration === 2) {
|
|
700
|
-
index = sample * numTilesPerRow * numTilesPerCol + y * numTilesPerRow + x;
|
|
701
|
-
}
|
|
702
|
-
let offset;
|
|
703
|
-
let byteCount;
|
|
704
|
-
if (this.isTiled) {
|
|
705
|
-
offset = this.fileDirectory.TileOffsets[index];
|
|
706
|
-
byteCount = this.fileDirectory.TileByteCounts[index];
|
|
707
|
-
} else {
|
|
708
|
-
offset = this.fileDirectory.StripOffsets[index];
|
|
709
|
-
byteCount = this.fileDirectory.StripByteCounts[index];
|
|
710
|
-
}
|
|
711
|
-
const slice = (await this.source.fetch([{ offset, length: byteCount }], signal))[0];
|
|
712
|
-
let request;
|
|
713
|
-
if (tiles === null || !tiles[index]) {
|
|
714
|
-
request = (async () => {
|
|
715
|
-
let data = await poolOrDecoder.decode(this.fileDirectory, slice);
|
|
716
|
-
const sampleFormat = this.getSampleFormat();
|
|
717
|
-
const bitsPerSample = this.getBitsPerSample();
|
|
718
|
-
if (needsNormalization(sampleFormat, bitsPerSample)) {
|
|
719
|
-
data = normalizeArray(
|
|
720
|
-
data,
|
|
721
|
-
sampleFormat,
|
|
722
|
-
this.planarConfiguration,
|
|
723
|
-
this.getSamplesPerPixel(),
|
|
724
|
-
bitsPerSample,
|
|
725
|
-
this.getTileWidth(),
|
|
726
|
-
this.getBlockHeight(y)
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
return data;
|
|
730
|
-
})();
|
|
731
|
-
if (tiles !== null) {
|
|
732
|
-
tiles[index] = request;
|
|
733
|
-
}
|
|
734
|
-
} else {
|
|
735
|
-
request = tiles[index];
|
|
736
|
-
}
|
|
737
|
-
return { x, y, sample, data: await request };
|
|
738
|
-
}
|
|
739
|
-
async _readRaster(imageWindow, samples, valueArrays, interleave, poolOrDecoder, width, height, resampleMethod, signal) {
|
|
740
|
-
const tileWidth = this.getTileWidth();
|
|
741
|
-
const tileHeight = this.getTileHeight();
|
|
742
|
-
const imageWidth = this.getWidth();
|
|
743
|
-
const imageHeight = this.getHeight();
|
|
744
|
-
const minXTile = Math.max(Math.floor(imageWindow[0] / tileWidth), 0);
|
|
745
|
-
const maxXTile = Math.min(
|
|
746
|
-
Math.ceil(imageWindow[2] / tileWidth),
|
|
747
|
-
Math.ceil(imageWidth / tileWidth)
|
|
748
|
-
);
|
|
749
|
-
const minYTile = Math.max(Math.floor(imageWindow[1] / tileHeight), 0);
|
|
750
|
-
const maxYTile = Math.min(
|
|
751
|
-
Math.ceil(imageWindow[3] / tileHeight),
|
|
752
|
-
Math.ceil(imageHeight / tileHeight)
|
|
753
|
-
);
|
|
754
|
-
const windowWidth = imageWindow[2] - imageWindow[0];
|
|
755
|
-
let bytesPerPixel = this.getBytesPerPixel();
|
|
756
|
-
const srcSampleOffsets = [];
|
|
757
|
-
const sampleReaders = [];
|
|
758
|
-
for (let i = 0; i < samples.length; ++i) {
|
|
759
|
-
if (this.planarConfiguration === 1) {
|
|
760
|
-
srcSampleOffsets.push(sum(this.fileDirectory.BitsPerSample, 0, samples[i]) / 8);
|
|
761
|
-
} else {
|
|
762
|
-
srcSampleOffsets.push(0);
|
|
763
|
-
}
|
|
764
|
-
sampleReaders.push(this.getReaderForSample(samples[i]));
|
|
765
|
-
}
|
|
766
|
-
const promises = [];
|
|
767
|
-
const { littleEndian } = this;
|
|
768
|
-
for (let yTile = minYTile; yTile < maxYTile; ++yTile) {
|
|
769
|
-
for (let xTile = minXTile; xTile < maxXTile; ++xTile) {
|
|
770
|
-
for (let sampleIndex = 0; sampleIndex < samples.length; ++sampleIndex) {
|
|
771
|
-
const si = sampleIndex;
|
|
772
|
-
const sample = samples[sampleIndex];
|
|
773
|
-
if (this.planarConfiguration === 2) {
|
|
774
|
-
bytesPerPixel = this.getSampleByteSize(sampleIndex);
|
|
775
|
-
}
|
|
776
|
-
const promise = this.getTileOrStrip(xTile, yTile, sample, poolOrDecoder, signal);
|
|
777
|
-
promises.push(promise);
|
|
778
|
-
promise.then((tile) => {
|
|
779
|
-
const buffer = tile.data;
|
|
780
|
-
const dataView = new DataView(buffer);
|
|
781
|
-
const blockHeight = this.getBlockHeight(tile.y);
|
|
782
|
-
const firstLine = tile.y * tileHeight;
|
|
783
|
-
const firstCol = tile.x * tileWidth;
|
|
784
|
-
const lastLine = firstLine + blockHeight;
|
|
785
|
-
const lastCol = (tile.x + 1) * tileWidth;
|
|
786
|
-
const reader = sampleReaders[si];
|
|
787
|
-
const ymax = Math.min(blockHeight, blockHeight - (lastLine - imageWindow[3]), imageHeight - firstLine);
|
|
788
|
-
const xmax = Math.min(tileWidth, tileWidth - (lastCol - imageWindow[2]), imageWidth - firstCol);
|
|
789
|
-
for (let y = Math.max(0, imageWindow[1] - firstLine); y < ymax; ++y) {
|
|
790
|
-
for (let x = Math.max(0, imageWindow[0] - firstCol); x < xmax; ++x) {
|
|
791
|
-
const pixelOffset = (y * tileWidth + x) * bytesPerPixel;
|
|
792
|
-
const value = reader.call(
|
|
793
|
-
dataView,
|
|
794
|
-
pixelOffset + srcSampleOffsets[si],
|
|
795
|
-
littleEndian
|
|
796
|
-
);
|
|
797
|
-
let windowCoordinate;
|
|
798
|
-
if (interleave) {
|
|
799
|
-
windowCoordinate = (y + firstLine - imageWindow[1]) * windowWidth * samples.length + (x + firstCol - imageWindow[0]) * samples.length + si;
|
|
800
|
-
valueArrays[windowCoordinate] = value;
|
|
801
|
-
} else {
|
|
802
|
-
windowCoordinate = (y + firstLine - imageWindow[1]) * windowWidth + x + firstCol - imageWindow[0];
|
|
803
|
-
valueArrays[si][windowCoordinate] = value;
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
await Promise.all(promises);
|
|
812
|
-
if (width && imageWindow[2] - imageWindow[0] !== width || height && imageWindow[3] - imageWindow[1] !== height) {
|
|
813
|
-
let resampled;
|
|
814
|
-
if (interleave) {
|
|
815
|
-
resampled = resampleInterleaved(
|
|
816
|
-
valueArrays,
|
|
817
|
-
imageWindow[2] - imageWindow[0],
|
|
818
|
-
imageWindow[3] - imageWindow[1],
|
|
819
|
-
width,
|
|
820
|
-
height,
|
|
821
|
-
samples.length,
|
|
822
|
-
resampleMethod
|
|
823
|
-
);
|
|
824
|
-
} else {
|
|
825
|
-
resampled = resample(
|
|
826
|
-
valueArrays,
|
|
827
|
-
imageWindow[2] - imageWindow[0],
|
|
828
|
-
imageWindow[3] - imageWindow[1],
|
|
829
|
-
width,
|
|
830
|
-
height,
|
|
831
|
-
resampleMethod
|
|
832
|
-
);
|
|
833
|
-
}
|
|
834
|
-
resampled.width = width;
|
|
835
|
-
resampled.height = height;
|
|
836
|
-
return resampled;
|
|
837
|
-
}
|
|
838
|
-
valueArrays.width = width || imageWindow[2] - imageWindow[0];
|
|
839
|
-
valueArrays.height = height || imageWindow[3] - imageWindow[1];
|
|
840
|
-
return valueArrays;
|
|
841
|
-
}
|
|
842
|
-
async readRasters({
|
|
843
|
-
window: wnd,
|
|
844
|
-
samples = [],
|
|
845
|
-
interleave,
|
|
846
|
-
pool = null,
|
|
847
|
-
width,
|
|
848
|
-
height,
|
|
849
|
-
resampleMethod,
|
|
850
|
-
fillValue,
|
|
851
|
-
signal
|
|
852
|
-
} = {}) {
|
|
853
|
-
const imageWindow = wnd || [0, 0, this.getWidth(), this.getHeight()];
|
|
854
|
-
if (imageWindow[0] > imageWindow[2] || imageWindow[1] > imageWindow[3]) {
|
|
855
|
-
throw new Error("Invalid subsets");
|
|
856
|
-
}
|
|
857
|
-
const imageWindowWidth = imageWindow[2] - imageWindow[0];
|
|
858
|
-
const imageWindowHeight = imageWindow[3] - imageWindow[1];
|
|
859
|
-
const numPixels = imageWindowWidth * imageWindowHeight;
|
|
860
|
-
const samplesPerPixel = this.getSamplesPerPixel();
|
|
861
|
-
if (!samples || !samples.length) {
|
|
862
|
-
for (let i = 0; i < samplesPerPixel; ++i) {
|
|
863
|
-
samples.push(i);
|
|
864
|
-
}
|
|
865
|
-
} else {
|
|
866
|
-
for (let i = 0; i < samples.length; ++i) {
|
|
867
|
-
if (samples[i] >= samplesPerPixel) {
|
|
868
|
-
return Promise.reject(new RangeError(`Invalid sample index '${samples[i]}'.`));
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
let valueArrays;
|
|
873
|
-
if (interleave) {
|
|
874
|
-
const format = this.fileDirectory.SampleFormat ? Math.max.apply(null, this.fileDirectory.SampleFormat) : 1;
|
|
875
|
-
const bitsPerSample = Math.max.apply(null, this.fileDirectory.BitsPerSample);
|
|
876
|
-
valueArrays = arrayForType(format, bitsPerSample, numPixels * samples.length);
|
|
877
|
-
if (fillValue) {
|
|
878
|
-
valueArrays.fill(fillValue);
|
|
879
|
-
}
|
|
880
|
-
} else {
|
|
881
|
-
valueArrays = [];
|
|
882
|
-
for (let i = 0; i < samples.length; ++i) {
|
|
883
|
-
const valueArray = this.getArrayForSample(samples[i], numPixels);
|
|
884
|
-
if (Array.isArray(fillValue) && i < fillValue.length) {
|
|
885
|
-
valueArray.fill(fillValue[i]);
|
|
886
|
-
} else if (fillValue && !Array.isArray(fillValue)) {
|
|
887
|
-
valueArray.fill(fillValue);
|
|
888
|
-
}
|
|
889
|
-
valueArrays.push(valueArray);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
const poolOrDecoder = pool || await getDecoder(this.fileDirectory);
|
|
893
|
-
const result = await this._readRaster(
|
|
894
|
-
imageWindow,
|
|
895
|
-
samples,
|
|
896
|
-
valueArrays,
|
|
897
|
-
interleave,
|
|
898
|
-
poolOrDecoder,
|
|
899
|
-
width,
|
|
900
|
-
height,
|
|
901
|
-
resampleMethod,
|
|
902
|
-
signal
|
|
903
|
-
);
|
|
904
|
-
return result;
|
|
905
|
-
}
|
|
906
|
-
async readRGB({
|
|
907
|
-
window,
|
|
908
|
-
interleave = true,
|
|
909
|
-
pool = null,
|
|
910
|
-
width,
|
|
911
|
-
height,
|
|
912
|
-
resampleMethod,
|
|
913
|
-
enableAlpha = false,
|
|
914
|
-
signal
|
|
915
|
-
} = {}) {
|
|
916
|
-
const imageWindow = window || [0, 0, this.getWidth(), this.getHeight()];
|
|
917
|
-
if (imageWindow[0] > imageWindow[2] || imageWindow[1] > imageWindow[3]) {
|
|
918
|
-
throw new Error("Invalid subsets");
|
|
919
|
-
}
|
|
920
|
-
const pi = this.fileDirectory.PhotometricInterpretation;
|
|
921
|
-
if (pi === photometricInterpretations.RGB) {
|
|
922
|
-
let s = [0, 1, 2];
|
|
923
|
-
if (!(this.fileDirectory.ExtraSamples === ExtraSamplesValues.Unspecified) && enableAlpha) {
|
|
924
|
-
s = [];
|
|
925
|
-
for (let i = 0; i < this.fileDirectory.BitsPerSample.length; i += 1) {
|
|
926
|
-
s.push(i);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
return this.readRasters({
|
|
930
|
-
window,
|
|
931
|
-
interleave,
|
|
932
|
-
samples: s,
|
|
933
|
-
pool,
|
|
934
|
-
width,
|
|
935
|
-
height,
|
|
936
|
-
resampleMethod,
|
|
937
|
-
signal
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
let samples;
|
|
941
|
-
switch (pi) {
|
|
942
|
-
case photometricInterpretations.WhiteIsZero:
|
|
943
|
-
case photometricInterpretations.BlackIsZero:
|
|
944
|
-
case photometricInterpretations.Palette:
|
|
945
|
-
samples = [0];
|
|
946
|
-
break;
|
|
947
|
-
case photometricInterpretations.CMYK:
|
|
948
|
-
samples = [0, 1, 2, 3];
|
|
949
|
-
break;
|
|
950
|
-
case photometricInterpretations.YCbCr:
|
|
951
|
-
case photometricInterpretations.CIELab:
|
|
952
|
-
samples = [0, 1, 2];
|
|
953
|
-
break;
|
|
954
|
-
default:
|
|
955
|
-
throw new Error("Invalid or unsupported photometric interpretation.");
|
|
956
|
-
}
|
|
957
|
-
const subOptions = {
|
|
958
|
-
window: imageWindow,
|
|
959
|
-
interleave: true,
|
|
960
|
-
samples,
|
|
961
|
-
pool,
|
|
962
|
-
width,
|
|
963
|
-
height,
|
|
964
|
-
resampleMethod,
|
|
965
|
-
signal
|
|
966
|
-
};
|
|
967
|
-
const { fileDirectory } = this;
|
|
968
|
-
const raster = await this.readRasters(subOptions);
|
|
969
|
-
const max = 2 ** this.fileDirectory.BitsPerSample[0];
|
|
970
|
-
let data;
|
|
971
|
-
switch (pi) {
|
|
972
|
-
case photometricInterpretations.WhiteIsZero:
|
|
973
|
-
data = fromWhiteIsZero(raster, max);
|
|
974
|
-
break;
|
|
975
|
-
case photometricInterpretations.BlackIsZero:
|
|
976
|
-
data = fromBlackIsZero(raster, max);
|
|
977
|
-
break;
|
|
978
|
-
case photometricInterpretations.Palette:
|
|
979
|
-
data = fromPalette(raster, fileDirectory.ColorMap);
|
|
980
|
-
break;
|
|
981
|
-
case photometricInterpretations.CMYK:
|
|
982
|
-
data = fromCMYK(raster);
|
|
983
|
-
break;
|
|
984
|
-
case photometricInterpretations.YCbCr:
|
|
985
|
-
data = fromYCbCr(raster);
|
|
986
|
-
break;
|
|
987
|
-
case photometricInterpretations.CIELab:
|
|
988
|
-
data = fromCIELab(raster);
|
|
989
|
-
break;
|
|
990
|
-
default:
|
|
991
|
-
throw new Error("Unsupported photometric interpretation.");
|
|
992
|
-
}
|
|
993
|
-
if (!interleave) {
|
|
994
|
-
const red = new Uint8Array(data.length / 3);
|
|
995
|
-
const green = new Uint8Array(data.length / 3);
|
|
996
|
-
const blue = new Uint8Array(data.length / 3);
|
|
997
|
-
for (let i = 0, j = 0; i < data.length; i += 3, ++j) {
|
|
998
|
-
red[j] = data[i];
|
|
999
|
-
green[j] = data[i + 1];
|
|
1000
|
-
blue[j] = data[i + 2];
|
|
1001
|
-
}
|
|
1002
|
-
data = [red, green, blue];
|
|
1003
|
-
}
|
|
1004
|
-
data.width = raster.width;
|
|
1005
|
-
data.height = raster.height;
|
|
1006
|
-
return data;
|
|
1007
|
-
}
|
|
1008
|
-
getTiePoints() {
|
|
1009
|
-
if (!this.fileDirectory.ModelTiepoint) {
|
|
1010
|
-
return [];
|
|
1011
|
-
}
|
|
1012
|
-
const tiePoints = [];
|
|
1013
|
-
for (let i = 0; i < this.fileDirectory.ModelTiepoint.length; i += 6) {
|
|
1014
|
-
tiePoints.push({
|
|
1015
|
-
i: this.fileDirectory.ModelTiepoint[i],
|
|
1016
|
-
j: this.fileDirectory.ModelTiepoint[i + 1],
|
|
1017
|
-
k: this.fileDirectory.ModelTiepoint[i + 2],
|
|
1018
|
-
x: this.fileDirectory.ModelTiepoint[i + 3],
|
|
1019
|
-
y: this.fileDirectory.ModelTiepoint[i + 4],
|
|
1020
|
-
z: this.fileDirectory.ModelTiepoint[i + 5]
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
return tiePoints;
|
|
1024
|
-
}
|
|
1025
|
-
getGDALMetadata(sample = null) {
|
|
1026
|
-
const metadata = {};
|
|
1027
|
-
if (!this.fileDirectory.GDAL_METADATA) {
|
|
1028
|
-
return null;
|
|
1029
|
-
}
|
|
1030
|
-
const string = this.fileDirectory.GDAL_METADATA;
|
|
1031
|
-
let items = findTagsByName(string, "Item");
|
|
1032
|
-
if (sample === null) {
|
|
1033
|
-
items = items.filter((item) => getAttribute(item, "sample") === void 0);
|
|
1034
|
-
} else {
|
|
1035
|
-
items = items.filter((item) => Number(getAttribute(item, "sample")) === sample);
|
|
1036
|
-
}
|
|
1037
|
-
for (let i = 0; i < items.length; ++i) {
|
|
1038
|
-
const item = items[i];
|
|
1039
|
-
metadata[getAttribute(item, "name")] = item.inner;
|
|
1040
|
-
}
|
|
1041
|
-
return metadata;
|
|
1042
|
-
}
|
|
1043
|
-
getGDALNoData() {
|
|
1044
|
-
if (!this.fileDirectory.GDAL_NODATA) {
|
|
1045
|
-
return null;
|
|
1046
|
-
}
|
|
1047
|
-
const string = this.fileDirectory.GDAL_NODATA;
|
|
1048
|
-
return Number(string.substring(0, string.length - 1));
|
|
1049
|
-
}
|
|
1050
|
-
getOrigin() {
|
|
1051
|
-
const tiePoints = this.fileDirectory.ModelTiepoint;
|
|
1052
|
-
const modelTransformation = this.fileDirectory.ModelTransformation;
|
|
1053
|
-
if (tiePoints && tiePoints.length === 6) {
|
|
1054
|
-
return [
|
|
1055
|
-
tiePoints[3],
|
|
1056
|
-
tiePoints[4],
|
|
1057
|
-
tiePoints[5]
|
|
1058
|
-
];
|
|
1059
|
-
}
|
|
1060
|
-
if (modelTransformation) {
|
|
1061
|
-
return [
|
|
1062
|
-
modelTransformation[3],
|
|
1063
|
-
modelTransformation[7],
|
|
1064
|
-
modelTransformation[11]
|
|
1065
|
-
];
|
|
1066
|
-
}
|
|
1067
|
-
throw new Error("The image does not have an affine transformation.");
|
|
1068
|
-
}
|
|
1069
|
-
getResolution(referenceImage = null) {
|
|
1070
|
-
const modelPixelScale = this.fileDirectory.ModelPixelScale;
|
|
1071
|
-
const modelTransformation = this.fileDirectory.ModelTransformation;
|
|
1072
|
-
if (modelPixelScale) {
|
|
1073
|
-
return [
|
|
1074
|
-
modelPixelScale[0],
|
|
1075
|
-
-modelPixelScale[1],
|
|
1076
|
-
modelPixelScale[2]
|
|
1077
|
-
];
|
|
1078
|
-
}
|
|
1079
|
-
if (modelTransformation) {
|
|
1080
|
-
return [
|
|
1081
|
-
modelTransformation[0],
|
|
1082
|
-
modelTransformation[5],
|
|
1083
|
-
modelTransformation[10]
|
|
1084
|
-
];
|
|
1085
|
-
}
|
|
1086
|
-
if (referenceImage) {
|
|
1087
|
-
const [refResX, refResY, refResZ] = referenceImage.getResolution();
|
|
1088
|
-
return [
|
|
1089
|
-
refResX * referenceImage.getWidth() / this.getWidth(),
|
|
1090
|
-
refResY * referenceImage.getHeight() / this.getHeight(),
|
|
1091
|
-
refResZ * referenceImage.getWidth() / this.getWidth()
|
|
1092
|
-
];
|
|
1093
|
-
}
|
|
1094
|
-
throw new Error("The image does not have an affine transformation.");
|
|
1095
|
-
}
|
|
1096
|
-
pixelIsArea() {
|
|
1097
|
-
return this.geoKeys.GTRasterTypeGeoKey === 1;
|
|
1098
|
-
}
|
|
1099
|
-
getBoundingBox() {
|
|
1100
|
-
const origin = this.getOrigin();
|
|
1101
|
-
const resolution = this.getResolution();
|
|
1102
|
-
const x1 = origin[0];
|
|
1103
|
-
const y1 = origin[1];
|
|
1104
|
-
const x2 = x1 + resolution[0] * this.getWidth();
|
|
1105
|
-
const y2 = y1 + resolution[1] * this.getHeight();
|
|
1106
|
-
return [
|
|
1107
|
-
Math.min(x1, x2),
|
|
1108
|
-
Math.min(y1, y2),
|
|
1109
|
-
Math.max(x1, x2),
|
|
1110
|
-
Math.max(y1, y2)
|
|
1111
|
-
];
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
var GeoTIFFImage$1 = GeoTIFFImage;
|
|
1115
|
-
class DataView64 {
|
|
1116
|
-
constructor(arrayBuffer) {
|
|
1117
|
-
this._dataView = new DataView(arrayBuffer);
|
|
1118
|
-
}
|
|
1119
|
-
get buffer() {
|
|
1120
|
-
return this._dataView.buffer;
|
|
1121
|
-
}
|
|
1122
|
-
getUint64(offset, littleEndian) {
|
|
1123
|
-
const left = this.getUint32(offset, littleEndian);
|
|
1124
|
-
const right = this.getUint32(offset + 4, littleEndian);
|
|
1125
|
-
let combined;
|
|
1126
|
-
if (littleEndian) {
|
|
1127
|
-
combined = left + 2 ** 32 * right;
|
|
1128
|
-
if (!Number.isSafeInteger(combined)) {
|
|
1129
|
-
throw new Error(
|
|
1130
|
-
`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
return combined;
|
|
1134
|
-
}
|
|
1135
|
-
combined = 2 ** 32 * left + right;
|
|
1136
|
-
if (!Number.isSafeInteger(combined)) {
|
|
1137
|
-
throw new Error(
|
|
1138
|
-
`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1139
|
-
);
|
|
1140
|
-
}
|
|
1141
|
-
return combined;
|
|
1142
|
-
}
|
|
1143
|
-
getInt64(offset, littleEndian) {
|
|
1144
|
-
let value = 0;
|
|
1145
|
-
const isNegative = (this._dataView.getUint8(offset + (littleEndian ? 7 : 0)) & 128) > 0;
|
|
1146
|
-
let carrying = true;
|
|
1147
|
-
for (let i = 0; i < 8; i++) {
|
|
1148
|
-
let byte = this._dataView.getUint8(offset + (littleEndian ? i : 7 - i));
|
|
1149
|
-
if (isNegative) {
|
|
1150
|
-
if (carrying) {
|
|
1151
|
-
if (byte !== 0) {
|
|
1152
|
-
byte = ~(byte - 1) & 255;
|
|
1153
|
-
carrying = false;
|
|
1154
|
-
}
|
|
1155
|
-
} else {
|
|
1156
|
-
byte = ~byte & 255;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
value += byte * 256 ** i;
|
|
1160
|
-
}
|
|
1161
|
-
if (isNegative) {
|
|
1162
|
-
value = -value;
|
|
1163
|
-
}
|
|
1164
|
-
return value;
|
|
1165
|
-
}
|
|
1166
|
-
getUint8(offset, littleEndian) {
|
|
1167
|
-
return this._dataView.getUint8(offset, littleEndian);
|
|
1168
|
-
}
|
|
1169
|
-
getInt8(offset, littleEndian) {
|
|
1170
|
-
return this._dataView.getInt8(offset, littleEndian);
|
|
1171
|
-
}
|
|
1172
|
-
getUint16(offset, littleEndian) {
|
|
1173
|
-
return this._dataView.getUint16(offset, littleEndian);
|
|
1174
|
-
}
|
|
1175
|
-
getInt16(offset, littleEndian) {
|
|
1176
|
-
return this._dataView.getInt16(offset, littleEndian);
|
|
1177
|
-
}
|
|
1178
|
-
getUint32(offset, littleEndian) {
|
|
1179
|
-
return this._dataView.getUint32(offset, littleEndian);
|
|
1180
|
-
}
|
|
1181
|
-
getInt32(offset, littleEndian) {
|
|
1182
|
-
return this._dataView.getInt32(offset, littleEndian);
|
|
1183
|
-
}
|
|
1184
|
-
getFloat16(offset, littleEndian) {
|
|
1185
|
-
return getFloat16(this._dataView, offset, littleEndian);
|
|
1186
|
-
}
|
|
1187
|
-
getFloat32(offset, littleEndian) {
|
|
1188
|
-
return this._dataView.getFloat32(offset, littleEndian);
|
|
1189
|
-
}
|
|
1190
|
-
getFloat64(offset, littleEndian) {
|
|
1191
|
-
return this._dataView.getFloat64(offset, littleEndian);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
class DataSlice {
|
|
1195
|
-
constructor(arrayBuffer, sliceOffset, littleEndian, bigTiff) {
|
|
1196
|
-
this._dataView = new DataView(arrayBuffer);
|
|
1197
|
-
this._sliceOffset = sliceOffset;
|
|
1198
|
-
this._littleEndian = littleEndian;
|
|
1199
|
-
this._bigTiff = bigTiff;
|
|
1200
|
-
}
|
|
1201
|
-
get sliceOffset() {
|
|
1202
|
-
return this._sliceOffset;
|
|
1203
|
-
}
|
|
1204
|
-
get sliceTop() {
|
|
1205
|
-
return this._sliceOffset + this.buffer.byteLength;
|
|
1206
|
-
}
|
|
1207
|
-
get littleEndian() {
|
|
1208
|
-
return this._littleEndian;
|
|
1209
|
-
}
|
|
1210
|
-
get bigTiff() {
|
|
1211
|
-
return this._bigTiff;
|
|
1212
|
-
}
|
|
1213
|
-
get buffer() {
|
|
1214
|
-
return this._dataView.buffer;
|
|
1215
|
-
}
|
|
1216
|
-
covers(offset, length) {
|
|
1217
|
-
return this.sliceOffset <= offset && this.sliceTop >= offset + length;
|
|
1218
|
-
}
|
|
1219
|
-
readUint8(offset) {
|
|
1220
|
-
return this._dataView.getUint8(
|
|
1221
|
-
offset - this._sliceOffset,
|
|
1222
|
-
this._littleEndian
|
|
1223
|
-
);
|
|
1224
|
-
}
|
|
1225
|
-
readInt8(offset) {
|
|
1226
|
-
return this._dataView.getInt8(
|
|
1227
|
-
offset - this._sliceOffset,
|
|
1228
|
-
this._littleEndian
|
|
1229
|
-
);
|
|
1230
|
-
}
|
|
1231
|
-
readUint16(offset) {
|
|
1232
|
-
return this._dataView.getUint16(
|
|
1233
|
-
offset - this._sliceOffset,
|
|
1234
|
-
this._littleEndian
|
|
1235
|
-
);
|
|
1236
|
-
}
|
|
1237
|
-
readInt16(offset) {
|
|
1238
|
-
return this._dataView.getInt16(
|
|
1239
|
-
offset - this._sliceOffset,
|
|
1240
|
-
this._littleEndian
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
readUint32(offset) {
|
|
1244
|
-
return this._dataView.getUint32(
|
|
1245
|
-
offset - this._sliceOffset,
|
|
1246
|
-
this._littleEndian
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
readInt32(offset) {
|
|
1250
|
-
return this._dataView.getInt32(
|
|
1251
|
-
offset - this._sliceOffset,
|
|
1252
|
-
this._littleEndian
|
|
1253
|
-
);
|
|
1254
|
-
}
|
|
1255
|
-
readFloat32(offset) {
|
|
1256
|
-
return this._dataView.getFloat32(
|
|
1257
|
-
offset - this._sliceOffset,
|
|
1258
|
-
this._littleEndian
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
readFloat64(offset) {
|
|
1262
|
-
return this._dataView.getFloat64(
|
|
1263
|
-
offset - this._sliceOffset,
|
|
1264
|
-
this._littleEndian
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
readUint64(offset) {
|
|
1268
|
-
const left = this.readUint32(offset);
|
|
1269
|
-
const right = this.readUint32(offset + 4);
|
|
1270
|
-
let combined;
|
|
1271
|
-
if (this._littleEndian) {
|
|
1272
|
-
combined = left + 2 ** 32 * right;
|
|
1273
|
-
if (!Number.isSafeInteger(combined)) {
|
|
1274
|
-
throw new Error(
|
|
1275
|
-
`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1276
|
-
);
|
|
1277
|
-
}
|
|
1278
|
-
return combined;
|
|
1279
|
-
}
|
|
1280
|
-
combined = 2 ** 32 * left + right;
|
|
1281
|
-
if (!Number.isSafeInteger(combined)) {
|
|
1282
|
-
throw new Error(
|
|
1283
|
-
`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
|
|
1284
|
-
);
|
|
1285
|
-
}
|
|
1286
|
-
return combined;
|
|
1287
|
-
}
|
|
1288
|
-
readInt64(offset) {
|
|
1289
|
-
let value = 0;
|
|
1290
|
-
const isNegative = (this._dataView.getUint8(offset + (this._littleEndian ? 7 : 0)) & 128) > 0;
|
|
1291
|
-
let carrying = true;
|
|
1292
|
-
for (let i = 0; i < 8; i++) {
|
|
1293
|
-
let byte = this._dataView.getUint8(
|
|
1294
|
-
offset + (this._littleEndian ? i : 7 - i)
|
|
1295
|
-
);
|
|
1296
|
-
if (isNegative) {
|
|
1297
|
-
if (carrying) {
|
|
1298
|
-
if (byte !== 0) {
|
|
1299
|
-
byte = ~(byte - 1) & 255;
|
|
1300
|
-
carrying = false;
|
|
1301
|
-
}
|
|
1302
|
-
} else {
|
|
1303
|
-
byte = ~byte & 255;
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
value += byte * 256 ** i;
|
|
1307
|
-
}
|
|
1308
|
-
if (isNegative) {
|
|
1309
|
-
value = -value;
|
|
1310
|
-
}
|
|
1311
|
-
return value;
|
|
1312
|
-
}
|
|
1313
|
-
readOffset(offset) {
|
|
1314
|
-
if (this._bigTiff) {
|
|
1315
|
-
return this.readUint64(offset);
|
|
1316
|
-
}
|
|
1317
|
-
return this.readUint32(offset);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
const defaultPoolSize = typeof navigator !== "undefined" ? navigator.hardwareConcurrency || 2 : 2;
|
|
1321
|
-
class Pool {
|
|
1322
|
-
constructor(size = defaultPoolSize, createWorker) {
|
|
1323
|
-
this.workers = null;
|
|
1324
|
-
this._awaitingDecoder = null;
|
|
1325
|
-
this.size = size;
|
|
1326
|
-
this.messageId = 0;
|
|
1327
|
-
if (size) {
|
|
1328
|
-
this._awaitingDecoder = createWorker ? Promise.resolve(createWorker) : new Promise((resolve) => {
|
|
1329
|
-
Promise.resolve().then(function() {
|
|
1330
|
-
return decoder;
|
|
1331
|
-
}).then((module) => {
|
|
1332
|
-
resolve(module.create);
|
|
1333
|
-
});
|
|
1334
|
-
});
|
|
1335
|
-
this._awaitingDecoder.then((create2) => {
|
|
1336
|
-
this._awaitingDecoder = null;
|
|
1337
|
-
this.workers = [];
|
|
1338
|
-
for (let i = 0; i < size; i++) {
|
|
1339
|
-
this.workers.push({ worker: create2(), idle: true });
|
|
1340
|
-
}
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
async decode(fileDirectory, buffer) {
|
|
1345
|
-
if (this._awaitingDecoder) {
|
|
1346
|
-
await this._awaitingDecoder;
|
|
1347
|
-
}
|
|
1348
|
-
return this.size === 0 ? getDecoder(fileDirectory).then((decoder2) => decoder2.decode(fileDirectory, buffer)) : new Promise((resolve) => {
|
|
1349
|
-
const worker = this.workers.find((candidate) => candidate.idle) || this.workers[Math.floor(Math.random() * this.size)];
|
|
1350
|
-
worker.idle = false;
|
|
1351
|
-
const id = this.messageId++;
|
|
1352
|
-
const onMessage = (e) => {
|
|
1353
|
-
if (e.data.id === id) {
|
|
1354
|
-
worker.idle = true;
|
|
1355
|
-
resolve(e.data.decoded);
|
|
1356
|
-
worker.worker.removeEventListener("message", onMessage);
|
|
1357
|
-
}
|
|
1358
|
-
};
|
|
1359
|
-
worker.worker.addEventListener("message", onMessage);
|
|
1360
|
-
worker.worker.postMessage({ fileDirectory, buffer, id }, [buffer]);
|
|
1361
|
-
});
|
|
1362
|
-
}
|
|
1363
|
-
destroy() {
|
|
1364
|
-
if (this.workers) {
|
|
1365
|
-
this.workers.forEach((worker) => {
|
|
1366
|
-
worker.worker.terminate();
|
|
1367
|
-
});
|
|
1368
|
-
this.workers = null;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
var Pool$1 = Pool;
|
|
1373
|
-
const CRLFCRLF = "\r\n\r\n";
|
|
1374
|
-
function itemsToObject(items) {
|
|
1375
|
-
if (typeof Object.fromEntries !== "undefined") {
|
|
1376
|
-
return Object.fromEntries(items);
|
|
1377
|
-
}
|
|
1378
|
-
const obj = {};
|
|
1379
|
-
for (const [key, value] of items) {
|
|
1380
|
-
obj[key.toLowerCase()] = value;
|
|
1381
|
-
}
|
|
1382
|
-
return obj;
|
|
1383
|
-
}
|
|
1384
|
-
function parseHeaders(text) {
|
|
1385
|
-
const items = text.split("\r\n").map((line) => {
|
|
1386
|
-
const kv = line.split(":").map((str) => str.trim());
|
|
1387
|
-
kv[0] = kv[0].toLowerCase();
|
|
1388
|
-
return kv;
|
|
1389
|
-
});
|
|
1390
|
-
return itemsToObject(items);
|
|
1391
|
-
}
|
|
1392
|
-
function parseContentType(rawContentType) {
|
|
1393
|
-
const [type, ...rawParams] = rawContentType.split(";").map((s) => s.trim());
|
|
1394
|
-
const paramsItems = rawParams.map((param) => param.split("="));
|
|
1395
|
-
return { type, params: itemsToObject(paramsItems) };
|
|
1396
|
-
}
|
|
1397
|
-
function parseContentRange(rawContentRange) {
|
|
1398
|
-
let start;
|
|
1399
|
-
let end;
|
|
1400
|
-
let total;
|
|
1401
|
-
if (rawContentRange) {
|
|
1402
|
-
[, start, end, total] = rawContentRange.match(/bytes (\d+)-(\d+)\/(\d+)/);
|
|
1403
|
-
start = parseInt(start, 10);
|
|
1404
|
-
end = parseInt(end, 10);
|
|
1405
|
-
total = parseInt(total, 10);
|
|
1406
|
-
}
|
|
1407
|
-
return { start, end, total };
|
|
1408
|
-
}
|
|
1409
|
-
function parseByteRanges(responseArrayBuffer, boundary) {
|
|
1410
|
-
let offset = null;
|
|
1411
|
-
const decoder2 = new TextDecoder("ascii");
|
|
1412
|
-
const out = [];
|
|
1413
|
-
const startBoundary = `--${boundary}`;
|
|
1414
|
-
const endBoundary = `${startBoundary}--`;
|
|
1415
|
-
for (let i = 0; i < 10; ++i) {
|
|
1416
|
-
const text = decoder2.decode(
|
|
1417
|
-
new Uint8Array(responseArrayBuffer, i, startBoundary.length)
|
|
1418
|
-
);
|
|
1419
|
-
if (text === startBoundary) {
|
|
1420
|
-
offset = i;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
if (offset === null) {
|
|
1424
|
-
throw new Error("Could not find initial boundary");
|
|
1425
|
-
}
|
|
1426
|
-
while (offset < responseArrayBuffer.byteLength) {
|
|
1427
|
-
const text = decoder2.decode(
|
|
1428
|
-
new Uint8Array(
|
|
1429
|
-
responseArrayBuffer,
|
|
1430
|
-
offset,
|
|
1431
|
-
Math.min(startBoundary.length + 1024, responseArrayBuffer.byteLength - offset)
|
|
1432
|
-
)
|
|
1433
|
-
);
|
|
1434
|
-
if (text.length === 0 || text.startsWith(endBoundary)) {
|
|
1435
|
-
break;
|
|
1436
|
-
}
|
|
1437
|
-
if (!text.startsWith(startBoundary)) {
|
|
1438
|
-
throw new Error("Part does not start with boundary");
|
|
1439
|
-
}
|
|
1440
|
-
const innerText = text.substr(startBoundary.length + 2);
|
|
1441
|
-
if (innerText.length === 0) {
|
|
1442
|
-
break;
|
|
1443
|
-
}
|
|
1444
|
-
const endOfHeaders = innerText.indexOf(CRLFCRLF);
|
|
1445
|
-
const headers = parseHeaders(innerText.substr(0, endOfHeaders));
|
|
1446
|
-
const { start, end, total } = parseContentRange(headers["content-range"]);
|
|
1447
|
-
const startOfData = offset + startBoundary.length + endOfHeaders + CRLFCRLF.length;
|
|
1448
|
-
const length = parseInt(end, 10) + 1 - parseInt(start, 10);
|
|
1449
|
-
out.push({
|
|
1450
|
-
headers,
|
|
1451
|
-
data: responseArrayBuffer.slice(startOfData, startOfData + length),
|
|
1452
|
-
offset: start,
|
|
1453
|
-
length,
|
|
1454
|
-
fileSize: total
|
|
1455
|
-
});
|
|
1456
|
-
offset = startOfData + length + 4;
|
|
1457
|
-
}
|
|
1458
|
-
return out;
|
|
1459
|
-
}
|
|
1460
|
-
class BaseSource {
|
|
1461
|
-
async fetch(slices, signal = void 0) {
|
|
1462
|
-
return Promise.all(
|
|
1463
|
-
slices.map((slice) => this.fetchSlice(slice, signal))
|
|
1464
|
-
);
|
|
1465
|
-
}
|
|
1466
|
-
async fetchSlice(slice) {
|
|
1467
|
-
throw new Error(`fetching of slice ${slice} not possible, not implemented`);
|
|
1468
|
-
}
|
|
1469
|
-
get fileSize() {
|
|
1470
|
-
return null;
|
|
1471
|
-
}
|
|
1472
|
-
async close() {
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
async function wait(milliseconds) {
|
|
1476
|
-
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
1477
|
-
}
|
|
1478
|
-
function zip(a, b) {
|
|
1479
|
-
const A = Array.isArray(a) ? a : Array.from(a);
|
|
1480
|
-
const B = Array.isArray(b) ? b : Array.from(b);
|
|
1481
|
-
return A.map((k, i) => [k, B[i]]);
|
|
1482
|
-
}
|
|
1483
|
-
class AbortError extends Error {
|
|
1484
|
-
constructor(params) {
|
|
1485
|
-
super(params);
|
|
1486
|
-
if (Error.captureStackTrace) {
|
|
1487
|
-
Error.captureStackTrace(this, AbortError);
|
|
1488
|
-
}
|
|
1489
|
-
this.name = "AbortError";
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
class CustomAggregateError extends Error {
|
|
1493
|
-
constructor(errors, message) {
|
|
1494
|
-
super(message);
|
|
1495
|
-
this.errors = errors;
|
|
1496
|
-
this.message = message;
|
|
1497
|
-
this.name = "AggregateError";
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
const AggregateError = CustomAggregateError;
|
|
1501
|
-
class Block {
|
|
1502
|
-
constructor(offset, length, data = null) {
|
|
1503
|
-
this.offset = offset;
|
|
1504
|
-
this.length = length;
|
|
1505
|
-
this.data = data;
|
|
1506
|
-
}
|
|
1507
|
-
get top() {
|
|
1508
|
-
return this.offset + this.length;
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
class BlockGroup {
|
|
1512
|
-
constructor(offset, length, blockIds) {
|
|
1513
|
-
this.offset = offset;
|
|
1514
|
-
this.length = length;
|
|
1515
|
-
this.blockIds = blockIds;
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
class BlockedSource extends BaseSource {
|
|
1519
|
-
constructor(source, { blockSize = 65536, cacheSize = 100 } = {}) {
|
|
1520
|
-
super();
|
|
1521
|
-
this.source = source;
|
|
1522
|
-
this.blockSize = blockSize;
|
|
1523
|
-
this.blockCache = new _lruCache_6_0_0_lruCache({ max: cacheSize });
|
|
1524
|
-
this.blockRequests = /* @__PURE__ */ new Map();
|
|
1525
|
-
this.blockIdsToFetch = /* @__PURE__ */ new Set();
|
|
1526
|
-
}
|
|
1527
|
-
get fileSize() {
|
|
1528
|
-
return this.source.fileSize;
|
|
1529
|
-
}
|
|
1530
|
-
async fetch(slices, signal) {
|
|
1531
|
-
const cachedBlocks = /* @__PURE__ */ new Map();
|
|
1532
|
-
const blockRequests = /* @__PURE__ */ new Map();
|
|
1533
|
-
const missingBlockIds = /* @__PURE__ */ new Set();
|
|
1534
|
-
for (const { offset, length } of slices) {
|
|
1535
|
-
let top = offset + length;
|
|
1536
|
-
const { fileSize } = this;
|
|
1537
|
-
if (fileSize !== null) {
|
|
1538
|
-
top = Math.min(top, fileSize);
|
|
1539
|
-
}
|
|
1540
|
-
const firstBlockOffset = Math.floor(offset / this.blockSize) * this.blockSize;
|
|
1541
|
-
for (let current = firstBlockOffset; current < top; current += this.blockSize) {
|
|
1542
|
-
const blockId = Math.floor(current / this.blockSize);
|
|
1543
|
-
if (this.blockCache.has(blockId)) {
|
|
1544
|
-
cachedBlocks.set(blockId, this.blockCache.get(blockId));
|
|
1545
|
-
} else if (this.blockRequests.has(blockId)) {
|
|
1546
|
-
blockRequests.set(blockId, this.blockRequests.get(blockId));
|
|
1547
|
-
} else if (this.blockIdsToFetch.has(blockId)) {
|
|
1548
|
-
missingBlockIds.add(blockId);
|
|
1549
|
-
} else {
|
|
1550
|
-
this.blockIdsToFetch.add(blockId);
|
|
1551
|
-
missingBlockIds.add(blockId);
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
await wait();
|
|
1556
|
-
this.fetchBlocks(signal);
|
|
1557
|
-
for (const blockId of missingBlockIds) {
|
|
1558
|
-
const block = this.blockRequests.get(blockId);
|
|
1559
|
-
const cachedBlock = this.blockCache.get(blockId);
|
|
1560
|
-
if (block) {
|
|
1561
|
-
blockRequests.set(blockId, block);
|
|
1562
|
-
} else if (cachedBlock) {
|
|
1563
|
-
cachedBlocks.set(blockId, cachedBlock);
|
|
1564
|
-
} else {
|
|
1565
|
-
throw new Error(`Block ${blockId} is not in the block requests`);
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
let results = await Promise.allSettled(Array.from(blockRequests.values()));
|
|
1569
|
-
if (results.some((result) => result.status === "rejected")) {
|
|
1570
|
-
const retriedBlockRequests = /* @__PURE__ */ new Set();
|
|
1571
|
-
for (const [blockId, result] of zip(blockRequests.keys(), results)) {
|
|
1572
|
-
const { rejected, reason } = result;
|
|
1573
|
-
if (rejected) {
|
|
1574
|
-
if (reason.name === "AbortError" && reason.signal !== signal) {
|
|
1575
|
-
this.blockIdsToFetch.add(blockId);
|
|
1576
|
-
retriedBlockRequests.add(blockId);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
if (this.blockIdsToFetch.length > 0) {
|
|
1581
|
-
this.fetchBlocks(signal);
|
|
1582
|
-
for (const blockId of retriedBlockRequests) {
|
|
1583
|
-
const block = this.blockRequests.get(blockId);
|
|
1584
|
-
if (!block) {
|
|
1585
|
-
throw new Error(`Block ${blockId} is not in the block requests`);
|
|
1586
|
-
}
|
|
1587
|
-
blockRequests.set(blockId, block);
|
|
1588
|
-
}
|
|
1589
|
-
results = await Promise.allSettled(Array.from(blockRequests.values()));
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
if (results.some((result) => result.status === "rejected")) {
|
|
1593
|
-
if (signal && signal.aborted) {
|
|
1594
|
-
throw new AbortError("Request was aborted");
|
|
1595
|
-
}
|
|
1596
|
-
throw new AggregateError(
|
|
1597
|
-
results.filter((result) => result.status === "rejected").map((result) => result.reason),
|
|
1598
|
-
"Request failed"
|
|
1599
|
-
);
|
|
1600
|
-
}
|
|
1601
|
-
const values = results.map((result) => result.value);
|
|
1602
|
-
const requiredBlocks = new Map(zip(Array.from(blockRequests.keys()), values));
|
|
1603
|
-
for (const [blockId, block] of cachedBlocks) {
|
|
1604
|
-
requiredBlocks.set(blockId, block);
|
|
1605
|
-
}
|
|
1606
|
-
return this.readSliceData(slices, requiredBlocks);
|
|
1607
|
-
}
|
|
1608
|
-
fetchBlocks(signal) {
|
|
1609
|
-
if (this.blockIdsToFetch.size > 0) {
|
|
1610
|
-
const groups = this.groupBlocks(this.blockIdsToFetch);
|
|
1611
|
-
const groupRequests = this.source.fetch(groups, signal);
|
|
1612
|
-
for (let groupIndex = 0; groupIndex < groups.length; ++groupIndex) {
|
|
1613
|
-
const group = groups[groupIndex];
|
|
1614
|
-
for (const blockId of group.blockIds) {
|
|
1615
|
-
const blockRequest = (async () => {
|
|
1616
|
-
try {
|
|
1617
|
-
const response = (await groupRequests)[groupIndex];
|
|
1618
|
-
const blockOffset = blockId * this.blockSize;
|
|
1619
|
-
const o = blockOffset - response.offset;
|
|
1620
|
-
const t = Math.min(o + this.blockSize, response.data.byteLength);
|
|
1621
|
-
const data = response.data.slice(o, t);
|
|
1622
|
-
const block = new Block(
|
|
1623
|
-
blockOffset,
|
|
1624
|
-
data.byteLength,
|
|
1625
|
-
data
|
|
1626
|
-
);
|
|
1627
|
-
this.blockCache.set(blockId, block);
|
|
1628
|
-
return block;
|
|
1629
|
-
} catch (err) {
|
|
1630
|
-
if (err.name === "AbortError") {
|
|
1631
|
-
err.signal = signal;
|
|
1632
|
-
}
|
|
1633
|
-
throw err;
|
|
1634
|
-
} finally {
|
|
1635
|
-
this.blockRequests.delete(blockId);
|
|
1636
|
-
}
|
|
1637
|
-
})();
|
|
1638
|
-
this.blockRequests.set(blockId, blockRequest);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
this.blockIdsToFetch.clear();
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
groupBlocks(blockIds) {
|
|
1645
|
-
const sortedBlockIds = Array.from(blockIds).sort((a, b) => a - b);
|
|
1646
|
-
if (sortedBlockIds.length === 0) {
|
|
1647
|
-
return [];
|
|
1648
|
-
}
|
|
1649
|
-
let current = [];
|
|
1650
|
-
let lastBlockId = null;
|
|
1651
|
-
const groups = [];
|
|
1652
|
-
for (const blockId of sortedBlockIds) {
|
|
1653
|
-
if (lastBlockId === null || lastBlockId + 1 === blockId) {
|
|
1654
|
-
current.push(blockId);
|
|
1655
|
-
lastBlockId = blockId;
|
|
1656
|
-
} else {
|
|
1657
|
-
groups.push(new BlockGroup(
|
|
1658
|
-
current[0] * this.blockSize,
|
|
1659
|
-
current.length * this.blockSize,
|
|
1660
|
-
current
|
|
1661
|
-
));
|
|
1662
|
-
current = [blockId];
|
|
1663
|
-
lastBlockId = blockId;
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
groups.push(new BlockGroup(
|
|
1667
|
-
current[0] * this.blockSize,
|
|
1668
|
-
current.length * this.blockSize,
|
|
1669
|
-
current
|
|
1670
|
-
));
|
|
1671
|
-
return groups;
|
|
1672
|
-
}
|
|
1673
|
-
readSliceData(slices, blocks) {
|
|
1674
|
-
return slices.map((slice) => {
|
|
1675
|
-
const top = slice.offset + slice.length;
|
|
1676
|
-
const blockIdLow = Math.floor(slice.offset / this.blockSize);
|
|
1677
|
-
const blockIdHigh = Math.floor((slice.offset + slice.length) / this.blockSize);
|
|
1678
|
-
const sliceData = new ArrayBuffer(slice.length);
|
|
1679
|
-
const sliceView = new Uint8Array(sliceData);
|
|
1680
|
-
for (let blockId = blockIdLow; blockId <= blockIdHigh; ++blockId) {
|
|
1681
|
-
const block = blocks.get(blockId);
|
|
1682
|
-
const delta = block.offset - slice.offset;
|
|
1683
|
-
const topDelta = block.top - top;
|
|
1684
|
-
let blockInnerOffset = 0;
|
|
1685
|
-
let rangeInnerOffset = 0;
|
|
1686
|
-
let usedBlockLength;
|
|
1687
|
-
if (delta < 0) {
|
|
1688
|
-
blockInnerOffset = -delta;
|
|
1689
|
-
} else if (delta > 0) {
|
|
1690
|
-
rangeInnerOffset = delta;
|
|
1691
|
-
}
|
|
1692
|
-
if (topDelta < 0) {
|
|
1693
|
-
usedBlockLength = block.length - blockInnerOffset;
|
|
1694
|
-
} else {
|
|
1695
|
-
usedBlockLength = top - block.offset - blockInnerOffset;
|
|
1696
|
-
}
|
|
1697
|
-
const blockView = new Uint8Array(block.data, blockInnerOffset, usedBlockLength);
|
|
1698
|
-
sliceView.set(blockView, rangeInnerOffset);
|
|
1699
|
-
}
|
|
1700
|
-
return sliceData;
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
class BaseResponse {
|
|
1705
|
-
get ok() {
|
|
1706
|
-
return this.status >= 200 && this.status <= 299;
|
|
1707
|
-
}
|
|
1708
|
-
get status() {
|
|
1709
|
-
throw new Error("not implemented");
|
|
1710
|
-
}
|
|
1711
|
-
getHeader(headerName) {
|
|
1712
|
-
throw new Error("not implemented");
|
|
1713
|
-
}
|
|
1714
|
-
async getData() {
|
|
1715
|
-
throw new Error("not implemented");
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
class BaseClient {
|
|
1719
|
-
constructor(url) {
|
|
1720
|
-
this.url = url;
|
|
1721
|
-
}
|
|
1722
|
-
async request({ headers, credentials, signal } = {}) {
|
|
1723
|
-
throw new Error("request is not implemented");
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
class FetchResponse extends BaseResponse {
|
|
1727
|
-
constructor(response) {
|
|
1728
|
-
super();
|
|
1729
|
-
this.response = response;
|
|
1730
|
-
}
|
|
1731
|
-
get status() {
|
|
1732
|
-
return this.response.status;
|
|
1733
|
-
}
|
|
1734
|
-
getHeader(name) {
|
|
1735
|
-
return this.response.headers.get(name);
|
|
1736
|
-
}
|
|
1737
|
-
async getData() {
|
|
1738
|
-
const data = this.response.arrayBuffer ? await this.response.arrayBuffer() : (await this.response.buffer()).buffer;
|
|
1739
|
-
return data;
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
class FetchClient extends BaseClient {
|
|
1743
|
-
constructor(url, credentials) {
|
|
1744
|
-
super(url);
|
|
1745
|
-
this.credentials = credentials;
|
|
1746
|
-
}
|
|
1747
|
-
async request({ headers, credentials, signal } = {}) {
|
|
1748
|
-
const response = await fetch(this.url, {
|
|
1749
|
-
headers,
|
|
1750
|
-
credentials,
|
|
1751
|
-
signal
|
|
1752
|
-
});
|
|
1753
|
-
return new FetchResponse(response);
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
class XHRResponse extends BaseResponse {
|
|
1757
|
-
constructor(xhr, data) {
|
|
1758
|
-
super();
|
|
1759
|
-
this.xhr = xhr;
|
|
1760
|
-
this.data = data;
|
|
1761
|
-
}
|
|
1762
|
-
get status() {
|
|
1763
|
-
return this.xhr.status;
|
|
1764
|
-
}
|
|
1765
|
-
getHeader(name) {
|
|
1766
|
-
return this.xhr.getResponseHeader(name);
|
|
1767
|
-
}
|
|
1768
|
-
async getData() {
|
|
1769
|
-
return this.data;
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
class XHRClient extends BaseClient {
|
|
1773
|
-
constructRequest(headers, signal) {
|
|
1774
|
-
return new Promise((resolve, reject) => {
|
|
1775
|
-
const xhr = new XMLHttpRequest();
|
|
1776
|
-
xhr.open("GET", this.url);
|
|
1777
|
-
xhr.responseType = "arraybuffer";
|
|
1778
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
1779
|
-
xhr.setRequestHeader(key, value);
|
|
1780
|
-
}
|
|
1781
|
-
xhr.onload = () => {
|
|
1782
|
-
const data = xhr.response;
|
|
1783
|
-
resolve(new XHRResponse(xhr, data));
|
|
1784
|
-
};
|
|
1785
|
-
xhr.onerror = reject;
|
|
1786
|
-
xhr.onabort = () => reject(new AbortError("Request aborted"));
|
|
1787
|
-
xhr.send();
|
|
1788
|
-
if (signal) {
|
|
1789
|
-
if (signal.aborted) {
|
|
1790
|
-
xhr.abort();
|
|
1791
|
-
}
|
|
1792
|
-
signal.addEventListener("abort", () => xhr.abort());
|
|
1793
|
-
}
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
async request({ headers, signal } = {}) {
|
|
1797
|
-
const response = await this.constructRequest(headers, signal);
|
|
1798
|
-
return response;
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
var fs = {};
|
|
1802
|
-
class HttpResponse extends BaseResponse {
|
|
1803
|
-
constructor(response, dataPromise) {
|
|
1804
|
-
super();
|
|
1805
|
-
this.response = response;
|
|
1806
|
-
this.dataPromise = dataPromise;
|
|
1807
|
-
}
|
|
1808
|
-
get status() {
|
|
1809
|
-
return this.response.statusCode;
|
|
1810
|
-
}
|
|
1811
|
-
getHeader(name) {
|
|
1812
|
-
return this.response.headers[name];
|
|
1813
|
-
}
|
|
1814
|
-
async getData() {
|
|
1815
|
-
const data = await this.dataPromise;
|
|
1816
|
-
return data;
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
class HttpClient extends BaseClient {
|
|
1820
|
-
constructor(url) {
|
|
1821
|
-
super(url);
|
|
1822
|
-
this.parsedUrl = fs.parse(this.url);
|
|
1823
|
-
this.httpApi = this.parsedUrl.protocol === "http:" ? fs : fs;
|
|
1824
|
-
}
|
|
1825
|
-
constructRequest(headers, signal) {
|
|
1826
|
-
return new Promise((resolve, reject) => {
|
|
1827
|
-
const request = this.httpApi.get(
|
|
1828
|
-
{
|
|
1829
|
-
...this.parsedUrl,
|
|
1830
|
-
headers
|
|
1831
|
-
},
|
|
1832
|
-
(response) => {
|
|
1833
|
-
const dataPromise = new Promise((resolveData) => {
|
|
1834
|
-
const chunks = [];
|
|
1835
|
-
response.on("data", (chunk) => {
|
|
1836
|
-
chunks.push(chunk);
|
|
1837
|
-
});
|
|
1838
|
-
response.on("end", () => {
|
|
1839
|
-
const data = Buffer.concat(chunks).buffer;
|
|
1840
|
-
resolveData(data);
|
|
1841
|
-
});
|
|
1842
|
-
response.on("error", reject);
|
|
1843
|
-
});
|
|
1844
|
-
resolve(new HttpResponse(response, dataPromise));
|
|
1845
|
-
}
|
|
1846
|
-
);
|
|
1847
|
-
request.on("error", reject);
|
|
1848
|
-
if (signal) {
|
|
1849
|
-
if (signal.aborted) {
|
|
1850
|
-
request.destroy(new AbortError("Request aborted"));
|
|
1851
|
-
}
|
|
1852
|
-
signal.addEventListener("abort", () => request.destroy(new AbortError("Request aborted")));
|
|
1853
|
-
}
|
|
1854
|
-
});
|
|
1855
|
-
}
|
|
1856
|
-
async request({ headers, signal } = {}) {
|
|
1857
|
-
const response = await this.constructRequest(headers, signal);
|
|
1858
|
-
return response;
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
class RemoteSource extends BaseSource {
|
|
1862
|
-
constructor(client, headers, maxRanges, allowFullFile) {
|
|
1863
|
-
super();
|
|
1864
|
-
this.client = client;
|
|
1865
|
-
this.headers = headers;
|
|
1866
|
-
this.maxRanges = maxRanges;
|
|
1867
|
-
this.allowFullFile = allowFullFile;
|
|
1868
|
-
this._fileSize = null;
|
|
1869
|
-
}
|
|
1870
|
-
async fetch(slices, signal) {
|
|
1871
|
-
if (this.maxRanges >= slices.length) {
|
|
1872
|
-
return this.fetchSlices(slices, signal);
|
|
1873
|
-
} else if (this.maxRanges > 0 && slices.length > 1)
|
|
1874
|
-
;
|
|
1875
|
-
return Promise.all(
|
|
1876
|
-
slices.map((slice) => this.fetchSlice(slice, signal))
|
|
1877
|
-
);
|
|
1878
|
-
}
|
|
1879
|
-
async fetchSlices(slices, signal) {
|
|
1880
|
-
const response = await this.client.request({
|
|
1881
|
-
headers: {
|
|
1882
|
-
...this.headers,
|
|
1883
|
-
Range: `bytes=${slices.map(({ offset, length }) => `${offset}-${offset + length}`).join(",")}`
|
|
1884
|
-
},
|
|
1885
|
-
signal
|
|
1886
|
-
});
|
|
1887
|
-
if (!response.ok) {
|
|
1888
|
-
throw new Error("Error fetching data.");
|
|
1889
|
-
} else if (response.status === 206) {
|
|
1890
|
-
const { type, params } = parseContentType(response.getHeader("content-type"));
|
|
1891
|
-
if (type === "multipart/byteranges") {
|
|
1892
|
-
const byteRanges = parseByteRanges(await response.getData(), params.boundary);
|
|
1893
|
-
this._fileSize = byteRanges[0].fileSize || null;
|
|
1894
|
-
return byteRanges;
|
|
1895
|
-
}
|
|
1896
|
-
const data = await response.getData();
|
|
1897
|
-
const { start, end, total } = parseContentRange(response.getHeader("content-range"));
|
|
1898
|
-
this._fileSize = total || null;
|
|
1899
|
-
const first = [{
|
|
1900
|
-
data,
|
|
1901
|
-
offset: start,
|
|
1902
|
-
length: end - start
|
|
1903
|
-
}];
|
|
1904
|
-
if (slices.length > 1) {
|
|
1905
|
-
const others = await Promise.all(slices.slice(1).map((slice) => this.fetchSlice(slice, signal)));
|
|
1906
|
-
return first.concat(others);
|
|
1907
|
-
}
|
|
1908
|
-
return first;
|
|
1909
|
-
} else {
|
|
1910
|
-
if (!this.allowFullFile) {
|
|
1911
|
-
throw new Error("Server responded with full file");
|
|
1912
|
-
}
|
|
1913
|
-
const data = await response.getData();
|
|
1914
|
-
this._fileSize = data.byteLength;
|
|
1915
|
-
return [{
|
|
1916
|
-
data,
|
|
1917
|
-
offset: 0,
|
|
1918
|
-
length: data.byteLength
|
|
1919
|
-
}];
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
async fetchSlice(slice, signal) {
|
|
1923
|
-
const { offset, length } = slice;
|
|
1924
|
-
const response = await this.client.request({
|
|
1925
|
-
headers: {
|
|
1926
|
-
...this.headers,
|
|
1927
|
-
Range: `bytes=${offset}-${offset + length}`
|
|
1928
|
-
},
|
|
1929
|
-
signal
|
|
1930
|
-
});
|
|
1931
|
-
if (!response.ok) {
|
|
1932
|
-
throw new Error("Error fetching data.");
|
|
1933
|
-
} else if (response.status === 206) {
|
|
1934
|
-
const data = await response.getData();
|
|
1935
|
-
const { total } = parseContentRange(response.getHeader("content-range"));
|
|
1936
|
-
this._fileSize = total || null;
|
|
1937
|
-
return {
|
|
1938
|
-
data,
|
|
1939
|
-
offset,
|
|
1940
|
-
length
|
|
1941
|
-
};
|
|
1942
|
-
} else {
|
|
1943
|
-
if (!this.allowFullFile) {
|
|
1944
|
-
throw new Error("Server responded with full file");
|
|
1945
|
-
}
|
|
1946
|
-
const data = await response.getData();
|
|
1947
|
-
this._fileSize = data.byteLength;
|
|
1948
|
-
return {
|
|
1949
|
-
data,
|
|
1950
|
-
offset: 0,
|
|
1951
|
-
length: data.byteLength
|
|
1952
|
-
};
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
get fileSize() {
|
|
1956
|
-
return this._fileSize;
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
function maybeWrapInBlockedSource(source, { blockSize, cacheSize }) {
|
|
1960
|
-
if (blockSize === null) {
|
|
1961
|
-
return source;
|
|
1962
|
-
}
|
|
1963
|
-
return new BlockedSource(source, blockSize, cacheSize);
|
|
1964
|
-
}
|
|
1965
|
-
function makeFetchSource(url, { headers = {}, credentials, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) {
|
|
1966
|
-
const client = new FetchClient(url, credentials);
|
|
1967
|
-
const source = new RemoteSource(client, headers, maxRanges, allowFullFile);
|
|
1968
|
-
return maybeWrapInBlockedSource(source, blockOptions);
|
|
1969
|
-
}
|
|
1970
|
-
function makeXHRSource(url, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) {
|
|
1971
|
-
const client = new XHRClient(url);
|
|
1972
|
-
const source = new RemoteSource(client, headers, maxRanges, allowFullFile);
|
|
1973
|
-
return maybeWrapInBlockedSource(source, blockOptions);
|
|
1974
|
-
}
|
|
1975
|
-
function makeHttpSource(url, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) {
|
|
1976
|
-
const client = new HttpClient(url);
|
|
1977
|
-
const source = new RemoteSource(client, headers, maxRanges, allowFullFile);
|
|
1978
|
-
return maybeWrapInBlockedSource(source, blockOptions);
|
|
1979
|
-
}
|
|
1980
|
-
function makeRemoteSource(url, { forceXHR = false, ...clientOptions } = {}) {
|
|
1981
|
-
if (typeof fetch === "function" && !forceXHR) {
|
|
1982
|
-
return makeFetchSource(url, clientOptions);
|
|
1983
|
-
}
|
|
1984
|
-
if (typeof XMLHttpRequest !== "undefined") {
|
|
1985
|
-
return makeXHRSource(url, clientOptions);
|
|
1986
|
-
}
|
|
1987
|
-
return makeHttpSource(url, clientOptions);
|
|
1988
|
-
}
|
|
1989
|
-
class FileReaderSource extends BaseSource {
|
|
1990
|
-
constructor(file) {
|
|
1991
|
-
super();
|
|
1992
|
-
this.file = file;
|
|
1993
|
-
}
|
|
1994
|
-
async fetchSlice(slice, signal) {
|
|
1995
|
-
return new Promise((resolve, reject) => {
|
|
1996
|
-
const blob = this.file.slice(slice.offset, slice.offset + slice.length);
|
|
1997
|
-
const reader = new FileReader();
|
|
1998
|
-
reader.onload = (event) => resolve(event.target.result);
|
|
1999
|
-
reader.onerror = reject;
|
|
2000
|
-
reader.onabort = reject;
|
|
2001
|
-
reader.readAsArrayBuffer(blob);
|
|
2002
|
-
if (signal) {
|
|
2003
|
-
signal.addEventListener("abort", () => reader.abort());
|
|
2004
|
-
}
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
function makeFileReaderSource(file) {
|
|
2009
|
-
return new FileReaderSource(file);
|
|
2010
|
-
}
|
|
2011
|
-
function getFieldTypeLength(fieldType) {
|
|
2012
|
-
switch (fieldType) {
|
|
2013
|
-
case fieldTypes.BYTE:
|
|
2014
|
-
case fieldTypes.ASCII:
|
|
2015
|
-
case fieldTypes.SBYTE:
|
|
2016
|
-
case fieldTypes.UNDEFINED:
|
|
2017
|
-
return 1;
|
|
2018
|
-
case fieldTypes.SHORT:
|
|
2019
|
-
case fieldTypes.SSHORT:
|
|
2020
|
-
return 2;
|
|
2021
|
-
case fieldTypes.LONG:
|
|
2022
|
-
case fieldTypes.SLONG:
|
|
2023
|
-
case fieldTypes.FLOAT:
|
|
2024
|
-
case fieldTypes.IFD:
|
|
2025
|
-
return 4;
|
|
2026
|
-
case fieldTypes.RATIONAL:
|
|
2027
|
-
case fieldTypes.SRATIONAL:
|
|
2028
|
-
case fieldTypes.DOUBLE:
|
|
2029
|
-
case fieldTypes.LONG8:
|
|
2030
|
-
case fieldTypes.SLONG8:
|
|
2031
|
-
case fieldTypes.IFD8:
|
|
2032
|
-
return 8;
|
|
2033
|
-
default:
|
|
2034
|
-
throw new RangeError(`Invalid field type: ${fieldType}`);
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
function parseGeoKeyDirectory(fileDirectory) {
|
|
2038
|
-
const rawGeoKeyDirectory = fileDirectory.GeoKeyDirectory;
|
|
2039
|
-
if (!rawGeoKeyDirectory) {
|
|
2040
|
-
return null;
|
|
2041
|
-
}
|
|
2042
|
-
const geoKeyDirectory = {};
|
|
2043
|
-
for (let i = 4; i <= rawGeoKeyDirectory[3] * 4; i += 4) {
|
|
2044
|
-
const key = geoKeyNames[rawGeoKeyDirectory[i]];
|
|
2045
|
-
const location = rawGeoKeyDirectory[i + 1] ? fieldTagNames[rawGeoKeyDirectory[i + 1]] : null;
|
|
2046
|
-
const count = rawGeoKeyDirectory[i + 2];
|
|
2047
|
-
const offset = rawGeoKeyDirectory[i + 3];
|
|
2048
|
-
let value = null;
|
|
2049
|
-
if (!location) {
|
|
2050
|
-
value = offset;
|
|
2051
|
-
} else {
|
|
2052
|
-
value = fileDirectory[location];
|
|
2053
|
-
if (typeof value === "undefined" || value === null) {
|
|
2054
|
-
throw new Error(`Could not get value of geoKey '${key}'.`);
|
|
2055
|
-
} else if (typeof value === "string") {
|
|
2056
|
-
value = value.substring(offset, offset + count - 1);
|
|
2057
|
-
} else if (value.subarray) {
|
|
2058
|
-
value = value.subarray(offset, offset + count);
|
|
2059
|
-
if (count === 1) {
|
|
2060
|
-
value = value[0];
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
geoKeyDirectory[key] = value;
|
|
2065
|
-
}
|
|
2066
|
-
return geoKeyDirectory;
|
|
2067
|
-
}
|
|
2068
|
-
function getValues(dataSlice, fieldType, count, offset) {
|
|
2069
|
-
let values = null;
|
|
2070
|
-
let readMethod = null;
|
|
2071
|
-
const fieldTypeLength = getFieldTypeLength(fieldType);
|
|
2072
|
-
switch (fieldType) {
|
|
2073
|
-
case fieldTypes.BYTE:
|
|
2074
|
-
case fieldTypes.ASCII:
|
|
2075
|
-
case fieldTypes.UNDEFINED:
|
|
2076
|
-
values = new Uint8Array(count);
|
|
2077
|
-
readMethod = dataSlice.readUint8;
|
|
2078
|
-
break;
|
|
2079
|
-
case fieldTypes.SBYTE:
|
|
2080
|
-
values = new Int8Array(count);
|
|
2081
|
-
readMethod = dataSlice.readInt8;
|
|
2082
|
-
break;
|
|
2083
|
-
case fieldTypes.SHORT:
|
|
2084
|
-
values = new Uint16Array(count);
|
|
2085
|
-
readMethod = dataSlice.readUint16;
|
|
2086
|
-
break;
|
|
2087
|
-
case fieldTypes.SSHORT:
|
|
2088
|
-
values = new Int16Array(count);
|
|
2089
|
-
readMethod = dataSlice.readInt16;
|
|
2090
|
-
break;
|
|
2091
|
-
case fieldTypes.LONG:
|
|
2092
|
-
case fieldTypes.IFD:
|
|
2093
|
-
values = new Uint32Array(count);
|
|
2094
|
-
readMethod = dataSlice.readUint32;
|
|
2095
|
-
break;
|
|
2096
|
-
case fieldTypes.SLONG:
|
|
2097
|
-
values = new Int32Array(count);
|
|
2098
|
-
readMethod = dataSlice.readInt32;
|
|
2099
|
-
break;
|
|
2100
|
-
case fieldTypes.LONG8:
|
|
2101
|
-
case fieldTypes.IFD8:
|
|
2102
|
-
values = new Array(count);
|
|
2103
|
-
readMethod = dataSlice.readUint64;
|
|
2104
|
-
break;
|
|
2105
|
-
case fieldTypes.SLONG8:
|
|
2106
|
-
values = new Array(count);
|
|
2107
|
-
readMethod = dataSlice.readInt64;
|
|
2108
|
-
break;
|
|
2109
|
-
case fieldTypes.RATIONAL:
|
|
2110
|
-
values = new Uint32Array(count * 2);
|
|
2111
|
-
readMethod = dataSlice.readUint32;
|
|
2112
|
-
break;
|
|
2113
|
-
case fieldTypes.SRATIONAL:
|
|
2114
|
-
values = new Int32Array(count * 2);
|
|
2115
|
-
readMethod = dataSlice.readInt32;
|
|
2116
|
-
break;
|
|
2117
|
-
case fieldTypes.FLOAT:
|
|
2118
|
-
values = new Float32Array(count);
|
|
2119
|
-
readMethod = dataSlice.readFloat32;
|
|
2120
|
-
break;
|
|
2121
|
-
case fieldTypes.DOUBLE:
|
|
2122
|
-
values = new Float64Array(count);
|
|
2123
|
-
readMethod = dataSlice.readFloat64;
|
|
2124
|
-
break;
|
|
2125
|
-
default:
|
|
2126
|
-
throw new RangeError(`Invalid field type: ${fieldType}`);
|
|
2127
|
-
}
|
|
2128
|
-
if (!(fieldType === fieldTypes.RATIONAL || fieldType === fieldTypes.SRATIONAL)) {
|
|
2129
|
-
for (let i = 0; i < count; ++i) {
|
|
2130
|
-
values[i] = readMethod.call(
|
|
2131
|
-
dataSlice,
|
|
2132
|
-
offset + i * fieldTypeLength
|
|
2133
|
-
);
|
|
2134
|
-
}
|
|
2135
|
-
} else {
|
|
2136
|
-
for (let i = 0; i < count; i += 2) {
|
|
2137
|
-
values[i] = readMethod.call(
|
|
2138
|
-
dataSlice,
|
|
2139
|
-
offset + i * fieldTypeLength
|
|
2140
|
-
);
|
|
2141
|
-
values[i + 1] = readMethod.call(
|
|
2142
|
-
dataSlice,
|
|
2143
|
-
offset + (i * fieldTypeLength + 4)
|
|
2144
|
-
);
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
if (fieldType === fieldTypes.ASCII) {
|
|
2148
|
-
return new TextDecoder("utf-8").decode(values);
|
|
2149
|
-
}
|
|
2150
|
-
return values;
|
|
2151
|
-
}
|
|
2152
|
-
class ImageFileDirectory {
|
|
2153
|
-
constructor(fileDirectory, geoKeyDirectory, nextIFDByteOffset) {
|
|
2154
|
-
this.fileDirectory = fileDirectory;
|
|
2155
|
-
this.geoKeyDirectory = geoKeyDirectory;
|
|
2156
|
-
this.nextIFDByteOffset = nextIFDByteOffset;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
class GeoTIFFImageIndexError extends Error {
|
|
2160
|
-
constructor(index) {
|
|
2161
|
-
super(`No image at index ${index}`);
|
|
2162
|
-
this.index = index;
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
class GeoTIFFBase {
|
|
2166
|
-
async readRasters(options = {}) {
|
|
2167
|
-
const { window: imageWindow, width, height } = options;
|
|
2168
|
-
let { resX, resY, bbox } = options;
|
|
2169
|
-
const firstImage = await this.getImage();
|
|
2170
|
-
let usedImage = firstImage;
|
|
2171
|
-
const imageCount = await this.getImageCount();
|
|
2172
|
-
const imgBBox = firstImage.getBoundingBox();
|
|
2173
|
-
if (imageWindow && bbox) {
|
|
2174
|
-
throw new Error('Both "bbox" and "window" passed.');
|
|
2175
|
-
}
|
|
2176
|
-
if (width || height) {
|
|
2177
|
-
if (imageWindow) {
|
|
2178
|
-
const [oX, oY] = firstImage.getOrigin();
|
|
2179
|
-
const [rX, rY] = firstImage.getResolution();
|
|
2180
|
-
bbox = [
|
|
2181
|
-
oX + imageWindow[0] * rX,
|
|
2182
|
-
oY + imageWindow[1] * rY,
|
|
2183
|
-
oX + imageWindow[2] * rX,
|
|
2184
|
-
oY + imageWindow[3] * rY
|
|
2185
|
-
];
|
|
2186
|
-
}
|
|
2187
|
-
const usedBBox = bbox || imgBBox;
|
|
2188
|
-
if (width) {
|
|
2189
|
-
if (resX) {
|
|
2190
|
-
throw new Error("Both width and resX passed");
|
|
2191
|
-
}
|
|
2192
|
-
resX = (usedBBox[2] - usedBBox[0]) / width;
|
|
2193
|
-
}
|
|
2194
|
-
if (height) {
|
|
2195
|
-
if (resY) {
|
|
2196
|
-
throw new Error("Both width and resY passed");
|
|
2197
|
-
}
|
|
2198
|
-
resY = (usedBBox[3] - usedBBox[1]) / height;
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
if (resX || resY) {
|
|
2202
|
-
const allImages = [];
|
|
2203
|
-
for (let i = 0; i < imageCount; ++i) {
|
|
2204
|
-
const image = await this.getImage(i);
|
|
2205
|
-
const { SubfileType: subfileType, NewSubfileType: newSubfileType } = image.fileDirectory;
|
|
2206
|
-
if (i === 0 || subfileType === 2 || newSubfileType & 1) {
|
|
2207
|
-
allImages.push(image);
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
allImages.sort((a, b) => a.getWidth() - b.getWidth());
|
|
2211
|
-
for (let i = 0; i < allImages.length; ++i) {
|
|
2212
|
-
const image = allImages[i];
|
|
2213
|
-
const imgResX = (imgBBox[2] - imgBBox[0]) / image.getWidth();
|
|
2214
|
-
const imgResY = (imgBBox[3] - imgBBox[1]) / image.getHeight();
|
|
2215
|
-
usedImage = image;
|
|
2216
|
-
if (resX && resX > imgResX || resY && resY > imgResY) {
|
|
2217
|
-
break;
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
let wnd = imageWindow;
|
|
2222
|
-
if (bbox) {
|
|
2223
|
-
const [oX, oY] = firstImage.getOrigin();
|
|
2224
|
-
const [imageResX, imageResY] = usedImage.getResolution(firstImage);
|
|
2225
|
-
wnd = [
|
|
2226
|
-
Math.round((bbox[0] - oX) / imageResX),
|
|
2227
|
-
Math.round((bbox[1] - oY) / imageResY),
|
|
2228
|
-
Math.round((bbox[2] - oX) / imageResX),
|
|
2229
|
-
Math.round((bbox[3] - oY) / imageResY)
|
|
2230
|
-
];
|
|
2231
|
-
wnd = [
|
|
2232
|
-
Math.min(wnd[0], wnd[2]),
|
|
2233
|
-
Math.min(wnd[1], wnd[3]),
|
|
2234
|
-
Math.max(wnd[0], wnd[2]),
|
|
2235
|
-
Math.max(wnd[1], wnd[3])
|
|
2236
|
-
];
|
|
2237
|
-
}
|
|
2238
|
-
return usedImage.readRasters({ ...options, window: wnd });
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
class GeoTIFF extends GeoTIFFBase {
|
|
2242
|
-
constructor(source, littleEndian, bigTiff, firstIFDOffset, options = {}) {
|
|
2243
|
-
super();
|
|
2244
|
-
this.source = source;
|
|
2245
|
-
this.littleEndian = littleEndian;
|
|
2246
|
-
this.bigTiff = bigTiff;
|
|
2247
|
-
this.firstIFDOffset = firstIFDOffset;
|
|
2248
|
-
this.cache = options.cache || false;
|
|
2249
|
-
this.ifdRequests = [];
|
|
2250
|
-
this.ghostValues = null;
|
|
2251
|
-
}
|
|
2252
|
-
async getSlice(offset, size) {
|
|
2253
|
-
const fallbackSize = this.bigTiff ? 4048 : 1024;
|
|
2254
|
-
return new DataSlice(
|
|
2255
|
-
(await this.source.fetch([{
|
|
2256
|
-
offset,
|
|
2257
|
-
length: typeof size !== "undefined" ? size : fallbackSize
|
|
2258
|
-
}]))[0],
|
|
2259
|
-
offset,
|
|
2260
|
-
this.littleEndian,
|
|
2261
|
-
this.bigTiff
|
|
2262
|
-
);
|
|
2263
|
-
}
|
|
2264
|
-
async parseFileDirectoryAt(offset) {
|
|
2265
|
-
const entrySize = this.bigTiff ? 20 : 12;
|
|
2266
|
-
const offsetSize = this.bigTiff ? 8 : 2;
|
|
2267
|
-
let dataSlice = await this.getSlice(offset);
|
|
2268
|
-
const numDirEntries = this.bigTiff ? dataSlice.readUint64(offset) : dataSlice.readUint16(offset);
|
|
2269
|
-
const byteSize = numDirEntries * entrySize + (this.bigTiff ? 16 : 6);
|
|
2270
|
-
if (!dataSlice.covers(offset, byteSize)) {
|
|
2271
|
-
dataSlice = await this.getSlice(offset, byteSize);
|
|
2272
|
-
}
|
|
2273
|
-
const fileDirectory = {};
|
|
2274
|
-
let i = offset + (this.bigTiff ? 8 : 2);
|
|
2275
|
-
for (let entryCount = 0; entryCount < numDirEntries; i += entrySize, ++entryCount) {
|
|
2276
|
-
const fieldTag = dataSlice.readUint16(i);
|
|
2277
|
-
const fieldType = dataSlice.readUint16(i + 2);
|
|
2278
|
-
const typeCount = this.bigTiff ? dataSlice.readUint64(i + 4) : dataSlice.readUint32(i + 4);
|
|
2279
|
-
let fieldValues;
|
|
2280
|
-
let value;
|
|
2281
|
-
const fieldTypeLength = getFieldTypeLength(fieldType);
|
|
2282
|
-
const valueOffset = i + (this.bigTiff ? 12 : 8);
|
|
2283
|
-
if (fieldTypeLength * typeCount <= (this.bigTiff ? 8 : 4)) {
|
|
2284
|
-
fieldValues = getValues(dataSlice, fieldType, typeCount, valueOffset);
|
|
2285
|
-
} else {
|
|
2286
|
-
const actualOffset = dataSlice.readOffset(valueOffset);
|
|
2287
|
-
const length = getFieldTypeLength(fieldType) * typeCount;
|
|
2288
|
-
if (dataSlice.covers(actualOffset, length)) {
|
|
2289
|
-
fieldValues = getValues(dataSlice, fieldType, typeCount, actualOffset);
|
|
2290
|
-
} else {
|
|
2291
|
-
const fieldDataSlice = await this.getSlice(actualOffset, length);
|
|
2292
|
-
fieldValues = getValues(fieldDataSlice, fieldType, typeCount, actualOffset);
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
if (typeCount === 1 && arrayFields.indexOf(fieldTag) === -1 && !(fieldType === fieldTypes.RATIONAL || fieldType === fieldTypes.SRATIONAL)) {
|
|
2296
|
-
value = fieldValues[0];
|
|
2297
|
-
} else {
|
|
2298
|
-
value = fieldValues;
|
|
2299
|
-
}
|
|
2300
|
-
fileDirectory[fieldTagNames[fieldTag]] = value;
|
|
2301
|
-
}
|
|
2302
|
-
const geoKeyDirectory = parseGeoKeyDirectory(fileDirectory);
|
|
2303
|
-
const nextIFDByteOffset = dataSlice.readOffset(
|
|
2304
|
-
offset + offsetSize + entrySize * numDirEntries
|
|
2305
|
-
);
|
|
2306
|
-
return new ImageFileDirectory(
|
|
2307
|
-
fileDirectory,
|
|
2308
|
-
geoKeyDirectory,
|
|
2309
|
-
nextIFDByteOffset
|
|
2310
|
-
);
|
|
2311
|
-
}
|
|
2312
|
-
async requestIFD(index) {
|
|
2313
|
-
if (this.ifdRequests[index]) {
|
|
2314
|
-
return this.ifdRequests[index];
|
|
2315
|
-
} else if (index === 0) {
|
|
2316
|
-
this.ifdRequests[index] = this.parseFileDirectoryAt(this.firstIFDOffset);
|
|
2317
|
-
return this.ifdRequests[index];
|
|
2318
|
-
} else if (!this.ifdRequests[index - 1]) {
|
|
2319
|
-
try {
|
|
2320
|
-
this.ifdRequests[index - 1] = this.requestIFD(index - 1);
|
|
2321
|
-
} catch (e) {
|
|
2322
|
-
if (e instanceof GeoTIFFImageIndexError) {
|
|
2323
|
-
throw new GeoTIFFImageIndexError(index);
|
|
2324
|
-
}
|
|
2325
|
-
throw e;
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
this.ifdRequests[index] = (async () => {
|
|
2329
|
-
const previousIfd = await this.ifdRequests[index - 1];
|
|
2330
|
-
if (previousIfd.nextIFDByteOffset === 0) {
|
|
2331
|
-
throw new GeoTIFFImageIndexError(index);
|
|
2332
|
-
}
|
|
2333
|
-
return this.parseFileDirectoryAt(previousIfd.nextIFDByteOffset);
|
|
2334
|
-
})();
|
|
2335
|
-
return this.ifdRequests[index];
|
|
2336
|
-
}
|
|
2337
|
-
async getImage(index = 0) {
|
|
2338
|
-
const ifd = await this.requestIFD(index);
|
|
2339
|
-
return new GeoTIFFImage$1(
|
|
2340
|
-
ifd.fileDirectory,
|
|
2341
|
-
ifd.geoKeyDirectory,
|
|
2342
|
-
this.dataView,
|
|
2343
|
-
this.littleEndian,
|
|
2344
|
-
this.cache,
|
|
2345
|
-
this.source
|
|
2346
|
-
);
|
|
2347
|
-
}
|
|
2348
|
-
async getImageCount() {
|
|
2349
|
-
let index = 0;
|
|
2350
|
-
let hasNext = true;
|
|
2351
|
-
while (hasNext) {
|
|
2352
|
-
try {
|
|
2353
|
-
await this.requestIFD(index);
|
|
2354
|
-
++index;
|
|
2355
|
-
} catch (e) {
|
|
2356
|
-
if (e instanceof GeoTIFFImageIndexError) {
|
|
2357
|
-
hasNext = false;
|
|
2358
|
-
} else {
|
|
2359
|
-
throw e;
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
return index;
|
|
2364
|
-
}
|
|
2365
|
-
async getGhostValues() {
|
|
2366
|
-
const offset = this.bigTiff ? 16 : 8;
|
|
2367
|
-
if (this.ghostValues) {
|
|
2368
|
-
return this.ghostValues;
|
|
2369
|
-
}
|
|
2370
|
-
const detectionString = "GDAL_STRUCTURAL_METADATA_SIZE=";
|
|
2371
|
-
const heuristicAreaSize = detectionString.length + 100;
|
|
2372
|
-
let slice = await this.getSlice(offset, heuristicAreaSize);
|
|
2373
|
-
if (detectionString === getValues(slice, fieldTypes.ASCII, detectionString.length, offset)) {
|
|
2374
|
-
const valuesString = getValues(slice, fieldTypes.ASCII, heuristicAreaSize, offset);
|
|
2375
|
-
const firstLine = valuesString.split("\n")[0];
|
|
2376
|
-
const metadataSize = Number(firstLine.split("=")[1].split(" ")[0]) + firstLine.length;
|
|
2377
|
-
if (metadataSize > heuristicAreaSize) {
|
|
2378
|
-
slice = await this.getSlice(offset, metadataSize);
|
|
2379
|
-
}
|
|
2380
|
-
const fullString = getValues(slice, fieldTypes.ASCII, metadataSize, offset);
|
|
2381
|
-
this.ghostValues = {};
|
|
2382
|
-
fullString.split("\n").filter((line) => line.length > 0).map((line) => line.split("=")).forEach(([key, value]) => {
|
|
2383
|
-
this.ghostValues[key] = value;
|
|
2384
|
-
});
|
|
2385
|
-
}
|
|
2386
|
-
return this.ghostValues;
|
|
2387
|
-
}
|
|
2388
|
-
static async fromSource(source, options, signal) {
|
|
2389
|
-
const headerData = (await source.fetch([{ offset: 0, length: 1024 }], signal))[0];
|
|
2390
|
-
const dataView = new DataView64(headerData);
|
|
2391
|
-
const BOM = dataView.getUint16(0, 0);
|
|
2392
|
-
let littleEndian;
|
|
2393
|
-
if (BOM === 18761) {
|
|
2394
|
-
littleEndian = true;
|
|
2395
|
-
} else if (BOM === 19789) {
|
|
2396
|
-
littleEndian = false;
|
|
2397
|
-
} else {
|
|
2398
|
-
throw new TypeError("Invalid byte order value.");
|
|
2399
|
-
}
|
|
2400
|
-
const magicNumber = dataView.getUint16(2, littleEndian);
|
|
2401
|
-
let bigTiff;
|
|
2402
|
-
if (magicNumber === 42) {
|
|
2403
|
-
bigTiff = false;
|
|
2404
|
-
} else if (magicNumber === 43) {
|
|
2405
|
-
bigTiff = true;
|
|
2406
|
-
const offsetByteSize = dataView.getUint16(4, littleEndian);
|
|
2407
|
-
if (offsetByteSize !== 8) {
|
|
2408
|
-
throw new Error("Unsupported offset byte-size.");
|
|
2409
|
-
}
|
|
2410
|
-
} else {
|
|
2411
|
-
throw new TypeError("Invalid magic number.");
|
|
2412
|
-
}
|
|
2413
|
-
const firstIFDOffset = bigTiff ? dataView.getUint64(8, littleEndian) : dataView.getUint32(4, littleEndian);
|
|
2414
|
-
return new GeoTIFF(source, littleEndian, bigTiff, firstIFDOffset, options);
|
|
2415
|
-
}
|
|
2416
|
-
close() {
|
|
2417
|
-
if (typeof this.source.close === "function") {
|
|
2418
|
-
return this.source.close();
|
|
2419
|
-
}
|
|
2420
|
-
return false;
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
class MultiGeoTIFF extends GeoTIFFBase {
|
|
2424
|
-
constructor(mainFile, overviewFiles) {
|
|
2425
|
-
super();
|
|
2426
|
-
this.mainFile = mainFile;
|
|
2427
|
-
this.overviewFiles = overviewFiles;
|
|
2428
|
-
this.imageFiles = [mainFile].concat(overviewFiles);
|
|
2429
|
-
this.fileDirectoriesPerFile = null;
|
|
2430
|
-
this.fileDirectoriesPerFileParsing = null;
|
|
2431
|
-
this.imageCount = null;
|
|
2432
|
-
}
|
|
2433
|
-
async parseFileDirectoriesPerFile() {
|
|
2434
|
-
const requests = [this.mainFile.parseFileDirectoryAt(this.mainFile.firstIFDOffset)].concat(this.overviewFiles.map((file) => file.parseFileDirectoryAt(file.firstIFDOffset)));
|
|
2435
|
-
this.fileDirectoriesPerFile = await Promise.all(requests);
|
|
2436
|
-
return this.fileDirectoriesPerFile;
|
|
2437
|
-
}
|
|
2438
|
-
async getImage(index = 0) {
|
|
2439
|
-
await this.getImageCount();
|
|
2440
|
-
await this.parseFileDirectoriesPerFile();
|
|
2441
|
-
let visited = 0;
|
|
2442
|
-
let relativeIndex = 0;
|
|
2443
|
-
for (let i = 0; i < this.imageFiles.length; i++) {
|
|
2444
|
-
const imageFile = this.imageFiles[i];
|
|
2445
|
-
for (let ii = 0; ii < this.imageCounts[i]; ii++) {
|
|
2446
|
-
if (index === visited) {
|
|
2447
|
-
const ifd = await imageFile.requestIFD(relativeIndex);
|
|
2448
|
-
return new GeoTIFFImage$1(
|
|
2449
|
-
ifd.fileDirectory,
|
|
2450
|
-
ifd.geoKeyDirectory,
|
|
2451
|
-
imageFile.dataView,
|
|
2452
|
-
imageFile.littleEndian,
|
|
2453
|
-
imageFile.cache,
|
|
2454
|
-
imageFile.source
|
|
2455
|
-
);
|
|
2456
|
-
}
|
|
2457
|
-
visited++;
|
|
2458
|
-
relativeIndex++;
|
|
2459
|
-
}
|
|
2460
|
-
relativeIndex = 0;
|
|
2461
|
-
}
|
|
2462
|
-
throw new RangeError("Invalid image index");
|
|
2463
|
-
}
|
|
2464
|
-
async getImageCount() {
|
|
2465
|
-
if (this.imageCount !== null) {
|
|
2466
|
-
return this.imageCount;
|
|
2467
|
-
}
|
|
2468
|
-
const requests = [this.mainFile.getImageCount()].concat(this.overviewFiles.map((file) => file.getImageCount()));
|
|
2469
|
-
this.imageCounts = await Promise.all(requests);
|
|
2470
|
-
this.imageCount = this.imageCounts.reduce((count, ifds) => count + ifds, 0);
|
|
2471
|
-
return this.imageCount;
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
async function fromUrl(url, options = {}, signal) {
|
|
2475
|
-
return GeoTIFF.fromSource(makeRemoteSource(url, options), signal);
|
|
2476
|
-
}
|
|
2477
|
-
async function fromBlob(blob, signal) {
|
|
2478
|
-
return GeoTIFF.fromSource(makeFileReaderSource(blob), signal);
|
|
2479
|
-
}
|
|
2480
|
-
async function fromUrls(mainUrl, overviewUrls = [], options = {}, signal) {
|
|
2481
|
-
const mainFile = await GeoTIFF.fromSource(makeRemoteSource(mainUrl, options), signal);
|
|
2482
|
-
const overviewFiles = await Promise.all(
|
|
2483
|
-
overviewUrls.map((url) => GeoTIFF.fromSource(makeRemoteSource(url, options)))
|
|
2484
|
-
);
|
|
2485
|
-
return new MultiGeoTIFF(mainFile, overviewFiles);
|
|
2486
|
-
}
|
|
2487
|
-
function decodeRowAcc(row, stride) {
|
|
2488
|
-
let length = row.length - stride;
|
|
2489
|
-
let offset = 0;
|
|
2490
|
-
do {
|
|
2491
|
-
for (let i = stride; i > 0; i--) {
|
|
2492
|
-
row[offset + stride] += row[offset];
|
|
2493
|
-
offset++;
|
|
2494
|
-
}
|
|
2495
|
-
length -= stride;
|
|
2496
|
-
} while (length > 0);
|
|
2497
|
-
}
|
|
2498
|
-
function decodeRowFloatingPoint(row, stride, bytesPerSample) {
|
|
2499
|
-
let index = 0;
|
|
2500
|
-
let count = row.length;
|
|
2501
|
-
const wc = count / bytesPerSample;
|
|
2502
|
-
while (count > stride) {
|
|
2503
|
-
for (let i = stride; i > 0; --i) {
|
|
2504
|
-
row[index + stride] += row[index];
|
|
2505
|
-
++index;
|
|
2506
|
-
}
|
|
2507
|
-
count -= stride;
|
|
2508
|
-
}
|
|
2509
|
-
const copy = row.slice();
|
|
2510
|
-
for (let i = 0; i < wc; ++i) {
|
|
2511
|
-
for (let b = 0; b < bytesPerSample; ++b) {
|
|
2512
|
-
row[bytesPerSample * i + b] = copy[(bytesPerSample - b - 1) * wc + i];
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
function applyPredictor(block, predictor, width, height, bitsPerSample, planarConfiguration) {
|
|
2517
|
-
if (!predictor || predictor === 1) {
|
|
2518
|
-
return block;
|
|
2519
|
-
}
|
|
2520
|
-
for (let i = 0; i < bitsPerSample.length; ++i) {
|
|
2521
|
-
if (bitsPerSample[i] % 8 !== 0) {
|
|
2522
|
-
throw new Error("When decoding with predictor, only multiple of 8 bits are supported.");
|
|
2523
|
-
}
|
|
2524
|
-
if (bitsPerSample[i] !== bitsPerSample[0]) {
|
|
2525
|
-
throw new Error("When decoding with predictor, all samples must have the same size.");
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
const bytesPerSample = bitsPerSample[0] / 8;
|
|
2529
|
-
const stride = planarConfiguration === 2 ? 1 : bitsPerSample.length;
|
|
2530
|
-
for (let i = 0; i < height; ++i) {
|
|
2531
|
-
if (i * stride * width * bytesPerSample >= block.byteLength) {
|
|
2532
|
-
break;
|
|
2533
|
-
}
|
|
2534
|
-
let row;
|
|
2535
|
-
if (predictor === 2) {
|
|
2536
|
-
switch (bitsPerSample[0]) {
|
|
2537
|
-
case 8:
|
|
2538
|
-
row = new Uint8Array(
|
|
2539
|
-
block,
|
|
2540
|
-
i * stride * width * bytesPerSample,
|
|
2541
|
-
stride * width * bytesPerSample
|
|
2542
|
-
);
|
|
2543
|
-
break;
|
|
2544
|
-
case 16:
|
|
2545
|
-
row = new Uint16Array(
|
|
2546
|
-
block,
|
|
2547
|
-
i * stride * width * bytesPerSample,
|
|
2548
|
-
stride * width * bytesPerSample / 2
|
|
2549
|
-
);
|
|
2550
|
-
break;
|
|
2551
|
-
case 32:
|
|
2552
|
-
row = new Uint32Array(
|
|
2553
|
-
block,
|
|
2554
|
-
i * stride * width * bytesPerSample,
|
|
2555
|
-
stride * width * bytesPerSample / 4
|
|
2556
|
-
);
|
|
2557
|
-
break;
|
|
2558
|
-
default:
|
|
2559
|
-
throw new Error(`Predictor 2 not allowed with ${bitsPerSample[0]} bits per sample.`);
|
|
2560
|
-
}
|
|
2561
|
-
decodeRowAcc(row, stride);
|
|
2562
|
-
} else if (predictor === 3) {
|
|
2563
|
-
row = new Uint8Array(
|
|
2564
|
-
block,
|
|
2565
|
-
i * stride * width * bytesPerSample,
|
|
2566
|
-
stride * width * bytesPerSample
|
|
2567
|
-
);
|
|
2568
|
-
decodeRowFloatingPoint(row, stride, bytesPerSample);
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
return block;
|
|
2572
|
-
}
|
|
2573
|
-
class BaseDecoder {
|
|
2574
|
-
async decode(fileDirectory, buffer) {
|
|
2575
|
-
const decoded = await this.decodeBlock(buffer);
|
|
2576
|
-
const predictor = fileDirectory.Predictor || 1;
|
|
2577
|
-
if (predictor !== 1) {
|
|
2578
|
-
const isTiled = !fileDirectory.StripOffsets;
|
|
2579
|
-
const tileWidth = isTiled ? fileDirectory.TileWidth : fileDirectory.ImageWidth;
|
|
2580
|
-
const tileHeight = isTiled ? fileDirectory.TileLength : fileDirectory.RowsPerStrip || fileDirectory.ImageLength;
|
|
2581
|
-
return applyPredictor(
|
|
2582
|
-
decoded,
|
|
2583
|
-
predictor,
|
|
2584
|
-
tileWidth,
|
|
2585
|
-
tileHeight,
|
|
2586
|
-
fileDirectory.BitsPerSample,
|
|
2587
|
-
fileDirectory.PlanarConfiguration
|
|
2588
|
-
);
|
|
2589
|
-
}
|
|
2590
|
-
return decoded;
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
class RawDecoder extends BaseDecoder {
|
|
2594
|
-
decodeBlock(buffer) {
|
|
2595
|
-
return buffer;
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
var raw = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2599
|
-
__proto__: null,
|
|
2600
|
-
"default": RawDecoder
|
|
2601
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
2602
|
-
const MIN_BITS = 9;
|
|
2603
|
-
const CLEAR_CODE = 256;
|
|
2604
|
-
const EOI_CODE = 257;
|
|
2605
|
-
const MAX_BYTELENGTH = 12;
|
|
2606
|
-
function getByte(array, position, length) {
|
|
2607
|
-
const d = position % 8;
|
|
2608
|
-
const a = Math.floor(position / 8);
|
|
2609
|
-
const de = 8 - d;
|
|
2610
|
-
const ef = position + length - (a + 1) * 8;
|
|
2611
|
-
let fg = 8 * (a + 2) - (position + length);
|
|
2612
|
-
const dg = (a + 2) * 8 - position;
|
|
2613
|
-
fg = Math.max(0, fg);
|
|
2614
|
-
if (a >= array.length) {
|
|
2615
|
-
console.warn("ran off the end of the buffer before finding EOI_CODE (end on input code)");
|
|
2616
|
-
return EOI_CODE;
|
|
2617
|
-
}
|
|
2618
|
-
let chunk1 = array[a] & 2 ** (8 - d) - 1;
|
|
2619
|
-
chunk1 <<= length - de;
|
|
2620
|
-
let chunks = chunk1;
|
|
2621
|
-
if (a + 1 < array.length) {
|
|
2622
|
-
let chunk2 = array[a + 1] >>> fg;
|
|
2623
|
-
chunk2 <<= Math.max(0, length - dg);
|
|
2624
|
-
chunks += chunk2;
|
|
2625
|
-
}
|
|
2626
|
-
if (ef > 8 && a + 2 < array.length) {
|
|
2627
|
-
const hi = (a + 3) * 8 - (position + length);
|
|
2628
|
-
const chunk3 = array[a + 2] >>> hi;
|
|
2629
|
-
chunks += chunk3;
|
|
2630
|
-
}
|
|
2631
|
-
return chunks;
|
|
2632
|
-
}
|
|
2633
|
-
function appendReversed(dest, source) {
|
|
2634
|
-
for (let i = source.length - 1; i >= 0; i--) {
|
|
2635
|
-
dest.push(source[i]);
|
|
2636
|
-
}
|
|
2637
|
-
return dest;
|
|
2638
|
-
}
|
|
2639
|
-
function decompress(input) {
|
|
2640
|
-
const dictionaryIndex = new Uint16Array(4093);
|
|
2641
|
-
const dictionaryChar = new Uint8Array(4093);
|
|
2642
|
-
for (let i = 0; i <= 257; i++) {
|
|
2643
|
-
dictionaryIndex[i] = 4096;
|
|
2644
|
-
dictionaryChar[i] = i;
|
|
2645
|
-
}
|
|
2646
|
-
let dictionaryLength = 258;
|
|
2647
|
-
let byteLength = MIN_BITS;
|
|
2648
|
-
let position = 0;
|
|
2649
|
-
function initDictionary() {
|
|
2650
|
-
dictionaryLength = 258;
|
|
2651
|
-
byteLength = MIN_BITS;
|
|
2652
|
-
}
|
|
2653
|
-
function getNext(array2) {
|
|
2654
|
-
const byte = getByte(array2, position, byteLength);
|
|
2655
|
-
position += byteLength;
|
|
2656
|
-
return byte;
|
|
2657
|
-
}
|
|
2658
|
-
function addToDictionary(i, c) {
|
|
2659
|
-
dictionaryChar[dictionaryLength] = c;
|
|
2660
|
-
dictionaryIndex[dictionaryLength] = i;
|
|
2661
|
-
dictionaryLength++;
|
|
2662
|
-
return dictionaryLength - 1;
|
|
2663
|
-
}
|
|
2664
|
-
function getDictionaryReversed(n) {
|
|
2665
|
-
const rev = [];
|
|
2666
|
-
for (let i = n; i !== 4096; i = dictionaryIndex[i]) {
|
|
2667
|
-
rev.push(dictionaryChar[i]);
|
|
2668
|
-
}
|
|
2669
|
-
return rev;
|
|
2670
|
-
}
|
|
2671
|
-
const result = [];
|
|
2672
|
-
initDictionary();
|
|
2673
|
-
const array = new Uint8Array(input);
|
|
2674
|
-
let code = getNext(array);
|
|
2675
|
-
let oldCode;
|
|
2676
|
-
while (code !== EOI_CODE) {
|
|
2677
|
-
if (code === CLEAR_CODE) {
|
|
2678
|
-
initDictionary();
|
|
2679
|
-
code = getNext(array);
|
|
2680
|
-
while (code === CLEAR_CODE) {
|
|
2681
|
-
code = getNext(array);
|
|
2682
|
-
}
|
|
2683
|
-
if (code === EOI_CODE) {
|
|
2684
|
-
break;
|
|
2685
|
-
} else if (code > CLEAR_CODE) {
|
|
2686
|
-
throw new Error(`corrupted code at scanline ${code}`);
|
|
2687
|
-
} else {
|
|
2688
|
-
const val = getDictionaryReversed(code);
|
|
2689
|
-
appendReversed(result, val);
|
|
2690
|
-
oldCode = code;
|
|
2691
|
-
}
|
|
2692
|
-
} else if (code < dictionaryLength) {
|
|
2693
|
-
const val = getDictionaryReversed(code);
|
|
2694
|
-
appendReversed(result, val);
|
|
2695
|
-
addToDictionary(oldCode, val[val.length - 1]);
|
|
2696
|
-
oldCode = code;
|
|
2697
|
-
} else {
|
|
2698
|
-
const oldVal = getDictionaryReversed(oldCode);
|
|
2699
|
-
if (!oldVal) {
|
|
2700
|
-
throw new Error(`Bogus entry. Not in dictionary, ${oldCode} / ${dictionaryLength}, position: ${position}`);
|
|
2701
|
-
}
|
|
2702
|
-
appendReversed(result, oldVal);
|
|
2703
|
-
result.push(oldVal[oldVal.length - 1]);
|
|
2704
|
-
addToDictionary(oldCode, oldVal[oldVal.length - 1]);
|
|
2705
|
-
oldCode = code;
|
|
2706
|
-
}
|
|
2707
|
-
if (dictionaryLength + 1 >= 2 ** byteLength) {
|
|
2708
|
-
if (byteLength === MAX_BYTELENGTH) {
|
|
2709
|
-
oldCode = void 0;
|
|
2710
|
-
} else {
|
|
2711
|
-
byteLength++;
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
code = getNext(array);
|
|
2715
|
-
}
|
|
2716
|
-
return new Uint8Array(result);
|
|
2717
|
-
}
|
|
2718
|
-
class LZWDecoder extends BaseDecoder {
|
|
2719
|
-
decodeBlock(buffer) {
|
|
2720
|
-
return decompress(buffer).buffer;
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
var lzw = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2724
|
-
__proto__: null,
|
|
2725
|
-
"default": LZWDecoder
|
|
2726
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
2727
|
-
const dctZigZag = new Int32Array([
|
|
2728
|
-
0,
|
|
2729
|
-
1,
|
|
2730
|
-
8,
|
|
2731
|
-
16,
|
|
2732
|
-
9,
|
|
2733
|
-
2,
|
|
2734
|
-
3,
|
|
2735
|
-
10,
|
|
2736
|
-
17,
|
|
2737
|
-
24,
|
|
2738
|
-
32,
|
|
2739
|
-
25,
|
|
2740
|
-
18,
|
|
2741
|
-
11,
|
|
2742
|
-
4,
|
|
2743
|
-
5,
|
|
2744
|
-
12,
|
|
2745
|
-
19,
|
|
2746
|
-
26,
|
|
2747
|
-
33,
|
|
2748
|
-
40,
|
|
2749
|
-
48,
|
|
2750
|
-
41,
|
|
2751
|
-
34,
|
|
2752
|
-
27,
|
|
2753
|
-
20,
|
|
2754
|
-
13,
|
|
2755
|
-
6,
|
|
2756
|
-
7,
|
|
2757
|
-
14,
|
|
2758
|
-
21,
|
|
2759
|
-
28,
|
|
2760
|
-
35,
|
|
2761
|
-
42,
|
|
2762
|
-
49,
|
|
2763
|
-
56,
|
|
2764
|
-
57,
|
|
2765
|
-
50,
|
|
2766
|
-
43,
|
|
2767
|
-
36,
|
|
2768
|
-
29,
|
|
2769
|
-
22,
|
|
2770
|
-
15,
|
|
2771
|
-
23,
|
|
2772
|
-
30,
|
|
2773
|
-
37,
|
|
2774
|
-
44,
|
|
2775
|
-
51,
|
|
2776
|
-
58,
|
|
2777
|
-
59,
|
|
2778
|
-
52,
|
|
2779
|
-
45,
|
|
2780
|
-
38,
|
|
2781
|
-
31,
|
|
2782
|
-
39,
|
|
2783
|
-
46,
|
|
2784
|
-
53,
|
|
2785
|
-
60,
|
|
2786
|
-
61,
|
|
2787
|
-
54,
|
|
2788
|
-
47,
|
|
2789
|
-
55,
|
|
2790
|
-
62,
|
|
2791
|
-
63
|
|
2792
|
-
]);
|
|
2793
|
-
const dctCos1 = 4017;
|
|
2794
|
-
const dctSin1 = 799;
|
|
2795
|
-
const dctCos3 = 3406;
|
|
2796
|
-
const dctSin3 = 2276;
|
|
2797
|
-
const dctCos6 = 1567;
|
|
2798
|
-
const dctSin6 = 3784;
|
|
2799
|
-
const dctSqrt2 = 5793;
|
|
2800
|
-
const dctSqrt1d2 = 2896;
|
|
2801
|
-
function buildHuffmanTable(codeLengths, values) {
|
|
2802
|
-
let k = 0;
|
|
2803
|
-
const code = [];
|
|
2804
|
-
let length = 16;
|
|
2805
|
-
while (length > 0 && !codeLengths[length - 1]) {
|
|
2806
|
-
--length;
|
|
2807
|
-
}
|
|
2808
|
-
code.push({ children: [], index: 0 });
|
|
2809
|
-
let p = code[0];
|
|
2810
|
-
let q;
|
|
2811
|
-
for (let i = 0; i < length; i++) {
|
|
2812
|
-
for (let j = 0; j < codeLengths[i]; j++) {
|
|
2813
|
-
p = code.pop();
|
|
2814
|
-
p.children[p.index] = values[k];
|
|
2815
|
-
while (p.index > 0) {
|
|
2816
|
-
p = code.pop();
|
|
2817
|
-
}
|
|
2818
|
-
p.index++;
|
|
2819
|
-
code.push(p);
|
|
2820
|
-
while (code.length <= i) {
|
|
2821
|
-
code.push(q = { children: [], index: 0 });
|
|
2822
|
-
p.children[p.index] = q.children;
|
|
2823
|
-
p = q;
|
|
2824
|
-
}
|
|
2825
|
-
k++;
|
|
2826
|
-
}
|
|
2827
|
-
if (i + 1 < length) {
|
|
2828
|
-
code.push(q = { children: [], index: 0 });
|
|
2829
|
-
p.children[p.index] = q.children;
|
|
2830
|
-
p = q;
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
return code[0].children;
|
|
2834
|
-
}
|
|
2835
|
-
function decodeScan(data, initialOffset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
|
|
2836
|
-
const { mcusPerLine, progressive } = frame;
|
|
2837
|
-
const startOffset = initialOffset;
|
|
2838
|
-
let offset = initialOffset;
|
|
2839
|
-
let bitsData = 0;
|
|
2840
|
-
let bitsCount = 0;
|
|
2841
|
-
function readBit() {
|
|
2842
|
-
if (bitsCount > 0) {
|
|
2843
|
-
bitsCount--;
|
|
2844
|
-
return bitsData >> bitsCount & 1;
|
|
2845
|
-
}
|
|
2846
|
-
bitsData = data[offset++];
|
|
2847
|
-
if (bitsData === 255) {
|
|
2848
|
-
const nextByte = data[offset++];
|
|
2849
|
-
if (nextByte) {
|
|
2850
|
-
throw new Error(`unexpected marker: ${(bitsData << 8 | nextByte).toString(16)}`);
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
bitsCount = 7;
|
|
2854
|
-
return bitsData >>> 7;
|
|
2855
|
-
}
|
|
2856
|
-
function decodeHuffman(tree) {
|
|
2857
|
-
let node = tree;
|
|
2858
|
-
let bit;
|
|
2859
|
-
while ((bit = readBit()) !== null) {
|
|
2860
|
-
node = node[bit];
|
|
2861
|
-
if (typeof node === "number") {
|
|
2862
|
-
return node;
|
|
2863
|
-
}
|
|
2864
|
-
if (typeof node !== "object") {
|
|
2865
|
-
throw new Error("invalid huffman sequence");
|
|
2866
|
-
}
|
|
2867
|
-
}
|
|
2868
|
-
return null;
|
|
2869
|
-
}
|
|
2870
|
-
function receive(initialLength) {
|
|
2871
|
-
let length = initialLength;
|
|
2872
|
-
let n2 = 0;
|
|
2873
|
-
while (length > 0) {
|
|
2874
|
-
const bit = readBit();
|
|
2875
|
-
if (bit === null) {
|
|
2876
|
-
return void 0;
|
|
2877
|
-
}
|
|
2878
|
-
n2 = n2 << 1 | bit;
|
|
2879
|
-
--length;
|
|
2880
|
-
}
|
|
2881
|
-
return n2;
|
|
2882
|
-
}
|
|
2883
|
-
function receiveAndExtend(length) {
|
|
2884
|
-
const n2 = receive(length);
|
|
2885
|
-
if (n2 >= 1 << length - 1) {
|
|
2886
|
-
return n2;
|
|
2887
|
-
}
|
|
2888
|
-
return n2 + (-1 << length) + 1;
|
|
2889
|
-
}
|
|
2890
|
-
function decodeBaseline(component2, zz) {
|
|
2891
|
-
const t = decodeHuffman(component2.huffmanTableDC);
|
|
2892
|
-
const diff = t === 0 ? 0 : receiveAndExtend(t);
|
|
2893
|
-
component2.pred += diff;
|
|
2894
|
-
zz[0] = component2.pred;
|
|
2895
|
-
let k2 = 1;
|
|
2896
|
-
while (k2 < 64) {
|
|
2897
|
-
const rs = decodeHuffman(component2.huffmanTableAC);
|
|
2898
|
-
const s = rs & 15;
|
|
2899
|
-
const r = rs >> 4;
|
|
2900
|
-
if (s === 0) {
|
|
2901
|
-
if (r < 15) {
|
|
2902
|
-
break;
|
|
2903
|
-
}
|
|
2904
|
-
k2 += 16;
|
|
2905
|
-
} else {
|
|
2906
|
-
k2 += r;
|
|
2907
|
-
const z = dctZigZag[k2];
|
|
2908
|
-
zz[z] = receiveAndExtend(s);
|
|
2909
|
-
k2++;
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
}
|
|
2913
|
-
function decodeDCFirst(component2, zz) {
|
|
2914
|
-
const t = decodeHuffman(component2.huffmanTableDC);
|
|
2915
|
-
const diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
|
|
2916
|
-
component2.pred += diff;
|
|
2917
|
-
zz[0] = component2.pred;
|
|
2918
|
-
}
|
|
2919
|
-
function decodeDCSuccessive(component2, zz) {
|
|
2920
|
-
zz[0] |= readBit() << successive;
|
|
2921
|
-
}
|
|
2922
|
-
let eobrun = 0;
|
|
2923
|
-
function decodeACFirst(component2, zz) {
|
|
2924
|
-
if (eobrun > 0) {
|
|
2925
|
-
eobrun--;
|
|
2926
|
-
return;
|
|
2927
|
-
}
|
|
2928
|
-
let k2 = spectralStart;
|
|
2929
|
-
const e = spectralEnd;
|
|
2930
|
-
while (k2 <= e) {
|
|
2931
|
-
const rs = decodeHuffman(component2.huffmanTableAC);
|
|
2932
|
-
const s = rs & 15;
|
|
2933
|
-
const r = rs >> 4;
|
|
2934
|
-
if (s === 0) {
|
|
2935
|
-
if (r < 15) {
|
|
2936
|
-
eobrun = receive(r) + (1 << r) - 1;
|
|
2937
|
-
break;
|
|
2938
|
-
}
|
|
2939
|
-
k2 += 16;
|
|
2940
|
-
} else {
|
|
2941
|
-
k2 += r;
|
|
2942
|
-
const z = dctZigZag[k2];
|
|
2943
|
-
zz[z] = receiveAndExtend(s) * (1 << successive);
|
|
2944
|
-
k2++;
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
let successiveACState = 0;
|
|
2949
|
-
let successiveACNextValue;
|
|
2950
|
-
function decodeACSuccessive(component2, zz) {
|
|
2951
|
-
let k2 = spectralStart;
|
|
2952
|
-
const e = spectralEnd;
|
|
2953
|
-
let r = 0;
|
|
2954
|
-
while (k2 <= e) {
|
|
2955
|
-
const z = dctZigZag[k2];
|
|
2956
|
-
const direction = zz[z] < 0 ? -1 : 1;
|
|
2957
|
-
switch (successiveACState) {
|
|
2958
|
-
case 0: {
|
|
2959
|
-
const rs = decodeHuffman(component2.huffmanTableAC);
|
|
2960
|
-
const s = rs & 15;
|
|
2961
|
-
r = rs >> 4;
|
|
2962
|
-
if (s === 0) {
|
|
2963
|
-
if (r < 15) {
|
|
2964
|
-
eobrun = receive(r) + (1 << r);
|
|
2965
|
-
successiveACState = 4;
|
|
2966
|
-
} else {
|
|
2967
|
-
r = 16;
|
|
2968
|
-
successiveACState = 1;
|
|
2969
|
-
}
|
|
2970
|
-
} else {
|
|
2971
|
-
if (s !== 1) {
|
|
2972
|
-
throw new Error("invalid ACn encoding");
|
|
2973
|
-
}
|
|
2974
|
-
successiveACNextValue = receiveAndExtend(s);
|
|
2975
|
-
successiveACState = r ? 2 : 3;
|
|
2976
|
-
}
|
|
2977
|
-
continue;
|
|
2978
|
-
}
|
|
2979
|
-
case 1:
|
|
2980
|
-
case 2:
|
|
2981
|
-
if (zz[z]) {
|
|
2982
|
-
zz[z] += (readBit() << successive) * direction;
|
|
2983
|
-
} else {
|
|
2984
|
-
r--;
|
|
2985
|
-
if (r === 0) {
|
|
2986
|
-
successiveACState = successiveACState === 2 ? 3 : 0;
|
|
2987
|
-
}
|
|
2988
|
-
}
|
|
2989
|
-
break;
|
|
2990
|
-
case 3:
|
|
2991
|
-
if (zz[z]) {
|
|
2992
|
-
zz[z] += (readBit() << successive) * direction;
|
|
2993
|
-
} else {
|
|
2994
|
-
zz[z] = successiveACNextValue << successive;
|
|
2995
|
-
successiveACState = 0;
|
|
2996
|
-
}
|
|
2997
|
-
break;
|
|
2998
|
-
case 4:
|
|
2999
|
-
if (zz[z]) {
|
|
3000
|
-
zz[z] += (readBit() << successive) * direction;
|
|
3001
|
-
}
|
|
3002
|
-
break;
|
|
3003
|
-
}
|
|
3004
|
-
k2++;
|
|
3005
|
-
}
|
|
3006
|
-
if (successiveACState === 4) {
|
|
3007
|
-
eobrun--;
|
|
3008
|
-
if (eobrun === 0) {
|
|
3009
|
-
successiveACState = 0;
|
|
3010
|
-
}
|
|
3011
|
-
}
|
|
3012
|
-
}
|
|
3013
|
-
function decodeMcu(component2, decodeFunction, mcu2, row, col) {
|
|
3014
|
-
const mcuRow = mcu2 / mcusPerLine | 0;
|
|
3015
|
-
const mcuCol = mcu2 % mcusPerLine;
|
|
3016
|
-
const blockRow = mcuRow * component2.v + row;
|
|
3017
|
-
const blockCol = mcuCol * component2.h + col;
|
|
3018
|
-
decodeFunction(component2, component2.blocks[blockRow][blockCol]);
|
|
3019
|
-
}
|
|
3020
|
-
function decodeBlock(component2, decodeFunction, mcu2) {
|
|
3021
|
-
const blockRow = mcu2 / component2.blocksPerLine | 0;
|
|
3022
|
-
const blockCol = mcu2 % component2.blocksPerLine;
|
|
3023
|
-
decodeFunction(component2, component2.blocks[blockRow][blockCol]);
|
|
3024
|
-
}
|
|
3025
|
-
const componentsLength = components.length;
|
|
3026
|
-
let component;
|
|
3027
|
-
let i;
|
|
3028
|
-
let j;
|
|
3029
|
-
let k;
|
|
3030
|
-
let n;
|
|
3031
|
-
let decodeFn;
|
|
3032
|
-
if (progressive) {
|
|
3033
|
-
if (spectralStart === 0) {
|
|
3034
|
-
decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
|
|
3035
|
-
} else {
|
|
3036
|
-
decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
|
|
3037
|
-
}
|
|
3038
|
-
} else {
|
|
3039
|
-
decodeFn = decodeBaseline;
|
|
3040
|
-
}
|
|
3041
|
-
let mcu = 0;
|
|
3042
|
-
let marker;
|
|
3043
|
-
let mcuExpected;
|
|
3044
|
-
if (componentsLength === 1) {
|
|
3045
|
-
mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
|
|
3046
|
-
} else {
|
|
3047
|
-
mcuExpected = mcusPerLine * frame.mcusPerColumn;
|
|
3048
|
-
}
|
|
3049
|
-
const usedResetInterval = resetInterval || mcuExpected;
|
|
3050
|
-
while (mcu < mcuExpected) {
|
|
3051
|
-
for (i = 0; i < componentsLength; i++) {
|
|
3052
|
-
components[i].pred = 0;
|
|
3053
|
-
}
|
|
3054
|
-
eobrun = 0;
|
|
3055
|
-
if (componentsLength === 1) {
|
|
3056
|
-
component = components[0];
|
|
3057
|
-
for (n = 0; n < usedResetInterval; n++) {
|
|
3058
|
-
decodeBlock(component, decodeFn, mcu);
|
|
3059
|
-
mcu++;
|
|
3060
|
-
}
|
|
3061
|
-
} else {
|
|
3062
|
-
for (n = 0; n < usedResetInterval; n++) {
|
|
3063
|
-
for (i = 0; i < componentsLength; i++) {
|
|
3064
|
-
component = components[i];
|
|
3065
|
-
const { h, v } = component;
|
|
3066
|
-
for (j = 0; j < v; j++) {
|
|
3067
|
-
for (k = 0; k < h; k++) {
|
|
3068
|
-
decodeMcu(component, decodeFn, mcu, j, k);
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3072
|
-
mcu++;
|
|
3073
|
-
if (mcu === mcuExpected) {
|
|
3074
|
-
break;
|
|
3075
|
-
}
|
|
3076
|
-
}
|
|
3077
|
-
}
|
|
3078
|
-
bitsCount = 0;
|
|
3079
|
-
marker = data[offset] << 8 | data[offset + 1];
|
|
3080
|
-
if (marker < 65280) {
|
|
3081
|
-
throw new Error("marker was not found");
|
|
3082
|
-
}
|
|
3083
|
-
if (marker >= 65488 && marker <= 65495) {
|
|
3084
|
-
offset += 2;
|
|
3085
|
-
} else {
|
|
3086
|
-
break;
|
|
3087
|
-
}
|
|
3088
|
-
}
|
|
3089
|
-
return offset - startOffset;
|
|
3090
|
-
}
|
|
3091
|
-
function buildComponentData(frame, component) {
|
|
3092
|
-
const lines = [];
|
|
3093
|
-
const { blocksPerLine, blocksPerColumn } = component;
|
|
3094
|
-
const samplesPerLine = blocksPerLine << 3;
|
|
3095
|
-
const R = new Int32Array(64);
|
|
3096
|
-
const r = new Uint8Array(64);
|
|
3097
|
-
function quantizeAndInverse(zz, dataOut, dataIn) {
|
|
3098
|
-
const qt = component.quantizationTable;
|
|
3099
|
-
let v0;
|
|
3100
|
-
let v1;
|
|
3101
|
-
let v2;
|
|
3102
|
-
let v3;
|
|
3103
|
-
let v4;
|
|
3104
|
-
let v5;
|
|
3105
|
-
let v6;
|
|
3106
|
-
let v7;
|
|
3107
|
-
let t;
|
|
3108
|
-
const p = dataIn;
|
|
3109
|
-
let i;
|
|
3110
|
-
for (i = 0; i < 64; i++) {
|
|
3111
|
-
p[i] = zz[i] * qt[i];
|
|
3112
|
-
}
|
|
3113
|
-
for (i = 0; i < 8; ++i) {
|
|
3114
|
-
const row = 8 * i;
|
|
3115
|
-
if (p[1 + row] === 0 && p[2 + row] === 0 && p[3 + row] === 0 && p[4 + row] === 0 && p[5 + row] === 0 && p[6 + row] === 0 && p[7 + row] === 0) {
|
|
3116
|
-
t = dctSqrt2 * p[0 + row] + 512 >> 10;
|
|
3117
|
-
p[0 + row] = t;
|
|
3118
|
-
p[1 + row] = t;
|
|
3119
|
-
p[2 + row] = t;
|
|
3120
|
-
p[3 + row] = t;
|
|
3121
|
-
p[4 + row] = t;
|
|
3122
|
-
p[5 + row] = t;
|
|
3123
|
-
p[6 + row] = t;
|
|
3124
|
-
p[7 + row] = t;
|
|
3125
|
-
continue;
|
|
3126
|
-
}
|
|
3127
|
-
v0 = dctSqrt2 * p[0 + row] + 128 >> 8;
|
|
3128
|
-
v1 = dctSqrt2 * p[4 + row] + 128 >> 8;
|
|
3129
|
-
v2 = p[2 + row];
|
|
3130
|
-
v3 = p[6 + row];
|
|
3131
|
-
v4 = dctSqrt1d2 * (p[1 + row] - p[7 + row]) + 128 >> 8;
|
|
3132
|
-
v7 = dctSqrt1d2 * (p[1 + row] + p[7 + row]) + 128 >> 8;
|
|
3133
|
-
v5 = p[3 + row] << 4;
|
|
3134
|
-
v6 = p[5 + row] << 4;
|
|
3135
|
-
t = v0 - v1 + 1 >> 1;
|
|
3136
|
-
v0 = v0 + v1 + 1 >> 1;
|
|
3137
|
-
v1 = t;
|
|
3138
|
-
t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
|
|
3139
|
-
v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
|
|
3140
|
-
v3 = t;
|
|
3141
|
-
t = v4 - v6 + 1 >> 1;
|
|
3142
|
-
v4 = v4 + v6 + 1 >> 1;
|
|
3143
|
-
v6 = t;
|
|
3144
|
-
t = v7 + v5 + 1 >> 1;
|
|
3145
|
-
v5 = v7 - v5 + 1 >> 1;
|
|
3146
|
-
v7 = t;
|
|
3147
|
-
t = v0 - v3 + 1 >> 1;
|
|
3148
|
-
v0 = v0 + v3 + 1 >> 1;
|
|
3149
|
-
v3 = t;
|
|
3150
|
-
t = v1 - v2 + 1 >> 1;
|
|
3151
|
-
v1 = v1 + v2 + 1 >> 1;
|
|
3152
|
-
v2 = t;
|
|
3153
|
-
t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
|
|
3154
|
-
v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
|
|
3155
|
-
v7 = t;
|
|
3156
|
-
t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
|
|
3157
|
-
v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
|
|
3158
|
-
v6 = t;
|
|
3159
|
-
p[0 + row] = v0 + v7;
|
|
3160
|
-
p[7 + row] = v0 - v7;
|
|
3161
|
-
p[1 + row] = v1 + v6;
|
|
3162
|
-
p[6 + row] = v1 - v6;
|
|
3163
|
-
p[2 + row] = v2 + v5;
|
|
3164
|
-
p[5 + row] = v2 - v5;
|
|
3165
|
-
p[3 + row] = v3 + v4;
|
|
3166
|
-
p[4 + row] = v3 - v4;
|
|
3167
|
-
}
|
|
3168
|
-
for (i = 0; i < 8; ++i) {
|
|
3169
|
-
const col = i;
|
|
3170
|
-
if (p[1 * 8 + col] === 0 && p[2 * 8 + col] === 0 && p[3 * 8 + col] === 0 && p[4 * 8 + col] === 0 && p[5 * 8 + col] === 0 && p[6 * 8 + col] === 0 && p[7 * 8 + col] === 0) {
|
|
3171
|
-
t = dctSqrt2 * dataIn[i + 0] + 8192 >> 14;
|
|
3172
|
-
p[0 * 8 + col] = t;
|
|
3173
|
-
p[1 * 8 + col] = t;
|
|
3174
|
-
p[2 * 8 + col] = t;
|
|
3175
|
-
p[3 * 8 + col] = t;
|
|
3176
|
-
p[4 * 8 + col] = t;
|
|
3177
|
-
p[5 * 8 + col] = t;
|
|
3178
|
-
p[6 * 8 + col] = t;
|
|
3179
|
-
p[7 * 8 + col] = t;
|
|
3180
|
-
continue;
|
|
3181
|
-
}
|
|
3182
|
-
v0 = dctSqrt2 * p[0 * 8 + col] + 2048 >> 12;
|
|
3183
|
-
v1 = dctSqrt2 * p[4 * 8 + col] + 2048 >> 12;
|
|
3184
|
-
v2 = p[2 * 8 + col];
|
|
3185
|
-
v3 = p[6 * 8 + col];
|
|
3186
|
-
v4 = dctSqrt1d2 * (p[1 * 8 + col] - p[7 * 8 + col]) + 2048 >> 12;
|
|
3187
|
-
v7 = dctSqrt1d2 * (p[1 * 8 + col] + p[7 * 8 + col]) + 2048 >> 12;
|
|
3188
|
-
v5 = p[3 * 8 + col];
|
|
3189
|
-
v6 = p[5 * 8 + col];
|
|
3190
|
-
t = v0 - v1 + 1 >> 1;
|
|
3191
|
-
v0 = v0 + v1 + 1 >> 1;
|
|
3192
|
-
v1 = t;
|
|
3193
|
-
t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
|
|
3194
|
-
v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
|
|
3195
|
-
v3 = t;
|
|
3196
|
-
t = v4 - v6 + 1 >> 1;
|
|
3197
|
-
v4 = v4 + v6 + 1 >> 1;
|
|
3198
|
-
v6 = t;
|
|
3199
|
-
t = v7 + v5 + 1 >> 1;
|
|
3200
|
-
v5 = v7 - v5 + 1 >> 1;
|
|
3201
|
-
v7 = t;
|
|
3202
|
-
t = v0 - v3 + 1 >> 1;
|
|
3203
|
-
v0 = v0 + v3 + 1 >> 1;
|
|
3204
|
-
v3 = t;
|
|
3205
|
-
t = v1 - v2 + 1 >> 1;
|
|
3206
|
-
v1 = v1 + v2 + 1 >> 1;
|
|
3207
|
-
v2 = t;
|
|
3208
|
-
t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
|
|
3209
|
-
v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
|
|
3210
|
-
v7 = t;
|
|
3211
|
-
t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
|
|
3212
|
-
v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
|
|
3213
|
-
v6 = t;
|
|
3214
|
-
p[0 * 8 + col] = v0 + v7;
|
|
3215
|
-
p[7 * 8 + col] = v0 - v7;
|
|
3216
|
-
p[1 * 8 + col] = v1 + v6;
|
|
3217
|
-
p[6 * 8 + col] = v1 - v6;
|
|
3218
|
-
p[2 * 8 + col] = v2 + v5;
|
|
3219
|
-
p[5 * 8 + col] = v2 - v5;
|
|
3220
|
-
p[3 * 8 + col] = v3 + v4;
|
|
3221
|
-
p[4 * 8 + col] = v3 - v4;
|
|
3222
|
-
}
|
|
3223
|
-
for (i = 0; i < 64; ++i) {
|
|
3224
|
-
const sample = 128 + (p[i] + 8 >> 4);
|
|
3225
|
-
if (sample < 0) {
|
|
3226
|
-
dataOut[i] = 0;
|
|
3227
|
-
} else if (sample > 255) {
|
|
3228
|
-
dataOut[i] = 255;
|
|
3229
|
-
} else {
|
|
3230
|
-
dataOut[i] = sample;
|
|
3231
|
-
}
|
|
3232
|
-
}
|
|
3233
|
-
}
|
|
3234
|
-
for (let blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
|
|
3235
|
-
const scanLine = blockRow << 3;
|
|
3236
|
-
for (let i = 0; i < 8; i++) {
|
|
3237
|
-
lines.push(new Uint8Array(samplesPerLine));
|
|
3238
|
-
}
|
|
3239
|
-
for (let blockCol = 0; blockCol < blocksPerLine; blockCol++) {
|
|
3240
|
-
quantizeAndInverse(component.blocks[blockRow][blockCol], r, R);
|
|
3241
|
-
let offset = 0;
|
|
3242
|
-
const sample = blockCol << 3;
|
|
3243
|
-
for (let j = 0; j < 8; j++) {
|
|
3244
|
-
const line = lines[scanLine + j];
|
|
3245
|
-
for (let i = 0; i < 8; i++) {
|
|
3246
|
-
line[sample + i] = r[offset++];
|
|
3247
|
-
}
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
}
|
|
3251
|
-
return lines;
|
|
3252
|
-
}
|
|
3253
|
-
class JpegStreamReader {
|
|
3254
|
-
constructor() {
|
|
3255
|
-
this.jfif = null;
|
|
3256
|
-
this.adobe = null;
|
|
3257
|
-
this.quantizationTables = [];
|
|
3258
|
-
this.huffmanTablesAC = [];
|
|
3259
|
-
this.huffmanTablesDC = [];
|
|
3260
|
-
this.resetFrames();
|
|
3261
|
-
}
|
|
3262
|
-
resetFrames() {
|
|
3263
|
-
this.frames = [];
|
|
3264
|
-
}
|
|
3265
|
-
parse(data) {
|
|
3266
|
-
let offset = 0;
|
|
3267
|
-
function readUint16() {
|
|
3268
|
-
const value = data[offset] << 8 | data[offset + 1];
|
|
3269
|
-
offset += 2;
|
|
3270
|
-
return value;
|
|
3271
|
-
}
|
|
3272
|
-
function readDataBlock() {
|
|
3273
|
-
const length = readUint16();
|
|
3274
|
-
const array = data.subarray(offset, offset + length - 2);
|
|
3275
|
-
offset += array.length;
|
|
3276
|
-
return array;
|
|
3277
|
-
}
|
|
3278
|
-
function prepareComponents(frame) {
|
|
3279
|
-
let maxH = 0;
|
|
3280
|
-
let maxV = 0;
|
|
3281
|
-
let component;
|
|
3282
|
-
let componentId;
|
|
3283
|
-
for (componentId in frame.components) {
|
|
3284
|
-
if (frame.components.hasOwnProperty(componentId)) {
|
|
3285
|
-
component = frame.components[componentId];
|
|
3286
|
-
if (maxH < component.h) {
|
|
3287
|
-
maxH = component.h;
|
|
3288
|
-
}
|
|
3289
|
-
if (maxV < component.v) {
|
|
3290
|
-
maxV = component.v;
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
}
|
|
3294
|
-
const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / maxH);
|
|
3295
|
-
const mcusPerColumn = Math.ceil(frame.scanLines / 8 / maxV);
|
|
3296
|
-
for (componentId in frame.components) {
|
|
3297
|
-
if (frame.components.hasOwnProperty(componentId)) {
|
|
3298
|
-
component = frame.components[componentId];
|
|
3299
|
-
const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / maxH);
|
|
3300
|
-
const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / maxV);
|
|
3301
|
-
const blocksPerLineForMcu = mcusPerLine * component.h;
|
|
3302
|
-
const blocksPerColumnForMcu = mcusPerColumn * component.v;
|
|
3303
|
-
const blocks = [];
|
|
3304
|
-
for (let i = 0; i < blocksPerColumnForMcu; i++) {
|
|
3305
|
-
const row = [];
|
|
3306
|
-
for (let j = 0; j < blocksPerLineForMcu; j++) {
|
|
3307
|
-
row.push(new Int32Array(64));
|
|
3308
|
-
}
|
|
3309
|
-
blocks.push(row);
|
|
3310
|
-
}
|
|
3311
|
-
component.blocksPerLine = blocksPerLine;
|
|
3312
|
-
component.blocksPerColumn = blocksPerColumn;
|
|
3313
|
-
component.blocks = blocks;
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
frame.maxH = maxH;
|
|
3317
|
-
frame.maxV = maxV;
|
|
3318
|
-
frame.mcusPerLine = mcusPerLine;
|
|
3319
|
-
frame.mcusPerColumn = mcusPerColumn;
|
|
3320
|
-
}
|
|
3321
|
-
let fileMarker = readUint16();
|
|
3322
|
-
if (fileMarker !== 65496) {
|
|
3323
|
-
throw new Error("SOI not found");
|
|
3324
|
-
}
|
|
3325
|
-
fileMarker = readUint16();
|
|
3326
|
-
while (fileMarker !== 65497) {
|
|
3327
|
-
switch (fileMarker) {
|
|
3328
|
-
case 65280:
|
|
3329
|
-
break;
|
|
3330
|
-
case 65504:
|
|
3331
|
-
case 65505:
|
|
3332
|
-
case 65506:
|
|
3333
|
-
case 65507:
|
|
3334
|
-
case 65508:
|
|
3335
|
-
case 65509:
|
|
3336
|
-
case 65510:
|
|
3337
|
-
case 65511:
|
|
3338
|
-
case 65512:
|
|
3339
|
-
case 65513:
|
|
3340
|
-
case 65514:
|
|
3341
|
-
case 65515:
|
|
3342
|
-
case 65516:
|
|
3343
|
-
case 65517:
|
|
3344
|
-
case 65518:
|
|
3345
|
-
case 65519:
|
|
3346
|
-
case 65534: {
|
|
3347
|
-
const appData = readDataBlock();
|
|
3348
|
-
if (fileMarker === 65504) {
|
|
3349
|
-
if (appData[0] === 74 && appData[1] === 70 && appData[2] === 73 && appData[3] === 70 && appData[4] === 0) {
|
|
3350
|
-
this.jfif = {
|
|
3351
|
-
version: { major: appData[5], minor: appData[6] },
|
|
3352
|
-
densityUnits: appData[7],
|
|
3353
|
-
xDensity: appData[8] << 8 | appData[9],
|
|
3354
|
-
yDensity: appData[10] << 8 | appData[11],
|
|
3355
|
-
thumbWidth: appData[12],
|
|
3356
|
-
thumbHeight: appData[13],
|
|
3357
|
-
thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
|
|
3358
|
-
};
|
|
3359
|
-
}
|
|
3360
|
-
}
|
|
3361
|
-
if (fileMarker === 65518) {
|
|
3362
|
-
if (appData[0] === 65 && appData[1] === 100 && appData[2] === 111 && appData[3] === 98 && appData[4] === 101 && appData[5] === 0) {
|
|
3363
|
-
this.adobe = {
|
|
3364
|
-
version: appData[6],
|
|
3365
|
-
flags0: appData[7] << 8 | appData[8],
|
|
3366
|
-
flags1: appData[9] << 8 | appData[10],
|
|
3367
|
-
transformCode: appData[11]
|
|
3368
|
-
};
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
break;
|
|
3372
|
-
}
|
|
3373
|
-
case 65499: {
|
|
3374
|
-
const quantizationTablesLength = readUint16();
|
|
3375
|
-
const quantizationTablesEnd = quantizationTablesLength + offset - 2;
|
|
3376
|
-
while (offset < quantizationTablesEnd) {
|
|
3377
|
-
const quantizationTableSpec = data[offset++];
|
|
3378
|
-
const tableData = new Int32Array(64);
|
|
3379
|
-
if (quantizationTableSpec >> 4 === 0) {
|
|
3380
|
-
for (let j = 0; j < 64; j++) {
|
|
3381
|
-
const z = dctZigZag[j];
|
|
3382
|
-
tableData[z] = data[offset++];
|
|
3383
|
-
}
|
|
3384
|
-
} else if (quantizationTableSpec >> 4 === 1) {
|
|
3385
|
-
for (let j = 0; j < 64; j++) {
|
|
3386
|
-
const z = dctZigZag[j];
|
|
3387
|
-
tableData[z] = readUint16();
|
|
3388
|
-
}
|
|
3389
|
-
} else {
|
|
3390
|
-
throw new Error("DQT: invalid table spec");
|
|
3391
|
-
}
|
|
3392
|
-
this.quantizationTables[quantizationTableSpec & 15] = tableData;
|
|
3393
|
-
}
|
|
3394
|
-
break;
|
|
3395
|
-
}
|
|
3396
|
-
case 65472:
|
|
3397
|
-
case 65473:
|
|
3398
|
-
case 65474: {
|
|
3399
|
-
readUint16();
|
|
3400
|
-
const frame = {
|
|
3401
|
-
extended: fileMarker === 65473,
|
|
3402
|
-
progressive: fileMarker === 65474,
|
|
3403
|
-
precision: data[offset++],
|
|
3404
|
-
scanLines: readUint16(),
|
|
3405
|
-
samplesPerLine: readUint16(),
|
|
3406
|
-
components: {},
|
|
3407
|
-
componentsOrder: []
|
|
3408
|
-
};
|
|
3409
|
-
const componentsCount = data[offset++];
|
|
3410
|
-
let componentId;
|
|
3411
|
-
for (let i = 0; i < componentsCount; i++) {
|
|
3412
|
-
componentId = data[offset];
|
|
3413
|
-
const h = data[offset + 1] >> 4;
|
|
3414
|
-
const v = data[offset + 1] & 15;
|
|
3415
|
-
const qId = data[offset + 2];
|
|
3416
|
-
frame.componentsOrder.push(componentId);
|
|
3417
|
-
frame.components[componentId] = {
|
|
3418
|
-
h,
|
|
3419
|
-
v,
|
|
3420
|
-
quantizationIdx: qId
|
|
3421
|
-
};
|
|
3422
|
-
offset += 3;
|
|
3423
|
-
}
|
|
3424
|
-
prepareComponents(frame);
|
|
3425
|
-
this.frames.push(frame);
|
|
3426
|
-
break;
|
|
3427
|
-
}
|
|
3428
|
-
case 65476: {
|
|
3429
|
-
const huffmanLength = readUint16();
|
|
3430
|
-
for (let i = 2; i < huffmanLength; ) {
|
|
3431
|
-
const huffmanTableSpec = data[offset++];
|
|
3432
|
-
const codeLengths = new Uint8Array(16);
|
|
3433
|
-
let codeLengthSum = 0;
|
|
3434
|
-
for (let j = 0; j < 16; j++, offset++) {
|
|
3435
|
-
codeLengths[j] = data[offset];
|
|
3436
|
-
codeLengthSum += codeLengths[j];
|
|
3437
|
-
}
|
|
3438
|
-
const huffmanValues = new Uint8Array(codeLengthSum);
|
|
3439
|
-
for (let j = 0; j < codeLengthSum; j++, offset++) {
|
|
3440
|
-
huffmanValues[j] = data[offset];
|
|
3441
|
-
}
|
|
3442
|
-
i += 17 + codeLengthSum;
|
|
3443
|
-
if (huffmanTableSpec >> 4 === 0) {
|
|
3444
|
-
this.huffmanTablesDC[huffmanTableSpec & 15] = buildHuffmanTable(
|
|
3445
|
-
codeLengths,
|
|
3446
|
-
huffmanValues
|
|
3447
|
-
);
|
|
3448
|
-
} else {
|
|
3449
|
-
this.huffmanTablesAC[huffmanTableSpec & 15] = buildHuffmanTable(
|
|
3450
|
-
codeLengths,
|
|
3451
|
-
huffmanValues
|
|
3452
|
-
);
|
|
3453
|
-
}
|
|
3454
|
-
}
|
|
3455
|
-
break;
|
|
3456
|
-
}
|
|
3457
|
-
case 65501:
|
|
3458
|
-
readUint16();
|
|
3459
|
-
this.resetInterval = readUint16();
|
|
3460
|
-
break;
|
|
3461
|
-
case 65498: {
|
|
3462
|
-
readUint16();
|
|
3463
|
-
const selectorsCount = data[offset++];
|
|
3464
|
-
const components = [];
|
|
3465
|
-
const frame = this.frames[0];
|
|
3466
|
-
for (let i = 0; i < selectorsCount; i++) {
|
|
3467
|
-
const component = frame.components[data[offset++]];
|
|
3468
|
-
const tableSpec = data[offset++];
|
|
3469
|
-
component.huffmanTableDC = this.huffmanTablesDC[tableSpec >> 4];
|
|
3470
|
-
component.huffmanTableAC = this.huffmanTablesAC[tableSpec & 15];
|
|
3471
|
-
components.push(component);
|
|
3472
|
-
}
|
|
3473
|
-
const spectralStart = data[offset++];
|
|
3474
|
-
const spectralEnd = data[offset++];
|
|
3475
|
-
const successiveApproximation = data[offset++];
|
|
3476
|
-
const processed = decodeScan(
|
|
3477
|
-
data,
|
|
3478
|
-
offset,
|
|
3479
|
-
frame,
|
|
3480
|
-
components,
|
|
3481
|
-
this.resetInterval,
|
|
3482
|
-
spectralStart,
|
|
3483
|
-
spectralEnd,
|
|
3484
|
-
successiveApproximation >> 4,
|
|
3485
|
-
successiveApproximation & 15
|
|
3486
|
-
);
|
|
3487
|
-
offset += processed;
|
|
3488
|
-
break;
|
|
3489
|
-
}
|
|
3490
|
-
case 65535:
|
|
3491
|
-
if (data[offset] !== 255) {
|
|
3492
|
-
offset--;
|
|
3493
|
-
}
|
|
3494
|
-
break;
|
|
3495
|
-
default:
|
|
3496
|
-
if (data[offset - 3] === 255 && data[offset - 2] >= 192 && data[offset - 2] <= 254) {
|
|
3497
|
-
offset -= 3;
|
|
3498
|
-
break;
|
|
3499
|
-
}
|
|
3500
|
-
throw new Error(`unknown JPEG marker ${fileMarker.toString(16)}`);
|
|
3501
|
-
}
|
|
3502
|
-
fileMarker = readUint16();
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
getResult() {
|
|
3506
|
-
const { frames } = this;
|
|
3507
|
-
if (this.frames.length === 0) {
|
|
3508
|
-
throw new Error("no frames were decoded");
|
|
3509
|
-
} else if (this.frames.length > 1) {
|
|
3510
|
-
console.warn("more than one frame is not supported");
|
|
3511
|
-
}
|
|
3512
|
-
for (let i = 0; i < this.frames.length; i++) {
|
|
3513
|
-
const cp = this.frames[i].components;
|
|
3514
|
-
for (const j of Object.keys(cp)) {
|
|
3515
|
-
cp[j].quantizationTable = this.quantizationTables[cp[j].quantizationIdx];
|
|
3516
|
-
delete cp[j].quantizationIdx;
|
|
3517
|
-
}
|
|
3518
|
-
}
|
|
3519
|
-
const frame = frames[0];
|
|
3520
|
-
const { components, componentsOrder } = frame;
|
|
3521
|
-
const outComponents = [];
|
|
3522
|
-
const width = frame.samplesPerLine;
|
|
3523
|
-
const height = frame.scanLines;
|
|
3524
|
-
for (let i = 0; i < componentsOrder.length; i++) {
|
|
3525
|
-
const component = components[componentsOrder[i]];
|
|
3526
|
-
outComponents.push({
|
|
3527
|
-
lines: buildComponentData(frame, component),
|
|
3528
|
-
scaleX: component.h / frame.maxH,
|
|
3529
|
-
scaleY: component.v / frame.maxV
|
|
3530
|
-
});
|
|
3531
|
-
}
|
|
3532
|
-
const out = new Uint8Array(width * height * outComponents.length);
|
|
3533
|
-
let oi = 0;
|
|
3534
|
-
for (let y = 0; y < height; ++y) {
|
|
3535
|
-
for (let x = 0; x < width; ++x) {
|
|
3536
|
-
for (let i = 0; i < outComponents.length; ++i) {
|
|
3537
|
-
const component = outComponents[i];
|
|
3538
|
-
out[oi] = component.lines[0 | y * component.scaleY][0 | x * component.scaleX];
|
|
3539
|
-
++oi;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
}
|
|
3543
|
-
return out;
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
|
-
class JpegDecoder extends BaseDecoder {
|
|
3547
|
-
constructor(fileDirectory) {
|
|
3548
|
-
super();
|
|
3549
|
-
this.reader = new JpegStreamReader();
|
|
3550
|
-
if (fileDirectory.JPEGTables) {
|
|
3551
|
-
this.reader.parse(fileDirectory.JPEGTables);
|
|
3552
|
-
}
|
|
3553
|
-
}
|
|
3554
|
-
decodeBlock(buffer) {
|
|
3555
|
-
this.reader.resetFrames();
|
|
3556
|
-
this.reader.parse(new Uint8Array(buffer));
|
|
3557
|
-
return this.reader.getResult().buffer;
|
|
3558
|
-
}
|
|
3559
|
-
}
|
|
3560
|
-
var jpeg = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3561
|
-
__proto__: null,
|
|
3562
|
-
"default": JpegDecoder
|
|
3563
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
3564
|
-
class DeflateDecoder extends BaseDecoder {
|
|
3565
|
-
decodeBlock(buffer) {
|
|
3566
|
-
return inflate_1(new Uint8Array(buffer)).buffer;
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
var deflate = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3570
|
-
__proto__: null,
|
|
3571
|
-
"default": DeflateDecoder
|
|
3572
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
3573
|
-
class PackbitsDecoder extends BaseDecoder {
|
|
3574
|
-
decodeBlock(buffer) {
|
|
3575
|
-
const dataView = new DataView(buffer);
|
|
3576
|
-
const out = [];
|
|
3577
|
-
for (let i = 0; i < buffer.byteLength; ++i) {
|
|
3578
|
-
let header = dataView.getInt8(i);
|
|
3579
|
-
if (header < 0) {
|
|
3580
|
-
const next = dataView.getUint8(i + 1);
|
|
3581
|
-
header = -header;
|
|
3582
|
-
for (let j = 0; j <= header; ++j) {
|
|
3583
|
-
out.push(next);
|
|
3584
|
-
}
|
|
3585
|
-
i += 1;
|
|
3586
|
-
} else {
|
|
3587
|
-
for (let j = 0; j <= header; ++j) {
|
|
3588
|
-
out.push(dataView.getUint8(i + j + 1));
|
|
3589
|
-
}
|
|
3590
|
-
i += header + 1;
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
return new Uint8Array(out).buffer;
|
|
3594
|
-
}
|
|
3595
|
-
}
|
|
3596
|
-
var packbits = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3597
|
-
__proto__: null,
|
|
3598
|
-
"default": PackbitsDecoder
|
|
3599
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
3600
|
-
class LercDecoder extends BaseDecoder {
|
|
3601
|
-
constructor(fileDirectory) {
|
|
3602
|
-
super();
|
|
3603
|
-
this.planarConfiguration = typeof fileDirectory.PlanarConfiguration !== "undefined" ? fileDirectory.PlanarConfiguration : 1;
|
|
3604
|
-
this.samplesPerPixel = typeof fileDirectory.SamplesPerPixel !== "undefined" ? fileDirectory.SamplesPerPixel : 1;
|
|
3605
|
-
this.addCompression = fileDirectory.LercParameters[LercParameters.AddCompression];
|
|
3606
|
-
}
|
|
3607
|
-
decodeBlock(buffer) {
|
|
3608
|
-
switch (this.addCompression) {
|
|
3609
|
-
case LercAddCompression.None:
|
|
3610
|
-
break;
|
|
3611
|
-
case LercAddCompression.Deflate:
|
|
3612
|
-
buffer = inflate_1(new Uint8Array(buffer)).buffer;
|
|
3613
|
-
break;
|
|
3614
|
-
default:
|
|
3615
|
-
throw new Error(`Unsupported LERC additional compression method identifier: ${this.addCompression}`);
|
|
3616
|
-
}
|
|
3617
|
-
const lercResult = Lerc.decode(buffer, { returnPixelInterleavedDims: this.planarConfiguration === 1 });
|
|
3618
|
-
const lercData = lercResult.pixels[0];
|
|
3619
|
-
return lercData.buffer;
|
|
3620
|
-
}
|
|
3621
|
-
}
|
|
3622
|
-
var lerc = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3623
|
-
__proto__: null,
|
|
3624
|
-
"default": LercDecoder
|
|
3625
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
3626
|
-
class WebImageDecoder extends BaseDecoder {
|
|
3627
|
-
constructor() {
|
|
3628
|
-
super();
|
|
3629
|
-
if (typeof createImageBitmap === "undefined") {
|
|
3630
|
-
throw new Error("Cannot decode WebImage as `createImageBitmap` is not available");
|
|
3631
|
-
} else if (typeof document === "undefined" && typeof OffscreenCanvas === "undefined") {
|
|
3632
|
-
throw new Error("Cannot decode WebImage as neither `document` nor `OffscreenCanvas` is not available");
|
|
3633
|
-
}
|
|
3634
|
-
}
|
|
3635
|
-
async decode(fileDirectory, buffer) {
|
|
3636
|
-
const blob = new Blob([buffer]);
|
|
3637
|
-
const imageBitmap = await createImageBitmap(blob);
|
|
3638
|
-
let canvas;
|
|
3639
|
-
if (typeof document !== "undefined") {
|
|
3640
|
-
canvas = document.createElement("canvas");
|
|
3641
|
-
canvas.width = imageBitmap.width;
|
|
3642
|
-
canvas.height = imageBitmap.height;
|
|
3643
|
-
} else {
|
|
3644
|
-
canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
|
|
3645
|
-
}
|
|
3646
|
-
const ctx = canvas.getContext("2d");
|
|
3647
|
-
ctx.drawImage(imageBitmap, 0, 0);
|
|
3648
|
-
return ctx.getImageData(0, 0, imageBitmap.width, imageBitmap.height).data.buffer;
|
|
3649
|
-
}
|
|
3650
|
-
}
|
|
3651
|
-
var webimage = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3652
|
-
__proto__: null,
|
|
3653
|
-
"default": WebImageDecoder
|
|
3654
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
3655
|
-
function create() {
|
|
3656
|
-
const source = 'function e(e,t,r,n,i,a,o){try{var s=e[a](o),f=s.value}catch(e){return void r(e)}s.done?t(f):Promise.resolve(f).then(n,i)}function t(t){return function(){var r=this,n=arguments;return new Promise((function(i,a){var o=t.apply(r,n);function s(t){e(o,i,a,s,f,"next",t)}function f(t){e(o,i,a,s,f,"throw",t)}s(void 0)}))}}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}var n={exports:{}};!function(e){var t=function(e){var t,n=Object.prototype,i=n.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=t&&t.prototype instanceof y?t:y,a=Object.create(i.prototype),o=new T(n||[]);return a._invoke=function(e,t,r){var n=h;return function(i,a){if(n===p)throw new Error("Generator is already running");if(n===m){if("throw"===i)throw a;return E()}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var s=I(o,r);if(s){if(s===v)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===h)throw n=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var f=c(e,t,r);if("normal"===f.type){if(n=r.done?m:d,f.arg===v)continue;return{value:f.arg,done:r.done}}"throw"===f.type&&(n=m,r.method="throw",r.arg=f.arg)}}}(e,r,o),a}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var h="suspendedStart",d="suspendedYield",p="executing",m="completed",v={};function y(){}function w(){}function g(){}var b={};l(b,o,(function(){return this}));var k=Object.getPrototypeOf,x=k&&k(k(D([])));x&&x!==n&&i.call(x,o)&&(b=x);var _=g.prototype=y.prototype=Object.create(b);function A(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function P(e,t){function n(a,o,s,f){var l=c(e[a],e,o);if("throw"!==l.type){var u=l.arg,h=u.value;return h&&"object"===r(h)&&i.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,s,f)}),(function(e){n("throw",e,s,f)})):t.resolve(h).then((function(e){u.value=e,s(u)}),(function(e){return n("throw",e,s,f)}))}f(l.arg)}var a;this._invoke=function(e,r){function i(){return new t((function(t,i){n(e,r,t,i)}))}return a=a?a.then(i,i):i()}}function I(e,r){var n=e.iterator[r.method];if(n===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=t,I(e,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a \'throw\' method")}return v}var i=c(n,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function U(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function S(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(U,this),this.reset(!0)}function D(e){if(e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,a=function r(){for(;++n<e.length;)if(i.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}return{next:E}}function E(){return{value:t,done:!0}}return w.prototype=g,l(_,"constructor",g),l(g,"constructor",w),w.displayName=l(g,f,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===w||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,l(e,f,"GeneratorFunction")),e.prototype=Object.create(_),e},e.awrap=function(e){return{__await:e}},A(P.prototype),l(P.prototype,s,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,i,a){void 0===a&&(a=Promise);var o=new P(u(t,r,n,i),a);return e.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},A(_),l(_,f,"Generator"),l(_,o,(function(){return this})),l(_,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=D,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(S),!e)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,i){return s.type="throw",s.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var f=i.call(o,"catchLoc"),l=i.call(o,"finallyLoc");if(f&&l){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(f){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),S(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;S(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:D(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"===("undefined"==typeof globalThis?"undefined":r(globalThis))?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(n);var i=n.exports,a=new Map;function o(e,t){Array.isArray(e)||(e=[e]),e.forEach((function(e){return a.set(e,t)}))}function s(e){return f.apply(this,arguments)}function f(){return(f=t(i.mark((function e(t){var r,n;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=a.get(t.Compression)){e.next=3;break}throw new Error("Unknown compression method identifier: ".concat(t.Compression));case 3:return e.next=5,r();case 5:return n=e.sent,e.abrupt("return",new n(t));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}o([void 0,1],(function(){return Promise.resolve().then((function(){return _})).then((function(e){return e.default}))})),o(5,(function(){return Promise.resolve().then((function(){return S})).then((function(e){return e.default}))})),o(6,(function(){throw new Error("old style JPEG compression is not supported.")})),o(7,(function(){return Promise.resolve().then((function(){return L})).then((function(e){return e.default}))})),o([8,32946],(function(){return Promise.resolve().then((function(){return Ne})).then((function(e){return e.default}))})),o(32773,(function(){return Promise.resolve().then((function(){return Ye})).then((function(e){return e.default}))})),o(34887,(function(){return Promise.resolve().then((function(){return ut})).then((function(e){return e.default}))})),o(50001,(function(){return Promise.resolve().then((function(){return dt})).then((function(e){return e.default}))}));var l=globalThis;function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function h(e,t,r){return t&&c(e.prototype,t),r&&c(e,r),e}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function p(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&d(e,t)}function m(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return e}(e)}function v(e){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},v(e)}function y(e,t){var r=e.length-t,n=0;do{for(var i=t;i>0;i--)e[n+t]+=e[n],n++;r-=t}while(r>0)}function w(e,t,r){for(var n=0,i=e.length,a=i/r;i>t;){for(var o=t;o>0;--o)e[n+t]+=e[n],++n;i-=t}for(var s=e.slice(),f=0;f<a;++f)for(var l=0;l<r;++l)e[r*f+l]=s[(r-l-1)*a+f]}function g(e,t,r,n,i,a){if(!t||1===t)return e;for(var o=0;o<i.length;++o){if(i[o]%8!=0)throw new Error("When decoding with predictor, only multiple of 8 bits are supported.");if(i[o]!==i[0])throw new Error("When decoding with predictor, all samples must have the same size.")}for(var s=i[0]/8,f=2===a?1:i.length,l=0;l<n&&!(l*f*r*s>=e.byteLength);++l){var u=void 0;if(2===t){switch(i[0]){case 8:u=new Uint8Array(e,l*f*r*s,f*r*s);break;case 16:u=new Uint16Array(e,l*f*r*s,f*r*s/2);break;case 32:u=new Uint32Array(e,l*f*r*s,f*r*s/4);break;default:throw new Error("Predictor 2 not allowed with ".concat(i[0]," bits per sample."))}y(u,f)}else 3===t&&w(u=new Uint8Array(e,l*f*r*s,f*r*s),f,s)}return e}l.addEventListener("message",function(){var e=t(i.mark((function e(t){var r,n,a,o,f,u;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.data,n=r.id,a=r.fileDirectory,o=r.buffer,e.next=3,s(a);case 3:return f=e.sent,e.next=6,f.decode(a,o);case 6:u=e.sent,l.postMessage({decoded:u,id:n},[u]);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}());var b=function(){function e(){u(this,e)}var r;return h(e,[{key:"decode",value:(r=t(i.mark((function e(t,r){var n,a,o,s,f;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.decodeBlock(r);case 2:if(n=e.sent,1===(a=t.Predictor||1)){e.next=9;break}return o=!t.StripOffsets,s=o?t.TileWidth:t.ImageWidth,f=o?t.TileLength:t.RowsPerStrip||t.ImageLength,e.abrupt("return",g(n,a,s,f,t.BitsPerSample,t.PlanarConfiguration));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})}]),e}();function k(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var x=function(e){p(r,b);var t=k(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){return e}}]),r}(),_=Object.freeze({__proto__:null,default:x});function A(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}function P(e,t){for(var r=t.length-1;r>=0;r--)e.push(t[r]);return e}function I(e){for(var t=new Uint16Array(4093),r=new Uint8Array(4093),n=0;n<=257;n++)t[n]=4096,r[n]=n;var i=258,a=9,o=0;function s(){i=258,a=9}function f(e){var t=function(e,t,r){var n=t%8,i=Math.floor(t/8),a=8-n,o=t+r-8*(i+1),s=8*(i+2)-(t+r),f=8*(i+2)-t;if(s=Math.max(0,s),i>=e.length)return console.warn("ran off the end of the buffer before finding EOI_CODE (end on input code)"),257;var l=e[i]&Math.pow(2,8-n)-1,u=l<<=r-a;if(i+1<e.length){var c=e[i+1]>>>s;u+=c<<=Math.max(0,r-f)}if(o>8&&i+2<e.length){var h=8*(i+3)-(t+r);u+=e[i+2]>>>h}return u}(e,o,a);return o+=a,t}function l(e,n){return r[i]=n,t[i]=e,++i-1}function u(e){for(var n=[],i=e;4096!==i;i=t[i])n.push(r[i]);return n}var c=[];s();for(var h,d=new Uint8Array(e),p=f(d);257!==p;){if(256===p){for(s(),p=f(d);256===p;)p=f(d);if(257===p)break;if(p>256)throw new Error("corrupted code at scanline ".concat(p));P(c,u(p)),h=p}else if(p<i){var m=u(p);P(c,m),l(h,m[m.length-1]),h=p}else{var v=u(h);if(!v)throw new Error("Bogus entry. Not in dictionary, ".concat(h," / ").concat(i,", position: ").concat(o));P(c,v),c.push(v[v.length-1]),l(h,v[v.length-1]),h=p}i+1>=Math.pow(2,a)&&(12===a?h=void 0:a++),p=f(d)}return new Uint8Array(c)}var U=function(e){p(r,b);var t=A(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){return I(e).buffer}}]),r}(),S=Object.freeze({__proto__:null,default:U});function T(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var D=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]);function E(e,t){for(var r=0,n=[],i=16;i>0&&!e[i-1];)--i;n.push({children:[],index:0});for(var a,o=n[0],s=0;s<i;s++){for(var f=0;f<e[s];f++){for((o=n.pop()).children[o.index]=t[r];o.index>0;)o=n.pop();for(o.index++,n.push(o);n.length<=s;)n.push(a={children:[],index:0}),o.children[o.index]=a.children,o=a;r++}s+1<i&&(n.push(a={children:[],index:0}),o.children[o.index]=a.children,o=a)}return n[0].children}function B(e,t,n,i,a,o,s,f,l){var u=n.mcusPerLine,c=n.progressive,h=t,d=t,p=0,m=0;function v(){if(m>0)return m--,p>>m&1;if(255===(p=e[d++])){var t=e[d++];if(t)throw new Error("unexpected marker: ".concat((p<<8|t).toString(16)))}return m=7,p>>>7}function y(e){for(var t,n=e;null!==(t=v());){if("number"==typeof(n=n[t]))return n;if("object"!==r(n))throw new Error("invalid huffman sequence")}return null}function w(e){for(var t=e,r=0;t>0;){var n=v();if(null===n)return;r=r<<1|n,--t}return r}function g(e){var t=w(e);return t>=1<<e-1?t:t+(-1<<e)+1}var b=0;var k,x=0;function _(e,t,r,n,i){var a=r%u,o=(r/u|0)*e.v+n,s=a*e.h+i;t(e,e.blocks[o][s])}function A(e,t,r){var n=r/e.blocksPerLine|0,i=r%e.blocksPerLine;t(e,e.blocks[n][i])}var P,I,U,S,T,E,B=i.length;E=c?0===o?0===f?function(e,t){var r=y(e.huffmanTableDC),n=0===r?0:g(r)<<l;e.pred+=n,t[0]=e.pred}:function(e,t){t[0]|=v()<<l}:0===f?function(e,t){if(b>0)b--;else for(var r=o,n=s;r<=n;){var i=y(e.huffmanTableAC),a=15&i,f=i>>4;if(0===a){if(f<15){b=w(f)+(1<<f)-1;break}r+=16}else t[D[r+=f]]=g(a)*(1<<l),r++}}:function(e,t){for(var r=o,n=s,i=0;r<=n;){var a=D[r],f=t[a]<0?-1:1;switch(x){case 0:var u=y(e.huffmanTableAC),c=15&u;if(i=u>>4,0===c)i<15?(b=w(i)+(1<<i),x=4):(i=16,x=1);else{if(1!==c)throw new Error("invalid ACn encoding");k=g(c),x=i?2:3}continue;case 1:case 2:t[a]?t[a]+=(v()<<l)*f:0==--i&&(x=2===x?3:0);break;case 3:t[a]?t[a]+=(v()<<l)*f:(t[a]=k<<l,x=0);break;case 4:t[a]&&(t[a]+=(v()<<l)*f)}r++}4===x&&0==--b&&(x=0)}:function(e,t){var r=y(e.huffmanTableDC),n=0===r?0:g(r);e.pred+=n,t[0]=e.pred;for(var i=1;i<64;){var a=y(e.huffmanTableAC),o=15&a,s=a>>4;if(0===o){if(s<15)break;i+=16}else t[D[i+=s]]=g(o),i++}};var O,M,C=0;M=1===B?i[0].blocksPerLine*i[0].blocksPerColumn:u*n.mcusPerColumn;for(var L=a||M;C<M;){for(I=0;I<B;I++)i[I].pred=0;if(b=0,1===B)for(P=i[0],T=0;T<L;T++)A(P,E,C),C++;else for(T=0;T<L;T++){for(I=0;I<B;I++){var R=P=i[I],V=R.h,G=R.v;for(U=0;U<G;U++)for(S=0;S<V;S++)_(P,E,C,U,S)}if(++C===M)break}if(m=0,(O=e[d]<<8|e[d+1])<65280)throw new Error("marker was not found");if(!(O>=65488&&O<=65495))break;d+=2}return d-h}function O(e,t){var r=[],n=t.blocksPerLine,i=t.blocksPerColumn,a=n<<3,o=new Int32Array(64),s=new Uint8Array(64);function f(e,r,n){var i,a,o,s,f,l,u,c,h,d,p=t.quantizationTable,m=n;for(d=0;d<64;d++)m[d]=e[d]*p[d];for(d=0;d<8;++d){var v=8*d;0!==m[1+v]||0!==m[2+v]||0!==m[3+v]||0!==m[4+v]||0!==m[5+v]||0!==m[6+v]||0!==m[7+v]?(i=5793*m[0+v]+128>>8,a=5793*m[4+v]+128>>8,o=m[2+v],s=m[6+v],f=2896*(m[1+v]-m[7+v])+128>>8,c=2896*(m[1+v]+m[7+v])+128>>8,l=m[3+v]<<4,h=i-a+1>>1,i=i+a+1>>1,a=h,h=3784*o+1567*s+128>>8,o=1567*o-3784*s+128>>8,s=h,h=f-(u=m[5+v]<<4)+1>>1,f=f+u+1>>1,u=h,h=c+l+1>>1,l=c-l+1>>1,c=h,h=i-s+1>>1,i=i+s+1>>1,s=h,h=a-o+1>>1,a=a+o+1>>1,o=h,h=2276*f+3406*c+2048>>12,f=3406*f-2276*c+2048>>12,c=h,h=799*l+4017*u+2048>>12,l=4017*l-799*u+2048>>12,u=h,m[0+v]=i+c,m[7+v]=i-c,m[1+v]=a+u,m[6+v]=a-u,m[2+v]=o+l,m[5+v]=o-l,m[3+v]=s+f,m[4+v]=s-f):(h=5793*m[0+v]+512>>10,m[0+v]=h,m[1+v]=h,m[2+v]=h,m[3+v]=h,m[4+v]=h,m[5+v]=h,m[6+v]=h,m[7+v]=h)}for(d=0;d<8;++d){var y=d;0!==m[8+y]||0!==m[16+y]||0!==m[24+y]||0!==m[32+y]||0!==m[40+y]||0!==m[48+y]||0!==m[56+y]?(i=5793*m[0+y]+2048>>12,a=5793*m[32+y]+2048>>12,o=m[16+y],s=m[48+y],f=2896*(m[8+y]-m[56+y])+2048>>12,c=2896*(m[8+y]+m[56+y])+2048>>12,l=m[24+y],h=i-a+1>>1,i=i+a+1>>1,a=h,h=3784*o+1567*s+2048>>12,o=1567*o-3784*s+2048>>12,s=h,h=f-(u=m[40+y])+1>>1,f=f+u+1>>1,u=h,h=c+l+1>>1,l=c-l+1>>1,c=h,h=i-s+1>>1,i=i+s+1>>1,s=h,h=a-o+1>>1,a=a+o+1>>1,o=h,h=2276*f+3406*c+2048>>12,f=3406*f-2276*c+2048>>12,c=h,h=799*l+4017*u+2048>>12,l=4017*l-799*u+2048>>12,u=h,m[0+y]=i+c,m[56+y]=i-c,m[8+y]=a+u,m[48+y]=a-u,m[16+y]=o+l,m[40+y]=o-l,m[24+y]=s+f,m[32+y]=s-f):(h=5793*n[d+0]+8192>>14,m[0+y]=h,m[8+y]=h,m[16+y]=h,m[24+y]=h,m[32+y]=h,m[40+y]=h,m[48+y]=h,m[56+y]=h)}for(d=0;d<64;++d){var w=128+(m[d]+8>>4);r[d]=w<0?0:w>255?255:w}}for(var l=0;l<i;l++){for(var u=l<<3,c=0;c<8;c++)r.push(new Uint8Array(a));for(var h=0;h<n;h++){f(t.blocks[l][h],s,o);for(var d=0,p=h<<3,m=0;m<8;m++)for(var v=r[u+m],y=0;y<8;y++)v[p+y]=s[d++]}}return r}var M=function(){function e(){u(this,e),this.jfif=null,this.adobe=null,this.quantizationTables=[],this.huffmanTablesAC=[],this.huffmanTablesDC=[],this.resetFrames()}return h(e,[{key:"resetFrames",value:function(){this.frames=[]}},{key:"parse",value:function(e){var t=0;function r(){var r=e[t]<<8|e[t+1];return t+=2,r}function n(e){var t,r,n=0,i=0;for(r in e.components)e.components.hasOwnProperty(r)&&(n<(t=e.components[r]).h&&(n=t.h),i<t.v&&(i=t.v));var a=Math.ceil(e.samplesPerLine/8/n),o=Math.ceil(e.scanLines/8/i);for(r in e.components)if(e.components.hasOwnProperty(r)){t=e.components[r];for(var s=Math.ceil(Math.ceil(e.samplesPerLine/8)*t.h/n),f=Math.ceil(Math.ceil(e.scanLines/8)*t.v/i),l=a*t.h,u=o*t.v,c=[],h=0;h<u;h++){for(var d=[],p=0;p<l;p++)d.push(new Int32Array(64));c.push(d)}t.blocksPerLine=s,t.blocksPerColumn=f,t.blocks=c}e.maxH=n,e.maxV=i,e.mcusPerLine=a,e.mcusPerColumn=o}var i,a,o=r();if(65496!==o)throw new Error("SOI not found");for(o=r();65497!==o;){switch(o){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var s=(i=void 0,a=void 0,i=r(),a=e.subarray(t,t+i-2),t+=a.length,a);65504===o&&74===s[0]&&70===s[1]&&73===s[2]&&70===s[3]&&0===s[4]&&(this.jfif={version:{major:s[5],minor:s[6]},densityUnits:s[7],xDensity:s[8]<<8|s[9],yDensity:s[10]<<8|s[11],thumbWidth:s[12],thumbHeight:s[13],thumbData:s.subarray(14,14+3*s[12]*s[13])}),65518===o&&65===s[0]&&100===s[1]&&111===s[2]&&98===s[3]&&101===s[4]&&0===s[5]&&(this.adobe={version:s[6],flags0:s[7]<<8|s[8],flags1:s[9]<<8|s[10],transformCode:s[11]});break;case 65499:for(var f=r()+t-2;t<f;){var l=e[t++],u=new Int32Array(64);if(l>>4==0)for(var c=0;c<64;c++){u[D[c]]=e[t++]}else{if(l>>4!=1)throw new Error("DQT: invalid table spec");for(var h=0;h<64;h++){u[D[h]]=r()}}this.quantizationTables[15&l]=u}break;case 65472:case 65473:case 65474:r();for(var d={extended:65473===o,progressive:65474===o,precision:e[t++],scanLines:r(),samplesPerLine:r(),components:{},componentsOrder:[]},p=e[t++],m=void 0,v=0;v<p;v++){m=e[t];var y=e[t+1]>>4,w=15&e[t+1],g=e[t+2];d.componentsOrder.push(m),d.components[m]={h:y,v:w,quantizationIdx:g},t+=3}n(d),this.frames.push(d);break;case 65476:for(var b=r(),k=2;k<b;){for(var x=e[t++],_=new Uint8Array(16),A=0,P=0;P<16;P++,t++)_[P]=e[t],A+=_[P];for(var I=new Uint8Array(A),U=0;U<A;U++,t++)I[U]=e[t];k+=17+A,x>>4==0?this.huffmanTablesDC[15&x]=E(_,I):this.huffmanTablesAC[15&x]=E(_,I)}break;case 65501:r(),this.resetInterval=r();break;case 65498:r();for(var S=e[t++],T=[],O=this.frames[0],M=0;M<S;M++){var C=O.components[e[t++]],L=e[t++];C.huffmanTableDC=this.huffmanTablesDC[L>>4],C.huffmanTableAC=this.huffmanTablesAC[15&L],T.push(C)}var R=e[t++],V=e[t++],G=e[t++],F=B(e,t,O,T,this.resetInterval,R,V,G>>4,15&G);t+=F;break;case 65535:255!==e[t]&&t--;break;default:if(255===e[t-3]&&e[t-2]>=192&&e[t-2]<=254){t-=3;break}throw new Error("unknown JPEG marker ".concat(o.toString(16)))}o=r()}}},{key:"getResult",value:function(){var e=this.frames;if(0===this.frames.length)throw new Error("no frames were decoded");this.frames.length>1&&console.warn("more than one frame is not supported");for(var t=0;t<this.frames.length;t++)for(var r=this.frames[t].components,n=0,i=Object.keys(r);n<i.length;n++){var a=i[n];r[a].quantizationTable=this.quantizationTables[r[a].quantizationIdx],delete r[a].quantizationIdx}for(var o=e[0],s=o.components,f=o.componentsOrder,l=[],u=o.samplesPerLine,c=o.scanLines,h=0;h<f.length;h++){var d=s[f[h]];l.push({lines:O(0,d),scaleX:d.h/o.maxH,scaleY:d.v/o.maxV})}for(var p=new Uint8Array(u*c*l.length),m=0,v=0;v<c;++v)for(var y=0;y<u;++y)for(var w=0;w<l.length;++w){var g=l[w];p[m]=g.lines[0|v*g.scaleY][0|y*g.scaleX],++m}return p}}]),e}(),C=function(e){p(r,b);var t=T(r);function r(e){var n;return u(this,r),(n=t.call(this)).reader=new M,e.JPEGTables&&n.reader.parse(e.JPEGTables),n}return h(r,[{key:"decodeBlock",value:function(e){return this.reader.resetFrames(),this.reader.parse(new Uint8Array(e)),this.reader.getResult().buffer}}]),r}(),L=Object.freeze({__proto__:null,default:C});function R(e){for(var t=e.length;--t>=0;)e[t]=0}R(new Array(576)),R(new Array(60)),R(new Array(512)),R(new Array(256)),R(new Array(29)),R(new Array(30));var V=function(e,t,r,n){for(var i=65535&e|0,a=e>>>16&65535|0,o=0;0!==r;){r-=o=r>2e3?2e3:r;do{a=a+(i=i+t[n++]|0)|0}while(--o);i%=65521,a%=65521}return i|a<<16|0},G=new Uint32Array(function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}()),F=function(e,t,r,n){var i=G,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[255&(e^t[o])];return-1^e},z={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},j={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},N=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},Z=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var n=t.shift();if(n){if("object"!==r(n))throw new TypeError(n+"must be non-object");for(var i in n)N(n,i)&&(e[i]=n[i])}}return e},K=function(e){for(var t=0,r=0,n=e.length;r<n;r++)t+=e[r].length;for(var i=new Uint8Array(t),a=0,o=0,s=e.length;a<s;a++){var f=e[a];i.set(f,o),o+=f.length}return i},H=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(e){H=!1}for(var Y=new Uint8Array(256),X=0;X<256;X++)Y[X]=X>=252?6:X>=248?5:X>=240?4:X>=224?3:X>=192?2:1;Y[254]=Y[254]=1;var W=function(e){if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);var t,r,n,i,a,o=e.length,s=0;for(i=0;i<o;i++)55296==(64512&(r=e.charCodeAt(i)))&&i+1<o&&56320==(64512&(n=e.charCodeAt(i+1)))&&(r=65536+(r-55296<<10)+(n-56320),i++),s+=r<128?1:r<2048?2:r<65536?3:4;for(t=new Uint8Array(s),a=0,i=0;a<s;i++)55296==(64512&(r=e.charCodeAt(i)))&&i+1<o&&56320==(64512&(n=e.charCodeAt(i+1)))&&(r=65536+(r-55296<<10)+(n-56320),i++),r<128?t[a++]=r:r<2048?(t[a++]=192|r>>>6,t[a++]=128|63&r):r<65536?(t[a++]=224|r>>>12,t[a++]=128|r>>>6&63,t[a++]=128|63&r):(t[a++]=240|r>>>18,t[a++]=128|r>>>12&63,t[a++]=128|r>>>6&63,t[a++]=128|63&r);return t},q=function(e,t){var r,n,i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));var a=new Array(2*i);for(n=0,r=0;r<i;){var o=e[r++];if(o<128)a[n++]=o;else{var s=Y[o];if(s>4)a[n++]=65533,r+=s-1;else{for(o&=2===s?31:3===s?15:7;s>1&&r<i;)o=o<<6|63&e[r++],s--;s>1?a[n++]=65533:o<65536?a[n++]=o:(o-=65536,a[n++]=55296|o>>10&1023,a[n++]=56320|1023&o)}}}return function(e,t){if(t<65534&&e.subarray&&H)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));for(var r="",n=0;n<t;n++)r+=String.fromCharCode(e[n]);return r}(a,n)},J=function(e,t){(t=t||e.length)>e.length&&(t=e.length);for(var r=t-1;r>=0&&128==(192&e[r]);)r--;return r<0||0===r?t:r+Y[e[r]]>t?r:t};var Q=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0},$=function(e,t){var r,n,i,a,o,s,f,l,u,c,h,d,p,m,v,y,w,g,b,k,x,_,A,P,I=e.state;r=e.next_in,A=e.input,n=r+(e.avail_in-5),i=e.next_out,P=e.output,a=i-(t-e.avail_out),o=i+(e.avail_out-257),s=I.dmax,f=I.wsize,l=I.whave,u=I.wnext,c=I.window,h=I.hold,d=I.bits,p=I.lencode,m=I.distcode,v=(1<<I.lenbits)-1,y=(1<<I.distbits)-1;e:do{d<15&&(h+=A[r++]<<d,d+=8,h+=A[r++]<<d,d+=8),w=p[h&v];t:for(;;){if(h>>>=g=w>>>24,d-=g,0===(g=w>>>16&255))P[i++]=65535&w;else{if(!(16&g)){if(0==(64&g)){w=p[(65535&w)+(h&(1<<g)-1)];continue t}if(32&g){I.mode=12;break e}e.msg="invalid literal/length code",I.mode=30;break e}b=65535&w,(g&=15)&&(d<g&&(h+=A[r++]<<d,d+=8),b+=h&(1<<g)-1,h>>>=g,d-=g),d<15&&(h+=A[r++]<<d,d+=8,h+=A[r++]<<d,d+=8),w=m[h&y];r:for(;;){if(h>>>=g=w>>>24,d-=g,!(16&(g=w>>>16&255))){if(0==(64&g)){w=m[(65535&w)+(h&(1<<g)-1)];continue r}e.msg="invalid distance code",I.mode=30;break e}if(k=65535&w,d<(g&=15)&&(h+=A[r++]<<d,(d+=8)<g&&(h+=A[r++]<<d,d+=8)),(k+=h&(1<<g)-1)>s){e.msg="invalid distance too far back",I.mode=30;break e}if(h>>>=g,d-=g,k>(g=i-a)){if((g=k-g)>l&&I.sane){e.msg="invalid distance too far back",I.mode=30;break e}if(x=0,_=c,0===u){if(x+=f-g,g<b){b-=g;do{P[i++]=c[x++]}while(--g);x=i-k,_=P}}else if(u<g){if(x+=f+u-g,(g-=u)<b){b-=g;do{P[i++]=c[x++]}while(--g);if(x=0,u<b){b-=g=u;do{P[i++]=c[x++]}while(--g);x=i-k,_=P}}}else if(x+=u-g,g<b){b-=g;do{P[i++]=c[x++]}while(--g);x=i-k,_=P}for(;b>2;)P[i++]=_[x++],P[i++]=_[x++],P[i++]=_[x++],b-=3;b&&(P[i++]=_[x++],b>1&&(P[i++]=_[x++]))}else{x=i-k;do{P[i++]=P[x++],P[i++]=P[x++],P[i++]=P[x++],b-=3}while(b>2);b&&(P[i++]=P[x++],b>1&&(P[i++]=P[x++]))}break}}break}}while(r<n&&i<o);r-=b=d>>3,h&=(1<<(d-=b<<3))-1,e.next_in=r,e.next_out=i,e.avail_in=r<n?n-r+5:5-(r-n),e.avail_out=i<o?o-i+257:257-(i-o),I.hold=h,I.bits=d},ee=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),te=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),re=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),ne=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),ie=function(e,t,r,n,i,a,o,s){var f,l,u,c,h,d,p,m,v,y=s.bits,w=0,g=0,b=0,k=0,x=0,_=0,A=0,P=0,I=0,U=0,S=null,T=0,D=new Uint16Array(16),E=new Uint16Array(16),B=null,O=0;for(w=0;w<=15;w++)D[w]=0;for(g=0;g<n;g++)D[t[r+g]]++;for(x=y,k=15;k>=1&&0===D[k];k--);if(x>k&&(x=k),0===k)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(b=1;b<k&&0===D[b];b++);for(x<b&&(x=b),P=1,w=1;w<=15;w++)if(P<<=1,(P-=D[w])<0)return-1;if(P>0&&(0===e||1!==k))return-1;for(E[1]=0,w=1;w<15;w++)E[w+1]=E[w]+D[w];for(g=0;g<n;g++)0!==t[r+g]&&(o[E[t[r+g]]++]=g);if(0===e?(S=B=o,d=19):1===e?(S=ee,T-=257,B=te,O-=257,d=256):(S=re,B=ne,d=-1),U=0,g=0,w=b,h=a,_=x,A=0,u=-1,c=(I=1<<x)-1,1===e&&I>852||2===e&&I>592)return 1;for(;;){p=w-A,o[g]<d?(m=0,v=o[g]):o[g]>d?(m=B[O+o[g]],v=S[T+o[g]]):(m=96,v=0),f=1<<w-A,b=l=1<<_;do{i[h+(U>>A)+(l-=f)]=p<<24|m<<16|v|0}while(0!==l);for(f=1<<w-1;U&f;)f>>=1;if(0!==f?(U&=f-1,U+=f):U=0,g++,0==--D[w]){if(w===k)break;w=t[r+o[g]]}if(w>x&&(U&c)!==u){for(0===A&&(A=x),h+=b,P=1<<(_=w-A);_+A<k&&!((P-=D[_+A])<=0);)_++,P<<=1;if(I+=1<<_,1===e&&I>852||2===e&&I>592)return 1;i[u=U&c]=x<<24|_<<16|h-a|0}}return 0!==U&&(i[h+U]=w-A<<24|64<<16|0),s.bits=x,0},ae=j.Z_FINISH,oe=j.Z_BLOCK,se=j.Z_TREES,fe=j.Z_OK,le=j.Z_STREAM_END,ue=j.Z_NEED_DICT,ce=j.Z_STREAM_ERROR,he=j.Z_DATA_ERROR,de=j.Z_MEM_ERROR,pe=j.Z_BUF_ERROR,me=j.Z_DEFLATED,ve=function(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)};function ye(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}var we,ge,be=function(e){if(!e||!e.state)return ce;var t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=1,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,fe},ke=function(e){if(!e||!e.state)return ce;var t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,be(e)},xe=function(e,t){var r;if(!e||!e.state)return ce;var n=e.state;return t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?ce:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,ke(e))},_e=function(e,t){if(!e)return ce;var r=new ye;e.state=r,r.window=null;var n=xe(e,t);return n!==fe&&(e.state=null),n},Ae=!0,Pe=function(e){if(Ae){we=new Int32Array(512),ge=new Int32Array(32);for(var t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(ie(1,e.lens,0,288,we,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;ie(2,e.lens,0,32,ge,0,e.work,{bits:5}),Ae=!1}e.lencode=we,e.lenbits=9,e.distcode=ge,e.distbits=5},Ie=function(e,t,r,n){var i,a=e.state;return null===a.window&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new Uint8Array(a.wsize)),n>=a.wsize?(a.window.set(t.subarray(r-a.wsize,r),0),a.wnext=0,a.whave=a.wsize):((i=a.wsize-a.wnext)>n&&(i=n),a.window.set(t.subarray(r-n,r-n+i),a.wnext),(n-=i)?(a.window.set(t.subarray(r-n,r),0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0},Ue={inflateReset:ke,inflateReset2:xe,inflateResetKeep:be,inflateInit:function(e){return _e(e,15)},inflateInit2:_e,inflate:function(e,t){var r,n,i,a,o,s,f,l,u,c,h,d,p,m,v,y,w,g,b,k,x,_,A,P,I=0,U=new Uint8Array(4),S=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!e||!e.state||!e.output||!e.input&&0!==e.avail_in)return ce;12===(r=e.state).mode&&(r.mode=13),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,l=r.hold,u=r.bits,c=s,h=f,_=fe;e:for(;;)switch(r.mode){case 1:if(0===r.wrap){r.mode=13;break}for(;u<16;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(2&r.wrap&&35615===l){r.check=0,U[0]=255&l,U[1]=l>>>8&255,r.check=F(r.check,U,2,0),l=0,u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&l)<<8)+(l>>8))%31){e.msg="incorrect header check",r.mode=30;break}if((15&l)!==me){e.msg="unknown compression method",r.mode=30;break}if(u-=4,x=8+(15&(l>>>=4)),0===r.wbits)r.wbits=x;else if(x>r.wbits){e.msg="invalid window size",r.mode=30;break}r.dmax=1<<r.wbits,e.adler=r.check=1,r.mode=512&l?10:12,l=0,u=0;break;case 2:for(;u<16;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(r.flags=l,(255&r.flags)!==me){e.msg="unknown compression method",r.mode=30;break}if(57344&r.flags){e.msg="unknown header flags set",r.mode=30;break}r.head&&(r.head.text=l>>8&1),512&r.flags&&(U[0]=255&l,U[1]=l>>>8&255,r.check=F(r.check,U,2,0)),l=0,u=0,r.mode=3;case 3:for(;u<32;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}r.head&&(r.head.time=l),512&r.flags&&(U[0]=255&l,U[1]=l>>>8&255,U[2]=l>>>16&255,U[3]=l>>>24&255,r.check=F(r.check,U,4,0)),l=0,u=0,r.mode=4;case 4:for(;u<16;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}r.head&&(r.head.xflags=255&l,r.head.os=l>>8),512&r.flags&&(U[0]=255&l,U[1]=l>>>8&255,r.check=F(r.check,U,2,0)),l=0,u=0,r.mode=5;case 5:if(1024&r.flags){for(;u<16;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}r.length=l,r.head&&(r.head.extra_len=l),512&r.flags&&(U[0]=255&l,U[1]=l>>>8&255,r.check=F(r.check,U,2,0)),l=0,u=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&((d=r.length)>s&&(d=s),d&&(r.head&&(x=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(n.subarray(a,a+d),x)),512&r.flags&&(r.check=F(r.check,n,d,a)),s-=d,a+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===s)break e;d=0;do{x=n[a+d++],r.head&&x&&r.length<65536&&(r.head.name+=String.fromCharCode(x))}while(x&&d<s);if(512&r.flags&&(r.check=F(r.check,n,d,a)),s-=d,a+=d,x)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=8;case 8:if(4096&r.flags){if(0===s)break e;d=0;do{x=n[a+d++],r.head&&x&&r.length<65536&&(r.head.comment+=String.fromCharCode(x))}while(x&&d<s);if(512&r.flags&&(r.check=F(r.check,n,d,a)),s-=d,a+=d,x)break e}else r.head&&(r.head.comment=null);r.mode=9;case 9:if(512&r.flags){for(;u<16;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(l!==(65535&r.check)){e.msg="header crc mismatch",r.mode=30;break}l=0,u=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;u<32;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}e.adler=r.check=ve(l),l=0,u=0,r.mode=11;case 11:if(0===r.havedict)return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=l,r.bits=u,ue;e.adler=r.check=1,r.mode=12;case 12:if(t===oe||t===se)break e;case 13:if(r.last){l>>>=7&u,u-=7&u,r.mode=27;break}for(;u<3;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}switch(r.last=1&l,u-=1,3&(l>>>=1)){case 0:r.mode=14;break;case 1:if(Pe(r),r.mode=20,t===se){l>>>=2,u-=2;break e}break;case 2:r.mode=17;break;case 3:e.msg="invalid block type",r.mode=30}l>>>=2,u-=2;break;case 14:for(l>>>=7&u,u-=7&u;u<32;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if((65535&l)!=(l>>>16^65535)){e.msg="invalid stored block lengths",r.mode=30;break}if(r.length=65535&l,l=0,u=0,r.mode=15,t===se)break e;case 15:r.mode=16;case 16:if(d=r.length){if(d>s&&(d=s),d>f&&(d=f),0===d)break e;i.set(n.subarray(a,a+d),o),s-=d,a+=d,f-=d,o+=d,r.length-=d;break}r.mode=12;break;case 17:for(;u<14;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(r.nlen=257+(31&l),l>>>=5,u-=5,r.ndist=1+(31&l),l>>>=5,u-=5,r.ncode=4+(15&l),l>>>=4,u-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=30;break}r.have=0,r.mode=18;case 18:for(;r.have<r.ncode;){for(;u<3;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}r.lens[S[r.have++]]=7&l,l>>>=3,u-=3}for(;r.have<19;)r.lens[S[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,A={bits:r.lenbits},_=ie(0,r.lens,0,19,r.lencode,0,r.work,A),r.lenbits=A.bits,_){e.msg="invalid code lengths set",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have<r.nlen+r.ndist;){for(;y=(I=r.lencode[l&(1<<r.lenbits)-1])>>>16&255,w=65535&I,!((v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(w<16)l>>>=v,u-=v,r.lens[r.have++]=w;else{if(16===w){for(P=v+2;u<P;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(l>>>=v,u-=v,0===r.have){e.msg="invalid bit length repeat",r.mode=30;break}x=r.lens[r.have-1],d=3+(3&l),l>>>=2,u-=2}else if(17===w){for(P=v+3;u<P;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}u-=v,x=0,d=3+(7&(l>>>=v)),l>>>=3,u-=3}else{for(P=v+7;u<P;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}u-=v,x=0,d=11+(127&(l>>>=v)),l>>>=7,u-=7}if(r.have+d>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=30;break}for(;d--;)r.lens[r.have++]=x}}if(30===r.mode)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=30;break}if(r.lenbits=9,A={bits:r.lenbits},_=ie(1,r.lens,0,r.nlen,r.lencode,0,r.work,A),r.lenbits=A.bits,_){e.msg="invalid literal/lengths set",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,A={bits:r.distbits},_=ie(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,A),r.distbits=A.bits,_){e.msg="invalid distances set",r.mode=30;break}if(r.mode=20,t===se)break e;case 20:r.mode=21;case 21:if(s>=6&&f>=258){e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=l,r.bits=u,$(e,h),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,l=r.hold,u=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;y=(I=r.lencode[l&(1<<r.lenbits)-1])>>>16&255,w=65535&I,!((v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(y&&0==(240&y)){for(g=v,b=y,k=w;y=(I=r.lencode[k+((l&(1<<g+b)-1)>>g)])>>>16&255,w=65535&I,!(g+(v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}l>>>=g,u-=g,r.back+=g}if(l>>>=v,u-=v,r.back+=v,r.length=w,0===y){r.mode=26;break}if(32&y){r.back=-1,r.mode=12;break}if(64&y){e.msg="invalid literal/length code",r.mode=30;break}r.extra=15&y,r.mode=22;case 22:if(r.extra){for(P=r.extra;u<P;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}r.length+=l&(1<<r.extra)-1,l>>>=r.extra,u-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;y=(I=r.distcode[l&(1<<r.distbits)-1])>>>16&255,w=65535&I,!((v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(0==(240&y)){for(g=v,b=y,k=w;y=(I=r.distcode[k+((l&(1<<g+b)-1)>>g)])>>>16&255,w=65535&I,!(g+(v=I>>>24)<=u);){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}l>>>=g,u-=g,r.back+=g}if(l>>>=v,u-=v,r.back+=v,64&y){e.msg="invalid distance code",r.mode=30;break}r.offset=w,r.extra=15&y,r.mode=24;case 24:if(r.extra){for(P=r.extra;u<P;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}r.offset+=l&(1<<r.extra)-1,l>>>=r.extra,u-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=30;break}r.mode=25;case 25:if(0===f)break e;if(d=h-f,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=30;break}d>r.wnext?(d-=r.wnext,p=r.wsize-d):p=r.wnext-d,d>r.length&&(d=r.length),m=r.window}else m=i,p=o-r.offset,d=r.length;d>f&&(d=f),f-=d,r.length-=d;do{i[o++]=m[p++]}while(--d);0===r.length&&(r.mode=21);break;case 26:if(0===f)break e;i[o++]=r.length,f--,r.mode=21;break;case 27:if(r.wrap){for(;u<32;){if(0===s)break e;s--,l|=n[a++]<<u,u+=8}if(h-=f,e.total_out+=h,r.total+=h,h&&(e.adler=r.check=r.flags?F(r.check,i,h,o-h):V(r.check,i,h,o-h)),h=f,(r.flags?l:ve(l))!==r.check){e.msg="incorrect data check",r.mode=30;break}l=0,u=0}r.mode=28;case 28:if(r.wrap&&r.flags){for(;u<32;){if(0===s)break e;s--,l+=n[a++]<<u,u+=8}if(l!==(4294967295&r.total)){e.msg="incorrect length check",r.mode=30;break}l=0,u=0}r.mode=29;case 29:_=le;break e;case 30:_=he;break e;case 31:return de;default:return ce}return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=l,r.bits=u,(r.wsize||h!==e.avail_out&&r.mode<30&&(r.mode<27||t!==ae))&&Ie(e,e.output,e.next_out,h-e.avail_out),c-=e.avail_in,h-=e.avail_out,e.total_in+=c,e.total_out+=h,r.total+=h,r.wrap&&h&&(e.adler=r.check=r.flags?F(r.check,i,h,e.next_out-h):V(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(12===r.mode?128:0)+(20===r.mode||15===r.mode?256:0),(0===c&&0===h||t===ae)&&_===fe&&(_=pe),_},inflateEnd:function(e){if(!e||!e.state)return ce;var t=e.state;return t.window&&(t.window=null),e.state=null,fe},inflateGetHeader:function(e,t){if(!e||!e.state)return ce;var r=e.state;return 0==(2&r.wrap)?ce:(r.head=t,t.done=!1,fe)},inflateSetDictionary:function(e,t){var r,n=t.length;return e&&e.state?0!==(r=e.state).wrap&&11!==r.mode?ce:11===r.mode&&V(1,t,n,0)!==r.check?he:Ie(e,t,n,n)?(r.mode=31,de):(r.havedict=1,fe):ce},inflateInfo:"pako inflate (from Nodeca project)"};var Se=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1},Te=Object.prototype.toString,De=j.Z_NO_FLUSH,Ee=j.Z_FINISH,Be=j.Z_OK,Oe=j.Z_STREAM_END,Me=j.Z_NEED_DICT,Ce=j.Z_STREAM_ERROR,Le=j.Z_DATA_ERROR,Re=j.Z_MEM_ERROR;function Ve(e){this.options=Z({chunkSize:65536,windowBits:15,to:""},e||{});var t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Q,this.strm.avail_out=0;var r=Ue.inflateInit2(this.strm,t.windowBits);if(r!==Be)throw new Error(z[r]);if(this.header=new Se,Ue.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=W(t.dictionary):"[object ArrayBuffer]"===Te.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(r=Ue.inflateSetDictionary(this.strm,t.dictionary))!==Be))throw new Error(z[r])}function Ge(e,t){var r=new Ve(t);if(r.push(e),r.err)throw r.msg||z[r.err];return r.result}Ve.prototype.push=function(e,t){var r,n,i,a=this.strm,o=this.options.chunkSize,s=this.options.dictionary;if(this.ended)return!1;for(n=t===~~t?t:!0===t?Ee:De,"[object ArrayBuffer]"===Te.call(e)?a.input=new Uint8Array(e):a.input=e,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(o),a.next_out=0,a.avail_out=o),(r=Ue.inflate(a,n))===Me&&s&&((r=Ue.inflateSetDictionary(a,s))===Be?r=Ue.inflate(a,n):r===Le&&(r=Me));a.avail_in>0&&r===Oe&&a.state.wrap>0&&0!==e[a.next_in];)Ue.inflateReset(a),r=Ue.inflate(a,n);switch(r){case Ce:case Le:case Me:case Re:return this.onEnd(r),this.ended=!0,!1}if(i=a.avail_out,a.next_out&&(0===a.avail_out||r===Oe))if("string"===this.options.to){var f=J(a.output,a.next_out),l=a.next_out-f,u=q(a.output,f);a.next_out=l,a.avail_out=o-l,l&&a.output.set(a.output.subarray(f,f+l),0),this.onData(u)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==Be||0!==i){if(r===Oe)return r=Ue.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Ve.prototype.onData=function(e){this.chunks.push(e)},Ve.prototype.onEnd=function(e){e===Be&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=K(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Fe={Inflate:Ve,inflate:Ge,inflateRaw:function(e,t){return(t=t||{}).raw=!0,Ge(e,t)},ungzip:Ge,constants:j}.inflate;function ze(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var je=function(e){p(r,b);var t=ze(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){return Fe(new Uint8Array(e)).buffer}}]),r}(),Ne=Object.freeze({__proto__:null,default:je});function Ze(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var Ke,He=function(e){p(r,b);var t=Ze(r);function r(){return u(this,r),t.apply(this,arguments)}return h(r,[{key:"decodeBlock",value:function(e){for(var t=new DataView(e),r=[],n=0;n<e.byteLength;++n){var i=t.getInt8(n);if(i<0){var a=t.getUint8(n+1);i=-i;for(var o=0;o<=i;++o)r.push(a);n+=1}else{for(var s=0;s<=i;++s)r.push(t.getUint8(n+s+1));n+=i+1}}return new Uint8Array(r).buffer}}]),r}(),Ye=Object.freeze({__proto__:null,default:He}),Xe={exports:{}};Ke=Xe,\n/* Copyright 2015-2021 Esri. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 @preserve */\nfunction(){var e,t,r,n,i,a,o,s,f,l,u,c,h,d,p,m,v=(e={defaultNoDataValue:-34027999387901484e22,decode:function(a,o){var s=(o=o||{}).encodedMaskData||null===o.encodedMaskData,f=i(a,o.inputOffset||0,s),l=null!==o.noDataValue?o.noDataValue:e.defaultNoDataValue,u=t(f,o.pixelType||Float32Array,o.encodedMaskData,l,o.returnMask),c={width:f.width,height:f.height,pixelData:u.resultPixels,minValue:u.minValue,maxValue:f.pixels.maxValue,noDataValue:l};return u.resultMask&&(c.maskData=u.resultMask),o.returnEncodedMask&&f.mask&&(c.encodedMaskData=f.mask.bitset?f.mask.bitset:null),o.returnFileInfo&&(c.fileInfo=r(f),o.computeUsedBitDepths&&(c.fileInfo.bitDepths=n(f))),c}},t=function(e,t,r,n,i){var o,s,f,l=0,u=e.pixels.numBlocksX,c=e.pixels.numBlocksY,h=Math.floor(e.width/u),d=Math.floor(e.height/c),p=2*e.maxZError,m=Number.MAX_VALUE;r=r||(e.mask?e.mask.bitset:null),s=new t(e.width*e.height),i&&r&&(f=new Uint8Array(e.width*e.height));for(var v,y,w=new Float32Array(h*d),g=0;g<=c;g++){var b=g!==c?d:e.height%c;if(0!==b)for(var k=0;k<=u;k++){var x=k!==u?h:e.width%u;if(0!==x){var _,A,P,I,U=g*e.width*d+k*h,S=e.width-x,T=e.pixels.blocks[l];if(T.encoding<2?(0===T.encoding?_=T.rawData:(a(T.stuffedData,T.bitsPerPixel,T.numValidPixels,T.offset,p,w,e.pixels.maxValue),_=w),A=0):P=2===T.encoding?0:T.offset,r)for(y=0;y<b;y++){for(7&U&&(I=r[U>>3],I<<=7&U),v=0;v<x;v++)7&U||(I=r[U>>3]),128&I?(f&&(f[U]=1),m=m>(o=T.encoding<2?_[A++]:P)?o:m,s[U++]=o):(f&&(f[U]=0),s[U++]=n),I<<=1;U+=S}else if(T.encoding<2)for(y=0;y<b;y++){for(v=0;v<x;v++)m=m>(o=_[A++])?o:m,s[U++]=o;U+=S}else for(m=m>P?P:m,y=0;y<b;y++){for(v=0;v<x;v++)s[U++]=P;U+=S}if(1===T.encoding&&A!==T.numValidPixels)throw"Block and Mask do not match";l++}}}return{resultPixels:s,resultMask:f,minValue:m}},r=function(e){return{fileIdentifierString:e.fileIdentifierString,fileVersion:e.fileVersion,imageType:e.imageType,height:e.height,width:e.width,maxZError:e.maxZError,eofOffset:e.eofOffset,mask:e.mask?{numBlocksX:e.mask.numBlocksX,numBlocksY:e.mask.numBlocksY,numBytes:e.mask.numBytes,maxValue:e.mask.maxValue}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,numBytes:e.pixels.numBytes,maxValue:e.pixels.maxValue,noDataValue:e.noDataValue}}},n=function(e){for(var t=e.pixels.numBlocksX*e.pixels.numBlocksY,r={},n=0;n<t;n++){var i=e.pixels.blocks[n];0===i.encoding?r.float32=!0:1===i.encoding?r[i.bitsPerPixel]=!0:r[0]=!0}return Object.keys(r)},i=function(e,t,r){var n={},i=new Uint8Array(e,t,10);if(n.fileIdentifierString=String.fromCharCode.apply(null,i),"CntZImage"!==n.fileIdentifierString.trim())throw"Unexpected file identifier string: "+n.fileIdentifierString;t+=10;var a=new DataView(e,t,24);if(n.fileVersion=a.getInt32(0,!0),n.imageType=a.getInt32(4,!0),n.height=a.getUint32(8,!0),n.width=a.getUint32(12,!0),n.maxZError=a.getFloat64(16,!0),t+=24,!r)if(a=new DataView(e,t,16),n.mask={},n.mask.numBlocksY=a.getUint32(0,!0),n.mask.numBlocksX=a.getUint32(4,!0),n.mask.numBytes=a.getUint32(8,!0),n.mask.maxValue=a.getFloat32(12,!0),t+=16,n.mask.numBytes>0){var o=new Uint8Array(Math.ceil(n.width*n.height/8)),s=(a=new DataView(e,t,n.mask.numBytes)).getInt16(0,!0),f=2,l=0;do{if(s>0)for(;s--;)o[l++]=a.getUint8(f++);else{var u=a.getUint8(f++);for(s=-s;s--;)o[l++]=u}s=a.getInt16(f,!0),f+=2}while(f<n.mask.numBytes);if(-32768!==s||l<o.length)throw"Unexpected end of mask RLE encoding";n.mask.bitset=o,t+=n.mask.numBytes}else 0==(n.mask.numBytes|n.mask.numBlocksY|n.mask.maxValue)&&(n.mask.bitset=new Uint8Array(Math.ceil(n.width*n.height/8)));a=new DataView(e,t,16),n.pixels={},n.pixels.numBlocksY=a.getUint32(0,!0),n.pixels.numBlocksX=a.getUint32(4,!0),n.pixels.numBytes=a.getUint32(8,!0),n.pixels.maxValue=a.getFloat32(12,!0),t+=16;var c=n.pixels.numBlocksX,h=n.pixels.numBlocksY,d=c+(n.width%c>0?1:0),p=h+(n.height%h>0?1:0);n.pixels.blocks=new Array(d*p);for(var m=0,v=0;v<p;v++)for(var y=0;y<d;y++){var w=0,g=e.byteLength-t;a=new DataView(e,t,Math.min(10,g));var b={};n.pixels.blocks[m++]=b;var k=a.getUint8(0);if(w++,b.encoding=63&k,b.encoding>3)throw"Invalid block encoding ("+b.encoding+")";if(2!==b.encoding){if(0!==k&&2!==k){if(k>>=6,b.offsetType=k,2===k)b.offset=a.getInt8(1),w++;else if(1===k)b.offset=a.getInt16(1,!0),w+=2;else{if(0!==k)throw"Invalid block offset type";b.offset=a.getFloat32(1,!0),w+=4}if(1===b.encoding)if(k=a.getUint8(w),w++,b.bitsPerPixel=63&k,k>>=6,b.numValidPixelsType=k,2===k)b.numValidPixels=a.getUint8(w),w++;else if(1===k)b.numValidPixels=a.getUint16(w,!0),w+=2;else{if(0!==k)throw"Invalid valid pixel count type";b.numValidPixels=a.getUint32(w,!0),w+=4}}var x;if(t+=w,3!==b.encoding)if(0===b.encoding){var _=(n.pixels.numBytes-1)/4;if(_!==Math.floor(_))throw"uncompressed block has invalid length";x=new ArrayBuffer(4*_),new Uint8Array(x).set(new Uint8Array(e,t,4*_));var A=new Float32Array(x);b.rawData=A,t+=4*_}else if(1===b.encoding){var P=Math.ceil(b.numValidPixels*b.bitsPerPixel/8),I=Math.ceil(P/4);x=new ArrayBuffer(4*I),new Uint8Array(x).set(new Uint8Array(e,t,P)),b.stuffedData=new Uint32Array(x),t+=P}}else t++}return n.eofOffset=t,n},a=function(e,t,r,n,i,a,o){var s,f,l,u=(1<<t)-1,c=0,h=0,d=Math.ceil((o-n)/i),p=4*e.length-Math.ceil(t*r/8);for(e[e.length-1]<<=8*p,s=0;s<r;s++){if(0===h&&(l=e[c++],h=32),h>=t)f=l>>>h-t&u,h-=t;else{var m=t-h;f=(l&u)<<m&u,f+=(l=e[c++])>>>(h=32-m)}a[s]=f<d?n+f*i:o}return a},e),y=(o=function(e,t,r,n,i,a,o,s){var f,l,u,c,h,d=(1<<r)-1,p=0,m=0,v=4*e.length-Math.ceil(r*n/8);if(e[e.length-1]<<=8*v,i)for(f=0;f<n;f++)0===m&&(u=e[p++],m=32),m>=r?(l=u>>>m-r&d,m-=r):(l=(u&d)<<(c=r-m)&d,l+=(u=e[p++])>>>(m=32-c)),t[f]=i[l];else for(h=Math.ceil((s-a)/o),f=0;f<n;f++)0===m&&(u=e[p++],m=32),m>=r?(l=u>>>m-r&d,m-=r):(l=(u&d)<<(c=r-m)&d,l+=(u=e[p++])>>>(m=32-c)),t[f]=l<h?a+l*o:s},s=function(e,t,r,n,i,a){var o,s=(1<<t)-1,f=0,l=0,u=0,c=0,h=0,d=[],p=4*e.length-Math.ceil(t*r/8);e[e.length-1]<<=8*p;var m=Math.ceil((a-n)/i);for(l=0;l<r;l++)0===c&&(o=e[f++],c=32),c>=t?(h=o>>>c-t&s,c-=t):(h=(o&s)<<(u=t-c)&s,h+=(o=e[f++])>>>(c=32-u)),d[l]=h<m?n+h*i:a;return d.unshift(n),d},f=function(e,t,r,n,i,a,o,s){var f,l,u,c,h=(1<<r)-1,d=0,p=0,m=0;if(i)for(f=0;f<n;f++)0===p&&(u=e[d++],p=32,m=0),p>=r?(l=u>>>m&h,p-=r,m+=r):(l=u>>>m&h,p=32-(c=r-p),l|=((u=e[d++])&(1<<c)-1)<<r-c,m=c),t[f]=i[l];else{var v=Math.ceil((s-a)/o);for(f=0;f<n;f++)0===p&&(u=e[d++],p=32,m=0),p>=r?(l=u>>>m&h,p-=r,m+=r):(l=u>>>m&h,p=32-(c=r-p),l|=((u=e[d++])&(1<<c)-1)<<r-c,m=c),t[f]=l<v?a+l*o:s}return t},l=function(e,t,r,n,i,a){var o,s=(1<<t)-1,f=0,l=0,u=0,c=0,h=0,d=0,p=[],m=Math.ceil((a-n)/i);for(l=0;l<r;l++)0===c&&(o=e[f++],c=32,d=0),c>=t?(h=o>>>d&s,c-=t,d+=t):(h=o>>>d&s,c=32-(u=t-c),h|=((o=e[f++])&(1<<u)-1)<<t-u,d=u),p[l]=h<m?n+h*i:a;return p.unshift(n),p},u=function(e,t,r,n){var i,a,o,s,f=(1<<r)-1,l=0,u=0,c=4*e.length-Math.ceil(r*n/8);for(e[e.length-1]<<=8*c,i=0;i<n;i++)0===u&&(o=e[l++],u=32),u>=r?(a=o>>>u-r&f,u-=r):(a=(o&f)<<(s=r-u)&f,a+=(o=e[l++])>>>(u=32-s)),t[i]=a;return t},c=function(e,t,r,n){var i,a,o,s,f=(1<<r)-1,l=0,u=0,c=0;for(i=0;i<n;i++)0===u&&(o=e[l++],u=32,c=0),u>=r?(a=o>>>c&f,u-=r,c+=r):(a=o>>>c&f,u=32-(s=r-u),a|=((o=e[l++])&(1<<s)-1)<<r-s,c=s),t[i]=a;return t},h={HUFFMAN_LUT_BITS_MAX:12,computeChecksumFletcher32:function(e){for(var t=65535,r=65535,n=e.length,i=Math.floor(n/2),a=0;i;){var o=i>=359?359:i;i-=o;do{t+=e[a++]<<8,r+=t+=e[a++]}while(--o);t=(65535&t)+(t>>>16),r=(65535&r)+(r>>>16)}return 1&n&&(r+=t+=e[a]<<8),((r=(65535&r)+(r>>>16))<<16|(t=(65535&t)+(t>>>16)))>>>0},readHeaderInfo:function(e,t){var r=t.ptr,n=new Uint8Array(e,r,6),i={};if(i.fileIdentifierString=String.fromCharCode.apply(null,n),0!==i.fileIdentifierString.lastIndexOf("Lerc2",0))throw"Unexpected file identifier string (expect Lerc2 ): "+i.fileIdentifierString;r+=6;var a,o=new DataView(e,r,8),s=o.getInt32(0,!0);if(i.fileVersion=s,r+=4,s>=3&&(i.checksum=o.getUint32(4,!0),r+=4),o=new DataView(e,r,12),i.height=o.getUint32(0,!0),i.width=o.getUint32(4,!0),r+=8,s>=4?(i.numDims=o.getUint32(8,!0),r+=4):i.numDims=1,o=new DataView(e,r,40),i.numValidPixel=o.getUint32(0,!0),i.microBlockSize=o.getInt32(4,!0),i.blobSize=o.getInt32(8,!0),i.imageType=o.getInt32(12,!0),i.maxZError=o.getFloat64(16,!0),i.zMin=o.getFloat64(24,!0),i.zMax=o.getFloat64(32,!0),r+=40,t.headerInfo=i,t.ptr=r,s>=3&&(a=s>=4?52:48,this.computeChecksumFletcher32(new Uint8Array(e,r-a,i.blobSize-14))!==i.checksum))throw"Checksum failed.";return!0},checkMinMaxRanges:function(e,t){var r=t.headerInfo,n=this.getDataTypeArray(r.imageType),i=r.numDims*this.getDataTypeSize(r.imageType),a=this.readSubArray(e,t.ptr,n,i),o=this.readSubArray(e,t.ptr+i,n,i);t.ptr+=2*i;var s,f=!0;for(s=0;s<r.numDims;s++)if(a[s]!==o[s]){f=!1;break}return r.minValues=a,r.maxValues=o,f},readSubArray:function(e,t,r,n){var i;if(r===Uint8Array)i=new Uint8Array(e,t,n);else{var a=new ArrayBuffer(n);new Uint8Array(a).set(new Uint8Array(e,t,n)),i=new r(a)}return i},readMask:function(e,t){var r,n,i=t.ptr,a=t.headerInfo,o=a.width*a.height,s=a.numValidPixel,f=new DataView(e,i,4),l={};if(l.numBytes=f.getUint32(0,!0),i+=4,(0===s||o===s)&&0!==l.numBytes)throw"invalid mask";if(0===s)r=new Uint8Array(Math.ceil(o/8)),l.bitset=r,n=new Uint8Array(o),t.pixels.resultMask=n,i+=l.numBytes;else if(l.numBytes>0){r=new Uint8Array(Math.ceil(o/8));var u=(f=new DataView(e,i,l.numBytes)).getInt16(0,!0),c=2,h=0,d=0;do{if(u>0)for(;u--;)r[h++]=f.getUint8(c++);else for(d=f.getUint8(c++),u=-u;u--;)r[h++]=d;u=f.getInt16(c,!0),c+=2}while(c<l.numBytes);if(-32768!==u||h<r.length)throw"Unexpected end of mask RLE encoding";n=new Uint8Array(o);var p=0,m=0;for(m=0;m<o;m++)7&m?(p=r[m>>3],p<<=7&m):p=r[m>>3],128&p&&(n[m]=1);t.pixels.resultMask=n,l.bitset=r,i+=l.numBytes}return t.ptr=i,t.mask=l,!0},readDataOneSweep:function(e,t,r,n){var i,a=t.ptr,o=t.headerInfo,s=o.numDims,f=o.width*o.height,l=o.imageType,u=o.numValidPixel*h.getDataTypeSize(l)*s,c=t.pixels.resultMask;if(r===Uint8Array)i=new Uint8Array(e,a,u);else{var d=new ArrayBuffer(u);new Uint8Array(d).set(new Uint8Array(e,a,u)),i=new r(d)}if(i.length===f*s)t.pixels.resultPixels=n?h.swapDimensionOrder(i,f,s,r,!0):i;else{t.pixels.resultPixels=new r(f*s);var p=0,m=0,v=0,y=0;if(s>1){if(n){for(m=0;m<f;m++)if(c[m])for(y=m,v=0;v<s;v++,y+=f)t.pixels.resultPixels[y]=i[p++]}else for(m=0;m<f;m++)if(c[m])for(y=m*s,v=0;v<s;v++)t.pixels.resultPixels[y+v]=i[p++]}else for(m=0;m<f;m++)c[m]&&(t.pixels.resultPixels[m]=i[p++])}return a+=u,t.ptr=a,!0},readHuffmanTree:function(e,t){var r=this.HUFFMAN_LUT_BITS_MAX,n=new DataView(e,t.ptr,16);if(t.ptr+=16,n.getInt32(0,!0)<2)throw"unsupported Huffman version";var i=n.getInt32(4,!0),a=n.getInt32(8,!0),o=n.getInt32(12,!0);if(a>=o)return!1;var s=new Uint32Array(o-a);h.decodeBits(e,t,s);var f,l,u,c,p=[];for(f=a;f<o;f++)p[l=f-(f<i?0:i)]={first:s[f-a],second:null};var m=e.byteLength-t.ptr,v=Math.ceil(m/4),y=new ArrayBuffer(4*v);new Uint8Array(y).set(new Uint8Array(e,t.ptr,m));var w,g=new Uint32Array(y),b=0,k=0;for(w=g[0],f=a;f<o;f++)(c=p[l=f-(f<i?0:i)].first)>0&&(p[l].second=w<<b>>>32-c,32-b>=c?32===(b+=c)&&(b=0,w=g[++k]):(b+=c-32,w=g[++k],p[l].second|=w>>>32-b));var x=0,_=0,A=new d;for(f=0;f<p.length;f++)void 0!==p[f]&&(x=Math.max(x,p[f].first));_=x>=r?r:x;var P,I,U,S,T,D=[];for(f=a;f<o;f++)if((c=p[l=f-(f<i?0:i)].first)>0)if(P=[c,l],c<=_)for(I=p[l].second<<_-c,U=1<<_-c,u=0;u<U;u++)D[I|u]=P;else for(I=p[l].second,T=A,S=c-1;S>=0;S--)I>>>S&1?(T.right||(T.right=new d),T=T.right):(T.left||(T.left=new d),T=T.left),0!==S||T.val||(T.val=P[1]);return{decodeLut:D,numBitsLUTQick:_,numBitsLUT:x,tree:A,stuffedData:g,srcPtr:k,bitPos:b}},readHuffman:function(e,t,r,n){var i,a,o,s,f,l,u,c,d,p=t.headerInfo.numDims,m=t.headerInfo.height,v=t.headerInfo.width,y=v*m,w=this.readHuffmanTree(e,t),g=w.decodeLut,b=w.tree,k=w.stuffedData,x=w.srcPtr,_=w.bitPos,A=w.numBitsLUTQick,P=w.numBitsLUT,I=0===t.headerInfo.imageType?128:0,U=t.pixels.resultMask,S=0;_>0&&(x++,_=0);var T,D=k[x],E=1===t.encodeMode,B=new r(y*p),O=B;if(p<2||E){for(T=0;T<p;T++)if(p>1&&(O=new r(B.buffer,y*T,y),S=0),t.headerInfo.numValidPixel===v*m)for(c=0,l=0;l<m;l++)for(u=0;u<v;u++,c++){if(a=0,f=s=D<<_>>>32-A,32-_<A&&(f=s|=k[x+1]>>>64-_-A),g[f])a=g[f][1],_+=g[f][0];else for(f=s=D<<_>>>32-P,32-_<P&&(f=s|=k[x+1]>>>64-_-P),i=b,d=0;d<P;d++)if(!(i=s>>>P-d-1&1?i.right:i.left).left&&!i.right){a=i.val,_=_+d+1;break}_>=32&&(_-=32,D=k[++x]),o=a-I,E?(o+=u>0?S:l>0?O[c-v]:S,o&=255,O[c]=o,S=o):O[c]=o}else for(c=0,l=0;l<m;l++)for(u=0;u<v;u++,c++)if(U[c]){if(a=0,f=s=D<<_>>>32-A,32-_<A&&(f=s|=k[x+1]>>>64-_-A),g[f])a=g[f][1],_+=g[f][0];else for(f=s=D<<_>>>32-P,32-_<P&&(f=s|=k[x+1]>>>64-_-P),i=b,d=0;d<P;d++)if(!(i=s>>>P-d-1&1?i.right:i.left).left&&!i.right){a=i.val,_=_+d+1;break}_>=32&&(_-=32,D=k[++x]),o=a-I,E?(u>0&&U[c-1]?o+=S:l>0&&U[c-v]?o+=O[c-v]:o+=S,o&=255,O[c]=o,S=o):O[c]=o}}else for(c=0,l=0;l<m;l++)for(u=0;u<v;u++)if(c=l*v+u,!U||U[c])for(T=0;T<p;T++,c+=y){if(a=0,f=s=D<<_>>>32-A,32-_<A&&(f=s|=k[x+1]>>>64-_-A),g[f])a=g[f][1],_+=g[f][0];else for(f=s=D<<_>>>32-P,32-_<P&&(f=s|=k[x+1]>>>64-_-P),i=b,d=0;d<P;d++)if(!(i=s>>>P-d-1&1?i.right:i.left).left&&!i.right){a=i.val,_=_+d+1;break}_>=32&&(_-=32,D=k[++x]),o=a-I,O[c]=o}t.ptr=t.ptr+4*(x+1)+(_>0?4:0),t.pixels.resultPixels=B,p>1&&!n&&(t.pixels.resultPixels=h.swapDimensionOrder(B,y,p,r))},decodeBits:function(e,t,r,n,i){var a=t.headerInfo,h=a.fileVersion,d=0,p=e.byteLength-t.ptr>=5?5:e.byteLength-t.ptr,m=new DataView(e,t.ptr,p),v=m.getUint8(0);d++;var y=v>>6,w=0===y?4:3-y,g=(32&v)>0,b=31&v,k=0;if(1===w)k=m.getUint8(d),d++;else if(2===w)k=m.getUint16(d,!0),d+=2;else{if(4!==w)throw"Invalid valid pixel count type";k=m.getUint32(d,!0),d+=4}var x,_,A,P,I,U,S,T,D,E=2*a.maxZError,B=a.numDims>1?a.maxValues[i]:a.zMax;if(g){for(t.counter.lut++,T=m.getUint8(d),d++,P=Math.ceil((T-1)*b/8),I=Math.ceil(P/4),_=new ArrayBuffer(4*I),A=new Uint8Array(_),t.ptr+=d,A.set(new Uint8Array(e,t.ptr,P)),S=new Uint32Array(_),t.ptr+=P,D=0;T-1>>>D;)D++;P=Math.ceil(k*D/8),I=Math.ceil(P/4),_=new ArrayBuffer(4*I),(A=new Uint8Array(_)).set(new Uint8Array(e,t.ptr,P)),x=new Uint32Array(_),t.ptr+=P,U=h>=3?l(S,b,T-1,n,E,B):s(S,b,T-1,n,E,B),h>=3?f(x,r,D,k,U):o(x,r,D,k,U)}else t.counter.bitstuffer++,D=b,t.ptr+=d,D>0&&(P=Math.ceil(k*D/8),I=Math.ceil(P/4),_=new ArrayBuffer(4*I),(A=new Uint8Array(_)).set(new Uint8Array(e,t.ptr,P)),x=new Uint32Array(_),t.ptr+=P,h>=3?null==n?c(x,r,D,k):f(x,r,D,k,!1,n,E,B):null==n?u(x,r,D,k):o(x,r,D,k,!1,n,E,B))},readTiles:function(e,t,r,n){var i=t.headerInfo,a=i.width,o=i.height,s=a*o,f=i.microBlockSize,l=i.imageType,u=h.getDataTypeSize(l),c=Math.ceil(a/f),d=Math.ceil(o/f);t.pixels.numBlocksY=d,t.pixels.numBlocksX=c,t.pixels.ptr=0;var p,m,v,y,w,g,b,k,x,_,A=0,P=0,I=0,U=0,S=0,T=0,D=0,E=0,B=0,O=0,M=0,C=0,L=0,R=0,V=0,G=new r(f*f),F=o%f||f,z=a%f||f,j=i.numDims,N=t.pixels.resultMask,Z=t.pixels.resultPixels,K=i.fileVersion>=5?14:15,H=i.zMax;for(I=0;I<d;I++)for(S=I!==d-1?f:F,U=0;U<c;U++)for(O=I*a*f+U*f,M=a-(T=U!==c-1?f:z),k=0;k<j;k++){if(j>1?(_=Z,O=I*a*f+U*f,Z=new r(t.pixels.resultPixels.buffer,s*k*u,s),H=i.maxValues[k]):_=null,D=e.byteLength-t.ptr,m={},V=0,E=(p=new DataView(e,t.ptr,Math.min(10,D))).getUint8(0),V++,x=i.fileVersion>=5?4&E:0,B=E>>6&255,(E>>2&K)!=(U*f>>3&K))throw"integrity issue";if(x&&0===k)throw"integrity issue";if((w=3&E)>3)throw t.ptr+=V,"Invalid block encoding ("+w+")";if(2!==w)if(0===w){if(x)throw"integrity issue";if(t.counter.uncompressed++,t.ptr+=V,C=(C=S*T*u)<(L=e.byteLength-t.ptr)?C:L,v=new ArrayBuffer(C%u==0?C:C+u-C%u),new Uint8Array(v).set(new Uint8Array(e,t.ptr,C)),y=new r(v),R=0,N)for(A=0;A<S;A++){for(P=0;P<T;P++)N[O]&&(Z[O]=y[R++]),O++;O+=M}else for(A=0;A<S;A++){for(P=0;P<T;P++)Z[O++]=y[R++];O+=M}t.ptr+=R*u}else if(g=h.getDataTypeUsed(x&&l<6?4:l,B),b=h.getOnePixel(m,V,g,p),V+=h.getDataTypeSize(g),3===w)if(t.ptr+=V,t.counter.constantoffset++,N)for(A=0;A<S;A++){for(P=0;P<T;P++)N[O]&&(Z[O]=x?Math.min(H,_[O]+b):b),O++;O+=M}else for(A=0;A<S;A++){for(P=0;P<T;P++)Z[O]=x?Math.min(H,_[O]+b):b,O++;O+=M}else if(t.ptr+=V,h.decodeBits(e,t,G,b,k),V=0,x)if(N)for(A=0;A<S;A++){for(P=0;P<T;P++)N[O]&&(Z[O]=G[V++]+_[O]),O++;O+=M}else for(A=0;A<S;A++){for(P=0;P<T;P++)Z[O]=G[V++]+_[O],O++;O+=M}else if(N)for(A=0;A<S;A++){for(P=0;P<T;P++)N[O]&&(Z[O]=G[V++]),O++;O+=M}else for(A=0;A<S;A++){for(P=0;P<T;P++)Z[O++]=G[V++];O+=M}else{if(x)if(N)for(A=0;A<S;A++)for(P=0;P<T;P++)N[O]&&(Z[O]=_[O]),O++;else for(A=0;A<S;A++)for(P=0;P<T;P++)Z[O]=_[O],O++;t.counter.constant++,t.ptr+=V}}j>1&&!n&&(t.pixels.resultPixels=h.swapDimensionOrder(t.pixels.resultPixels,s,j,r))},formatFileInfo:function(e){return{fileIdentifierString:e.headerInfo.fileIdentifierString,fileVersion:e.headerInfo.fileVersion,imageType:e.headerInfo.imageType,height:e.headerInfo.height,width:e.headerInfo.width,numValidPixel:e.headerInfo.numValidPixel,microBlockSize:e.headerInfo.microBlockSize,blobSize:e.headerInfo.blobSize,maxZError:e.headerInfo.maxZError,pixelType:h.getPixelType(e.headerInfo.imageType),eofOffset:e.eofOffset,mask:e.mask?{numBytes:e.mask.numBytes}:null,pixels:{numBlocksX:e.pixels.numBlocksX,numBlocksY:e.pixels.numBlocksY,maxValue:e.headerInfo.zMax,minValue:e.headerInfo.zMin,noDataValue:e.noDataValue}}},constructConstantSurface:function(e,t){var r=e.headerInfo.zMax,n=e.headerInfo.zMin,i=e.headerInfo.maxValues,a=e.headerInfo.numDims,o=e.headerInfo.height*e.headerInfo.width,s=0,f=0,l=0,u=e.pixels.resultMask,c=e.pixels.resultPixels;if(u)if(a>1){if(t)for(s=0;s<a;s++)for(l=s*o,r=i[s],f=0;f<o;f++)u[f]&&(c[l+f]=r);else for(f=0;f<o;f++)if(u[f])for(l=f*a,s=0;s<a;s++)c[l+a]=i[s]}else for(f=0;f<o;f++)u[f]&&(c[f]=r);else if(a>1&&n!==r)if(t)for(s=0;s<a;s++)for(l=s*o,r=i[s],f=0;f<o;f++)c[l+f]=r;else for(f=0;f<o;f++)for(l=f*a,s=0;s<a;s++)c[l+s]=i[s];else for(f=0;f<o*a;f++)c[f]=r},getDataTypeArray:function(e){var t;switch(e){case 0:t=Int8Array;break;case 1:t=Uint8Array;break;case 2:t=Int16Array;break;case 3:t=Uint16Array;break;case 4:t=Int32Array;break;case 5:t=Uint32Array;break;case 6:default:t=Float32Array;break;case 7:t=Float64Array}return t},getPixelType:function(e){var t;switch(e){case 0:t="S8";break;case 1:t="U8";break;case 2:t="S16";break;case 3:t="U16";break;case 4:t="S32";break;case 5:t="U32";break;case 6:default:t="F32";break;case 7:t="F64"}return t},isValidPixelValue:function(e,t){if(null==t)return!1;var r;switch(e){case 0:r=t>=-128&&t<=127;break;case 1:r=t>=0&&t<=255;break;case 2:r=t>=-32768&&t<=32767;break;case 3:r=t>=0&&t<=65536;break;case 4:r=t>=-2147483648&&t<=2147483647;break;case 5:r=t>=0&&t<=4294967296;break;case 6:r=t>=-34027999387901484e22&&t<=34027999387901484e22;break;case 7:r=t>=-17976931348623157e292&&t<=17976931348623157e292;break;default:r=!1}return r},getDataTypeSize:function(e){var t=0;switch(e){case 0:case 1:t=1;break;case 2:case 3:t=2;break;case 4:case 5:case 6:t=4;break;case 7:t=8;break;default:t=e}return t},getDataTypeUsed:function(e,t){var r=e;switch(e){case 2:case 4:r=e-t;break;case 3:case 5:r=e-2*t;break;case 6:r=0===t?e:1===t?2:1;break;case 7:r=0===t?e:e-2*t+1;break;default:r=e}return r},getOnePixel:function(e,t,r,n){var i=0;switch(r){case 0:i=n.getInt8(t);break;case 1:i=n.getUint8(t);break;case 2:i=n.getInt16(t,!0);break;case 3:i=n.getUint16(t,!0);break;case 4:i=n.getInt32(t,!0);break;case 5:i=n.getUInt32(t,!0);break;case 6:i=n.getFloat32(t,!0);break;case 7:i=n.getFloat64(t,!0);break;default:throw"the decoder does not understand this pixel type"}return i},swapDimensionOrder:function(e,t,r,n,i){var a=0,o=0,s=0,f=0,l=e;if(r>1)if(l=new n(t*r),i)for(a=0;a<t;a++)for(f=a,s=0;s<r;s++,f+=t)l[f]=e[o++];else for(a=0;a<t;a++)for(f=a,s=0;s<r;s++,f+=t)l[o++]=e[f];return l}},d=function(e,t,r){this.val=e,this.left=t,this.right=r},{decode:function(e,t){var r=(t=t||{}).noDataValue,n=0,i={};i.ptr=t.inputOffset||0,i.pixels={},h.readHeaderInfo(e,i);var a=i.headerInfo,o=a.fileVersion,s=h.getDataTypeArray(a.imageType);if(o>5)throw"unsupported lerc version 2."+o;h.readMask(e,i),a.numValidPixel===a.width*a.height||i.pixels.resultMask||(i.pixels.resultMask=t.maskData);var f=a.width*a.height;i.pixels.resultPixels=new s(f*a.numDims),i.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0};var l,u=!t.returnPixelInterleavedDims;if(0!==a.numValidPixel)if(a.zMax===a.zMin)h.constructConstantSurface(i,u);else if(o>=4&&h.checkMinMaxRanges(e,i))h.constructConstantSurface(i,u);else{var c=new DataView(e,i.ptr,2),d=c.getUint8(0);if(i.ptr++,d)h.readDataOneSweep(e,i,s,u);else if(o>1&&a.imageType<=1&&Math.abs(a.maxZError-.5)<1e-5){var p=c.getUint8(1);if(i.ptr++,i.encodeMode=p,p>2||o<4&&p>1)throw"Invalid Huffman flag "+p;p?h.readHuffman(e,i,s,u):h.readTiles(e,i,s,u)}else h.readTiles(e,i,s,u)}i.eofOffset=i.ptr,t.inputOffset?(l=i.headerInfo.blobSize+t.inputOffset-i.ptr,Math.abs(l)>=1&&(i.eofOffset=t.inputOffset+i.headerInfo.blobSize)):(l=i.headerInfo.blobSize-i.ptr,Math.abs(l)>=1&&(i.eofOffset=i.headerInfo.blobSize));var m={width:a.width,height:a.height,pixelData:i.pixels.resultPixels,minValue:a.zMin,maxValue:a.zMax,validPixelCount:a.numValidPixel,dimCount:a.numDims,dimStats:{minValues:a.minValues,maxValues:a.maxValues},maskData:i.pixels.resultMask};if(i.pixels.resultMask&&h.isValidPixelValue(a.imageType,r)){var v=i.pixels.resultMask;for(n=0;n<f;n++)v[n]||(m.pixelData[n]=r);m.noDataValue=r}return i.noDataValue=r,t.returnFileInfo&&(m.fileInfo=h.formatFileInfo(i)),m},getBandCount:function(e){for(var t=0,r=0,n={ptr:0,pixels:{}};r<e.byteLength-58;)h.readHeaderInfo(e,n),r+=n.headerInfo.blobSize,t++,n.ptr=r;return t}}),w=(p=new ArrayBuffer(4),m=new Uint8Array(p),new Uint32Array(p)[0]=1,1===m[0]),g={decode:function(e,t){if(!w)throw"Big endian system is not supported.";var r,n,i=(t=t||{}).inputOffset||0,a=new Uint8Array(e,i,10),o=String.fromCharCode.apply(null,a);if("CntZImage"===o.trim())r=v,n=1;else{if("Lerc2"!==o.substring(0,5))throw"Unexpected file identifier string: "+o;r=y,n=2}for(var s,f,l,u,c,h,d=0,p=e.byteLength-10,m=[],g={width:0,height:0,pixels:[],pixelType:t.pixelType,mask:null,statistics:[]},b=0;i<p;){var k=r.decode(e,{inputOffset:i,encodedMaskData:s,maskData:l,returnMask:0===d,returnEncodedMask:0===d,returnFileInfo:!0,returnPixelInterleavedDims:t.returnPixelInterleavedDims,pixelType:t.pixelType||null,noDataValue:t.noDataValue||null});i=k.fileInfo.eofOffset,l=k.maskData,0===d&&(s=k.encodedMaskData,g.width=k.width,g.height=k.height,g.dimCount=k.dimCount||1,g.pixelType=k.pixelType||k.fileInfo.pixelType,g.mask=l),n>1&&(l&&m.push(l),k.fileInfo.mask&&k.fileInfo.mask.numBytes>0&&b++),d++,g.pixels.push(k.pixelData),g.statistics.push({minValue:k.minValue,maxValue:k.maxValue,noDataValue:k.noDataValue,dimStats:k.dimStats})}if(n>1&&b>1){for(h=g.width*g.height,g.bandMasks=m,(l=new Uint8Array(h)).set(m[0]),u=1;u<m.length;u++)for(f=m[u],c=0;c<h;c++)l[c]=l[c]&f[c];g.maskData=l}return g}};Ke.exports?Ke.exports=g:this.Lerc=g}();var We=Xe.exports,qe={315:"Artist",258:"BitsPerSample",265:"CellLength",264:"CellWidth",320:"ColorMap",259:"Compression",33432:"Copyright",306:"DateTime",338:"ExtraSamples",266:"FillOrder",289:"FreeByteCounts",288:"FreeOffsets",291:"GrayResponseCurve",290:"GrayResponseUnit",316:"HostComputer",270:"ImageDescription",257:"ImageLength",256:"ImageWidth",271:"Make",281:"MaxSampleValue",280:"MinSampleValue",272:"Model",254:"NewSubfileType",274:"Orientation",262:"PhotometricInterpretation",284:"PlanarConfiguration",296:"ResolutionUnit",278:"RowsPerStrip",277:"SamplesPerPixel",305:"Software",279:"StripByteCounts",273:"StripOffsets",255:"SubfileType",263:"Threshholding",282:"XResolution",283:"YResolution",326:"BadFaxLines",327:"CleanFaxData",343:"ClipPath",328:"ConsecutiveBadFaxLines",433:"Decode",434:"DefaultImageColor",269:"DocumentName",336:"DotRange",321:"HalftoneHints",346:"Indexed",347:"JPEGTables",285:"PageName",297:"PageNumber",317:"Predictor",319:"PrimaryChromaticities",532:"ReferenceBlackWhite",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",559:"StripRowCounts",330:"SubIFDs",292:"T4Options",293:"T6Options",325:"TileByteCounts",323:"TileLength",324:"TileOffsets",322:"TileWidth",301:"TransferFunction",318:"WhitePoint",344:"XClipPathUnits",286:"XPosition",529:"YCbCrCoefficients",531:"YCbCrPositioning",530:"YCbCrSubSampling",345:"YClipPathUnits",287:"YPosition",37378:"ApertureValue",40961:"ColorSpace",36868:"DateTimeDigitized",36867:"DateTimeOriginal",34665:"Exif IFD",36864:"ExifVersion",33434:"ExposureTime",41728:"FileSource",37385:"Flash",40960:"FlashpixVersion",33437:"FNumber",42016:"ImageUniqueID",37384:"LightSource",37500:"MakerNote",37377:"ShutterSpeedValue",37510:"UserComment",33723:"IPTC",34675:"ICC Profile",700:"XMP",42112:"GDAL_METADATA",42113:"GDAL_NODATA",34377:"Photoshop",33550:"ModelPixelScale",33922:"ModelTiepoint",34264:"ModelTransformation",34735:"GeoKeyDirectory",34736:"GeoDoubleParams",34737:"GeoAsciiParams",50674:"LercParameters"},Je={};for(var Qe in qe)qe.hasOwnProperty(Qe)&&(Je[qe[Qe]]=parseInt(Qe,10));Je.BitsPerSample,Je.ExtraSamples,Je.SampleFormat,Je.StripByteCounts,Je.StripOffsets,Je.StripRowCounts,Je.TileByteCounts,Je.TileOffsets,Je.SubIFDs;var $e={1:"BYTE",2:"ASCII",3:"SHORT",4:"LONG",5:"RATIONAL",6:"SBYTE",7:"UNDEFINED",8:"SSHORT",9:"SLONG",10:"SRATIONAL",11:"FLOAT",12:"DOUBLE",13:"IFD",16:"LONG8",17:"SLONG8",18:"IFD8"},et={};for(var tt in $e)$e.hasOwnProperty(tt)&&(et[$e[tt]]=parseInt(tt,10));var rt=1,nt=0,it=1,at={1024:"GTModelTypeGeoKey",1025:"GTRasterTypeGeoKey",1026:"GTCitationGeoKey",2048:"GeographicTypeGeoKey",2049:"GeogCitationGeoKey",2050:"GeogGeodeticDatumGeoKey",2051:"GeogPrimeMeridianGeoKey",2052:"GeogLinearUnitsGeoKey",2053:"GeogLinearUnitSizeGeoKey",2054:"GeogAngularUnitsGeoKey",2055:"GeogAngularUnitSizeGeoKey",2056:"GeogEllipsoidGeoKey",2057:"GeogSemiMajorAxisGeoKey",2058:"GeogSemiMinorAxisGeoKey",2059:"GeogInvFlatteningGeoKey",2060:"GeogAzimuthUnitsGeoKey",2061:"GeogPrimeMeridianLongGeoKey",2062:"GeogTOWGS84GeoKey",3072:"ProjectedCSTypeGeoKey",3073:"PCSCitationGeoKey",3074:"ProjectionGeoKey",3075:"ProjCoordTransGeoKey",3076:"ProjLinearUnitsGeoKey",3077:"ProjLinearUnitSizeGeoKey",3078:"ProjStdParallel1GeoKey",3079:"ProjStdParallel2GeoKey",3080:"ProjNatOriginLongGeoKey",3081:"ProjNatOriginLatGeoKey",3082:"ProjFalseEastingGeoKey",3083:"ProjFalseNorthingGeoKey",3084:"ProjFalseOriginLongGeoKey",3085:"ProjFalseOriginLatGeoKey",3086:"ProjFalseOriginEastingGeoKey",3087:"ProjFalseOriginNorthingGeoKey",3088:"ProjCenterLongGeoKey",3089:"ProjCenterLatGeoKey",3090:"ProjCenterEastingGeoKey",3091:"ProjCenterNorthingGeoKey",3092:"ProjScaleAtNatOriginGeoKey",3093:"ProjScaleAtCenterGeoKey",3094:"ProjAzimuthAngleGeoKey",3095:"ProjStraightVertPoleLongGeoKey",3096:"ProjRectifiedGridAngleGeoKey",4096:"VerticalCSTypeGeoKey",4097:"VerticalCitationGeoKey",4098:"VerticalDatumGeoKey",4099:"VerticalUnitsGeoKey"},ot={};for(var st in at)at.hasOwnProperty(st)&&(ot[at[st]]=parseInt(st,10));function ft(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var lt=function(e){p(r,b);var t=ft(r);function r(e){var n;return u(this,r),(n=t.call(this)).planarConfiguration=void 0!==e.PlanarConfiguration?e.PlanarConfiguration:1,n.samplesPerPixel=void 0!==e.SamplesPerPixel?e.SamplesPerPixel:1,n.addCompression=e.LercParameters[rt],n}return h(r,[{key:"decodeBlock",value:function(e){switch(this.addCompression){case nt:break;case it:e=Fe(new Uint8Array(e)).buffer;break;default:throw new Error("Unsupported LERC additional compression method identifier: ".concat(this.addCompression))}return We.decode(e,{returnPixelInterleavedDims:1===this.planarConfiguration}).pixels[0].buffer}}]),r}(),ut=Object.freeze({__proto__:null,default:lt});function ct(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var i=v(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return m(this,r)}}var ht=function(e){p(a,b);var r,n=ct(a);function a(){var e;if(u(this,a),e=n.call(this),"undefined"==typeof createImageBitmap)throw new Error("Cannot decode WebImage as `createImageBitmap` is not available");if("undefined"==typeof document&&"undefined"==typeof OffscreenCanvas)throw new Error("Cannot decode WebImage as neither `document` nor `OffscreenCanvas` is not available");return e}return h(a,[{key:"decode",value:(r=t(i.mark((function e(t,r){var n,a,o,s;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new Blob([r]),e.next=3,createImageBitmap(n);case 3:return a=e.sent,"undefined"!=typeof document?((o=document.createElement("canvas")).width=a.width,o.height=a.height):o=new OffscreenCanvas(a.width,a.height),(s=o.getContext("2d")).drawImage(a,0,0),e.abrupt("return",s.getImageData(0,0,a.width,a.height).data.buffer);case 8:case"end":return e.stop()}}),e)}))),function(e,t){return r.apply(this,arguments)})}]),a}(),dt=Object.freeze({__proto__:null,default:ht});';
|
|
3657
|
-
return new browser(typeof Blob === "undefined" ? "data:application/javascript;base64," + Buffer.from(source, "binary").toString("base64") : URL.createObjectURL(new Blob([source], { type: "application/javascript" })));
|
|
3658
|
-
}
|
|
3659
|
-
var decoder = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3660
|
-
__proto__: null,
|
|
3661
|
-
create
|
|
3662
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
3663
|
-
export { Pool$1 as P, fromUrls as a, fromUrl as b, fromBlob as f };
|