Created
September 18, 2016 12:28
-
-
Save freundTech/dede6adb6dd3d2388e94498338faef4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <jpeglib.h> | |
#include <iostream> | |
#include <iomanip> | |
#include <sstream> | |
using namespace std; | |
JBLOCKARRAY rowPtrs[MAX_COMPONENTS]; | |
void read(jpeg_decompress_struct srcinfo, jvirt_barray_ptr * src_coef_arrays, int x, int y) { | |
x /= 8; | |
y /= 8; | |
cout << "Block at " << x << ", " << y << endl; | |
for (JDIMENSION compNum=0; compNum < srcinfo.num_components; compNum++) { | |
cout << endl << "Component " << compNum << endl; | |
for (JDIMENSION i=0; i<DCTSIZE2; i++){ | |
rowPtrs[compNum] = ((&srcinfo)->mem->access_virt_barray)((j_common_ptr) &srcinfo, src_coef_arrays[compNum],x, (JDIMENSION) 1 , FALSE); | |
cout << setfill(' ') << setw(5) << rowPtrs[compNum][0][y][i]; | |
if ((i+1) % 8 == 0 ) { | |
cout << endl; | |
} | |
} | |
} | |
} | |
int main(int argc, char** argv) { | |
if (argc != 4) { | |
cerr << "Usage: ./getdct image.jpg x y" << endl; | |
return 1; | |
} | |
istringstream ss(argv[2]); | |
int x; | |
if (!(ss >> x)) { | |
cerr << "Invalid number " << argv[2] << endl; | |
} | |
istringstream ss2(argv[3]); | |
int y; | |
if (!(ss2 >> y)) { | |
cerr << "Invalid number " << argv[3] << endl; | |
} | |
FILE * infile; | |
struct jpeg_decompress_struct srcinfo; | |
struct jpeg_error_mgr srcerr; | |
if ((infile = fopen(argv[1], "rb")) == NULL) { | |
fprintf(stderr, "can't open %s\n", argv[1]); | |
return 0; | |
} | |
srcinfo.err = jpeg_std_error(&srcerr); | |
jpeg_create_decompress(&srcinfo); | |
jpeg_stdio_src(&srcinfo, infile); | |
(void) jpeg_read_header(&srcinfo, FALSE); | |
//coefficients | |
jvirt_barray_ptr * src_coef_arrays = jpeg_read_coefficients(&srcinfo); | |
read(srcinfo, src_coef_arrays, x, y); | |
jpeg_destroy_decompress(&srcinfo); | |
fclose(infile); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment