本文整理汇总了TypeScript中jpgjs.JpegDecoder类的典型用法代码示例。如果您正苦于以下问题:TypeScript JpegDecoder类的具体用法?TypeScript JpegDecoder怎么用?TypeScript JpegDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JpegDecoder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: decodeJpegStack
export function decodeJpegStack(data: Uint8Array, chunkDataSize: vec3, numComponents: number) {
let parser = new JpegDecoder();
parser.parse(data);
// Just check that the total number pixels matches the expected value.
if (parser.width * parser.height !== chunkDataSize[0] * chunkDataSize[1] * chunkDataSize[2]) {
throw new Error(
`JPEG data does not have the expected dimensions: ` +
`width=${parser.width}, height=${parser.height}, ` +
`chunkDataSize=${vec3.str(chunkDataSize)}`);
}
if (parser.numComponents !== numComponents) {
throw new Error(
`JPEG data does not have the expected number of components: ` +
`components=${parser.numComponents}, expected=${numComponents}`);
}
if (parser.numComponents === 1) {
return parser.getData(parser.width, parser.height, /*forceRGBOutput=*/false);
} else if (parser.numComponents === 3) {
let output = parser.getData(parser.width, parser.height, /*forceRGBOutput=*/false);
return transposeArray2d(output, parser.width * parser.height, 3);
} else {
throw new Error(
`JPEG data has an unsupported number of components: components=${parser.numComponents}`);
}
}
示例2: decodeJpegStack
export function decodeJpegStack(data: Uint8Array, chunkDataSize: Vec3) {
let parser = new JpegDecoder();
parser.parse(data);
if (parser.numComponents !== 1) {
throw new Error('JPEG data does not have the expected number of components');
}
// Just check that the total number pixels matches the expected value.
if (parser.width * parser.height !== chunkDataSize[0] * chunkDataSize[1] * chunkDataSize[2]) {
throw new Error(`JPEG data does not have the expected dimensions: width=${parser.width}, height=${parser.height}, chunkDataSize=${vec3.str(chunkDataSize)}`);
}
return parser.getData(parser.width, parser.height, /*forceRGBOutput=*/false);
}