New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/pixel

Package Overview
Dependencies
Maintainers
1
Versions
229
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/pixel - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

5

canvas.js
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -69,3 +70,3 @@ });

*/
export const imagePromise = (src) => __awaiter(this, void 0, void 0, function* () {
export const imagePromise = (src) => __awaiter(void 0, void 0, void 0, function* () {
const img = new Image();

@@ -72,0 +73,0 @@ img.src = src;

@@ -6,2 +6,10 @@ # Change Log

## [0.1.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.4...@thi.ng/pixel@0.1.5) (2019-11-09)
**Note:** Version bump only for package @thi.ng/pixel
## [0.1.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.3...@thi.ng/pixel@0.1.4) (2019-09-21)

@@ -8,0 +16,0 @@

21

lib/index.js

@@ -28,6 +28,7 @@ 'use strict';

var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -73,3 +74,3 @@ });

};
const imagePromise = (src) => __awaiter(undefined, void 0, void 0, function* () {
const imagePromise = (src) => __awaiter(void 0, void 0, void 0, function* () {
const img = new Image();

@@ -333,2 +334,10 @@ img.src = src;

class PackedBuffer {
constructor(w, h, fmt, pixels) {
this.width = w;
this.height = h;
this.format = fmt.__compiled
? fmt
: defPackedFormat(fmt);
this.pixels = pixels || new CTORS[fmt.type](w * h);
}
static fromImage(img, fmt, width, height = width) {

@@ -349,10 +358,2 @@ const ctx = imageCanvas(img, width, height);

}
constructor(w, h, fmt, pixels) {
this.width = w;
this.height = h;
this.format = fmt.__compiled
? fmt
: defPackedFormat(fmt);
this.pixels = pixels || new CTORS[fmt.type](w * h);
}
as(fmt) {

@@ -359,0 +360,0 @@ return this.getRegion(0, 0, this.width, this.height, fmt);

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@thi.ng/checks"),require("@thi.ng/api"),require("@thi.ng/math"),require("@thi.ng/porter-duff")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/checks","@thi.ng/api","@thi.ng/math","@thi.ng/porter-duff"],e):e(((t=t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.pixel={}),t.thi.ng.checks,t.thi.ng.api,t.thi.ng.math,t.thi.ng.porterDuff)}(this,function(t,e,n,i,s){"use strict";var a,r,h;(a=t.Lane||(t.Lane={}))[a.ALPHA=0]="ALPHA",a[a.RED=3]="RED",a[a.GREEN=2]="GREEN",a[a.BLUE=1]="BLUE",(r=t.Wrap||(t.Wrap={}))[r.NONE=0]="NONE",r[r.U=1]="U",r[r.V=2]="V",r[r.UV=3]="UV",(h=t.Filter||(t.Filter={}))[h.NEAREST=0]="NEAREST",h[h.LINEAR=1]="LINEAR";var l=function(t,e,n,i){return new(n||(n=Promise))(function(s,a){function r(t){try{l(i.next(t))}catch(t){a(t)}}function h(t){try{l(i.throw(t))}catch(t){a(t)}}function l(t){t.done?s(t.value):new n(function(e){e(t.value)}).then(r,h)}l((i=i.apply(t,e||[])).next())})};const o=(t,e=t)=>{const n=document.createElement("canvas");return n.width=t,n.height=e,{canvas:n,ctx:n.getContext("2d")}};function c(t,n){let i,s;if(e.isNumber(t)){const e=o(t,n);i=e.canvas,s=e.ctx}else s=(i=t).getContext("2d");const a=s.getImageData(0,0,i.width,i.height);return{canvas:i,ctx:s,img:a,pixels:new Uint32Array(a.data.buffer)}}const f=(t,n,i=n)=>{const s=e.isNumber(n)?o(n,i):o(t.width,t.height);return s.ctx.drawImage(t,0,0,s.canvas.width,s.canvas.height),s},u=(t,e,i,s=1)=>n.assert(t.length>=e*i*s,"pixel buffer too small"),p=(t,e)=>{const i=t.channels[e];return n.assert(null!=i,`invalid channel ID: ${e}`),i},m=t=>(29*(t>>>16&255)+150*(t>>>8&255)+76*(255&t))/255,g=(t,e,n,s,a,r,h=0,l=0)=>(t<0&&(n+=t,h-=t,t=0),e<0&&(s+=e,l-=e,e=0),[t,e,i.clamp(n,0,a-t),i.clamp(s,0,r-e),h,l]),A=(t,e,n={})=>{let i,s,a,r,h,l,o=t.width,c=e.width;return[i,s,h,l]=g(n.sx||0,n.sy||0,n.w||o,n.h||t.height,o,t.height),[a,r,h,l,i,s]=g(n.dx||0,n.dy||0,h,l,c,e.height,i,s),{sx:i,sy:s,dx:a,dy:r,rw:h,rh:l}},d=(t,e,n)=>{for(let i=t.length;--i>=0;)t[i]=n(t[i],e)},z=(t,e,n,i)=>{for(let s=t.length;--s>=0;)t[s]=i(t[s],n(e[s]))},R=(t,e,n,i,s)=>{const a=~s;for(let r=t.length;--r>=0;)t[r]=t[r]&a|n(i(e[r]))&s},x=(t,e,n)=>{const i=e.fromABGR,s=e.toABGR;for(let e=t.length;--e>=0;)t[e]=i(n(s(t[e])))},G=(t,e)=>e>0?`(${t} << ${e})`:e<0?`(${t} >>> ${-e})`:`${t}`,w=(t,e)=>G(t,-e),y=t=>`0x${t.toString(16)}`,B=t=>{const e=(1<<t)-1;return new Function("luma",`return (x) => ${w("luma(x)",8-t)} & ${e};`)(m)},v=t=>{let e;if(8!==t){const n=(1<<t)-1;e=`(((x & ${n}) * ${255/n}) | 0)`}else e="x";return new Function("x",`return 0xff000000 | (${e} * 0x010101);`)},$=t=>new Function("x","return ("+t.map(t=>{const e=t.abgrShift+(8-t.size);return`(${w("x",e)} & ${y(t.maskA)})`}).join(" | ")+") >>> 0;"),b=(t,e)=>{const n=t.map(t=>{if(8!==t.size){const e=t.mask0,n=255/e,i=w("x",t.shift);return G(`((${i} & ${e}) * ${n})`,24-8*t.lane)}return G(`(x & ${y(t.maskA)})`,t.abgrShift)}).join(" | ");return new Function("x",`return (${e?"":"0xff000000 | "}${n}) >>> 0;`)},E=t=>{n.assert(t.channels.length>0,"no channel specs given");const e=t.channels.reduce(([t,e],n,s)=>(e-=n.size,t.push(((t,e,n)=>{const s=(1<<t.size)-1,a=s<<n>>>0,r=~a>>>0,h=null!=t.lane?t.lane:e,l=t=>t>>>n&s,o=(t,e)=>t&r|(e&s)<<n;return{size:t.size,abgrShift:24-8*h-n,lane:h,shift:n,mask0:s,maskA:a,int:l,setInt:o,float:t=>l(t)/s,setFloat:(t,e)=>o(t,i.clamp01(e)*s)}})(n,s,e)),[t,e]),[[],t.size])[0];return{__compiled:!0,type:t.type,size:t.size,alpha:t.alpha||0,channels:e,fromABGR:t.fromABGR||$(e),toABGR:t.toABGR||b(e,!!t.alpha)}},I=E({type:0,size:8,alpha:8,channels:[{size:8,lane:0}]}),C=E({type:0,size:8,channels:[{size:8,lane:3}],fromABGR:t=>m(t),toABGR:t=>4278190080|65793*(255&t)}),N=E({type:3,size:16,alpha:8,channels:[{size:8,lane:0},{size:8,lane:3}],fromABGR:t=>m(t)|t>>>16&65280,toABGR:t=>(65280&t)<<16|65793*(255&t)}),P=E({type:3,size:16,channels:[{size:16,lane:3}],fromABGR:t=>257*(m(t)+.5|0),toABGR:t=>4278190080|65793*(t>>>8)}),U=E({type:5,size:32,channels:[{size:8,lane:0},{size:16,lane:3}],fromABGR:t=>257*(m(t)+.5|0)|257*(t>>>8&16711680),toABGR:t=>4278190080&t|65793*(t>>>8&255)}),k=E({type:3,size:16,channels:[{size:5,lane:3},{size:6,lane:2},{size:5,lane:1}]}),F=E({type:3,size:16,alpha:1,channels:[{size:1,lane:0},{size:5,lane:3},{size:5,lane:2},{size:5,lane:1}]}),L=E({type:3,size:16,alpha:4,channels:[{size:4,lane:0},{size:4,lane:3},{size:4,lane:2},{size:4,lane:1}]}),D=E({type:5,size:24,channels:[{size:8,lane:3},{size:8,lane:2},{size:8,lane:1}]}),S=E({type:5,size:32,alpha:8,channels:[{size:8,lane:0},{size:8,lane:3},{size:8,lane:2},{size:8,lane:1}]}),_=E({type:5,size:24,channels:[{size:8,lane:1},{size:8,lane:2},{size:8,lane:3}],fromABGR:t=>16777215&t,toABGR:t=>4278190080|t}),H=E({type:5,size:32,alpha:8,channels:[{size:8,lane:0},{size:8,lane:1},{size:8,lane:2},{size:8,lane:3}],fromABGR:t=>t,toABGR:t=>t}),j={0:Uint8Array,3:Uint16Array,5:Uint32Array};class q{static fromImage(t,e,n,i=n){const s=f(t,n,i),a=s.canvas.width,r=s.canvas.height,h=new Uint32Array(s.ctx.getImageData(0,0,a,r).data.buffer),l=new j[e.type](a*r),o=e.fromABGR;for(let t=l.length;--t>=0;)l[t]=o(h[t]);return new q(a,r,e,l)}static fromCanvas(t){return new q(t.width,t.height,H,c(t).pixels)}constructor(t,e,n,i){this.width=t,this.height=e,this.format=n.__compiled?n:E(n),this.pixels=i||new j[n.type](t*e)}as(t){return this.getRegion(0,0,this.width,this.height,t)}getAt(t,e){return t>=0&&t<this.width&&e>=0&&e<this.height?this.pixels[(0|t)+(0|e)*this.width]:0}setAt(t,e,n){return t>=0&&t<this.width&&e>=0&&e<this.height&&(this.pixels[(0|t)+(0|e)*this.width]=n),this}getChannelAt(t,e,n,i=!1){const s=p(this.format,n),a=this.getAt(t,e);return i?s.float(a):s.int(a)}setChannelAt(t,e,n,i,s=!1){const a=p(this.format,n),r=this.getAt(t,e);return s?a.setFloat(r,i):a.setInt(r,i),this}blend(t,e,n){let i=this.width,s=e.width;const{sx:a,sy:r,dx:h,dy:l,rw:o,rh:c}=A(this,e,n);if(o<1||c<1)return e;const f=this.pixels,u=e.pixels,p=this.format.toABGR,m=e.format.toABGR,g=e.format.fromABGR;for(let e=(0|a)+(0|r)*i,n=(0|h)+(0|l)*s,A=0;A<c;A++,e+=i,n+=s)for(let i=0;i<o;i++)u[n+i]=g(t(p(f[e+i]),m(u[n+i])));return e}blit(t,e){let n=this.width,i=t.width;const{sx:s,sy:a,dx:r,dy:h,rw:l,rh:o}=A(this,t,e);if(l<1||o<1)return t;const c=this.pixels,f=t.pixels,u=this.format.toABGR,p=t.format.fromABGR,m=this.format!==t.format?(t,e)=>{for(let n=0;n<l;n++)f[e+n]=p(u(c[t+n]))}:(t,e)=>f.set(c.subarray(t,t+l),e);for(let t=(0|s)+(0|a)*n,e=(0|r)+(0|h)*i,l=0;l<o;l++,t+=n,e+=i)m(t,e);return t}blitCanvas(t,e=0,n=0){const i=t.getContext("2d"),s=i.getImageData(e,n,this.width,this.height),a=new Uint32Array(s.data.buffer),r=this.pixels,h=this.format.toABGR;for(let t=a.length;--t>=0;)a[t]=h(r[t]);i.putImageData(s,e,n)}getRegion(t,e,n,i,s){const[a,r,h,l]=g(t,e,n,i,this.width,this.height);return this.blit(new q(h,l,s||this.format),{sx:a,sy:r,w:h,h:l})}getChannel(t){const e=p(this.format,t),n=new q(this.width,this.height,{type:e.size>16?5:e.size>8?3:0,size:e.size,channels:[{size:e.size,lane:3}],fromABGR:B(e.size),toABGR:v(e.size)}),i=this.pixels,s=n.pixels,a=e.int;for(let t=i.length;--t>=0;)s[t]=a(i[t]);return n}setChannel(t,n){const i=p(this.format,t),s=this.pixels,a=i.setInt;if(e.isNumber(n))d(s,n,a);else{const t=n.pixels,e=n.format.channels[0];u(t,this.width,this.height),i.size===e.size?z(s,t,e.int,a):R(s,t,this.format.fromABGR,n.format.toABGR,i.maskA)}return this}invert(){const t=this.pixels,e=this.format,n=Math.pow(2,e.size-e.alpha)-1;for(let e=t.length;--e>=0;)t[e]^=n;return this}premultiply(){return x(this.pixels,this.format,s.premultiplyInt),this}postmultiply(){return x(this.pixels,this.format,s.postmultiplyInt),this}isPremultiplied(){const t=this.pixels,e=this.format.toABGR;for(let n=t.length;--n>=0;)if(!s.isPremultipliedInt(e(t[n])))return!1;return!0}forEach(t){const e=this.pixels;for(let n=e.length;--n>=0;)e[n]=t(e[n]);return this}}t.ABGR8888=H,t.ALPHA8=I,t.ARGB1555=F,t.ARGB4444=L,t.ARGB8888=S,t.BGR888=_,t.GRAY16=P,t.GRAY8=C,t.GRAY_ALPHA16=U,t.GRAY_ALPHA8=N,t.PackedBuffer=q,t.RGB565=k,t.RGB888=D,t.buffer=(t,e,n,i)=>new q(t,e,n,i),t.canvas2d=o,t.canvasPixels=c,t.clampRegion=g,t.compileFromABGR=$,t.compileGrayFromABGR=B,t.compileGrayToABGR=v,t.compileToABGR=b,t.defPackedFormat=E,t.ensureChannel=p,t.ensureSize=u,t.imageCanvas=f,t.imagePromise=t=>l(void 0,void 0,void 0,function*(){const e=new Image;return e.src=t,yield e.decode(),e}),t.luminanceABGR=m,t.prepRegions=A,t.setChannelConvert=R,t.setChannelSame=z,t.setChannelUni=d,t.transformABGR=x,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@thi.ng/checks"),require("@thi.ng/api"),require("@thi.ng/math"),require("@thi.ng/porter-duff")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/checks","@thi.ng/api","@thi.ng/math","@thi.ng/porter-duff"],e):e(((t=t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.pixel={}),t.thi.ng.checks,t.thi.ng.api,t.thi.ng.math,t.thi.ng.porterDuff)}(this,(function(t,e,n,i,s){"use strict";var a,r,h;(a=t.Lane||(t.Lane={}))[a.ALPHA=0]="ALPHA",a[a.RED=3]="RED",a[a.GREEN=2]="GREEN",a[a.BLUE=1]="BLUE",(r=t.Wrap||(t.Wrap={}))[r.NONE=0]="NONE",r[r.U=1]="U",r[r.V=2]="V",r[r.UV=3]="UV",(h=t.Filter||(t.Filter={}))[h.NEAREST=0]="NEAREST",h[h.LINEAR=1]="LINEAR";var l=function(t,e,n,i){return new(n||(n=Promise))((function(s,a){function r(t){try{l(i.next(t))}catch(t){a(t)}}function h(t){try{l(i.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,h)}l((i=i.apply(t,e||[])).next())}))};const o=(t,e=t)=>{const n=document.createElement("canvas");return n.width=t,n.height=e,{canvas:n,ctx:n.getContext("2d")}};function c(t,n){let i,s;if(e.isNumber(t)){const e=o(t,n);i=e.canvas,s=e.ctx}else s=(i=t).getContext("2d");const a=s.getImageData(0,0,i.width,i.height);return{canvas:i,ctx:s,img:a,pixels:new Uint32Array(a.data.buffer)}}const f=(t,n,i=n)=>{const s=e.isNumber(n)?o(n,i):o(t.width,t.height);return s.ctx.drawImage(t,0,0,s.canvas.width,s.canvas.height),s},u=(t,e,i,s=1)=>n.assert(t.length>=e*i*s,"pixel buffer too small"),p=(t,e)=>{const i=t.channels[e];return n.assert(null!=i,`invalid channel ID: ${e}`),i},m=t=>(29*(t>>>16&255)+150*(t>>>8&255)+76*(255&t))/255,g=(t,e,n,s,a,r,h=0,l=0)=>(t<0&&(n+=t,h-=t,t=0),e<0&&(s+=e,l-=e,e=0),[t,e,i.clamp(n,0,a-t),i.clamp(s,0,r-e),h,l]),A=(t,e,n={})=>{let i,s,a,r,h,l,o=t.width,c=e.width;return[i,s,h,l]=g(n.sx||0,n.sy||0,n.w||o,n.h||t.height,o,t.height),[a,r,h,l,i,s]=g(n.dx||0,n.dy||0,h,l,c,e.height,i,s),{sx:i,sy:s,dx:a,dy:r,rw:h,rh:l}},d=(t,e,n)=>{for(let i=t.length;--i>=0;)t[i]=n(t[i],e)},z=(t,e,n,i)=>{for(let s=t.length;--s>=0;)t[s]=i(t[s],n(e[s]))},R=(t,e,n,i,s)=>{const a=~s;for(let r=t.length;--r>=0;)t[r]=t[r]&a|n(i(e[r]))&s},x=(t,e,n)=>{const i=e.fromABGR,s=e.toABGR;for(let e=t.length;--e>=0;)t[e]=i(n(s(t[e])))},G=(t,e)=>e>0?`(${t} << ${e})`:e<0?`(${t} >>> ${-e})`:`${t}`,w=(t,e)=>G(t,-e),y=t=>`0x${t.toString(16)}`,B=t=>{const e=(1<<t)-1;return new Function("luma",`return (x) => ${w("luma(x)",8-t)} & ${e};`)(m)},v=t=>{let e;if(8!==t){const n=(1<<t)-1;e=`(((x & ${n}) * ${255/n}) | 0)`}else e="x";return new Function("x",`return 0xff000000 | (${e} * 0x010101);`)},$=t=>new Function("x","return ("+t.map(t=>{const e=t.abgrShift+(8-t.size);return`(${w("x",e)} & ${y(t.maskA)})`}).join(" | ")+") >>> 0;"),b=(t,e)=>{const n=t.map(t=>{if(8!==t.size){const e=t.mask0,n=255/e,i=w("x",t.shift);return G(`((${i} & ${e}) * ${n})`,24-8*t.lane)}return G(`(x & ${y(t.maskA)})`,t.abgrShift)}).join(" | ");return new Function("x",`return (${e?"":"0xff000000 | "}${n}) >>> 0;`)},E=t=>{n.assert(t.channels.length>0,"no channel specs given");const e=t.channels.reduce(([t,e],n,s)=>(e-=n.size,t.push(((t,e,n)=>{const s=(1<<t.size)-1,a=s<<n>>>0,r=~a>>>0,h=null!=t.lane?t.lane:e,l=t=>t>>>n&s,o=(t,e)=>t&r|(e&s)<<n;return{size:t.size,abgrShift:24-8*h-n,lane:h,shift:n,mask0:s,maskA:a,int:l,setInt:o,float:t=>l(t)/s,setFloat:(t,e)=>o(t,i.clamp01(e)*s)}})(n,s,e)),[t,e]),[[],t.size])[0];return{__compiled:!0,type:t.type,size:t.size,alpha:t.alpha||0,channels:e,fromABGR:t.fromABGR||$(e),toABGR:t.toABGR||b(e,!!t.alpha)}},I=E({type:0,size:8,alpha:8,channels:[{size:8,lane:0}]}),C=E({type:0,size:8,channels:[{size:8,lane:3}],fromABGR:t=>m(t),toABGR:t=>4278190080|65793*(255&t)}),N=E({type:3,size:16,alpha:8,channels:[{size:8,lane:0},{size:8,lane:3}],fromABGR:t=>m(t)|t>>>16&65280,toABGR:t=>(65280&t)<<16|65793*(255&t)}),P=E({type:3,size:16,channels:[{size:16,lane:3}],fromABGR:t=>257*(m(t)+.5|0),toABGR:t=>4278190080|65793*(t>>>8)}),U=E({type:5,size:32,channels:[{size:8,lane:0},{size:16,lane:3}],fromABGR:t=>257*(m(t)+.5|0)|257*(t>>>8&16711680),toABGR:t=>4278190080&t|65793*(t>>>8&255)}),k=E({type:3,size:16,channels:[{size:5,lane:3},{size:6,lane:2},{size:5,lane:1}]}),F=E({type:3,size:16,alpha:1,channels:[{size:1,lane:0},{size:5,lane:3},{size:5,lane:2},{size:5,lane:1}]}),L=E({type:3,size:16,alpha:4,channels:[{size:4,lane:0},{size:4,lane:3},{size:4,lane:2},{size:4,lane:1}]}),D=E({type:5,size:24,channels:[{size:8,lane:3},{size:8,lane:2},{size:8,lane:1}]}),S=E({type:5,size:32,alpha:8,channels:[{size:8,lane:0},{size:8,lane:3},{size:8,lane:2},{size:8,lane:1}]}),_=E({type:5,size:24,channels:[{size:8,lane:1},{size:8,lane:2},{size:8,lane:3}],fromABGR:t=>16777215&t,toABGR:t=>4278190080|t}),H=E({type:5,size:32,alpha:8,channels:[{size:8,lane:0},{size:8,lane:1},{size:8,lane:2},{size:8,lane:3}],fromABGR:t=>t,toABGR:t=>t}),j={0:Uint8Array,3:Uint16Array,5:Uint32Array};class q{constructor(t,e,n,i){this.width=t,this.height=e,this.format=n.__compiled?n:E(n),this.pixels=i||new j[n.type](t*e)}static fromImage(t,e,n,i=n){const s=f(t,n,i),a=s.canvas.width,r=s.canvas.height,h=new Uint32Array(s.ctx.getImageData(0,0,a,r).data.buffer),l=new j[e.type](a*r),o=e.fromABGR;for(let t=l.length;--t>=0;)l[t]=o(h[t]);return new q(a,r,e,l)}static fromCanvas(t){return new q(t.width,t.height,H,c(t).pixels)}as(t){return this.getRegion(0,0,this.width,this.height,t)}getAt(t,e){return t>=0&&t<this.width&&e>=0&&e<this.height?this.pixels[(0|t)+(0|e)*this.width]:0}setAt(t,e,n){return t>=0&&t<this.width&&e>=0&&e<this.height&&(this.pixels[(0|t)+(0|e)*this.width]=n),this}getChannelAt(t,e,n,i=!1){const s=p(this.format,n),a=this.getAt(t,e);return i?s.float(a):s.int(a)}setChannelAt(t,e,n,i,s=!1){const a=p(this.format,n),r=this.getAt(t,e);return s?a.setFloat(r,i):a.setInt(r,i),this}blend(t,e,n){let i=this.width,s=e.width;const{sx:a,sy:r,dx:h,dy:l,rw:o,rh:c}=A(this,e,n);if(o<1||c<1)return e;const f=this.pixels,u=e.pixels,p=this.format.toABGR,m=e.format.toABGR,g=e.format.fromABGR;for(let e=(0|a)+(0|r)*i,n=(0|h)+(0|l)*s,A=0;A<c;A++,e+=i,n+=s)for(let i=0;i<o;i++)u[n+i]=g(t(p(f[e+i]),m(u[n+i])));return e}blit(t,e){let n=this.width,i=t.width;const{sx:s,sy:a,dx:r,dy:h,rw:l,rh:o}=A(this,t,e);if(l<1||o<1)return t;const c=this.pixels,f=t.pixels,u=this.format.toABGR,p=t.format.fromABGR,m=this.format!==t.format?(t,e)=>{for(let n=0;n<l;n++)f[e+n]=p(u(c[t+n]))}:(t,e)=>f.set(c.subarray(t,t+l),e);for(let t=(0|s)+(0|a)*n,e=(0|r)+(0|h)*i,l=0;l<o;l++,t+=n,e+=i)m(t,e);return t}blitCanvas(t,e=0,n=0){const i=t.getContext("2d"),s=i.getImageData(e,n,this.width,this.height),a=new Uint32Array(s.data.buffer),r=this.pixels,h=this.format.toABGR;for(let t=a.length;--t>=0;)a[t]=h(r[t]);i.putImageData(s,e,n)}getRegion(t,e,n,i,s){const[a,r,h,l]=g(t,e,n,i,this.width,this.height);return this.blit(new q(h,l,s||this.format),{sx:a,sy:r,w:h,h:l})}getChannel(t){const e=p(this.format,t),n=new q(this.width,this.height,{type:e.size>16?5:e.size>8?3:0,size:e.size,channels:[{size:e.size,lane:3}],fromABGR:B(e.size),toABGR:v(e.size)}),i=this.pixels,s=n.pixels,a=e.int;for(let t=i.length;--t>=0;)s[t]=a(i[t]);return n}setChannel(t,n){const i=p(this.format,t),s=this.pixels,a=i.setInt;if(e.isNumber(n))d(s,n,a);else{const t=n.pixels,e=n.format.channels[0];u(t,this.width,this.height),i.size===e.size?z(s,t,e.int,a):R(s,t,this.format.fromABGR,n.format.toABGR,i.maskA)}return this}invert(){const t=this.pixels,e=this.format,n=Math.pow(2,e.size-e.alpha)-1;for(let e=t.length;--e>=0;)t[e]^=n;return this}premultiply(){return x(this.pixels,this.format,s.premultiplyInt),this}postmultiply(){return x(this.pixels,this.format,s.postmultiplyInt),this}isPremultiplied(){const t=this.pixels,e=this.format.toABGR;for(let n=t.length;--n>=0;)if(!s.isPremultipliedInt(e(t[n])))return!1;return!0}forEach(t){const e=this.pixels;for(let n=e.length;--n>=0;)e[n]=t(e[n]);return this}}t.ABGR8888=H,t.ALPHA8=I,t.ARGB1555=F,t.ARGB4444=L,t.ARGB8888=S,t.BGR888=_,t.GRAY16=P,t.GRAY8=C,t.GRAY_ALPHA16=U,t.GRAY_ALPHA8=N,t.PackedBuffer=q,t.RGB565=k,t.RGB888=D,t.buffer=(t,e,n,i)=>new q(t,e,n,i),t.canvas2d=o,t.canvasPixels=c,t.clampRegion=g,t.compileFromABGR=$,t.compileGrayFromABGR=B,t.compileGrayToABGR=v,t.compileToABGR=b,t.defPackedFormat=E,t.ensureChannel=p,t.ensureSize=u,t.imageCanvas=f,t.imagePromise=t=>l(void 0,void 0,void 0,(function*(){const e=new Image;return e.src=t,yield e.decode(),e})),t.luminanceABGR=m,t.prepRegions=A,t.setChannelConvert=R,t.setChannelSame=z,t.setChannelUni=d,t.transformABGR=x,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@thi.ng/pixel",
"version": "0.1.4",
"description": "TODO",
"version": "0.1.5",
"description": "Packed pixel buffer w/ customizable formats, blitting, conversions",
"module": "./index.js",

@@ -32,10 +32,10 @@ "main": "./lib/index.js",

"nyc": "^14.0.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.3"
"typedoc": "^0.15.0",
"typescript": "^3.6.4"
},
"dependencies": {
"@thi.ng/api": "^6.4.0",
"@thi.ng/checks": "^2.4.0",
"@thi.ng/math": "^1.4.2",
"@thi.ng/porter-duff": "^0.1.3"
"@thi.ng/api": "^6.5.0",
"@thi.ng/checks": "^2.4.1",
"@thi.ng/math": "^1.5.0",
"@thi.ng/porter-duff": "^0.1.4"
},

@@ -58,3 +58,3 @@ "keywords": [

"sideEffects": false,
"gitHead": "5f865588e37a27ceb46484c24fce4d59a0637f90"
"gitHead": "97add769f24aa32a1a5e13c5c941605e1b9eb569"
}

@@ -13,2 +13,10 @@ import { isNumber } from "@thi.ng/checks";

export class PackedBuffer {
constructor(w, h, fmt, pixels) {
this.width = w;
this.height = h;
this.format = fmt.__compiled
? fmt
: defPackedFormat(fmt);
this.pixels = pixels || new CTORS[fmt.type](w * h);
}
static fromImage(img, fmt, width, height = width) {

@@ -29,10 +37,2 @@ const ctx = imageCanvas(img, width, height);

}
constructor(w, h, fmt, pixels) {
this.width = w;
this.height = h;
this.format = fmt.__compiled
? fmt
: defPackedFormat(fmt);
this.pixels = pixels || new CTORS[fmt.type](w * h);
}
as(fmt) {

@@ -39,0 +39,0 @@ return this.getRegion(0, 0, this.width, this.height, fmt);

@@ -26,3 +26,3 @@ # @thi.ng/pixel

![screenshot](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/pixel/pixel-basics.png)
![screenshot](https://raw.githubusercontent.com/thi-ng/umbrella/master/assets/pixel/pixel-basics.png)

@@ -110,3 +110,3 @@ Typed array backed, packed integer pixel buffers with customizable

![porter-duff compositing modes](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/porter-duff/porter-duff2.png)
![porter-duff compositing modes](https://raw.githubusercontent.com/thi-ng/umbrella/master/assets/porter-duff/porter-duff2.png)

@@ -113,0 +113,0 @@ Code for the screenshot at the top of this readme...

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc