X-Git-Url: https://git.sesse.net/?p=qscale;a=blobdiff_plain;f=libqscale.c;fp=libqscale.c;h=c26a4418e91746bf337d7552cd6dc9fc513ce4b6;hp=c02aa1a58ee685471f2a0fa31157341ea363432c;hb=07342f6e7cf83fbf6707ec370c22431e98b62fd7;hpb=a1446ef0a38e566288fc325be5eea86abb307ec3 diff --git a/libqscale.c b/libqscale.c index c02aa1a..c26a441 100644 --- a/libqscale.c +++ b/libqscale.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #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));