IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 3, 2023, 9:35:14 AM (3 years ago)
Author:
eugene
Message:

cleanup rdjpg code, fix build error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/rdjpg.c

    r42349 r42351  
    11# include "data.h"
    2 #include <setjmp.h>
    32# include "jpeglib.h"
     3# include <setjmp.h>
    44
    55struct my_error_mgr {
     
    2727int rdjpg (int argc, char **argv) {
    2828 
    29   int i, N, blank;
     29  int N;
    3030  Buffer *buf;
     31
     32  struct jpeg_decompress_struct cinfo;
     33  struct my_error_mgr jerr;
    3134
    3235  int VERBOSE = FALSE;
     
    4144  }
    4245
    43   struct jpeg_decompress_struct cinfo;
    44   struct my_error_mgr jerr;
    45 
    46   JSAMPARRAY buffer;            /* Output row buffer */
    47   int row_stride;               /* physical row width in output buffer */
    48 
    49   // struct my_error_mgr jerr; : needed for error handling (deferred)
    50 
    51   /* test if file exists */
     46  // open input file for read
    5247  FILE *f = fopen (argv[2], "r");
    5348  if (f == (FILE *) NULL) {
     
    5651  }
    5752
    58   /* find matrix, free old data */
     53  // find matrix, free old data
    5954  if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) {
    6055    fclose (f);
     
    6459  gfits_free_header (&buf[0].header);
    6560
    66   /* save file name */
     61  // save file name in buffer info
    6762  char *filename = filebasename (argv[2]);
    6863  strcpy (buf[0].file, filename);
    6964  free (filename);
    7065
    71   int status = FALSE;
    72 
     66  // the setup for the error handling seems a bit circular, but this
     67  // example from the libjpeg example.c seems to work?
    7368  cinfo.err = jpeg_std_error(&jerr.pub);
    7469  jerr.pub.error_exit = my_error_exit;
    75   /* Establish the setjmp return context for my_error_exit to use. */
     70
     71  // an error in the jpeg code will jump (goto) here:
    7672  if (setjmp(jerr.setjmp_buffer)) {
    7773    /* If we get here, the JPEG code has signaled an error.
     
    8985  jpeg_start_decompress(&cinfo);
    9086
    91   /* We may need to do some setup of our own at this point before reading
    92    * the data.  After jpeg_start_decompress() we have the correct scaled
    93    * output image dimensions available, as well as the output colormap
    94    * if we asked for color quantization.
    95    * In this example, we need to make an output work buffer of the right size.
    96    */
     87  /* JSAMPLEs per row in output buffer */
     88  int Nx = cinfo.output_width;
     89  int Ny = cinfo.output_height;
     90  int Npix_row = Nx * cinfo.output_components;
    9791
    98   /* JSAMPLEs per row in output buffer */
    99   row_stride = cinfo.output_width * cinfo.output_components;
    100   // Nx = cinfo.output_width or row_stride
    101   // Ny = cinfo.output_height
    102 
    103   CreateBuffer (buf, cinfo.output_width, cinfo.output_height, -32, 0.0, 1.0);
     92  CreateBuffer (buf, Nx, Ny, -32, 0.0, 1.0);
    10493  float *Vout = (float *)buf[0].matrix.buffer;
    10594
    10695  /* Make a one-row-high sample array that will go away when done with image */
    107   buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
     96  JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, Npix_row, 1);
    10897
    10998  // read each of the scanlines
    110   for (int iy = 0; iy < cinfo.output_height; iy++) {
     99  for (int iy = 0; iy < Ny; iy++) {
    111100    jpeg_read_scanlines(&cinfo, buffer, 1);
    112101
    113     /* Assume put_scanline_someplace wants a pointer and sample count. */
    114     for (int ix = 0; ix < cinfo.output_width; ix ++) {
     102    // for now just copy R + G + B as the total value:
     103    for (int ix = 0; ix < Nx; ix ++) {
    115104      unsigned char Rpix = buffer[0][3*ix + 0];
    116105      unsigned char Gpix = buffer[0][3*ix + 1];
    117106      unsigned char Bpix = buffer[0][3*ix + 2];
    118107      float value = Rpix + Gpix + Bpix;
    119       Vout[cinfo.output_width*iy + ix] = value;
     108      Vout[Nx*iy + ix] = value;
    120109    }
    121110  }
     
    126115  fclose (f);
    127116 
    128   /*
    129   if (!status) {
    130     gprint (GP_ERR, "problem reading file, buffer not opened\n");
    131     DeleteBuffer (buf);
    132     return (FALSE);
    133     }
    134   */
    135 
    136117  buf[0].bitpix = buf[0].header.bitpix;    /* store the original values */
    137118  buf[0].bscale = buf[0].header.bscale;    /* store the original values */
     
    141122  if (VERBOSE) gprint (GP_LOG, "read "OFF_T_FMT" bytes from %s into buffer %s\n", buf[0].header.datasize + buf[0].matrix.datasize, argv[2], argv[1]);
    142123
    143   blank = 0xffff;
    144 
    145   /** now - convert the matrix values to floats for internal use **/
    146   // gfits_convert_format (&buf[0].header, &buf[0].matrix, -32, 1.0, 0.0, blank, gfits_get_unsign_mode());
    147 
    148124  return (TRUE);
    149125}
    150 
    151 # if (0)
    152 // XXX not sure about error handling here
    153 // cinfo.err = jpeg_std_error(&jerr.pub);
    154 // jerr.pub.error_exit = my_error_exit;
    155 
    156 /* Establish the setjmp return context for my_error_exit to use. */
    157 if (setjmp(jerr.setjmp_buffer)) {
    158   /* If we get here, the JPEG code has signaled an error.
    159    * We need to clean up the JPEG object, close the input file, and return.
    160    */
    161   jpeg_destroy_decompress(&cinfo);
    162   fclose(f);
    163   return 0;
    164 }
    165 # endif
    166 
Note: See TracChangeset for help on using the changeset viewer.