Code:
/*********************************************************************************/
/* Defines */
/*********************************************************************************/
#define JPEG_INTERNALS
/*********************************************************************************/
/* Includes */
/*********************************************************************************/
//extern "C"
//{
//#include "include/jpeglib.h"
//}
//#include "include/jinclude.h"
//#include "include/jpeglib.h"
//#include "include/transupp.h"
//#include "include/jerror.h"
#include <stdio.h>
#include <iostream>
#include "jinclude.h"
#include "jpeglib.h"
#include "transupp.h"
#include "jerror.h"
#include <ctype.h>
#include <setjmp.h>
//using namespace std;
/*********************************************************************************/
/* External Declarations */
/*********************************************************************************/
extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
extern int image_height; /* Number of rows in image */
extern int image_width; /* Number of columns in image */
/*********************************************************************************/
/* General Functions */
/*********************************************************************************/
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);
}
}
}
}
}
}
}
GLOBAL(int)
read_JPEG_file (char * filename)
{
struct jpeg_decompress_struct cinfo;
//struct my_error_mgr jerr;
FILE * infile; /* source file */
JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */
if ((infile = fopen(filename, "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
return 0;
}
// cinfo.err = jpeg_std_error(&jerr.pub);
// jerr.pub.error_exit = my_error_exit;
//
// if (setjmp(jerr.setjmp_buffer)) {
// /* If we get here, the JPEG code has signaled an error.
// * We need to clean up the JPEG object, close the input file, and return.
// */
// jpeg_destroy_decompress(&cinfo);
// fclose(infile);
// return 0;
// }
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
(void) jpeg_read_header(&cinfo, TRUE);
// (void) jpeg_start_decompress(&cinfo);
//
// row_stride = cinfo.output_width * cinfo.output_components;
//
// buffer = (*cinfo.mem->alloc_sarray)
// ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
//
// while (cinfo.output_scanline < cinfo.output_height) {
// /* jpeg_read_scanlines expects an array of pointers to scanlines.
// * Here the array is only one element long, but you could ask for
// * more than one scanline at a time if that's more convenient.
// */
// (void) jpeg_read_scanlines(&cinfo, buffer, 1);
// /* Assume put_scanline_someplace wants a pointer and sample count. */
// put_scanline_someplace(buffer[0], row_stride);
// }
//
// (void) jpeg_finish_decompress(&cinfo);
// jpeg_destroy_decompress(&cinfo);
fclose(infile);
return 1;
}
/*********************************************************************************/
/* Main Execution Block */
/*********************************************************************************/
int main() {
return 0;
}
/*********************************************************************************/
/* End of Program */
/*********************************************************************************/
The issue right now, assuming what I'm doing is in the right direction, is that `jpeg_CreateDecompress', `jpeg_stdio_src', and `jpeg_read_header' claim to be undefined.