@@ -866,6 +866,7 @@ export class Paint implements IPaint {
866
866
color : Color ;
867
867
} ;
868
868
shader ;
869
+ colorFilter ;
869
870
pathEffect : PathEffect ;
870
871
xfermode : IPorterDuffXfermode ;
871
872
mTextAttribs : NSMutableDictionary < any , any > ;
@@ -967,6 +968,9 @@ export class Paint implements IPaint {
967
968
public getShader ( ) {
968
969
return this . shader ;
969
970
}
971
+ public getColorFilter ( ) {
972
+ return this . colorFilter ;
973
+ }
970
974
public setStrokeWidth ( value : number ) : void {
971
975
this . strokeWidth = value ;
972
976
}
@@ -1003,6 +1007,12 @@ export class Paint implements IPaint {
1003
1007
}
1004
1008
this . shader = value ;
1005
1009
}
1010
+ public setColorFilter ( value : any ) {
1011
+ if ( this . colorFilter ) {
1012
+ this . colorFilter . release ( ) ;
1013
+ }
1014
+ this . colorFilter = value ;
1015
+ }
1006
1016
setFont ( font : Font ) {
1007
1017
if ( font === this . mFont ) {
1008
1018
return ;
@@ -1145,6 +1155,10 @@ export class Paint implements IPaint {
1145
1155
this . shader . clear ( ) ;
1146
1156
this . shader = null ;
1147
1157
}
1158
+ if ( this . colorFilter ) {
1159
+ this . colorFilter . clear ( ) ;
1160
+ this . colorFilter = null ;
1161
+ }
1148
1162
}
1149
1163
public setPathEffect ( param0 : PathEffect ) {
1150
1164
this . pathEffect = param0 ;
@@ -1415,17 +1429,32 @@ export class Canvas implements ICanvas {
1415
1429
if ( ! image ) {
1416
1430
return ;
1417
1431
}
1432
+ const length = args . length ;
1433
+ const paint = args [ length - 1 ] as Paint ;
1434
+ let cgImage ;
1435
+ if ( paint ?. colorFilter ) {
1436
+ const ciFilter = paint . colorFilter . ciFilter ;
1437
+ const tmp = CIImage . alloc ( ) . initWithImage ( image ) ;
1438
+ ciFilter . setValueForKey ( tmp , 'inputImage' ) ;
1439
+
1440
+ const outputRect = tmp . extent ;
1441
+ const context = CIContext . contextWithOptions ( null ) ;
1442
+ cgImage = context . createCGImageFromRect ( ciFilter . outputImage , outputRect ) ;
1443
+ // image = UIImage.imageWithCGImageScaleOrientation(cgim, image.scale, image.imageOrientation);
1444
+ } else {
1445
+ cgImage = image . CGImage ;
1446
+ }
1418
1447
1419
1448
if ( args [ 1 ] instanceof Matrix ) {
1420
1449
CGContextConcatCTM ( ctx , args [ 1 ] . _transform ) ;
1421
1450
CGContextTranslateCTM ( ctx , 0 , image . size . height ) ;
1422
1451
CGContextScaleCTM ( ctx , 1.0 , - 1.0 ) ;
1423
- CGContextDrawImage ( ctx , CGRectMake ( 0 , 0 , image . size . width , image . size . height ) , image . CGImage ) ;
1452
+ CGContextDrawImage ( ctx , CGRectMake ( 0 , 0 , image . size . width , image . size . height ) , cgImage ) ;
1424
1453
} else {
1425
1454
const dst = args [ 2 ] instanceof Rect ? args [ 2 ] . cgRect : CGRectMake ( args [ 1 ] , args [ 2 ] , image . size . width , image . size . height ) ;
1426
1455
CGContextTranslateCTM ( ctx , 0 , dst . origin . y + dst . size . height ) ;
1427
1456
CGContextScaleCTM ( ctx , 1.0 , - 1.0 ) ;
1428
- CGContextDrawImage ( ctx , CGRectMake ( dst . origin . x , 0 , dst . size . width , dst . size . height ) , image . CGImage ) ;
1457
+ CGContextDrawImage ( ctx , CGRectMake ( dst . origin . x , 0 , dst . size . width , dst . size . height ) , cgImage ) ;
1429
1458
}
1430
1459
}
1431
1460
@@ -2156,6 +2185,27 @@ export class LinearGradient {
2156
2185
}
2157
2186
}
2158
2187
}
2188
+ export class ColorMatrixColorFilter {
2189
+ _ciFilter ;
2190
+ constructor ( private values : number [ ] ) { }
2191
+ get ciFilter ( ) {
2192
+ if ( ! this . _ciFilter ) {
2193
+ this . _ciFilter = CIFilter . filterWithName ( 'CIColorMatrix' ) ;
2194
+ const value = this . values ;
2195
+ this . _ciFilter . setValueForKey ( CIVector . vectorWithValuesCount ( new FloatConstructor ( value . slice ( 0 , 4 ) ) . buffer as any , 4 ) , 'inputRVector' ) ;
2196
+ this . _ciFilter . setValueForKey ( CIVector . vectorWithValuesCount ( new FloatConstructor ( value . slice ( 5 , 9 ) ) . buffer as any , 4 ) , 'inputGVector' ) ;
2197
+ this . _ciFilter . setValueForKey ( CIVector . vectorWithValuesCount ( new FloatConstructor ( value . slice ( 10 , 14 ) ) . buffer as any , 4 ) , 'inputBVector' ) ;
2198
+ this . _ciFilter . setValueForKey ( CIVector . vectorWithValuesCount ( new FloatConstructor ( value . slice ( 15 , 19 ) ) . buffer as any , 4 ) , 'inputAVector' ) ;
2199
+ this . _ciFilter . setValueForKey ( CIVector . vectorWithValuesCount ( new FloatConstructor ( [ value [ 4 ] , value [ 9 ] , value [ 14 ] , value [ 19 ] ] ) . buffer as any , 4 ) , 'inputBiasVector' ) ;
2200
+ }
2201
+ return this . _ciFilter ;
2202
+ }
2203
+ release ( ) {
2204
+ if ( this . _ciFilter ) {
2205
+ this . _ciFilter = undefined ;
2206
+ }
2207
+ }
2208
+ }
2159
2209
export class RadialGradient {
2160
2210
_gradient ;
2161
2211
constructor ( public centerX : number , public centerY : number , public radius : number , public colors : any , public stops : any , public tileMode : TileMode ) { }
0 commit comments