Always generate square cursor images in changeCursor (fix portrait mode issue).

This is a workaround for corrupted non-square cursors seen on some
Windows 7 machines with NVIDIA cards. The corruption only happens when
the screen is in portrait mode.
This commit is contained in:
vj 2012-10-17 09:56:20 +02:00
parent 01cd47de36
commit 016b408d71

View File

@ -657,11 +657,18 @@ return constructor(); // Return the public API interface
/* Set CSS cursor property using data URI encoded cursor file */ /* Set CSS cursor property using data URI encoded cursor file */
function changeCursor(target, pixels, mask, hotx, hoty, w, h, cmap) { function changeCursor(target, pixels, mask, hotx, hoty, w0, h0, cmap) {
"use strict"; "use strict";
var cur = [], rgb, IHDRsz, RGBsz, ANDsz, XORsz, url, idx, alpha, x, y; var cur = [], rgb, IHDRsz, RGBsz, ANDsz, XORsz, url, idx, alpha, x, y;
//Util.Debug(">> changeCursor, x: " + hotx + ", y: " + hoty + ", w: " + w + ", h: " + h); //Util.Debug(">> changeCursor, x: " + hotx + ", y: " + hoty + ", w0: " + w0 + ", h0: " + h0);
var w = w0;
var h = h0;
if (h < w)
h = w; // increase h to make it square
else
w = h; // increace w to make it square
// Push multi-byte little-endian values // Push multi-byte little-endian values
cur.push16le = function (num) { cur.push16le = function (num) {
this.push((num ) & 0xFF, this.push((num ) & 0xFF,
@ -715,22 +722,28 @@ function changeCursor(target, pixels, mask, hotx, hoty, w, h, cmap) {
// 62: color data (RGBQUAD icColors[]) // 62: color data (RGBQUAD icColors[])
for (y = h-1; y >= 0; y -= 1) { for (y = h-1; y >= 0; y -= 1) {
for (x = 0; x < w; x += 1) { for (x = 0; x < w; x += 1) {
idx = y * Math.ceil(w / 8) + Math.floor(x/8); if (x >= w0 || y >= h0) {
alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0; cur.push(0); // blue
cur.push(0); // green
if (cmap) { cur.push(0); // red
idx = (w * y) + x; cur.push(0); // alpha
rgb = cmap[pixels[idx]];
cur.push(rgb[2]); // blue
cur.push(rgb[1]); // green
cur.push(rgb[0]); // red
cur.push(alpha); // alpha
} else { } else {
idx = ((w * y) + x) * 4; idx = y * Math.ceil(w0 / 8) + Math.floor(x/8);
cur.push(pixels[idx + 2]); // blue alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
cur.push(pixels[idx + 1]); // green if (cmap) {
cur.push(pixels[idx ]); // red idx = (w0 * y) + x;
cur.push(alpha); // alpha rgb = cmap[pixels[idx]];
cur.push(rgb[2]); // blue
cur.push(rgb[1]); // green
cur.push(rgb[0]); // red
cur.push(alpha); // alpha
} else {
idx = ((w0 * y) + x) * 4;
cur.push(pixels[idx + 2]); // blue
cur.push(pixels[idx + 1]); // green
cur.push(pixels[idx ]); // red
cur.push(alpha); // alpha
}
} }
} }
} }