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.2 to 0.1.3

8

CHANGELOG.md

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

## [0.1.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.2...@thi.ng/pixel@0.1.3) (2019-08-21)
**Note:** Version bump only for package @thi.ng/pixel
## [0.1.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/pixel@0.1.1...@thi.ng/pixel@0.1.2) (2019-08-16)

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

58

lib/index.js

@@ -102,2 +102,25 @@ 'use strict';

};
const setChannelUni = (dbuf, src, set) => {
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], src);
}
};
const setChannelSame = (dbuf, sbuf, get, set) => {
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], get(sbuf[i]));
}
};
const setChannelConvert = (dbuf, sbuf, from, sto, mask) => {
const invMask = ~mask;
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = (dbuf[i] & invMask) | (from(sto(sbuf[i])) & mask);
}
};
const transformABGR = (pix, format, fn) => {
const from = format.fromABGR;
const to = format.toABGR;
for (let i = pix.length; --i >= 0;) {
pix[i] = from(fn(to(pix[i])));
}
};

@@ -441,5 +464,3 @@ const compileLShift = (x, shift) => shift > 0

if (checks.isNumber(src)) {
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], src);
}
setChannelUni(dbuf, src, set);
}

@@ -451,15 +472,6 @@ else {

if (chan.size === schan.size) {
const get = schan.int;
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], get(sbuf[i]));
}
setChannelSame(dbuf, sbuf, schan.int, set);
}
else {
const sto = src.format.toABGR;
const from = this.format.fromABGR;
const mask = chan.maskA;
const invMask = ~mask;
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = (dbuf[i] & invMask) | (from(sto(sbuf[i])) & mask);
}
setChannelConvert(dbuf, sbuf, this.format.fromABGR, src.format.toABGR, chan.maskA);
}

@@ -479,17 +491,7 @@ }

premultiply() {
const pix = this.pixels;
const from = this.format.fromABGR;
const to = this.format.toABGR;
for (let i = pix.length; --i >= 0;) {
pix[i] = from(porterDuff.premultiplyInt(to(pix[i])));
}
transformABGR(this.pixels, this.format, porterDuff.premultiplyInt);
return this;
}
postmultiply() {
const pix = this.pixels;
const from = this.format.fromABGR;
const to = this.format.toABGR;
for (let i = pix.length; --i >= 0;) {
pix[i] = from(porterDuff.postmultiplyInt(to(pix[i])));
}
transformABGR(this.pixels, this.format, porterDuff.postmultiplyInt);
return this;

@@ -545,1 +547,5 @@ }

exports.prepRegions = prepRegions;
exports.setChannelConvert = setChannelConvert;
exports.setChannelSame = setChannelSame;
exports.setChannelUni = setChannelUni;
exports.transformABGR = transformABGR;

