2
2
* CanvasLite
3
3
* an html canvas implementation in pure JavaScript
4
4
*
5
- * @version 0.9.92r2 (2023-08-02 12:05:01 )
5
+ * @version 0.9.92r2 (2023-08-02 12:49:06 )
6
6
* https://github.com/foo123/CanvasLite
7
7
*
8
8
**/ /**
9
9
* CanvasLite
10
10
* an html canvas implementation in pure JavaScript
11
11
*
12
- * @version 0.9.92r2 (2023-08-02 12:05:01 )
12
+ * @version 0.9.92r2 (2023-08-02 12:49:06 )
13
13
* https://github.com/foo123/CanvasLite
14
14
*
15
15
**/
@@ -277,7 +277,7 @@ function RenderingContext2D(width, height, set_rgba_at, get_rgba_from)
277
277
set : function ( c ) {
278
278
if ( c instanceof Gradient || c instanceof Pattern )
279
279
{
280
- get_stroke_at = Rasterizer . getRGBAFrom ( c . getColorAt . bind ( c ) ) ;
280
+ get_stroke_at = c . getColorAt . bind ( c ) ;
281
281
}
282
282
else
283
283
{
@@ -292,7 +292,7 @@ function RenderingContext2D(width, height, set_rgba_at, get_rgba_from)
292
292
set : function ( c ) {
293
293
if ( c instanceof Gradient || c instanceof Pattern )
294
294
{
295
- get_fill_at = Rasterizer . getRGBAFrom ( c . getColorAt . bind ( c ) ) ;
295
+ get_fill_at = c . getColorAt . bind ( c ) ;
296
296
}
297
297
else
298
298
{
@@ -3314,37 +3314,16 @@ function Gradient(grad_color_at)
3314
3314
self . getColorAt = function ( x , y ) {
3315
3315
var im = transform . imatrix ( true ) ,
3316
3316
p = im ? im . transform ( x , y ) : null ,
3317
- rgba = new ImArray ( 4 ) ;
3317
+ rgba = [ 0 , 0 , 0 , 0 ] ;
3318
3318
return p ? grad_color_at ( p [ 0 ] , p [ 1 ] , colorStops ( ) , rgba , 0 ) : rgba ;
3319
3319
} ;
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
- } ;
3340
3320
}
3341
3321
Gradient . VERSION = "1.2.3" ;
3342
3322
Gradient [ PROTO ] = {
3343
3323
constructor : Gradient ,
3344
3324
transform : null ,
3345
3325
addColorStop : null ,
3346
- getColorAt : null ,
3347
- getBitmap : null
3326
+ getColorAt : null
3348
3327
} ;
3349
3328
Gradient . createLinearGradient = function ( x1 , y1 , x2 , y2 ) {
3350
3329
x1 = x1 || 0 ;
@@ -3487,38 +3466,20 @@ function Pattern(pat_color_at)
3487
3466
configurable : false
3488
3467
} ) ;
3489
3468
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 ] ;
3491
3470
if ( im )
3492
3471
{
3493
3472
p = im . transform ( x , y ) ;
3494
3473
pat_color_at ( p [ 0 ] , p [ 1 ] , rgba , 0 ) ;
3495
3474
}
3475
+ rgba [ 3 ] /= 255 ;
3496
3476
return rgba ;
3497
3477
} ;
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
- } ;
3516
3478
}
3517
3479
Pattern [ PROTO ] = {
3518
3480
constructor : Pattern ,
3519
3481
transform : null ,
3520
- getColorAt : null ,
3521
- getBitmap : null
3482
+ getColorAt : null
3522
3483
} ;
3523
3484
Pattern . createPattern = function ( imageData , repetition ) {
3524
3485
if ( imageData && ( 'function' === typeof imageData . getImageData ) ) imageData = imageData . getImageData ( ) ;
@@ -3733,7 +3694,7 @@ function interpolatePixel(pixel, index, rgba0, rgba1, t)
3733
3694
pixel [ index + 0 ] = clamp ( stdMath . round ( rgba0 [ 0 ] + t * ( rgba1 [ 0 ] - rgba0 [ 0 ] ) ) , 0 , 255 ) ;
3734
3695
pixel [ index + 1 ] = clamp ( stdMath . round ( rgba0 [ 1 ] + t * ( rgba1 [ 1 ] - rgba0 [ 1 ] ) ) , 0 , 255 ) ;
3735
3696
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 ;
3737
3698
return pixel ;
3738
3699
}
3739
3700
var hexRE = / ^ # ( [ 0 - 9 a - f A - F ] { 3 , 6 } ) \b / ,
0 commit comments