PT_OPEN_UPDATE
authorTero Marttila <terom@fixme.fi>
Tue, 29 Dec 2009 01:06:52 +0200
changeset 11 eb2a1472f084
parent 10 6806a90d934f
child 12 3576e00388fd
PT_OPEN_UPDATE
src/lib/cache.c
src/lib/image.c
src/lib/pngtile.h
src/util/main.c
--- a/src/lib/cache.c	Tue Dec 29 00:22:57 2009 +0200
+++ b/src/lib/cache.c	Tue Dec 29 01:06:52 2009 +0200
@@ -123,12 +123,6 @@
     int fd;
     char tmp_path[1024];
     
-    // check mode
-    if (!(cache->mode & PT_IMG_WRITE)) {
-        errno = EPERM;
-        return -1;
-    }
-    
     // get .tmp path
     if (path_with_fext(cache->path, tmp_path, sizeof(tmp_path), ".tmp"))
         return -1;
@@ -157,7 +151,7 @@
     prot |= PROT_READ;
 
     if (!readonly) {
-        assert(cache->mode & PT_IMG_WRITE);
+        assert(cache->mode & PT_OPEN_UPDATE);
 
         prot |= PROT_WRITE;
     }
@@ -233,12 +227,12 @@
 /**
  * Create a new .tmp cache file, open it, and write out the header.
  */
-static int pt_cache_open_create (struct pt_cache *cache, struct pt_cache_header *header)
+static int pt_cache_create (struct pt_cache *cache, struct pt_cache_header *header)
 {
     void *base;
 
     // no access
-    if (!(cache->mode & PT_IMG_WRITE)) {
+    if (!(cache->mode & PT_OPEN_UPDATE)) {
         errno = EPERM;
         return -1;
     }
@@ -352,7 +346,7 @@
             header.width, header.height, header.bit_depth, header.color_type
     );
 
-    // only pack 1 pixel per byte
+    // only pack 1 pixel per byte, changes rowbytes
     if (header.bit_depth < 8)
         png_set_packing(png);
 
@@ -385,7 +379,7 @@
     }
 
     // create .tmp and write out header
-    if (pt_cache_open_create(cache, &header))
+    if (pt_cache_create(cache, &header))
         return -1;
 
 
@@ -448,3 +442,4 @@
 
     free(cache);
 }
+
--- a/src/lib/image.c	Tue Dec 29 00:22:57 2009 +0200
+++ b/src/lib/image.c	Tue Dec 29 01:06:52 2009 +0200
@@ -117,7 +117,7 @@
     png_infop info;
 
     // pre-check enabled
-    if (!(image->cache->mode & PT_IMG_WRITE)) {
+    if (!(image->cache->mode & PT_OPEN_UPDATE)) {
         errno = EPERM;
         return -1;
     }
--- a/src/lib/pngtile.h	Tue Dec 29 00:22:57 2009 +0200
+++ b/src/lib/pngtile.h	Tue Dec 29 01:06:52 2009 +0200
@@ -22,10 +22,10 @@
 /** Bitmask for pt_image_open modes */
 enum pt_image_mode {
     /** Update cache if needed */
-    PT_IMG_WRITE    = 0x01,
+    PT_OPEN_UPDATE   = 0x01,
 
     /** Accept stale cache */
-    PT_IMG_STALE    = 0x02,
+    PT_OPEN_STALE    = 0x02,
 };
 
 /**
@@ -63,7 +63,9 @@
     // TODO: int zoom;
 };
 
-
+/**
+ * TODO: impl
+ */
 int pt_ctx_new (struct pt_ctx **ctx_ptr);
 
 /**
@@ -72,7 +74,7 @@
  * @param img_ptr returned pt_image handle
  * @param ctx global state to use
  * @param path filesystem path to .png file
- * @param mode combination of PT_IMG_* flags
+ * @param mode combination of PT_OPEN_* flags
  */
 int pt_image_open (struct pt_image **image_ptr, struct pt_ctx *ctx, const char *png_path, int cache_mode);
 
--- a/src/util/main.c	Tue Dec 29 00:22:57 2009 +0200
+++ b/src/util/main.c	Tue Dec 29 01:06:52 2009 +0200
@@ -118,7 +118,7 @@
         log_debug("Loading image from: %s...", img_path);
 
         // open
-        if (pt_image_open(&image, ctx, img_path, PT_IMG_WRITE)) {
+        if (pt_image_open(&image, ctx, img_path, PT_OPEN_UPDATE)) {
             log_errno("pt_image_open: %s", img_path);
             continue;
         }