Special property ‣ __clamped_array ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
When a typedArray yields a Uint8Array, the property clampedArray will also be available,
providing a Uint8ClampedArray view of the data:
pub const Pixel = @Vector(4, u8);
pub const Pixels = []Pixel;
<?php
$m = zigar_use(__DIR__ . '/clamped-array-example-1.zig');
$pixels = new $m->Pixels([ [ 127, 127, 127, 127 ], [ 0, 0, 0, 0 ] ]);
echo "Typed array:\n";
print_r($pixels->__typed_array);
echo "Clamped array:\n";
print_r($pixels->__clamped_array);
$pixels->__clamped_array[0] = 257;
$pixels->__clamped_array[1] = -5;
$pixels->__clamped_array[2] = 88;
echo "Pixels afterward:\n";
print_r($pixels);
Typed array:
Uint8Array Object
(
[ITEMS](/chung-leong/zigar/wiki/ITEMS) => Array
(
[0] => 127
[1] => 127
[2] => 127
[3] => 127
[4] => 0
[5] => 0
[6] => 0
[7] => 0
)
[buffer] => ArrayBuffer Object
(
[byteLength] => 8
[detached] =>
[readOnly] =>
)
[byteLength] => 8
[byteOffset] => 0
[length] => 8
)
Clamped array:
Uint8ClampedArray Object
(
[ITEMS](/chung-leong/zigar/wiki/ITEMS) => Array
(
[0] => 127
[1] => 127
[2] => 127
[3] => 127
[4] => 0
[5] => 0
[6] => 0
[7] => 0
)
[buffer] => ArrayBuffer Object
(
[byteLength] => 8
[detached] =>
[readOnly] =>
)
[byteLength] => 8
[byteOffset] => 0
[length] => 8
)
Pixels afterward:
[]@Vector(4, u8) Object
(
[0] => @Vector(4, u8) Object
(
[0] => 255
[1] => 0
[2] => 88
[3] => 127
)
[1] => @Vector(4, u8) Object
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
)