/*
* MIT License
*
* Copyright (c) 2017 Photopea
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
;(function(){
var UTIF = {};
// Make available for import by `require()`
if (typeof module == "object") {module.exports = UTIF;}
else {self.UTIF = UTIF;}
function log() { if (typeof process=="undefined" || process.env.NODE_ENV=="development") console.log.apply(console, arguments); }
(function(UTIF){
// Following lines add a JPEG decoder to UTIF.JpegDecoder
(function(){"use strict";var W=function a1(){function W(p){this.message="JPEG error: "+p}W.prototype=new Error;W.prototype.name="JpegError";W.constructor=W;return W}(),ak=function ag(){var p=new Uint8Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),t=4017,ac=799,ah=3406,ao=2276,ar=1567,ai=3784,s=5793,ad=2896;function ak(Q){if(Q==null)Q={};if(Q.w==null)Q.w=-1;this.V=Q.n;this.N=Q.w}function a5(Q,h){var f=0,G=[],n,E,a=16,F;while(a>0&&!Q[a-1]){a--}G.push({children:[],index:0});var C=G[0];for(n=0;n0){C=G.pop()}C.index++;G.push(C);while(G.length<=n){G.push(F={children:[],index:0});C.children[C.index]=F.children;C=F}f++}if(n+10){V--;return J>>V&1}J=Q[h++];if(J===255){var I=Q[h++];if(I){if(I===220&&d){h+=2;var l=Z(Q,h);h+=2;if(l>0&&l!==f.s){throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data",l)}}else if(I===217){if(d){var M=q*8;
if(M>0&&M>>7}function u(I){var l=I;while(!0){l=l[Y()];switch(typeof l){case"number":return l;case"object":continue}throw new W("invalid huffman sequence")}}function m(I){var e=0;while(I>0){e=e<<1|Y();I--}return e}function j(I){if(I===1){return Y()===1?1:-1}var e=m(I);if(e>=1<>4;if(i===0){if(A<15){break}N+=16;continue}N+=A;var o=p[N];X.D[I+o]=j(i);N++}}function $(X,I){var l=u(X.J),M=l===0?0:j(l)<0){r--;return}var N=E,l=a;while(N<=l){var M=u(X.i),S=M&15,i=M>>4;if(S===0){if(i<15){r=m(i)+(1<>4;if(S===0){if(M<15){r=m(M)+(1<0){for(O=0;O0?"unexpected":"excessive";h=k.offset}if(k.M>=65488&&k.M<=65495){h+=2}else{break}}return h-z}function al(Q,h,f){var G=Q.$,n=Q.D,E,a,C,F,d,T,U,z,J,V,Y,u,m,j,v,$,b;if(!G){throw new W("missing required Quantization Table.")}for(var r=0;r<64;r+=8){J=n[h+r];V=n[h+r+1];Y=n[h+r+2];u=n[h+r+3];m=n[h+r+4];j=n[h+r+5];v=n[h+r+6];$=n[h+r+7];J*=G[r];if((V|Y|u|m|j|v|$)===0){b=s*J+512>>10;f[r]=b;f[r+1]=b;f[r+2]=b;f[r+3]=b;f[r+4]=b;f[r+5]=b;f[r+6]=b;f[r+7]=b;continue}V*=G[r+1];Y*=G[r+2];u*=G[r+3];m*=G[r+4];j*=G[r+5];v*=G[r+6];$*=G[r+7];E=s*J+128>>8;a=s*m+128>>8;C=Y;F=v;d=ad*(V-$)+128>>8;z=ad*(V+$)+128>>8;
T=u<<4;U=j<<4;E=E+a+1>>1;a=E-a;b=C*ai+F*ar+128>>8;C=C*ar-F*ai+128>>8;F=b;d=d+U+1>>1;U=d-U;z=z+T+1>>1;T=z-T;E=E+F+1>>1;F=E-F;a=a+C+1>>1;C=a-C;b=d*ao+z*ah+2048>>12;d=d*ah-z*ao+2048>>12;z=b;b=T*ac+U*t+2048>>12;T=T*t-U*ac+2048>>12;U=b;f[r]=E+z;f[r+7]=E-z;f[r+1]=a+U;f[r+6]=a-U;f[r+2]=C+T;f[r+5]=C-T;f[r+3]=F+d;f[r+4]=F-d}for(var P=0;P<8;++P){J=f[P];V=f[P+8];Y=f[P+16];u=f[P+24];m=f[P+32];j=f[P+40];v=f[P+48];$=f[P+56];if((V|Y|u|m|j|v|$)===0){b=s*J+8192>>14;if(b<-2040){b=0}else if(b>=2024){b=255}else{b=b+2056>>4}n[h+P]=b;n[h+P+8]=b;n[h+P+16]=b;n[h+P+24]=b;n[h+P+32]=b;n[h+P+40]=b;n[h+P+48]=b;n[h+P+56]=b;continue}E=s*J+2048>>12;a=s*m+2048>>12;C=Y;F=v;d=ad*(V-$)+2048>>12;z=ad*(V+$)+2048>>12;T=u;U=j;E=(E+a+1>>1)+4112;a=E-a;b=C*ai+F*ar+2048>>12;C=C*ar-F*ai+2048>>12;F=b;d=d+U+1>>1;U=d-U;z=z+T+1>>1;T=z-T;E=E+F+1>>1;F=E-F;a=a+C+1>>1;C=a-C;b=d*ao+z*ah+2048>>12;d=d*ah-z*ao+2048>>12;z=b;
b=T*ac+U*t+2048>>12;T=T*t-U*ac+2048>>12;U=b;J=E+z;$=E-z;V=a+U;v=a-U;Y=C+T;j=C-T;u=F+d;m=F-d;if(J<16){J=0}else if(J>=4080){J=255}else{J>>=4}if(V<16){V=0}else if(V>=4080){V=255}else{V>>=4}if(Y<16){Y=0}else if(Y>=4080){Y=255}else{Y>>=4}if(u<16){u=0}else if(u>=4080){u=255}else{u>>=4}if(m<16){m=0}else if(m>=4080){m=255}else{m>>=4}if(j<16){j=0}else if(j>=4080){j=255}else{j>>=4}if(v<16){v=0}else if(v>=4080){v=255}else{v>>=4}if($<16){$=0}else if($>=4080){$=255}else{$>>=4}n[h+P]=J;
n[h+P+8]=V;n[h+P+16]=Y;n[h+P+24]=u;n[h+P+32]=m;n[h+P+40]=j;n[h+P+48]=v;n[h+P+56]=$}}function a0(Q,h){var f=h.P,G=h.c,n=new Int16Array(64);for(var E=0;E=G){return null}var E=Z(Q,h);if(E>=65472&&E<=65534){return{u:null,M:E,offset:h}}var a=Z(Q,n);while(!(a>=65472&&a<=65534)){if(++n>=G){return null}a=Z(Q,n)}return{u:E.toString(16),M:a,offset:n}}ak.prototype={parse(Q,h){if(h==null)h={};
var f=h.F,E=0,a=null,C=null,F,d,T=0;function G(){var o=Z(Q,E);E+=2;var B=E+o-2,V=an(Q,B,E);if(V&&V.u){B=V.offset}var ab=Q.subarray(E,B);E+=ab.length;return ab}function n(F){var o=Math.ceil(F.o/8/F.X),B=Math.ceil(F.s/8/F.B);for(var Y=0;Y>4===0){for(u=0;u<64;u++){b=p[u];P[b]=Q[E++]}}else if(r>>4===1){for(u=0;u<64;u++){b=p[u];P[b]=Z(Q,E);E+=2}}else{throw new W("DQT - invalid table spec")}U[r&15]=P}break;case 65472:case 65473:case 65474:if(F){throw new W("Only single frame JPEGs supported")}E+=2;F={};F.G=V===65473;F.Z=V===65474;F.precision=Q[E++];var D=Z(Q,E),a4,q=0,H=0;E+=2;F.s=f||D;F.o=Z(Q,E);E+=2;F.W=[];F._={};var a8=Q[E++];for(Y=0;Y>4,y=Q[E+1]&15;if(q>4===0?J:z)[_&15]=a5(N,K)}break;case 65501:E+=2;d=Z(Q,E);E+=2;break;case 65498:var x=++T===1&&!f,R;E+=2;var k=Q[E++],g=[];for(Y=0;Y>4];R.i=z[a6&15];g.push(R)}var I=Q[E++],l=Q[E++],M=Q[E++];try{var S=a7(Q,E,F,g,d,I,l,M>>4,M&15,x);E+=S}catch(ex){if(ex instanceof DNLMarkerError){return this.parse(Q,{F:ex.s})}else if(ex instanceof EOIMarkerError){break markerLoop}throw ex}break;case 65500:E+=4;break;case 65535:if(Q[E]!==255){E--}break;default:var i=an(Q,E-2,E-3);if(i&&i.u){E=i.offset;break}if(E>=Q.length-1){break markerLoop}throw new W("JpegImage.parse - unknown marker: "+V.toString(16))}V=Z(Q,E);E+=2}this.width=F.o;this.height=F.s;this.g=a;this.b=C;this.W=[];for(Y=0;Y>8)+P[J+1]}}}return v},get f(){if(this.b){return!!this.b.a}if(this.p===3){if(this.N===0){return!1}else if(this.W[0].index===82&&this.W[1].index===71&&this.W[2].index===66){return!1}return!0}if(this.N===1){return!0}return!1},z:function aj(Q){var h,f,G;
for(var n=0,E=Q.length;n4){throw new W("Unsupported color mode")}var E=this.Y(h,f,n);if(this.p===1&&G){var a=E.length,C=new Uint8ClampedArray(a*3),F=0;for(var d=0;d>24}function Z(p,t){return p[t]<<8|p[t+1]}function am(p,t){return(p[t]<<24|p[t+1]<<16|p[t+2]<<8|p[t+3])>>>0}UTIF.JpegDecoder=ak}());
//UTIF.JpegDecoder = PDFJS.JpegImage;
UTIF.encodeImage = function(rgba, w, h, metadata)
{
var idf = { "t256":[w], "t257":[h], "t258":[8,8,8,8], "t259":[1], "t262":[2], "t273":[1000], // strips offset
"t277":[4], "t278":[h], /* rows per strip */ "t279":[w*h*4], // strip byte counts
"t282":[[72,1]], "t283":[[72,1]], "t284":[1], "t286":[[0,1]], "t287":[[0,1]], "t296":[1], "t305": ["Photopea (UTIF.js)"], "t338":[1]
};
if (metadata) for (var i in metadata) idf[i] = metadata[i];
var prfx = new Uint8Array(UTIF.encode([idf]));
var img = new Uint8Array(rgba);
var data = new Uint8Array(1000+w*h*4);
for(var i=0; i probably not an image
img.isLE = id=="II";
img.width = img["t256"][0]; //delete img["t256"];
img.height = img["t257"][0]; //delete img["t257"];
var cmpr = img["t259"] ? img["t259"][0] : 1; //delete img["t259"];
var fo = img["t266"] ? img["t266"][0] : 1; //delete img["t266"];
if(img["t284"] && img["t284"][0]==2) log("PlanarConfiguration 2 should not be used!");
if(cmpr==7 && img["t258"] && img["t258"].length>3) img["t258"]=img["t258"].slice(0,3);
var spp = img["t277"]?img["t277"][0]:1;
var bps = img["t258"]?img["t258"][0]:1;
var bipp = bps*spp; // bits per pixel
/*
var bipp; // bits per pixel
if(img["t258"]) bipp = Math.min(32,img["t258"][0])*img["t258"].length;
else bipp = (img["t277"]?img["t277"][0]:1);
*/
// Some .NEF files have t258==14, even though they use 16 bits per pixel
if(cmpr==1 && img["t279"]!=null && img["t278"] && img["t262"][0]==32803) {
bipp = Math.round((img["t279"][0]*8)/(img.width*img["t278"][0]));
}
if(img["t50885"] && img["t50885"][0]==4) bipp = img["t258"][0]*3; // RAW_CANON_40D_SRAW_V103.CR2
var bipl = Math.ceil(img.width*bipp/8)*8;
var soff = img["t273"]; if(soff==null || img["t322"]) soff = img["t324"];
var bcnt = img["t279"]; if(cmpr==1 && soff.length==1) bcnt = [img.height*(bipl>>>3)]; if(bcnt==null || img["t322"]) bcnt = img["t325"];
//bcnt[0] = Math.min(bcnt[0], data.length); // Hasselblad, "RAW_HASSELBLAD_H3D39II.3FR"
var bytes = new Uint8Array(img.height*(bipl>>>3)), bilen = 0;
if(img["t322"]!=null) // tiled
{
var tw = img["t322"][0], th = img["t323"][0];
var tx = Math.floor((img.width + tw - 1) / tw);
var ty = Math.floor((img.height + th - 1) / th);
var tbuff = new Uint8Array(Math.ceil(tw*th*bipp/8)|0);
console.log("====", tx,ty);
for(var y=0; y>>3, bpl = Math.ceil(bps*noc*w/8);
// convert to Little Endian /*
if(bps==16 && !img.isLE && img["t33422"]==null) // not DNG
for(var y=0; y>>8)&255;
}
else if(noc==3) for(var j= 3; j> 3 ^ 0x3ff0;
return (buffer[byte] | buffer[byte + 1] << 8) >> (vpos & 7) & ~((-1) << bits);
}
}
// Raw Format 6
function getBufferDataRW6(i) {
return buffer[vpos + 15 - i];
}
function readPageRW6() {
bytes[0] = (getBufferDataRW6(0) << 6) | (getBufferDataRW6(1) >> 2); // 14 bit
bytes[1] = (((getBufferDataRW6(1) & 0x3) << 12) | (getBufferDataRW6(2) << 4) | (getBufferDataRW6(3) >> 4)) & 0x3fff;
bytes[2] = (getBufferDataRW6(3) >> 2) & 0x3;
bytes[3] = ((getBufferDataRW6(3) & 0x3) << 8) | getBufferDataRW6(4);
bytes[4] = (getBufferDataRW6(5) << 2) | (getBufferDataRW6(6) >> 6);
bytes[5] = ((getBufferDataRW6(6) & 0x3f) << 4) | (getBufferDataRW6(7) >> 4);
bytes[6] = (getBufferDataRW6(7) >> 2) & 0x3;
bytes[7] = ((getBufferDataRW6(7) & 0x3) << 8) | getBufferDataRW6(8);
bytes[8] = ((getBufferDataRW6(9) << 2) & 0x3fc) | (getBufferDataRW6(10) >> 6);
bytes[9] = ((getBufferDataRW6(10) << 4) | (getBufferDataRW6(11) >> 4)) & 0x3ff;
bytes[10] = (getBufferDataRW6(11) >> 2) & 0x3;
bytes[11] = ((getBufferDataRW6(11) & 0x3) << 8) | getBufferDataRW6(12);
bytes[12] = (((getBufferDataRW6(13) << 2) & 0x3fc) | getBufferDataRW6(14) >> 6) & 0x3ff;
bytes[13] = ((getBufferDataRW6(14) << 4) | (getBufferDataRW6(15) >> 4)) & 0x3ff;
vpos += 16;
byte = 0;
}
function readPageRw6_bps12() {
bytes[0] = (getBufferDataRW6(0) << 4) | (getBufferDataRW6(1) >> 4);
bytes[1] = (((getBufferDataRW6(1) & 0xf) << 8) | (getBufferDataRW6(2))) & 0xfff;
bytes[2] = (getBufferDataRW6(3) >> 6) & 0x3;
bytes[3] = ((getBufferDataRW6(3) & 0x3f) << 2) | (getBufferDataRW6(4) >> 6);
bytes[4] = ((getBufferDataRW6(4) & 0x3f) << 2) | (getBufferDataRW6(5) >> 6);
bytes[5] = ((getBufferDataRW6(5) & 0x3f) << 2) | (getBufferDataRW6(6) >> 6);
bytes[6] = (getBufferDataRW6(6) >> 4) & 0x3;
bytes[7] = ((getBufferDataRW6(6) & 0xf) << 4) | (getBufferDataRW6(7) >> 4);
bytes[8] = ((getBufferDataRW6(7) & 0xf) << 4) | (getBufferDataRW6(8) >> 4);
bytes[9] = ((getBufferDataRW6(8) & 0xf) << 4) | (getBufferDataRW6(9) >> 4);
bytes[10] = (getBufferDataRW6(9) >> 2) & 0x3;
bytes[11] = ((getBufferDataRW6(9) & 0x3) << 6) | (getBufferDataRW6(10) >> 2);
bytes[12] = ((getBufferDataRW6(10) & 0x3) << 6) | (getBufferDataRW6(11) >> 2);
bytes[13] = ((getBufferDataRW6(11) & 0x3) << 6) | (getBufferDataRW6(12) >> 2);
bytes[14] = getBufferDataRW6(12) & 0x3;
bytes[15] = getBufferDataRW6(13);
bytes[16] = getBufferDataRW6(14);
bytes[17] = getBufferDataRW6(15);
vpos += 16;
byte = 0;
}
// Main loop
function resetPredNonzeros(){
pred[0]=0; pred[1]=0;
nonz[0]=0; nonz[1]=0;
}
if (RW2_Format == 7) {
throw RW2_Format;
// Skatch of version 7
/*
var pixels_per_block = bitsPerSample == 14 ? 9 : 10;
rowbytes = 0|(rawWidth / pixels_per_block * 16);
for (row = 0; row < rawHeight - 15; row += 16) {
var rowstoread = Math.min(16, rawHeight - row);
var readlen = rowbytes*rowstoread;
buffer = new Uint8Array(image.slice(bidx, bidx+readlen));
vpos = 0;
bidx += readlen;
i = 0;
for (crow = 0; crow < rowstoread; crow++) {
idx = (row + crow) * rawWidth;
for (col = 0; col <= rawWidth - pixels_per_block; col += pixels_per_block) {
for(j=0; j < pixels_per_block; j++) bytes[j] = buffer[i++];
if (bitsPerSample == 12) {
result[idx ] = ((bytes[1] & 0xF) << 8) + bytes[0];
result[idx + 1] = 16 * bytes[2] + (bytes[1] >> 4);
result[idx + 2] = ((bytes[4] & 0xF) << 8) + bytes[3];
result[idx + 3] = 16 * bytes[5] + (bytes[4] >> 4);
result[idx + 4] = ((bytes[7] & 0xF) << 8) + bytes[6];
result[idx + 5] = 16 * bytes[8] + (bytes[7] >> 4);
result[idx + 6] = ((bytes[10] & 0xF) << 8) + bytes[9];
result[idx + 7] = 16 * bytes[11] + (bytes[10] >> 4);
result[idx + 8] = ((bytes[13] & 0xF) << 8) + bytes[12];
result[idx + 9] = 16 * bytes[14] + (bytes[13] >> 4);
} else if (bitsPerSample == 14) {
result[idx] = bytes[0] + ((bytes[1] & 0x3F) << 8);
result[idx + 1] = (bytes[1] >> 6) + 4 * (bytes[2]) + ((bytes[3] & 0xF) << 10);
result[idx + 2] = (bytes[3] >> 4) + 16 * (bytes[4]) + ((bytes[5] & 3) << 12);
result[idx + 3] = ((bytes[5] & 0xFC) >> 2) + (bytes[6] << 6);
result[idx + 4] = bytes[7] + ((bytes[8] & 0x3F) << 8);
result[idx + 5] = (bytes[8] >> 6) + 4 * bytes[9] + ((bytes[10] & 0xF) << 10);
result[idx + 6] = (bytes[10] >> 4) + 16 * bytes[11] + ((bytes[12] & 3) << 12);
result[idx + 7] = ((bytes[12] & 0xFC) >> 2) + (bytes[13] << 6);
result[idx + 8] = bytes[14] + ((bytes[15] & 0x3F) << 8);
}
}
}
}
*/
}
else if(RW2_Format == 6) {
var is12bit = bitsPerSample == 12,
readPageRw6Fn = is12bit ? readPageRw6_bps12 : readPageRW6,
pixelsPerBlock = is12bit ? 14 : 11,
pixelbase0 = is12bit ? 0x80 : 0x200,
pixelbase_compare = is12bit ? 0x800 : 0x2000,
spix_compare = is12bit ? 0x3fff : 0xffff,
pixel_mask = is12bit ? 0xfff : 0x3fff,
blocksperrow = rawWidth / pixelsPerBlock,
rowbytes = blocksperrow * 16,
bufferSize = is12bit ? 18 : 14;
for (row = 0; row < rawHeight - 15; row += 16) {
var rowstoread = Math.min(16, rawHeight - row);
var readlen = rowbytes*rowstoread;
buffer = new Uint8Array(img_buffer, off+bidx, readlen);//new Uint8Array(image.slice(bidx, bidx+readlen));
vpos = 0;
bidx += readlen;
for (crow = 0, col = 0; crow < rowstoread; crow++, col = 0) {
idx = (row + crow) * rawWidth;
for (var rblock = 0; rblock < blocksperrow; rblock++) {
readPageRw6Fn();
resetPredNonzeros();
sh=0; pixel_base=0;
for (i = 0; i < pixelsPerBlock; i++){
isOdd = i & 1;
if (i % 3 == 2) {
var base = byte < bufferSize ? bytes[byte++] : 0;
if (base == 3) base = 4;
pixel_base = pixelbase0 << base;
sh = 1 << base;
}
var epixel = byte < bufferSize ? bytes[byte++] : 0;
if (pred[isOdd]) {
epixel *= sh;
if (pixel_base < pixelbase_compare && nonz[isOdd] > pixel_base)
epixel += nonz[isOdd] - pixel_base;
nonz[isOdd] = epixel;
} else {
pred[isOdd] = epixel;
if (epixel)
nonz[isOdd] = epixel;
else
epixel = nonz[isOdd];
}
result[idx + col++] = (epixel - 0xf) <= spix_compare ? (epixel - 0xf) & spix_compare : ((epixel + 0x7ffffff1) >> 0x1f) & pixel_mask;
}
}
}
}
}
else if (RW2_Format == 5) {
var blockSize = bitsPerSample == 12 ? 10 : 9;
for (row = 0; row < rawHeight; row++) {
for (col = 0; col < rawWidth; col+=blockSize) {
getDataRaw(0);
// Tuhle podminku pouziva i RW2_Format 7
if (bitsPerSample == 12) {
result[idx++] = ((bytes[1] & 0xF) << 8) + bytes[0];
result[idx++] = 16 * bytes[2] + (bytes[1] >> 4);
result[idx++] = ((bytes[4] & 0xF) << 8) + bytes[3];
result[idx++] = 16 * bytes[5] + (bytes[4] >> 4);
result[idx++] = ((bytes[7] & 0xF) << 8) + bytes[6];
result[idx++] = 16 * bytes[8] + (bytes[7] >> 4);
result[idx++] = ((bytes[10] & 0xF) << 8) + bytes[9];
result[idx++] = 16 * bytes[11] + (bytes[10] >> 4);
result[idx++] = ((bytes[13] & 0xF) << 8) + bytes[12];
result[idx++] = 16 * bytes[14] + (bytes[13] >> 4);
} else if (bitsPerSample == 14) {
result[idx++] = bytes[0] + ((bytes[1] & 0x3F) << 8);
result[idx++] = (bytes[1] >> 6) + 4 * (bytes[2]) + ((bytes[3] & 0xF) << 10);
result[idx++] = (bytes[3] >> 4) + 16 * (bytes[4]) + ((bytes[5] & 3) << 12);
result[idx++] = ((bytes[5] & 0xFC) >> 2) + (bytes[6] << 6);
result[idx++] = bytes[7] + ((bytes[8] & 0x3F) << 8);
result[idx++] = (bytes[8] >> 6) + 4 * bytes[9] + ((bytes[10] & 0xF) << 10);
result[idx++] = (bytes[10] >> 4) + 16 * bytes[11] + ((bytes[12] & 3) << 12);
result[idx++] = ((bytes[12] & 0xFC) >> 2) + (bytes[13] << 6);
result[idx++] = bytes[14] + ((bytes[15] & 0x3F) << 8);
}
}
}
//console.log(result[1000000 - 1])
} else if(RW2_Format == 4) {
for (row = 0; row < rawHeight; row++){
for(col = 0; col < rawWidth; col++){
i = col % 14;
isOdd = i & 1;
if (i==0) resetPredNonzeros();
if (i%3 == 2)
sh = 4 >> (3 - getDataRaw(2));
if (nonz[isOdd]) {
j = getDataRaw(8);
if(j != 0){
pred[isOdd] -= 0x80 << sh;
if (pred[isOdd] < 0 || sh == 4)
pred[isOdd] &= ~((-1) << sh);
pred[isOdd] += j << sh;
}
} else {
nonz[isOdd] = getDataRaw(8);
if(nonz[isOdd] || i > 11)
pred[isOdd] = nonz[isOdd] << 4 | getDataRaw(4);
}
result[idx++] = pred[col & 1];
}
}
}
else throw RW2_Format;
}
UTIF.decode._decodeVC5 = function(){var x=[1,0,1,0,2,2,1,1,3,7,1,2,5,25,1,3,6,48,1,4,6,54,1,5,7,111,1,8,7,99,1,6,7,105,12,0,7,107,1,7,8,209,20,0,8,212,1,9,8,220,1,10,9,393,1,11,9,394,32,0,9,416,1,12,9,427,1,13,10,887,1,18,10,784,1,14,10,790,1,15,10,835,60,0,10,852,1,16,10,885,1,17,11,1571,1,19,11,1668,1,20,11,1669,100,0,11,1707,1,21,11,1772,1,22,12,3547,1,29,12,3164,1,24,12,3166,1,25,12,3140,1,23,12,3413,1,26,12,3537,1,27,12,3539,1,28,13,7093,1,35,13,6283,1,30,13,6331,1,31,13,6335,180,0,13,6824,1,32,13,7072,1,33,13,7077,320,0,13,7076,1,34,14,12565,1,36,14,12661,1,37,14,12669,1,38,14,13651,1,39,14,14184,1,40,15,28295,1,46,15,28371,1,47,15,25320,1,42,15,25336,1,43,15,25128,1,41,15,27300,1,44,15,28293,1,45,16,50259,1,48,16,50643,1,49,16,50675,1,50,16,56740,1,53,16,56584,1,51,16,56588,1,52,17,113483,1,61,17,113482,1,60,17,101285,1,55,17,101349,1,56,17,109205,1,57,17,109207,1,58,17,100516,1,54,17,113171,1,59,18,202568,1,62,18,202696,1,63,18,218408,1,64,18,218412,1,65,18,226340,1,66,18,226356,1,67,18,226358,1,68,19,402068,1,69,19,405138,1,70,19,405394,1,71,19,436818,1,72,19,436826,1,73,19,452714,1,75,19,452718,1,76,19,452682,1,74,20,804138,1,77,20,810279,1,78,20,810790,1,79,20,873638,1,80,20,873654,1,81,20,905366,1,82,20,905430,1,83,20,905438,1,84,21,1608278,1,85,21,1620557,1,86,21,1621582,1,87,21,1621583,1,88,21,1747310,1,89,21,1810734,1,90,21,1810735,1,91,21,1810863,1,92,21,1810879,1,93,22,3621725,1,99,22,3621757,1,100,22,3241112,1,94,22,3494556,1,95,22,3494557,1,96,22,3494622,1,97,22,3494623,1,98,23,6482227,1,102,23,6433117,1,101,23,6989117,1,103,23,6989119,1,105,23,6989118,1,104,23,7243449,1,106,23,7243512,1,107,24,13978233,1,111,24,12964453,1,109,24,12866232,1,108,24,14486897,1,113,24,13978232,1,110,24,14486896,1,112,24,14487026,1,114,24,14487027,1,115,25,25732598,1,225,25,25732597,1,189,25,25732596,1,188,25,25732595,1,203,25,25732594,1,202,25,25732593,1,197,25,25732592,1,207,25,25732591,1,169,25,25732590,1,223,25,25732589,1,159,25,25732522,1,235,25,25732579,1,152,25,25732575,1,192,25,25732489,1,179,25,25732573,1,201,25,25732472,1,172,25,25732576,1,149,25,25732488,1,178,25,25732566,1,120,25,25732571,1,219,25,25732577,1,150,25,25732487,1,127,25,25732506,1,211,25,25732548,1,125,25,25732588,1,158,25,25732486,1,247,25,25732467,1,238,25,25732508,1,163,25,25732552,1,228,25,25732603,1,183,25,25732513,1,217,25,25732587,1,168,25,25732520,1,122,25,25732484,1,128,25,25732562,1,249,25,25732505,1,187,25,25732504,1,186,25,25732483,1,136,25,25928905,1,181,25,25732560,1,255,25,25732500,1,230,25,25732482,1,135,25,25732555,1,233,25,25732568,1,222,25,25732583,1,145,25,25732481,1,134,25,25732586,1,167,25,25732521,1,248,25,25732518,1,209,25,25732480,1,243,25,25732512,1,216,25,25732509,1,164,25,25732547,1,140,25,25732479,1,157,25,25732544,1,239,25,25732574,1,191,25,25732564,1,251,25,25732478,1,156,25,25732546,1,139,25,25732498,1,242,25,25732557,1,133,25,25732477,1,162,25,25732515,1,213,25,25732584,1,165,25,25732514,1,212,25,25732476,1,227,25,25732494,1,198,25,25732531,1,236,25,25732530,1,234,25,25732529,1,117,25,25732528,1,215,25,25732527,1,124,25,25732526,1,123,25,25732525,1,254,25,25732524,1,253,25,25732523,1,148,25,25732570,1,218,25,25732580,1,146,25,25732581,1,147,25,25732569,1,224,25,25732533,1,143,25,25732540,1,184,25,25732541,1,185,25,25732585,1,166,25,25732556,1,132,25,25732485,1,129,25,25732563,1,250,25,25732578,1,151,25,25732501,1,119,25,25732502,1,193,25,25732536,1,176,25,25732496,1,245,25,25732553,1,229,25,25732516,1,206,25,25732582,1,144,25,25732517,1,208,25,25732558,1,137,25,25732543,1,241,25,25732466,1,237,25,25732507,1,190,25,25732542,1,240,25,25732551,1,131,25,25732554,1,232,25,25732565,1,252,25,25732475,1,171,25,25732493,1,205,25,25732492,1,204,25,25732491,1,118,25,25732490,1,214,25,25928904,1,180,25,25732549,1,126,25,25732602,1,182,25,25732539,1,175,25,25732545,1,141,25,25732559,1,138,25,25732537,1,177,25,25732534,1,153,25,25732503,1,194,25,25732606,1,160,25,25732567,1,121,25,25732538,1,174,25,25732497,1,246,25,25732550,1,130,25,25732572,1,200,25,25732474,1,170,25,25732511,1,221,25,25732601,1,196,25,25732532,1,142,25,25732519,1,210,25,25732495,1,199,25,25732605,1,155,25,25732535,1,154,25,25732499,1,244,25,25732510,1,220,25,25732600,1,195,25,25732607,1,161,25,25732604,1,231,25,25732473,1,173,25,25732599,1,226,26,51465122,1,116,26,51465123,0,1],o,C,k,P=[3,3,3,3,2,2,2,1,1,1],V=24576,ar=16384,H=8192,az=ar|H;
function d(t){var E=t[1],h=t[0][E>>>3]>>>7-(E&7)&1;t[1]++;return h}function ag(t,E){if(o==null){o={};
for(var h=0;h>>1}return t}function A(t,E){return t>>E}function O(t,E,h,L,g,n){E[h]=A(A(11*t[g]-4*t[g+n]+t[g+n+n]+4,3)+t[L],1);
E[h+n]=A(A(5*t[g]+4*t[g+n]-t[g+n+n]+4,3)-t[L],1)}function J(t,E,h,L,g,n){var W=t[g-n]-t[g+n],j=t[g],$=t[L];
E[h]=A(A(W+4,3)+j+$,1);E[h+n]=A(A(-W+4,3)+j-$,1)}function y(t,E,h,L,g,n){E[h]=A(A(5*t[g]+4*t[g-n]-t[g-n-n]+4,3)+t[L],1);
E[h+n]=A(A(11*t[g]-4*t[g-n]+t[g-n-n]+4,3)-t[L],1)}function q(t){t=t<0?0:t>4095?4095:t;t=k[t]>>>2;return t}function av(t,E,h,L,g,n){L=new Uint16Array(L.buffer);
var W=Date.now(),j=UTIF._binBE,$=E+h,r,u,X,I,ax,a3,R,ai,aa,ap,ah,ae,aD,al,i,aE,T,B;E+=4;var a5=n[0]==1;
while(E<$){var S=j.readShort(t,E),s=j.readUshort(t,E+2);E+=4;if(S==12)r=s;else if(S==20)u=s;else if(S==21)X=s;
else if(S==48)I=s;else if(S==53)ax=s;else if(S==35)a3=s;else if(S==62)R=s;else if(S==101)ai=s;else if(S==109)aa=s;
else if(S==84)ap=s;else if(S==106)ah=s;else if(S==107)ae=s;else if(S==108)aD=s;else if(S==102)al=s;else if(S==104)i=s;
else if(S==105)aE=s;else{var F=S<0?-S:S,D=F&65280,_=0;if(F&az){if(F&H){_=s&65535;_+=(F&255)<<16}else{_=s&65535}}if((F&V)==V){if(T==null){T=[];
for(var M=0;M<4;M++)T[M]=new Int16Array((u>>>1)*(X>>>1));B=new Int16Array((u>>>1)*(X>>>1));C=new Int16Array(1024);
for(var M=0;M<1024;M++){var aG=M-512,p=Math.abs(aG),r=Math.floor(768*p*p*p/(255*255*255))+p;C[M]=Math.sign(aG)*r}k=new Uint16Array(4096);
var aA=(1<<16)-1;for(var M=0;M<4096;M++){var at=M,a1=aA*(Math.pow(113,at/4095)-1)/112;k[M]=Math.min(a1,aA)}}var w=T[R],v=m(u,1+P[I]),N=m(X,1+P[I]);
if(I==0){for(var b=0;b>>1)+G]=t[c]<<8|t[c+1]}}else{var a7=[t,E*8],a4=[],ay=0,aw=v*N,f=[0,0],Q=0,s=0;
while(ay0){a4[ay++]=s;Q--}}var l=(I-1)%3,aF=l!=1?v:0,a2=l!=0?N:0;
for(var b=0;b>>1)+aF,au=b*v;for(var G=0;G>>1,an=v*2,a9=N*2;
for(var b=0;b>14-K*2&3;var a6=aC[aB];if(a6!=0)for(var b=0;b>>1)*(u>>>1)+(G>>>1),z=a8[c],ao=ab[c]-2048,ak=aq[c]-2048,ad=as[c]-2048,aj=(ao<<1)+z,a0=(ak<<1)+z,aH=z+ad,am=z-ad;
if(a5){L[U]=q(aH);L[U+1]=q(a0);L[U+u]=q(aj);L[U+u+1]=q(am)}else{L[U]=q(aj);L[U+1]=q(aH);L[U+u]=q(am);
L[U+u+1]=q(a0)}}}E+=_*4}else if(F==16388){E+=_*4}else if(D==8192||D==8448||D==9216){}else throw F.toString(16)}}console.log(Date.now()-W)}return av}()
UTIF.decode._decodeLogLuv32 = function(img, data, off, len, tgt, toff) {
var w = img.width, qw=w*4;
var io = 0, out = new Uint8Array(qw);
while(io>> (tab[i] >>> 8);
for(var c=0; c>>4); tgt[toff+i+1]=(b0<<4)|(b2>>>4); tgt[toff+i+2]=(b2<<4)|(b1>>>4); }
return;
}
var pix = new Uint16Array(16);
var row, col, val, max, min, imax, imin, sh, bit, i, dp;
var data = new Uint8Array(raw_width+1);
for (row=0; row < height; row++) {
//fread (data, 1, raw_width, ifp);
for(var j=0; j>> 11);
imax = 0x0f & (val >>> 22);
imin = 0x0f & (val >>> 26);
for (sh=0; sh < 4 && 0x80 << sh <= max-min; sh++);
for (bit=30, i=0; i < 16; i++)
if (i == imax) pix[i] = max;
else if (i == imin) pix[i] = min;
else {
pix[i] = ((bin.readUshort(data, dp+(bit >> 3)) >>> (bit & 7) & 0x7f) << sh) + min;
if (pix[i] > 0x7ff) pix[i] = 0x7ff;
bit += 7;
}
for (i=0; i < 16; i++, col+=2) {
//RAW(row,col) = curve[pix[i] << 1] >> 2;
var clr = pix[i]<<1; //clr = 0xffff;
UTIF.decode._putsF(tgt, (row*raw_width+col)*tiff_bps, clr<<(16-tiff_bps));
}
col -= col & 1 ? 1:31;
}
}
}
UTIF.decode._decodeNikon = function(img,imgs, data, off, src_length, tgt, toff)
{
var nikon_tree = [
[ 0, 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy */
5,4,3,6,2,7,1,0,8,9,11,10,12 ],
[ 0, 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0, /* 12-bit lossy after split */
0x39,0x5a,0x38,0x27,0x16,5,4,3,2,1,0,11,12,12 ],
[ 0, 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, /* 12-bit lossless */
5,4,6,3,7,2,8,1,9,0,10,11,12 ],
[ 0, 0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0, /* 14-bit lossy */
5,6,4,7,8,3,9,2,1,0,10,11,12,13,14 ],
[ 0, 0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0, /* 14-bit lossy after split */
8,0x5c,0x4b,0x3a,0x29,7,6,5,4,3,2,1,0,13,14 ],
[ 0, 0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0, /* 14-bit lossless */
7,6,8,5,9,4,10,3,11,12,2,0,1,13,14 ] ];
var raw_width = img["t256"][0], height=img["t257"][0], tiff_bps=img["t258"][0];
var tree = 0, split = 0;
var make_decoder = UTIF.decode._make_decoder;
var getbithuff = UTIF.decode._getbithuff;
var mn = imgs[0].exifIFD.makerNote, md = mn["t150"]?mn["t150"]:mn["t140"], mdo=0; //console.log(mn,md);
//console.log(md[0].toString(16), md[1].toString(16), tiff_bps);
var ver0 = md[mdo++], ver1 = md[mdo++];
if (ver0 == 0x49 || ver1 == 0x58) mdo+=2110;
if (ver0 == 0x46) tree = 2;
if (tiff_bps == 14) tree += 3;
var vpred = [[0,0],[0,0]], bin=(img.isLE ? UTIF._binLE : UTIF._binBE);
for(var i=0; i<2; i++) for(var j=0; j<2; j++) { vpred[i][j] = bin.readShort(md,mdo); mdo+=2; } // not sure here ... [i][j] or [j][i]
//console.log(vpred);
var max = 1 << tiff_bps & 0x7fff, step=0;
var csize = bin.readShort(md,mdo); mdo+=2;
if (csize > 1) step = Math.floor(max / (csize-1));
if (ver0 == 0x44 && ver1 == 0x20 && step > 0) split = bin.readShort(md,562);
var i;
var row, col;
var len, shl, diff;
var min_v = 0;
var hpred = [0,0];
var huff = make_decoder(nikon_tree[tree]);
//var g_input_offset=0, bitbuf=0, vbits=0, reset=0;
var prm = [off,0,0,0];
//console.log(split); split = 170;
for (min_v=row=0; row < height; row++) {
if (split && row == split) {
//free (huff);
huff = make_decoder (nikon_tree[tree+1]);
//max_v += (min_v = 16) << 1;
}
for (col=0; col < raw_width; col++) {
i = getbithuff(data,prm,huff[0],huff);
len = i & 15;
shl = i >>> 4;
diff = (((getbithuff(data,prm,len-shl,0) << 1) + 1) << shl) >>> 1;
if ((diff & (1 << (len-1))) == 0)
diff -= (1 << len) - (shl==0?1:0);
if (col < 2) hpred[col] = vpred[row & 1][col] += diff;
else hpred[col & 1] += diff;
var clr = Math.min(Math.max(hpred[col & 1],0),(1<>>3); dt[o]|=val>>>16; dt[o+1]|=val>>>8; dt[o+2]|=val; }
UTIF.decode._getbithuff = function(data,prm,nbits, huff) {
var zero_after_ff = 0;
var get_byte = UTIF.decode._get_byte;
var c;
var off=prm[0], bitbuf=prm[1], vbits=prm[2], reset=prm[3];
//if (nbits > 25) return 0;
//if (nbits < 0) return bitbuf = vbits = reset = 0;
if (nbits == 0 || vbits < 0) return 0;
while (!reset && vbits < nbits && (c = data[off++]) != -1 &&
!(reset = zero_after_ff && c == 0xff && data[off++])) {
//console.log("byte read into c");
bitbuf = (bitbuf << 8) + c;
vbits += 8;
}
c = (bitbuf << (32-vbits)) >>> (32-nbits);
if (huff) {
vbits -= huff[c+1] >>> 8; //console.log(c, huff[c]>>8);
c = huff[c+1]&255;
} else
vbits -= nbits;
if (vbits < 0) throw "e";
prm[0]=off; prm[1]=bitbuf; prm[2]=vbits; prm[3]=reset;
return c;
}
UTIF.decode._make_decoder = function(source) {
var max, len, h, i, j;
var huff = [];
for (max=16; max!=0 && !source[max]; max--);
var si=17;
huff[0] = max;
for (h=len=1; len <= max; len++)
for (i=0; i < source[len]; i++, ++si)
for (j=0; j < 1 << (max-len); j++)
if (h <= 1 << max)
huff[h++] = (len << 8) | source[si];
return huff;
}
UTIF.decode._decodeNewJPEG = function(img, data, off, len, tgt, toff)
{
len = Math.min(len, data.length-off);
var tables = img["t347"], tlen = tables ? tables.length : 0, buff = new Uint8Array(tlen + len);
if (tables) {
var SOI = 216, EOI = 217, boff = 0;
for (var i=0; i<(tlen-1); i++)
{
// Skip EOI marker from JPEGTables
if (tables[i]==255 && tables[i+1]==EOI) break;
buff[boff++] = tables[i];
}
// Skip SOI marker from data
var byte1 = data[off], byte2 = data[off + 1];
if (byte1!=255 || byte2!=SOI)
{
buff[boff++] = byte1;
buff[boff++] = byte2;
}
for (var i=2; i>>8); }
else for(var i=0; i>>8); tgt[toff+(i<<1)+1] = (out[i]&255); }
}
else if(bps==14 || bps==12 || bps==10) { // 4 * 14 == 56 == 7 * 8
var rst = 16-bps;
for(var i=0; i 1);
}
if(!isTiled)
{
if(data[off]==255 && data[off+1]==SOI) return { jpegOffset: off };
if(jpgIchgFmt!=null)
{
if(data[off+jifoff]==255 && data[off+jifoff+1]==SOI) joff = off+jifoff;
else log("JPEGInterchangeFormat does not point to SOI");
if(jpgIchgFmtLen==null) log("JPEGInterchangeFormatLength field is missing");
else if(jifoff >= soff || (jifoff+jiflen) <= soff) log("JPEGInterchangeFormatLength field value is invalid");
if(joff != null) return { jpegOffset: joff };
}
}
if(ycbcrss!=null) { ssx = ycbcrss[0]; ssy = ycbcrss[1]; }
if(jpgIchgFmt!=null)
if(jpgIchgFmtLen!=null)
if(jiflen >= 2 && (jifoff+jiflen) <= soff)
{
if(data[off+jifoff+jiflen-2]==255 && data[off+jifoff+jiflen-1]==SOI) tables = new Uint8Array(jiflen-2);
else tables = new Uint8Array(jiflen);
for(i=0; i offset to first strip or tile");
if(tables == null)
{
var ooff = 0, out = [];
out[ooff++] = 255; out[ooff++] = SOI;
var qtables = img["t519"];
if(qtables==null) throw new Error("JPEGQTables tag is missing");
for(i=0; i>> 8); out[ooff++] = nc & 255;
out[ooff++] = (i | (k << 4));
for(j=0; j<16; j++) out[ooff++] = data[off+htables[i]+j];
for(j=0; j>> 8) & 255; out[ooff++] = img.height & 255;
out[ooff++] = (img.width >>> 8) & 255; out[ooff++] = img.width & 255;
out[ooff++] = spp;
if(spp==1) { out[ooff++] = 1; out[ooff++] = 17; out[ooff++] = 0; }
else for(i=0; i<3; i++)
{
out[ooff++] = i + 1;
out[ooff++] = (i != 0) ? 17 : (((ssx & 15) << 4) | (ssy & 15));
out[ooff++] = i;
}
if(jpgresint!=null && jpgresint[0]!=0)
{
out[ooff++] = 255; out[ooff++] = DRI; out[ooff++] = 0; out[ooff++] = 4;
out[ooff++] = (jpgresint[0] >>> 8) & 255;
out[ooff++] = jpgresint[0] & 255;
}
tables = new Uint8Array(out);
}
var sofpos = -1;
i = 0;
while(i < (tables.length - 1)) {
if(tables[i]==255 && tables[i+1]==SOF0) { sofpos = i; break; }
i++;
}
if(sofpos == -1)
{
var tmptab = new Uint8Array(tables.length + 10 + 3*spp);
tmptab.set(tables);
var tmpoff = tables.length;
sofpos = tables.length;
tables = tmptab;
tables[tmpoff++] = 255; tables[tmpoff++] = SOF0;
tables[tmpoff++] = 0; tables[tmpoff++] = 8 + 3*spp; tables[tmpoff++] = 8;
tables[tmpoff++] = (img.height >>> 8) & 255; tables[tmpoff++] = img.height & 255;
tables[tmpoff++] = (img.width >>> 8) & 255; tables[tmpoff++] = img.width & 255;
tables[tmpoff++] = spp;
if(spp==1) { tables[tmpoff++] = 1; tables[tmpoff++] = 17; tables[tmpoff++] = 0; }
else for(i=0; i<3; i++)
{
tables[tmpoff++] = i + 1;
tables[tmpoff++] = (i != 0) ? 17 : (((ssx & 15) << 4) | (ssy & 15));
tables[tmpoff++] = i;
}
}
if(data[soff]==255 && data[soff+1]==SOS)
{
var soslen = (data[soff+2]<<8) | data[soff+3];
sosMarker = new Uint8Array(soslen+2);
sosMarker[0] = data[soff]; sosMarker[1] = data[soff+1]; sosMarker[2] = data[soff+2]; sosMarker[3] = data[soff+3];
for(i=0; i<(soslen-2); i++) sosMarker[i+4] = data[soff+i+4];
}
else
{
sosMarker = new Uint8Array(2 + 6 + 2*spp);
var sosoff = 0;
sosMarker[sosoff++] = 255; sosMarker[sosoff++] = SOS;
sosMarker[sosoff++] = 0; sosMarker[sosoff++] = 6 + 2*spp; sosMarker[sosoff++] = spp;
if(spp==1) { sosMarker[sosoff++] = 1; sosMarker[sosoff++] = 0; }
else for(i=0; i<3; i++)
{
sosMarker[sosoff++] = i+1; sosMarker[sosoff++] = (i << 4) | i;
}
sosMarker[sosoff++] = 0; sosMarker[sosoff++] = 63; sosMarker[sosoff++] = 0;
}
return { jpegOffset: off, tables: tables, sosMarker: sosMarker, sofPosition: sofpos };
}
UTIF.decode._decodeOldJPEG = function(img, data, off, len, tgt, toff)
{
var i, dlen, tlen, buff, buffoff;
var jpegData = UTIF.decode._decodeOldJPEGInit(img, data, off, len);
if(jpegData.jpegOffset!=null)
{
dlen = off+len-jpegData.jpegOffset;
buff = new Uint8Array(dlen);
for(i=0; i>> 8) & 255; buff[jpegData.sofPosition+6] = img.height & 255;
buff[jpegData.sofPosition+7] = (img.width >>> 8) & 255; buff[jpegData.sofPosition+8] = img.width & 255;
if(data[off]!=255 || data[off+1]!=SOS)
{
buff.set(jpegData.sosMarker, buffoff);
buffoff += sosMarker.length;
}
for(i=0; i=0 && n<128) for(var i=0; i< n+1; i++) { ta[toff]=sa[off]; toff++; off++; }
if(n>=-127 && n<0) { for(var i=0; i<-n+1; i++) { ta[toff]=sa[off]; toff++; } off++; }
}
return toff;
}
UTIF.decode._decodeThunder = function(data, off, len, tgt, toff)
{
var d2 = [ 0, 1, 0, -1 ], d3 = [ 0, 1, 2, 3, 0, -3, -2, -1 ];
var lim = off+len, qoff = toff*2, px = 0;
while(off>>6), n = (b&63); off++;
if(msk==3) { px=(n&15); tgt[qoff>>>1] |= (px<<(4*(1-qoff&1))); qoff++; }
if(msk==0) for(var i=0; i>>1] |= (px<<(4*(1-qoff&1))); qoff++; }
if(msk==2) for(var i=0; i<2; i++) { var d=(n>>>(3*(1-i)))&7; if(d!=4) { px+=d3[d]; tgt[qoff>>>1] |= (px<<(4*(1-qoff&1))); qoff++; } }
if(msk==1) for(var i=0; i<3; i++) { var d=(n>>>(2*(2-i)))&3; if(d!=2) { px+=d2[d]; tgt[qoff>>>1] |= (px<<(4*(1-qoff&1))); qoff++; } }
}
}
UTIF.decode._dmap = { "1":0,"011":1,"000011":2,"0000011":3, "010":-1,"000010":-2,"0000010":-3 };
UTIF.decode._lens = ( function()
{
var addKeys = function(lens, arr, i0, inc) { for(var i=0; i>>3)>>3]>>>(7-(boff&7)))&1;
if(fo==2) bit = (data[boff>>>3]>>>( (boff&7)))&1;
boff++; wrd+=bit;
if(mode=="H")
{
if(U._lens[clr][wrd]!=null)
{
var dl=U._lens[clr][wrd]; wrd=""; len+=dl;
if(dl<64) { U._addNtimes(line,len,clr); a0+=len; clr=1-clr; len=0; toRead--; if(toRead==0) mode=""; }
}
}
else
{
if(wrd=="0001") { wrd=""; U._addNtimes(line,b2-a0,clr); a0=b2; }
if(wrd=="001" ) { wrd=""; mode="H"; toRead=2; }
if(U._dmap[wrd]!=null) { a1 = b1+U._dmap[wrd]; U._addNtimes(line, a1-a0, clr); a0=a1; wrd=""; clr=1-clr; }
}
if(line.length==w && mode=="")
{
U._writeBits(line, tgt, toff*8+y*bipl);
clr=0; y++; a0=0;
pline=U._makeDiff(line); line=[];
}
//if(wrd.length>150) { log(wrd); break; throw "e"; }
}
}
UTIF.decode._findDiff = function(line, x, clr) { for(var i=0; i=x && line[i+1]==clr) return line[i]; }
UTIF.decode._makeDiff = function(line)
{
var out = []; if(line[0]==1) out.push(0,1);
for(var i=1; i>>3)>>3]>>>(7-(boff&7)))&1;
if(fo==2) bit = (data[boff>>>3]>>>( (boff&7)))&1;
boff++; wrd+=bit;
len = U._lens[clr][wrd];
if(len!=null) {
U._addNtimes(line,len,clr); wrd="";
if(len<64) clr = 1-clr;
if(line.length==w) { U._writeBits(line, tgt, toff*8+y*bipl); line=[]; y++; clr=0; if((boff&7)!=0) boff+=8-(boff&7); if(len>=64) boff+=8; }
}
}
}
UTIF.decode._decodeG3 = function(data, off, slen, tgt, toff, w, fo, twoDim)
{
var U = UTIF.decode, boff=off<<3, len=0, wrd="";
var line=[], pline=[]; for(var i=0; i>>3)>>3]>>>(7-(boff&7)))&1;
if(fo==2) bit = (data[boff>>>3]>>>( (boff&7)))&1;
boff++; wrd+=bit;
if(is1D)
{
if(U._lens[clr][wrd]!=null)
{
var dl=U._lens[clr][wrd]; wrd=""; len+=dl;
if(dl<64) { U._addNtimes(line,len,clr); clr=1-clr; len=0; }
}
}
else
{
if(mode=="H")
{
if(U._lens[clr][wrd]!=null)
{
var dl=U._lens[clr][wrd]; wrd=""; len+=dl;
if(dl<64) { U._addNtimes(line,len,clr); a0+=len; clr=1-clr; len=0; toRead--; if(toRead==0) mode=""; }
}
}
else
{
if(wrd=="0001") { wrd=""; U._addNtimes(line,b2-a0,clr); a0=b2; }
if(wrd=="001" ) { wrd=""; mode="H"; toRead=2; }
if(U._dmap[wrd]!=null) { a1 = b1+U._dmap[wrd]; U._addNtimes(line, a1-a0, clr); a0=a1; wrd=""; clr=1-clr; }
}
}
if(wrd.endsWith("000000000001")) // needed for some files
{
if(y>=0) U._writeBits(line, tgt, toff*8+y*bipl);
if(twoDim) {
if(fo==1) is1D = ((data[boff>>>3]>>>(7-(boff&7)))&1)==1;
if(fo==2) is1D = ((data[boff>>>3]>>>( (boff&7)))&1)==1;
boff++;
}
//log("EOL",y, "next 1D:", is1D);
wrd=""; clr=0; y++; a0=0;
pline=U._makeDiff(line); line=[];
}
}
if(line.length==w) U._writeBits(line, tgt, toff*8+y*bipl);
}
UTIF.decode._addNtimes = function(arr, n, val) { for(var i=0; i>>3] |= (bits[i]<<(7-((boff+i)&7)));
}
UTIF.decode._decodeLZW=UTIF.decode._decodeLZW=function(){var e,U,Z,u,K=0,V=0,g=0,N=0,O=function(){var S=e>>>3,A=U[S]<<16|U[S+1]<<8|U[S+2],j=A>>>24-(e&7)-V&(1<>>----------------");
for(var i=0; idata.buffer.byteLength) num=data.buffer.byteLength-no; arr = new Uint8Array(data.buffer, no, num); }
if(type== 2) { var o0 = (num<5 ? offset-4 : voff), c=data[o0], len=Math.max(0, Math.min(num-1,data.length-o0));
if(c<128 || len==0) arr.push( bin.readASCII(data, o0, len) );
else arr = new Uint8Array(data.buffer, o0, len); }
if(type== 3) { for(var j=0; j4) { bin.writeUint(data, offset, eoff); toff=eoff; }
if (type== 1 || type==7) { for(var i=0; i4) { dlen += (dlen&1); eoff += dlen; }
offset += 4;
}
return [offset, eoff];
}
UTIF.toRGBA8 = function(out, scl)
{
function gamma(x) { return x < 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1.0 / 2.4) - 0.055; }
var w = out.width, h = out.height, area = w*h, qarea = area*4, data = out.data;
var img = new Uint8Array(area*4);
//console.log(out);
// 0: WhiteIsZero, 1: BlackIsZero, 2: RGB, 3: Palette color, 4: Transparency mask, 5: CMYK
var intp = (out["t262"] ? out["t262"][0]: 2), bps = (out["t258"]?Math.min(32,out["t258"][0]):1);
if(out["t262"]==null && bps==1) intp=0;
var smpls = out["t277"]?out["t277"][0] : (out["t258"]?out["t258"].length : [1,1,3,1,1,4,3][intp]);
var sfmt = out["t339"]?out["t339"][0] : null; if(intp==1 && bps==32 && sfmt!=3) throw "e"; // sample format
var bpl = Math.ceil(smpls*bps*w/8);
//log("interpretation: ", intp, "smpls", smpls, "bps", bps, "sample format",sfmt, out);
if(false) {}
else if(intp==0)
{
scl = 1/256; // "Photopeatest.tif"
for(var y=0; y>3)])>>(7- (i&7)))& 1; img[qi]=img[qi+1]=img[qi+2]=( 1-px)*255; img[qi+3]=255; }
if(bps== 4) for(var i=0; i>1)])>>(4-4*(i&1)))&15; img[qi]=img[qi+1]=img[qi+2]=(15-px)* 17; img[qi+3]=255; }
if(bps== 8) for(var i=0; i>3)])>>(7- (i&7)))&1; img[qi]=img[qi+1]=img[qi+2]=(px)*255; img[qi+3]=255; }
if(bps== 2) for(var i=0; i>2)])>>(6-2*(i&3)))&3; img[qi]=img[qi+1]=img[qi+2]=(px)* 85; img[qi+3]=255; }
if(bps== 8) for(var i=0; i>>2)+i, px=f32[o]; img[qi]=img[qi+1]=img[qi+2]= ~~(0.5+255*px); img[qi+3]=255; }
}
}
else if(intp==2)
{
if(bps== 8)
{
if(smpls==1) for(var i=0; i=4) for(var i=0; i1 && out["t338"] && out["t338"][0]!=0;
for(var y=0; y>>3)]>>>(7- (x&7)))& 1;
else if(bps==2) mi=(data[dof+(x>>>2)]>>>(6-2*(x&3)))& 3;
else if(bps==4) mi=(data[dof+(x>>>1)]>>>(4-4*(x&1)))&15;
else if(bps==8) mi= data[dof+x*smpls];
else throw bps;
img[qi]=(map[mi]>>8); img[qi+1]=(map[cn+mi]>>8); img[qi+2]=(map[cn+cn+mi]>>8); img[qi+3]=nexta ? data[dof+x*smpls+1] : 255;
}
}
else if(intp==5)
{
var gotAlpha = smpls>4 ? 1 : 0;
for(var i=0; i>>1);
var Y = data[si+(j&1)], Cb=data[si+2]-128, Cr=data[si+3]-128;
var r = Y + ( (Cr >> 2) + (Cr >> 3) + (Cr >> 5) ) ;
var g = Y - ( (Cb >> 2) + (Cb >> 4) + (Cb >> 5)) - ( (Cr >> 1) + (Cr >> 3) + (Cr >> 4) + (Cr >> 5)) ;
var b = Y + ( Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6)) ;
img[qi ]=Math.max(0,Math.min(255,r));
img[qi+1]=Math.max(0,Math.min(255,g));
img[qi+2]=Math.max(0,Math.min(255,b));
img[qi+3]=255;
}
}
}
else if(intp==32845) {
for(var y=0; yma) { ma=ar; page=img; }
}
UTIF.decodeImage(buff, page, ifds);
var rgba = UTIF.toRGBA8(page), w=page.width, h=page.height;
var cnv = document.createElement("canvas"); cnv.width=w; cnv.height=h;
var ctx = cnv.getContext("2d");
var imgd = new ImageData(new Uint8ClampedArray(rgba.buffer),w,h);
ctx.putImageData(imgd,0,0);
return cnv.toDataURL();
}
UTIF._binBE =
{
nextZero : function(data, o) { while(data[o]!=0) o++; return o; },
readUshort : function(buff, p) { return (buff[p]<< 8) | buff[p+1]; },
readShort : function(buff, p) { var a=UTIF._binBE.ui8; a[0]=buff[p+1]; a[1]=buff[p+0]; return UTIF._binBE. i16[0]; },
readInt : function(buff, p) { var a=UTIF._binBE.ui8; a[0]=buff[p+3]; a[1]=buff[p+2]; a[2]=buff[p+1]; a[3]=buff[p+0]; return UTIF._binBE. i32[0]; },
readUint : function(buff, p) { var a=UTIF._binBE.ui8; a[0]=buff[p+3]; a[1]=buff[p+2]; a[2]=buff[p+1]; a[3]=buff[p+0]; return UTIF._binBE.ui32[0]; },
readASCII : function(buff, p, l) { var s = ""; for(var i=0; i> 8)&255; buff[p+1] = n&255; },
writeInt : function(buff, p, n) { var a=UTIF._binBE.ui8; UTIF._binBE.i32[0]=n; buff[p+3]=a[0]; buff[p+2]=a[1]; buff[p+1]=a[2]; buff[p+0]=a[3]; },
writeUint : function(buff, p, n) { buff[p] = (n>>24)&255; buff[p+1] = (n>>16)&255; buff[p+2] = (n>>8)&255; buff[p+3] = (n>>0)&255; },
writeASCII : function(buff, p, s) { for(var i = 0; i < s.length; i++) buff[p+i] = s.charCodeAt(i); },
writeDouble: function(buff, p, n)
{
UTIF._binBE.fl64[0] = n;
for (var i = 0; i < 8; i++) buff[p + i] = UTIF._binBE.ui8[7 - i];
}
}
UTIF._binBE.ui8 = new Uint8Array (8);
UTIF._binBE.i16 = new Int16Array (UTIF._binBE.ui8.buffer);
UTIF._binBE.i32 = new Int32Array (UTIF._binBE.ui8.buffer);
UTIF._binBE.ui32 = new Uint32Array (UTIF._binBE.ui8.buffer);
UTIF._binBE.fl32 = new Float32Array(UTIF._binBE.ui8.buffer);
UTIF._binBE.fl64 = new Float64Array(UTIF._binBE.ui8.buffer);
UTIF._binLE =
{
nextZero : UTIF._binBE.nextZero,
readUshort : function(buff, p) { return (buff[p+1]<< 8) | buff[p]; },
readShort : function(buff, p) { var a=UTIF._binBE.ui8; a[0]=buff[p+0]; a[1]=buff[p+1]; return UTIF._binBE. i16[0]; },
readInt : function(buff, p) { var a=UTIF._binBE.ui8; a[0]=buff[p+0]; a[1]=buff[p+1]; a[2]=buff[p+2]; a[3]=buff[p+3]; return UTIF._binBE. i32[0]; },
readUint : function(buff, p) { var a=UTIF._binBE.ui8; a[0]=buff[p+0]; a[1]=buff[p+1]; a[2]=buff[p+2]; a[3]=buff[p+3]; return UTIF._binBE.ui32[0]; },
readASCII : UTIF._binBE.readASCII,
readFloat : function(buff, p) { var a=UTIF._binBE.ui8; for(var i=0;i<4;i++) a[i]=buff[p+ i]; return UTIF._binBE.fl32[0]; },
readDouble : function(buff, p) { var a=UTIF._binBE.ui8; for(var i=0;i<8;i++) a[i]=buff[p+ i]; return UTIF._binBE.fl64[0]; },
writeUshort: function(buff, p, n) { buff[p] = (n)&255; buff[p+1] = (n>>8)&255; },
writeInt : function(buff, p, n) { var a=UTIF._binBE.ui8; UTIF._binBE.i32[0]=n; buff[p+0]=a[0]; buff[p+1]=a[1]; buff[p+2]=a[2]; buff[p+3]=a[3]; },
writeUint : function(buff, p, n) { buff[p] = (n>>>0)&255; buff[p+1] = (n>>>8)&255; buff[p+2] = (n>>>16)&255; buff[p+3] = (n>>>24)&255; },
writeASCII : UTIF._binBE.writeASCII
}
UTIF._copyTile = function(tb, tw, th, b, w, h, xoff, yoff)
{
//log("copyTile", tw, th, w, h, xoff, yoff);
var xlim = Math.min(tw, w-xoff);
var ylim = Math.min(th, h-yoff);
for(var y=0; y>>2<<5);while(i==0){i=n(N,d,1);m=n(N,d+1,2);d+=3;if(m==0){if((d&7)!=0)d+=8-(d&7);
var D=(d>>>3)+4,q=N[D-4]|N[D-3]<<8;if(Z)W=H.H.W(W,w+q);W.set(new R(N.buffer,N.byteOffset+D,q),w);d=D+q<<3;
w+=q;continue}if(Z)W=H.H.W(W,w+(1<<17));if(m==1){v=b.J;C=b.h;X=(1<<9)-1;u=(1<<5)-1}if(m==2){J=A(N,d,5)+257;
h=A(N,d+5,5)+1;Q=A(N,d+10,4)+4;d+=14;var E=d,j=1;for(var c=0;c<38;c+=2){b.Q[c]=0;b.Q[c+1]=0}for(var c=0;
cj)j=K}d+=3*Q;M(b.Q,j);I(b.Q,j,b.u);v=b.w;C=b.d;
d=l(b.u,(1<>>4;if(p>>>8==0){W[w++]=p}else if(p==256){break}else{var z=w+p-254;
if(p>264){var _=b.q[p-257];z=w+(_>>>3)+A(N,d,_&7);d+=_&7}var $=C[e(N,d)&u];d+=$&15;var s=$>>>4,Y=b.c[s],a=(Y>>>4)+n(N,d,Y&15);
d+=Y&15;while(w>>4;
if(b<=15){A[I]=b;I++}else{var Z=0,m=0;if(b==16){m=3+l(V,n,2);n+=2;Z=A[I-1]}else if(b==17){m=3+l(V,n,3);
n+=3}else if(b==18){m=11+l(V,n,7);n+=7}var J=I+m;while(I>>1;
while(An)n=M;A++}while(A>1,I=N[l+1],e=M<<4|I,b=W-I,Z=N[l]<>>15-W;R[J]=e;Z++}}};H.H.l=function(N,W){var R=H.H.m.r,V=15-W;for(var n=0;n>>V}};H.H.M=function(N,W,R){R=R<<(W&7);var V=W>>>3;N[V]|=R;N[V+1]|=R>>>8};
H.H.I=function(N,W,R){R=R<<(W&7);var V=W>>>3;N[V]|=R;N[V+1]|=R>>>8;N[V+2]|=R>>>16};H.H.e=function(N,W,R){return(N[W>>>3]|N[(W>>>3)+1]<<8)>>>(W&7)&(1<>>3]|N[(W>>>3)+1]<<8|N[(W>>>3)+2]<<16)>>>(W&7)&(1<>>3]|N[(W>>>3)+1]<<8|N[(W>>>3)+2]<<16)>>>(W&7)};
H.H.i=function(N,W){return(N[W>>>3]|N[(W>>>3)+1]<<8|N[(W>>>3)+2]<<16|N[(W>>>3)+3]<<24)>>>(W&7)};H.H.m=function(){var N=Uint16Array,W=Uint32Array;
return{K:new N(16),j:new N(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new N(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new W(32),J:new N(512),_:[],h:new N(32),$:[],w:new N(32768),C:[],v:[],d:new N(32768),D:[],u:new N(512),Q:[],r:new N(1<<15),s:new W(286),Y:new W(30),a:new W(19),t:new W(15e3),k:new N(1<<16),g:new N(1<<15)}}();
(function(){var N=H.H.m,W=1<<15;for(var R=0;R>>1|(V&1431655765)<<1;
V=(V&3435973836)>>>2|(V&858993459)<<2;V=(V&4042322160)>>>4|(V&252645135)<<4;V=(V&4278255360)>>>8|(V&16711935)<<8;
N.r[R]=(V>>>16|V<<16)>>>17}function n(A,l,M){while(l--!=0)A.push(0,M)}for(var R=0;R<32;R++){N.q[R]=N.S[R]<<3|N.T[R];
N.c[R]=N.p[R]<<4|N.z[R]}n(N._,144,8);n(N._,255-143,9);n(N._,279-255,7);n(N._,287-279,8);H.H.n(N._,9);
H.H.A(N._,9,N.J);H.H.l(N._,9);n(N.$,32,5);H.H.n(N.$,5);H.H.A(N.$,5,N.h);H.H.l(N.$,5);n(N.Q,19,0);n(N.C,286,0);
n(N.D,30,0);n(N.v,320,0)}());return H.H.N}();
UTIF.LosslessJpegDecode =function(){var b,O;function l(){return b[O++]}function m(){return b[O++]<<8|b[O++]}function a0(h){var V=l(),I=[0,0,0,255],f=[],G=8;
for(var w=0;w<16;w++)f[w]=l();for(var w=0;w<16;w++){for(var x=0;x>--s&1;
Y=I[Y+F]}E[w]=Y}}function z(h,V,I,f){if(h[V+3]!=255)return 0;if(I==0)return V;for(var w=0;w<2;w++){if(h[V+w]==0){h[V+w]=h.length;
h.push(0,0,f,255)}var x=z(h,h[V+w],I-1,f+1);if(x!=0)return x}return 0}function i(h){var V=h.b,I=h.f;
while(V<25&&h.a>(V.b-=h)&65535>>16-h}function g(h,V){var I=h[0],f=0,w=255,x=0;if(V.b<16)i(V);var T=V.f>>V.b-8&255;
f=h[1][T];w=I[f+3];V.b-=I[f+2];while(w==255){x=V.f>>--V.b&1;f=I[f+x];w=I[f+3]}return w}function P(h,V){if(h<32768>>16-V)h+=-(1<>4,J&15]}}else if(Y==65476){var a3=O+F-2;while(O>>4];x[v[0]]=v.slice(1)}I=l();O+=2;break}else if(Y==65501){w=m()}else{O+=F-2}}var a4=f>8?Uint16Array:Uint8Array,$=new a4(s*_*E),M={b:0,f:0,c:I==8,a:O,data:b,d:b.length,e:w};
if(M.c)a1($,_*E,M,G[0],s);else{var c=[],p=0,D=0;for(var t=0;tp)p=S;
if(K>D)D=K;c.push(S*K)}if(p!=1||D!=1){if(E!=3||c[1]!=1||c[2]!=1)throw"e";if(p!=2||D!=1&&D!=2)throw"e";
var u=[],Z=0;for(var t=0;t>>1)*B+(S>>>1))*Z,y=(K&1)*2+(S&1);
$[q]=n[k+y];$[q+1]=n[k+4];$[q+2]=n[k+5]}else for(var S=0;S<_;S++){var q=(K*_+S)*E,k=(K*B+(S>>>1))*Z,y=S&1;
$[q]=n[k+y];$[q+1]=n[k+2];$[q+2]=n[k+3]}}}else{X($,_*E,M,G,E,s);if(w==0)j($,I,_,s,0,E,E,f);else{var U=Math.floor(w/_);
for(var K=0;K>>1);else if(V==6)Q=h[J]+(r-h[J-G]>>>1);else if(V==7)Q=r+h[J]>>>1;else throw V;
h[a]+=Q}}}}return C}();
(function(){var G=0,F=1,i=2,b=3,J=4,N=5,E=6,s=7,c=8,T=9,a3=10,f=11,q=12,M=13,m=14,x=15,L=16,$=17,p=18;
function a5(t){var Z=UTIF._binBE.readUshort,u={b:Z(t,0),i:t[2],C:t[3],u:t[4],q:Z(t,5),k:Z(t,7),e:Z(t,9),l:Z(t,11),s:t[13],d:Z(t,14)};
if(u.b!=18771||u.i>1||u.q<6||u.q%6||u.e<768||u.e%24||u.l!=768||u.k=u.l||u.s>16||u.s!=u.k/u.l||u.s!=Math.ceil(u.e/u.l)||u.d!=u.q/6||u.u!=12&&u.u!=14&&u.u!=16||u.C!=16&&u.C!=0){throw"Invalid data"}if(u.i==0){throw"Not implemented. We need this file!"}u.h=u.C==16;
u.m=(u.h?u.l*2/3:u.l>>>1)|0;u.A=u.m+2;u.f=64;u.g=(1<>>6);for(var e=0;e<3;e++){for(var Q=0;
Q<41;Q++){Z[e][Q]=[u,1]}}return Z}function a4(t){for(var Z=-1,u=0;!u;Z++){u=t[t.j]>>>7-t.a&1;t.a++;t.a&=7;
if(!t.a)t.j++}return Z}function K(t,Z){var u=0,e=8-t.a,Q=t.j,V=t.a;if(Z){if(Z>=e){do{u<<=e;Z-=e;u|=t[t.j]&(1<=8)}if(Z){u<<=Z;e-=Z;u|=t[t.j]>>>e&(1<n&&C>>2;if(o){w[X]=h;return}l=Z.t*Z.c[t.g+Y-H]+Z.c[t.g+g-Y]}else{h=Y>g&&Y>P||Y>>2:A+v>>>1;
l=Z.t*Z.c[t.g+Y-g]+Z.c[t.g+g-A]}R=y(l);var W=a4(u);if(W>>1):a>>>1;
O[R][0]+=y(a);if(O[R][1]==t.f){O[R][0]>>>=1;O[R][1]>>>=1}O[R][1]++;h=l<0?h-a:h+a;if(t.i){if(h<0)h+=Z.w;
else if(h>t.g)h-=Z.w}w[X]=h>=0?Math.min(h,t.g):0}function U(t,Z,u){var e=t[0].length;for(var Q=Z;Q<=u;
Q++){t[Q][0]=t[Q-1][1];t[Q][e-1]=t[Q-1][e-2]}}function B(t){U(t,s,q);U(t,i,J);U(t,x,$)}function _(t,Z,u,e,Q,V,O,o,X,k,j,I,a){var l=0,R=1,w=QJ;
while(R8){r(t,Z,u,e,Q,R,o[X]);r(t,Z,u,e,V,R,o[X]);R+=2}}B(e)}function a8(t,Z,u,e,Q,V){_(t,Z,u,e,i,s,Q,V,0,0,1,0,8);
_(t,Z,u,e,c,x,Q,V,1,0,1,0,8);_(t,Z,u,e,b,T,Q,V,2,1,0,3,0);_(t,Z,u,e,a3,L,Q,V,0,0,0,3,2);_(t,Z,u,e,J,f,Q,V,1,0,0,3,2);
_(t,Z,u,e,q,$,Q,V,2,1,0,3,0)}function a9(t,Z,u,e,Q,V){var O=V.length,o=t.l;if(Q+1==t.s)o=t.e-Q*t.l;var X=6*t.e*e+Q*t.l;
for(var k=0;k<6;k++){for(var j=0;j>>1)}else if(I==2){a=x+(k>>>1)}else{a=s+k}var l=t.h?(j*2/3&2147483646|j%3&1)+(j%3>>>1):j>>>1;
Z[X+j]=u[a][l+1]}X+=t.e}}UTIF._decompressRAF=function(t,Z){var u=a5(t),e=a7(t,u),Q=a2(u),V=new Int16Array(u.e*u.q);
if(Z==null){Z=u.h?[[1,1,0,1,1,2],[1,1,2,1,1,0],[2,0,1,0,2,1],[1,1,2,1,1,0],[1,1,0,1,1,2],[0,2,1,2,0,1]]:[[0,1],[3,2]]}var O=[[G,b],[F,J],[N,f],[E,q],[M,L],[m,$]],o=[];
for(var X=0;X