File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 111
111
112
112
function getColor ( ) {
113
113
RGBaster . colors ( imgDom , {
114
- exclude : [ ] ,
114
+ exclude : [ '255,255,255' ] , //需要去除的颜色 模糊(不提供时会主动提取背景色!)
115
115
success : function ( payload ) {
116
116
// payload.dominant是主色,RGB形式表示
117
117
// payload.secondary是次色,RGB形式表示
Original file line number Diff line number Diff line change 160
160
dominant : { name : '' , count : 0 } ,
161
161
palette : [ ]
162
162
} ;
163
- let _backColorRangeArr = backColorRange ( fmtImgData ( data ) ) . name . split ( ',' ) ;
163
+ //获取 图片背景色
164
+ let _backColorRangeArr = exclude . length ? exclude : [ backColorRange ( fmtImgData ( data ) ) . name ] ;
164
165
let _bias = RGBaster . backColorRange . bias ;
165
166
var i = 0 ;
166
167
for ( ; i < data . length ; i += 4 ) {
176
177
}
177
178
178
179
//skip background color range
179
- if ( ( Math . abs ( _backColorRangeArr [ 0 ] - data [ i ] ) < _bias && Math . abs ( _backColorRangeArr [ 1 ] - data [ i + 1 ] ) < _bias && Math . abs ( _backColorRangeArr [ 2 ] - data [ i + 2 ] ) < _bias ) ) {
180
- // console.log(rgbString)
181
- continue ;
180
+ let isBackColorRangeFlag = false ;
181
+ for ( let color of _backColorRangeArr ) {
182
+ let _color = color . split ( ',' ) ;
183
+ if ( ( Math . abs ( _color [ 0 ] - data [ i ] ) < _bias && Math . abs ( _color [ 1 ] - data [ i + 1 ] ) < _bias && Math . abs ( _color [ 2 ] - data [ i + 2 ] ) < _bias ) ) {
184
+ // console.log(rgbString)
185
+ isBackColorRangeFlag = true ;
186
+ break ;
187
+ }
188
+ }
189
+ if ( isBackColorRangeFlag ) {
190
+ continue ;
182
191
}
192
+
183
193
// Ignore those colors in the exclude list.
184
- if ( exclude . indexOf ( makeRGB ( rgbString ) ) === - 1 ) {
194
+ if ( exclude . indexOf ( rgbString ) === - 1 ) {
185
195
//计数
186
196
if ( rgbString in colorCounts ) {
187
197
colorCounts [ rgbString ] = colorCounts [ rgbString ] + 1 ;
You can’t perform that action at this time.
0 commit comments