]> git.sesse.net Git - fjl/blobdiff - driver.c
Fix height/width read.
[fjl] / driver.c
index 1411b51311e7efca363b88b038a1c9a634173455..0834df763d2124f9268c441b9e2f2074d97815c3 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -62,8 +62,8 @@ void read_sof(struct byte_source* source, struct jpeg_image* image)
        assert(len >= 8);
        image->precision = read_uint8(byte_source_input_func, source);
        assert(image->precision == 8);
-       image->width = read_uint16(byte_source_input_func, source);
        image->height = read_uint16(byte_source_input_func, source);
+       image->width = read_uint16(byte_source_input_func, source);
        image->num_components = read_uint8(byte_source_input_func, source);
        len -= 8;
 
@@ -185,8 +185,13 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab
                                }
                        }
 
-                       if (cn == 1 && ++xb * DCTSIZE == y_stride) {
-                               fwrite(y_row_data, y_stride * DCTSIZE * image->vsample[1], 1, stdout);
+                       if (cn != 1) {
+                               continue;
+                       }
+
+                       xb += image->hsample[cn];
+                       if (xb * DCTSIZE == y_stride) {
+                               fwrite(y_row_data, y_stride * DCTSIZE * image->vsample[cn], 1, stdout);
                                xb = 0;
                        }
                }