Thread: Need help rotating a JEPG using libjpeg v9

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    9

    Need help rotating a JEPG using libjpeg v9

    I've spent several days going through the motions getting libjpeg v9 compiled. I can run jpegtran.exe, which is one of the compiled files to successfully rotate jpeg's divisible by 16 in WxH. Now I'm trying to implement a code based solution using the included example.c and transupp.c functions. There may be a better way than this but I'm not sure how else. transupp.c has the function do_rot_180 and example.c has read_JPEG_file and write_JPEG_file and I've tried making a project that includes those functions and the #include files that each file requires but it's not compiling.

    I'm kind of a noob when it comes to the more advanced aspects of C++ so I'm sure I'm missing something with the .DLL or supposedly a .lib (I can't find one) or something. I'm good at working within functional projects but that's just because all of the more complicated set up stuff is taken care of for the most part.

    Current code:
    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.

    Also, I'm doing in this the latest Eclipse CDT on Windows 7 if that makes any difference.
    Last edited by Xenosis; 01-31-2013 at 01:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble using libjpeg
    By divsragha in forum Game Programming
    Replies: 7
    Last Post: 07-12-2011, 10:17 AM
  2. linker error when using libjpeg
    By s-men in forum C++ Programming
    Replies: 2
    Last Post: 08-21-2008, 10:02 AM
  3. libjpeg problems linking in cpp
    By parad0x13 in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2008, 04:29 PM
  4. libjpeg sgefault on jpeg_read_scanlines()
    By Syko in forum C Programming
    Replies: 6
    Last Post: 11-27-2005, 02:14 AM
  5. Compiler errors when using libjpeg.
    By Nikanoru in forum C++ Programming
    Replies: 11
    Last Post: 08-07-2003, 06:46 AM

Tags for this Thread