Skip to content

Commit

Permalink
Merge a71edfa into 0fce9f7
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Jul 5, 2020
2 parents 0fce9f7 + a71edfa commit 994ecb3
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 29 deletions.
1 change: 1 addition & 0 deletions modules/images/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"point cloud",
"PLY"
],
"types": "src/index.d.ts",
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"esnext": "dist/es6/index.js",
Expand Down
5 changes: 0 additions & 5 deletions modules/images/src/image-loader.worker.js

This file was deleted.

5 changes: 3 additions & 2 deletions modules/images/src/image-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {encodeImage} from './lib/encoders/encode-image';
export default {
name: 'Images',
extensions: ['jpeg'],
encode: encodeImage,
DEFAULT_OPTIONS: {
// TODO encode is broken, fix...
encode: async (image, options) => await encodeImage(image, options.type),
options: {
type: 'png'
}
};
41 changes: 41 additions & 0 deletions modules/images/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// TYPES
export {ImageDataType, ImageType, ImageTypeEnum} from './types';

// LOADERS AND WRITERS
export {default as ImageLoader} from './image-loader';
export {default as ImageWriter} from './image-writer';

// IMAGE CATEGORY API

// Binary Image API
export {getBinaryImageMetadata} from './lib/category-api/binary-image-api';

// Parsed Image API
export {isImageTypeSupported, getDefaultImageType} from './lib/category-api/image-type';

export {
isImage,
getImageType,
getImageSize,
getImageData
} from './lib/category-api/parsed-image-api';

// Texture Loading API
export {loadImage} from './lib/texture-api/load-image';
export {loadImageArray} from './lib/texture-api/load-image-array';
export {loadImageCube} from './lib/texture-api/load-image-cube';

// DEPRECATED
// TODO - Remove in V3

export {default as HTMLImageLoader} from './image-loader';

import {getDefaultImageType} from './lib/category-api/image-type';

export function getSupportedImageType(imageType?);

export {
isBinaryImage,
getBinaryImageMIMEType,
getBinaryImageSize
} from './lib/deprecated/binary-image-api-deprecated';
9 changes: 3 additions & 6 deletions modules/images/src/lib/category-api/image-type.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* Image type string used to control or determine the type of images returned from ImageLoader
*/
export type ImageType = 'imagebitmap' | 'image' | 'data';
import {ImageTypeEnum} from '../../types';

/**
* Checks if a loaders.gl image type is supported
* @param type image type string
*/
export function isImageTypeSupported(type: ImageType): boolean;
export function isImageTypeSupported(type: string): boolean;

/**
* Returns the "most performant" supported image type on this platform
* @returns image type string
*/
export function getDefaultImageType(): ImageType;
export function getDefaultImageType(): ImageTypeEnum;
6 changes: 6 additions & 0 deletions modules/images/src/lib/category-api/parsed-image-api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {ImageType, ImageTypeEnum, ImageDataType} from '../../types';

export function isImage(image: ImageType): boolean;
export function getImageType(image: ImageType, throwOnError?: boolean): ImageTypeEnum;
export function getImageData(image: ImageType): ImageDataType | ImageData;
export function getImageSize(image: ImageType): {width: number; height: number};
3 changes: 1 addition & 2 deletions modules/images/src/lib/category-api/parsed-image-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export function getImageData(image) {
canvas.width = image.width;
canvas.height = image.height;
context.drawImage(image, 0, 0);
const imageData = context.getImageData(0, 0, image.width, image.height);
return imageData;
return context.getImageData(0, 0, image.width, image.height);
default:
return assert(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DEPRECATED METHODS

/** @deprecated Use getBinaryImageMetadata() instead */
export function isBinaryImage(arrayBuffer: any, mimeType: any): any;
export function isBinaryImage(arrayBuffer: any, mimeType?: any): any;
/** @deprecated Use getBinaryImageMetadata() instead */
export function getBinaryImageMIMEType(arrayBuffer: any): any;
/** @deprecated Use getBinaryImageMetadata() instead */
Expand Down
12 changes: 5 additions & 7 deletions modules/images/src/lib/encoders/encode-image.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

/**
* Returns data bytes representing a compressed image in PNG or JPG format,
* This data can be saved using file system (f) methods or used in a request.
* @param image - Image or Canvas
* @param mimeType
* TODO clean up
* param {String} opt.type='png' - png, jpg or image/png, image/jpg are valid
* param {String} opt.dataURI= - Whether to include a data URI header
* @param image - ImageBitmap Image or Canvas
* @param options
* param opt.type='png' - png, jpg or image/png, image/jpg are valid
* param mimeType= - Whether to include a data URI header
*/
export function encodeImage(image: any, mimeType: string): ArrayBuffer;
export function encodeImage(image: any, type?: string): string;
20 changes: 20 additions & 0 deletions modules/images/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/**
* data images
*/
export type ImageDataType = {
data: Uint8Array;
width: number;
height: number;
compressed?: boolean;
}

/**
* Supported Image Types
*/
export type ImageType = ImageBitmap | typeof Image | ImageDataType;

/**
* Image type string used to control or determine the type of images returned from ImageLoader
*/
export type ImageTypeEnum = 'imagebitmap' | 'image' | 'data';
4 changes: 4 additions & 0 deletions modules/images/test/lib/category-api/parsed-image-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ test('Image Category#isImage', async t => {
for (const image of IMAGES) {
t.equals(isImage(image), true, 'isImage recognizes image');
}
// @ts-ignore
t.equals(isImage('not an image'), false, 'isImage rejects non-image');
t.end();
});
Expand All @@ -72,6 +73,7 @@ test('Image Category#getImageType', async t => {
for (const image of IMAGES) {
t.ok(IMAGE_TYPES.includes(getImageType(image)), 'returns a valid image type');
}
// @ts-ignore
t.throws(() => getImageType('not an image'));
t.end();
});
Expand All @@ -81,6 +83,7 @@ test('Image Category#getImageSize', async t => {
for (const image of IMAGES) {
t.equals(typeof getImageSize(image), 'object', 'returns size object');
}
// @ts-ignore
t.throws(() => getImageSize('unknown type'));
t.end();
});
Expand All @@ -90,6 +93,7 @@ test('Image Category#getImageData', async t => {
for (const image of IMAGES) {
t.equals(typeof getImageData(image), 'object', 'returns data');
}
// @ts-ignore
t.throws(() => getImageData('not an image'));
t.end();
});
5 changes: 4 additions & 1 deletion modules/loader-utils/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export type LoaderObject = {
* A writer defintion that can be used with `@loaders.gl/core` functions
*/
export type WriterObject = {
encode();
options: object;
deprecatedOptions?: object;

encode(data: any, options: object): Promise<any>; // TODO Promise<ArrayBuffer>
};

export type LoaderContext = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"pre-push": "^0.1.1",
"reify": "^0.19.1",
"source-map-support": "^0.5.12",
"typescript": "^3.7.4"
"typescript": "^3.9.6"
},
"pre-commit": "pre-commit",
"pre-push": "pre-push",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10118,10 +10118,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.7.4:
version "3.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.5.tgz#586f0dba300cde8be52dd1ac4f7e1009c1b13f36"
integrity sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

typical@^2.6.1:
version "2.6.1"
Expand Down

0 comments on commit 994ecb3

Please sign in to comment.