Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

jcapimin.c

Go to the documentation of this file.
00001 /*
00002  * jcapimin.c
00003  *
00004  * Copyright (C) 1994-1995, Thomas G. Lane.
00005  * This file is part of the Independent JPEG Group's software.
00006  * For conditions of distribution and use, see the accompanying README file.
00007  *
00008  * This file contains application interface code for the compression half
00009  * of the JPEG library.  These are the "minimum" API routines that may be
00010  * needed in either the normal full-compression case or the transcoding-only
00011  * case.
00012  *
00013  * Most of the routines intended to be called directly by an application
00014  * are in this file or in jcapistd.c.  But also see jcparam.c for
00015  * parameter-setup helper routines, jcomapi.c for routines shared by
00016  * compression and decompression, and jctrans.c for the transcoding case.
00017  */
00018 
00019 #define JPEG_INTERNALS
00020 #include "jinclude.h"
00021 #include "jpeglib.h"
00022 
00023 
00024 /*
00025  * Initialization of a JPEG compression object.
00026  * The error manager must already be set up (in case memory manager fails).
00027  */
00028 
00029 GLOBAL void
00030 jpeg_create_compress (j_compress_ptr cinfo)
00031 {
00032   int i;
00033 
00034   /* For debugging purposes, zero the whole master structure.
00035    * But error manager pointer is already there, so save and restore it.
00036    */
00037   {
00038     struct jpeg_error_mgr * err = cinfo->err;
00039     MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
00040     cinfo->err = err;
00041   }
00042   cinfo->is_decompressor = FALSE;
00043 
00044   /* Initialize a memory manager instance for this object */
00045   jinit_memory_mgr((j_common_ptr) cinfo);
00046 
00047   /* Zero out pointers to permanent structures. */
00048   cinfo->progress = NULL;
00049   cinfo->dest = NULL;
00050 
00051   cinfo->comp_info = NULL;
00052 
00053   for (i = 0; i < NUM_QUANT_TBLS; i++)
00054     cinfo->quant_tbl_ptrs[i] = NULL;
00055 
00056   for (i = 0; i < NUM_HUFF_TBLS; i++) {
00057     cinfo->dc_huff_tbl_ptrs[i] = NULL;
00058     cinfo->ac_huff_tbl_ptrs[i] = NULL;
00059   }
00060 
00061   cinfo->input_gamma = 1.0; /* in case application forgets */
00062 
00063   /* OK, I'm ready */
00064   cinfo->global_state = CSTATE_START;
00065 }
00066 
00067 
00068 /*
00069  * Destruction of a JPEG compression object
00070  */
00071 
00072 GLOBAL void
00073 jpeg_destroy_compress (j_compress_ptr cinfo)
00074 {
00075   jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
00076 }
00077 
00078 
00079 /*
00080  * Abort processing of a JPEG compression operation,
00081  * but don't destroy the object itself.
00082  */
00083 
00084 GLOBAL void
00085 jpeg_abort_compress (j_compress_ptr cinfo)
00086 {
00087   jpeg_abort((j_common_ptr) cinfo); /* use common routine */
00088 }
00089 
00090 
00091 /*
00092  * Forcibly suppress or un-suppress all quantization and Huffman tables.
00093  * Marks all currently defined tables as already written (if suppress)
00094  * or not written (if !suppress).  This will control whether they get emitted
00095  * by a subsequent jpeg_start_compress call.
00096  *
00097  * This routine is exported for use by applications that want to produce
00098  * abbreviated JPEG datastreams.  It logically belongs in jcparam.c, but
00099  * since it is called by jpeg_start_compress, we put it here --- otherwise
00100  * jcparam.o would be linked whether the application used it or not.
00101  */
00102 
00103 GLOBAL void
00104 jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
00105 {
00106   int i;
00107   JQUANT_TBL * qtbl;
00108   JHUFF_TBL * htbl;
00109 
00110   for (i = 0; i < NUM_QUANT_TBLS; i++) {
00111     if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
00112       qtbl->sent_table = suppress;
00113   }
00114 
00115   for (i = 0; i < NUM_HUFF_TBLS; i++) {
00116     if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
00117       htbl->sent_table = suppress;
00118     if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
00119       htbl->sent_table = suppress;
00120   }
00121 }
00122 
00123 
00124 /*
00125  * Finish JPEG compression.
00126  *
00127  * If a multipass operating mode was selected, this may do a great deal of
00128  * work including most of the actual output.
00129  */
00130 
00131 GLOBAL void
00132 jpeg_finish_compress (j_compress_ptr cinfo)
00133 {
00134   JDIMENSION iMCU_row;
00135 
00136   if (cinfo->global_state == CSTATE_SCANNING ||
00137       cinfo->global_state == CSTATE_RAW_OK) {
00138     /* Terminate first pass */
00139     if (cinfo->next_scanline < cinfo->image_height)
00140       ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
00141     (*cinfo->master->finish_pass) (cinfo);
00142   } else if (cinfo->global_state != CSTATE_WRCOEFS)
00143     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00144   /* Perform any remaining passes */
00145   while (! cinfo->master->is_last_pass) {
00146     (*cinfo->master->prepare_for_pass) (cinfo);
00147     for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
00148       if (cinfo->progress != NULL) {
00149     cinfo->progress->pass_counter = (long) iMCU_row;
00150     cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
00151     (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
00152       }
00153       /* We bypass the main controller and invoke coef controller directly;
00154        * all work is being done from the coefficient buffer.
00155        */
00156       if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
00157     ERREXIT(cinfo, JERR_CANT_SUSPEND);
00158     }
00159     (*cinfo->master->finish_pass) (cinfo);
00160   }
00161   /* Write EOI, do final cleanup */
00162   (*cinfo->marker->write_file_trailer) (cinfo);
00163   (*cinfo->dest->term_destination) (cinfo);
00164   /* We can use jpeg_abort to release memory and reset global_state */
00165   jpeg_abort((j_common_ptr) cinfo);
00166 }
00167 
00168 
00169 /*
00170  * Write a special marker.
00171  * This is only recommended for writing COM or APPn markers.
00172  * Must be called after jpeg_start_compress() and before
00173  * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
00174  */
00175 
00176 GLOBAL void
00177 jpeg_write_marker (j_compress_ptr cinfo, int marker,
00178            const JOCTET *dataptr, unsigned int datalen)
00179 {
00180   if (cinfo->next_scanline != 0 ||
00181       (cinfo->global_state != CSTATE_SCANNING &&
00182        cinfo->global_state != CSTATE_RAW_OK &&
00183        cinfo->global_state != CSTATE_WRCOEFS))
00184     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00185 
00186   (*cinfo->marker->write_any_marker) (cinfo, marker, dataptr, datalen);
00187 }
00188 
00189 
00190 /*
00191  * Alternate compression function: just write an abbreviated table file.
00192  * Before calling this, all parameters and a data destination must be set up.
00193  *
00194  * To produce a pair of files containing abbreviated tables and abbreviated
00195  * image data, one would proceed as follows:
00196  *
00197  *      initialize JPEG object
00198  *      set JPEG parameters
00199  *      set destination to table file
00200  *      jpeg_write_tables(cinfo);
00201  *      set destination to image file
00202  *      jpeg_start_compress(cinfo, FALSE);
00203  *      write data...
00204  *      jpeg_finish_compress(cinfo);
00205  *
00206  * jpeg_write_tables has the side effect of marking all tables written
00207  * (same as jpeg_suppress_tables(..., TRUE)).  Thus a subsequent start_compress
00208  * will not re-emit the tables unless it is passed write_all_tables=TRUE.
00209  */
00210 
00211 GLOBAL void
00212 jpeg_write_tables (j_compress_ptr cinfo)
00213 {
00214   if (cinfo->global_state != CSTATE_START)
00215     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
00216 
00217   /* (Re)initialize error mgr and destination modules */
00218   (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
00219   (*cinfo->dest->init_destination) (cinfo);
00220   /* Initialize the marker writer ... bit of a crock to do it here. */
00221   jinit_marker_writer(cinfo);
00222   /* Write them tables! */
00223   (*cinfo->marker->write_tables_only) (cinfo);
00224   /* And clean up. */
00225   (*cinfo->dest->term_destination) (cinfo);
00226   /* We can use jpeg_abort to release memory. */
00227   jpeg_abort((j_common_ptr) cinfo);
00228 }

Generated on Thu Aug 25 12:37:34 2005 for Quake III Arena by  doxygen 1.3.9.1