Александр Муксимов Asked:2020-09-25 17:22:41 +0800 CST2020-09-25 17:22:41 +0800 CST 2020-09-25 17:22:41 +0800 CST JPEG解码 772 告诉我一个免费分发的库(与 Windows 兼容)或从 JPEG 文件中提取量化余弦系数的源。这是逆 JPEG 解码(霍夫曼编码到 DCT 系数)的第一步。我知道算法如何做到这一点,但我真的不想重新发明轮子并浪费时间测试自制程序。 c++ 1 个回答 Voted Best Answer zed 2020-09-25T18:30:11+08:002020-09-25T18:30:11+08:00 这可以通过 libjpeg 完成。 示例(因此:提取 JPEG DCT 系数): #include <stdio.h> #include <jpeglib.h> #include <iostream> using namespace std; JBLOCKARRAY rowPtrs[MAX_COMPONENTS]; void read(jpeg_decompress_struct srcinfo, jvirt_barray_ptr * src_coef_arrays) { //cout << "Started reading DCT" << endl; for (JDIMENSION compNum=0; compNum < srcinfo.num_components; compNum++) { size_t blockRowSize = (size_t) sizeof(JCOEF) * DCTSIZE2 * srcinfo.comp_info[compNum].width_in_blocks; for (JDIMENSION rowNum=0; rowNum < srcinfo.comp_info[compNum].height_in_blocks; rowNum++) { // A pointer to the virtual array of dct values rowPtrs[compNum] = ((&srcinfo)->mem->access_virt_barray)((j_common_ptr) &srcinfo, src_coef_arrays[compNum],rowNum, (JDIMENSION) 1, FALSE); // Loop through the blocks to get the dct values for (JDIMENSION blockNum=0; blockNum < srcinfo.comp_info[compNum].width_in_blocks; blockNum++){ //...iterate over DCT coefficients for (JDIMENSION i=0; i<DCTSIZE2; i++){ //and print them to standard out - one per line cout << rowPtrs[compNum][0][blockNum][i] << endl; } } } } } int main() { //TODO: change this to read a different file const char* filename = "image4.jpg"; FILE * infile; struct jpeg_decompress_struct srcinfo; struct jpeg_error_mgr srcerr; if ((infile = fopen(filename, "rb")) == NULL) { fprintf(stderr, "can't open %s\n", filename); 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); jpeg_destroy_decompress(&srcinfo); fclose(infile); return 0; }
这可以通过 libjpeg 完成。
示例(因此:提取 JPEG DCT 系数):