#include <math.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <malloc.h>
#include "libqscale.h"
struct jpeg_error_mgr jerr;
dinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&dinfo);
- jpeg_stdio_src(&dinfo, stdin);
+ jpeg_stdio_src(&dinfo, file);
jpeg_read_header(&dinfo, TRUE);
dinfo.raw_data_out = TRUE;
jpeg_start_decompress(&dinfo);
}
}
+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));
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
- jpeg_stdio_dest(&cinfo, stdout);
+ jpeg_stdio_dest(&cinfo, file);
cinfo.input_components = 3;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, jpeg_quality, FALSE);