#include <math.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <malloc.h>
#include "libqscale.h"
}
}
+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));