A simple image class for pixel graphics can be used here. In the basic class you can include everything necessary for a graphic: Information about the width, height, and the pixel data in a two-dimensional array. A example for the same lies below.
PHP Code:
function image pixels (width, height) (
this.getWidth = function () (
this.mWidth return;
)
this.getHeight = function () (
this.mHeight return;
)
this.getRow = function (y) (
return this.mImageRows [y];
)
/ / Our constructor creates the image and fills it with zero
this.mWidth = width;
this.mHeight = height;
this.mImageRows = [];
for (var y = 0, y <height; y + +) (
var row = [];
for (var x = 0, x <width; x + +) (
row.push (0);
)
this.mImageRows.push (row);
)
Now we can build us a small picture with a gradient from green to red: P
var image = new Image pixels (64, 256);
PHP Code:
)
for (var y = 0, y <image.getHeight (), y + +) (
var row = image.getRow (y);
for (var x = 0, x <image.getWidth (), x + +) (
row [x] = (y <<16) | ((255 - y) <<8);
)
)
As you can see, we store all the pixels in RGB format, 8bit per color channel.
Bookmarks