+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;
+}
+