見我遇到了一些奇怪的問題,更新需要幫助的libjpeg從
底部編譯jpegtran.c代碼。對於初學者,我正在使用最新的Eclipse CDT,並且在實施do_rot_180之前,編譯器鏈接文件夾projectName/include,但在它現在需要特定的include/*。h後指定。
與此問題相關,在項目瀏覽器中,似乎認爲libjpeg.h丟失或無效,儘管它位於磁盤上的文件夾中。
我正在使用libjpeg-9。
包括(包括哪些transupp.c和包括example.c):
功能(do_rot_180是transupp.c和read_JPEG_file是example.c):
See updated code block below under Edit 2 (pretty much just jpegtran.c code)
This is the rotate function which is unused in jpegtran.c:
//LOCAL(void)
//do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
// JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
// jvirt_barray_ptr *src_coef_arrays,
// jvirt_barray_ptr *dst_coef_arrays)
///* 180 degree rotation is equivalent to
// * 1. Vertical mirroring;
// * 2. Horizontal mirroring.
// * These two steps are merged into a single processing routine.
// */
//{
// JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
// JDIMENSION x_crop_blocks, y_crop_blocks;
// int ci, i, j, offset_y;
// JBLOCKARRAY src_buffer, dst_buffer;
// JBLOCKROW src_row_ptr, dst_row_ptr;
// JCOEFPTR src_ptr, dst_ptr;
// jpeg_component_info *compptr;
//
// MCU_cols = srcinfo->output_width/
// (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);
// MCU_rows = srcinfo->output_height/
// (dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size);
//
// for (ci = 0; ci < dstinfo->num_components; ci++) {
// compptr = dstinfo->comp_info + ci;
// comp_width = MCU_cols * compptr->h_samp_factor;
// comp_height = MCU_rows * compptr->v_samp_factor;
// x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
// y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
// for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
// dst_blk_y += compptr->v_samp_factor) {
// dst_buffer = (*srcinfo->mem->access_virt_barray)
// ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
// (JDIMENSION) compptr->v_samp_factor, TRUE);
// if (y_crop_blocks + dst_blk_y < comp_height) {
// /* Row is within the vertically mirrorable area. */
// src_buffer = (*srcinfo->mem->access_virt_barray)
// ((j_common_ptr) srcinfo, src_coef_arrays[ci],
// comp_height - y_crop_blocks - dst_blk_y -
// (JDIMENSION) compptr->v_samp_factor,
// (JDIMENSION) compptr->v_samp_factor, FALSE);
// } else {
// /* Bottom-edge rows are only mirrored horizontally. */
// src_buffer = (*srcinfo->mem->access_virt_barray)
// ((j_common_ptr) srcinfo, src_coef_arrays[ci],
// dst_blk_y + y_crop_blocks,
// (JDIMENSION) compptr->v_samp_factor, FALSE);
// }
// for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
// dst_row_ptr = dst_buffer[offset_y];
// if (y_crop_blocks + dst_blk_y < comp_height) {
// /* Row is within the mirrorable area. */
// src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
// for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
// dst_ptr = dst_row_ptr[dst_blk_x];
// if (x_crop_blocks + dst_blk_x < comp_width) {
// /* Process the blocks that can be mirrored both ways. */
// src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
// for (i = 0; i < DCTSIZE; i += 2) {
// /* For even row, negate every odd column. */
// for (j = 0; j < DCTSIZE; j += 2) {
// *dst_ptr++ = *src_ptr++;
// *dst_ptr++ = - *src_ptr++;
// }
// /* For odd row, negate every even column. */
// for (j = 0; j < DCTSIZE; j += 2) {
// *dst_ptr++ = - *src_ptr++;
// *dst_ptr++ = *src_ptr++;
// }
// }
// } else {
// /* Any remaining right-edge blocks are only mirrored vertically. */
// src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x];
// for (i = 0; i < DCTSIZE; i += 2) {
// for (j = 0; j < DCTSIZE; j++)
// *dst_ptr++ = *src_ptr++;
// for (j = 0; j < DCTSIZE; j++)
// *dst_ptr++ = - *src_ptr++;
// }
// }
// }
// } else {
// /* Remaining rows are just mirrored horizontally. */
// src_row_ptr = src_buffer[offset_y];
// for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
// if (x_crop_blocks + dst_blk_x < comp_width) {
// /* Process the blocks that can be mirrored. */
// dst_ptr = dst_row_ptr[dst_blk_x];
// src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
// for (i = 0; i < DCTSIZE2; i += 2) {
// *dst_ptr++ = *src_ptr++;
// *dst_ptr++ = - *src_ptr++;
// }
// } else {
// /* Any remaining right-edge blocks are only copied. */
// jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
// dst_row_ptr + dst_blk_x,
// (JDIMENSION) 1);
// }
// }
// }
// }
// }
// }
//}
最重要的是,我實際上找不到在哪裏jcopy_block_row已定義。我瀏覽過所有包含文件和它們的.c對應文件。
我注意到read_JPEG_file函數中的錯誤處理的東西,並想從內部調用do_rot_180,但我還沒有得到那麼多。
我發現的唯一的線索就是這transupp.c:
附加說明:所以它在什麼地方jpegtran.exe與編譯的.dll單獨工作。
編輯 - 將jpegint.h複製到include/which解決了包含問題。
#ifdef JPEG_INTERNALS
#include "jpegint.h" /* fetch private declarations */
#include "jerror.h" /* fetch error codes too */
#endif
現在它甚至不能編譯,雖然他們似乎都在jpeglib.h或jpegint.h中聲明:
編輯2 - 代碼現在包含jpegtran.c東西只是能夠旋轉180度。更新的代碼塊:
/*********************************************************************************/
/* Defines */
/*********************************************************************************/
#define JPEG_INTERNALS
/*********************************************************************************/
/* Includes */
/*********************************************************************************/
#include <stdio.h>
#include <iostream>
#include "jinclude.h"
#include "jpeglib.h"
#include "cdjpeg.h"
#include "transupp.h"
#include "jerror.h"
#include <ctype.h>
#include <setjmp.h>
//using namespace std;
static char * infilename;
static char * outfilename;
static JCOPY_OPTION copyoption;
static jpeg_transform_info transformoption;
FILE * infile;
FILE * outfile;
void openFile(char file) {
if(file == 'i') {
infile = fopen(infilename, "rb");
}
else if(file == 'o') {
outfile = fopen(outfilename, "wb");
}
}
/*********************************************************************************/
/* Main Execution Block */
/*********************************************************************************/
int main() {
struct jpeg_decompress_struct srcinfo;
struct jpeg_compress_struct dstinfo;
struct jpeg_error_mgr jsrcerr, jdsterr;
jvirt_barray_ptr * src_coef_arrays;
jvirt_barray_ptr * dst_coef_arrays;
//int file_index;
srcinfo.err = jpeg_std_error(&jsrcerr);
jpeg_create_decompress(&srcinfo);
dstinfo.err = jpeg_std_error(&jdsterr);
jpeg_create_compress(&dstinfo);
jsrcerr.trace_level = jdsterr.trace_level;
srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;
//
outfilename = NULL;
copyoption = JCOPYOPT_DEFAULT;
transformoption.transform = JXFORM_NONE;
transformoption.trim = FALSE;
transformoption.force_grayscale = FALSE;
transformoption.transform = JXFORM_ROT_180;
//
std::cout << "Enter a filename to rotate 180 degrees." << std::endl;
std::cin >> infilename;
openFile('i');
std::cout << "Enter the output filename." << std::endl;
std::cin >> outfilename;
openFile('o');
//
jpeg_stdio_src(&srcinfo, infile);
jcopy_markers_setup(&srcinfo, copyoption);
(void) jpeg_read_header(&srcinfo, TRUE);
jtransform_request_workspace(&srcinfo, &transformoption);
src_coef_arrays = jpeg_read_coefficients(&srcinfo);
jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
src_coef_arrays,
&transformoption);
jpeg_stdio_dest(&dstinfo, outfile);
jpeg_write_coefficients(&dstinfo, dst_coef_arrays);
jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);
jtransform_execute_transformation(&srcinfo, &dstinfo,
src_coef_arrays,
&transformoption);
jpeg_finish_compress(&dstinfo);
jpeg_destroy_compress(&dstinfo);
(void) jpeg_finish_decompress(&srcinfo);
jpeg_destroy_decompress(&srcinfo);
//
if (infile != stdin)
fclose(infile);
if (outfile != stdout)
fclose(outfile);
return 0;
}
/*********************************************************************************/
/* End of Program */
/*********************************************************************************/
編輯3 - 製造傑夫提到的變化和我編譯它的時候(在Eclipse)運行到這個問題:
cannot find -lC:\Users\tmp\workspace2\jpegManipulator\lib\libjpeg.a jpegManipulator C/C++ Problem
Invalid project path: Duplicate path entries found (/jpegManipulator [Include path] base-path:jpegManipulator isSystemInclude:true includePath:include), path: [/jpegManipulator].jpegManipulator pathentry Path Entry Problem
我有工作區目錄/ lib目錄設置爲庫源,以及在庫選項卡中設置的特定libjpeg.a庫 - 它絕對在目錄中。
如果我不包含特定的libjpeg.a文件,它會抱怨缺少函數引用,但如果我確實包含它,它會抱怨說沒有找到libjpeg.a。這適用於v9和v6b。
cannot find -lC:\Users\tmp\workspace2\jpeg6bmanip\libs\libjpeg.a jpeg6bmanip C/C++ Problem
cannot find -lC:\Users\tmp\workspace2\jpeg6bmanip\libs\libjpeg.la jpeg6bmanip C/C++ Problem
解決編輯3問題:https://stackoverflow.com/q/14692302/1666510但新的問題之後。由於聲稱無法找到jpeglib.h,因此無法運行程序或進行調試。
[在Windows上編譯/使用libjpeg for Eclipse](http://stackoverflow.com/questions/14593579/compiling-using-libjpeg-in-windows-for-eclipse) – Enigma