commit
65f1058736
126
pdf.js
126
pdf.js
@ -1613,7 +1613,7 @@ var CCITTFaxStream = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.byteAlign)
|
if (this.byteAlign)
|
||||||
inputBits &= ~7;
|
this.inputBits &= ~7;
|
||||||
|
|
||||||
var gotEOL = false;
|
var gotEOL = false;
|
||||||
|
|
||||||
@ -4520,10 +4520,24 @@ var CanvasGraphics = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
var ColorSpace = (function() {
|
var ColorSpace = (function() {
|
||||||
|
// Constructor should define this.numComps, this.defaultColor, this.name
|
||||||
function constructor() {
|
function constructor() {
|
||||||
error('should not call ColorSpace constructor');
|
error('should not call ColorSpace constructor');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constructor.prototype = {
|
||||||
|
// Input: array of size numComps representing color component values
|
||||||
|
// Output: array of rgb values, each value ranging from [0.1]
|
||||||
|
getRgb: function cs_getRgb(color) {
|
||||||
|
error('Should not call ColorSpace.getRgb');
|
||||||
|
},
|
||||||
|
// Input: Uint8Array of component values, each value scaled to [0,255]
|
||||||
|
// Output: Uint8Array of rgb values, each value scaled to [0,255]
|
||||||
|
getRgbBuffer: function cs_getRgbBuffer(input) {
|
||||||
|
error('Should not call ColorSpace.getRgbBuffer');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
constructor.parse = function colorspace_parse(cs, xref, res) {
|
constructor.parse = function colorspace_parse(cs, xref, res) {
|
||||||
if (IsName(cs)) {
|
if (IsName(cs)) {
|
||||||
var colorSpaces = res.get('ColorSpace');
|
var colorSpaces = res.get('ColorSpace');
|
||||||
@ -4601,8 +4615,14 @@ var ColorSpace = (function() {
|
|||||||
var hiVal = cs[2] + 1;
|
var hiVal = cs[2] + 1;
|
||||||
var lookup = xref.fetchIfRef(cs[3]);
|
var lookup = xref.fetchIfRef(cs[3]);
|
||||||
return new IndexedCS(base, hiVal, lookup);
|
return new IndexedCS(base, hiVal, lookup);
|
||||||
|
break;
|
||||||
|
case 'Separation':
|
||||||
|
var name = cs[1];
|
||||||
|
var alt = ColorSpace.parse(cs[2], xref, res);
|
||||||
|
var tintFn = new PDFFunction(xref, xref.fetchIfRef(cs[3]));
|
||||||
|
return new SeparationCS(alt, tintFn);
|
||||||
|
break;
|
||||||
case 'Lab':
|
case 'Lab':
|
||||||
case 'Seperation':
|
|
||||||
case 'DeviceN':
|
case 'DeviceN':
|
||||||
default:
|
default:
|
||||||
error("unrecognized color space object '" + mode + "'");
|
error("unrecognized color space object '" + mode + "'");
|
||||||
@ -4615,6 +4635,44 @@ var ColorSpace = (function() {
|
|||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var SeparationCS = (function() {
|
||||||
|
function constructor(base, tintFn) {
|
||||||
|
this.name = "Separation";
|
||||||
|
this.numComps = 1;
|
||||||
|
this.defaultColor = [1];
|
||||||
|
|
||||||
|
this.base = base;
|
||||||
|
this.tintFn = tintFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor.prototype = {
|
||||||
|
getRgb: function sepcs_getRgb(color) {
|
||||||
|
var tinted = this.tintFn.func(color);
|
||||||
|
return this.base.getRgb(tinted);
|
||||||
|
},
|
||||||
|
getRgbBuffer: function sepcs_getRgbBuffer(input) {
|
||||||
|
var tintFn = this.tintFn;
|
||||||
|
var base = this.base;
|
||||||
|
|
||||||
|
var length = 3 * input.length;
|
||||||
|
var pos = 0;
|
||||||
|
|
||||||
|
var numComps = base.numComps;
|
||||||
|
var baseBuf = new Uint8Array(numComps * input.length);
|
||||||
|
for (var i = 0, ii = input.length; i < ii; ++i) {
|
||||||
|
var scaled = input[i] / 255;
|
||||||
|
var tinted = tintFn.func([scaled]);
|
||||||
|
for (var j = 0; j < numComps; ++j)
|
||||||
|
baseBuf[pos++] = 255 * tinted[j];
|
||||||
|
}
|
||||||
|
return base.getRgbBuffer(baseBuf);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
var PatternCS = (function() {
|
var PatternCS = (function() {
|
||||||
function constructor() {
|
function constructor() {
|
||||||
this.name = 'Pattern';
|
this.name = 'Pattern';
|
||||||
@ -4649,17 +4707,18 @@ var IndexedCS = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
getRgb: function graycs_getRgb(color) {
|
getRgb: function indexcs_getRgb(color) {
|
||||||
var lookup = this.lookup;
|
|
||||||
var base = this.base;
|
|
||||||
var numComps = base.numComps;
|
var numComps = base.numComps;
|
||||||
|
|
||||||
|
var start = color[0] * numComps;
|
||||||
var c = [];
|
var c = [];
|
||||||
for (var i = 0; i < numComps; ++i)
|
|
||||||
c.push(lookup[i]);
|
for (var i = start, ii = start + numComps; i < ii; ++i)
|
||||||
|
c.push(this.lookup[i]);
|
||||||
|
|
||||||
return this.base.getRgb(c);
|
return this.base.getRgb(c);
|
||||||
},
|
},
|
||||||
getRgbBuffer: function graycs_getRgbBuffer(input) {
|
getRgbBuffer: function indexcs_getRgbBuffer(input) {
|
||||||
var base = this.base;
|
var base = this.base;
|
||||||
var numComps = base.numComps;
|
var numComps = base.numComps;
|
||||||
var lookup = this.lookup;
|
var lookup = this.lookup;
|
||||||
@ -4668,7 +4727,7 @@ var IndexedCS = (function() {
|
|||||||
var baseBuf = new Uint8Array(length * numComps);
|
var baseBuf = new Uint8Array(length * numComps);
|
||||||
var baseBufPos = 0;
|
var baseBufPos = 0;
|
||||||
for (var i = 0; i < length; ++i) {
|
for (var i = 0; i < length; ++i) {
|
||||||
var lookupPos = input[i];
|
var lookupPos = input[i] * numComps;
|
||||||
for (var j = 0; j < numComps; ++j) {
|
for (var j = 0; j < numComps; ++j) {
|
||||||
baseBuf[baseBufPos++] = lookup[lookupPos + j];
|
baseBuf[baseBufPos++] = lookup[lookupPos + j];
|
||||||
}
|
}
|
||||||
@ -4693,7 +4752,7 @@ var DeviceGrayCS = (function() {
|
|||||||
return [c, c, c];
|
return [c, c, c];
|
||||||
},
|
},
|
||||||
getRgbBuffer: function graycs_getRgbBuffer(input) {
|
getRgbBuffer: function graycs_getRgbBuffer(input) {
|
||||||
var length = input.length;
|
var length = input.length * 3;
|
||||||
var rgbBuf = new Uint8Array(length);
|
var rgbBuf = new Uint8Array(length);
|
||||||
for (var i = 0, j = 0; i < length; ++i) {
|
for (var i = 0, j = 0; i < length; ++i) {
|
||||||
var c = input[i];
|
var c = input[i];
|
||||||
@ -4786,8 +4845,22 @@ var DeviceCmykCS = (function() {
|
|||||||
return [r, g, b];
|
return [r, g, b];
|
||||||
},
|
},
|
||||||
getRgbBuffer: function cmykcs_getRgbBuffer(colorBuf) {
|
getRgbBuffer: function cmykcs_getRgbBuffer(colorBuf) {
|
||||||
error('conversion from rgb to cmyk not implemented for images');
|
var length = colorBuf.length / 4;
|
||||||
return colorBuf;
|
var rgbBuf = new Uint8Array(length * 3);
|
||||||
|
var rgbBufPos = 0;
|
||||||
|
var colorBufPos = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
var cmyk = [];
|
||||||
|
for (var j = 0; j < 4; ++j)
|
||||||
|
cmyk.push(colorBuf[colorBufPos++]/255);
|
||||||
|
|
||||||
|
var rgb = this.getRgb(cmyk);
|
||||||
|
for (var j = 0; j < 3; ++j)
|
||||||
|
rgbBuf[rgbBufPos++] = Math.round(rgb[j] * 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rgbBuf;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return constructor;
|
return constructor;
|
||||||
@ -4904,7 +4977,7 @@ var PDFImage = (function() {
|
|||||||
output[i] = Math.round(255 * ret / ((1 << bpc) - 1));
|
output[i] = Math.round(255 * ret / ((1 << bpc) - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.colorSpace.getRbaBuffer(output);
|
return output;
|
||||||
},
|
},
|
||||||
getOpacity: function getOpacity() {
|
getOpacity: function getOpacity() {
|
||||||
var smask = this.smask;
|
var smask = this.smask;
|
||||||
@ -4936,32 +5009,17 @@ var PDFImage = (function() {
|
|||||||
var rowBytes = (width * numComps * bpc + 7) >> 3;
|
var rowBytes = (width * numComps * bpc + 7) >> 3;
|
||||||
var imgArray = this.image.getBytes(height * rowBytes);
|
var imgArray = this.image.getBytes(height * rowBytes);
|
||||||
|
|
||||||
var comps = this.getComponents(imgArray);
|
var comps = this.colorSpace.getRgbBuffer(this.getComponents(imgArray));
|
||||||
var compsPos = 0;
|
var compsPos = 0;
|
||||||
var opacity = this.getOpacity();
|
var opacity = this.getOpacity();
|
||||||
var opacityPos = 0;
|
var opacityPos = 0;
|
||||||
var length = width * height * 4;
|
var length = width * height * 4;
|
||||||
|
|
||||||
switch (numComps) {
|
for (var i = 0; i < length; i += 4) {
|
||||||
case 1:
|
buffer[i] = comps[compsPos++];
|
||||||
for (var i = 0; i < length; i += 4) {
|
buffer[i + 1] = comps[compsPos++];
|
||||||
var p = comps[compsPos++];
|
buffer[i + 2] = comps[compsPos++];
|
||||||
buffer[i] = p;
|
buffer[i + 3] = opacity[opacityPos++];
|
||||||
buffer[i + 1] = p;
|
|
||||||
buffer[i + 2] = p;
|
|
||||||
buffer[i + 3] = opacity[opacityPos++];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
for (var i = 0; i < length; i += 4) {
|
|
||||||
buffer[i] = comps[compsPos++];
|
|
||||||
buffer[i + 1] = comps[compsPos++];
|
|
||||||
buffer[i + 2] = comps[compsPos++];
|
|
||||||
buffer[i + 3] = opacity[opacityPos++];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
TODO('Images with ' + numComps + ' components per pixel');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fillGrayBuffer: function fillGrayBuffer(buffer) {
|
fillGrayBuffer: function fillGrayBuffer(buffer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user