Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

jdapimin.c File Reference

#include "jinclude.h"
#include "jpeglib.h"

Go to the source code of this file.


Defines

#define JPEG_INTERNALS

Functions

 jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
 jpeg_destroy_decompress (j_decompress_ptr cinfo)
 jpeg_abort_decompress (j_decompress_ptr cinfo)
 default_decompress_parms (j_decompress_ptr cinfo)
 jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
 jpeg_consume_input (j_decompress_ptr cinfo)
 jpeg_input_complete (j_decompress_ptr cinfo)
 jpeg_has_multiple_scans (j_decompress_ptr cinfo)
 jpeg_finish_decompress (j_decompress_ptr cinfo)

Define Documentation

#define JPEG_INTERNALS
 

Definition at line 19 of file jdapimin.c.


Function Documentation

default_decompress_parms j_decompress_ptr    cinfo
 

Definition at line 114 of file jdapimin.c.

References jpeg_decompress_struct::Adobe_transform, jpeg_decompress_struct::buffered_image, jpeg_decompress_struct::colormap, jpeg_decompress_struct::comp_info, jpeg_component_info::component_id, jpeg_decompress_struct::dct_method, jpeg_decompress_struct::desired_number_of_colors, jpeg_decompress_struct::dither_mode, jpeg_decompress_struct::do_block_smoothing, jpeg_decompress_struct::do_fancy_upsampling, jpeg_decompress_struct::enable_1pass_quant, jpeg_decompress_struct::enable_2pass_quant, jpeg_decompress_struct::enable_external_quant, JCS_CMYK, JCS_GRAYSCALE, JCS_RGB, JCS_UNKNOWN, JCS_YCbCr, JCS_YCCK, JDCT_DEFAULT, JDITHER_FS, jpeg_decompress_struct::jpeg_color_space, JTRC_UNKNOWN_IDS, jpeg_decompress_struct::num_components, jpeg_decompress_struct::out_color_space, jpeg_decompress_struct::output_gamma, jpeg_decompress_struct::quantize_colors, jpeg_decompress_struct::raw_data_out, jpeg_decompress_struct::saw_Adobe_marker, jpeg_decompress_struct::saw_JFIF_marker, jpeg_decompress_struct::scale_denom, jpeg_decompress_struct::scale_num, TRACEMS3, jpeg_decompress_struct::two_pass_quantize, and WARNMS1.

Referenced by jpeg_consume_input().

