Skip to content

Commit

Permalink
refactor(pixel): update IPixelBuffer, extract format defs
Browse files Browse the repository at this point in the history
- make IPixelBuffer fields readonly, expose stride
- move all format related defs to /format subdir
  • Loading branch information
postspectacular committed Feb 1, 2021
1 parent 6b5fed9 commit 3416ff7
Show file tree
Hide file tree
Showing 25 changed files with 478 additions and 395 deletions.
6 changes: 4 additions & 2 deletions packages/pixel/package.json
@@ -1,7 +1,7 @@
{
"name": "@thi.ng/pixel",
"version": "0.6.0",
"description": "Typed array backed, packed integer and unpacked floating point pixel buffers w/ customizable formats, blitting, dithering, conversions",
"description": "Typed array backed, integer and floating point pixel buffers w/ customizable formats, blitting, dithering, conversions",
"module": "./index.js",
"main": "./lib/index.js",
"umd:main": "./lib/index.umd.js",
Expand Down Expand Up @@ -57,7 +57,8 @@
"files": [
"*.js",
"*.d.ts",
"lib"
"lib",
"format"
],
"keywords": [
"alpha",
Expand All @@ -73,6 +74,7 @@
"datastructure",
"dither",
"float",
"format",
"grayscale",
"image",
"interval",
Expand Down
11 changes: 6 additions & 5 deletions packages/pixel/src/api.ts
Expand Up @@ -206,11 +206,12 @@ export interface RawPixelBuffer extends CanvasContext {
pixels: Uint32Array;
}

export interface IPixelBuffer<T extends TypedArray, P> {
width: number;
height: number;
format: IABGRConvert<any>;
pixels: T;
export interface IPixelBuffer<T extends TypedArray = TypedArray, P = any> {
readonly width: number;
readonly height: number;
readonly format: IABGRConvert<any>;
readonly stride: number;
readonly pixels: T;

/**
* Returns pixel value at given position. If pos is outside the
Expand Down
15 changes: 8 additions & 7 deletions packages/pixel/src/float.ts
Expand Up @@ -9,7 +9,8 @@ import type {
IPixelBuffer,
PackedFormat,
} from "./api";
import { defFloatFormat, FLOAT_GRAY } from "./format";
import { defFloatFormat } from "./format/float-format";
import { FLOAT_GRAY } from "./format/float-gray";
import { PackedBuffer } from "./packed";
import { clampRegion, ensureChannel, ensureSize, prepRegions } from "./utils";

Expand Down Expand Up @@ -49,12 +50,12 @@ export class FloatBuffer implements IPixelBuffer<Float32Array, NumericArray> {
return dest;
}

width: number;
height: number;
stride: number;
rowStride: number;
pixels: Float32Array;
format: FloatFormat;
readonly width: number;
readonly height: number;
readonly stride: number;
readonly rowStride: number;
readonly pixels: Float32Array;
readonly format: FloatFormat;
protected __empty: NumericArray;

constructor(
Expand Down

0 comments on commit 3416ff7

Please sign in to comment.