]> git.sesse.net Git - qscale/commitdiff
Fix behavior for input images not aligned on a DCT block.
authorsgunderson@bigfoot.com <>
Sun, 3 Feb 2008 17:13:18 +0000 (18:13 +0100)
committersgunderson@bigfoot.com <>
Sun, 3 Feb 2008 17:13:18 +0000 (18:13 +0100)
qscale.c

index 54985cc7e6beb47640cbd5fc6c64eac7e26487d7..8ceb53eb0ea8565d31cf72df64c8814154c9b991 100644 (file)
--- a/qscale.c
+++ b/qscale.c
@@ -38,7 +38,7 @@ struct pix_desc {
        unsigned startcoeff;
 };
 
-void hscale(float *pix, unsigned char *npix, unsigned w, unsigned h, unsigned nw, unsigned dstride)
+void hscale(float *pix, unsigned char *npix, unsigned w, unsigned h, unsigned nw, unsigned sstride, unsigned dstride)
 {
        struct pix_desc *pd = (struct pix_desc *)malloc(nw * sizeof(struct pix_desc));
        int size_coeffs = 8;
@@ -97,7 +97,7 @@ void hscale(float *pix, unsigned char *npix, unsigned w, unsigned h, unsigned nw
        }
        
        for (y = 0; y < h; ++y) {
-               float *sptr = pix + y*w;
+               float *sptr = pix + y*sstride;
                unsigned char *dptr = npix + y*dstride;
                unsigned char ch;
                for (x = 0; x < nw; ++x) {
@@ -352,6 +352,10 @@ int main(int argc, char **argv)
        dinfo.raw_data_out = TRUE;
        jpeg_start_decompress(&dinfo);
 
+       unsigned w0 = dinfo.image_width * samp_h0 / max_samp_h, h0 = dinfo.image_height * samp_v0 / max_samp_v;
+       unsigned w1 = dinfo.image_width * samp_h1 / max_samp_h, h1 = dinfo.image_height * samp_v1 / max_samp_v;
+       unsigned w2 = dinfo.image_width * samp_h2 / max_samp_h, h2 = dinfo.image_height * samp_v2 / max_samp_v;
+
        fprintf(stderr, "Scaling using Lanczos filter:\n");
        fprintf(stderr, "  Y component: %ux%u -> %ux%u\n", dinfo.comp_info[0].width_in_blocks * DCTSIZE, dinfo.comp_info[0].height_in_blocks * DCTSIZE, nw0, nh0);
        fprintf(stderr, "  Cb component: %ux%u -> %ux%u\n", dinfo.comp_info[1].width_in_blocks * DCTSIZE, dinfo.comp_info[1].height_in_blocks * DCTSIZE, nw1, nh1);
@@ -387,23 +391,23 @@ int main(int argc, char **argv)
 
        {
                float *npix = (float*)memalign(16, dinfo.comp_info[0].width_in_blocks * DCTSIZE * nh0 * sizeof(float)); 
-               vscale(data_y, npix, dinfo.comp_info[0].width_in_blocks * DCTSIZE, dinfo.comp_info[0].height_in_blocks * DCTSIZE, nh0, dinfo.comp_info[0].width_in_blocks * DCTSIZE);
+               vscale(data_y, npix, dinfo.comp_info[0].width_in_blocks * DCTSIZE, h0, nh0, dinfo.comp_info[0].width_in_blocks * DCTSIZE);
                data_ny = (unsigned char *)malloc(nw0 * stride0);
-               hscale(npix, data_ny, dinfo.comp_info[0].width_in_blocks * DCTSIZE, nh0, nw0, stride0);
+               hscale(npix, data_ny, w0, nh0, nw0, dinfo.comp_info[0].width_in_blocks * DCTSIZE, stride0);
                free(npix);
        }
        {
                float *npix = (float*)memalign(16, dinfo.comp_info[1].width_in_blocks * DCTSIZE * nh1 * sizeof(float)); 
-               vscale(data_cr, npix, dinfo.comp_info[1].width_in_blocks * DCTSIZE, dinfo.comp_info[1].height_in_blocks * DCTSIZE, nh1, dinfo.comp_info[1].width_in_blocks * DCTSIZE);
+               vscale(data_cr, npix, dinfo.comp_info[1].width_in_blocks * DCTSIZE, h1, nh1, dinfo.comp_info[1].width_in_blocks * DCTSIZE);
                data_ncr = (unsigned char *)malloc(nw1 * stride1);
-               hscale(npix, data_ncr, dinfo.comp_info[1].width_in_blocks * DCTSIZE, nh1, nw1, stride1);
+               hscale(npix, data_ncr, w1, nh1, nw1, dinfo.comp_info[1].width_in_blocks * DCTSIZE, stride1);
                free(npix);
        }
        {
                float *npix = (float*)memalign(16, dinfo.comp_info[2].width_in_blocks * DCTSIZE * nh2 * sizeof(float)); 
-               vscale(data_cb, npix, dinfo.comp_info[2].width_in_blocks * DCTSIZE, dinfo.comp_info[2].height_in_blocks * DCTSIZE, nh2, dinfo.comp_info[2].width_in_blocks * DCTSIZE);
+               vscale(data_cb, npix, dinfo.comp_info[2].width_in_blocks * DCTSIZE, h2, nh2, dinfo.comp_info[2].width_in_blocks * DCTSIZE);
                data_ncb = (unsigned char *)malloc(nw2 * stride2);
-               hscale(npix, data_ncb, dinfo.comp_info[2].width_in_blocks * DCTSIZE, nh2, nw2, stride2);
+               hscale(npix, data_ncb, w2, nh2, nw2, dinfo.comp_info[2].width_in_blocks * DCTSIZE, stride2);
                free(npix);
        }
        jpeg_destroy_decompress(&dinfo);