python/pypngtile.pyx
author Tero Marttila <terom@fixme.fi>
Tue, 26 Jan 2010 01:37:01 +0200
changeset 104 b5ae988c78b8
parent 91 0bf7878bdf5c
child 133 67f956b71bdf
permissions -rw-r--r--
add .path attr to pypngtile.Image
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
cdef extern from "errno.h" :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
    extern int errno
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
cdef extern from "string.h" :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
    char* strerror (int err)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
     7
    void* memset (void *, int, size_t)
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
     8
    void* memcpy (void *, void *, size_t)
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
     9
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
cimport stdio
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
cimport stdlib
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
cimport python_string
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
cdef extern from "Python.h" :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
    int PyFile_Check (object p)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
    stdio.FILE* PyFile_AsFile (object p)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    void PyFile_IncUseCount (object p)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    void PyFile_DecUseCount (object p)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
cdef extern from "pngtile.h" :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
    struct pt_ctx :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
        pass
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    struct pt_image :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
        pass
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
    enum pt_open_mode :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    28
        PT_OPEN_READ    # 0
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
        PT_OPEN_UPDATE
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
    enum pt_cache_status :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    32
        PT_CACHE_ERROR  # -1
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
        PT_CACHE_FRESH
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
        PT_CACHE_NONE
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
        PT_CACHE_STALE
57
06258920cec8 update pypngtile.pyx
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    36
        PT_CACHE_INCOMPAT
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
    struct pt_image_info :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    39
        size_t img_width, img_height, img_bpp
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    40
        int image_mtime, cache_mtime, cache_version
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    41
        size_t image_bytes, cache_bytes
57
06258920cec8 update pypngtile.pyx
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    42
        size_t cache_blocks
06258920cec8 update pypngtile.pyx
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    43
06258920cec8 update pypngtile.pyx
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    44
    struct pt_image_params :
06258920cec8 update pypngtile.pyx
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    45
        int background_color[4]
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
    46
    
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
    struct pt_tile_info :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
        size_t width, height
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
        size_t x, y
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    50
        int zoom
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    51
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    52
    ctypedef pt_image_info* const_image_info_ptr "const struct pt_image_info *"
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
    53
    
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
    54
    ## functions
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    55
    int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    56
    int pt_image_info_ "pt_image_info" (pt_image *image, pt_image_info **info_ptr) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    57
    int pt_image_status (pt_image *image) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    58
    int pt_image_load (pt_image *image) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    59
    int pt_image_update (pt_image *image, pt_image_params *params) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    60
    int pt_image_tile_file (pt_image *image, pt_tile_info *info, stdio.FILE *out) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    61
    int pt_image_tile_mem (pt_image *image, pt_tile_info *info, char **buf_ptr, size_t *len_ptr) nogil
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    62
    void pt_image_destroy (pt_image *image) nogil
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
    63
    
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
    64
    # error code -> name
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
    char* pt_strerror (int err)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    67
## constants
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    68
# Image()
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    69
OPEN_READ       = PT_OPEN_READ
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    70
OPEN_UPDATE     = PT_OPEN_UPDATE
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    71
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    72
# Image.status -> ...
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    73
CACHE_FRESH     = PT_CACHE_FRESH
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    74
CACHE_NONE      = PT_CACHE_NONE
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    75
CACHE_STALE     = PT_CACHE_STALE
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    76
CACHE_INCOMPAT  = PT_CACHE_INCOMPAT
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
class Error (BaseException) :
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    79
    """
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    80
        Base class for errors raised by pypngtile.
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    81
    """
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    83
    def __init__ (self, func, err) :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    84
        super(Error, self).__init__("%s: %s: %s" % (func, pt_strerror(err), strerror(errno)))
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
cdef class Image :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    87
    """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    88
        An image file on disk (.png) and an associated .cache file.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    89
        
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    90
        Open the .png file at the given path using the given mode.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    91
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    92
        path        - filesystem path to .png file
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    93
        mode        - mode to operate cache in
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    94
            OPEN_READ       - read-only access to cache
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    95
            OPEN_UPDATE     - allow .update()
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    96
    """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    97
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
    cdef pt_image *image
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
104
b5ae988c78b8 add .path attr to pypngtile.Image
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   100
    # XXX: should really be a pt_image property...
b5ae988c78b8 add .path attr to pypngtile.Image
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   101
    cdef readonly object path
b5ae988c78b8 add .path attr to pypngtile.Image
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   102
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   103
    
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   104
    # open the pt_image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   105
    def __cinit__ (self, char *path, int mode = 0) :
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   106
        cdef int err
104
b5ae988c78b8 add .path attr to pypngtile.Image
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   107
b5ae988c78b8 add .path attr to pypngtile.Image
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   108
        # store
