Skip to content

Commit 1a431ff

Browse files
committed
canvaslite
1 parent 4cbff8f commit 1a431ff

File tree

1 file changed

+10
-49
lines changed

1 file changed

+10
-49
lines changed

examples/CanvasLite.js

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* CanvasLite
33
* an html canvas implementation in pure JavaScript
44
*
5-
* @version 0.9.92r2 (2023-08-02 12:05:01)
5+
* @version 0.9.92r2 (2023-08-02 12:49:06)
66
* https://github.com/foo123/CanvasLite
77
*
88
**//**
99
* CanvasLite
1010
* an html canvas implementation in pure JavaScript
1111
*
12-
* @version 0.9.92r2 (2023-08-02 12:05:01)
12+
* @version 0.9.92r2 (2023-08-02 12:49:06)
1313
* https://github.com/foo123/CanvasLite
1414
*
1515
**/
@@ -277,7 +277,7 @@ function RenderingContext2D(width, height, set_rgba_at, get_rgba_from)
277277
set: function(c) {
278278
if (c instanceof Gradient || c instanceof Pattern)
279279
{
280-
get_stroke_at = Rasterizer.getRGBAFrom(c.getColorAt.bind(c));
280+
get_stroke_at = c.getColorAt.bind(c);
281281
}
282282
else
283283
{
@@ -292,7 +292,7 @@ function RenderingContext2D(width, height, set_rgba_at, get_rgba_from)
292292
set: function(c) {
293293
if (c instanceof Gradient || c instanceof Pattern)
294294
{
295-
get_fill_at = Rasterizer.getRGBAFrom(c.getColorAt.bind(c));
295+
get_fill_at = c.getColorAt.bind(c);
296296
}
297297
else
298298
{
@@ -3314,37 +3314,16 @@ function Gradient(grad_color_at)
33143314
self.getColorAt = function(x, y) {
33153315
var im = transform.imatrix(true),
33163316
p = im ? im.transform(x, y) : null,
3317-
rgba = new ImArray(4);
3317+
rgba = [0, 0, 0, 0];
33183318
return p ? grad_color_at(p[0], p[1], colorStops(), rgba, 0) : rgba;
33193319
};
3320-
self.getBitmap = function(width, height) {
3321-
width = stdMath.round(width);
3322-
height = stdMath.round(height);
3323-
var imatrix = transform.imatrix(true),
3324-
color_stops,
3325-
i, x, y, p,
3326-
size = (width*height) << 2,
3327-
bmp = new ImArray(size);
3328-
if (imatrix)
3329-
{
3330-
color_stops = colorStops();
3331-
for (x=0,y=0,i=0; i<size; i+=4,++x)
3332-
{
3333-
if (x >= width) {x=0; ++y;}
3334-
p = imatrix.transform(x, y);
3335-
grad_color_at(p[0], p[1], color_stops, bmp, i);
3336-
}
3337-
}
3338-
return bmp;
3339-
};
33403320
}
33413321
Gradient.VERSION = "1.2.3";
33423322
Gradient[PROTO] = {
33433323
constructor: Gradient,
33443324
transform: null,
33453325
addColorStop: null,
3346-
getColorAt: null,
3347-
getBitmap: null
3326+
getColorAt: null
33483327
};
33493328
Gradient.createLinearGradient = function(x1, y1, x2, y2) {
33503329
x1 = x1 || 0;
@@ -3487,38 +3466,20 @@ function Pattern(pat_color_at)
34873466
configurable: false
34883467
});
34893468
self.getColorAt = function(x, y) {
3490-
var im = transform.imatrix(true), p, rgba = new ImArray(4);
3469+
var im = transform.imatrix(true), p, rgba = [0, 0, 0, 0];
34913470
if (im)
34923471
{
34933472
p = im.transform(x, y);
34943473
pat_color_at(p[0], p[1], rgba, 0);
34953474
}
3475+
rgba[3] /= 255;
34963476
return rgba;
34973477
};
3498-
self.getBitmap = function(width, height) {
3499-
width = stdMath.round(width);
3500-
height = stdMath.round(height);
3501-
var imatrix = transform.imatrix(true),
3502-
i, x, y, p,
3503-
size = (width*height) << 2,
3504-
bmp = new ImArray(size);
3505-
if (imatrix)
3506-
{
3507-
for (x=0,y=0,i=0; i<size; i+=4,++x)
3508-
{
3509-
if (x >= width) {x=0; ++y;}
3510-
p = imatrix.transform(x, y);
3511-
pat_color_at(p[0], p[1], bmp, i);
3512-
}
3513-
}
3514-
return bmp;
3515-
};
35163478
}
35173479
Pattern[PROTO] = {
35183480
constructor: Pattern,
35193481
transform: null,
3520-
getColorAt: null,
3521-
getBitmap: null
3482+
getColorAt: null
35223483
};
35233484
Pattern.createPattern = function(imageData, repetition) {
35243485
if (imageData && ('function' === typeof imageData.getImageData)) imageData = imageData.getImageData();
@@ -3733,7 +3694,7 @@ function interpolatePixel(pixel, index, rgba0, rgba1, t)
37333694
pixel[index + 0] = clamp(stdMath.round(rgba0[0] + t*(rgba1[0] - rgba0[0])), 0, 255);
37343695
pixel[index + 1] = clamp(stdMath.round(rgba0[1] + t*(rgba1[1] - rgba0[1])), 0, 255);
37353696
pixel[index + 2] = clamp(stdMath.round(rgba0[2] + t*(rgba1[2] - rgba0[2])), 0, 255);
3736-
pixel[index + 3] = 3 < rgba0.length ? clamp(stdMath.round(255*(rgba0[3] + t*(rgba1[3] - rgba0[3]))), 0, 255) : 255;
3697+
pixel[index + 3] = 3 < rgba0.length ? clamp(rgba0[3] + t*(rgba1[3] - rgba0[3]), 0, 1) : 1;
37373698
return pixel;
37383699
}
37393700
var hexRE = /^#([0-9a-fA-F]{3,6})\b/,

0 commit comments

Comments
 (0)