@@ -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,i,n,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,i,n){return new(i||(i=Promise))(function(s,a){function r(t){try{l(n.next(t))}catch(t){a(t)}}function h(t){try{l(n.throw(t))}catch(t){a(t)}}function l(t){t.done?s(t.value):new i(function(e){e(t.value)}).then(r,h)}l((n=n.apply(t,e||[])).next())})};const o=(t,e=t)=>{const i=document.createElement("canvas");return i.width=t,i.height=e,{canvas:i,ctx:i.getContext("2d")}};function c(t,i){let n,s;if(e.isNumber(t)){const e=o(t,i);n=e.canvas,s=e.ctx}else s=(n=t).getContext("2d");const a=s.getImageData(0,0,n.width,n.height);return{canvas:n,ctx:s,img:a,pixels:new Uint32Array(a.data.buffer)}}const f=(t,i,n=i)=>{const s=e.isNumber(i)?o(i,n):o(t.width,t.height);return s.ctx.drawImage(t,0,0,s.canvas.width,s.canvas.height),s},u=(t,e,n,s=1)=>i.assert(t.length>=e*n*s,"pixel buffer too small"),m=(t,e)=>{const n=t.channels[e];return i.assert(null!=n,`invalid channel ID: ${e}`),n},p=t=>(29*(t>>>16&255)+150*(t>>>8&255)+76*(255&t))/255,g=(t,e,i,s,a,r,h=0,l=0)=>(t<0&&(i+=t,h-=t,t=0),e<0&&(s+=e,l-=e,e=0),[t,e,n.clamp(i,0,a-t),n.clamp(s,0,r-e),h,l]),A=(t,e,i={})=>{let n,s,a,r,h,l,o=t.width,c=e.width;return[n,s,h,l]=g(i.sx||0,i.sy||0,i.w||o,i.h||t.height,o,t.height),[a,r,h,l,n,s]=g(i.dx||0,i.dy||0,h,l,c,e.height,n,s),{sx:n,sy:s,dx:a,dy:r,rw:h,rh:l}},d=(t,e)=>e>0?`(${t} << ${e})`:e<0?`(${t} >>> ${-e})`:`${t}`,z=(t,e)=>d(t,-e),R=t=>`0x${t.toString(16)}`,x=t=>{const e=(1<<t)-1;return new Function("luma",`return (x) => ${z("luma(x)",8-t)} & ${e};`)(p)},G=t=>{let e;if(8!==t){const i=(1<<t)-1;e=`(((x & ${i}) * ${255/i}) | 0)`}else e="x";return new Function("x",`return 0xff000000 | (${e} * 0x010101);`)},w=t=>new Function("x","return ("+t.map(t=>{const e=t.abgrShift+(8-t.size);return`(${z("x",e)} & ${R(t.maskA)})`}).join(" | ")+") >>> 0;"),y=(t,e)=>{const i=t.map(t=>{if(8!==t.size){const e=t.mask0,i=255/e,n=z("x",t.shift);return d(`((${n} & ${e}) * ${i})`,24-8*t.lane)}return d(`(x & ${R(t.maskA)})`,t.abgrShift)}).join(" | ");return new Function("x",`return (${e?"":"0xff000000 | "}${i}) >>> 0;`)},B=t=>{i.assert(t.channels.length>0,"no channel specs given");const e=t.channels.reduce(([t,e],i,n)=>(e-=i.size,t.push(((t,e,i)=>{const n=(1<<t.size)-1,s=n<<i>>>0,a=~s>>>0,r=null!=t.lane?t.lane:e,h=t=>t>>>i&n,l=(t,e)=>t&a|(e&n)<<i;return{size:t.size,abgrShift:24-8*r-i,lane:r,shift:i,mask0:n,maskA:s,int:h,setInt:l,float:t=>h(t)/n,setFloat:(t,e)=>l(t,e*n)}})(i,n,e)),[t,e]),[[],t.size])[0];return{__compiled:!0,type:t.type,size:t.size,alpha:t.alpha||0,channels:e,fromABGR:t.fromABGR||w(e),toABGR:t.toABGR||y(e,!!t.alpha)}},v=B({type:0,size:8,alpha:8,channels:[{size:8,lane:0}]}),$=B({type:0,size:8,channels:[{size:8,lane:3}],fromABGR:t=>p(t),toABGR:t=>4278190080|65793*(255&t)}),b=B({type:3,size:16,alpha:8,channels:[{size:8,lane:0},{size:8,lane:3}],fromABGR:t=>p(t)|t>>>16&65280,toABGR:t=>(65280&t)<<16|65793*(255&t)}),E=B({type:3,size:16,channels:[{size:16,lane:3}],fromABGR:t=>257*(p(t)+.5|0),toABGR:t=>4278190080|65793*(t>>>8)}),I=B({type:5,size:32,channels:[{size:8,lane:0},{size:16,lane:3}],fromABGR:t=>257*(p(t)+.5|0)|257*(t>>>8&16711680),toABGR:t=>4278190080&t|65793*(t>>>8&255)}),N=B({type:3,size:16,channels:[{size:5,lane:3},{size:6,lane:2},{size:5,lane:1}]}),P=B({type:3,size:16,alpha:1,channels:[{size:1,lane:0},{size:5,lane:3},{size:5,lane:2},{size:5,lane:1}]}),U=B({type:3,size:16,alpha:4,channels:[{size:4,lane:0},{size:4,lane:3},{size:4,lane:2},{size:4,lane:1}]}),k=B({type:5,size:24,channels:[{size:8,lane:3},{size:8,lane:2},{size:8,lane:1}]}),C=B({type:5,size:32,alpha:8,channels:[{size:8,lane:0},{size:8,lane:3},{size:8,lane:2},{size:8,lane:1}]}),F=B({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}),L=B({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}),D={0:Uint8Array,3:Uint16Array,5:Uint32Array};class _{static fromImage(t,e,i,n=i){const s=f(t,i,n),a=s.canvas.width,r=s.canvas.height,h=new Uint32Array(s.ctx.getImageData(0,0,a,r).data.buffer),l=new D[e.type](a*r),o=e.fromABGR;for(let t=l.length;--t>=0;)l[t]=o(h[t]);return new _(a,r,e,l)}static fromCanvas(t){return new _(t.width,t.height,L,c(t).pixels)}constructor(t,e,i,n){this.width=t,this.height=e,this.format=i.__compiled?i:B(i),this.pixels=n||new D[i.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,i){return t>=0&&t<this.width&&e>=0&&e<this.height&&(this.pixels[(0|t)+(0|e)*this.width]=i),this}getChannelAt(t,e,i,n=!1){const s=m(this.format,i),a=this.getAt(t,e);return n?s.float(a):s.int(a)}setChannelAt(t,e,i,n,s=!1){const a=m(this.format,i),r=this.getAt(t,e);return s?a.setFloat(r,n):a.setInt(r,n),this}blend(t,e,i){let n=this.width,s=e.width;const{sx:a,sy:r,dx:h,dy:l,rw:o,rh:c}=A(this,e,i);if(o<1||c<1)return e;const f=this.pixels,u=e.pixels,m=this.format.toABGR,p=e.format.toABGR,g=e.format.fromABGR;for(let e=(0|a)+(0|r)*n,i=(0|h)+(0|l)*s,A=0;A<c;A++,e+=n,i+=s)for(let n=0;n<o;n++)u[i+n]=g(t(m(f[e+n]),p(u[i+n])));return e}blit(t,e){let i=this.width,n=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,m=t.format.fromABGR,p=this.format!==t.format?(t,e)=>{for(let i=0;i<l;i++)f[e+i]=m(u(c[t+i]))}:(t,e)=>f.set(c.subarray(t,t+l),e);for(let t=(0|s)+(0|a)*i,e=(0|r)+(0|h)*n,l=0;l<o;l++,t+=i,e+=n)p(t,e);return t}blitCanvas(t,e=0,i=0){const n=t.getContext("2d"),s=n.getImageData(e,i,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]);n.putImageData(s,e,i)}getRegion(t,e,i,n,s){const[a,r,h,l]=g(t,e,i,n,this.width,this.height);return this.blit(new _(h,l,s||this.format),{sx:a,sy:r,w:h,h:l})}getChannel(t){const e=m(this.format,t),i=new _(this.width,this.height,{type:e.size>16?5:e.size>8?3:0,size:e.size,channels:[{size:e.size,lane:3}],fromABGR:x(e.size),toABGR:G(e.size)}),n=this.pixels,s=i.pixels,a=e.int;for(let t=n.length;--t>=0;)s[t]=a(n[t]);return i}setChannel(t,i){const n=m(this.format,t),s=this.pixels,a=n.setInt;if(e.isNumber(i))for(let t=s.length;--t>=0;)s[t]=a(s[t],i);else{const t=i.pixels,e=i.format.channels[0];if(u(t,this.width,this.height),n.size===e.size){const i=e.int;for(let e=s.length;--e>=0;)s[e]=a(s[e],i(t[e]))}else{const e=i.format.toABGR,a=this.format.fromABGR,r=n.maskA,h=~r;for(let i=s.length;--i>=0;)s[i]=s[i]&h|a(e(t[i]))&r}}return this}invert(){const t=this.pixels,e=this.format,i=Math.pow(2,e.size-e.alpha)-1;for(let e=t.length;--e>=0;)t[e]^=i;return this}premultiply(){const t=this.pixels,e=this.format.fromABGR,i=this.format.toABGR;for(let n=t.length;--n>=0;)t[n]=e(s.premultiplyInt(i(t[n])));return this}postmultiply(){const t=this.pixels,e=this.format.fromABGR,i=this.format.toABGR;for(let n=t.length;--n>=0;)t[n]=e(s.postmultiplyInt(i(t[n])));return this}isPremultiplied(){const t=this.pixels,e=this.format.toABGR;for(let i=t.length;--i>=0;)if(!s.isPremultipliedInt(e(t[i])))return!1;return!0}forEach(t){const e=this.pixels;for(let i=e.length;--i>=0;)e[i]=t(e[i]);return this}}t.ABGR8888=L,t.ALPHA8=v,t.ARGB1555=P,t.ARGB4444=U,t.ARGB8888=C,t.BGR888=F,t.GRAY16=E,t.GRAY8=$,t.GRAY_ALPHA16=I,t.GRAY_ALPHA8=b,t.PackedBuffer=_,t.RGB565=N,t.RGB888=k,t.buffer=(t,e,i,n)=>new _(t,e,i,n),t.canvas2d=o,t.canvasPixels=c,t.clampRegion=g,t.compileFromABGR=w,t.compileGrayFromABGR=x,t.compileGrayToABGR=G,t.compileToABGR=y,t.defPackedFormat=B,t.ensureChannel=m,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=p,t.prepRegions=A,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){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,i)=>(e-=n.size,t.push(((t,e,n)=>{const i=(1<<t.size)-1,s=i<<n>>>0,a=~s>>>0,r=null!=t.lane?t.lane:e,h=t=>t>>>n&i,l=(t,e)=>t&a|(e&i)<<n;return{size:t.size,abgrShift:24-8*r-n,lane:r,shift:n,mask0:i,maskA:s,int:h,setInt:l,float:t=>h(t)/i,setFloat:(t,e)=>l(t,e*i)}})(n,i,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})});
{
"name": "@thi.ng/pixel",
"version": "0.1.2",
"version": "0.1.3",
"description": "TODO",

@@ -36,6 +36,6 @@ "module": "./index.js",

"dependencies": {
"@thi.ng/api": "^6.3.2",
"@thi.ng/api": "^6.3.3",
"@thi.ng/checks": "^2.3.0",
"@thi.ng/math": "^1.4.2",
"@thi.ng/porter-duff": "^0.1.1"
"@thi.ng/porter-duff": "^0.1.2"
},

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

"sideEffects": false,
"gitHead": "6b16cbac7b4495b39ada728be077c7630272d3ac"
"gitHead": "161b4f8afaef0df742a8e2c7776993b828662589"
}

