gpt4 book ai didi

c++ - 需要帮助从 libjpeg 编译 jpegtran.c 代码

转载 作者:行者123 更新时间:2023-11-28 07:47:20 28 4
gpt4 key购买 nike

更新见底部

我遇到了一些奇怪的问题。对于初学者,我使用的是最新的 Eclipse CDT,在实现 do_rot_180 之前,编译器链接了文件夹 projectName/include 但之后它现在需要指定特定的 include/*.h下面。

与该问题相关,在项目资源管理器中,似乎认为 libjpeg.h 丢失或无效,尽管它位于磁盘上的文件夹中。

我正在使用 libjpeg-9。

eclipse issue

包括(包括transupp.c和example.c包括的内容):

includes in eclipse hard drive includes

函数(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 中:

transupp.c

附加说明:jpegtran.exe 与编译后的 .DLL 分开工作,因此它必须在某个地方。


编辑 - 将 jpegint.h 复制到 include/中,解决了包含问题。

#ifdef JPEG_INTERNALS
#include "jpegint.h" /* fetch private declarations */
#include "jerror.h" /* fetch error codes too */
#endif

现在它无法编译,即使它们似乎都在 jpeglib.h 或 jpegint.h 中声明:

undefined referenced (4)


编辑 2 - 代码现在包含仅能旋转 180 度的 jpegtran.c 内容。更新的代码块:

/*********************************************************************************/
/* 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 - 进行了 Jeff 提到的更改,我在编译它时遇到了这个问题(在 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

最佳答案

几年前,我在使用 MinGW 进行开发时遇到过类似的事情。我必须下载 libjpeg 的源代码并在我的机器上构建它才能获得 libjpeg.a 文件。来源可以在这里找到:

http://www.ijg.org/

我在构建这个库时发现的问题是,当我执行“nm libjpeg.a”时,很明显 cdjpeg.h 和 transupp.h 中的符号没有被编译到库中。我找不到通过配置来完成此操作的方法,因为当我执行“configure --help”时没有看到任何明显的东西。相反,我编辑了 Makefile.in 文件,它定义了 .lo 文件的 am__objects_1 列表。我在最后添加了 cdjpeg 和 transupp,如下所示:

am__objects_1 = jaricom.lo jcapimin.lo jcapistd.lo jcarith.lo \
jccoefct.lo jccolor.lo jcdctmgr.lo jchuff.lo jcinit.lo \
jcmainct.lo jcmarker.lo jcmaster.lo jcomapi.lo jcparam.lo \
jcprepct.lo jcsample.lo jctrans.lo jdapimin.lo jdapistd.lo \
jdarith.lo jdatadst.lo jdatasrc.lo jdcoefct.lo jdcolor.lo \
jddctmgr.lo jdhuff.lo jdinput.lo jdmainct.lo jdmarker.lo \
jdmaster.lo jdmerge.lo jdpostct.lo jdsample.lo jdtrans.lo \
jerror.lo jfdctflt.lo jfdctfst.lo jfdctint.lo jidctflt.lo \
jidctfst.lo jidctint.lo jquant1.lo jquant2.lo jutils.lo \
jmemmgr.lo cdjpeg.lo transupp.lo @MEMORYMGR@.lo

然后我做了一个“make”和一个“make install”,库中出现了符号。那时我能够得到你的代码来构建。 autotools 专家可能会想出更好的方法,但这至少会让你继续下去。

关于c++ - 需要帮助从 libjpeg 编译 jpegtran.c 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14631530/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com