32 size_t x, y |
38 size_t x, y |
33 |
39 |
34 int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode) |
40 int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode) |
35 int pt_image_info_func "pt_image_info" (pt_image *image, pt_image_info **info_ptr) |
41 int pt_image_info_func "pt_image_info" (pt_image *image, pt_image_info **info_ptr) |
36 int pt_image_status (pt_image *image) |
42 int pt_image_status (pt_image *image) |
|
43 int pt_image_update (pt_image *image) |
37 int pt_image_tile (pt_image *image, pt_tile_info *info, FILE *out) |
44 int pt_image_tile (pt_image *image, pt_tile_info *info, FILE *out) |
38 void pt_image_destroy (pt_image *image) |
45 void pt_image_destroy (pt_image *image) |
|
46 |
|
47 char* pt_strerror (int err) |
39 |
48 |
40 OPEN_UPDATE = PT_OPEN_UPDATE |
49 OPEN_UPDATE = PT_OPEN_UPDATE |
41 CACHE_ERROR = PT_CACHE_ERROR |
50 CACHE_ERROR = PT_CACHE_ERROR |
42 CACHE_FRESH = PT_CACHE_FRESH |
51 CACHE_FRESH = PT_CACHE_FRESH |
43 CACHE_NONE = PT_CACHE_NONE |
52 CACHE_NONE = PT_CACHE_NONE |
44 CACHE_STALE = PT_CACHE_STALE |
53 CACHE_STALE = PT_CACHE_STALE |
45 |
54 |
46 class Error (BaseException) : |
55 class Error (BaseException) : |
47 pass |
56 pass |
48 |
57 |
|
58 cdef int trap_err (char *op, int ret) except -1 : |
|
59 if ret < 0 : |
|
60 raise Error("%s: %s: %s" % (op, pt_strerror(ret), strerror(errno))) |
|
61 |
|
62 else : |
|
63 return ret |
|
64 |
49 cdef class Image : |
65 cdef class Image : |
50 cdef pt_image *image |
66 cdef pt_image *image |
51 |
67 |
52 def __cinit__ (self, char *png_path, int cache_mode = 0) : |
68 def __cinit__ (self, char *png_path, int cache_mode = 0) : |
53 if pt_image_open(&self.image, NULL, png_path, cache_mode) < 0 : |
69 trap_err("pt_image_open", |
54 raise Error("pt_image_open: " + png_path) |
70 pt_image_open(&self.image, NULL, png_path, cache_mode) |
|
71 ) |
55 |
72 |
56 def info (self) : |
73 def info (self) : |
57 cdef pt_image_info *image_info |
74 cdef pt_image_info *image_info |
58 |
75 |
59 if pt_image_info_func(self.image, &image_info) < 0 : |
76 trap_err("pt_image_info", |
60 raise Error("pt_image_info") |
77 pt_image_info_func(self.image, &image_info) |
|
78 ) |
61 |
79 |
62 return (image_info.width, image_info.height) |
80 return (image_info.width, image_info.height) |
63 |
81 |
64 def status (self) : |
82 def status (self) : |
65 cdef int status = pt_image_status(self.image) |
83 return trap_err("pt_image_status", |
66 |
84 pt_image_status(self.image) |
67 if status < 0 : |
85 ) |
68 raise Error("pt_image_status") |
86 |
69 |
87 def update (self) : |
70 else : |
88 trap_err("pt_image_update", |
71 return status |
89 pt_image_update(self.image) |
|
90 ) |
72 |
91 |
73 def tile (self, size_t width, size_t height, size_t x, size_t y, object out) : |
92 def tile (self, size_t width, size_t height, size_t x, size_t y, object out) : |
74 cdef FILE *outf |
93 cdef FILE *outf |
75 cdef pt_tile_info ti |
94 cdef pt_tile_info ti |
76 |
95 |