dbf-halloween2015

annotate libs/libjpeg/jcomapi.c @ 1:c3f5c32cb210

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