move public headers to include/, python stuff to python/ sub-dir
authorTero Marttila <terom@fixme.fi>
Tue, 29 Dec 2009 15:38:31 +0200
changeset 16 6e781cf3d459
parent 15 01de253f3bbf
child 17 baf3fe7c6354
move public headers to include/, python stuff to python/ sub-dir
Makefile
include/pngtile.h
python/pngtile.pyx
python/setup.py
setup.py
src/lib/pngtile.h
src/py/pngtile.pyx
--- a/Makefile	Tue Dec 29 15:34:18 2009 +0200
+++ b/Makefile	Tue Dec 29 15:38:31 2009 +0200
@@ -4,7 +4,7 @@
 CFLAGS = -Wall -std=gnu99 -g
 
 # preprocessor flags
-CPPFLAGS = -Isrc/
+CPPFLAGS = -Iinclude -Isrc/
 
 # libraries to use
 LOADLIBES = -lpng
@@ -17,7 +17,10 @@
 
 lib/libpngtile.so : \
 	build/obj/lib/image.o build/obj/lib/cache.o \
-	build/obj/shared/util.o
+	build/obj/shared/util.o build/obj/shared/log.o
+
+lib/pypngtile.so : \
+	lib/libpngtile.so
 
 bin/util: \
 	lib/libpngtile.so \
@@ -70,6 +73,15 @@
 lib/lib%.so :
 	$(CC) -shared $(LDFLAGS) $+ $(LOADLIBES) $(LDLIBS) -o $@
 
+build/pyx/%.c : src/py/%.pyx
+	cython -o $@ $<
+
+build/obj/py/%.o : build/pyx/%.c
+	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
+
+lib/py%.so : build/obj/py/%.o
+	$(CC) -shared $(LDFLAGS) $+ $(LOADLIBES) $(LDLIBS) -o $@
+
 dist:
 	mkdir -p dist/$(DIST_NAME)
 	cp -rv Makefile $(DIST_RESOURCES) src/ dist/$(DIST_NAME)/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/pngtile.h	Tue Dec 29 15:38:31 2009 +0200
