1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-01 05:12:16 -05:00
Simba/Projects/MMLLib/pymml/mmlcolor.py
Merlijn Wajer 9f6cdb2de3 libMML: Swapped tolerance parameters.
pyMML: Added findColorTolerance and findColorsTolerance.
2010-06-01 13:40:51 +02:00

52 lines
1.5 KiB
Python

from ctypes import *
from mmltypes import isiterable
from mmltypes import POINT, PPOINT, PINTEGER
from mmltypes import PascalArray
class ColorException(Exception):
def __init__(self, err):
Exception.__init__(self, err)
# FIXME: Complete...
class Color(object):
'''
The Color class.
'''
_mc = None
def __init__(self, MC):
self._mc = MC
self._initialiseDLLFuncs()
def find(self, box, color, tol = 0):
x, y = (c_int(-1), c_int(-1))
if tol is 0:
ret = self._mc.dll.findColor(byref(x), byref(y), color, *box)
else:
ret = self._mc.dll.findColorTolerance(byref(x), byref(y), color,
tol, *box)
return (x, y)
def findAll(self, box, color, tol = 0):
ptr = PPOINT()
if tol is 0:
self._mc.dll.findColors(byref(ptr), color, *box)
else:
self._mc.dll.findColors(byref(ptr), color, tol, *box)
arr = PascalArray(POINT, ptr, self._mc)
print 'Length:', len(arr)
# for i in range(len(arr)):
# print i, arr[i].x, arr[i].y
return arr
def _initialiseDLLFuncs(self):
self._mc.dll.findColor.restype = c_int
self._mc.dll.findColor.argtypes = [PINTEGER, PINTEGER, c_int, c_int,
c_int, c_int, c_int]
self._mc.dll.findColors.restype = c_int
self._mc.dll.findColors.argtypes = [POINTER(PPOINT), c_int, c_int,
c_int, c_int, c_int]