export default {
	id : 1,
	testUrl:'http://192.168.1.5:10086',
	zIndex:2,
	setColor:(rgba:any,url:string,obj:any) =>{
		return new Promise(resolve =>{
		 var min = obj?.min == undefined ? 5 : obj.min;
		 var max = obj?.max == undefined ? 5 : obj.max;
		 var img = new Image();
		 img.src = url;
		 img.onload = () => {
			 const width = img.width;
			 const height = img.height;
			 const canvas = document.createElement("canvas");
			 canvas.width = width
			 canvas.height = height
			 var ctx:any = canvas.getContext("2d");
			 ctx.drawImage(img,0,0)
			 var data = ctx.getImageData(0,0,width,height)
			 var ratio = []
			 for (let index = 0; index < rgba.length; index++) {
				var num = 0;
				for (let i = 0; i < data.data.length; i+=4) {
					var r = data.data[i];
					var g = data.data[i+1];
					var b = data.data[i+2];
					var a = data.data[i+3];
					if(r - min < rgba[index][0] 
						&& r + max > rgba[index][0]
						&& g - min < rgba[index][1] 
						&& g + max > rgba[index][1]
						&& b - min < rgba[index][2]
						&& b + max > rgba[index][2]
						){
							num++
						}
				}
				let rgb = {
					rgb:rgba[index],
					ratio:parseInt(String((num/ (width * height) * 100).toFixed(6)))
				}
				ratio.push(rgb)
				// console.log((num/ (width * height) * 100).toFixed(2));

			 }
			 
			 resolve({
				 width,
				 height,
				 ratio:ratio,
			 })
		 }
		})
	 },
	//  magnifying(normalEl,binEl,mouseWH:any){
	// 	let mouseW = mouseWH.width?mouseWH.width:10+'rem'
	// 	let mouseH = mouseWH.height?mouseWH.height:10+'rem'
	// 	normalEl.offsetWidth
	//  }
}