@itwin/core-frontend 3.2.0-dev.16 → 3.2.0-dev.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/ImageUtil.d.ts +4 -2
- package/lib/cjs/ImageUtil.d.ts.map +1 -1
- package/lib/cjs/ImageUtil.js +8 -4
- package/lib/cjs/ImageUtil.js.map +1 -1
- package/lib/esm/ImageUtil.d.ts +4 -2
- package/lib/esm/ImageUtil.d.ts.map +1 -1
- package/lib/esm/ImageUtil.js +8 -4
- package/lib/esm/ImageUtil.js.map +1 -1
- package/package.json +20 -20
package/lib/cjs/ImageUtil.d.ts
CHANGED
|
@@ -43,18 +43,20 @@ export declare function getImageSourceFormatForMimeType(mimeType: string): Image
|
|
|
43
43
|
export declare function imageElementFromImageSource(source: ImageSource): Promise<HTMLImageElement>;
|
|
44
44
|
/** Create an html Image element from a URL.
|
|
45
45
|
* @param url The URL pointing to the image data.
|
|
46
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
46
47
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.
|
|
47
48
|
* @see tryImageElementFromUrl.
|
|
48
49
|
* @public
|
|
49
50
|
*/
|
|
50
|
-
export declare function imageElementFromUrl(url: string): Promise<HTMLImageElement>;
|
|
51
|
+
export declare function imageElementFromUrl(url: string, skipCrossOriginCheck?: boolean): Promise<HTMLImageElement>;
|
|
51
52
|
/** Try to create an html Image element from a URL.
|
|
52
53
|
* @param url The URL pointing to the image data.
|
|
54
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
53
55
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.
|
|
54
56
|
* @see imageElementFromUrl
|
|
55
57
|
* @public
|
|
56
58
|
*/
|
|
57
|
-
export declare function tryImageElementFromUrl(url: string): Promise<HTMLImageElement | undefined>;
|
|
59
|
+
export declare function tryImageElementFromUrl(url: string, skipCrossOriginCheck?: boolean): Promise<HTMLImageElement | undefined>;
|
|
58
60
|
/**
|
|
59
61
|
* Extract the dimensions of the jpeg or png data encoded in an ImageSource.
|
|
60
62
|
* @param source The ImageSource containing the binary jpeg or png data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageUtil.d.ts","sourceRoot":"","sources":["../../src/ImageUtil.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA8BtC;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,UAAoB,EAAE,QAAQ,SAAY,GAAG,iBAAiB,CAoBpK;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,GAAE,OAAc,GAAG,iBAAiB,GAAG,SAAS,CA8BrH;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAyB,GAAG,WAAW,GAAG,SAAS,CA0CvH;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAWxE;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAO/F;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGhG;AAED
|
|
1
|
+
{"version":3,"file":"ImageUtil.d.ts","sourceRoot":"","sources":["../../src/ImageUtil.ts"],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AC,CAGxF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,UAAO,GAAG,MAAM,GAAG,SAAS,CAIrG;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,UAAO,GAAG,MAAM,GAAG,SAAS,CAO3G;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAU7E;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,SAAM,GAAG,QAAQ,CAUnF;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,SAAQ,EAAE,qBAAqB,SAAM,GAAG,MAAM,GAAG,SAAS,CAexI"}
|
package/lib/cjs/ImageUtil.js
CHANGED
|
@@ -175,15 +175,18 @@ async function imageElementFromImageSource(source) {
|
|
|
175
175
|
exports.imageElementFromImageSource = imageElementFromImageSource;
|
|
176
176
|
/** Create an html Image element from a URL.
|
|
177
177
|
* @param url The URL pointing to the image data.
|
|
178
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
178
179
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.
|
|
179
180
|
* @see tryImageElementFromUrl.
|
|
180
181
|
* @public
|
|
181
182
|
*/
|
|
182
|
-
async function imageElementFromUrl(url) {
|
|
183
|
+
async function imageElementFromUrl(url, skipCrossOriginCheck = false) {
|
|
183
184
|
// We must set crossorigin property so that images loaded from same origin can be used with texImage2d.
|
|
184
185
|
// We must do that outside of the promise constructor or it won't work, for reasons.
|
|
185
186
|
const image = new Image();
|
|
186
|
-
|
|
187
|
+
if (!skipCrossOriginCheck) {
|
|
188
|
+
image.crossOrigin = "anonymous";
|
|
189
|
+
}
|
|
187
190
|
return new Promise((resolve, reject) => {
|
|
188
191
|
image.onload = () => resolve(image);
|
|
189
192
|
// The "error" produced by Image is not an Error. It looks like an Event, but isn't one.
|
|
@@ -194,13 +197,14 @@ async function imageElementFromUrl(url) {
|
|
|
194
197
|
exports.imageElementFromUrl = imageElementFromUrl;
|
|
195
198
|
/** Try to create an html Image element from a URL.
|
|
196
199
|
* @param url The URL pointing to the image data.
|
|
200
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
197
201
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.
|
|
198
202
|
* @see imageElementFromUrl
|
|
199
203
|
* @public
|
|
200
204
|
*/
|
|
201
|
-
async function tryImageElementFromUrl(url) {
|
|
205
|
+
async function tryImageElementFromUrl(url, skipCrossOriginCheck = false) {
|
|
202
206
|
try {
|
|
203
|
-
return await imageElementFromUrl(url);
|
|
207
|
+
return await imageElementFromUrl(url, skipCrossOriginCheck);
|
|
204
208
|
}
|
|
205
209
|
catch {
|
|
206
210
|
return undefined;
|
package/lib/cjs/ImageUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageUtil.js","sourceRoot":"","sources":["../../src/ImageUtil.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAA+C;AAC/C,oDAAoG;AACpG,yCAAsC;AAStC,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAE/C,SAAS,aAAa,CAAC,IAAU,EAAE,GAAe,EAAE,GAAW;IAC7D,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,GAAG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A0F;IAC1F,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,GAAG,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW,CAAC;IACvC,MAAM,WAAW,GAAG,KAAK,CAAC;IAC1B,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,GAAG,CAAC;IACjD,MAAM,KAAK,GAAG,IAAI,GAAG,UAAU,CAAC;IAChC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC;IAClD,MAAM,MAAM,GAAG,GAAG,GAAG,WAAW,CAAC;IACjC,OAAO,IAAI,mBAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC;AAVD,kDAUC;AAED;;;;;;GAMG;AACH,SAAgB,2BAA2B,CAAC,MAAyB,EAAE,QAAQ,GAAG,KAAK,EAAE,qBAAqB,GAAG,GAAG;IAClH,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,wBAAwB;IAChD,MAAM,iBAAiB,GAAG,CAAC,CAAC,CAAC,8BAA8B;IAC3D,IAAI,OAAO,GAAG,GAAG,CAAC,CAAC,2BAA2B;IAE9C,OAAO,OAAO,GAAG,qBAAqB,EAAE;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACrD,yCAAyC;QACzC,IAAI,IAAI,CAAC,MAAM,GAAG,iBAAiB,GAAG,QAAQ;YAC5C,OAAO,IAAI,CAAC;QAEd,OAAO,IAAI,UAAU,CAAC;KACvB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAfD,kEAeC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Rendering\r\n */\r\n\r\nimport { Point2d } from \"@itwin/core-geometry\";\r\nimport { ImageBuffer, ImageBufferFormat, ImageSource, ImageSourceFormat } from \"@itwin/core-common\";\r\nimport { ViewRect } from \"./ViewRect\";\r\n\r\ninterface Rgba {\r\n r: number;\r\n g: number;\r\n b: number;\r\n a: number;\r\n}\r\n\r\nconst scratchRgba = { r: 0, g: 0, b: 0, a: 0 };\r\n\r\nfunction rgbaFromAlpha(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = rgba.g = rgba.b = rgba.a = src[idx];\r\n return idx + 1;\r\n}\r\n\r\nfunction rgbaFromRgb(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = src[idx + 0];\r\n rgba.g = src[idx + 1];\r\n rgba.b = src[idx + 2];\r\n rgba.a = 255;\r\n return idx + 3;\r\n}\r\n\r\nfunction rgbaFromRgba(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgbaFromRgb(rgba, src, idx);\r\n rgba.a = src[idx + 3];\r\n return idx + 4;\r\n}\r\n\r\n/** Resize a canvas to a desired size. The final size will be targetSize plus barSize. The original canvas is left untouched and a new, resized canvas with potential side bars is returned.\r\n * @param canvasIn the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) to resize.\r\n * @param targetSize the desired new size for the canvas image.\r\n * @param barSize total size of side bars to add to the image in width and height; defaults to (0, 0). For example, if you specify (2, 0), a 1 pixel side bar will be added to the left and right sides of the resized image. If an odd dimension is specified, the left or upper side of the image will be one pixel larger than the opposite side. For example, if you specify (1, 0), a 1 pixel side bar will be added to the left side of the image and a 0 pixel side bar will be added to the right side of the image.\r\n * @param barStyle CSS style string to apply to any side bars; defaults to \"#C0C0C0\", which is silver.\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the resized image and any requested side bars.\r\n * @public\r\n */\r\nexport function canvasToResizedCanvasWithBars(canvasIn: HTMLCanvasElement, targetSize: Point2d, barSize = new Point2d(0, 0), barStyle = \"#C0C0C0\"): HTMLCanvasElement {\r\n const canvasOut = document.createElement(\"canvas\");\r\n canvasOut.width = targetSize.x + barSize.x;\r\n canvasOut.height = targetSize.y + barSize.y;\r\n\r\n let adjustImageX = barSize.x / 2;\r\n let adjustImageY = barSize.y / 2;\r\n\r\n if (1 === barSize.x % 2) {\r\n adjustImageX += 0.5;\r\n }\r\n if (1 === barSize.y % 2) {\r\n adjustImageY += 0.5;\r\n }\r\n\r\n const context = canvasOut.getContext(\"2d\")!;\r\n context.fillStyle = barStyle;\r\n context.fillRect(0, 0, canvasOut.width, canvasOut.height);\r\n context.drawImage(canvasIn, adjustImageX, adjustImageY, targetSize.x, targetSize.y);\r\n return canvasOut;\r\n}\r\n\r\n/** Create a canvas element with the same dimensions and contents as an image buffer.\r\n * @param buffer the source [[ImageBuffer]] object from which the [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object will be constructed.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the contents of the source image buffer, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function imageBufferToCanvas(buffer: ImageBuffer, preserveAlpha: boolean = true): HTMLCanvasElement | undefined {\r\n const canvas = document.createElement(\"canvas\");\r\n if (null === canvas)\r\n return undefined;\r\n\r\n canvas.width = buffer.width;\r\n canvas.height = buffer.height;\r\n\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.createImageData(buffer.width, buffer.height);\r\n const extractRgba = ImageBufferFormat.Alpha === buffer.format ? rgbaFromAlpha : (ImageBufferFormat.Rgb === buffer.format ? rgbaFromRgb : rgbaFromRgba);\r\n\r\n const bufferData = buffer.data;\r\n let i = 0;\r\n let j = 0;\r\n const rgba = scratchRgba;\r\n while (i < bufferData.length) {\r\n i = extractRgba(rgba, bufferData, i);\r\n imageData.data[j + 0] = rgba.r;\r\n imageData.data[j + 1] = rgba.g;\r\n imageData.data[j + 2] = rgba.b;\r\n imageData.data[j + 3] = preserveAlpha ? rgba.a : 0xff;\r\n j += 4;\r\n }\r\n\r\n context.putImageData(imageData, 0, 0);\r\n return canvas;\r\n}\r\n\r\n/** Create an ImageBuffer in the specified format with the same dimensions and contents as a canvas.\r\n * @param canvas the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object from which the [[ImageBuffer]] object will be constructed.\r\n * @param format the desired format of the created ImageBuffer; defaults to [[ImageBufferFormat.Rgba]].\r\n * @returns an [[ImageBuffer]] object containing the contents of the source canvas, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function canvasToImageBuffer(canvas: HTMLCanvasElement, format = ImageBufferFormat.Rgba): ImageBuffer | undefined {\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.getImageData(0, 0, canvas.width, canvas.height);\r\n\r\n let imageBufferData: Uint8Array | undefined;\r\n\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length);\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData = new Uint8Array((imageData.data.length / 4) * 3);\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length / 4);\r\n }\r\n\r\n if (undefined === imageBufferData)\r\n return undefined;\r\n\r\n let i = 0;\r\n let j = 0;\r\n while (i < imageData.data.length) {\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n imageBufferData[j + 3] = imageData.data[i + 3];\r\n j += 4;\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n j += 3;\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData[j] = imageData.data[i + 3];\r\n j++;\r\n }\r\n i += 4;\r\n }\r\n\r\n return ImageBuffer.create(imageBufferData, format, canvas.width);\r\n}\r\n\r\n/** Get a string describing the mime type associated with an ImageSource format.\r\n * @public\r\n */\r\nexport function getImageSourceMimeType(format: ImageSourceFormat): string {\r\n\r\n switch (format) {\r\n case ImageSourceFormat.Jpeg:\r\n return \"image/jpeg\";\r\n case ImageSourceFormat.Png:\r\n return \"image/png\";\r\n case ImageSourceFormat.Svg:\r\n return \"image/svg+xml;charset=utf-8\";\r\n }\r\n return \"\";\r\n}\r\n\r\n/** Get the ImageSourceFormat corresponding to the mime type string, or undefined if the string does not identify a supported ImageSourceFormat.\r\n * @public\r\n */\r\nexport function getImageSourceFormatForMimeType(mimeType: string): ImageSourceFormat | undefined {\r\n switch (mimeType) {\r\n case \"image/jpeg\": return ImageSourceFormat.Jpeg;\r\n case \"image/png\": return ImageSourceFormat.Png;\r\n case \"image/svg+xml;charset=utf-8\": return ImageSourceFormat.Svg;\r\n default: return undefined;\r\n }\r\n}\r\n\r\n/** Extract an html Image element from a binary jpeg or png.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise which resolves to an HTMLImageElement containing the uncompressed bitmap image in RGBA format.\r\n * @public\r\n */\r\nexport async function imageElementFromImageSource(source: ImageSource): Promise<HTMLImageElement> {\r\n const blob = new Blob([source.data], { type: getImageSourceMimeType(source.format) });\r\n return imageElementFromUrl(URL.createObjectURL(blob));\r\n}\r\n\r\n/** Create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.\r\n * @see tryImageElementFromUrl.\r\n * @public\r\n */\r\nexport async function imageElementFromUrl(url: string): Promise<HTMLImageElement> {\r\n // We must set crossorigin property so that images loaded from same origin can be used with texImage2d.\r\n // We must do that outside of the promise constructor or it won't work, for reasons.\r\n const image = new Image();\r\n image.crossOrigin = \"anonymous\";\r\n return new Promise((resolve: (image: HTMLImageElement) => void, reject) => {\r\n image.onload = () => resolve(image);\r\n\r\n // The \"error\" produced by Image is not an Error. It looks like an Event, but isn't one.\r\n image.onerror = () => reject(new Error(\"Failed to create image from url\"));\r\n image.src = url;\r\n });\r\n}\r\n\r\n/** Try to create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.\r\n * @see imageElementFromUrl\r\n * @public\r\n */\r\nexport async function tryImageElementFromUrl(url: string): Promise<HTMLImageElement | undefined> {\r\n try {\r\n return await imageElementFromUrl(url);\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n/**\r\n * Extract the dimensions of the jpeg or png data encoded in an ImageSource.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise resolving to a Point2d of which x corresponds to the integer width of the uncompressed bitmap and y to the height.\r\n * @public\r\n */\r\nexport async function extractImageSourceDimensions(source: ImageSource): Promise<Point2d> {\r\n const image = await imageElementFromImageSource(source);\r\n return new Point2d(image.naturalWidth, image.naturalHeight);\r\n}\r\n\r\n/**\r\n * Produces a data url in \"image/png\" format from the contents of an ImageBuffer.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a data url as a string suitable for setting as the `src` property of an HTMLImageElement, or undefined if the url could not be created.\r\n * @public\r\n */\r\nexport function imageBufferToPngDataUrl(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n // The default format (and the only format required to be supported) for toDataUrl() is \"image/png\".\r\n const canvas = imageBufferToCanvas(buffer, preserveAlpha);\r\n return undefined !== canvas ? canvas.toDataURL() : undefined;\r\n}\r\n\r\n/**\r\n * Converts the contents of an ImageBuffer to PNG format.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a base64-encoded string representing the image as a PNG, or undefined if the conversion failed.\r\n * @public\r\n */\r\nexport function imageBufferToBase64EncodedPng(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n const urlPrefix = \"data:image/png;base64,\";\r\n const url = imageBufferToPngDataUrl(buffer, preserveAlpha);\r\n if (undefined === url || !url.startsWith(urlPrefix))\r\n return undefined;\r\n\r\n return url.substring(urlPrefix.length);\r\n}\r\n\r\n/** Open an image specified as a data URL in a new window or tab. Works around differences between browsers and Electron.\r\n * @param url The base64-encoded image URL.\r\n * @param title An optional title to apply to the new window.\r\n * @beta\r\n */\r\nexport function openImageDataUrlInNewWindow(url: string, title?: string): void {\r\n const win = window.open();\r\n if (null === win)\r\n return;\r\n\r\n const div = win.document.createElement(\"div\");\r\n div.innerHTML = `<img src='${url}'/>`;\r\n win.document.body.append(div);\r\n if (undefined !== title)\r\n win.document.title = title;\r\n}\r\n\r\n/** Determine the maximum [[ViewRect]] that can be fitted and centered in specified ViewRect given a required aspect ratio.\r\n * @param viewRect The rectangle in which the returned rectangle is to be centered and fitted.\r\n * @param aspectRatio Ratio of width to height.\r\n * @returns A ViewRect centered in the input rectangle.\r\n * @public\r\n */\r\nexport function getCenteredViewRect(viewRect: ViewRect, aspectRatio = 1.4): ViewRect {\r\n // Determine scale that ensures ability to return an image with the prescribed aspectRatio\r\n const scale = Math.min(viewRect.width / aspectRatio, viewRect.height);\r\n const finalWidth = scale * aspectRatio;\r\n const finalHeight = scale;\r\n const left = (viewRect.width - finalWidth) / 2.0;\r\n const right = left + finalWidth;\r\n const top = (viewRect.height - finalHeight) / 2.0;\r\n const bottom = top + finalHeight;\r\n return new ViewRect(left, top, right, bottom);\r\n}\r\n\r\n/** Produce a jpeg compressed to no more than specified bytes and of no less than specified quality.\r\n * @param canvas Canvas containing the image to be compressed.\r\n * @param maxBytes Maximum size of output jpeg in bytes.\r\n * @param minCompressionQuality The minimum acceptable image quality as a number between 0 (lowest quality) and 1 (highest quality).\r\n * @returns A [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for the image, or `undefined` if the compression and size constraints could not be met.\r\n * @public\r\n */\r\nexport function getCompressedJpegFromCanvas(canvas: HTMLCanvasElement, maxBytes = 60000, minCompressionQuality = 0.1): string | undefined {\r\n const decrements = 0.1; // Decrements of quality\r\n const bytesPerCharacter = 2; // Assume 16-bit per character\r\n let quality = 1.0; // JPEG Compression quality\r\n\r\n while (quality > minCompressionQuality) {\r\n const data = canvas.toDataURL(\"image/jpeg\", quality);\r\n // If we are less than 60 Kb, we are good\r\n if (data.length * bytesPerCharacter < maxBytes)\r\n return data;\r\n\r\n quality -= decrements;\r\n }\r\n\r\n return undefined;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ImageUtil.js","sourceRoot":"","sources":["../../src/ImageUtil.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAA+C;AAC/C,oDAAoG;AACpG,yCAAsC;AAStC,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAE/C,SAAS,aAAa,CAAC,IAAU,EAAE,GAAe,EAAE,GAAW;IAC7D,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,GAAG,GAAG,CAAC,CAAC;AACjB,CAAC;A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---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Rendering\r\n */\r\n\r\nimport { Point2d } from \"@itwin/core-geometry\";\r\nimport { ImageBuffer, ImageBufferFormat, ImageSource, ImageSourceFormat } from \"@itwin/core-common\";\r\nimport { ViewRect } from \"./ViewRect\";\r\n\r\ninterface Rgba {\r\n r: number;\r\n g: number;\r\n b: number;\r\n a: number;\r\n}\r\n\r\nconst scratchRgba = { r: 0, g: 0, b: 0, a: 0 };\r\n\r\nfunction rgbaFromAlpha(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = rgba.g = rgba.b = rgba.a = src[idx];\r\n return idx + 1;\r\n}\r\n\r\nfunction rgbaFromRgb(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = src[idx + 0];\r\n rgba.g = src[idx + 1];\r\n rgba.b = src[idx + 2];\r\n rgba.a = 255;\r\n return idx + 3;\r\n}\r\n\r\nfunction rgbaFromRgba(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgbaFromRgb(rgba, src, idx);\r\n rgba.a = src[idx + 3];\r\n return idx + 4;\r\n}\r\n\r\n/** Resize a canvas to a desired size. The final size will be targetSize plus barSize. The original canvas is left untouched and a new, resized canvas with potential side bars is returned.\r\n * @param canvasIn the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) to resize.\r\n * @param targetSize the desired new size for the canvas image.\r\n * @param barSize total size of side bars to add to the image in width and height; defaults to (0, 0). For example, if you specify (2, 0), a 1 pixel side bar will be added to the left and right sides of the resized image. If an odd dimension is specified, the left or upper side of the image will be one pixel larger than the opposite side. For example, if you specify (1, 0), a 1 pixel side bar will be added to the left side of the image and a 0 pixel side bar will be added to the right side of the image.\r\n * @param barStyle CSS style string to apply to any side bars; defaults to \"#C0C0C0\", which is silver.\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the resized image and any requested side bars.\r\n * @public\r\n */\r\nexport function canvasToResizedCanvasWithBars(canvasIn: HTMLCanvasElement, targetSize: Point2d, barSize = new Point2d(0, 0), barStyle = \"#C0C0C0\"): HTMLCanvasElement {\r\n const canvasOut = document.createElement(\"canvas\");\r\n canvasOut.width = targetSize.x + barSize.x;\r\n canvasOut.height = targetSize.y + barSize.y;\r\n\r\n let adjustImageX = barSize.x / 2;\r\n let adjustImageY = barSize.y / 2;\r\n\r\n if (1 === barSize.x % 2) {\r\n adjustImageX += 0.5;\r\n }\r\n if (1 === barSize.y % 2) {\r\n adjustImageY += 0.5;\r\n }\r\n\r\n const context = canvasOut.getContext(\"2d\")!;\r\n context.fillStyle = barStyle;\r\n context.fillRect(0, 0, canvasOut.width, canvasOut.height);\r\n context.drawImage(canvasIn, adjustImageX, adjustImageY, targetSize.x, targetSize.y);\r\n return canvasOut;\r\n}\r\n\r\n/** Create a canvas element with the same dimensions and contents as an image buffer.\r\n * @param buffer the source [[ImageBuffer]] object from which the [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object will be constructed.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the contents of the source image buffer, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function imageBufferToCanvas(buffer: ImageBuffer, preserveAlpha: boolean = true): HTMLCanvasElement | undefined {\r\n const canvas = document.createElement(\"canvas\");\r\n if (null === canvas)\r\n return undefined;\r\n\r\n canvas.width = buffer.width;\r\n canvas.height = buffer.height;\r\n\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.createImageData(buffer.width, buffer.height);\r\n const extractRgba = ImageBufferFormat.Alpha === buffer.format ? rgbaFromAlpha : (ImageBufferFormat.Rgb === buffer.format ? rgbaFromRgb : rgbaFromRgba);\r\n\r\n const bufferData = buffer.data;\r\n let i = 0;\r\n let j = 0;\r\n const rgba = scratchRgba;\r\n while (i < bufferData.length) {\r\n i = extractRgba(rgba, bufferData, i);\r\n imageData.data[j + 0] = rgba.r;\r\n imageData.data[j + 1] = rgba.g;\r\n imageData.data[j + 2] = rgba.b;\r\n imageData.data[j + 3] = preserveAlpha ? rgba.a : 0xff;\r\n j += 4;\r\n }\r\n\r\n context.putImageData(imageData, 0, 0);\r\n return canvas;\r\n}\r\n\r\n/** Create an ImageBuffer in the specified format with the same dimensions and contents as a canvas.\r\n * @param canvas the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object from which the [[ImageBuffer]] object will be constructed.\r\n * @param format the desired format of the created ImageBuffer; defaults to [[ImageBufferFormat.Rgba]].\r\n * @returns an [[ImageBuffer]] object containing the contents of the source canvas, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function canvasToImageBuffer(canvas: HTMLCanvasElement, format = ImageBufferFormat.Rgba): ImageBuffer | undefined {\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.getImageData(0, 0, canvas.width, canvas.height);\r\n\r\n let imageBufferData: Uint8Array | undefined;\r\n\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length);\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData = new Uint8Array((imageData.data.length / 4) * 3);\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length / 4);\r\n }\r\n\r\n if (undefined === imageBufferData)\r\n return undefined;\r\n\r\n let i = 0;\r\n let j = 0;\r\n while (i < imageData.data.length) {\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n imageBufferData[j + 3] = imageData.data[i + 3];\r\n j += 4;\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n j += 3;\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData[j] = imageData.data[i + 3];\r\n j++;\r\n }\r\n i += 4;\r\n }\r\n\r\n return ImageBuffer.create(imageBufferData, format, canvas.width);\r\n}\r\n\r\n/** Get a string describing the mime type associated with an ImageSource format.\r\n * @public\r\n */\r\nexport function getImageSourceMimeType(format: ImageSourceFormat): string {\r\n\r\n switch (format) {\r\n case ImageSourceFormat.Jpeg:\r\n return \"image/jpeg\";\r\n case ImageSourceFormat.Png:\r\n return \"image/png\";\r\n case ImageSourceFormat.Svg:\r\n return \"image/svg+xml;charset=utf-8\";\r\n }\r\n return \"\";\r\n}\r\n\r\n/** Get the ImageSourceFormat corresponding to the mime type string, or undefined if the string does not identify a supported ImageSourceFormat.\r\n * @public\r\n */\r\nexport function getImageSourceFormatForMimeType(mimeType: string): ImageSourceFormat | undefined {\r\n switch (mimeType) {\r\n case \"image/jpeg\": return ImageSourceFormat.Jpeg;\r\n case \"image/png\": return ImageSourceFormat.Png;\r\n case \"image/svg+xml;charset=utf-8\": return ImageSourceFormat.Svg;\r\n default: return undefined;\r\n }\r\n}\r\n\r\n/** Extract an html Image element from a binary jpeg or png.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise which resolves to an HTMLImageElement containing the uncompressed bitmap image in RGBA format.\r\n * @public\r\n */\r\nexport async function imageElementFromImageSource(source: ImageSource): Promise<HTMLImageElement> {\r\n const blob = new Blob([source.data], { type: getImageSourceMimeType(source.format) });\r\n return imageElementFromUrl(URL.createObjectURL(blob));\r\n}\r\n\r\n/** Create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.\r\n * @see tryImageElementFromUrl.\r\n * @public\r\n */\r\nexport async function imageElementFromUrl(url: string, skipCrossOriginCheck = false): Promise<HTMLImageElement> {\r\n // We must set crossorigin property so that images loaded from same origin can be used with texImage2d.\r\n // We must do that outside of the promise constructor or it won't work, for reasons.\r\n const image = new Image();\r\n if (!skipCrossOriginCheck) {\r\n image.crossOrigin = \"anonymous\";\r\n }\r\n return new Promise((resolve: (image: HTMLImageElement) => void, reject) => {\r\n image.onload = () => resolve(image);\r\n\r\n // The \"error\" produced by Image is not an Error. It looks like an Event, but isn't one.\r\n image.onerror = () => reject(new Error(\"Failed to create image from url\"));\r\n image.src = url;\r\n });\r\n}\r\n\r\n/** Try to create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.\r\n * @see imageElementFromUrl\r\n * @public\r\n */\r\nexport async function tryImageElementFromUrl(url: string, skipCrossOriginCheck = false): Promise<HTMLImageElement | undefined> {\r\n try {\r\n return await imageElementFromUrl(url, skipCrossOriginCheck);\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n/**\r\n * Extract the dimensions of the jpeg or png data encoded in an ImageSource.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise resolving to a Point2d of which x corresponds to the integer width of the uncompressed bitmap and y to the height.\r\n * @public\r\n */\r\nexport async function extractImageSourceDimensions(source: ImageSource): Promise<Point2d> {\r\n const image = await imageElementFromImageSource(source);\r\n return new Point2d(image.naturalWidth, image.naturalHeight);\r\n}\r\n\r\n/**\r\n * Produces a data url in \"image/png\" format from the contents of an ImageBuffer.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a data url as a string suitable for setting as the `src` property of an HTMLImageElement, or undefined if the url could not be created.\r\n * @public\r\n */\r\nexport function imageBufferToPngDataUrl(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n // The default format (and the only format required to be supported) for toDataUrl() is \"image/png\".\r\n const canvas = imageBufferToCanvas(buffer, preserveAlpha);\r\n return undefined !== canvas ? canvas.toDataURL() : undefined;\r\n}\r\n\r\n/**\r\n * Converts the contents of an ImageBuffer to PNG format.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a base64-encoded string representing the image as a PNG, or undefined if the conversion failed.\r\n * @public\r\n */\r\nexport function imageBufferToBase64EncodedPng(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n const urlPrefix = \"data:image/png;base64,\";\r\n const url = imageBufferToPngDataUrl(buffer, preserveAlpha);\r\n if (undefined === url || !url.startsWith(urlPrefix))\r\n return undefined;\r\n\r\n return url.substring(urlPrefix.length);\r\n}\r\n\r\n/** Open an image specified as a data URL in a new window or tab. Works around differences between browsers and Electron.\r\n * @param url The base64-encoded image URL.\r\n * @param title An optional title to apply to the new window.\r\n * @beta\r\n */\r\nexport function openImageDataUrlInNewWindow(url: string, title?: string): void {\r\n const win = window.open();\r\n if (null === win)\r\n return;\r\n\r\n const div = win.document.createElement(\"div\");\r\n div.innerHTML = `<img src='${url}'/>`;\r\n win.document.body.append(div);\r\n if (undefined !== title)\r\n win.document.title = title;\r\n}\r\n\r\n/** Determine the maximum [[ViewRect]] that can be fitted and centered in specified ViewRect given a required aspect ratio.\r\n * @param viewRect The rectangle in which the returned rectangle is to be centered and fitted.\r\n * @param aspectRatio Ratio of width to height.\r\n * @returns A ViewRect centered in the input rectangle.\r\n * @public\r\n */\r\nexport function getCenteredViewRect(viewRect: ViewRect, aspectRatio = 1.4): ViewRect {\r\n // Determine scale that ensures ability to return an image with the prescribed aspectRatio\r\n const scale = Math.min(viewRect.width / aspectRatio, viewRect.height);\r\n const finalWidth = scale * aspectRatio;\r\n const finalHeight = scale;\r\n const left = (viewRect.width - finalWidth) / 2.0;\r\n const right = left + finalWidth;\r\n const top = (viewRect.height - finalHeight) / 2.0;\r\n const bottom = top + finalHeight;\r\n return new ViewRect(left, top, right, bottom);\r\n}\r\n\r\n/** Produce a jpeg compressed to no more than specified bytes and of no less than specified quality.\r\n * @param canvas Canvas containing the image to be compressed.\r\n * @param maxBytes Maximum size of output jpeg in bytes.\r\n * @param minCompressionQuality The minimum acceptable image quality as a number between 0 (lowest quality) and 1 (highest quality).\r\n * @returns A [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for the image, or `undefined` if the compression and size constraints could not be met.\r\n * @public\r\n */\r\nexport function getCompressedJpegFromCanvas(canvas: HTMLCanvasElement, maxBytes = 60000, minCompressionQuality = 0.1): string | undefined {\r\n const decrements = 0.1; // Decrements of quality\r\n const bytesPerCharacter = 2; // Assume 16-bit per character\r\n let quality = 1.0; // JPEG Compression quality\r\n\r\n while (quality > minCompressionQuality) {\r\n const data = canvas.toDataURL(\"image/jpeg\", quality);\r\n // If we are less than 60 Kb, we are good\r\n if (data.length * bytesPerCharacter < maxBytes)\r\n return data;\r\n\r\n quality -= decrements;\r\n }\r\n\r\n return undefined;\r\n}\r\n"]}
|
package/lib/esm/ImageUtil.d.ts
CHANGED
|
@@ -43,18 +43,20 @@ export declare function getImageSourceFormatForMimeType(mimeType: string): Image
|
|
|
43
43
|
export declare function imageElementFromImageSource(source: ImageSource): Promise<HTMLImageElement>;
|
|
44
44
|
/** Create an html Image element from a URL.
|
|
45
45
|
* @param url The URL pointing to the image data.
|
|
46
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
46
47
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.
|
|
47
48
|
* @see tryImageElementFromUrl.
|
|
48
49
|
* @public
|
|
49
50
|
*/
|
|
50
|
-
export declare function imageElementFromUrl(url: string): Promise<HTMLImageElement>;
|
|
51
|
+
export declare function imageElementFromUrl(url: string, skipCrossOriginCheck?: boolean): Promise<HTMLImageElement>;
|
|
51
52
|
/** Try to create an html Image element from a URL.
|
|
52
53
|
* @param url The URL pointing to the image data.
|
|
54
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
53
55
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.
|
|
54
56
|
* @see imageElementFromUrl
|
|
55
57
|
* @public
|
|
56
58
|
*/
|
|
57
|
-
export declare function tryImageElementFromUrl(url: string): Promise<HTMLImageElement | undefined>;
|
|
59
|
+
export declare function tryImageElementFromUrl(url: string, skipCrossOriginCheck?: boolean): Promise<HTMLImageElement | undefined>;
|
|
58
60
|
/**
|
|
59
61
|
* Extract the dimensions of the jpeg or png data encoded in an ImageSource.
|
|
60
62
|
* @param source The ImageSource containing the binary jpeg or png data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageUtil.d.ts","sourceRoot":"","sources":["../../src/ImageUtil.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA8BtC;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,UAAoB,EAAE,QAAQ,SAAY,GAAG,iBAAiB,CAoBpK;AAED;;;;;GA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|
|
|
166
166
|
}
|
|
167
167
|
/** Create an html Image element from a URL.
|
|
168
168
|
* @param url The URL pointing to the image data.
|
|
169
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
169
170
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.
|
|
170
171
|
* @see tryImageElementFromUrl.
|
|
171
172
|
* @public
|
|
172
173
|
*/
|
|
173
|
-
export async function imageElementFromUrl(url) {
|
|
174
|
+
export async function imageElementFromUrl(url, skipCrossOriginCheck = false) {
|
|
174
175
|
// We must set crossorigin property so that images loaded from same origin can be used with texImage2d.
|
|
175
176
|
// We must do that outside of the promise constructor or it won't work, for reasons.
|
|
176
177
|
const image = new Image();
|
|
177
|
-
|
|
178
|
+
if (!skipCrossOriginCheck) {
|
|
179
|
+
image.crossOrigin = "anonymous";
|
|
180
|
+
}
|
|
178
181
|
return new Promise((resolve, reject) => {
|
|
179
182
|
image.onload = () => resolve(image);
|
|
180
183
|
// The "error" produced by Image is not an Error. It looks like an Event, but isn't one.
|
|
@@ -184,13 +187,14 @@ export async function imageElementFromUrl(url) {
|
|
|
184
187
|
}
|
|
185
188
|
/** Try to create an html Image element from a URL.
|
|
186
189
|
* @param url The URL pointing to the image data.
|
|
190
|
+
* @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.
|
|
187
191
|
* @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.
|
|
188
192
|
* @see imageElementFromUrl
|
|
189
193
|
* @public
|
|
190
194
|
*/
|
|
191
|
-
export async function tryImageElementFromUrl(url) {
|
|
195
|
+
export async function tryImageElementFromUrl(url, skipCrossOriginCheck = false) {
|
|
192
196
|
try {
|
|
193
|
-
return await imageElementFromUrl(url);
|
|
197
|
+
return await imageElementFromUrl(url, skipCrossOriginCheck);
|
|
194
198
|
}
|
|
195
199
|
catch {
|
|
196
200
|
return undefined;
|
package/lib/esm/ImageUtil.js.map
CH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K,EAAE,qBAAqB,GAAG,GAAG;IAClH,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,wBAAwB;IAChD,MAAM,iBAAiB,GAAG,CAAC,CAAC,CAAC,8BAA8B;IAC3D,IAAI,OAAO,GAAG,GAAG,CAAC,CAAC,2BAA2B;IAE9C,OAAO,OAAO,GAAG,qBAAqB,EAAE;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACrD,yCAAyC;QACzC,IAAI,IAAI,CAAC,MAAM,GAAG,iBAAiB,GAAG,QAAQ;YAC5C,OAAO,IAAI,CAAC;QAEd,OAAO,IAAI,UAAU,CAAC;KACvB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Rendering\r\n */\r\n\r\nimport { Point2d } from \"@itwin/core-geometry\";\r\nimport { ImageBuffer, ImageBufferFormat, ImageSource, ImageSourceFormat } from \"@itwin/core-common\";\r\nimport { ViewRect } from \"./ViewRect\";\r\n\r\ninterface Rgba {\r\n r: number;\r\n g: number;\r\n b: number;\r\n a: number;\r\n}\r\n\r\nconst scratchRgba = { r: 0, g: 0, b: 0, a: 0 };\r\n\r\nfunction rgbaFromAlpha(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = rgba.g = rgba.b = rgba.a = src[idx];\r\n return idx + 1;\r\n}\r\n\r\nfunction rgbaFromRgb(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = src[idx + 0];\r\n rgba.g = src[idx + 1];\r\n rgba.b = src[idx + 2];\r\n rgba.a = 255;\r\n return idx + 3;\r\n}\r\n\r\nfunction rgbaFromRgba(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgbaFromRgb(rgba, src, idx);\r\n rgba.a = src[idx + 3];\r\n return idx + 4;\r\n}\r\n\r\n/** Resize a canvas to a desired size. The final size will be targetSize plus barSize. The original canvas is left untouched and a new, resized canvas with potential side bars is returned.\r\n * @param canvasIn the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) to resize.\r\n * @param targetSize the desired new size for the canvas image.\r\n * @param barSize total size of side bars to add to the image in width and height; defaults to (0, 0). For example, if you specify (2, 0), a 1 pixel side bar will be added to the left and right sides of the resized image. If an odd dimension is specified, the left or upper side of the image will be one pixel larger than the opposite side. For example, if you specify (1, 0), a 1 pixel side bar will be added to the left side of the image and a 0 pixel side bar will be added to the right side of the image.\r\n * @param barStyle CSS style string to apply to any side bars; defaults to \"#C0C0C0\", which is silver.\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the resized image and any requested side bars.\r\n * @public\r\n */\r\nexport function canvasToResizedCanvasWithBars(canvasIn: HTMLCanvasElement, targetSize: Point2d, barSize = new Point2d(0, 0), barStyle = \"#C0C0C0\"): HTMLCanvasElement {\r\n const canvasOut = document.createElement(\"canvas\");\r\n canvasOut.width = targetSize.x + barSize.x;\r\n canvasOut.height = targetSize.y + barSize.y;\r\n\r\n let adjustImageX = barSize.x / 2;\r\n let adjustImageY = barSize.y / 2;\r\n\r\n if (1 === barSize.x % 2) {\r\n adjustImageX += 0.5;\r\n }\r\n if (1 === barSize.y % 2) {\r\n adjustImageY += 0.5;\r\n }\r\n\r\n const context = canvasOut.getContext(\"2d\")!;\r\n context.fillStyle = barStyle;\r\n context.fillRect(0, 0, canvasOut.width, canvasOut.height);\r\n context.drawImage(canvasIn, adjustImageX, adjustImageY, targetSize.x, targetSize.y);\r\n return canvasOut;\r\n}\r\n\r\n/** Create a canvas element with the same dimensions and contents as an image buffer.\r\n * @param buffer the source [[ImageBuffer]] object from which the [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object will be constructed.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the contents of the source image buffer, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function imageBufferToCanvas(buffer: ImageBuffer, preserveAlpha: boolean = true): HTMLCanvasElement | undefined {\r\n const canvas = document.createElement(\"canvas\");\r\n if (null === canvas)\r\n return undefined;\r\n\r\n canvas.width = buffer.width;\r\n canvas.height = buffer.height;\r\n\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.createImageData(buffer.width, buffer.height);\r\n const extractRgba = ImageBufferFormat.Alpha === buffer.format ? rgbaFromAlpha : (ImageBufferFormat.Rgb === buffer.format ? rgbaFromRgb : rgbaFromRgba);\r\n\r\n const bufferData = buffer.data;\r\n let i = 0;\r\n let j = 0;\r\n const rgba = scratchRgba;\r\n while (i < bufferData.length) {\r\n i = extractRgba(rgba, bufferData, i);\r\n imageData.data[j + 0] = rgba.r;\r\n imageData.data[j + 1] = rgba.g;\r\n imageData.data[j + 2] = rgba.b;\r\n imageData.data[j + 3] = preserveAlpha ? rgba.a : 0xff;\r\n j += 4;\r\n }\r\n\r\n context.putImageData(imageData, 0, 0);\r\n return canvas;\r\n}\r\n\r\n/** Create an ImageBuffer in the specified format with the same dimensions and contents as a canvas.\r\n * @param canvas the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object from which the [[ImageBuffer]] object will be constructed.\r\n * @param format the desired format of the created ImageBuffer; defaults to [[ImageBufferFormat.Rgba]].\r\n * @returns an [[ImageBuffer]] object containing the contents of the source canvas, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function canvasToImageBuffer(canvas: HTMLCanvasElement, format = ImageBufferFormat.Rgba): ImageBuffer | undefined {\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.getImageData(0, 0, canvas.width, canvas.height);\r\n\r\n let imageBufferData: Uint8Array | undefined;\r\n\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length);\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData = new Uint8Array((imageData.data.length / 4) * 3);\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length / 4);\r\n }\r\n\r\n if (undefined === imageBufferData)\r\n return undefined;\r\n\r\n let i = 0;\r\n let j = 0;\r\n while (i < imageData.data.length) {\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n imageBufferData[j + 3] = imageData.data[i + 3];\r\n j += 4;\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n j += 3;\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData[j] = imageData.data[i + 3];\r\n j++;\r\n }\r\n i += 4;\r\n }\r\n\r\n return ImageBuffer.create(imageBufferData, format, canvas.width);\r\n}\r\n\r\n/** Get a string describing the mime type associated with an ImageSource format.\r\n * @public\r\n */\r\nexport function getImageSourceMimeType(format: ImageSourceFormat): string {\r\n\r\n switch (format) {\r\n case ImageSourceFormat.Jpeg:\r\n return \"image/jpeg\";\r\n case ImageSourceFormat.Png:\r\n return \"image/png\";\r\n case ImageSourceFormat.Svg:\r\n return \"image/svg+xml;charset=utf-8\";\r\n }\r\n return \"\";\r\n}\r\n\r\n/** Get the ImageSourceFormat corresponding to the mime type string, or undefined if the string does not identify a supported ImageSourceFormat.\r\n * @public\r\n */\r\nexport function getImageSourceFormatForMimeType(mimeType: string): ImageSourceFormat | undefined {\r\n switch (mimeType) {\r\n case \"image/jpeg\": return ImageSourceFormat.Jpeg;\r\n case \"image/png\": return ImageSourceFormat.Png;\r\n case \"image/svg+xml;charset=utf-8\": return ImageSourceFormat.Svg;\r\n default: return undefined;\r\n }\r\n}\r\n\r\n/** Extract an html Image element from a binary jpeg or png.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise which resolves to an HTMLImageElement containing the uncompressed bitmap image in RGBA format.\r\n * @public\r\n */\r\nexport async function imageElementFromImageSource(source: ImageSource): Promise<HTMLImageElement> {\r\n const blob = new Blob([source.data], { type: getImageSourceMimeType(source.format) });\r\n return imageElementFromUrl(URL.createObjectURL(blob));\r\n}\r\n\r\n/** Create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.\r\n * @see tryImageElementFromUrl.\r\n * @public\r\n */\r\nexport async function imageElementFromUrl(url: string): Promise<HTMLImageElement> {\r\n // We must set crossorigin property so that images loaded from same origin can be used with texImage2d.\r\n // We must do that outside of the promise constructor or it won't work, for reasons.\r\n const image = new Image();\r\n image.crossOrigin = \"anonymous\";\r\n return new Promise((resolve: (image: HTMLImageElement) => void, reject) => {\r\n image.onload = () => resolve(image);\r\n\r\n // The \"error\" produced by Image is not an Error. It looks like an Event, but isn't one.\r\n image.onerror = () => reject(new Error(\"Failed to create image from url\"));\r\n image.src = url;\r\n });\r\n}\r\n\r\n/** Try to create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.\r\n * @see imageElementFromUrl\r\n * @public\r\n */\r\nexport async function tryImageElementFromUrl(url: string): Promise<HTMLImageElement | undefined> {\r\n try {\r\n return await imageElementFromUrl(url);\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n/**\r\n * Extract the dimensions of the jpeg or png data encoded in an ImageSource.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise resolving to a Point2d of which x corresponds to the integer width of the uncompressed bitmap and y to the height.\r\n * @public\r\n */\r\nexport async function extractImageSourceDimensions(source: ImageSource): Promise<Point2d> {\r\n const image = await imageElementFromImageSource(source);\r\n return new Point2d(image.naturalWidth, image.naturalHeight);\r\n}\r\n\r\n/**\r\n * Produces a data url in \"image/png\" format from the contents of an ImageBuffer.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a data url as a string suitable for setting as the `src` property of an HTMLImageElement, or undefined if the url could not be created.\r\n * @public\r\n */\r\nexport function imageBufferToPngDataUrl(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n // The default format (and the only format required to be supported) for toDataUrl() is \"image/png\".\r\n const canvas = imageBufferToCanvas(buffer, preserveAlpha);\r\n return undefined !== canvas ? canvas.toDataURL() : undefined;\r\n}\r\n\r\n/**\r\n * Converts the contents of an ImageBuffer to PNG format.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a base64-encoded string representing the image as a PNG, or undefined if the conversion failed.\r\n * @public\r\n */\r\nexport function imageBufferToBase64EncodedPng(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n const urlPrefix = \"data:image/png;base64,\";\r\n const url = imageBufferToPngDataUrl(buffer, preserveAlpha);\r\n if (undefined === url || !url.startsWith(urlPrefix))\r\n return undefined;\r\n\r\n return url.substring(urlPrefix.length);\r\n}\r\n\r\n/** Open an image specified as a data URL in a new window or tab. Works around differences between browsers and Electron.\r\n * @param url The base64-encoded image URL.\r\n * @param title An optional title to apply to the new window.\r\n * @beta\r\n */\r\nexport function openImageDataUrlInNewWindow(url: string, title?: string): void {\r\n const win = window.open();\r\n if (null === win)\r\n return;\r\n\r\n const div = win.document.createElement(\"div\");\r\n div.innerHTML = `<img src='${url}'/>`;\r\n win.document.body.append(div);\r\n if (undefined !== title)\r\n win.document.title = title;\r\n}\r\n\r\n/** Determine the maximum [[ViewRect]] that can be fitted and centered in specified ViewRect given a required aspect ratio.\r\n * @param viewRect The rectangle in which the returned rectangle is to be centered and fitted.\r\n * @param aspectRatio Ratio of width to height.\r\n * @returns A ViewRect centered in the input rectangle.\r\n * @public\r\n */\r\nexport function getCenteredViewRect(viewRect: ViewRect, aspectRatio = 1.4): ViewRect {\r\n // Determine scale that ensures ability to return an image with the prescribed aspectRatio\r\n const scale = Math.min(viewRect.width / aspectRatio, viewRect.height);\r\n const finalWidth = scale * aspectRatio;\r\n const finalHeight = scale;\r\n const left = (viewRect.width - finalWidth) / 2.0;\r\n const right = left + finalWidth;\r\n const top = (viewRect.height - finalHeight) / 2.0;\r\n const bottom = top + finalHeight;\r\n return new ViewRect(left, top, right, bottom);\r\n}\r\n\r\n/** Produce a jpeg compressed to no more than specified bytes and of no less than specified quality.\r\n * @param canvas Canvas containing the image to be compressed.\r\n * @param maxBytes Maximum size of output jpeg in bytes.\r\n * @param minCompressionQuality The minimum acceptable image quality as a number between 0 (lowest quality) and 1 (highest quality).\r\n * @returns A [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for the image, or `undefined` if the compression and size constraints could not be met.\r\n * @public\r\n */\r\nexport function getCompressedJpegFromCanvas(canvas: HTMLCanvasElement, maxBytes = 60000, minCompressionQuality = 0.1): string | undefined {\r\n const decrements = 0.1; // Decrements of quality\r\n const bytesPerCharacter = 2; // Assume 16-bit per character\r\n let quality = 1.0; // JPEG Compression quality\r\n\r\n while (quality > minCompressionQuality) {\r\n const data = canvas.toDataURL(\"image/jpeg\", quality);\r\n // If we are less than 60 Kb, we are good\r\n if (data.length * bytesPerCharacter < maxBytes)\r\n return data;\r\n\r\n quality -= decrements;\r\n }\r\n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E,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAyB,EAAE,QAAQ,GAAG,KAAK,EAAE,qBAAqB,GAAG,GAAG;IAClH,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,wBAAwB;IAChD,MAAM,iBAAiB,GAAG,CAAC,CAAC,CAAC,8BAA8B;IAC3D,IAAI,OAAO,GAAG,GAAG,CAAC,CAAC,2BAA2B;IAE9C,OAAO,OAAO,GAAG,qBAAqB,EAAE;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACrD,yCAAyC;QACzC,IAAI,IAAI,CAAC,MAAM,GAAG,iBAAiB,GAAG,QAAQ;YAC5C,OAAO,IAAI,CAAC;QAEd,OAAO,IAAI,UAAU,CAAC;KACvB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Rendering\r\n */\r\n\r\nimport { Point2d } from \"@itwin/core-geometry\";\r\nimport { ImageBuffer, ImageBufferFormat, ImageSource, ImageSourceFormat } from \"@itwin/core-common\";\r\nimport { ViewRect } from \"./ViewRect\";\r\n\r\ninterface Rgba {\r\n r: number;\r\n g: number;\r\n b: number;\r\n a: number;\r\n}\r\n\r\nconst scratchRgba = { r: 0, g: 0, b: 0, a: 0 };\r\n\r\nfunction rgbaFromAlpha(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = rgba.g = rgba.b = rgba.a = src[idx];\r\n return idx + 1;\r\n}\r\n\r\nfunction rgbaFromRgb(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgba.r = src[idx + 0];\r\n rgba.g = src[idx + 1];\r\n rgba.b = src[idx + 2];\r\n rgba.a = 255;\r\n return idx + 3;\r\n}\r\n\r\nfunction rgbaFromRgba(rgba: Rgba, src: Uint8Array, idx: number): number {\r\n rgbaFromRgb(rgba, src, idx);\r\n rgba.a = src[idx + 3];\r\n return idx + 4;\r\n}\r\n\r\n/** Resize a canvas to a desired size. The final size will be targetSize plus barSize. The original canvas is left untouched and a new, resized canvas with potential side bars is returned.\r\n * @param canvasIn the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) to resize.\r\n * @param targetSize the desired new size for the canvas image.\r\n * @param barSize total size of side bars to add to the image in width and height; defaults to (0, 0). For example, if you specify (2, 0), a 1 pixel side bar will be added to the left and right sides of the resized image. If an odd dimension is specified, the left or upper side of the image will be one pixel larger than the opposite side. For example, if you specify (1, 0), a 1 pixel side bar will be added to the left side of the image and a 0 pixel side bar will be added to the right side of the image.\r\n * @param barStyle CSS style string to apply to any side bars; defaults to \"#C0C0C0\", which is silver.\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the resized image and any requested side bars.\r\n * @public\r\n */\r\nexport function canvasToResizedCanvasWithBars(canvasIn: HTMLCanvasElement, targetSize: Point2d, barSize = new Point2d(0, 0), barStyle = \"#C0C0C0\"): HTMLCanvasElement {\r\n const canvasOut = document.createElement(\"canvas\");\r\n canvasOut.width = targetSize.x + barSize.x;\r\n canvasOut.height = targetSize.y + barSize.y;\r\n\r\n let adjustImageX = barSize.x / 2;\r\n let adjustImageY = barSize.y / 2;\r\n\r\n if (1 === barSize.x % 2) {\r\n adjustImageX += 0.5;\r\n }\r\n if (1 === barSize.y % 2) {\r\n adjustImageY += 0.5;\r\n }\r\n\r\n const context = canvasOut.getContext(\"2d\")!;\r\n context.fillStyle = barStyle;\r\n context.fillRect(0, 0, canvasOut.width, canvasOut.height);\r\n context.drawImage(canvasIn, adjustImageX, adjustImageY, targetSize.x, targetSize.y);\r\n return canvasOut;\r\n}\r\n\r\n/** Create a canvas element with the same dimensions and contents as an image buffer.\r\n * @param buffer the source [[ImageBuffer]] object from which the [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object will be constructed.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns an [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object containing the contents of the source image buffer, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function imageBufferToCanvas(buffer: ImageBuffer, preserveAlpha: boolean = true): HTMLCanvasElement | undefined {\r\n const canvas = document.createElement(\"canvas\");\r\n if (null === canvas)\r\n return undefined;\r\n\r\n canvas.width = buffer.width;\r\n canvas.height = buffer.height;\r\n\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.createImageData(buffer.width, buffer.height);\r\n const extractRgba = ImageBufferFormat.Alpha === buffer.format ? rgbaFromAlpha : (ImageBufferFormat.Rgb === buffer.format ? rgbaFromRgb : rgbaFromRgba);\r\n\r\n const bufferData = buffer.data;\r\n let i = 0;\r\n let j = 0;\r\n const rgba = scratchRgba;\r\n while (i < bufferData.length) {\r\n i = extractRgba(rgba, bufferData, i);\r\n imageData.data[j + 0] = rgba.r;\r\n imageData.data[j + 1] = rgba.g;\r\n imageData.data[j + 2] = rgba.b;\r\n imageData.data[j + 3] = preserveAlpha ? rgba.a : 0xff;\r\n j += 4;\r\n }\r\n\r\n context.putImageData(imageData, 0, 0);\r\n return canvas;\r\n}\r\n\r\n/** Create an ImageBuffer in the specified format with the same dimensions and contents as a canvas.\r\n * @param canvas the source [HTMLCanvasElement](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement) object from which the [[ImageBuffer]] object will be constructed.\r\n * @param format the desired format of the created ImageBuffer; defaults to [[ImageBufferFormat.Rgba]].\r\n * @returns an [[ImageBuffer]] object containing the contents of the source canvas, or undefined if the conversion fails.\r\n * @public\r\n */\r\nexport function canvasToImageBuffer(canvas: HTMLCanvasElement, format = ImageBufferFormat.Rgba): ImageBuffer | undefined {\r\n const context = canvas.getContext(\"2d\");\r\n if (null === context)\r\n return undefined;\r\n\r\n const imageData = context.getImageData(0, 0, canvas.width, canvas.height);\r\n\r\n let imageBufferData: Uint8Array | undefined;\r\n\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length);\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData = new Uint8Array((imageData.data.length / 4) * 3);\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData = new Uint8Array(imageData.data.length / 4);\r\n }\r\n\r\n if (undefined === imageBufferData)\r\n return undefined;\r\n\r\n let i = 0;\r\n let j = 0;\r\n while (i < imageData.data.length) {\r\n if (ImageBufferFormat.Rgba === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n imageBufferData[j + 3] = imageData.data[i + 3];\r\n j += 4;\r\n } else if (ImageBufferFormat.Rgb === format) {\r\n imageBufferData[j + 0] = imageData.data[i + 0];\r\n imageBufferData[j + 1] = imageData.data[i + 1];\r\n imageBufferData[j + 2] = imageData.data[i + 2];\r\n j += 3;\r\n } else if (ImageBufferFormat.Alpha === format) {\r\n imageBufferData[j] = imageData.data[i + 3];\r\n j++;\r\n }\r\n i += 4;\r\n }\r\n\r\n return ImageBuffer.create(imageBufferData, format, canvas.width);\r\n}\r\n\r\n/** Get a string describing the mime type associated with an ImageSource format.\r\n * @public\r\n */\r\nexport function getImageSourceMimeType(format: ImageSourceFormat): string {\r\n\r\n switch (format) {\r\n case ImageSourceFormat.Jpeg:\r\n return \"image/jpeg\";\r\n case ImageSourceFormat.Png:\r\n return \"image/png\";\r\n case ImageSourceFormat.Svg:\r\n return \"image/svg+xml;charset=utf-8\";\r\n }\r\n return \"\";\r\n}\r\n\r\n/** Get the ImageSourceFormat corresponding to the mime type string, or undefined if the string does not identify a supported ImageSourceFormat.\r\n * @public\r\n */\r\nexport function getImageSourceFormatForMimeType(mimeType: string): ImageSourceFormat | undefined {\r\n switch (mimeType) {\r\n case \"image/jpeg\": return ImageSourceFormat.Jpeg;\r\n case \"image/png\": return ImageSourceFormat.Png;\r\n case \"image/svg+xml;charset=utf-8\": return ImageSourceFormat.Svg;\r\n default: return undefined;\r\n }\r\n}\r\n\r\n/** Extract an html Image element from a binary jpeg or png.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise which resolves to an HTMLImageElement containing the uncompressed bitmap image in RGBA format.\r\n * @public\r\n */\r\nexport async function imageElementFromImageSource(source: ImageSource): Promise<HTMLImageElement> {\r\n const blob = new Blob([source.data], { type: getImageSourceMimeType(source.format) });\r\n return imageElementFromUrl(URL.createObjectURL(blob));\r\n}\r\n\r\n/** Create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL.\r\n * @see tryImageElementFromUrl.\r\n * @public\r\n */\r\nexport async function imageElementFromUrl(url: string, skipCrossOriginCheck = false): Promise<HTMLImageElement> {\r\n // We must set crossorigin property so that images loaded from same origin can be used with texImage2d.\r\n // We must do that outside of the promise constructor or it won't work, for reasons.\r\n const image = new Image();\r\n if (!skipCrossOriginCheck) {\r\n image.crossOrigin = \"anonymous\";\r\n }\r\n return new Promise((resolve: (image: HTMLImageElement) => void, reject) => {\r\n image.onload = () => resolve(image);\r\n\r\n // The \"error\" produced by Image is not an Error. It looks like an Event, but isn't one.\r\n image.onerror = () => reject(new Error(\"Failed to create image from url\"));\r\n image.src = url;\r\n });\r\n}\r\n\r\n/** Try to create an html Image element from a URL.\r\n * @param url The URL pointing to the image data.\r\n * @param skipCrossOriginCheck Set this to true to allow an image from a different origin than the web app to load. Default is false.\r\n * @returns A Promise resolving to an HTMLImageElement when the image data has been loaded from the URL, or to `undefined` if an exception occurred.\r\n * @see imageElementFromUrl\r\n * @public\r\n */\r\nexport async function tryImageElementFromUrl(url: string, skipCrossOriginCheck = false): Promise<HTMLImageElement | undefined> {\r\n try {\r\n return await imageElementFromUrl(url, skipCrossOriginCheck);\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n/**\r\n * Extract the dimensions of the jpeg or png data encoded in an ImageSource.\r\n * @param source The ImageSource containing the binary jpeg or png data.\r\n * @returns a Promise resolving to a Point2d of which x corresponds to the integer width of the uncompressed bitmap and y to the height.\r\n * @public\r\n */\r\nexport async function extractImageSourceDimensions(source: ImageSource): Promise<Point2d> {\r\n const image = await imageElementFromImageSource(source);\r\n return new Point2d(image.naturalWidth, image.naturalHeight);\r\n}\r\n\r\n/**\r\n * Produces a data url in \"image/png\" format from the contents of an ImageBuffer.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a data url as a string suitable for setting as the `src` property of an HTMLImageElement, or undefined if the url could not be created.\r\n * @public\r\n */\r\nexport function imageBufferToPngDataUrl(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n // The default format (and the only format required to be supported) for toDataUrl() is \"image/png\".\r\n const canvas = imageBufferToCanvas(buffer, preserveAlpha);\r\n return undefined !== canvas ? canvas.toDataURL() : undefined;\r\n}\r\n\r\n/**\r\n * Converts the contents of an ImageBuffer to PNG format.\r\n * @param buffer The ImageBuffer, of any format.\r\n * @param preserveAlpha If false, the alpha channel will be set to 255 (fully opaque). This is recommended when converting an already-blended image (e.g., one obtained from [[Viewport.readImageBuffer]]).\r\n * @returns a base64-encoded string representing the image as a PNG, or undefined if the conversion failed.\r\n * @public\r\n */\r\nexport function imageBufferToBase64EncodedPng(buffer: ImageBuffer, preserveAlpha = true): string | undefined {\r\n const urlPrefix = \"data:image/png;base64,\";\r\n const url = imageBufferToPngDataUrl(buffer, preserveAlpha);\r\n if (undefined === url || !url.startsWith(urlPrefix))\r\n return undefined;\r\n\r\n return url.substring(urlPrefix.length);\r\n}\r\n\r\n/** Open an image specified as a data URL in a new window or tab. Works around differences between browsers and Electron.\r\n * @param url The base64-encoded image URL.\r\n * @param title An optional title to apply to the new window.\r\n * @beta\r\n */\r\nexport function openImageDataUrlInNewWindow(url: string, title?: string): void {\r\n const win = window.open();\r\n if (null === win)\r\n return;\r\n\r\n const div = win.document.createElement(\"div\");\r\n div.innerHTML = `<img src='${url}'/>`;\r\n win.document.body.append(div);\r\n if (undefined !== title)\r\n win.document.title = title;\r\n}\r\n\r\n/** Determine the maximum [[ViewRect]] that can be fitted and centered in specified ViewRect given a required aspect ratio.\r\n * @param viewRect The rectangle in which the returned rectangle is to be centered and fitted.\r\n * @param aspectRatio Ratio of width to height.\r\n * @returns A ViewRect centered in the input rectangle.\r\n * @public\r\n */\r\nexport function getCenteredViewRect(viewRect: ViewRect, aspectRatio = 1.4): ViewRect {\r\n // Determine scale that ensures ability to return an image with the prescribed aspectRatio\r\n const scale = Math.min(viewRect.width / aspectRatio, viewRect.height);\r\n const finalWidth = scale * aspectRatio;\r\n const finalHeight = scale;\r\n const left = (viewRect.width - finalWidth) / 2.0;\r\n const right = left + finalWidth;\r\n const top = (viewRect.height - finalHeight) / 2.0;\r\n const bottom = top + finalHeight;\r\n return new ViewRect(left, top, right, bottom);\r\n}\r\n\r\n/** Produce a jpeg compressed to no more than specified bytes and of no less than specified quality.\r\n * @param canvas Canvas containing the image to be compressed.\r\n * @param maxBytes Maximum size of output jpeg in bytes.\r\n * @param minCompressionQuality The minimum acceptable image quality as a number between 0 (lowest quality) and 1 (highest quality).\r\n * @returns A [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) for the image, or `undefined` if the compression and size constraints could not be met.\r\n * @public\r\n */\r\nexport function getCompressedJpegFromCanvas(canvas: HTMLCanvasElement, maxBytes = 60000, minCompressionQuality = 0.1): string | undefined {\r\n const decrements = 0.1; // Decrements of quality\r\n const bytesPerCharacter = 2; // Assume 16-bit per character\r\n let quality = 1.0; // JPEG Compression quality\r\n\r\n while (quality > minCompressionQuality) {\r\n const data = canvas.toDataURL(\"image/jpeg\", quality);\r\n // If we are less than 60 Kb, we are good\r\n if (data.length * bytesPerCharacter < maxBytes)\r\n return data;\r\n\r\n quality -= decrements;\r\n }\r\n\r\n return undefined;\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-frontend",
|
|
3
|
-
"version": "3.2.0-dev.
|
|
3
|
+
"version": "3.2.0-dev.19",
|
|
4
4
|
"description": "iTwin.js frontend components",
|
|
5
5
|
"main": "lib/cjs/core-frontend.js",
|
|
6
6
|
"module": "lib/esm/core-frontend.js",
|
|
@@ -23,29 +23,29 @@
|
|
|
23
23
|
"url": "http://www.bentley.com"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@itwin/appui-abstract": "^3.2.0-dev.
|
|
27
|
-
"@itwin/core-bentley": "^3.2.0-dev.
|
|
28
|
-
"@itwin/core-common": "^3.2.0-dev.
|
|
29
|
-
"@itwin/core-geometry": "^3.2.0-dev.
|
|
30
|
-
"@itwin/core-orbitgt": "^3.2.0-dev.
|
|
31
|
-
"@itwin/core-quantity": "^3.2.0-dev.
|
|
32
|
-
"@itwin/webgl-compatibility": "^3.2.0-dev.
|
|
26
|
+
"@itwin/appui-abstract": "^3.2.0-dev.19",
|
|
27
|
+
"@itwin/core-bentley": "^3.2.0-dev.19",
|
|
28
|
+
"@itwin/core-common": "^3.2.0-dev.19",
|
|
29
|
+
"@itwin/core-geometry": "^3.2.0-dev.19",
|
|
30
|
+
"@itwin/core-orbitgt": "^3.2.0-dev.19",
|
|
31
|
+
"@itwin/core-quantity": "^3.2.0-dev.19",
|
|
32
|
+
"@itwin/webgl-compatibility": "^3.2.0-dev.19"
|
|
33
33
|
},
|
|
34
34
|
"//devDependencies": [
|
|
35
35
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
36
36
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@itwin/appui-abstract": "3.2.0-dev.
|
|
40
|
-
"@itwin/build-tools": "3.2.0-dev.
|
|
41
|
-
"@itwin/core-bentley": "3.2.0-dev.
|
|
42
|
-
"@itwin/core-common": "3.2.0-dev.
|
|
43
|
-
"@itwin/core-geometry": "3.2.0-dev.
|
|
44
|
-
"@itwin/core-orbitgt": "3.2.0-dev.
|
|
45
|
-
"@itwin/core-quantity": "3.2.0-dev.
|
|
46
|
-
"@itwin/certa": "3.2.0-dev.
|
|
47
|
-
"@itwin/eslint-plugin": "3.2.0-dev.
|
|
48
|
-
"@itwin/webgl-compatibility": "3.2.0-dev.
|
|
39
|
+
"@itwin/appui-abstract": "3.2.0-dev.19",
|
|
40
|
+
"@itwin/build-tools": "3.2.0-dev.19",
|
|
41
|
+
"@itwin/core-bentley": "3.2.0-dev.19",
|
|
42
|
+
"@itwin/core-common": "3.2.0-dev.19",
|
|
43
|
+
"@itwin/core-geometry": "3.2.0-dev.19",
|
|
44
|
+
"@itwin/core-orbitgt": "3.2.0-dev.19",
|
|
45
|
+
"@itwin/core-quantity": "3.2.0-dev.19",
|
|
46
|
+
"@itwin/certa": "3.2.0-dev.19",
|
|
47
|
+
"@itwin/eslint-plugin": "3.2.0-dev.19",
|
|
48
|
+
"@itwin/webgl-compatibility": "3.2.0-dev.19",
|
|
49
49
|
"@types/chai": "^4.1.4",
|
|
50
50
|
"@types/chai-as-promised": "^7",
|
|
51
51
|
"@types/deep-assign": "^0.1.0",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"NOTE: core-frontend should remain UI technology agnostic, so no react/angular dependencies are allowed"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@itwin/core-i18n": "3.2.0-dev.
|
|
78
|
-
"@itwin/core-telemetry": "3.2.0-dev.
|
|
77
|
+
"@itwin/core-i18n": "3.2.0-dev.19",
|
|
78
|
+
"@itwin/core-telemetry": "3.2.0-dev.19",
|
|
79
79
|
"@loaders.gl/core": "^3.1.6",
|
|
80
80
|
"@loaders.gl/draco": "^3.1.6",
|
|
81
81
|
"deep-assign": "^2.0.0",
|