diff --git a/.gitignore b/.gitignore index e90fd5e4..26d44417 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,3 @@ Python/build/ *.so *.o *.pyc - -# Typescript -TypeScript/node_modules/ diff --git a/TypeScript/.gitignore b/TypeScript/.gitignore new file mode 100644 index 00000000..04c01ba7 --- /dev/null +++ b/TypeScript/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ \ No newline at end of file diff --git a/TypeScript/dist/decode.d.ts b/TypeScript/dist/decode.d.ts deleted file mode 100644 index ea3ee1d6..00000000 --- a/TypeScript/dist/decode.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const decode: (blurhash: string, width: number, height: number, punch?: number) => Uint8ClampedArray; -export default decode; diff --git a/TypeScript/dist/decode.js b/TypeScript/dist/decode.js deleted file mode 100644 index dcb15b14..00000000 --- a/TypeScript/dist/decode.js +++ /dev/null @@ -1,76 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var base83_1 = require("./base83"); -var utils_1 = require("./utils"); -var decodeDC = function (value) { - var intR = value >> 16; - var intG = (value >> 8) & 255; - var intB = value & 255; - return [utils_1.sRGBToLinear(intR), utils_1.sRGBToLinear(intG), utils_1.sRGBToLinear(intB)]; -}; -var decodeAC = function (value, maximumValue) { - var quantR = Math.floor(value / (19 * 19)); - var quantG = Math.floor(value / 19) % 19; - var quantB = value % 19; - var rgb = [ - utils_1.signPow((quantR - 9) / 9, 2.0) * maximumValue, - utils_1.signPow((quantG - 9) / 9, 2.0) * maximumValue, - utils_1.signPow((quantB - 9) / 9, 2.0) * maximumValue, - ]; - return rgb; -}; -var decode = function (blurhash, width, height, punch) { - punch = punch | 1; - if (blurhash.length < 6) { - console.error('too short blurhash'); - return null; - } - var sizeFlag = base83_1.decode83(blurhash[0]); - var numY = Math.floor(sizeFlag / 9) + 1; - var numX = (sizeFlag % 9) + 1; - var quantisedMaximumValue = base83_1.decode83(blurhash[1]); - var maximumValue = (quantisedMaximumValue + 1) / 166; - if (blurhash.length !== 4 + 2 * numX * numY) { - console.error('blurhash length mismatch', blurhash.length, 4 + 2 * numX * numY); - return null; - } - var colors = new Array(numX * numY); - for (var i = 0; i < colors.length; i++) { - if (i === 0) { - var value = base83_1.decode83(blurhash.substring(2, 6)); - colors[i] = decodeDC(value); - } - else { - var value = base83_1.decode83(blurhash.substring(4 + i * 2, 6 + i * 2)); - colors[i] = decodeAC(value, maximumValue * punch); - } - } - var bytesPerRow = width * 4; - var pixels = new Uint8ClampedArray(bytesPerRow * height); - for (var y = 0; y < height; y++) { - for (var x = 0; x < width; x++) { - var r = 0; - var g = 0; - var b = 0; - for (var j = 0; j < numY; j++) { - for (var i = 0; i < numX; i++) { - var basis = Math.cos(Math.PI * x * i / width) * Math.cos(Math.PI * y * j / height); - var color = colors[i + j * numX]; - r += color[0] * basis; - g += color[1] * basis; - b += color[2] * basis; - } - } - var intR = utils_1.linearTosRGB(r); - var intG = utils_1.linearTosRGB(g); - var intB = utils_1.linearTosRGB(b); - pixels[4 * x + 0 + y * bytesPerRow] = intR; - pixels[4 * x + 1 + y * bytesPerRow] = intG; - pixels[4 * x + 2 + y * bytesPerRow] = intB; - pixels[4 * x + 3 + y * bytesPerRow] = 255; // alpha - } - } - return pixels; -}; -exports.default = decode; -//# sourceMappingURL=decode.js.map \ No newline at end of file diff --git a/TypeScript/dist/decode.js.map b/TypeScript/dist/decode.js.map deleted file mode 100644 index 87dbb1f7..00000000 --- a/TypeScript/dist/decode.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decode.js","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":";;AAAA,mCAAoC;AACpC,iCAA8D;AAE9D,IAAM,QAAQ,GAAG,UAAC,KAAa;IAC7B,IAAM,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;IACzB,IAAM,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC;IAChC,IAAM,IAAI,GAAG,KAAK,GAAG,GAA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CAAC,CAAC,CAAC;YAC3B,IAAI,IAAI,GAAG,oBAAY,CAAC,CAAC,CAAC,CAAC;YAE3B,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC;YAC3C,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC;YAC3C,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC;YAC3C,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ;QACrD,CAAC;IACH,CAAC;IACD,MAAM,CAAC,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/TypeScript/dist/index.d.ts b/TypeScript/dist/index.d.ts deleted file mode 100644 index bf5e794b..00000000 --- a/TypeScript/dist/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as decode } from './decode'; -export { default as encode } from './encode'; diff --git a/TypeScript/dist/index.js b/TypeScript/dist/index.js deleted file mode 100644 index bc18a43d..00000000 --- a/TypeScript/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var decode_1 = require("./decode"); -exports.decode = decode_1.default; -var encode_1 = require("./encode"); -exports.encode = encode_1.default; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/TypeScript/dist/index.js.map b/TypeScript/dist/index.js.map deleted file mode 100644 index f4ef53fe..00000000 --- a/TypeScript/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,mCAA6C;AAApC,0BAAA,OAAO,CAAU;AAC1B,mCAA6C;AAApC,0BAAA,OAAO,CAAU"} \ No newline at end of file diff --git a/TypeScript/dist/utils.d.ts b/TypeScript/dist/utils.d.ts deleted file mode 100644 index 7cd94c7f..00000000 --- a/TypeScript/dist/utils.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare const sRGBToLinear: (value: number) => number; -export declare const linearTosRGB: (value: number) => number; -export declare const sign: (n: number) => 1 | -1; -export declare const signPow: (val: number, exp: number) => number; diff --git a/TypeScript/dist/utils.js b/TypeScript/dist/utils.js deleted file mode 100644 index c4fe42ba..00000000 --- a/TypeScript/dist/utils.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.sRGBToLinear = function (value) { - var v = value / 255; - if (v <= 0.04045) { - return v / 12.92; - } - else { - return Math.pow((v + 0.055) / 1.055, 2.4); - } -}; -exports.linearTosRGB = function (value) { - var v = Math.max(0, Math.min(1, value)); - if (v <= 0.0031308) { - return Math.round(v * 12.92 * 255 + 0.5); - } - else { - return Math.round((1.055 * Math.pow(v, 1 / 2.4) - 0.055) * 255 + 0.5); - } -}; -exports.sign = function (n) { return (n < 0 ? -1 : 1); }; -exports.signPow = function (val, exp) { return exports.sign(val) * Math.pow(Math.abs(val), exp); }; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/TypeScript/dist/utils.js.map b/TypeScript/dist/utils.js.map deleted file mode 100644 index adec2174..00000000 --- a/TypeScript/dist/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAAa,QAAA,YAAY,GAAG,UAAC,KAAa;IACxC,IAAI,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC;IACpB,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC;QACjB,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC;IACnB,CAAC;IAAC,IAAI,CAAC,CAAC;QACN,MAAM,CAAC,IAAI,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