add pitched writepng function
authorkub <derkub@gmail.com>
Thu, 9 Jan 2025 22:57:17 +0000 (23:57 +0100)
committerkub <derkub@gmail.com>
Thu, 9 Jan 2025 22:57:17 +0000 (23:57 +0100)
readpng.c
readpng.h

index 5f36d6a..500e81c 100644 (file)
--- a/readpng.c
+++ b/readpng.c
@@ -234,7 +234,7 @@ done:
        return ret;
 }
 
-int writepng(const char *fname, unsigned short *src, int w, int h)
+int writepngpp(const char *fname, unsigned short *src, int w, int h, int pitch)
 {
        png_structp png_ptr = NULL;
        png_infop info_ptr = NULL;
@@ -262,6 +262,7 @@ int writepng(const char *fname, unsigned short *src, int w, int h)
                        dst[1] = PXGETG(*src);
                        dst[2] = PXGETB(*src);
                }
+               src += pitch-w;
        }
 
        /* initialize stuff */
@@ -307,3 +308,7 @@ end1:
        return ret;
 }
 
+int writepng(const char *fname, unsigned short *src, int w, int h)
+{
+       return writepngpp(fname, src, w, h, w);
+}
index c3d58a7..93846b5 100644 (file)
--- a/readpng.h
+++ b/readpng.h
@@ -16,6 +16,7 @@ extern "C" {
 #endif
 
 int readpng(void *dest, const char *fname, readpng_what what, int w, int h);
+int writepngpp(const char *fname, unsigned short *src, int w, int h, int pitch);
 int writepng(const char *fname, unsigned short *src, int w, int h);
 
 #ifdef __cplusplus