@@ -6,3 +6,3 @@ import { isNumber } from "@thi.ng/checks";

import { ABGR8888, defPackedFormat } from "./format";
import { clampRegion, ensureChannel, ensureSize, prepRegions } from "./utils";
import { clampRegion, ensureChannel, ensureSize, prepRegions, setChannelConvert, setChannelSame, setChannelUni, transformABGR } from "./utils";
const CTORS = {

@@ -146,5 +146,3 @@ [0 /* U8 */]: Uint8Array,

if (isNumber(src)) {
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], src);
}
setChannelUni(dbuf, src, set);
}

@@ -156,15 +154,6 @@ else {

if (chan.size === schan.size) {
const get = schan.int;
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], get(sbuf[i]));
}
setChannelSame(dbuf, sbuf, schan.int, set);
}
else {
const sto = src.format.toABGR;
const from = this.format.fromABGR;
const mask = chan.maskA;
const invMask = ~mask;
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = (dbuf[i] & invMask) | (from(sto(sbuf[i])) & mask);
}
setChannelConvert(dbuf, sbuf, this.format.fromABGR, src.format.toABGR, chan.maskA);
}

@@ -184,17 +173,7 @@ }

premultiply() {
const pix = this.pixels;
const from = this.format.fromABGR;
const to = this.format.toABGR;
for (let i = pix.length; --i >= 0;) {
pix[i] = from(premultiplyInt(to(pix[i])));
}
transformABGR(this.pixels, this.format, premultiplyInt);
return this;
}
postmultiply() {
const pix = this.pixels;
const from = this.format.fromABGR;
const to = this.format.toABGR;
for (let i = pix.length; --i >= 0;) {
pix[i] = from(postmultiplyInt(to(pix[i])));
}
transformABGR(this.pixels, this.format, postmultiplyInt);
return this;

@@ -201,0 +180,0 @@ }

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

