@@ -16,14 +16,9 @@ export class Eyedropper {
16
16
}
17
17
18
18
const canvas = BB . canvas ( 1 , 1 ) ;
19
- const ctx = BB . ctx ( canvas , { willReadFrequently : true } ) ;
19
+ const ctx = BB . ctx ( canvas ) ;
20
20
ctx . imageSmoothingEnabled = false ;
21
21
22
- const layerCanvas = BB . canvas ( 1 , 1 ) ;
23
- const layerCtx = BB . ctx ( layerCanvas ) ;
24
- layerCtx . imageSmoothingEnabled = false ;
25
- const imageData = new ImageData ( 1 , 1 ) ;
26
-
27
22
const tilesX = Math . ceil ( composed . size . width / HISTORY_TILE_SIZE ) ;
28
23
const tileCol = Math . floor ( x / HISTORY_TILE_SIZE ) ;
29
24
const tileRow = Math . floor ( y / HISTORY_TILE_SIZE ) ;
@@ -44,6 +39,7 @@ export class Eyedropper {
44
39
return ;
45
40
}
46
41
const tile = layer . tiles [ tileIndex ] ;
42
+ let fillStyle = '' ;
47
43
if ( tile instanceof ImageData ) {
48
44
let tileWidth = HISTORY_TILE_SIZE ;
49
45
if ( composed . size . width % HISTORY_TILE_SIZE !== 0 && tileCol === tilesX - 1 ) {
@@ -52,20 +48,24 @@ export class Eyedropper {
52
48
const pixelIndex =
53
49
( y % HISTORY_TILE_SIZE ) * tileWidth + ( x % HISTORY_TILE_SIZE ) ;
54
50
55
- imageData . data [ 0 ] = tile . data [ pixelIndex * 4 ] ;
56
- imageData . data [ 1 ] = tile . data [ pixelIndex * 4 + 1 ] ;
57
- imageData . data [ 2 ] = tile . data [ pixelIndex * 4 + 2 ] ;
58
- imageData . data [ 3 ] = tile . data [ pixelIndex * 4 + 3 ] ;
59
- layerCtx . putImageData ( imageData , 0 , 0 ) ;
51
+ if ( tile . data [ pixelIndex * 4 + 3 ] === 0 ) {
52
+ return ;
53
+ }
54
+
55
+ fillStyle = BB . ColorConverter . toRgbaStr ( {
56
+ r : tile . data [ pixelIndex * 4 ] ,
57
+ g : tile . data [ pixelIndex * 4 + 1 ] ,
58
+ b : tile . data [ pixelIndex * 4 + 2 ] ,
59
+ a : tile . data [ pixelIndex * 4 + 3 ] ,
60
+ } ) ;
60
61
} else {
61
- layerCtx . clearRect ( 0 , 0 , 1 , 1 ) ;
62
- layerCtx . fillStyle = tile . fill ;
63
- layerCtx . fillRect ( 0 , 0 , 1 , 1 ) ;
62
+ fillStyle = tile . fill ;
64
63
}
65
64
65
+ ctx . fillStyle = fillStyle ;
66
66
ctx . globalAlpha = layer . opacity ;
67
67
ctx . globalCompositeOperation = layer . mixModeStr ;
68
- ctx . drawImage ( layerCanvas , 0 , 0 ) ;
68
+ ctx . fillRect ( 0 , 0 , 1 , 1 ) ;
69
69
} ) ;
70
70
71
71
const imData = ctx . getImageData ( 0 , 0 , 1 , 1 ) ;
0 commit comments