Skip to content

Instantly share code, notes, and snippets.

@yuiAs
Created April 3, 2014 12:15
Show Gist options
  • Select an option

  • Save yuiAs/ad8d14da44bb6f354e11 to your computer and use it in GitHub Desktop.

Select an option

Save yuiAs/ad8d14da44bb6f354e11 to your computer and use it in GitHub Desktop.
SWF DefineBitsJPEG3から取得したデータにcanvas経由でαを適用
util.combineAlphaMask = function(image, mask) {
// drawImage, getImageData, putImageDataは doubleを取るので整数化する
// 仮キャンバス作成,描画
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(image, 0|0, 0|0);
// α適用
var d = ctx.getImageData(0|0, 0|0, canvas.width, canvas.height);
var p = d.data;
for (var i=0, j=0; i < p.length; i+=4, j++) {
p[i+3] = mask[j];
}
ctx.putImageData(d, 0|0, 0|0);
return canvas;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment