This commit is contained in:
Andreas Gal 2014-08-05 19:41:12 -07:00
Родитель 801662f0cc
Коммит 646ea9d3e7
1 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -422,4 +422,31 @@
data.class.getField("height", "I").set(data, height);
data.class.getField("nativeImageData", "I").set(data, texture);
}
Native["javax/microedition/lcdui/ImageData.getRGB.([IIIIIII)V"] = function(ctx, stack) {
var height = stack.pop(), width = stack.pop(), y = stack.pop(), x = stack.pop(), scanlength = stack.pop(), offset = stack.pop(),
rgbData = stack.pop(), _this = stack.pop();
var texture = _this.class.getField("nativeImageData", "I").get(_this);
// If nativeImageData is not a canvas texture already, then convert it now.
if (!(texture instanceof HTMLCanvasElement)) {
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(texture, 0, 0);
texture = canvas;
_this.class.getField("nativeImageData", "I").set(_this, texture);
}
var imageData = texture.getContext("2d").getImageData(x, y, width, height);
var i = 0;
for (y = 0; y < height; ++y) {
var j = offset + y * scanlength;
for (x = 0; x < width; ++x) {
rgbData[j++] = imageData[i++];
rgbData[j++] = imageData[i++];
rgbData[j++] = imageData[i++];
rgbData[j++] = imageData[i++];
}
}
}
})(Native);