UNPKG

@itwin/core-backend

Version:
33 lines 1.78 kB
/*--------------------------------------------------------------------------------------------- * 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 */ import { ImageBuffer, ImageBufferFormat } from "@itwin/core-common"; import { IModelNative } from "./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 */ export function imageBufferFromImageSource(args) { const ret = IModelNative.platform.imageBufferFromImageSource(args.source.format, args.source.data, args.targetFormat ?? 255, false); if (!ret) { return undefined; } return 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 */ export function imageSourceFromImageBuffer(args) { if (args.image.format === ImageBufferFormat.Alpha) { throw new Error("imageSourceFromImageBuffer cannot be used with alpha-only images"); } return 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