Skip to content

Commit

Permalink
refactor(pixel): update imports, use new Fn types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 5, 2020
1 parent 61cbfce commit 213ec33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions packages/pixel/src/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, IObjectOf, NumericArray, Type } from "@thi.ng/api";
import { assert, FnN, FnN2, IObjectOf, NumericArray, Type } from "@thi.ng/api";
import { clamp01 } from "@thi.ng/math";
import {
FloatFormat,
Expand All @@ -23,9 +23,8 @@ const defChannel = (
const maskA = (mask0 << shift) >>> 0;
const invMask = ~maskA >>> 0;
const lane = ch.lane != null ? ch.lane : idx;
const int = (x: number) => (x >>> shift) & mask0;
const setInt = (src: number, x: number) =>
(src & invMask) | ((x & mask0) << shift);
const int: FnN = (x) => (x >>> shift) & mask0;
const setInt: FnN2 = (src, x) => (src & invMask) | ((x & mask0) << shift);
return {
size: ch.size,
abgrShift: 24 - lane * 8 - shift,
Expand Down Expand Up @@ -207,8 +206,7 @@ export const defFloatFormat = (fmt: FloatFormatSpec) => {
};
const to = (col: NumericArray, i: number) =>
((col[i] * 0xff + 0.5) | 0) << chanShift[chan[i]];
const from = (col: number, i: number) =>
((col >>> chanShift[chan[i]]) & 0xff) / 0xff;
const from: FnN2 = (col, i) => ((col >>> chanShift[chan[i]]) & 0xff) / 0xff;
switch (chan.length) {
case 1:
if (fmt.gray) {
Expand Down
4 changes: 2 additions & 2 deletions packages/pixel/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, Fn, Fn2, TypedArray, UIntArray } from "@thi.ng/api";
import { assert, Fn, Fn2, FnN, TypedArray, UIntArray } from "@thi.ng/api";
import { clamp } from "@thi.ng/math";
import type { BlitOpts, PackedFormat, FloatFormat } from "./api";

Expand All @@ -17,7 +17,7 @@ export const ensureChannel = (fmt: PackedFormat | FloatFormat, id: number) => {
return chan;
};

export const luminanceABGR = (c: number) =>
export const luminanceABGR: FnN = (c) =>
(((c >>> 16) & 0xff) * 29 + ((c >>> 8) & 0xff) * 150 + (c & 0xff) * 76) /
255;

Expand Down

0 comments on commit 213ec33

Please sign in to comment.