00115 {
00116   /* Guess the input colorspace, and set output colorspace accordingly. */
00117   /* (Wish JPEG committee had provided a real way to specify this...) */
00118   /* Note application may override our guesses. */
00119   switch (cinfo->num_components) {
00120   case 1:
00121     cinfo->jpeg_color_space = JCS_GRAYSCALE;
00122     cinfo->out_color_space = JCS_GRAYSCALE;
00123     break;
00124     
00125   case 3:
00126     if (cinfo->saw_JFIF_marker) {
00127       cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
00128     } else if (cinfo->saw_Adobe_marker) {
00129       switch (cinfo->Adobe_transform) {
00130       case 0:
00131         cinfo->jpeg_color_space = JCS_RGB;
00132         break;
00133       case 1:
00134         cinfo->jpeg_color_space = JCS_YCbCr;
00135         break;
00136       default:
00137         WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
00138         cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
00139         break;
00140       }
00141     } else {
00142       /* Saw no special markers, try to guess from the component IDs */
00143       int cid0 = cinfo->comp_info[0].component_id;
00144       int cid1 = cinfo->comp_info[1].component_id;
00145       int cid2 = cinfo->comp_info[2].component_id;
00146 
00147       if (cid0 == 1 && cid1 == 2 && cid2 == 3)
00148         cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
00149       else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
00150         cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
00151       else {
00152         TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
00153         cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
00154       }
00155     }
00156     /* Always guess RGB is proper output colorspace. */
00157     cinfo->out_color_space = JCS_RGB;
00158     break;
00159     
00160   case 4:
00161     if (cinfo->saw_Adobe_marker) {
00162       switch (cinfo->Adobe_transform) {
00163       case 0:
00164         cinfo->jpeg_color_space = JCS_CMYK;
00165         break;
00166       case 2:
00167         cinfo->jpeg_color_space = JCS_YCCK;
00168         break;
00169       default:
00170         WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
00171         cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
00172         break;
00173       }
00174     } else {
00175       /* No special markers, assume straight CMYK. */
00176       cinfo->jpeg_color_space = JCS_CMYK;
00177     }
00178     cinfo->out_color_space = JCS_CMYK;
00179     break;
00180     
00181   default:
00182     cinfo->jpeg_color_space = JCS_UNKNOWN;
00183     cinfo->out_color_space = JCS_UNKNOWN;
00184     break;
00185   }
00186 
00187   /* Set defaults for other decompression parameters. */
00188   cinfo->scale_num = 1;         /* 1:1 scaling */
00189   cinfo->scale_denom = 1;
00190   cinfo->output_gamma = 1.0;
00191   cinfo->buffered_image = FALSE;
00192   cinfo->raw_data_out = FALSE;
00193   cinfo->dct_method = JDCT_DEFAULT;
00194   cinfo->do_fancy_upsampling = TRUE;
00195   cinfo->do_block_smoothing = TRUE;
00196   cinfo->quantize_colors = FALSE;
00197   /* We set these in case application only sets quantize_colors. */
00198   cinfo->dither_mode = JDITHER_FS;
00199 #ifdef QUANT_2PASS_SUPPORTED
00200   cinfo->two_pass_quantize = TRUE;
00201 #else
00202   cinfo->two_pass_quantize = FALSE;
00203 #endif
00204   cinfo->desired_number_of_colors = 256;
00205   cinfo->colormap = NULL;
00206   /* Initialize for no mode change in buffered-image mode. */
00207   cinfo->enable_1pass_quant = FALSE;
00208   cinfo->enable_external_quant = FALSE;
00209   cinfo->enable_2pass_quant = FALSE;
00210 }

jpeg_abort_decompress j_decompress_ptr    cinfo
 

Definition at line 103 of file jdapimin.c.

References jpeg_abort().

00104 {
00105   jpeg_abort((j_common_ptr) cinfo); /* use common routine */
00106 }

jpeg_consume_input j_decompress_ptr    cinfo
 

Definition at line 287 of file jdapimin.c.

References default_decompress_parms(), DSTATE_BUFIMAGE, DSTATE_BUFPOST, DSTATE_INHEADER, DSTATE_PRELOAD, DSTATE_PRESCAN, DSTATE_RAW_OK, DSTATE_READY, DSTATE_SCANNING, DSTATE_START, DSTATE_STOPPING, ERREXIT1, jpeg_decompress_struct::inputctl, JPEG_REACHED_SOS, JPEG_SUSPENDED, retcode, and jpeg_decompress_struct::src.

Referenced by jpeg_read_header().

00288 {
00289   int retcode = JPEG_SUSPENDED;
00290 
00291   /* NB: every possible DSTATE value should be listed in this switch */
00292   switch (cinfo->global_state) {
00293   case DSTATE_START:
00294     /* Start-of-datastream actions: reset appropriate modules */
00295     (*cinfo->inputctl->reset_input_controller) (cinfo);
00296     /* Initialize application's data source module */
00297     (*cinfo->src->init_source) (cinfo);
00298     cinfo->global_state = DSTATE_INHEADER;
00299     /*FALLTHROUGH*/
00300   case DSTATE_INHEADER:
00301     retcode = (*cinfo->inputctl->consume_input) (cinfo);
00302     if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
00303       /* Set up default parameters based on header data */
00304       default_decompress_parms(cinfo);
00305       /* Set global state: ready for start_decompress */
00306       cinfo->global_state = DSTATE_READY;
00307     }
00308     break;
00309   case DSTATE_READY:
00310     /* Can't advance past first SOS until start_decompress is called */
00311     retcode = JPEG_REACHED_SOS;
00312     break;
00313   case DSTATE_PRELOAD:
00314   case DSTATE_PRESCAN:
00315   case DSTATE_SCANNING:
00316   case DSTATE_RAW_OK:
00317   case DSTATE_BUFIMAGE:
00318   case DSTATE_BUFPOST:
00319   case DSTATE_STOPPING:
00320     retcode = (*cinfo->inputctl->consume_input) (cinfo);
00321     break;
00322   default:
00323     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00324   }
00325   return retcode;
00326 }

