painbrush

1.0.21.1.0
src/pixel.ts
src/pixel.tsDeleted
−70
Index: package/src/pixel.ts
===================================================================
--- package/src/pixel.ts
+++ package/src/pixel.ts
@@ -1,70 +0,0 @@
-import type { Color } from "./color/utils.ts";
-import type {
-  LayerMeta,
-  Layer,
-  SingleChannelLayer,
-} from "./layer.ts";
-
-export const COORDS_ZERO = { x: 0, y: 0 };
-
-export type XYCoords = { x: number; y: number };
-
-export const getPixelIndexFromCoords = (
-  coords: XYCoords,
-  { width }: LayerMeta,
-) => {
-  const xPosition = (coords.y * width + coords.x) * 3;
-  return xPosition;
-};
-
-export const getPixelXYCoords = (
-  index: number,
-  { width }: LayerMeta,
-): XYCoords => {
-  const pixelIndex = ~~(index / 3);
-  return {
-    x: pixelIndex % width,
-    y: ~~(pixelIndex / width),
-  };
-};
-
-export const getPixelColor = (
-  coords: XYCoords,
-  layer: Layer,
-): Color | null => {
-  const normalXYCoords = normalize(coords, layer);
-  if (!normalXYCoords) return null;
-  const { x, y } = normalXYCoords;
-
-  const pos = (x + y * layer.width) * 3;
-  return [layer.data[pos], layer.data[pos + 1], layer.data[pos + 2]];
-};
-
-export const getPixelFromSingleChannelLayer = (
-  coords: XYCoords,
-  layer: SingleChannelLayer,
-): number | null => {
-  const normalXYCoords = normalize(coords, layer);
-  if (!normalXYCoords) return null;
-  const { x, y } = normalXYCoords;
-
-  const pos = x + y * layer.width;
-  return layer.data[pos];
-};
-
-const normalize = (
-  coords: XYCoords,
-  layer: Layer,
-): XYCoords | null => {
-  const x = ~~coords.x;
-  const y = ~~coords.y;
-
-  if (x >= layer.width || x < 0) {
-    return null;
-  }
-  if (y >= layer.height || y < 0) {
-    return null;
-  }
-
-  return { x, y };
-};