From 1bb77093edbe5b58017c2e327191a38064243b2c Mon Sep 17 00:00:00 2001 From: codedread Date: Sat, 14 Mar 2020 09:54:04 -0700 Subject: [PATCH] Update license info on all webp-shim sources. Provide an example in the top-level README file for bitjs --- README.md | 16 ++++++++++++++++ build/webp-shim/Dockerfile | 5 +---- build/webp-shim/src/webp.c | 11 +++++++++++ build/webp-shim/test/harness.js | 9 +++++++++ image/webp-shim/webp-shim.js | 9 ++++++++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e6891a7..c691f89 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,22 @@ unzipper.update(anArrayBufferWithMoreBytes); unzipper.update(anArrayBufferWithYetMoreBytes); ``` +### bitjs.image + +This namespace includes code for dealing with image formats. It includes a module for converting WebP images into alternative raster graphics formats (PNG/JPG). + +``` +import {convertWebPtoPNG, convertWebPtoJPG} from './bitjs/image/webp-shim/webp-shim.js'; + +// convertWebPtoPNG() takes in an ArrayBuffer containing the bytes of a WebP +// image and returns a Promise that resolves with an ArrayBuffer containing the +// bytes of an equivalent PNG image. +convertWebPtoPNG(webpBuffer).then(pngBuf => { + const pngUrl = URL.createObjectURL(new Blob([pngArr], {type: 'image/png'})); + someImgElement.setAttribute(src, pngUrl); +}); +``` + ## Tests * [bitjs.io tests](https://codedread.github.io/bitjs/tests/io-test.html) diff --git a/build/webp-shim/Dockerfile b/build/webp-shim/Dockerfile index e1ea56f..1501a9a 100644 --- a/build/webp-shim/Dockerfile +++ b/build/webp-shim/Dockerfile @@ -6,9 +6,6 @@ RUN apt-get update && apt-get install -y \ python \ wget -# Put more deps here ... -# RUN apt-get update && apt-get install -y \ - RUN git clone https://github.com/webmproject/libwebp RUN git clone https://github.com/emscripten-core/emsdk.git && \ @@ -18,7 +15,7 @@ RUN git clone https://github.com/emscripten-core/emsdk.git && \ RUN git clone https://github.com/nothings/stb.git -# Figure out how to invoke emsdk/emsdk_env.sh and have it affect PATH. +# TODO: Figure out how to invoke emsdk/emsdk_env.sh and have it affect PATH. ENV PATH="$PATH:/emsdk:/emsdk/node/12.9.1_64bit/bin:/emsdk/upstream/emscripten" COPY . . diff --git a/build/webp-shim/src/webp.c b/build/webp-shim/src/webp.c index 5cbbb45..312c2b7 100644 --- a/build/webp-shim/src/webp.c +++ b/build/webp-shim/src/webp.c @@ -1,3 +1,14 @@ +/** + * webp.c + * + * Provides functionality for decoding a WebP imgae and converting it into + * alternative raster graphics formats (PNG/JPG). + * + * Licensed under the MIT License + * + * Copyright(c) 2020 Google Inc. + */ + #include #include #include "emscripten.h" diff --git a/build/webp-shim/test/harness.js b/build/webp-shim/test/harness.js index d7a0ee6..7eb7493 100644 --- a/build/webp-shim/test/harness.js +++ b/build/webp-shim/test/harness.js @@ -1,3 +1,12 @@ +/** + * harness.js + * + * Example of how to use the webp-shim functions. + * + * Licensed under the MIT License + * + * Copyright(c) 2020 Google Inc. + */ import {convertWebPtoPNG, convertWebPtoJPG} from '../../../image/webp-shim/webp-shim.js'; new Promise((resolve, reject) => { diff --git a/image/webp-shim/webp-shim.js b/image/webp-shim/webp-shim.js index 538bd49..21b444a 100644 --- a/image/webp-shim/webp-shim.js +++ b/image/webp-shim/webp-shim.js @@ -1,5 +1,12 @@ /** - * + * webp-shim.js + * + * Loads in the WASM module and exposes methods to convert a WebP image into + * alternative raster graphics formats (PNG/JPG). + * + * Licensed under the MIT License + * + * Copyright(c) 2020 Google Inc. */ const url = import.meta.url;