jpeg_CreateDecompress j_decompress_ptr    cinfo,
int    version,
size_t    structsize
 

Definition at line 30 of file jdapimin.c.

References jpeg_decompress_struct::ac_huff_tbl_ptrs, client_data, jpeg_decompress_struct::dc_huff_tbl_ptrs, DSTATE_START, ERREXIT2, i, JERR_BAD_LIB_VERSION, jinit_input_controller(), jinit_marker_reader(), jinit_memory_mgr(), JPEG_LIB_VERSION, jpeg_decompress_struct::marker_list, MEMZERO, NUM_HUFF_TBLS, NUM_QUANT_TBLS, jpeg_decompress_struct::quant_tbl_ptrs, SIZEOF, jpeg_decompress_struct::src, and structsize.

00031 {
00032   int i;
00033 
00034   /* Guard against version mismatches between library and caller. */
00035   cinfo->mem = NULL;            /* so jpeg_destroy knows mem mgr not called */
00036   if (version != JPEG_LIB_VERSION)
00037     ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
00038   if (structsize != SIZEOF(struct jpeg_decompress_struct))
00039     ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 
00040              (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
00041 
00042   /* For debugging purposes, we zero the whole master structure.
00043    * But the application has already set the err pointer, and may have set
00044    * client_data, so we have to save and restore those fields.
00045    * Note: if application hasn't set client_data, tools like Purify may
00046    * complain here.
00047    */
00048   {
00049     struct jpeg_error_mgr * err = cinfo->err;
00050     void * client_data = cinfo->client_data; /* ignore Purify complaint here */
00051     MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
00052     cinfo->err = err;
00053     cinfo->client_data = client_data;
00054   }
00055   cinfo->is_decompressor = TRUE;
00056 
00057   /* Initialize a memory manager instance for this object */
00058   jinit_memory_mgr((j_common_ptr) cinfo);
00059 
00060   /* Zero out pointers to permanent structures. */
00061   cinfo->progress = NULL;
00062   cinfo->src = NULL;
00063 
00064   for (i = 0; i < NUM_QUANT_TBLS; i++)
00065     cinfo->quant_tbl_ptrs[i] = NULL;
00066 
00067   for (i = 0; i < NUM_HUFF_TBLS; i++) {
00068     cinfo->dc_huff_tbl_ptrs[i] = NULL;
00069     cinfo->ac_huff_tbl_ptrs[i] = NULL;
00070   }
00071 
00072   /* Initialize marker processor so application can override methods
00073    * for COM, APPn markers before calling jpeg_read_header.
00074    */
00075   cinfo->marker_list = NULL;
00076   jinit_marker_reader(cinfo);
00077 
00078   /* And initialize the overall input controller. */
00079   jinit_input_controller(cinfo);
00080 
00081   /* OK, I'm ready */
00082   cinfo->global_state = DSTATE_START;
00083 }

jpeg_destroy_decompress j_decompress_ptr    cinfo
 

Definition at line 91 of file jdapimin.c.

References jpeg_destroy().

Referenced by main(), and read_JPEG_file().

00092 {
00093   jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
00094 }

jpeg_finish_decompress j_decompress_ptr    cinfo
 

Definition at line 369 of file jdapimin.c.

References jpeg_decompress_struct::buffered_image, DSTATE_BUFIMAGE, DSTATE_RAW_OK, DSTATE_SCANNING, DSTATE_STOPPING, jpeg_input_controller::eoi_reached, ERREXIT, ERREXIT1, jpeg_decompress_struct::inputctl, jpeg_abort(), JPEG_SUSPENDED, jpeg_decompress_struct::master, jpeg_decompress_struct::output_height, jpeg_decompress_struct::output_scanline, and jpeg_decompress_struct::src.

Referenced by main(), and read_JPEG_file().

00370 {
00371   if ((cinfo->global_state == DSTATE_SCANNING ||
00372        cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
00373     /* Terminate final pass of non-buffered mode */
00374     if (cinfo->output_scanline < cinfo->output_height)
00375       ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
00376     (*cinfo->master->finish_output_pass) (cinfo);
00377     cinfo->global_state = DSTATE_STOPPING;
00378   } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
00379     /* Finishing after a buffered-image operation */
00380     cinfo->global_state = DSTATE_STOPPING;
00381   } else if (cinfo->global_state != DSTATE_STOPPING) {
00382     /* STOPPING = repeat call after a suspension, anything else is error */
00383     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00384   }
00385   /* Read until EOI */
00386   while (! cinfo->inputctl->eoi_reached) {
00387     if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
00388       return FALSE;             /* Suspend, come back later */
00389   }
00390   /* Do final cleanup */
00391   (*cinfo->src->term_source) (cinfo);
00392   /* We can use jpeg_abort to release memory and reset global_state */
00393   jpeg_abort((j_common_ptr) cinfo);
00394   return TRUE;
00395 }

jpeg_has_multiple_scans j_decompress_ptr    cinfo
 

Definition at line 349 of file jdapimin.c.

References DSTATE_READY, DSTATE_STOPPING, ERREXIT1, jpeg_input_controller::has_multiple_scans, and jpeg_decompress_struct::inputctl.

00350 {
00351   /* Only valid after jpeg_read_header completes */
00352   if (cinfo->global_state < DSTATE_READY ||
00353       cinfo->global_state > DSTATE_STOPPING)
00354     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00355   return cinfo->inputctl->has_multiple_scans;
00356 }

jpeg_input_complete j_decompress_ptr    cinfo
 

Definition at line 334 of file jdapimin.c.

References DSTATE_START, DSTATE_STOPPING, jpeg_input_controller::eoi_reached, ERREXIT1, and jpeg_decompress_struct::inputctl.

00335 {
00336   /* Check for valid jpeg object */
00337   if (cinfo->global_state < DSTATE_START ||
00338       cinfo->global_state > DSTATE_STOPPING)
00339     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00340   return cinfo->inputctl->eoi_reached;
00341 }

jpeg_read_header j_decompress_ptr    cinfo,
boolean    require_image
 

Definition at line 241 of file jdapimin.c.

References DSTATE_INHEADER, DSTATE_START, ERREXIT, ERREXIT1, jpeg_abort(), jpeg_consume_input(), JPEG_HEADER_OK, JPEG_HEADER_TABLES_ONLY, JPEG_REACHED_EOI, JPEG_REACHED_SOS, JPEG_SUSPENDED, require_image, and retcode.

Referenced by main(), and read_JPEG_file().

00242 {
00243   int retcode;
00244 
00245   if (cinfo->global_state != DSTATE_START &&
00246       cinfo->global_state != DSTATE_INHEADER)
00247     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00248 
00249   retcode = jpeg_consume_input(cinfo);
00250 
00251   switch (retcode) {
00252   case JPEG_REACHED_SOS:
00253     retcode = JPEG_HEADER_OK;
00254     break;
00255   case JPEG_REACHED_EOI:
00256     if (require_image)          /* Complain if application wanted an image */
00257       ERREXIT(cinfo, JERR_NO_IMAGE);
00258     /* Reset to start state; it would be safer to require the application to
00259      * call jpeg_abort, but we can't change it now for compatibility reasons.
00260      * A side effect is to free any temporary memory (there shouldn't be any).
00261      */
00262     jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
00263     retcode = JPEG_HEADER_TABLES_ONLY;
00264     break;
00265   case JPEG_SUSPENDED:
00266     /* no work */
00267     break;
00268   }
00269 
00270   return retcode;
00271 }
 

Powered by Plone

This site conforms to the following standards: