New issue
Advanced search Search tips

Issue 720499 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: May 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: Bug-Regression


Show other hotlists

Hotlists containing this issue:
Hotlist-1


Sign in to add a comment

Image resize using canvas or getImageData sometimes makes image darker

Reported by viachesl...@gmail.com, May 10 2017

Issue description

Steps to reproduce the problem:
// We have a valid RGBA imageData as input
var canvas = document.createElement('canvas');
canvas.width = imageData.width;
canvas.height = imageData.height;
canvas.getContext('2d').putImageData(imageData, 0, 0);

// If I just read the whole data it's ok, no color change occurs
// result1 OK
var result1 = canvas.getContext('2d').getImageData(0, 0, imageData.width, imageData.height);

// But if I read a part of the data, the color histogram gets darker
// result2 NOK
var result2 = canvas.getContext('2d').getImageData(0, 0, Math.floor(imageData.width / 2), Math.floor(imageData.height / 2));

// If I downscale the canvas, the color histogram gets also darker
// result3 NOK

var scaleMegapixels = 1.0; 
var scaleFactor = Math.sqrt((imageData.width * imageData.height) / scaleMegapixels * 1024 * 1024);
var _scaleFactor = 1 / scaleFactor;

var downScaledWidth = Math.floor(imageData.width / scaleFactor);
var downScaledHeight = Math.floor(imageData.height / scaleFactor);

var downScaledCanvas = document.createElement('canvas');
downScaledCanvas.width = downScaledWidth;
downScaledCanvas.height = downScaledHeight;

var downScaledContext = downScaledCanvas.getContext('2d');
downScaledContext.scale(_scaleFactor, _scaleFactor);		

downScaledContext.drawImage(canvas, 0, 0, imageData.width, imageData.height);
var result3 = data.context.getImageData(0, 0, downScaledWidth, downScaledHeight);

What is the expected behavior?
Canvas API must not change RGB histogram that much.

What went wrong?
Input downscaled image or a part of image I get using getImageData becomes darker, its RGB historgam gets sagnificantly changed.

Did this work before? Yes N/A

Chrome version: 58.0.3029.83  Channel: n/a
OS Version: 7.0
Flash Version: 

Not reproduced on PC (both Windows & Mac), iOS, ok in Opera + Android, ok in Chrome 42.0.x.x + Android.
Reproduced on Samsung Galaxy A5 + Chrome.
 
bug_1.jpg
57.1 KB View Download
bug_2.jpg
29.4 KB View Download
bug_reproduce_1.jpg
163 KB View Download
bug_reproduce_2.jpg
225 KB View Download
Components: -Blink Blink>Canvas
UPD: color change may probably occur in putImageData.
We have a valid imageData.
Next we get rgb in some point (x, y) from the imageData.

var i = 4 * (y * imageData.width + x);
var rgb1 = '(' + imageData.data[i + 0] + ', ' + imageData.data[i + 1] + ', ' + imageData.data[i + 2] + ')';
alert(rgb1); // Here we see expected rgb values for example (111, 80, 6).

// Draw it into some new clear canvas and get rgb in the same point but in the canvas
context.putImageData(imageData, 0, 0);
var canvasColor = context.getImageData(x, y, 1, 1);
var pixels = canvasColor.data;
var r = pixels[0];
var g = pixels[1];
var b = pixels[2];
var rgb2 = '(' + r + ', ' + g + ', ' + b + ')';
alert(rgb2); // Here we may see darker rgb values for example (40, 20, 0).

On PC, iOS both results are always the same.

The issue also has some strange timing nature.
It can be dark executing the same logic several times, 
but then it may be ok, then again dark and so on.
Yes, looks like the same issue.
The mentioned workaround drawImage is not applicable for us as it accepts only
HTMLImageElement, HTMLVideoElement, HTMLCanvasElement or ImageBitmap.
But we have ImageData object as input.
Seems like we have nothing to do but wait for the correct stable solution.
Please notify here when M59 with the fix will be available.

Comment 5 by r.sain...@gmail.com, May 12 2017


After some tests:

-It does not work on Chrome beta 59.0.3071.12
-It works on Chrome Dev 60.0.3096.5


59 ko.JPG
28.5 KB View Download
60 ok.JPG
28.8 KB View Download

Comment 6 by junov@chromium.org, May 15 2017

Owner: fs...@chromium.org
Status: Assigned (was: Unconfirmed)

Comment 7 by junov@chromium.org, May 15 2017

Labels: M-59
Confirm, it does work on Chrome Dev 60.0.3096.5.
Do you know when the solution will be delivered into the original Chrome as well?

Comment 9 by fs...@chromium.org, May 16 2017

Ahn, this is a minor release difference problem.

The fix has been merged to 59.0.3071.36. 
You are on 59.0.3071.12. The current M59 version is 59.0.3071.47 (or 49 for Android). Updating to the latest beta should fix this.

Could you please recheck using the beta version on the app store?

well, i guess i made a mistake, when i wrote the versions (the captures are right) :

-It does not work on Chrome beta 59.0.3071.25
-It works on Chrome Dev 60.0.3096.5

I'm updating to beta 59.0.3071.49 to test it.


Ok, so i confirm it works on beta 59.0.3071.49  

Do you have any release date ?

It's a big problem for our business, and i guess for other companies.

Thanks.
Also confirm, it works on Chrome Beta 59.0.3071.49.
To know the release date would be highly appreciated.

Comment 13 by fs...@chromium.org, May 16 2017

Status: Fixed (was: Assigned)
According to https://www.chromium.org/developers/calendar the target data for stable M59 release is June 6th.

I understand that this is impacting badly your use case, but unfortunately this was not approved for M58 merge (which means we have to wait until Jun 6th for an stable fix).

As for a little insight on the decision process: we weight risk of merging (having a never tested version of Chrome running for all users) against fraction of impacted users (which, in this case, is relatively small) and how damaging the bug is (security, privacy, destroying data, etc).

I know that when a bug happens to us it feels that everything is critically broken (I certainly feel like that for every canvas-related bug), which is why we need to have a process that tries to be a bit more rational and tries to maximize Chrome's usefulness.

Since the issue is fixed, I'll close the bug for now. Thanks a lot for reporting and testing.

Sign in to add a comment