Blame gtkmm-osx/jpeg-6b/jcomapi.c

darco 56a656
/*
darco 56a656
 * jcomapi.c
darco 56a656
 *
darco 56a656
 * Copyright (C) 1994-1997, Thomas G. Lane.
darco 56a656
 * This file is part of the Independent JPEG Group's software.
darco 56a656
 * For conditions of distribution and use, see the accompanying README file.
darco 56a656
 *
darco 56a656
 * This file contains application interface routines that are used for both
darco 56a656
 * compression and decompression.
darco 56a656
 */
darco 56a656
darco 56a656
#define JPEG_INTERNALS
darco 56a656
#include "jinclude.h"
darco 56a656
#include "jpeglib.h"
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Abort processing of a JPEG compression or decompression operation,
darco 56a656
 * but don't destroy the object itself.
darco 56a656
 *
darco 56a656
 * For this, we merely clean up all the nonpermanent memory pools.
darco 56a656
 * Note that temp files (virtual arrays) are not allowed to belong to
darco 56a656
 * the permanent pool, so we will be able to close all temp files here.
darco 56a656
 * Closing a data source or destination, if necessary, is the application's
darco 56a656
 * responsibility.
darco 56a656
 */
darco 56a656
darco 56a656
GLOBAL(void)
darco 56a656
jpeg_abort (j_common_ptr cinfo)
darco 56a656
{
darco 56a656
  int pool;
darco 56a656
darco 56a656
  /* Do nothing if called on a not-initialized or destroyed JPEG object. */
darco 56a656
  if (cinfo->mem == NULL)
darco 56a656
    return;
darco 56a656
darco 56a656
  /* Releasing pools in reverse order might help avoid fragmentation
darco 56a656
   * with some (brain-damaged) malloc libraries.
darco 56a656
   */
darco 56a656
  for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
darco 56a656
    (*cinfo->mem->free_pool) (cinfo, pool);
darco 56a656
  }
darco 56a656
darco 56a656
  /* Reset overall state for possible reuse of object */
darco 56a656
  if (cinfo->is_decompressor) {
darco 56a656
    cinfo->global_state = DSTATE_START;
darco 56a656
    /* Try to keep application from accessing now-deleted marker list.
darco 56a656
     * A bit kludgy to do it here, but this is the most central place.
darco 56a656
     */
darco 56a656
    ((j_decompress_ptr) cinfo)->marker_list = NULL;
darco 56a656
  } else {
darco 56a656
    cinfo->global_state = CSTATE_START;
darco 56a656
  }
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Destruction of a JPEG object.
darco 56a656
 *
darco 56a656
 * Everything gets deallocated except the master jpeg_compress_struct itself
darco 56a656
 * and the error manager struct.  Both of these are supplied by the application
darco 56a656
 * and must be freed, if necessary, by the application.  (Often they are on
darco 56a656
 * the stack and so don't need to be freed anyway.)
darco 56a656
 * Closing a data source or destination, if necessary, is the application's
darco 56a656
 * responsibility.
darco 56a656
 */
darco 56a656
darco 56a656
GLOBAL(void)
darco 56a656
jpeg_destroy (j_common_ptr cinfo)
darco 56a656
{
darco 56a656
  /* We need only tell the memory manager to release everything. */
darco 56a656
  /* NB: mem pointer is NULL if memory mgr failed to initialize. */
darco 56a656
  if (cinfo->mem != NULL)
darco 56a656
    (*cinfo->mem->self_destruct) (cinfo);
darco 56a656
  cinfo->mem = NULL;		/* be safe if jpeg_destroy is called twice */
darco 56a656
  cinfo->global_state = 0;	/* mark it destroyed */
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
/*
darco 56a656
 * Convenience routines for allocating quantization and Huffman tables.
darco 56a656
 * (Would jutils.c be a more reasonable place to put these?)
darco 56a656
 */
darco 56a656
darco 56a656
GLOBAL(JQUANT_TBL *)
darco 56a656
jpeg_alloc_quant_table (j_common_ptr cinfo)
darco 56a656
{
darco 56a656
  JQUANT_TBL *tbl;
darco 56a656
darco 56a656
  tbl = (JQUANT_TBL *)
darco 56a656
    (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
darco 56a656
  tbl->sent_table = FALSE;	/* make sure this is false in any new table */
darco 56a656
  return tbl;
darco 56a656
}
darco 56a656
darco 56a656
darco 56a656
GLOBAL(JHUFF_TBL *)
darco 56a656
jpeg_alloc_huff_table (j_common_ptr cinfo)
darco 56a656
{
darco 56a656
  JHUFF_TBL *tbl;
darco 56a656
darco 56a656
  tbl = (JHUFF_TBL *)
darco 56a656
    (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
darco 56a656
  tbl->sent_table = FALSE;	/* make sure this is false in any new table */
darco 56a656
  return tbl;
darco 56a656
}