@@ -587,6 +587,42 @@ function Croquis(imageDataList, properties) {
587
587
pushLayerVisibleUndo ( index ) ;
588
588
layers [ index ] . style . visibility = visible ? 'visible' : 'hidden' ;
589
589
} ;
590
+ function makeColorData ( imageData1x1 ) {
591
+ var data = imageData1x1 . data ;
592
+ var r = data [ 0 ] ;
593
+ var g = data [ 1 ] ;
594
+ var b = data [ 2 ] ;
595
+ var a = data [ 3 ] ;
596
+ return {
597
+ r : r , g : g , b : b , a : a ,
598
+ htmlColor : 'rgba(' + [ r , g , b , a / 0xff ] . join ( ',' ) + ')'
599
+ } ;
600
+ }
601
+ self . pickColor = function ( x , y , index ) {
602
+ if ( ( x < 0 ) || ( x >= size . width ) || ( y < 0 ) || ( y >= size . height ) )
603
+ return null ;
604
+ index = ( index == null ) ? layerIndex : index ;
605
+ return makeColorData ( getLayerContext ( index ) . getImageData ( x , y , 1 , 1 ) ) ;
606
+ } ;
607
+ self . eyeDrop = function ( x , y , baseColor ) {
608
+ if ( self . pickColor ( x , y ) == null )
609
+ return null ;
610
+ baseColor = ( baseColor == null ) ? '#fff' : baseColor ;
611
+ var plane = document . createElement ( 'canvas' ) ;
612
+ plane . width = 1 ;
613
+ plane . height = 1 ;
614
+ var planeContext = plane . getContext ( '2d' ) ;
615
+ planeContext . fillStyle = baseColor ;
616
+ planeContext . fillRect ( 0 , 0 , 1 , 1 ) ;
617
+ for ( var i = 0 ; i < layers . length ; ++ i ) {
618
+ if ( ! self . getLayerVisible ( i ) )
619
+ continue ;
620
+ planeContext . globalAlpha = self . getLayerOpacity ( i ) ;
621
+ planeContext . fillStyle = self . pickColor ( x , y , i ) . htmlColor ;
622
+ planeContext . fillRect ( 0 , 0 , 1 , 1 ) ;
623
+ }
624
+ return makeColorData ( planeContext . getImageData ( 0 , 0 , 1 , 1 ) ) ;
625
+ } ;
590
626
var tool ;
591
627
var toolStabilizeLevel = 0 ;
592
628
var toolStabilizeWeight = 0.8 ;
0 commit comments