import { TypedArray } from "@thi.ng/api";
import { Fn, Fn2, TypedArray, UIntArray } from "@thi.ng/api";
import { BlitOpts, PackedFormat } from "./api";

@@ -21,1 +21,5 @@ export declare const ensureSize: (pixels: TypedArray, width: number, height: number, stride?: number) => void;

};
export declare const setChannelUni: (dbuf: UIntArray, src: number, set: Fn2<number, number, number>) => void;
export declare const setChannelSame: (dbuf: UIntArray, sbuf: UIntArray, get: Fn<number, number>, set: Fn2<number, number, number>) => void;
export declare const setChannelConvert: (dbuf: UIntArray, sbuf: UIntArray, from: Fn<number, number>, sto: Fn<number, number>, mask: number) => void;
export declare const transformABGR: (pix: UIntArray, format: PackedFormat, fn: Fn<number, number>) => void;

@@ -26,1 +26,24 @@ import { assert } from "@thi.ng/api";

};
export const setChannelUni = (dbuf, src, set) => {
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], src);
}
};
export const setChannelSame = (dbuf, sbuf, get, set) => {
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = set(dbuf[i], get(sbuf[i]));
}
};
export const setChannelConvert = (dbuf, sbuf, from, sto, mask) => {
const invMask = ~mask;
for (let i = dbuf.length; --i >= 0;) {
dbuf[i] = (dbuf[i] & invMask) | (from(sto(sbuf[i])) & mask);
}
};
export const transformABGR = (pix, format, fn) => {
const from = format.fromABGR;
const to = format.toABGR;
for (let i = pix.length; --i >= 0;) {
pix[i] = from(fn(to(pix[i])));
}
};

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