--- a/.hgignore Wed Jan 27 01:10:58 2010 +0200
+++ b/.hgignore Wed Jan 27 01:11:24 2010 +0200
@@ -4,8 +4,9 @@
\.pyc$
^build/
-^bin/pngtile$
-^lib/libpngtile.so$
+^bin/pngtile(-static)?$
+^data
+^lib/libpngtile.(so|a)$
^doc/html
^dist
-^Learning Diary\.pdf$
+^python/pypngtile.c$
--- a/Makefile Wed Jan 27 01:10:58 2010 +0200
+++ b/Makefile Wed Jan 27 01:11:24 2010 +0200
@@ -20,10 +20,11 @@
LOADLIBES = -lpng -lpthread
# output name
-DIST_NAME = pngtile-0.2
-DIST_RESOURCES = README $(shell "echo python/*.{py,pyx}")
+DIST_NAME = pngtile-${shell hg id -i}
+DIST_DEPS = python/pypngtile.c
+DIST_RESOURCES = README python/ pngtile/ static/ bin/
-all: depend lib/libpngtile.so bin/pngtile
+all: depend lib/libpngtile.so bin/pngtile lib/pypngtile.so
lib/libpngtile.so : \
build/obj/lib/ctx.o build/obj/lib/image.o build/obj/lib/cache.o build/obj/lib/tile.o build/obj/lib/png.o build/obj/lib/error.o \
@@ -50,15 +51,18 @@
.PHONY : dirs clean depend dist
+dist-clean : clean dirs
+
dirs:
mkdir -p bin lib dist
mkdir -p $(SRC_DIRS:%=build/deps/%)
- mkdir -p $(SRC_DIRS:%=build/obj/%)
+ mkdir -p $(SRC_DIRS:%=build/obj/%) build/obj/python
clean:
rm -f build/obj/*/*.o build/deps/*/*.d
- rm -f bin/{pngtile,pngtile-static} lib/libpngtile.{a,so} run/*
- rm -rf dist/*
+ rm -f bin/pngtile bin/pngtile-static lib/*.so lib/*.a
+ rm -f pngtile/*.pyc
+ rm -f */.*.swp */*/.*.swp
# .h dependencies
depend: $(SRC_NAMES:%.c=build/deps/%.d)
@@ -95,20 +99,20 @@
lib/lib%.a :
$(AR) rc $@ $+
-build/pyx/%.c : src/py/%.pyx
+python/%.c : python/%.pyx
cython -o $@ $<
-build/obj/py/%.o : build/pyx/%.c
- $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
+build/obj/python/%.o : python/%.c
+ $(CC) -c -fPIC -I/usr/include/python2.5 $(CPPFLAGS) $(CFLAGS) $< -o $@
-lib/py%.so : build/obj/py/%.o
+lib/py%.so : build/obj/python/py%.o
$(CC) -shared $(LDFLAGS) $+ $(LOADLIBES) $(LDLIBS) -o $@
-dist:
+dist: $(DIST_DEPS)
+ rm -rf dist/$(DIST_NAME)
mkdir -p dist/$(DIST_NAME)
- cp -rv Makefile $(DIST_RESOURCES) src/ include/ dist/$(DIST_NAME)/
- rm dist/$(DIST_NAME)/src/*/.*.sw[op]
- make -C dist/$(DIST_NAME) dirs
+ cp -rv Makefile $(DIST_RESOURCES) src/ include/ dist/$(DIST_NAME)/
+ make -C dist/$(DIST_NAME) dist-clean
tar -C dist -czvf dist/$(DIST_NAME).tar.gz $(DIST_NAME)
@echo "*** Output at dist/$(DIST_NAME).tar.gz"
--- a/README Wed Jan 27 01:10:58 2010 +0200
+++ b/README Wed Jan 27 01:11:24 2010 +0200
@@ -32,11 +32,13 @@
* libpng 1.2.15~beta5-3ubuntu0.1
* NPTL 2.7 (glibc 2.7-10ubuntu5)
- To compile, simply execute
+ To compile dist versions, simply execute
make
- The libpngtile.so will be placed under lib/, and the 'pngtile' binary under bin/.
+ The libpngtile.so and pypngtile.so libraries will be placed under lib/, and the 'pngtile' binary under bin/.
+
+ XXX: If compiling the pypngtile.so library with make fails, then `setup.py build_ext -i` should build it.
USAGE:
--- a/setup.py Wed Jan 27 01:10:58 2010 +0200
+++ b/setup.py Wed Jan 27 01:11:24 2010 +0200
@@ -1,12 +1,37 @@
from distutils.core import setup
from distutils.extension import Extension
-from Cython.Distutils import build_ext
+
+import os.path
+
+build_root = os.path.abspath(os.path.dirname(__file__))
+
+pypngtile_c = "python/pypngtile.c"
+pypngtile_name = "python/pypngtile.pyx"
+
+cmdclass = dict()
+
+try :
+ from Cython.Distutils import build_ext
+
+ cmdclass['build_ext'] = build_ext
+
+except ImportError :
+ path = os.path.join(build_root, pypngtile_c)
+
+ if os.path.exists(path) :
+ print "Warning: falling back from .pyx -> .c due to missing Cython"
+ # just use the .c
+ pypngtile_name = pypngtile_c
+
+ else :
+ # fail
+ raise
setup(
name = 'pngtiles',
- cmdclass = {'build_ext': build_ext},
+ cmdclass = cmdclass,
ext_modules = [
- Extension("pypngtile", ["python/pypngtile.pyx"],
+ Extension("pypngtile", [pypngtile_name],
include_dirs = ['include'],
library_dirs = ['lib'],
libraries = ['pngtile'],
--- a/src/lib/png.c Wed Jan 27 01:10:58 2010 +0200
+++ b/src/lib/png.c Wed Jan 27 01:11:24 2010 +0200
@@ -403,24 +403,34 @@
*/
static inline void png_pixel_data (const png_color **outp, const struct pt_png_header *header, const uint8_t *data, size_t row, size_t col)
{
- if (header->color_type == PNG_COLOR_TYPE_PALETTE) {
- // palette entry number
- int p;
+ // palette entry number
+ int p;
- if (header->bit_depth == 8)
- p = *((uint8_t *) tile_row_col(header, data, row, col));
- else
- // unknown
+ switch (header->color_type) {
+ case PNG_COLOR_TYPE_PALETTE:
+ switch (header->bit_depth) {
+ case 8:
+ // 8bpp palette
+ p = *((uint8_t *) tile_row_col(header, data, row, col));
+
+ break;
+
+ default :
+ // unknown
+ return;
+ }
+
+ // hrhr - assume our working data is valid (or we have 255 palette entries, so it doesn't matter...)
+ assert(p < header->num_palette);
+
+ // reference data from palette
+ *outp = &header->palette[p];
+
return;
- // hrhr - assume our working data is valid (or we have 255 palette entries, so it doesn't matter...)
- assert(p < header->num_palette);
-
- // reference data from palette
- *outp = &header->palette[p];
-
- } else {
- // unknown
+ default :
+ // unknown pixel format
+ return;
}
}
--- a/src/pngtile/main.c Wed Jan 27 01:10:58 2010 +0200
+++ b/src/pngtile/main.c Wed Jan 27 01:11:24 2010 +0200
@@ -331,29 +331,29 @@
// update if stale
if (status != PT_CACHE_FRESH || force_update) {
if (status == PT_CACHE_NONE)
- log_debug("\tImage cache is missing");
+ log_info("\tImage cache is missing");
else if (status == PT_CACHE_STALE)
- log_debug("\tImage cache is stale");
+ log_info("\tImage cache is stale");
else if (status == PT_CACHE_INCOMPAT)
- log_debug("\tImage cache is incompatible");
+ log_info("\tImage cache is incompatible");
else if (status == PT_CACHE_FRESH)
- log_debug("\tImage cache is fresh");
+ log_info("\tImage cache is fresh");
else
log_warn("\tImage cache status is unknown");
if (!no_update) {
- log_debug("\tUpdating image cache...");
+ log_info("\tUpdating image cache...");
if ((err = pt_image_update(image, &update_params))) {
log_error("pt_image_update: %s: %s", img_path, pt_strerror(err));
goto error;
}
- log_info("\tUpdated image cache");
+ log_debug("\tUpdated image cache");
} else {
log_warn("\tSupressing cache update");
@@ -363,7 +363,7 @@
log_debug("\tImage cache is fresh");
// ensure it's loaded
- log_debug("\tLoad image cache...");
+ log_info("\tLoad image cache...");
if ((err = pt_image_load(image))) {
log_errno("pt_image_load: %s", pt_strerror(err));
--- a/static/index.html Wed Jan 27 01:10:58 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <title>Mandelbrot</title>
- <script src="/static/prototype.js" type="text/javascript"></script>
- <script src="/static/dragdrop.js" type="text/javascript"></script>
- <script src="/static/builder.js" type="text/javascript"></script>
- <script src="/static/tiles2.js" type="text/javascript"></script>
- <link rel="Stylesheet" type="text/css" href="static/style.css">
- </head>
- <body>
- <div id="wrapper">
- <div id="viewport" style="width: 100%; height: 100%">
- <div class="substrate"></div>
- </div>
- </div>
-
- <script type="text/javascript">
- var tile_source = new Source("/tile", 256, 256, 0, 13);
- var main = new Viewport(tile_source, "viewport");
- </script>
- </body>
-</html>