home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / jpeg / jcapimin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.1 KB  |  230 lines

  1. /*
  2.  * jcapimin.c
  3.  *
  4.  * Copyright (C) 1994-1995, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains application interface code for the compression half
  9.  * of the JPEG library.  These are the "minimum" API routines that may be
  10.  * needed in either the normal full-compression case or the transcoding-only
  11.  * case.
  12.  *
  13.  * Most of the routines intended to be called directly by an application
  14.  * are in this file or in jcapistd.c.  But also see jcparam.c for
  15.  * parameter-setup helper routines, jcomapi.c for routines shared by
  16.  * compression and decompression, and jctrans.c for the transcoding case.
  17.  */
  18.  
  19. #define JPEG_INTERNALS
  20. #include "xp_core.h"/*defines of int32 ect*/
  21. #include "jinclude.h"
  22. #include "jpeglib.h"
  23.  
  24.  
  25. /*
  26.  * Initialization of a JPEG compression object.
  27.  * The error manager must already be set up (in case memory manager fails).
  28.  */
  29.  
  30. GLOBAL JRI_PUBLIC_API(void)
  31. jpeg_create_compress (j_compress_ptr cinfo)
  32. {
  33.   int16 i;
  34.  
  35.   /* For debugging purposes, zero the whole master structure.
  36.    * But error manager pointer is already there, so save and restore it.
  37.    */
  38.   {
  39.     struct jpeg_error_mgr * err = cinfo->err;
  40.     MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  41.     cinfo->err = err;
  42.   }
  43.   cinfo->is_decompressor = FALSE;
  44.  
  45.   /* Initialize a memory manager instance for this object */
  46.   jinit_memory_mgr((j_common_ptr) cinfo);
  47.  
  48.   /* Zero out pointers to permanent structures. */
  49.   cinfo->progress = NULL;
  50.   cinfo->dest = NULL;
  51.  
  52.   cinfo->comp_info = NULL;
  53.  
  54.   for (i = 0; i < NUM_QUANT_TBLS; i++)
  55.     cinfo->quant_tbl_ptrs[i] = NULL;
  56.  
  57.   for (i = 0; i < NUM_HUFF_TBLS; i++) {
  58.     cinfo->dc_huff_tbl_ptrs[i] = NULL;
  59.     cinfo->ac_huff_tbl_ptrs[i] = NULL;
  60.   }
  61.  
  62.   cinfo->input_gamma = 1.0;    /* in case application forgets */
  63.  
  64.   /* OK, I'm ready */
  65.   cinfo->global_state = CSTATE_START;
  66. }
  67.  
  68.  
  69. /*
  70.  * Destruction of a JPEG compression object
  71.  */
  72.  
  73. GLOBAL JRI_PUBLIC_API(void)
  74. jpeg_destroy_compress (j_compress_ptr cinfo)
  75. {
  76.   jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  77. }
  78.  
  79.  
  80. /*
  81.  * Abort processing of a JPEG compression operation,
  82.  * but don't destroy the object itself.
  83.  */
  84.  
  85. GLOBAL void
  86. jpeg_abort_compress (j_compress_ptr cinfo)
  87. {
  88.   jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  89. }
  90.  
  91.  
  92. /*
  93.  * Forcibly suppress or un-suppress all quantization and Huffman tables.
  94.  * Marks all currently defined tables as already written (if suppress)
  95.  * or not written (if !suppress).  This will control whether they get emitted
  96.  * by a subsequent jpeg_start_compress call.
  97.  *
  98.  * This routine is exported for use by applications that want to produce
  99.  * abbreviated JPEG datastreams.  It logically belongs in jcparam.c, but
  100.  * since it is called by jpeg_start_compress, we put it here --- otherwise
  101.  * jcparam.o would be linked whether the application used it or not.
  102.  */
  103.  
  104. GLOBAL void
  105. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  106. {
  107.   int16 i;
  108.   JQUANT_TBL * qtbl;
  109.   JHUFF_TBL * htbl;
  110.  
  111.   for (i = 0; i < NUM_QUANT_TBLS; i++) {
  112.     if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  113.       qtbl->sent_table = suppress;
  114.   }
  115.  
  116.   for (i = 0; i < NUM_HUFF_TBLS; i++) {
  117.     if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  118.       htbl->sent_table = suppress;
  119.     if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  120.       htbl->sent_table = suppress;
  121.   }
  122. }
  123.  
  124.  
  125. /*
  126.  * Finish JPEG compression.
  127.  *
  128.  * If a multipass operating mode was selected, this may do a great deal of
  129.  * work including most of the actual output.
  130.  */
  131.  
  132. GLOBAL JRI_PUBLIC_API(void)
  133. jpeg_finish_compress (j_compress_ptr cinfo)
  134. {
  135.   JDIMENSION iMCU_row;
  136.  
  137.   if (cinfo->global_state == CSTATE_SCANNING ||
  138.       cinfo->global_state == CSTATE_RAW_OK) {
  139.     /* Terminate first pass */
  140.     if (cinfo->next_scanline < cinfo->image_height)
  141.       ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  142.     (*cinfo->master->finish_pass) (cinfo);
  143.   } else if (cinfo->global_state != CSTATE_WRCOEFS)
  144.     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145.   /* Perform any remaining passes */
  146.   while (! cinfo->master->is_last_pass) {
  147.     (*cinfo->master->prepare_for_pass) (cinfo);
  148.     for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  149.       if (cinfo->progress != NULL) {
  150.     cinfo->progress->pass_counter = (int32) iMCU_row;
  151.     cinfo->progress->pass_limit = (int32) cinfo->total_iMCU_rows;
  152.     (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  153.       }
  154.       /* We bypass the main controller and invoke coef controller directly;
  155.        * all work is being done from the coefficient buffer.
  156.        */
  157.       if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  158.     ERREXIT(cinfo, JERR_CANT_SUSPEND);
  159.     }
  160.     (*cinfo->master->finish_pass) (cinfo);
  161.   }
  162.   /* Write EOI, do final cleanup */
  163.   (*cinfo->marker->write_file_trailer) (cinfo);
  164.   (*cinfo->dest->term_destination) (cinfo);
  165.   /* We can use jpeg_abort to release memory and reset global_state */
  166.   jpeg_abort((j_common_ptr) cinfo);
  167. }
  168.  
  169.  
  170. /*
  171.  * Write a special marker.
  172.  * This is only recommended for writing COM or APPn markers.
  173.  * Must be called after jpeg_start_compress() and before
  174.  * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
  175.  */
  176.  
  177. GLOBAL void
  178. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  179.            const JOCTET *dataptr, unsigned int datalen)
  180. {
  181.   if (cinfo->next_scanline != 0 ||
  182.       (cinfo->global_state != CSTATE_SCANNING &&
  183.        cinfo->global_state != CSTATE_RAW_OK &&
  184.        cinfo->global_state != CSTATE_WRCOEFS))
  185.     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  186.  
  187.   (*cinfo->marker->write_any_marker) (cinfo, marker, dataptr, datalen);
  188. }
  189.  
  190.  
  191. /*
  192.  * Alternate compression function: just write an abbreviated table file.
  193.  * Before calling this, all parameters and a data destination must be set up.
  194.  *
  195.  * To produce a pair of files containing abbreviated tables and abbreviated
  196.  * image data, one would proceed as follows:
  197.  *
  198.  *        initialize JPEG object
  199.  *        set JPEG parameters
  200.  *        set destination to table file
  201.  *        jpeg_write_tables(cinfo);
  202.  *        set destination to image file
  203.  *        jpeg_start_compress(cinfo, FALSE);
  204.  *        write data...
  205.  *        jpeg_finish_compress(cinfo);
  206.  *
  207.  * jpeg_write_tables has the side effect of marking all tables written
  208.  * (same as jpeg_suppress_tables(..., TRUE)).  Thus a subsequent start_compress
  209.  * will not re-emit the tables unless it is passed write_all_tables=TRUE.
  210.  */
  211.  
  212. GLOBAL void
  213. jpeg_write_tables (j_compress_ptr cinfo)
  214. {
  215.   if (cinfo->global_state != CSTATE_START)
  216.     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  217.  
  218.   /* (Re)initialize error mgr and destination modules */
  219.   (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  220.   (*cinfo->dest->init_destination) (cinfo);
  221.   /* Initialize the marker writer ... bit of a crock to do it here. */
  222.   jinit_marker_writer(cinfo);
  223.   /* Write them tables! */
  224.   (*cinfo->marker->write_tables_only) (cinfo);
  225.   /* And clean up. */
  226.   (*cinfo->dest->term_destination) (cinfo);
  227.   /* We can use jpeg_abort to release memory. */
  228.   jpeg_abort((j_common_ptr) cinfo);
  229. }
  230.