mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-04 18:29:23 +02:00
feat(struct): add Uint8ClampedArray type
This commit is contained in:
parent
c37e3dd953
commit
b601f7a7f2
4 changed files with 21 additions and 6 deletions
|
@ -2,7 +2,9 @@ import { Struct, StructValueType } from "@yume-chan/struct";
|
|||
import { Adb } from '../adb';
|
||||
import { AdbBufferedStream } from '../stream';
|
||||
|
||||
const Version = new Struct({ littleEndian: true }).uint32('version');
|
||||
const Version =
|
||||
new Struct({ littleEndian: true })
|
||||
.uint32('version');
|
||||
|
||||
/*
|
||||
* ADB uses 8 int32 fields to describe bit depths
|
||||
|
@ -31,7 +33,7 @@ export const AdbFrameBufferV1 =
|
|||
.uint32('green_length')
|
||||
.uint32('alpha_offset')
|
||||
.uint32('alpha_length')
|
||||
.arrayBuffer('data', { lengthField: 'size' });
|
||||
.uint8ClampedArray('data', { lengthField: 'size' });
|
||||
|
||||
export type AdbFrameBufferV1 = StructValueType<typeof AdbFrameBufferV1>;
|
||||
|
||||
|
@ -50,7 +52,7 @@ export const AdbFrameBufferV2 =
|
|||
.uint32('green_length')
|
||||
.uint32('alpha_offset')
|
||||
.uint32('alpha_length')
|
||||
.arrayBuffer('data', { lengthField: 'size' });
|
||||
.uint8ClampedArray('data', { lengthField: 'size' });
|
||||
|
||||
export type AdbFrameBufferV2 = StructValueType<typeof AdbFrameBufferV2>;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ export const FrameBuffer = withDisplayName('FrameBuffer')(({
|
|||
canvas.height = height;
|
||||
|
||||
const context = canvas.getContext("2d")!;
|
||||
const image = new ImageData(new Uint8ClampedArray(framebuffer.data!), width, height);
|
||||
const image = new ImageData(framebuffer.data, width, height);
|
||||
context.putImageData(image, 0, 0);
|
||||
setHasImage(true);
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@yume-chan/struct",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "C-style structure serializer and deserializer.",
|
||||
"keywords": [
|
||||
"structure",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createRuntimeObject, FieldDefinition, FieldRuntimeValue, getRuntimeValue, setRuntimeValue, StructDefaultOptions, StructDeserializationContext, StructOptions, StructSerializationContext } from './basic';
|
||||
import { ArrayBufferFieldType, ArrayBufferLikeFieldType, Evaluate, FixedLengthArrayBufferLikeFieldDefinition, FixedLengthArrayBufferLikeFieldOptions, Identity, KeysOfType, NumberFieldDefinition, NumberFieldType, Overwrite, StringFieldType, VariableLengthArrayBufferLikeFieldDefinition, VariableLengthArrayBufferLikeFieldOptions } from './types';
|
||||
import { ArrayBufferFieldType, ArrayBufferLikeFieldType, Evaluate, FixedLengthArrayBufferLikeFieldDefinition, FixedLengthArrayBufferLikeFieldOptions, Identity, KeysOfType, NumberFieldDefinition, NumberFieldType, Overwrite, StringFieldType, Uint8ClampedArrayFieldType, VariableLengthArrayBufferLikeFieldDefinition, VariableLengthArrayBufferLikeFieldOptions } from './types';
|
||||
|
||||
/**
|
||||
* Extract the value type of the specified `Struct`
|
||||
|
@ -354,6 +354,19 @@ export default class Struct<
|
|||
return this.arrayBufferLike(name, ArrayBufferFieldType.instance, options);
|
||||
};
|
||||
|
||||
public uint8ClampedArray: ArrayBufferTypeFieldDefinitionCreator<
|
||||
TValue,
|
||||
TInit,
|
||||
TExtra,
|
||||
TPostDeserialized,
|
||||
Uint8ClampedArrayFieldType
|
||||
> = (
|
||||
name: PropertyKey,
|
||||
options: any
|
||||
): any => {
|
||||
return this.arrayBufferLike(name, Uint8ClampedArrayFieldType.instance, options);
|
||||
};
|
||||
|
||||
public string: ArrayBufferTypeFieldDefinitionCreator<
|
||||
TValue,
|
||||
TInit,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue