Changeset - dde4374cb22a
[Not reviewed]
default
0 3 0
Laman - 8 years ago 2017-04-09 16:12:51

imgView: fixed coordinates transformation. fixed onResize glitches
3 files changed with 21 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/gui/boardview.py
Show inline comments
 
@@ -58,3 +58,8 @@ class BoardView(ResizableCanvas):
 
		y=r*self._cellHeight+self._padding
 
		radius=self._cellWidth/2
 
		self.create_oval(x-radius,y-radius,x+radius,y+radius,tags=tag,fill=hexCode)
 

	
 
	def _onResize(self,event):
 
		super()._onResize(event)
 
		self._cellWidth=(self._width-2*self._padding)/18
 
		self._cellHeight=(self._height-2*self._padding)/18
src/gui/imgview.py
Show inline comments
 
@@ -5,6 +5,7 @@ from PIL import ImageTk
 
import config
 
from .resizablecanvas import ResizableCanvas
 
from corners import Corners
 
from epoint import EPoint
 
from grid import Grid
 
import imageanalyzer
 

	
 
@@ -19,7 +20,6 @@ class ImgView(ResizableCanvas):
 

	
 
		self._img=None
 
		self._tkImg=None
 
		self._imgSizeCoef=1
 

	
 
		self.configure(width=480,height=360)
 
		self.bind('<1>',lambda e: self.addCorner(e.x,e.y))
 
@@ -54,25 +54,17 @@ class ImgView(ResizableCanvas):
 
					self.create_rectangle(r1,c1,r2,c2,outline="#00ffff")
 

	
 
	def setImg(self,img):
 
		w=int(self._width)
 
		h=int(self._height)
 
		wo,ho=img.size # o for original
 
		widthRatio=wo/w
 
		heightRatio=ho/h
 
		self._imgSizeCoef=max(widthRatio,heightRatio)
 

	
 
		self._img=img
 

	
 
	## Stores a grid corner located at x,y coordinates.
 
	def addCorner(self,x,y):
 
		self._corners.add(x,y)
 
		log.debug("click on %d,%d",x,y)
 
		log.debug("sizeCoef: %f",self._imgSizeCoef)
 
		if self._corners.canonizeOrder():
 
			# transform corners from show coordinates to real coordinates
 
			log.debug(self._corners.corners)
 
			self._boardGrid=Grid(self._corners.corners)
 
			corners=[(c*self._imgSizeCoef) for c in self._corners.corners]
 
			corners=[self._transformPoint(c) for c in self._corners.corners]
 
			self._parent.sendMsg("setCorners",(corners,))
 

	
 
		self.redraw()
 
@@ -86,5 +78,17 @@ class ImgView(ResizableCanvas):
 
		w=self._width
 
		super()._onResize(event)
 
		self._corners.scale(self._width/w)
 
		if len(self._corners.corners)==4:
 
		self._boardGrid=Grid(self._corners.corners)
 
		self.redraw()
 

	
 
	def _transformPoint(self,point):
 
		w=int(self._width)
 
		h=int(self._height)
 
		wo,ho=self._img.size # o for original
 
		widthRatio=wo/w
 
		heightRatio=ho/h
 
		self._imgSizeCoef=max(widthRatio,heightRatio)
 
		# shift compensates possible horizontal or vertical empty margins from unmatching aspect ratios
 
		self._imgShift=EPoint(wo-w*self._imgSizeCoef,ho-h*self._imgSizeCoef)/2
 
		return EPoint(self.canvasx(point.x),self.canvasy(point.y)) * self._imgSizeCoef + self._imgShift
src/imageanalyzer.py
Show inline comments
 
@@ -35,7 +35,9 @@ class ImageAnalyzer:
 
 
		for y in range(y1,y2+1):
 
			for x in range(x1,x2+1):
 
				try:
 
				red,green,blue=image.getpixel((x,y))
 
				except IndexError: continue
 
 
				I=(red+green+blue)/255/3
 
				m=min(red,green,blue)
0 comments (0 inline, 0 general)