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
bb84e1dcfb
commit
6fb611e522
6
INSTALL
6
INSTALL
|
@ -2,8 +2,8 @@
|
|||
1. REQUIREMENTS:
|
||||
----------------
|
||||
|
||||
* Python 2.7 or higher (http://www.python.org/)
|
||||
- Tested with Python 2.7 / 3.2
|
||||
* Python 2.6 or higher (http://www.python.org/)
|
||||
- Tested with Python 2.6 / 2.7 / 3.2 / 3.3
|
||||
|
||||
* Cython 0.17.0 or higher (http://cython.org/)
|
||||
- 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
|
||||
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
|
||||
user interaction.
|
||||
|
||||
|
|
|
@ -497,99 +497,99 @@ cdef class Image(Object):
|
|||
|
||||
PyBuffer_Release(&view)
|
||||
|
||||
def image_data_memoryview_get(self, bint for_writing=False, bint simple=True):
|
||||
"""image_data_memoryview_get(bool for_writing) -> MemoryView
|
||||
# def image_data_memoryview_get(self, bint for_writing=False, bint simple=True):
|
||||
# """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
|
||||
modified or not.
|
||||
:param bool simple: Whether the MemoryView is 1D or 2D
|
||||
:return MemoryView: The raw image data.
|
||||
# :param bool for_writing: Whether the data being retrieved will be
|
||||
# modified or not.
|
||||
# :param bool simple: Whether the MemoryView is 1D or 2D
|
||||
# :return MemoryView: The raw image data.
|
||||
|
||||
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
|
||||
writing, the image will be marked dirty so that it gets redrawn at
|
||||
the next update.
|
||||
# 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
|
||||
# writing, the image will be marked dirty so that it gets redrawn at
|
||||
# the next update.
|
||||
|
||||
Each time you call this method on an image object, its data
|
||||
buffer will have an internal reference counter
|
||||
incremented. Decrement it back by using
|
||||
:py:func:`image_data_set`.
|
||||
# Each time you call this method on an image object, its data
|
||||
# buffer will have an internal reference counter
|
||||
# incremented. Decrement it back by using
|
||||
# :py:func:`image_data_set`.
|
||||
|
||||
This is best suited for when you want to modify an existing image,
|
||||
without changing its dimensions.
|
||||
# This is best suited for when you want to modify an existing image,
|
||||
# without changing its dimensions.
|
||||
|
||||
.. note::
|
||||
The contents' format returned by it depend on the color
|
||||
space of the given image object.
|
||||
# .. note::
|
||||
# The contents' format returned by it depend on the color
|
||||
# space of the given image object.
|
||||
|
||||
.. note::
|
||||
You may want to use :py:func:`image_data_update_add` to
|
||||
inform data changes, if you did any.
|
||||
# .. note::
|
||||
# You may want to use :py:func:`image_data_update_add` to
|
||||
# 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)
|
||||
evas_object_image_size_get(self.obj, NULL, &h)
|
||||
cspace = evas_object_image_colorspace_get(self.obj)
|
||||
have_alpha = evas_object_image_alpha_get(self.obj)
|
||||
# stride = evas_object_image_stride_get(self.obj)
|
||||
# evas_object_image_size_get(self.obj, NULL, &h)
|
||||
# cspace = evas_object_image_colorspace_get(self.obj)
|
||||
# have_alpha = evas_object_image_alpha_get(self.obj)
|
||||
|
||||
bpp = 0
|
||||
if cspace == EVAS_COLORSPACE_ARGB8888:
|
||||
bpp = 4
|
||||
format = "L"
|
||||
elif cspace == EVAS_COLORSPACE_RGB565_A5P:
|
||||
if have_alpha == 0:
|
||||
bpp = 2
|
||||
format = "H"
|
||||
else:
|
||||
pass #bpp = 3
|
||||
# XXX: There's no type that has three bytes.
|
||||
# Is the format string actually used?
|
||||
if bpp == 0:
|
||||
raise ValueError("Unsupported colorspace")
|
||||
# bpp = 0
|
||||
# if cspace == EVAS_COLORSPACE_ARGB8888:
|
||||
# bpp = 4
|
||||
# format = "L"
|
||||
# elif cspace == EVAS_COLORSPACE_RGB565_A5P:
|
||||
# if have_alpha == 0:
|
||||
# bpp = 2
|
||||
# format = "H"
|
||||
# else:
|
||||
# pass #bpp = 3
|
||||
# # XXX: There's no type that has three bytes.
|
||||
# # Is the format string actually used?
|
||||
# if bpp == 0:
|
||||
# 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))
|
||||
if img_buf == NULL:
|
||||
raise MemoryError
|
||||
# cdef Py_buffer *img_buf = <Py_buffer *>PyMem_Malloc(sizeof(Py_buffer))
|
||||
# if img_buf == NULL:
|
||||
# raise MemoryError
|
||||
|
||||
cdef:
|
||||
Py_ssize_t simple_shape[1]
|
||||
Py_ssize_t shape[2]
|
||||
Py_ssize_t strides[2]
|
||||
Py_ssize_t suboffsets[2]
|
||||
# cdef:
|
||||
# Py_ssize_t simple_shape[1]
|
||||
# Py_ssize_t shape[2]
|
||||
# Py_ssize_t strides[2]
|
||||
# Py_ssize_t suboffsets[2]
|
||||
|
||||
if simple:
|
||||
simple_shape[0] = img_size
|
||||
else:
|
||||
shape[0] = stride / bpp
|
||||
shape[1] = h
|
||||
strides[0] = stride
|
||||
strides[1] = h * bpp
|
||||
suboffsets[0] = -1
|
||||
suboffsets[1] = -1
|
||||
# if simple:
|
||||
# simple_shape[0] = img_size
|
||||
# else:
|
||||
# shape[0] = stride / bpp
|
||||
# shape[1] = h
|
||||
# strides[0] = stride
|
||||
# strides[1] = h * bpp
|
||||
# suboffsets[0] = -1
|
||||
# suboffsets[1] = -1
|
||||
|
||||
img_buf.buf = evas_object_image_data_get(self.obj, for_writing)
|
||||
img_buf.len = img_size
|
||||
img_buf.readonly = not for_writing
|
||||
img_buf.format = format
|
||||
if simple:
|
||||
img_buf.ndim = 1
|
||||
img_buf.shape = simple_shape
|
||||
img_buf.strides = NULL
|
||||
img_buf.suboffsets = NULL
|
||||
else:
|
||||
img_buf.ndim = 2
|
||||
img_buf.shape = shape
|
||||
img_buf.strides = strides
|
||||
img_buf.suboffsets = suboffsets
|
||||
img_buf.itemsize = bpp
|
||||
# img_buf.buf = evas_object_image_data_get(self.obj, for_writing)
|
||||
# img_buf.len = img_size
|
||||
# img_buf.readonly = not for_writing
|
||||
# img_buf.format = format
|
||||
# if simple:
|
||||
# img_buf.ndim = 1
|
||||
# img_buf.shape = simple_shape
|
||||
# img_buf.strides = NULL
|
||||
# img_buf.suboffsets = NULL
|
||||
# else:
|
||||
# img_buf.ndim = 2
|
||||
# img_buf.shape = shape
|
||||
# img_buf.strides = strides
|
||||
# img_buf.suboffsets = suboffsets
|
||||
# img_buf.itemsize = bpp
|
||||
|
||||
return <object>PyMemoryView_FromBuffer(img_buf)
|
||||
# return <object>PyMemoryView_FromBuffer(img_buf)
|
||||
|
||||
|
||||
# TODO:
|
||||
|
|
|
@ -110,7 +110,9 @@ cdef object add_logger(object name):
|
|||
else:
|
||||
log.propagate = True
|
||||
log.setLevel(logging.WARNING)
|
||||
log.addHandler(logging.NullHandler())
|
||||
|
||||
if PY_VERSION_HEX >= 0x02070000:
|
||||
log.addHandler(logging.NullHandler())
|
||||
|
||||
logging.setLoggerClass(logging.Logger)
|
||||
|
||||
|
|
26
setup.py
26
setup.py
|
@ -33,18 +33,34 @@ except ImportError:
|
|||
def pkg_config(name, require, min_vers=None):
|
||||
try:
|
||||
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:
|
||||
assert 0 == subprocess.call(["pkg-config", "--atleast-version", min_vers, require])
|
||||
cflags = subprocess.check_output(["pkg-config", "--cflags", require]).decode("utf-8").split()
|
||||
libs = subprocess.check_output(["pkg-config", "--libs", require]).decode("utf-8").split()
|
||||
assert 0 == subprocess.call(
|
||||
["pkg-config", "--atleast-version", min_vers, require])
|
||||
|
||||
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")
|
||||
|
||||
return (cflags, libs)
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
print("Did not find " + name + " with 'pkg-config'.")
|
||||
return None
|
||||
except (AssertionError):
|
||||
print(name + " version mismatch. Found: " + ver + " Needed: " + min_vers)
|
||||
print(name+" version mismatch. Found: "+ver+" Needed: "+min_vers)
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue