Optimized loops in JPG conversion.

This change makes the 4 conversion loops look the same.
It optimizes access of the array length and access of the property
numComponents, which is known to be constant.
This commit is contained in:
Fabian Lange 2014-06-04 10:02:47 +02:00
parent 2449142fc3
commit dcde59fa76

View File

@ -861,7 +861,7 @@ var JpegImage = (function jpegImage() {
_convertYccToRgb: function convertYccToRgb(data) { _convertYccToRgb: function convertYccToRgb(data) {
var Y, Cb, Cr; var Y, Cb, Cr;
for (var i = 0; i < data.length; i += this.numComponents) { for (var i = 0, length = data.length; i < length; i += 3) {
Y = data[i ]; Y = data[i ];
Cb = data[i + 1]; Cb = data[i + 1];
Cr = data[i + 2]; Cr = data[i + 2];
@ -875,7 +875,7 @@ var JpegImage = (function jpegImage() {
_convertYcckToRgb: function convertYcckToRgb(data) { _convertYcckToRgb: function convertYcckToRgb(data) {
var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk; var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
var offset = 0; var offset = 0;
for (var i = 0; i < data.length; i += this.numComponents) { for (var i = 0, length = data.length; i < length; i += 4) {
Y = data[i]; Y = data[i];
Cb = data[i + 1]; Cb = data[i + 1];
Cr = data[i + 2]; Cr = data[i + 2];
@ -928,7 +928,7 @@ var JpegImage = (function jpegImage() {
_convertYcckToCmyk: function convertYcckToCmyk(data) { _convertYcckToCmyk: function convertYcckToCmyk(data) {
var Y, Cb, Cr; var Y, Cb, Cr;
for (var i = 0; i < data.length; i += this.numComponents) { for (var i = 0, length = data.length; i < length; i += 4) {
Y = data[i]; Y = data[i];
Cb = data[i + 1]; Cb = data[i + 1];
Cr = data[i + 2]; Cr = data[i + 2];
@ -943,14 +943,13 @@ var JpegImage = (function jpegImage() {
_convertCmykToRgb: function convertCmykToRgb(data) { _convertCmykToRgb: function convertCmykToRgb(data) {
var c, m, y, k; var c, m, y, k;
var offset = 0; var offset = 0;
var length = data.length;
var min = -255 * 255 * 255; var min = -255 * 255 * 255;
var scale = 1 / 255 / 255; var scale = 1 / 255 / 255;
for (var i = 0; i < length;) { for (var i = 0, length = data.length; i < length; i += 4) {
c = data[i++]; c = data[i];
m = data[i++]; m = data[i + 1];
y = data[i++]; y = data[i + 2];
k = data[i++]; k = data[i + 3];
var r = var r =
c * (-4.387332384609988 * c + 54.48615194189176 * m + c * (-4.387332384609988 * c + 54.48615194189176 * m +