python/pypngtile.pyx
author Tero Marttila <terom@fixme.fi>
Mon, 25 Jan 2010 05:14:00 +0200
changeset 91 0bf7878bdf5c
parent 87 ecd87b41e884
child 104 b5ae988c78b8
permissions -rw-r--r--
document pt_image_tile_* as semi-threadsafe, and nogil pypngtile.pyx (and get rid of trap_err, ugh). Also fix constness warning
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
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   100
    
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   101
    # open the pt_image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   102
    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
   103
        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
   104
        
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
   105
        # 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
   106
        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
   107
            # 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
   108
            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
   109
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
        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
   111
            raise Error("pt_image_open", err)
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   112
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   113
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
    def info (self) :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   115
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   116
            Return a dictionary containing various information about the image.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   117
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   118
            img_width           - pixel dimensions of the source image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   119
            img_height            only available if the cache was opened
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   120
            img_bpp             - bits per pixel for the source image
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
            image_mtime         - last modification timestamp for source image
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   123
            image_bytes         - size of source image file in bytes
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   124
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   125
            cache_version       - version of cache file available
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   126
            cache_mtime         - last modification timestamp for cache file
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   127
            cache_bytes         - size of cache file in bytes
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   128
            cache_blocks        - size of cache file in disk blocks - 512 bytes / block
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   129
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   130
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
   131
        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
   132
        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
   133
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
   134
        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
   135
            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
   136
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
        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
   138
            raise Error("pt_image_info", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   139
        
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   140
        # 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
   141
        return infop[0]
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   142
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   143
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
    def status (self) :
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   145
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   146
            Return a code describing the status of the underlying cache file.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   147
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   148
            CACHE_FRESH         - the cache file exists and is up-to-date
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   149
            CACHE_NONE          - the cache file does not exist
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   150
            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
   151
            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
   152
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   153
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
   154
        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
   155
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
   156
        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
   157
            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
   158
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
   159
        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
   160
            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
   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
        return ret
87
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   163
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   164
    def open (self) :
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   165
        """
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   166
            Open the underlying cache file for reading, if available.
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   167
        """
ecd87b41e884 pyx: Image.open
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   168
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
   169
        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
   170
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
   171
        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
   172
            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
   173
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
   174
        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
   175
            raise Error("pt_image_load", err)
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   176
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   177
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   178
    def update (self, background_color = None) :
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   179
        """
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   180
            Update the underlying cache file from the source image.
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   181
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   182
            background_color    - skip consecutive pixels that match this byte pattern in output
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
            Requires that the Image was opened using OPEN_UPDATE.
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
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   187
        cdef pt_image_params params
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   188
        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
   189
        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
   190
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   191
        memset(&params, 0, sizeof(params))
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
        # params
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   194
        if background_color :
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   195
            # cast
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   196
            bgcolor = <char *>background_color
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   197
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   198
            if 0 >= len(bgcolor) > 4 :
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   199
                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
   200
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   201
            # decode 
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   202
            memcpy(params.background_color, bgcolor, len(bgcolor))
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   203
    
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   204
        # 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
   205
        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
   206
            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
   207
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
   208
        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
   209
            raise Error("pt_image_update", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   210
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   211
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   212
    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
   213
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   214
            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
   215
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   216
            width       - dimensions of the output tile in px
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   217
            height      
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   218
            x           - coordinates in the source file
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   219
            y
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   220
            zoom        - zoom level: out = 2**(-zoom) * in
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   221
            out         - output file
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   222
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   223
            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
   224
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   225
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   226
        cdef stdio.FILE *outf
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   227
        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
   228
        cdef int err
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   229
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   230
        memset(&ti, 0, sizeof(ti))
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   231
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   232
        # convert to FILE
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   233
        if not PyFile_Check(out) :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   234
            raise TypeError("out: must be a file object")
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   235
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   236
        outf = PyFile_AsFile(out)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   237
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   238
        if not outf :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   239
            raise TypeError("out: must have a FILE*")
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   240
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   241
        # pack params
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   242
        ti.width = width
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   243
        ti.height = height
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   244
        ti.x = x
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   245
        ti.y = y
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   246
        ti.zoom = zoom
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   247
        
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   248
        # 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
   249
        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
   250
            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
   251
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
   252
        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
   253
            raise Error("pt_image_tile_file", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   254
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   255
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   256
    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
   257
        """
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   258
            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
   259
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   260
            width       - dimensions of the output tile in px
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   261
            height      
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   262
            x           - coordinates in the source file
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   263
            y
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   264
            zoom        - zoom level: out = 2**(-zoom) * in
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
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   267
        cdef pt_tile_info ti
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   268
        cdef char *buf
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   269
        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
   270
        cdef int err
83
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
        memset(&ti, 0, sizeof(ti))
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   273
        
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   274
        # pack params
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   275
        ti.width = width
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   276
        ti.height = height
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   277
        ti.x = x
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   278
        ti.y = y
34
a387bc77ad52 implement zoom
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   279
        ti.zoom = zoom
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   280
        
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   281
        # 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
   282
        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
   283
            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
   284
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
   285
        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
   286
            raise Error("pt_image_tile_mem", err)
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   287
        
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   288
        # copy buffer as str...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   289
        data = python_string.PyString_FromStringAndSize(buf, len)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   290
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   291
        # drop buffer...
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   292
        stdlib.free(buf)
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
        return data
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
78
a3aaf5c23454 improve pypngtile
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   296
    # release the pt_image
30
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   297
    def __dealloc__ (self) :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   298
        if self.image :
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   299
            pt_image_destroy(self.image)
53e99e552122 move the python/web code in
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   300
83
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   301
            self.image = NULL
a1e8fa84a9fb docfix tile_* funcs
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   302