Skip to content

Commit

Permalink
Use 3 param method for converting r,g,b into css string.
Browse files Browse the repository at this point in the history
This avoids creation of temporary arrays to pass them into the util
method. Also using "arguments" is more expensive then passing in 3
parameters.
  • Loading branch information
CodingFabian committed Oct 27, 2014
1 parent d65db7c commit 918d680
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/core/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
ratio[0] = i;
fn(ratio, 0, color, 0);
rgbColor = cs.getRgb(color, 0);
var cssColor = Util.makeCssRgb(rgbColor);
var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
colorStops.push([(i - t0) / diff, cssColor]);
}

var background = 'transparent';
if (dict.has('Background')) {
rgbColor = cs.getRgb(dict.get('Background'), 0);
background = Util.makeCssRgb(rgbColor);
background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
}

if (!extendStart) {
Expand Down
25 changes: 13 additions & 12 deletions src/display/annotation_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
container.style.backgroundColor = item.color;

var color = item.color;
var rgb = [];
for (var i = 0; i < 3; ++i) {
rgb[i] = Math.round(color[i] * 255);
}
item.colorCssRgb = Util.makeCssRgb(rgb);
item.colorCssRgb = Util.makeCssRgb(Math.round(color[0] * 255),
Math.round(color[1] * 255),
Math.round(color[2] * 255));

var highlight = document.createElement('div');
highlight.className = 'annotationHighlight';
Expand Down Expand Up @@ -136,13 +134,16 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
var i, ii;
if (item.hasBgColor) {
var color = item.color;
var rgb = [];
for (i = 0; i < 3; ++i) {
// Enlighten the color (70%)
var c = Math.round(color[i] * 255);
rgb[i] = Math.round((255 - c) * 0.7) + c;
}
content.style.backgroundColor = Util.makeCssRgb(rgb);

// Enlighten the color (70%)
var r = Math.round(color[0] * 255);
r = Math.round((255 - r) * 0.7) + r;
var g = Math.round(color[1] * 255);
g = Math.round((255 - g) * 0.7) + g;
var b = Math.round(color[2] * 255);
b = Math.round((255 - b) * 0.7) + b;

content.style.backgroundColor = Util.makeCssRgb(r, g, b);
}

var title = document.createElement('h1');
Expand Down
4 changes: 2 additions & 2 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1551,12 +1551,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.fillColor = this.getColorN_Pattern(arguments);
},
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
var color = Util.makeCssRgb(arguments);
var color = Util.makeCssRgb(r, g, b);
this.ctx.strokeStyle = color;
this.current.strokeColor = color;
},
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
var color = Util.makeCssRgb(arguments);
var color = Util.makeCssRgb(r, g, b);
this.ctx.fillStyle = color;
this.current.fillColor = color;
},
Expand Down
2 changes: 1 addition & 1 deletion src/display/pattern_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ var TilingPattern = (function TilingPatternClosure() {
context.strokeStyle = ctx.strokeStyle;
break;
case PaintType.UNCOLORED:
var cssColor = Util.makeCssRgb(color);
var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
context.fillStyle = cssColor;
context.strokeStyle = cssColor;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/display/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,11 @@ var SVGGraphics = (function SVGGraphicsClosure() {
this.current.miterLimit = limit;
},
setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
var color = Util.makeCssRgb(arguments);
var color = Util.makeCssRgb(r, g, b);
this.current.strokeColor = color;
},
setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
var color = Util.makeCssRgb(arguments);
var color = Util.makeCssRgb(r, g, b);
this.current.fillColor = color;
this.current.tspan = document.createElementNS(NS, 'svg:tspan');
this.current.xcoords = [];
Expand Down
8 changes: 4 additions & 4 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,10 @@ var Util = PDFJS.Util = (function UtilClosure() {

// makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
// creating many intermediate strings.
Util.makeCssRgb = function Util_makeCssRgb(rgb) {
rgbBuf[1] = rgb[0];
rgbBuf[3] = rgb[1];
rgbBuf[5] = rgb[2];
Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
rgbBuf[1] = r;
rgbBuf[3] = g;
rgbBuf[5] = b;
return rgbBuf.join('');
};

Expand Down

0 comments on commit 918d680

Please sign in to comment.