@itwin/core-backend
Version:
iTwin.js backend components
37 lines • 2.02 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Images
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.imageBufferFromImageSource = imageBufferFromImageSource;
exports.imageSourceFromImageBuffer = imageSourceFromImageBuffer;
const core_common_1 = require("@itwin/core-common");
const NativePlatform_1 = require("./internal/NativePlatform");
/** Decode a [BinaryImageSource]($common) into an [ImageBuffer]($common).
* Returns `undefined` if decoding fails, typically because the input was invalid.
* @see [[imageSourceFromImageBuffer]] for the inverse conversion.
* @public
*/
function imageBufferFromImageSource(args) {
const ret = NativePlatform_1.IModelNative.platform.imageBufferFromImageSource(args.source.format, args.source.data, args.targetFormat ?? 255, false);
if (!ret) {
return undefined;
}
return core_common_1.ImageBuffer.create(ret.data, ret.format, ret.width);
}
/** Encode an [ImageBuffer]($common) into a [BinaryImageSource]($common).
* Returns `undefined` if encoding fails, typically because the input was invalid.
* @throws Error if the ImageBuffer is of [ImageBufferFormat.Alpha]($common).
* @public
*/
function imageSourceFromImageBuffer(args) {
if (args.image.format === core_common_1.ImageBufferFormat.Alpha) {
throw new Error("imageSourceFromImageBuffer cannot be used with alpha-only images");
}
return NativePlatform_1.IModelNative.platform.imageSourceFromImageBuffer(args.image.format, args.image.data, args.image.width, args.image.height, args.targetFormat ?? 255, args.flipVertically ?? false, args.jpegQuality ?? 100);
}
//# sourceMappingURL=ImageSourceConversion.js.map
;