b5ae988c78b8 add .path attr to pypngtile.Image
Tero Marttila <terom@fixme.fi>
parents: 91
diff changeset
   109
        self.path = path
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   110
        
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   111
        # open
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   112
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   113
            # XXX: I hope use of path doesn't break...
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   114
            err = pt_image_open(&self.image, NULL, path, mode)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   115
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   116
        if err :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   117
            raise Error("pt_image_open", err)
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   118
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   119
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
    def info (self) :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   121
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   122
            Return a dictionary containing various information about the image.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   123
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   124
            img_width           - pixel dimensions of the source image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   125
            img_height            only available if the cache was opened
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   126
            img_bpp             - bits per pixel for the source image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   127
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   128
            image_mtime         - last modification timestamp for source image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   129
            image_bytes         - size of source image file in bytes
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   130
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   131
            cache_version       - version of cache file available
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   132
            cache_mtime         - last modification timestamp for cache file
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   133
            cache_bytes         - size of cache file in bytes
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   134
            cache_blocks        - size of cache file in disk blocks - 512 bytes / block
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   135
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   136
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   137
        cdef const_image_info_ptr infop
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   138
        cdef int err
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   139
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   140
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   141
            err = pt_image_info_(self.image, &infop)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   142
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   143
        if err :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   144
            raise Error("pt_image_info", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   145
        
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   146
        # return as a struct
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   147
        return infop[0]
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   148
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   149
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
    def status (self) :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   151
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   152
            Return a code describing the status of the underlying cache file.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   153
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   154
            CACHE_FRESH         - the cache file exists and is up-to-date
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   155
            CACHE_NONE          - the cache file does not exist
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   156
            CACHE_STALE         - the cache file exists, but is older than the source image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   157
            CACHE_INCOMPAT      - the cache file exists, but is incompatible with this version of the library
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   158
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   159
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   160
        cdef int ret
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   161
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   162
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   163
            ret = pt_image_status(self.image)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   164
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   165
        if ret :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   166
            raise Error("pt_image_status", ret)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   167
        
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   168
        return ret
87
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   169
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   170
    def open (self) :
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   171
        """
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   172
            Open the underlying cache file for reading, if available.
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   173
        """
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   174
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   175
        cdef int err
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   176
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   177
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   178
            err = pt_image_load(self.image)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   179
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   180
        if err :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   181
            raise Error("pt_image_load", err)
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   182
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   183
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   184
    def update (self, background_color = None) :
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   185
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   186
            Update the underlying cache file from the source image.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   187
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   188
            background_color    - skip consecutive pixels that match this byte pattern in output
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   189
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   190
            Requires that the Image was opened using OPEN_UPDATE.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   191
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   192
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   193
        cdef pt_image_params params
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   194
        cdef char *bgcolor
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   195
        cdef int err
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   196
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   197
        memset(&params, 0, sizeof(params))
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   198
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   199
        # params
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   200
        if background_color :
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   201
            # cast
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   202
            bgcolor = <char *>background_color
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   203
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   204
            if 0 >= len(bgcolor) > 4 :
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   205
                raise ValueError("background_color must be a str of between 1 and 4 bytes")
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   206
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   207
            # decode 
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   208
            memcpy(params.background_color, bgcolor, len(bgcolor))
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   209
    
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   210
        # run update
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   211
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   212
            err = pt_image_update(self.image, &params)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   213
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   214
        if err :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   215
            raise Error("pt_image_update", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   216
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   217
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   218
    def tile_file (self, size_t width, size_t height, size_t x, size_t y, int zoom, object out) :
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   219
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   220
            Render a region of the source image as a PNG tile to the given output file.
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   221
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   222
            width       - dimensions of the output tile in px
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   223
            height      
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   224
            x           - coordinates in the source file
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   225
            y
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   226
            zoom        - zoom level: out = 2**(-zoom) * in
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   227
            out         - output file
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   228
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   229
            Note that the given file object MUST be a *real* stdio FILE*, not a fake Python object.
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   230
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   231
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   232
        cdef stdio.FILE *outf
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   233
        cdef pt_tile_info ti
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   234
        cdef int err
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   235
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   236
        memset(&ti, 0, sizeof(ti))
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   237
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   238
        # convert to FILE
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   239
        if not PyFile_Check(out) :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   240
            raise TypeError("out: must be a file object")
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   241
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   242
        outf = PyFile_AsFile(out)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   243
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   244
        if not outf :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   245
            raise TypeError("out: must have a FILE*")
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   246
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   247
        # pack params
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   248
        ti.width = width
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   249
        ti.height = height
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   250
        ti.x = x
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   251
        ti.y = y
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   252
        ti.zoom = zoom
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
        
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   254
        # render
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   255
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   256
            err = pt_image_tile_file(self.image, &ti, outf)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   257
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   258
        if err :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   259
            raise Error("pt_image_tile_file", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   260
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   261
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   262
    def tile_mem (self, size_t width, size_t height, size_t x, size_t y, int zoom) :
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   263
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   264
            Render a region of the source image as a PNG tile, and return the PNG data a a string.
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   265
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   266
            width       - dimensions of the output tile in px
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   267
            height      
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   268
            x           - coordinates in the source file
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   269
            y
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   270
            zoom        - zoom level: out = 2**(-zoom) * in
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   271
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   272
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   273
        cdef pt_tile_info ti
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   274
        cdef char *buf
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   275
        cdef size_t len
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   276
        cdef int err
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   277
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   278
        memset(&ti, 0, sizeof(ti))
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   279
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   280
        # pack params
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   281
        ti.width = width
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   282
        ti.height = height
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   283
        ti.x = x
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   284
        ti.y = y
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   285
        ti.zoom = zoom
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   286
        
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   287
        # render and return via buf/len
91
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   288
        with nogil :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   289
            err = pt_image_tile_mem(self.image, &ti, &buf, &len)
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   290
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   291
        if err :
0bf7878bdf5c document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   292
            raise Error("pt_image_tile_mem", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   293
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   294
        # copy buffer as str...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
        data = python_string.PyString_FromStringAndSize(buf, len)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   296
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   297
        # drop buffer...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   298
        stdlib.free(buf)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   299
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   300
        return data
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   301
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   302
    # release the pt_image
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   303
    def __dealloc__ (self) :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   304
        if self.image :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   305
            pt_image_destroy(self.image)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   306
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   307
            self.image = NULL
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   308