@@ -0,0 +1,114 @@
+#ifndef PNGTILE_H
+#define PNGTILE_H
+
+/**
+ * @file
+ *
+ * Tile-based access to large PNG images.
+ */
+#include <stddef.h>
+#include <stdio.h> // for FILE*
+
+/**
+ * "Global" context shared between images
+ */
+struct pt_ctx;
+
+/**
+ * Per-image state
+ */
+struct pt_image;
+
+/** Bitmask for pt_image_open modes */
+enum pt_open_mode {
+    /** Update cache if needed */
+    PT_OPEN_UPDATE   = 0x01,
+
+    /** Accept stale cache */
+    // TODO: PT_OPEN_STALE    = 0x02,
+};
+
+/**
+ * Values for pt_image_cached
+ */
+enum pt_cache_status {
+    /** Cache status could not be determined */
+    PT_CACHE_ERROR      = -1,
+    
+    /** Cache is fresh */
+    PT_CACHE_FRESH      = 0,
+
+    /** Cache does not exist */
+    PT_CACHE_NONE       = 1,
+
+    /** Cache exists, but is stale */
+    PT_CACHE_STALE      = 2,
+};
+
+/** Metadata info for image */
+struct pt_image_info {
+    /** Dimensions of image */
+    size_t width, height;
+};
+
+/**
+ * Info for image tile 
+ *
+ * The tile may safely overlap with the edge of the image, but it should not be entirely outside of the image
+ */
+struct pt_tile_info {
+    /** Dimensions of output image */
+    size_t width, height;
+
+    /** Pixel coordinates of top-left corner */
+    size_t x, y;
+
+    /** Zoom factor (out < zero < in) */
+    // TODO: int zoom;
+};
+
+/**
+ * TODO: impl
+ */
+int pt_ctx_new (struct pt_ctx **ctx_ptr);
+
+/**
+ * Open a new pt_image for use.
+ *
+ * @param img_ptr returned pt_image handle
+ * @param ctx global state to use
+ * @param path filesystem path to .png file
+ * @param mode combination of PT_OPEN_* flags
+ */
+int pt_image_open (struct pt_image **image_ptr, struct pt_ctx *ctx, const char *png_path, int cache_mode);
+
+/**
+ * Get the image's metadata
+ */
+int pt_image_info (struct pt_image *image, const struct pt_image_info **info_ptr);
+
+/**
+ * Check the given image's cache is stale - in other words, if the image needs to be update()'d.
+ *
+ * @return one of pt_cache_status
+ */
+int pt_image_status (struct pt_image *image);
+
+/**
+ * Update the given image's cache.
+ */
+int pt_image_update (struct pt_image *image);
+
+/**
+ * Render a PNG tile to a stream.
+ *
+ * The PNG data will be written to the given stream, which will be flushed, but not closed.
+ */
+int pt_image_tile (struct pt_image *image, const struct pt_tile_info *info, FILE *out);
+
+/**
+ * Release the given pt_image without any clean shutdown
+ */
+void pt_image_destroy (struct pt_image *image);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/pngtile.pyx	Tue Dec 29 15:38:31 2009 +0200
@@ -0,0 +1,96 @@
+cdef extern from "stdio.h" :
+    struct FILE :
+        pass
+
+cdef extern from "Python.h" :
+    int PyFile_Check (object p)
+    FILE* PyFile_AsFile (object p)
+    void PyFile_IncUseCount (object p)
+    void PyFile_DecUseCount (object p)
+
+cdef extern from "pngtile.h" :
+    struct pt_ctx :
+        pass
+
+    struct pt_image :
+        pass
+
+    enum pt_open_mode :
+        PT_OPEN_UPDATE
+
+    enum pt_cache_status :
+        PT_CACHE_ERROR
+        PT_CACHE_FRESH
+        PT_CACHE_NONE
+        PT_CACHE_STALE
+
+    struct pt_image_info :
+        size_t width, height
+
+    struct pt_tile_info :
+        size_t width, height
+        size_t x, y
+        
+    int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode)
+    int pt_image_info_func "pt_image_info" (pt_image *image, pt_image_info **info_ptr)
+    int pt_image_status (pt_image *image)
+    int pt_image_tile (pt_image *image, pt_tile_info *info, FILE *out)
+    void pt_image_destroy (pt_image *image)
+
+OPEN_UPDATE = PT_OPEN_UPDATE
+CACHE_ERROR = PT_CACHE_ERROR
+CACHE_FRESH = PT_CACHE_FRESH
+CACHE_NONE = PT_CACHE_NONE
+CACHE_STALE = PT_CACHE_STALE
+
+class Error (BaseException) :
+    pass
+
+cdef class Image :
+    cdef pt_image *image
+
+    def __cinit__ (self, char *png_path, int cache_mode = 0) :
+        if pt_image_open(&self.image, NULL, png_path, cache_mode) < 0 :
+            raise Error("pt_image_open: " + png_path)
+    
+    def info (self) :
+        cdef pt_image_info *image_info
+
+        if pt_image_info_func(self.image, &image_info) < 0 :
+            raise Error("pt_image_info")
+
+        return (image_info.width, image_info.height)
+    
+    def status (self) :
+        cdef int status = pt_image_status(self.image)
+        
+        if status < 0 :
+            raise Error("pt_image_status")
+
+        else :
+            return status
+
+    def tile (self, size_t width, size_t height, size_t x, size_t y, object out) :
+        cdef FILE *outf
+        cdef pt_tile_info ti
+
+        if not PyFile_Check(out) :
+            raise TypeError("out: must be a file object")
+
+        outf = PyFile_AsFile(out)
+
+        if not outf :
+            raise TypeError("out: must have a FILE*")
+    
+        ti.width = width
+        ti.height = height
+        ti.x = x
+        ti.y = y
+        
+        if pt_image_tile(self.image, &ti, outf) < 0 :
+            raise Error("pt_image_tile")
+
+    def __dealloc__ (self) :
+        if self.image :
+            pt_image_destroy(self.image)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/setup.py	Tue Dec 29 15:38:31 2009 +0200
@@ -0,0 +1,16 @@
+from distutils.core import setup
+from distutils.extension import Extension
+from Cython.Distutils import build_ext
+
+setup(
+    name = 'pngtiles',
+    cmdclass = {'build_ext': build_ext},
+    ext_modules = [
+        Extension("pngtile", ["pngtile.pyx"],
+            include_dirs = ['../include'],
+            library_dirs = ['../lib'],
+            libraries = ['pngtile'],
+        ),
+    ],
+)
+
--- a/setup.py	Tue Dec 29 15:34:18 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-from distutils.core import setup
-from distutils.extension import Extension
-from Cython.Distutils import build_ext
-
-setup(
-    name = 'pngtiles',
-    cmdclass = {'build_ext': build_ext},
-    ext_modules = [
-        Extension("pngtile", ["src/py/pngtile.pyx"],
-            include_dirs = ['include/'],
-            library_dirs = ['lib/'],
-            libraries = ['pngtile'],
-        ),
-    ],
-)
-
--- a/src/lib/pngtile.h	Tue Dec 29 15:34:18 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-#ifndef PNGTILE_H
-#define PNGTILE_H
-
-/**
- * @file
- *
- * Tile-based access to large PNG images.
- */
-#include <stddef.h>
-#include <stdio.h> // for FILE*
-
-/**
- * "Global" context shared between images
- */
-struct pt_ctx;
-
-/**
- * Per-image state
- */
-struct pt_image;
-
-/** Bitmask for pt_image_open modes */
-enum pt_open_mode {
-    /** Update cache if needed */
-    PT_OPEN_UPDATE   = 0x01,
-
-    /** Accept stale cache */
-    // TODO: PT_OPEN_STALE    = 0x02,
-};
-
-/**
- * Values for pt_image_cached
- */
-enum pt_cache_status {
-    /** Cache status could not be determined */
-    PT_CACHE_ERROR      = -1,
-    
-    /** Cache is fresh */
-    PT_CACHE_FRESH      = 0,
-
-    /** Cache does not exist */
-    PT_CACHE_NONE       = 1,
-
-    /** Cache exists, but is stale */
-    PT_CACHE_STALE      = 2,
-};
-
-/** Metadata info for image */
-struct pt_image_info {
-    /** Dimensions of image */
-    size_t width, height;
-};
-
-/**
- * Info for image tile 
- *
- * The tile may safely overlap with the edge of the image, but it should not be entirely outside of the image
- */
-struct pt_tile_info {
-    /** Dimensions of output image */
-    size_t width, height;
-
-    /** Pixel coordinates of top-left corner */
-    size_t x, y;
-
-    /** Zoom factor (out < zero < in) */
-    // TODO: int zoom;
-};
-
-/**
- * TODO: impl
- */
-int pt_ctx_new (struct pt_ctx **ctx_ptr);
-
-/**
- * Open a new pt_image for use.
- *
- * @param img_ptr returned pt_image handle
- * @param ctx global state to use
- * @param path filesystem path to .png file
- * @param mode combination of PT_OPEN_* flags
- */
-int pt_image_open (struct pt_image **image_ptr, struct pt_ctx *ctx, const char *png_path, int cache_mode);
-
-/**
- * Get the image's metadata
- */
-int pt_image_info (struct pt_image *image, const struct pt_image_info **info_ptr);
-
-/**
- * Check the given image's cache is stale - in other words, if the image needs to be update()'d.
- *
- * @return one of pt_cache_status
- */
-int pt_image_status (struct pt_image *image);
-
-/**
- * Update the given image's cache.
- */
-int pt_image_update (struct pt_image *image);
-
-/**
- * Render a PNG tile to a stream.
- *
- * The PNG data will be written to the given stream, which will be flushed, but not closed.
- */
-int pt_image_tile (struct pt_image *image, const struct pt_tile_info *info, FILE *out);
-
-/**
- * Release the given pt_image without any clean shutdown
- */
-void pt_image_destroy (struct pt_image *image);
-
-#endif
--- a/src/py/pngtile.pyx	Tue Dec 29 15:34:18 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-cdef extern from "stdio.h" :
-    struct FILE :
-        pass
-
-cdef extern from "Python.h" :
-    int PyFile_Check (object p)
-    FILE* PyFile_AsFile (object p)
-    void PyFile_IncUseCount (object p)
-    void PyFile_DecUseCount (object p)
-
-cdef extern from "pngtile.h" :
-    struct pt_ctx :
-        pass
-
-    struct pt_image :
-        pass
-
-    enum pt_open_mode :
-        PT_OPEN_UPDATE
-
-    enum pt_cache_status :
-        PT_CACHE_ERROR
-        PT_CACHE_FRESH
-        PT_CACHE_NONE
-        PT_CACHE_STALE
-
-    struct pt_image_info :
-        size_t width, height
-
-    struct pt_tile_info :
-        size_t width, height
-        size_t x, y
-        
-    int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode)
-    int pt_image_info_func "pt_image_info" (pt_image *image, pt_image_info **info_ptr)
-    int pt_image_status (pt_image *image)
-    int pt_image_tile (pt_image *image, pt_tile_info *info, FILE *out)
-    void pt_image_destroy (pt_image *image)
-
-OPEN_UPDATE = PT_OPEN_UPDATE
-CACHE_ERROR = PT_CACHE_ERROR
-CACHE_FRESH = PT_CACHE_FRESH
-CACHE_NONE = PT_CACHE_NONE
-CACHE_STALE = PT_CACHE_STALE
-
-class Error (BaseException) :
-    pass
-
-cdef class Image :
-    cdef pt_image *image
-
-    def __cinit__ (self, char *png_path, int cache_mode = 0) :
-        if pt_image_open(&self.image, NULL, png_path, cache_mode) < 0 :
-            raise Error("pt_image_open: " + png_path)
-    
-    def info (self) :
-        cdef pt_image_info *image_info
-
-        if pt_image_info_func(self.image, &image_info) < 0 :
-            raise Error("pt_image_info")
-
-        return (image_info.width, image_info.height)
-    
-    def status (self) :
-        cdef int status = pt_image_status(self.image)
-        
-        if status < 0 :
-            raise Error("pt_image_status")
-
-        else :
-            return status
-
-    def tile (self, size_t width, size_t height, size_t x, size_t y, object out) :
-        cdef FILE *outf
-        cdef pt_tile_info ti
-
-        if not PyFile_Check(out) :
-            raise TypeError("out: must be a file object")
-
-        outf = PyFile_AsFile(out)
-
-        if not outf :
-            raise TypeError("out: must have a FILE*")
-    
-        ti.width = width
-        ti.height = height
-        ti.x = x
-        ti.y = y
-        
-        if pt_image_tile(self.image, &ti, outf) < 0 :
-            raise Error("pt_image_tile")
-
-    def __dealloc__ (self) :
-        if self.image :
-            pt_image_destroy(self.image)
-