Changeset 42351 for branches/eam_branches/ipp-20220316
- Timestamp:
- Feb 3, 2023, 9:35:14 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/rdjpg.c
r42349 r42351 1 1 # include "data.h" 2 #include <setjmp.h>3 2 # include "jpeglib.h" 3 # include <setjmp.h> 4 4 5 5 struct my_error_mgr { … … 27 27 int rdjpg (int argc, char **argv) { 28 28 29 int i, N, blank;29 int N; 30 30 Buffer *buf; 31 32 struct jpeg_decompress_struct cinfo; 33 struct my_error_mgr jerr; 31 34 32 35 int VERBOSE = FALSE; … … 41 44 } 42 45 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 52 47 FILE *f = fopen (argv[2], "r"); 53 48 if (f == (FILE *) NULL) { … … 56 51 } 57 52 58 / * find matrix, free old data */53 // find matrix, free old data 59 54 if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) { 60 55 fclose (f); … … 64 59 gfits_free_header (&buf[0].header); 65 60 66 / * save file name */61 // save file name in buffer info 67 62 char *filename = filebasename (argv[2]); 68 63 strcpy (buf[0].file, filename); 69 64 free (filename); 70 65 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? 73 68 cinfo.err = jpeg_std_error(&jerr.pub); 74 69 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: 76 72 if (setjmp(jerr.setjmp_buffer)) { 77 73 /* If we get here, the JPEG code has signaled an error. … … 89 85 jpeg_start_decompress(&cinfo); 90 86 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; 97 91 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); 104 93 float *Vout = (float *)buf[0].matrix.buffer; 105 94 106 95 /* 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); 108 97 109 98 // read each of the scanlines 110 for (int iy = 0; iy < cinfo.output_height; iy++) {99 for (int iy = 0; iy < Ny; iy++) { 111 100 jpeg_read_scanlines(&cinfo, buffer, 1); 112 101 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 ++) { 115 104 unsigned char Rpix = buffer[0][3*ix + 0]; 116 105 unsigned char Gpix = buffer[0][3*ix + 1]; 117 106 unsigned char Bpix = buffer[0][3*ix + 2]; 118 107 float value = Rpix + Gpix + Bpix; 119 Vout[ cinfo.output_width*iy + ix] = value;108 Vout[Nx*iy + ix] = value; 120 109 } 121 110 } … … 126 115 fclose (f); 127 116 128 /*129 if (!status) {130 gprint (GP_ERR, "problem reading file, buffer not opened\n");131 DeleteBuffer (buf);132 return (FALSE);133 }134 */135 136 117 buf[0].bitpix = buf[0].header.bitpix; /* store the original values */ 137 118 buf[0].bscale = buf[0].header.bscale; /* store the original values */ … … 141 122 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]); 142 123 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 148 124 return (TRUE); 149 125 } 150 151 # if (0)152 // XXX not sure about error handling here153 // 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 # endif166
Note:
See TracChangeset
for help on using the changeset viewer.
