;(function(){
var UTIF = {};
// Make available for import by `require()`
if (typeof module == "object") {module.exports = UTIF;}
else {self.UTIF = UTIF;}
var pako = (typeof require === "function") ? require("pako") : self.pako;
function log() { if (typeof process=="undefined" || process.env.NODE_ENV=="development") console.log.apply(console, arguments); }
(function(UTIF, pako){
// 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, h = (img["t278"] ? img["t278"][0] : img.height), bpl = Math.ceil(bps*noc*img.width/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;
}
// 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 blocksperrow = Math.floor(rawWidth / 11),
rowbytes = blocksperrow * 16;
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++) {
readPageRW6();
resetPredNonzeros();
sh=0; pixel_base=0;
for (i = 0; i < 11; i++){
isOdd = i & 1;
if (i % 3 == 2) {
var base = byte < 14 ? bytes[byte++] : 0;
if (base == 3) base = 4;
pixel_base = 0x200 << base;
sh = 1 << base;
}
var epixel = byte < 14 ? bytes[byte++] : 0;
if (pred[isOdd]) {
epixel *= sh;
if (pixel_base < 0x2000 && 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) <= 0xffff ? (epixel - 0xf) & 0xffff : ((epixel + 0x7ffffff1) >> 0x1f) & 0x3fff;
}
}
}
}
}
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 = UTIF.decode._decodeVC5=function(){var e=[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],x,u,H,d=[3,3,3,3,2,2,2,1,1,1],a=24576,a7=16384,K=8192,ai=a7|K;
function A(B){var P=B[1],D=B[0][P>>>3]>>>7-(P&7)&1;B[1]++;return D}function aj(B,P){if(x==null){x={};
for(var D=0;D>>1}return B}function c(B,P){return B>>P}function N(B,P,D,U,X,y){P[D]=c(c(11*B[X]-4*B[X+y]+B[X+y+y]+4,3)+B[U],1);
P[D+y]=c(c(5*B[X]+4*B[X+y]-B[X+y+y]+4,3)-B[U],1)}function g(B,P,D,U,X,y){var n=B[X-y]-B[X+y],S=B[X],O=B[U];
P[D]=c(c(n+4,3)+S+O,1);P[D+y]=c(c(-n+4,3)+S-O,1)}function L(B,P,D,U,X,y){P[D]=c(c(5*B[X]+4*B[X-y]-B[X-y-y]+4,3)+B[U],1);
P[D+y]=c(c(11*B[X]-4*B[X-y]+B[X-y-y]+4,3)-B[U],1)}function t(B){B=B<0?0:B>4095?4095:B;B=H[B]>>>2;return B}function ab(B,P,D,U,X){U=new Uint16Array(U.buffer);
var y=Date.now(),n=UTIF._binBE,S=P+D,O,q,i,M,m,aA,T,a8,a0,am,au,a3,aw,ao,v,ax,p,k;P+=4;while(P>>1)*(i>>>1));k=new Int16Array((q>>>1)*(i>>>1));u=new Int16Array(1024);
for(var f=0;f<1024;f++){var aF=f-512,j=Math.abs(aF),O=Math.floor(768*j*j*j/(255*255*255))+j;u[f]=Math.sign(aF)*O}H=new Uint16Array(4096);
var al=(1<<16)-1;for(var f=0;f<4096;f++){var ad=f,az=al*(Math.pow(113,ad/4095)-1)/112;H[f]=Math.min(az,al)}}var Z=p[T],V=Q(q,1+d[M]),z=Q(i,1+d[M]);
if(M==0){for(var b=0;b>>1)+G]=B[w]<<8|B[w+1]}}else{var aC=[B,P*8],aq=[],a5=0,ae=V*z,I=[0,0],s=0,E=0;
while(a50){aq[a5++]=E;s--}}var $=(M-1)%3,aE=$!=1?V:0,as=$!=0?z:0;
for(var b=0;b>>1)+aE,aa=b*V;for(var G=0;G>>1,an=V*2,at=z*2;
for(var b=0;b>14-r*2&3;var af=a6[aD];if(af!=0)for(var b=0;b>>1)*(q>>>1)+(G>>>1),R=a2[w],ak=ar[w]-2048,aB=ah[w]-2048,av=a1[w]-2048,a4=(ak<<1)+R,a9=(aB<<1)+R,ap=R+av,ag=R-av;
U[J]=t(a4);U[J+1]=t(ap);U[J+q]=t(ag);U[J+q+1]=t(a9)}}P+=o*4}else if(C==16388){P+=o*4}else if(F==8192||F==8448||F==9216){}else throw C.toString(16)}}console.log(Date.now()-y)}return ab}()
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) { // 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; i4) { 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)
{
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;
//log("interpretation: ", intp, "bps", bps, out);
if(false) {}
else if(intp==0)
{
var bpl = Math.ceil(bps*w/8);
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; 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 smpls = out["t258"]?out["t258"].length : 4;
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) {
function gamma(x) { return x < 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1.0 / 2.4) - 0.055; }
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>--r&1;
X=g[X+y]}w[t]=X}}function P(l,A,g,K){if(l[A+3]!=255)return 0;if(g==0)return A;for(var t=0;t<2;t++){if(l[A+t]==0){l[A+t]=l.length;
l.push(0,0,K,255)}var F=P(l,l[A+t],g-1,K+1);if(F!=0)return F}return 0}function f(l){var A=l.b,g=l.a;
while(A<25&&l.e>>8;g=g<<8|K;A+=8}if(A<0)throw"e";l.b=A;l.a=g}function O(l,A){if(A.b>(A.b-=l)&65535>>16-l}function B(l,A){var g=l[0],K=0,t=255,F=0;if(A.b<16)f(A);var $=A.a>>A.b-8&255;
K=l[1][$];t=g[K+3];A.b-=g[K+2];while(t==255){F=A.a>>--A.b&1;K=g[K+F];t=g[K+3]}return t}function D(l,A){if(l<32768>>16-A)l+=-(1<>4,q&15]}}else if(M==65476){var m=_+X-2;while(_>>4];t[i[0]]=i.slice(1)}g=u();_+=2;break}else{_+=X-2}}var T=K>8?Uint16Array:Uint8Array,Y=new T(w*r*L),d={b:0,a:0,c:g==8,e:_,data:o,d:o.length};
if(d.c)b(Y,r*L,d,$[0],w);else{var v=[],Q=0,C=0;for(var y=0;yQ)Q=s;
if(H>C)C=H;v.push(s*H)}if(Q!=1||C!=1){var E=[],c=0;for(var y=0;y>>1);else if(A==6)S=l[n]+(m-l[n-L]>>>1);else if(A==7)S=m+l[n]>>>1;else throw A;
l[q]+=S}}}}return x}();
(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