Add Python 2.6 compatibility, disabled one API method in evas.Image
Image.image_data_memoryview_get was disabled. This method can be added back once we figure out how to do conditional compilation using Python version. Using an evas.Image instance as a memoryview object should do the same thing as the disabled method.
This commit is contained in:
parent
cacde3e38a
commit
a9a944b17b
6
INSTALL
6
INSTALL
|
@ -2,8 +2,8 @@
|
||||||
1. REQUIREMENTS:
|
1. REQUIREMENTS:
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
* Python 2.7 or higher (http://www.python.org/)
|
* Python 2.6 or higher (http://www.python.org/)
|
||||||
- Tested with Python 2.7 / 3.2
|
- Tested with Python 2.6 / 2.7 / 3.2 / 3.3
|
||||||
|
|
||||||
* Cython 0.17.0 or higher (http://cython.org/)
|
* Cython 0.17.0 or higher (http://cython.org/)
|
||||||
- Tested with Cython 0.17.1
|
- Tested with Cython 0.17.1
|
||||||
|
@ -89,6 +89,8 @@
|
||||||
tests or use the 00_run_all_tests.py in each folder or even in the tests/ base
|
tests or use the 00_run_all_tests.py in each folder or even in the tests/ base
|
||||||
dir to run all the tests at once.
|
dir to run all the tests at once.
|
||||||
|
|
||||||
|
Python 2.7 is required for running the tests.
|
||||||
|
|
||||||
The scripts in examples/ folder must be run by the user as they require
|
The scripts in examples/ folder must be run by the user as they require
|
||||||
user interaction.
|
user interaction.
|
||||||
|
|
||||||
|
|
|
@ -497,99 +497,99 @@ cdef class Image(Object):
|
||||||
|
|
||||||
PyBuffer_Release(&view)
|
PyBuffer_Release(&view)
|
||||||
|
|
||||||
def image_data_memoryview_get(self, bint for_writing=False, bint simple=True):
|
# def image_data_memoryview_get(self, bint for_writing=False, bint simple=True):
|
||||||
"""image_data_memoryview_get(bool for_writing) -> MemoryView
|
# """image_data_memoryview_get(bool for_writing) -> MemoryView
|
||||||
|
|
||||||
Get a MemoryView object to the raw image data of the given image object.
|
# Get a MemoryView object to the raw image data of the given image object.
|
||||||
|
|
||||||
:param bool for_writing: Whether the data being retrieved will be
|
# :param bool for_writing: Whether the data being retrieved will be
|
||||||
modified or not.
|
# modified or not.
|
||||||
:param bool simple: Whether the MemoryView is 1D or 2D
|
# :param bool simple: Whether the MemoryView is 1D or 2D
|
||||||
:return MemoryView: The raw image data.
|
# :return MemoryView: The raw image data.
|
||||||
|
|
||||||
This method returns a MemoryView object to an image object's internal pixel
|
# This method returns a MemoryView object to an image object's internal pixel
|
||||||
buffer, for reading only or read/write. If you request it for
|
# buffer, for reading only or read/write. If you request it for
|
||||||
writing, the image will be marked dirty so that it gets redrawn at
|
# writing, the image will be marked dirty so that it gets redrawn at
|
||||||
the next update.
|
# the next update.
|
||||||
|
|
||||||
Each time you call this method on an image object, its data
|
# Each time you call this method on an image object, its data
|
||||||
buffer will have an internal reference counter
|
# buffer will have an internal reference counter
|
||||||
incremented. Decrement it back by using
|
# incremented. Decrement it back by using
|
||||||
:py:func:`image_data_set`.
|
# :py:func:`image_data_set`.
|
||||||
|
|
||||||
This is best suited for when you want to modify an existing image,
|
# This is best suited for when you want to modify an existing image,
|
||||||
without changing its dimensions.
|
# without changing its dimensions.
|
||||||
|
|
||||||
.. note::
|
# .. note::
|
||||||
The contents' format returned by it depend on the color
|
# The contents' format returned by it depend on the color
|
||||||
space of the given image object.
|
# space of the given image object.
|
||||||
|
|
||||||
.. note::
|
# .. note::
|
||||||
You may want to use :py:func:`image_data_update_add` to
|
# You may want to use :py:func:`image_data_update_add` to
|
||||||
inform data changes, if you did any.
|
# inform data changes, if you did any.
|
||||||
|
|
||||||
"""
|
# """
|
||||||
cdef int stride, h, bpp, cspace, have_alpha, img_size
|
# cdef int stride, h, bpp, cspace, have_alpha, img_size
|
||||||
|
|
||||||
stride = evas_object_image_stride_get(self.obj)
|
# stride = evas_object_image_stride_get(self.obj)
|
||||||
evas_object_image_size_get(self.obj, NULL, &h)
|
# evas_object_image_size_get(self.obj, NULL, &h)
|
||||||
cspace = evas_object_image_colorspace_get(self.obj)
|
# cspace = evas_object_image_colorspace_get(self.obj)
|
||||||
have_alpha = evas_object_image_alpha_get(self.obj)
|
# have_alpha = evas_object_image_alpha_get(self.obj)
|
||||||
|
|
||||||
bpp = 0
|
# bpp = 0
|
||||||
if cspace == EVAS_COLORSPACE_ARGB8888:
|
# if cspace == EVAS_COLORSPACE_ARGB8888:
|
||||||
bpp = 4
|
# bpp = 4
|
||||||
format = "L"
|
# format = "L"
|
||||||
elif cspace == EVAS_COLORSPACE_RGB565_A5P:
|
# elif cspace == EVAS_COLORSPACE_RGB565_A5P:
|
||||||
if have_alpha == 0:
|
# if have_alpha == 0:
|
||||||
bpp = 2
|
# bpp = 2
|
||||||
format = "H"
|
# format = "H"
|
||||||
else:
|
# else:
|
||||||
pass #bpp = 3
|
# pass #bpp = 3
|
||||||
# XXX: There's no type that has three bytes.
|
# # XXX: There's no type that has three bytes.
|
||||||
# Is the format string actually used?
|
# # Is the format string actually used?
|
||||||
if bpp == 0:
|
# if bpp == 0:
|
||||||
raise ValueError("Unsupported colorspace")
|
# raise ValueError("Unsupported colorspace")
|
||||||
|
|
||||||
img_size = stride * h * bpp
|
# img_size = stride * h * bpp
|
||||||
|
|
||||||
cdef Py_buffer *img_buf = <Py_buffer *>PyMem_Malloc(sizeof(Py_buffer))
|
# cdef Py_buffer *img_buf = <Py_buffer *>PyMem_Malloc(sizeof(Py_buffer))
|
||||||
if img_buf == NULL:
|
# if img_buf == NULL:
|
||||||
raise MemoryError
|
# raise MemoryError
|
||||||
|
|
||||||
cdef:
|
# cdef:
|
||||||
Py_ssize_t simple_shape[1]
|
# Py_ssize_t simple_shape[1]
|
||||||
Py_ssize_t shape[2]
|
# Py_ssize_t shape[2]
|
||||||
Py_ssize_t strides[2]
|
# Py_ssize_t strides[2]
|
||||||
Py_ssize_t suboffsets[2]
|
# Py_ssize_t suboffsets[2]
|
||||||
|
|
||||||
if simple:
|
# if simple:
|
||||||
simple_shape[0] = img_size
|
# simple_shape[0] = img_size
|
||||||
else:
|
# else:
|
||||||
shape[0] = stride / bpp
|
# shape[0] = stride / bpp
|
||||||
shape[1] = h
|
# shape[1] = h
|
||||||
strides[0] = stride
|
# strides[0] = stride
|
||||||
strides[1] = h * bpp
|
# strides[1] = h * bpp
|
||||||
suboffsets[0] = -1
|
# suboffsets[0] = -1
|
||||||
suboffsets[1] = -1
|
# suboffsets[1] = -1
|
||||||
|
|
||||||
img_buf.buf = evas_object_image_data_get(self.obj, for_writing)
|
# img_buf.buf = evas_object_image_data_get(self.obj, for_writing)
|
||||||
img_buf.len = img_size
|
# img_buf.len = img_size
|
||||||
img_buf.readonly = not for_writing
|
# img_buf.readonly = not for_writing
|
||||||
img_buf.format = format
|
# img_buf.format = format
|
||||||
if simple:
|
# if simple:
|
||||||
img_buf.ndim = 1
|
# img_buf.ndim = 1
|
||||||
img_buf.shape = simple_shape
|
# img_buf.shape = simple_shape
|
||||||
img_buf.strides = NULL
|
# img_buf.strides = NULL
|
||||||
img_buf.suboffsets = NULL
|
# img_buf.suboffsets = NULL
|
||||||
else:
|
# else:
|
||||||
img_buf.ndim = 2
|
# img_buf.ndim = 2
|
||||||
img_buf.shape = shape
|
# img_buf.shape = shape
|
||||||
img_buf.strides = strides
|
# img_buf.strides = strides
|
||||||
img_buf.suboffsets = suboffsets
|
# img_buf.suboffsets = suboffsets
|
||||||
img_buf.itemsize = bpp
|
# img_buf.itemsize = bpp
|
||||||
|
|
||||||
return <object>PyMemoryView_FromBuffer(img_buf)
|
# return <object>PyMemoryView_FromBuffer(img_buf)
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
|
|
|
@ -110,7 +110,9 @@ cdef object add_logger(object name):
|
||||||
else:
|
else:
|
||||||
log.propagate = True
|
log.propagate = True
|
||||||
log.setLevel(logging.WARNING)
|
log.setLevel(logging.WARNING)
|
||||||
log.addHandler(logging.NullHandler())
|
|
||||||
|
if PY_VERSION_HEX >= 0x02070000:
|
||||||
|
log.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
logging.setLoggerClass(logging.Logger)
|
logging.setLoggerClass(logging.Logger)
|
||||||
|
|
||||||
|
|
26
setup.py
26
setup.py
|
@ -37,18 +37,34 @@ except ImportError:
|
||||||
def pkg_config(name, require, min_vers=None):
|
def pkg_config(name, require, min_vers=None):
|
||||||
try:
|
try:
|
||||||
sys.stdout.write("Checking for " + name + ": ")
|
sys.stdout.write("Checking for " + name + ": ")
|
||||||
ver = subprocess.check_output(["pkg-config", "--modversion", require]).decode("utf-8").strip()
|
|
||||||
|
call = subprocess.Popen(
|
||||||
|
["pkg-config", "--modversion", require], stdout=subprocess.PIPE)
|
||||||
|
out, err = call.communicate()
|
||||||
|
ver = out.decode("utf-8").strip()
|
||||||
|
|
||||||
if min_vers is not None:
|
if min_vers is not None:
|
||||||
assert 0 == subprocess.call(["pkg-config", "--atleast-version", min_vers, require])
|
assert 0 == subprocess.call(
|
||||||
cflags = subprocess.check_output(["pkg-config", "--cflags", require]).decode("utf-8").split()
|
["pkg-config", "--atleast-version", min_vers, require])
|
||||||
libs = subprocess.check_output(["pkg-config", "--libs", require]).decode("utf-8").split()
|
|
||||||
|
call = subprocess.Popen(
|
||||||
|
["pkg-config", "--cflags", require], stdout=subprocess.PIPE)
|
||||||
|
out, err = call.communicate()
|
||||||
|
cflags = out.decode("utf-8").split()
|
||||||
|
|
||||||
|
call = subprocess.Popen(
|
||||||
|
["pkg-config", "--libs", require], stdout=subprocess.PIPE)
|
||||||
|
out, err = call.communicate()
|
||||||
|
libs = out.decode("utf-8").split()
|
||||||
|
|
||||||
sys.stdout.write("OK, found " + ver + "\n")
|
sys.stdout.write("OK, found " + ver + "\n")
|
||||||
|
|
||||||
return (cflags, libs)
|
return (cflags, libs)
|
||||||
except (OSError, subprocess.CalledProcessError):
|
except (OSError, subprocess.CalledProcessError):
|
||||||
print("Did not find " + name + " with 'pkg-config'.")
|
print("Did not find " + name + " with 'pkg-config'.")
|
||||||
return None
|
return None
|
||||||
except (AssertionError):
|
except (AssertionError):
|
||||||
print(name + " version mismatch. Found: " + ver + " Needed: " + min_vers)
|
print(name+" version mismatch. Found: "+ver+" Needed: "+min_vers)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue