MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / constructor

Method constructor

web/js/algorithms.js:58–69  ·  view source on GitHub ↗
(px)

Source from the content-addressed store, hash-verified

56
57 class ColorBox {
58 constructor(px) {
59 this.pixels = px;
60 let minR = 255, maxR = 0, minG = 255, maxG = 0, minB = 255, maxB = 0;
61 for (const [r, g, b] of px) {
62 if (r < minR) minR = r; if (r > maxR) maxR = r;
63 if (g < minG) minG = g; if (g > maxG) maxG = g;
64 if (b < minB) minB = b; if (b > maxB) maxB = b;
65 }
66 const rRange = maxR - minR, gRange = maxG - minG, bRange = maxB - minB;
67 this.largestRange = Math.max(rRange, gRange, bRange);
68 this.splitChannel = rRange >= gRange && rRange >= bRange ? 0 : gRange >= bRange ? 1 : 2;
69 }
70 getAvg() {
71 const n = this.pixels.length;
72 let r = 0, g = 0, b = 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected