istereo

annotate libs/libjpeg/jcomapi.c @ 39:ff055bff6a15

copyright statements and stuff
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sun, 11 Sep 2011 09:03:18 +0300
parents
children
rev   line source
nuclear@26 1 /*
nuclear@26 2 * jcomapi.c
nuclear@26 3 *
nuclear@26 4 * Copyright (C) 1994-1997, Thomas G. Lane.
nuclear@26 5 * This file is part of the Independent JPEG Group's software.
nuclear@26 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@26 7 *
nuclear@26 8 * This file contains application interface routines that are used for both
nuclear@26 9 * compression and decompression.
nuclear@26 10 */
nuclear@26 11
nuclear@26 12 #define JPEG_INTERNALS
nuclear@26 13 #include "jinclude.h"
nuclear@26 14 #include "jpeglib.h"
nuclear@26 15
nuclear@26 16
nuclear@26 17 /*
nuclear@26 18 * Abort processing of a JPEG compression or decompression operation,
nuclear@26 19 * but don't destroy the object itself.
nuclear@26 20 *
nuclear@26 21 * For this, we merely clean up all the nonpermanent memory pools.
nuclear@26 22 * Note that temp files (virtual arrays) are not allowed to belong to
nuclear@26 23 * the permanent pool, so we will be able to close all temp files here.
nuclear@26 24 * Closing a data source or destination, if necessary, is the application's
nuclear@26 25 * responsibility.
nuclear@26 26 */
nuclear@26 27
nuclear@26 28 GLOBAL(void)
nuclear@26 29 jpeg_abort (j_common_ptr cinfo)
nuclear@26 30 {
nuclear@26 31 int pool;
nuclear@26 32
nuclear@26 33 /* Do nothing if called on a not-initialized or destroyed JPEG object. */
nuclear@26 34 if (cinfo->mem == NULL)
nuclear@26 35 return;
nuclear@26 36
nuclear@26 37 /* Releasing pools in reverse order might help avoid fragmentation
nuclear@26 38 * with some (brain-damaged) malloc libraries.
nuclear@26 39 */
nuclear@26 40 for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
nuclear@26 41 (*cinfo->mem->free_pool) (cinfo, pool);
nuclear@26 42 }
nuclear@26 43
nuclear@26 44 /* Reset overall state for possible reuse of object */
nuclear@26 45 if (cinfo->is_decompressor) {
nuclear@26 46 cinfo->global_state = DSTATE_START;
nuclear@26 47 /* Try to keep application from accessing now-deleted marker list.
nuclear@26 48 * A bit kludgy to do it here, but this is the most central place.
nuclear@26 49 */
nuclear@26 50 ((j_decompress_ptr) cinfo)->marker_list = NULL;
nuclear@26 51 } else {
nuclear@26 52 cinfo->global_state = CSTATE_START;
nuclear@26 53 }
nuclear@26 54 }
nuclear@26 55
nuclear@26 56
nuclear@26 57 /*
nuclear@26 58 * Destruction of a JPEG object.
nuclear@26 59 *
nuclear@26 60 * Everything gets deallocated except the master jpeg_compress_struct itself
nuclear@26 61 * and the error manager struct. Both of these are supplied by the application
nuclear@26 62 * and must be freed, if necessary, by the application. (Often they are on
nuclear@26 63 * the stack and so don't need to be freed anyway.)
nuclear@26 64 * Closing a data source or destination, if necessary, is the application's
nuclear@26 65 * responsibility.
nuclear@26 66 */
nuclear@26 67
nuclear@26 68 GLOBAL(void)
nuclear@26 69 jpeg_destroy (j_common_ptr cinfo)
nuclear@26 70 {
nuclear@26 71 /* We need only tell the memory manager to release everything. */
nuclear@26 72 /* NB: mem pointer is NULL if memory mgr failed to initialize. */
nuclear@26 73 if (cinfo->mem != NULL)
nuclear@26 74 (*cinfo->mem->self_destruct) (cinfo);
nuclear@26 75 cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
nuclear@26 76 cinfo->global_state = 0; /* mark it destroyed */
nuclear@26 77 }
nuclear@26 78
nuclear@26 79
nuclear@26 80 /*
nuclear@26 81 * Convenience routines for allocating quantization and Huffman tables.
nuclear@26 82 * (Would jutils.c be a more reasonable place to put these?)
nuclear@26 83 */
nuclear@26 84
nuclear@26 85 GLOBAL(JQUANT_TBL *)
nuclear@26 86 jpeg_alloc_quant_table (j_common_ptr cinfo)
nuclear@26 87 {
nuclear@26 88 JQUANT_TBL *tbl;
nuclear@26 89
nuclear@26 90 tbl = (JQUANT_TBL *)
nuclear@26 91 (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
nuclear@26 92 tbl->sent_table = FALSE; /* make sure this is false in any new table */
nuclear@26 93 return tbl;
nuclear@26 94 }
nuclear@26 95
nuclear@26 96
nuclear@26 97 GLOBAL(JHUFF_TBL *)
nuclear@26 98 jpeg_alloc_huff_table (j_common_ptr cinfo)
nuclear@26 99 {
nuclear@26 100 JHUFF_TBL *tbl;
nuclear@26 101
nuclear@26 102 tbl = (JHUFF_TBL *)
nuclear@26 103 (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
nuclear@26 104 tbl->sent_table = FALSE; /* make sure this is false in any new table */
nuclear@26 105 return tbl;
nuclear@26 106 }