1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-29 04:22:16 -05:00
Simba/Projects/MMLLib/pymml/mmlcolor.py

89 lines
2.7 KiB
Python
Raw Normal View History

2010-05-31 19:59:48 -04:00
from ctypes import *
from mmltypes import isiterable
from mmltypes import POINT, PPOINT, PINTEGER
2010-06-08 13:16:58 -04:00
from mmltypes import RESULT_OK, RESULT_FALSE, RESULT_ERROR
2010-05-31 19:59:48 -04:00
"""
The Color Class
---------------
This class does the color finding.
"""
2010-05-31 19:59:48 -04:00
class ColorException(Exception):
def __init__(self, err):
Exception.__init__(self, err)
2010-06-08 13:16:58 -04:00
2010-05-31 19:59:48 -04:00
# FIXME: Complete...
class Color(object):
'''
The Color class.
'''
_mc = None
def __init__(self, MC, cli):
2010-06-08 13:16:58 -04:00
"""
Initialise the Color object.
"""
2010-05-31 19:59:48 -04:00
self._mc = MC
self._cli = cli
2010-05-31 19:59:48 -04:00
self._initialiseDLLFuncs()
def find(self, box, color, tol = 0):
2010-06-08 13:16:58 -04:00
"""
find a color in a box, with a specific tolerance.
returns a tuple of the x, y value of a matched color.
None if no color was found.
"""
2010-05-31 19:59:48 -04:00
x, y = (c_int(-1), c_int(-1))
if tol is 0:
ret = self._mc.dll.find_color(self._cli, byref(x), byref(y),
color, *box)
else:
ret = self._mc.dll.find_color_tolerance(self._cli, byref(x),
byref(y), color, tol, *box)
2010-06-08 13:18:48 -04:00
if ret is RESULT_OK:
2010-06-08 13:16:58 -04:00
return (x, y)
return None
2010-05-31 19:59:48 -04:00
def findAll(self, box, color, tol = 0):
2010-06-08 13:16:58 -04:00
"""
find all colors in a box, with a specific tolerance.
2010-06-29 12:19:18 -04:00
returned are all the matching points
2010-06-08 13:16:58 -04:00
"""
ptr, _len = PPOINT(), c_int(42)
print type(_len)
if tol is 0:
self._mc.dll.find_colors(self._cli, byref(ptr), byref(_len),
color, *box)
else:
self._mc.dll.find_colors_tolerance(self._cli, byref(ptr),
byref(_len), color, tol, *box)
# print 'Length:', _len
# for x in range(_len.value):
# print ptr[x].x
# print ptr
2010-06-08 13:16:58 -04:00
# FIXME return python list?
return ''
2010-05-31 19:59:48 -04:00
def _initialiseDLLFuncs(self):
self._mc.dll.find_color.restype = c_int
self._mc.dll.find_color.argtypes = [c_ulong, PINTEGER, PINTEGER, c_int,
2010-06-08 13:16:58 -04:00
c_int, c_int, c_int, c_int]
self._mc.dll.find_color_tolerance.restype = c_int
self._mc.dll.find_color_tolerance.argtypes = [c_ulong, PINTEGER,
PINTEGER, c_int, c_int, c_int, c_int, c_int, c_int]
self._mc.dll.find_colors.restype = c_int
self._mc.dll.find_colors.argtypes = [c_ulong, POINTER(PPOINT),
POINTER(c_int), c_int, c_int, c_int, c_int, c_int]
self._mc.dll.find_colors_tolerance.restype = c_int
self._mc.dll.find_colors_tolerance.argtypes = [c_ulong,
POINTER(PPOINT), POINTER(c_int), c_int, c_int,
2010-06-08 13:16:58 -04:00
c_int, c_int, c_int, c_int]