Advertisement
Guest User

extractdct.c

a guest
Nov 15th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. /*Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.*/
  2.  
  3. #include <stdio.h>
  4. #include "jpeglib.h"
  5.  
  6. int main() {
  7.     struct jpeg_decompress_struct srcinfo;
  8.     struct jpeg_error_mgr srcerr;
  9.     jvirt_barray_ptr *coef;
  10.     JBLOCKARRAY coef_array;
  11.     int c;
  12.     JDIMENSION n_rows, n_cols, y, x;
  13.  
  14.     srcinfo.err = jpeg_std_error(&srcerr);
  15.     jpeg_create_decompress(&srcinfo);
  16.     jpeg_stdio_src(&srcinfo, stdin);
  17.     jpeg_read_header(&srcinfo, TRUE);
  18.     coef = jpeg_read_coefficients(&srcinfo);
  19.  
  20.     for (c = 0; c < srcinfo.num_components; c++) {
  21.         n_rows = srcinfo.comp_info[c].height_in_blocks;
  22.         n_cols = srcinfo.comp_info[c].width_in_blocks;
  23.         for (y = 0; y < n_rows; y++) {
  24.             coef_array = (*srcinfo.mem->access_virt_barray)((j_common_ptr) &srcinfo, coef[c], y, 1, FALSE);
  25.             for (x = 0; x < n_cols; x++) {
  26.                 if (fwrite(coef_array[0][x], sizeof(JCOEF), DCTSIZE2, stdout) != DCTSIZE2) {
  27.                     fprintf(stderr, "Error writing coefficients\n");
  28.                 }
  29.             }
  30.         }
  31.     }
  32.  
  33.     jpeg_finish_decompress(&srcinfo);
  34.     jpeg_destroy_decompress(&srcinfo);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement