istereo2

annotate libs/libjpeg/jcomapi.c @ 7:a3c4fcc9f8f3

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