Comparing version 0.1.3 to 0.1.4
@@ -377,2 +377,2 @@ /** | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).icoEndec={})}(this,(function(t){"use strict";class e{constructor(t){this._imageBuffers=t.map(t=>{if(t instanceof ArrayBuffer)return Buffer.from(new Uint8Array(t));if(t instanceof Buffer)return t;throw"Encoder requires ArrayBuffers or Buffers"})}get buffer(){return this._buffer}encode(){this._buffer=Buffer.alloc(0),this._bufferOffset=0,this._imageOffset=0,this._writeICONDIR();for(let t=0;t<this._imageBuffers.length;t++)this._writeICONDIRENTRY(t);for(let t=0;t<this._imageBuffers.length;t++)this._writeICONDATA(t);return this._buffer}_writeICONDIR(){const t=Buffer.alloc(6);t.writeUInt16LE(0,0),t.writeUInt16LE(1,2),t.writeUInt16LE(this._imageBuffers.length,4),this._imageOffset+=6,this._buffer=Buffer.concat([this._buffer,t])}_writeICONDIRENTRY(t){const e=this._imageBuffers[t];137===e[0]&&80===e[1]&&78===e[2]&&71===e[3]?this._writeICONDIRENTRY_png(t):this._writeICONDIRENTRY_bmp(t)}_writeICONDIRENTRY_png(t){const e=this._imageBuffers[t],i=Buffer.alloc(16);if(73!==e[12]&&72!==e[13]&&68!==e[14]&&82!==e[15])throw"PNG's first chunk must be an IHDR";let f=e.readUInt32BE(16),r=e.readUInt32BE(20),s=e.readUInt8(24),n=0;if(3===e.readUInt8(25)){if("P"!==e[29]&&"L"!==e[30]&&"T"!==e[31]&&"E"!==e[32])throw"PNG's second chunk must be a PLTE if indexed";n=Math.ceil(e.readUInt32BE(25)/3)}if(f>256)throw"PNG width must not exceed 256";if(256===f&&(f=0),r>256)throw"PNG height must not exceed 256";256===r&&(r=0),i.writeUInt8(f,0),i.writeUInt8(r,1),i.writeUInt8(n,2),i.writeUInt8(0,3),i.writeUInt16LE(1,4),i.writeUInt16LE(s,6),i.writeUInt32LE(e.length,8),this._imageOffset+=16,this._buffer=Buffer.concat([this._buffer,i])}_writeICONDIRENTRY_bmp(t){const e=this._imageBuffers[t],i=Buffer.alloc(16);let f=e.readInt32LE(18),r=e.readInt32LE(22),s=e.readUInt16LE(26),n=e.readUInt32LE(46),h=e.readUInt16LE(28);if(f>256)throw"BMP width must not exceed 256";if(256===f&&(f=0),r>256)throw"BMP height must not exceed 256";if(256===r&&(r=0),1!==s)throw"BMP color planes must be 1";0===n&&32!==h&&(n=Math.pow(2,h)),n>256?n=0:256===n&&(n=255),i.writeUInt8(f,0),i.writeUInt8(r,1),i.writeUInt8(n,2),i.writeUInt8(0,3),i.writeUInt16LE(s,4),i.writeUInt16LE(h,6),i.writeUInt32LE(e.length-14,8),this._imageOffset+=16,this._buffer=Buffer.concat([this._buffer,i])}_writeICONDATA(t){let e=22*t+18;this._buffer.writeUInt32LE(this._imageOffset,e);const i=this._imageBuffers[t];137===i[0]&&80===i[1]&&78===i[2]&&71===i[3]?(this._buffer=Buffer.concat([this._buffer,i]),this._imageOffset+=i.length):(this._buffer=Buffer.concat([this._buffer,i.slice(14)]),this._imageOffset+=i.length-14)}}class i{constructor(){this._width=-1,this._height=-1,this._colors=-1,this._colorPlanes=-1,this._bitsPerPixel=-1,this._horizontalHotspot=-1,this._verticalHotspot=-1,this._imageSize=-1,this._imageOffset=-1,this._imageType=-1,this._imageData=null}get width(){return this._width}get height(){return this._height}get colors(){return this._colors}get colorPlanes(){return this._colorPlanes}get bitsPerPixel(){return this._bitsPerPixel}get horizontalHotspot(){return this._horizontalHotspot}get verticalHotspot(){return this._verticalHotspot}get imageSize(){return this._imageSize}get imageOffset(){return this._imageOffset}get imageType(){return this._imageType}get imageData(){return this._imageData}}class f{constructor(t){this._bufferOffset=0,this._buffer=t,this._iconEntries=[]}decode(){this._readICONDIR();for(let t=0;t<this._imageCount;t++)this._iconEntries[t]=new i,this._readICONDIRENTRY(t),this._readICONDATA(t);return this._iconEntries.map(t=>t.imageData)}_readICONDIR(){let t;if(t=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,0!==t)throw"Reserved must be 0";if(t=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,1!==t&&2!==t)throw"image type must be ICO or CUR";this._type=t,t=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,this._imageCount=t}_readICONDIRENTRY(t){let e;if(e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,this._iconEntries[t]._width=0===e?256:e,e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,this._iconEntries[t]._height=0===e?256:e,e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,this._iconEntries[t]._colors=e,e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,0!==e)throw"Reserved must be 0";if(e=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,1===this._type){if(0!==e&&1!==e)throw`Color plane was ${e}, should be 0 or 1`;this._iconEntries[t]._colorPlanes=e}else this._type===formatCUR&&(this._iconEntries[t]._horizontalHotspot=e);e=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,1===this._type?this._iconEntries[t]._bitsPerPixel=e:this._type===formatCUR&&(this._iconEntries[t]._verticalHotspot=e),e=this._buffer.readUInt32LE(this._bufferOffset),this._bufferOffset+=4,this._iconEntries[t]._imageSize=e,e=this._buffer.readUInt32LE(this._bufferOffset),this._bufferOffset+=4,this._iconEntries[t]._imageOffset=e}_readICONDATA(t){const e=this._iconEntries[t];let i=Buffer.from(this._buffer.buffer,e.imageOffset,e.imageSize);if(137===i[0]&&80===i[1]&&78===i[2]&&71===i[3])e._imageData=i,e._imageType="png";else{e._imageType="bmp";let t=i.readUInt32LE(0);i.writeInt32LE(e.width,4),i.writeInt32LE(e.height,8);let f=i.readUInt16LE(14),r=3===i.readUInt32LE(16),s=i.readUInt32LE(32);0===s&&32!==f&&(s=Math.pow(2,f));let n=t+(r?12:0)+s*(12===t?3:4),h=Buffer.alloc(14);h.writeUInt8(66,0),h.writeUInt8(77,1),h.writeUInt32LE(e.imageSize+14,2),h.writeUInt32LE(n+14,10),e._imageData=Buffer.concat([h,i])}}}t.Decoder=f,t.Encoder=e,t.decode=t=>{let e=new f(t);return e.decode(),e._iconEntries},t.encode=t=>(Array.isArray(t)||(t=[t]),new e(t).encode()),Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).icoEndec={})}(this,(function(t){"use strict";class e{constructor(t){this._imageBuffers=t.map(t=>{if(t instanceof ArrayBuffer)return Buffer.from(new Uint8Array(t));if(t instanceof Buffer)return t;throw"Encoder requires ArrayBuffers or Buffers"})}get buffer(){return this._buffer}encode(){this._buffer=Buffer.alloc(0),this._bufferOffset=0,this._imageOffset=0,this._writeICONDIR();for(let t=0;t<this._imageBuffers.length;t++)this._writeICONDIRENTRY(t);for(let t=0;t<this._imageBuffers.length;t++)this._writeICONDATA(t);return this._buffer}_writeICONDIR(){const t=Buffer.alloc(6);t.writeUInt16LE(0,0),t.writeUInt16LE(1,2),t.writeUInt16LE(this._imageBuffers.length,4),this._imageOffset+=6,this._buffer=Buffer.concat([this._buffer,t])}_writeICONDIRENTRY(t){const e=this._imageBuffers[t];137===e[0]&&80===e[1]&&78===e[2]&&71===e[3]?this._writeICONDIRENTRY_png(t):this._writeICONDIRENTRY_bmp(t)}_writeICONDIRENTRY_png(t){const e=this._imageBuffers[t],i=Buffer.alloc(16);if(73!==e[12]&&72!==e[13]&&68!==e[14]&&82!==e[15])throw"PNG's first chunk must be an IHDR";let f=e.readUInt32BE(16),r=e.readUInt32BE(20),s=e.readUInt8(24),n=0;if(3===e.readUInt8(25)){if("P"!==e[29]&&"L"!==e[30]&&"T"!==e[31]&&"E"!==e[32])throw"PNG's second chunk must be a PLTE if indexed";n=Math.ceil(e.readUInt32BE(25)/3)}if(f>256)throw"PNG width must not exceed 256";if(256===f&&(f=0),r>256)throw"PNG height must not exceed 256";256===r&&(r=0),i.writeUInt8(f,0),i.writeUInt8(r,1),i.writeUInt8(n,2),i.writeUInt8(0,3),i.writeUInt16LE(1,4),i.writeUInt16LE(s,6),i.writeUInt32LE(e.length,8),this._imageOffset+=16,this._buffer=Buffer.concat([this._buffer,i])}_writeICONDIRENTRY_bmp(t){const e=this._imageBuffers[t],i=Buffer.alloc(16);let f=e.readInt32LE(18),r=e.readInt32LE(22),s=e.readUInt16LE(26),n=e.readUInt32LE(46),h=e.readUInt16LE(28);if(f>256)throw"BMP width must not exceed 256";if(256===f&&(f=0),r>256)throw"BMP height must not exceed 256";if(256===r&&(r=0),1!==s)throw"BMP color planes must be 1";0===n&&32!==h&&(n=Math.pow(2,h)),n>256?n=0:256===n&&(n=255),i.writeUInt8(f,0),i.writeUInt8(r,1),i.writeUInt8(n,2),i.writeUInt8(0,3),i.writeUInt16LE(s,4),i.writeUInt16LE(h,6),i.writeUInt32LE(e.length-14,8),this._imageOffset+=16,this._buffer=Buffer.concat([this._buffer,i])}_writeICONDATA(t){let e=6+16*t+12;this._buffer.writeUInt32LE(this._imageOffset,e);const i=this._imageBuffers[t];137===i[0]&&80===i[1]&&78===i[2]&&71===i[3]?(this._buffer=Buffer.concat([this._buffer,i]),this._imageOffset+=i.length):(this._buffer=Buffer.concat([this._buffer,i.slice(14)]),this._imageOffset+=i.length-14)}}class i{constructor(){this._width=-1,this._height=-1,this._colors=-1,this._colorPlanes=-1,this._bitsPerPixel=-1,this._horizontalHotspot=-1,this._verticalHotspot=-1,this._imageSize=-1,this._imageOffset=-1,this._imageType=-1,this._imageData=null}get width(){return this._width}get height(){return this._height}get colors(){return this._colors}get colorPlanes(){return this._colorPlanes}get bitsPerPixel(){return this._bitsPerPixel}get horizontalHotspot(){return this._horizontalHotspot}get verticalHotspot(){return this._verticalHotspot}get imageSize(){return this._imageSize}get imageOffset(){return this._imageOffset}get imageType(){return this._imageType}get imageData(){return this._imageData}}class f{constructor(t){this._bufferOffset=0,this._buffer=t,this._iconEntries=[]}decode(){this._readICONDIR();for(let t=0;t<this._imageCount;t++)this._iconEntries[t]=new i,this._readICONDIRENTRY(t),this._readICONDATA(t);return this._iconEntries.map(t=>t.imageData)}_readICONDIR(){let t;if(t=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,0!==t)throw"Reserved must be 0";if(t=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,1!==t&&2!==t)throw"image type must be ICO or CUR";this._type=t,t=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,this._imageCount=t}_readICONDIRENTRY(t){let e;if(e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,this._iconEntries[t]._width=0===e?256:e,e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,this._iconEntries[t]._height=0===e?256:e,e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,this._iconEntries[t]._colors=e,e=this._buffer.readUInt8(this._bufferOffset),this._bufferOffset++,0!==e)throw"Reserved must be 0";if(e=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,1===this._type){if(0!==e&&1!==e)throw`Color plane was ${e}, should be 0 or 1`;this._iconEntries[t]._colorPlanes=e}else this._type===formatCUR&&(this._iconEntries[t]._horizontalHotspot=e);e=this._buffer.readUInt16LE(this._bufferOffset),this._bufferOffset+=2,1===this._type?this._iconEntries[t]._bitsPerPixel=e:this._type===formatCUR&&(this._iconEntries[t]._verticalHotspot=e),e=this._buffer.readUInt32LE(this._bufferOffset),this._bufferOffset+=4,this._iconEntries[t]._imageSize=e,e=this._buffer.readUInt32LE(this._bufferOffset),this._bufferOffset+=4,this._iconEntries[t]._imageOffset=e}_readICONDATA(t){const e=this._iconEntries[t];let i=Buffer.from(this._buffer.buffer,e.imageOffset,e.imageSize);if(137===i[0]&&80===i[1]&&78===i[2]&&71===i[3])e._imageData=i,e._imageType="png";else{e._imageType="bmp";let t=i.readUInt32LE(0);i.writeInt32LE(e.width,4),i.writeInt32LE(e.height,8);let f=i.readUInt16LE(14),r=3===i.readUInt32LE(16),s=i.readUInt32LE(32);0===s&&32!==f&&(s=Math.pow(2,f));let n=t+(r?12:0)+s*(12===t?3:4),h=Buffer.alloc(14);h.writeUInt8(66,0),h.writeUInt8(77,1),h.writeUInt32LE(e.imageSize+14,2),h.writeUInt32LE(n+14,10),e._imageData=Buffer.concat([h,i])}}}t.Decoder=f,t.Encoder=e,t.decode=t=>{let e=new f(t);return e.decode(),e._iconEntries},t.encode=t=>(Array.isArray(t)||(t=[t]),new e(t).encode()),Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "ico-endec", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41583