]> git.sesse.net Git - qscale/blobdiff - libqscale.c
Add some useful functions for the Perl module.
[qscale] / libqscale.c
index c02aa1a58ee685471f2a0fa31157341ea363432c..c26a4418e91746bf337d7552cd6dc9fc513ce4b6 100644 (file)
@@ -19,6 +19,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <malloc.h>
 
 #include "libqscale.h"
@@ -479,6 +480,36 @@ static void vscale(unsigned char *pix, float *npix, unsigned w, unsigned h, unsi
        }
 }
 
+qscale_img *qscale_clone(const qscale_img *img)
+{
+       qscale_img *dst = (qscale_img *)malloc(sizeof(qscale_img));
+       if (dst == NULL) {
+               return NULL;
+       }
+
+       *dst = *img;
+
+       unsigned dstride0 = (dst->w0 + DCTSIZE-1) & ~(DCTSIZE-1);
+       unsigned dstride1 = (dst->w1 + DCTSIZE-1) & ~(DCTSIZE-1);
+       unsigned dstride2 = (dst->w2 + DCTSIZE-1) & ~(DCTSIZE-1);
+
+       /* FIXME: handle out-of-memory gracefully */
+       {
+               dst->data_y = (unsigned char *)malloc(dst->h0 * dstride0);
+               memcpy(dst->data_y, img->data_y, dst->h0 * dstride0);
+       }
+       {
+               dst->data_cb = (unsigned char *)malloc(dst->h1 * dstride1);
+               memcpy(dst->data_cb, img->data_cb, dst->h0 * dstride0);
+       }
+       {
+               dst->data_cr = (unsigned char *)malloc(dst->h1 * dstride1);
+               memcpy(dst->data_cr, img->data_cr, dst->h0 * dstride0);
+       }
+
+       return dst;
+}
+
 qscale_img *qscale_scale(qscale_img *src, unsigned width, unsigned height, unsigned samp_h0, unsigned samp_v0, unsigned samp_h1, unsigned samp_v1, unsigned samp_h2, unsigned samp_v2, enum qscale_scaling_filter scaling_filter)
 {
        qscale_img *dst = (qscale_img *)malloc(sizeof(qscale_img));