diff --git a/.babelrc b/.babelrc index b57bf588..18705a6a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,12 +1,11 @@ { - "presets": ["env"], - "plugins": [ - [ - "transform-runtime", - { - "polyfill": false, - "regenerator": true - } - ] - ] -} + "presets": [[ + "@babel/preset-env", { + "modules": false, + "targets": { + "node": true + }, + "useBuiltIns": "usage" + } + ]] +} \ No newline at end of file diff --git a/package.json b/package.json index 8a9b543d..3867b7a4 100644 --- a/package.json +++ b/package.json @@ -15,16 +15,13 @@ "xmldom": "0.1.*" }, "devDependencies": { - "babel-cli": "^6.26.0", - "babel-core": "^6.26.0", - "babel-eslint": "^7.1.1", - "babel-loader": "^7.1.2", - "babel-plugin-syntax-async-functions": "^6.13.0", - "babel-plugin-transform-async-to-generator": "^6.16.0", - "babel-plugin-transform-runtime": "^6.23.0", - "babel-polyfill": "^6.26.0", - "babel-preset-env": "^1.6.1", + "@babel/cli": "^7.0.0", + "@babel/core": "^7.0.0", + "@babel/polyfill": "^7.0.0", + "@babel/preset-env": "^7.0.0", + "benchmark": "^2.1.4", "chai": "^3.5.0", + "cross-env": "^5.2.0", "detect-node": "^2.0.3", "es6-promise": "^4.0.5", "eslint": "^4.18.0", @@ -33,27 +30,32 @@ "eslint-plugin-jsx-a11y": "^6.0.3", "eslint-plugin-react": "^7.7.0", "express": "^4.16.3", + "extract-zip": "^1.6.7", "isomorphic-fetch": "^2.2.1", "jsdoc": "^3.5.5", "jsdoc-babel": "^0.2.1", "jshint-stylish": "^2.2.1", "mocha": "^3.1.2", + "node-wget": "^0.4.2", + "rollup": "^0.65.0", + "rollup-plugin-babel": "^4.0.2", + "rollup-plugin-butternut": "^0.1.0", + "rollup-plugin-commonjs": "^8.3.0", + "rollup-plugin-node-builtins": "^2.1.2", + "rollup-plugin-node-globals": "^1.2.1", + "rollup-plugin-node-resolve": "^3.3.0", + "shelljs": "^0.8.2", + "shx": "^0.3.2", "webpack": "^3.10.0", "webpack-dev-server": "^2.11.1", "worker-loader": "^1.1.1" }, "scripts": { - "dev": "webpack-dev-server -d -w --content-base test", - "watch": "webpack -d -w", - "build:clean": "rm -rf dist/*", - "bundle:dev": "webpack -d ", - "bundle:prod": "NODE_ENV=production webpack -p", - "build:babel": "babel src/ -d dist", - "build:babel:watch": "babel src/ -d dist -w", - "build": "npm run build:clean ; npm run bundle:dev ; npm run bundle:prod ; npm run build:babel", + "dev": "rollup -c -w", + "build": "rollup -c", "test": "mocha --compilers js:babel-core/register --require babel-polyfill", "lint": "eslint src", - "docs": "rm -rf docs/*; jsdoc -c .jsdoc.json -r src README.md -d docs", + "docs": "shx rm -rf docs/* && jsdoc -c .jsdoc.json -r src README.md -d docs", "prepublish": "npm run build" }, "author": "Fabian Schindler", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..611d49e6 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,32 @@ +import resolve from 'rollup-plugin-node-resolve' +import babel from 'rollup-plugin-babel' +import commonjs from 'rollup-plugin-commonjs' +import builtins from 'rollup-plugin-node-builtins'; +import globals from 'rollup-plugin-node-globals'; +import butternut from 'rollup-plugin-butternut'; + +export default { + input: 'src/main.js', + output: { + file: 'dist/bundle.js', + format: 'umd', + name: 'GeoTIFF', + sourcemap: 'dist/bundle.js.map' + }, + watch: { + include: 'src/**', + exclude: ['node_modules/**'], + }, + plugins: [ + builtins(), // FLags that some of the import statements are NodeJS built-ins + globals(), + resolve(), + commonjs({ + include: 'node_modules/**', + }), + babel({ + exclude: 'node_modules/**', + include: 'pako/**' + }), + ], +} diff --git a/src/decoder.worker.js b/src/decoder.worker.js index 4fbf21a5..01835f9c 100644 --- a/src/decoder.worker.js +++ b/src/decoder.worker.js @@ -1,8 +1,8 @@ /* eslint-disable no-restricted-globals */ import { getDecoder } from './compression'; - -function decode(self, fileDirectory, buffer) { + +export default function decode(self, fileDirectory, buffer) { const decoder = getDecoder(fileDirectory); const result = decoder.decode(fileDirectory, buffer); self.postMessage([result], [result]); diff --git a/src/source.js b/src/source.js index cf78b3e4..d5544d0c 100644 --- a/src/source.js +++ b/src/source.js @@ -1,9 +1,11 @@ import { Buffer } from 'buffer'; -import { open, read } from 'fs'; +import fs from 'fs'; import http from 'http'; import https from 'https'; import urlMod from 'url'; +const open = fs.open +const read = fs.read function readRangeFromBlocks(blocks, rangeOffset, rangeLength) { const rangeTop = rangeOffset + rangeLength; diff --git a/test/data/setupData.js b/test/data/setupData.js new file mode 100644 index 00000000..7533a8c7 --- /dev/null +++ b/test/data/setupData.js @@ -0,0 +1,61 @@ +const shell = require('shelljs'); +const wget = require('node-wget'); +var extract = require('extract-zip'); + +wget({ + url: 'https://github.com/EOxServer/autotest/raw/f8d9f4bde6686abbda09c711d4bf5239f5378aa9/autotest/data/meris/MER_FRS_1P_reduced/ENVISAT-MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_uint16_reduced_compressed.tif', + dest: 'initial.tiff', +}); + +wget({ + url: 'https://github.com/EOxServer/autotest/raw/f8d9f4bde6686abbda09c711d4bf5239f5378aa9/autotest/data/meris/mosaic_MER_FRS_1P_RGB_reduced/mosaic_ENVISAT-MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_RGB_reduced.tif', + dest: 'rgb.tiff', +}); + +shell.exec('gdal_translate -of GTiff initial.tiff stripped.tiff'); +shell.exec('gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 -co BLOCKYSIZE=32 stripped.tiff tiled.tiff'); +shell.exec('gdal_translate -of GTiff -ot Int32 stripped.tiff int32.tiff'); +shell.exec('gdal_translate -of GTiff -ot UInt32 stripped.tiff uint32.tiff'); +shell.exec('gdal_translate -of GTiff -ot Float32 stripped.tiff float32.tiff'); +shell.exec('gdal_translate -of GTiff -ot Float64 stripped.tiff float64.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=LZW stripped.tiff lzw.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=DEFLATE stripped.tiff deflate.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=DEFLATE -co PREDICTOR=2 stripped.tiff deflate_predictor.tiff'); +shell.exec('gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 -co BLOCKYSIZE=32 -co COMPRESS=DEFLATE -co PREDICTOR=2 stripped.tiff deflate_predictor_tiled.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=PACKBITS stripped.tiff packbits.tiff'); +shell.exec('gdal_translate -of GTiff -co INTERLEAVE=BAND stripped.tiff interleave.tiff'); +shell.exec('gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 -co BLOCKYSIZE=32 -co INTERLEAVE=BAND stripped.tiff tiledplanar.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=LZW -co TILED=YES -co BLOCKXSIZE=32 -co BLOCKYSIZE=32 -co INTERLEAVE=BAND stripped.tiff tiledplanarlzw.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=LZW -ot Float64 stripped.tiff float64lzw.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=LZW -co PREDICTOR=2 stripped.tiff lzw_predictor.tiff'); +shell.exec('gdal_translate -of GTiff -outsize 10% 10% stripped.tiff small.tiff'); +shell.exec('gdal_translate -of GTiff -co BIGTIFF=YES stripped.tiff bigtiff.tiff'); + + +// overviews +shell.cp('stripped.tiff', 'overviews.tiff'); +shell.exec('gdaladdo overviews.tiff 2 4 8 16'); + +// bigtiff +wget('http://www.awaresystems.be/imaging/tiff/bigtiff/BigTIFFSamples.zip'); +extract('BigTIFFSamples.zip', { + dir: __dirname, +}, +function (err) { //eslint-disable-line + console.log(err); + shell.rm('BigTIFFSamples.zip'); +}, +); + +// color images +shell.exec('rgb2pct.py rgb.tiff rgb_paletted.tiff'); +shell.exec('rgb2ycbcr rgb.tiff ycbcr.tif -h 1 -v 1'); +shell.exec('convert rgb.tiff -colorspace CMYK cmyk.tif'); +shell.exec('convert rgb.tiff -colorspace Lab cielab.tif'); + +shell.exec('gdal_translate -of GTiff -co COMPRESS=JPEG rgb.tiff jpeg.tiff'); +shell.exec('gdal_translate -of GTiff -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR rgb.tiff jpeg_ycbcr.tiff'); + + +// modeltransformation tag +wget('https://s3.amazonaws.com/wdt-external/no_pixelscale_or_tiepoints.tiff');