media/libjpeg/jcomapi.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial