Commit b4060cfc authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[piexwasm] Improve Closure markup and related code

Rename ImagePreviewResponseData => PiexPreviewImageData. Change raw =>
RAW in comments. Mark private ImageBuffer function @private and rename
the this.details member => this.details_ for consistency.

Add @param to onAbort error, use !PiexWasmImageResult, cast the Module
type !PiexWasmModule. No change in behavior, no new tests.

Bug: 1132695
Change-Id: Ia20783dc000b7a3d40537e3811aba6f6f6f6a7c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2433745
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811107}
parent d9caf50c
...@@ -7,32 +7,35 @@ console.log('[PiexLoader] loaded'); ...@@ -7,32 +7,35 @@ console.log('[PiexLoader] loaded');
/** /**
* Declares the piex-wasm Module interface. The Module has many interfaces * Declares the piex-wasm Module interface. The Module has many interfaces
* but only declare the parts required for PIEX work. * but only declare the parts required for PIEX work.
*
* @typedef {{ * @typedef {{
* calledRun: boolean, * calledRun: boolean,
* onAbort: function((!Error|string)):undefined, * onAbort: function((!Error|string)):undefined,
* HEAP8: !Uint8Array, * HEAP8: !Uint8Array,
* _malloc: function(number):number, * _malloc: function(number):number,
* _free: function(number):undefined, * _free: function(number):undefined,
* image: function(number, number):PiexWasmImageResult * image: function(number, number):!PiexWasmImageResult
* }} * }}
*/ */
let PiexWasmModule; let PiexWasmModule;
/** /**
* |window| var Module defined in page <script src='piex/piex.js.wasm'>. * |window| var Module defined in page <script src='piex/piex.js.wasm'>.
* @type {PiexWasmModule} * @type {!PiexWasmModule}
*/ */
const PiexModule = window['Module'] || {}; const PiexModule = /** @type {!PiexWasmModule} */ (window['Module']) || {};
/** /**
* Set true only if the Module.onAbort() handler is called. * Set true if the Module.onAbort() handler is called.
* @type {boolean} * @type {boolean}
*/ */
let piexFailed = false; let piexFailed = false;
/** /**
* Installs an (Emscripten) Module.onAbort handler. Record that the Module * Installs an (Emscripten) Module.onAbort handler. Record that the Module
* has failed and re-throw the error. * has failed in piexFailed and re-throw the error.
*
* @param {!Error|string} error
* @throws {!Error|string} * @throws {!Error|string}
*/ */
PiexModule.onAbort = (error) => { PiexModule.onAbort = (error) => {
...@@ -65,10 +68,10 @@ function piexModuleFailed() { ...@@ -65,10 +68,10 @@ function piexModuleFailed() {
* ifd: ?string * ifd: ?string
* }} * }}
*/ */
let ImagePreviewResponseData; let PiexPreviewImageData;
/** /**
* @param {!ImagePreviewResponseData} data The preview image data. * @param {!PiexPreviewImageData} data The extracted preview image data.
* @constructor * @constructor
* @struct * @struct
*/ */
...@@ -163,12 +166,12 @@ function readSourceData(source) { ...@@ -163,12 +166,12 @@ function readSourceData(source) {
} }
/** /**
* Piex wasm extacts the preview image metadata from a raw image. The preview * Piex-wasm extracts the "preview image" from a RAW image. The preview image
* image |format| is either 0 (JPEG) or 1 (RGB), and has a |colorSpace| (sRGB * |format| is either 0 (JPEG), or 1 (RGB), and has a JEITA EXIF |colorSpace|
* or AdobeRGB1998) and a JEITA EXIF image |orientation|. * (sRGB or AdobeRGB1998) and a JEITA EXIF image |orientation|.
* *
* An RGB format preview image has both |width| and |height|, but JPEG format * An RGB format preview image has both |width| and |height|, but JPEG format
* previews have neither (piex wasm C++ does not parse/decode JPEG). * previews have neither (piex-wasm C++ does not parse/decode JPEG).
* *
* The |offset| to, and |length| of, the preview image relative to the source * The |offset| to, and |length| of, the preview image relative to the source
* data is indicated by those fields. They are positive > 0. Note: the values * data is indicated by those fields. They are positive > 0. Note: the values
...@@ -187,7 +190,7 @@ function readSourceData(source) { ...@@ -187,7 +190,7 @@ function readSourceData(source) {
let PiexWasmPreviewImageMetadata; let PiexWasmPreviewImageMetadata;
/** /**
* The piex wasm Module.image(<raw image source>,...) API returns |error|, or * The piex-wasm Module.image(<RAW image source>,...) API returns |error|, or
* else the source |preview| and/or |thumbnail| image metadata along with the * else the source |preview| and/or |thumbnail| image metadata along with the
* photographic |details| derived from the RAW image EXIF. * photographic |details| derived from the RAW image EXIF.
* *
...@@ -204,23 +207,21 @@ let PiexWasmPreviewImageMetadata; ...@@ -204,23 +207,21 @@ let PiexWasmPreviewImageMetadata;
let PiexWasmImageResult; let PiexWasmImageResult;
/** /**
* Piex wasm raw image preview image extractor. * Preview Image EXtractor (PIEX).
*/ */
class ImageBuffer { class ImageBuffer {
/** /**
* @param {!ArrayBuffer} buffer - raw image source data. * @param {!ArrayBuffer} buffer - RAW image source data.
*/ */
constructor(buffer) { constructor(buffer) {
/** /**
* @type {!Uint8Array} * @const {!Uint8Array}
* @const
* @private * @private
*/ */
this.source = new Uint8Array(buffer); this.source = new Uint8Array(buffer);
/** /**
* @type {number} * @const {number}
* @const
* @private * @private
*/ */
this.length = buffer.byteLength; this.length = buffer.byteLength;
...@@ -258,10 +259,8 @@ class ImageBuffer { ...@@ -258,10 +259,8 @@ class ImageBuffer {
* the thumbnail image. * the thumbnail image.
* *
* @param {!PiexWasmImageResult} result * @param {!PiexWasmImageResult} result
*
* @throws {!Error} Data access security error. * @throws {!Error} Data access security error.
* * @return {!PiexPreviewImageData}
* @return {!ImagePreviewResponseData}
*/ */
preview(result) { preview(result) {
const preview = result.preview; const preview = result.preview;
...@@ -279,7 +278,7 @@ class ImageBuffer { ...@@ -279,7 +278,7 @@ class ImageBuffer {
return { return {
thumbnail: new Uint8Array(view).buffer, thumbnail: new Uint8Array(view).buffer,
mimeType: 'image/jpeg', mimeType: 'image/jpeg',
ifd: this.details(result, preview.orientation), ifd: this.details_(result, preview.orientation),
orientation: preview.orientation, orientation: preview.orientation,
colorSpace: preview.colorSpace, colorSpace: preview.colorSpace,
}; };
...@@ -289,11 +288,10 @@ class ImageBuffer { ...@@ -289,11 +288,10 @@ class ImageBuffer {
* Returns the thumbnail image. If no thumbnail image was found, returns * Returns the thumbnail image. If no thumbnail image was found, returns
* an empty thumbnail image. * an empty thumbnail image.
* *
* @private
* @param {!PiexWasmImageResult} result * @param {!PiexWasmImageResult} result
*
* @throws {!Error} Data access security error. * @throws {!Error} Data access security error.
* * @return {!PiexPreviewImageData}
* @return {!ImagePreviewResponseData}
*/ */
thumbnail_(result) { thumbnail_(result) {
const thumbnail = result.thumbnail; const thumbnail = result.thumbnail;
...@@ -320,7 +318,7 @@ class ImageBuffer { ...@@ -320,7 +318,7 @@ class ImageBuffer {
return { return {
thumbnail: new Uint8Array(view).buffer, thumbnail: new Uint8Array(view).buffer,
mimeType: 'image/jpeg', mimeType: 'image/jpeg',
ifd: this.details(result, thumbnail.orientation), ifd: this.details_(result, thumbnail.orientation),
orientation: thumbnail.orientation, orientation: thumbnail.orientation,
colorSpace: thumbnail.colorSpace, colorSpace: thumbnail.colorSpace,
}; };
...@@ -330,11 +328,10 @@ class ImageBuffer { ...@@ -330,11 +328,10 @@ class ImageBuffer {
* Returns the RGB thumbnail. If no RGB thumbnail was found, returns * Returns the RGB thumbnail. If no RGB thumbnail was found, returns
* an empty thumbnail image. * an empty thumbnail image.
* *
* @private
* @param {!PiexWasmImageResult} result * @param {!PiexWasmImageResult} result
*
* @throws {!Error} Data access security error. * @throws {!Error} Data access security error.
* * @return {!PiexPreviewImageData}
* @return {!ImagePreviewResponseData}
*/ */
rgb_(result) { rgb_(result) {
const thumbnail = result.thumbnail; const thumbnail = result.thumbnail;
...@@ -414,7 +411,7 @@ class ImageBuffer { ...@@ -414,7 +411,7 @@ class ImageBuffer {
return { return {
thumbnail: bitmap.buffer, thumbnail: bitmap.buffer,
mimeType: 'image/bmp', mimeType: 'image/bmp',
ifd: this.details(result, thumbnail.orientation), ifd: this.details_(result, thumbnail.orientation),
orientation: thumbnail.orientation, orientation: thumbnail.orientation,
colorSpace: thumbnail.colorSpace, colorSpace: thumbnail.colorSpace,
}; };
...@@ -430,7 +427,7 @@ class ImageBuffer { ...@@ -430,7 +427,7 @@ class ImageBuffer {
* @param {number} orientation - image EXIF orientation * @param {number} orientation - image EXIF orientation
* @return {?string} * @return {?string}
*/ */
details(result, orientation) { details_(result, orientation) {
const details = result.details; const details = result.details;
if (!details) { if (!details) {
return null; return null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment