mirror of https://github.com/kivy/kivy.git
osx core image: make it compile
This commit is contained in:
parent
42f10f6e94
commit
aa2fcfe1a3
|
@ -0,0 +1,121 @@
|
||||||
|
from libcpp cimport bool
|
||||||
|
|
||||||
|
ctypedef unsigned long size_t
|
||||||
|
ctypedef signed long CFIndex
|
||||||
|
|
||||||
|
cdef extern from "Python.h":
|
||||||
|
object PyString_FromStringAndSize(char *s, Py_ssize_t len)
|
||||||
|
|
||||||
|
|
||||||
|
cdef extern from "CoreFoundation/CFBase.h":
|
||||||
|
ctypedef void *CFAllocatorRef
|
||||||
|
|
||||||
|
|
||||||
|
cdef extern from "CoreFoundation/CFData.h":
|
||||||
|
ctypedef void *CFDataRef
|
||||||
|
# XXX
|
||||||
|
# char or int?
|
||||||
|
unsigned char * CFDataGetBytePtr(CFDataRef)
|
||||||
|
|
||||||
|
#cdef extern from "CoreGraphics/CGDataProvider.h":
|
||||||
|
cdef extern from "QuartzCore/QuartzCore.h":
|
||||||
|
ctypedef void *CGDataProviderRef
|
||||||
|
CFDataRef CGDataProviderCopyData(CGDataProviderRef)
|
||||||
|
|
||||||
|
|
||||||
|
cdef extern from "CoreFoundation/CFURL.h":
|
||||||
|
ctypedef void *CFURLRef
|
||||||
|
# Not in the snippet, but I deem necessary:
|
||||||
|
#
|
||||||
|
# CFURLRef CFURLCreateFromFileSystemRepresentation (
|
||||||
|
# CFAllocatorRef allocator,
|
||||||
|
# const UInt8 *buffer,
|
||||||
|
# CFIndex bufLen,
|
||||||
|
# Boolean isDirectory
|
||||||
|
# );
|
||||||
|
CFURLRef CFURLCreateFromFileSystemRepresentation(CFAllocatorRef,
|
||||||
|
unsigned char *,
|
||||||
|
CFIndex,
|
||||||
|
# XXX CORRECT?
|
||||||
|
bool)
|
||||||
|
|
||||||
|
|
||||||
|
cdef extern from "CoreFoundation/CFDictionary.h":
|
||||||
|
ctypedef void *CFDictionaryRef
|
||||||
|
|
||||||
|
|
||||||
|
#cdef extern from "CoreGraphics/CGImage.h":
|
||||||
|
cdef extern from "QuartzCore/QuartzCore.h":
|
||||||
|
ctypedef void *CGImageRef
|
||||||
|
CGDataProviderRef CGImageGetDataProvider(CGImageRef)
|
||||||
|
# guessing these, because of no wifi:
|
||||||
|
int CGImageGetWidth(CGImageRef)
|
||||||
|
int CGImageGetHeight(CGImageRef)
|
||||||
|
int CGImageGetAlphaInfo(CGImageRef)
|
||||||
|
int kCGImageAlphaNone
|
||||||
|
|
||||||
|
|
||||||
|
#cdef extern from "ImageIO/CGImageSource.h":
|
||||||
|
cdef extern from "QuartzCore/QuartzCore.h":
|
||||||
|
ctypedef void *CGImageSourceRef
|
||||||
|
CGImageSourceRef CGImageSourceCreateWithURL(CFURLRef,
|
||||||
|
CFDictionaryRef)
|
||||||
|
CGImageRef CGImageSourceCreateImageAtIndex(CGImageSourceRef,
|
||||||
|
size_t, CFDictionaryRef)
|
||||||
|
|
||||||
|
|
||||||
|
def load_raw_image_data(bytes _url):
|
||||||
|
cdef CFURLRef url
|
||||||
|
url = CFURLCreateFromFileSystemRepresentation(NULL, <bytes> _url, len(_url), 0)
|
||||||
|
|
||||||
|
cdef CGImageSourceRef myImageSourceRef
|
||||||
|
# or maybe: UIImage* uiImage = [UIImage imageWithContentsOfFile:fullPath];
|
||||||
|
# see iphone3d book
|
||||||
|
myImageSourceRef = CGImageSourceCreateWithURL(url, NULL)
|
||||||
|
if myImageSourceRef == NULL:
|
||||||
|
print 'myImageSourceRef is NULL'
|
||||||
|
return None
|
||||||
|
|
||||||
|
cdef CGImageRef myImageRef
|
||||||
|
myImageRef = CGImageSourceCreateImageAtIndex (myImageSourceRef, 0, NULL)
|
||||||
|
if myImageRef == NULL:
|
||||||
|
print 'myImageRef is NULL'
|
||||||
|
return None
|
||||||
|
|
||||||
|
cdef int width = CGImageGetWidth(myImageRef)
|
||||||
|
cdef int height = CGImageGetHeight(myImageRef)
|
||||||
|
cdef int hasAlpha = CGImageGetAlphaInfo(myImageRef) != kCGImageAlphaNone
|
||||||
|
|
||||||
|
# correctly detect the image type !!!
|
||||||
|
imgtype = 'rgb'
|
||||||
|
typesize = 3
|
||||||
|
if hasAlpha > 0:
|
||||||
|
imgtype = 'rgba'
|
||||||
|
typesize = 4
|
||||||
|
|
||||||
|
cdef CFDataRef data
|
||||||
|
data = CGDataProviderCopyData(CGImageGetDataProvider(myImageRef))
|
||||||
|
|
||||||
|
r_data = PyString_FromStringAndSize(<char *>CFDataGetBytePtr(data),
|
||||||
|
width * height * typesize)
|
||||||
|
|
||||||
|
# XXX clean image object
|
||||||
|
|
||||||
|
print 'Image:', _url, width, height, imgtype
|
||||||
|
return (width, height, imgtype, r_data)
|
||||||
|
|
||||||
|
#
|
||||||
|
# bool hasAlpha = CGImageGetAlphaInfo(cgImage) != kCGImageAlphaNone; CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage); switch (CGColorSpaceGetModel(colorSpace)) {
|
||||||
|
# case kCGColorSpaceModelMonochrome: description.Format =
|
||||||
|
# hasAlpha ? TextureFormatGrayAlpha : TextureFormatGray; break;
|
||||||
|
# case kCGColorSpaceModelRGB: description.Format =
|
||||||
|
# Texture Formats and Types
|
||||||
|
# | 189
|
||||||
|
# }
|
||||||
|
# hasAlpha ? TextureFormatRgba : TextureFormatRgb; break;
|
||||||
|
# default: assert(!"Unsupported color space."); break;
|
||||||
|
# } description.BitsPerComponent = CGImageGetBitsPerComponent(cgImage);
|
||||||
|
# return description;
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
11
setup.py
11
setup.py
|
@ -180,6 +180,7 @@ if True:
|
||||||
ext_files = [pyx]
|
ext_files = [pyx]
|
||||||
ext_libraries = libraries[:]
|
ext_libraries = libraries[:]
|
||||||
ext_include_dirs = include_dirs[:]
|
ext_include_dirs = include_dirs[:]
|
||||||
|
ext_extra_compile_args = []
|
||||||
ext_extra_link_args = extra_link_args[:]
|
ext_extra_link_args = extra_link_args[:]
|
||||||
|
|
||||||
if pyx.endswith('sdl.pyx'):
|
if pyx.endswith('sdl.pyx'):
|
||||||
|
@ -188,6 +189,15 @@ if True:
|
||||||
ext_libraries += sdl_libraries
|
ext_libraries += sdl_libraries
|
||||||
ext_include_dirs += sdl_includes
|
ext_include_dirs += sdl_includes
|
||||||
ext_extra_link_args += sdl_extra_link_args
|
ext_extra_link_args += sdl_extra_link_args
|
||||||
|
|
||||||
|
elif pyx.endswith('osxcoreimage.pyx'):
|
||||||
|
if platform != 'darwin':
|
||||||
|
continue
|
||||||
|
ext_extra_link_args += ['-framework', 'Cocoa']
|
||||||
|
ext_extra_link_args += ['-framework', 'Foundation']
|
||||||
|
ext_extra_link_args += ['-framework', 'QuartzCore']
|
||||||
|
ext_extra_compile_args += ['-isysroot', '/Developer/SDKs/MacOSX10.6.sdk']
|
||||||
|
|
||||||
elif 'graphics' in pyx:
|
elif 'graphics' in pyx:
|
||||||
ext_files += pxd_graphics
|
ext_files += pxd_graphics
|
||||||
else:
|
else:
|
||||||
|
@ -197,6 +207,7 @@ if True:
|
||||||
module_name,
|
module_name,
|
||||||
ext_files,
|
ext_files,
|
||||||
libraries=ext_libraries,
|
libraries=ext_libraries,
|
||||||
|
extra_compile_args=ext_extra_compile_args,
|
||||||
include_dirs=ext_include_dirs,
|
include_dirs=ext_include_dirs,
|
||||||
extra_link_args=ext_extra_link_args))
|
extra_link_args=ext_extra_link_args))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue