#include #include #include /* this segfaults */ int main (int argc, char *argv[]) { struct jpeg_compress_struct cinfo = { 0, }; struct jpeg_error_mgr jerr = { 0, }; char *raw_data; int size, i, row_stride; cinfo.err = jpeg_std_error (&jerr); jpeg_create_compress (&cinfo); jpeg_stdio_dest (&cinfo, stdout); size = cinfo.image_width * cinfo.image_height * 2; raw_data = calloc (3, size); if (fread (raw_data, 1, size, stdin) < size) { perror ("fread"); } cinfo.image_width = 720; cinfo.image_height = 1152; cinfo.in_color_space = JCS_RGB; cinfo.input_components = 3; jpeg_set_defaults (&cinfo); jpeg_set_quality (&cinfo, 70, TRUE); jpeg_start_compress (&cinfo, TRUE); row_stride = cinfo.image_width * 2; while (cinfo.next_scanline < cinfo.image_height) { jpeg_write_scanlines (&cinfo, (JSAMPROW *) raw_data + row_stride * cinfo.next_scanline, 1); } jpeg_finish_compress (&cinfo); jpeg_destroy_compress (&cinfo); return 0; }