3dphotoshoot
diff libs/libjpeg/jcomapi.c @ 14:06dc8b9b4f89
added libimago, libjpeg and libpng
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 07 Jun 2015 17:25:49 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/libjpeg/jcomapi.c Sun Jun 07 17:25:49 2015 +0300 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * jcomapi.c 1.6 + * 1.7 + * Copyright (C) 1994-1997, Thomas G. Lane. 1.8 + * This file is part of the Independent JPEG Group's software. 1.9 + * For conditions of distribution and use, see the accompanying README file. 1.10 + * 1.11 + * This file contains application interface routines that are used for both 1.12 + * compression and decompression. 1.13 + */ 1.14 + 1.15 +#define JPEG_INTERNALS 1.16 +#include "jinclude.h" 1.17 +#include "jpeglib.h" 1.18 + 1.19 + 1.20 +/* 1.21 + * Abort processing of a JPEG compression or decompression operation, 1.22 + * but don't destroy the object itself. 1.23 + * 1.24 + * For this, we merely clean up all the nonpermanent memory pools. 1.25 + * Note that temp files (virtual arrays) are not allowed to belong to 1.26 + * the permanent pool, so we will be able to close all temp files here. 1.27 + * Closing a data source or destination, if necessary, is the application's 1.28 + * responsibility. 1.29 + */ 1.30 + 1.31 +GLOBAL(void) 1.32 +jpeg_abort (j_common_ptr cinfo) 1.33 +{ 1.34 + int pool; 1.35 + 1.36 + /* Do nothing if called on a not-initialized or destroyed JPEG object. */ 1.37 + if (cinfo->mem == NULL) 1.38 + return; 1.39 + 1.40 + /* Releasing pools in reverse order might help avoid fragmentation 1.41 + * with some (brain-damaged) malloc libraries. 1.42 + */ 1.43 + for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { 1.44 + (*cinfo->mem->free_pool) (cinfo, pool); 1.45 + } 1.46 + 1.47 + /* Reset overall state for possible reuse of object */ 1.48 + if (cinfo->is_decompressor) { 1.49 + cinfo->global_state = DSTATE_START; 1.50 + /* Try to keep application from accessing now-deleted marker list. 1.51 + * A bit kludgy to do it here, but this is the most central place. 1.52 + */ 1.53 + ((j_decompress_ptr) cinfo)->marker_list = NULL; 1.54 + } else { 1.55 + cinfo->global_state = CSTATE_START; 1.56 + } 1.57 +} 1.58 + 1.59 + 1.60 +/* 1.61 + * Destruction of a JPEG object. 1.62 + * 1.63 + * Everything gets deallocated except the master jpeg_compress_struct itself 1.64 + * and the error manager struct. Both of these are supplied by the application 1.65 + * and must be freed, if necessary, by the application. (Often they are on 1.66 + * the stack and so don't need to be freed anyway.) 1.67 + * Closing a data source or destination, if necessary, is the application's 1.68 + * responsibility. 1.69 + */ 1.70 + 1.71 +GLOBAL(void) 1.72 +jpeg_destroy (j_common_ptr cinfo) 1.73 +{ 1.74 + /* We need only tell the memory manager to release everything. */ 1.75 + /* NB: mem pointer is NULL if memory mgr failed to initialize. */ 1.76 + if (cinfo->mem != NULL) 1.77 + (*cinfo->mem->self_destruct) (cinfo); 1.78 + cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ 1.79 + cinfo->global_state = 0; /* mark it destroyed */ 1.80 +} 1.81 + 1.82 + 1.83 +/* 1.84 + * Convenience routines for allocating quantization and Huffman tables. 1.85 + * (Would jutils.c be a more reasonable place to put these?) 1.86 + */ 1.87 + 1.88 +GLOBAL(JQUANT_TBL *) 1.89 +jpeg_alloc_quant_table (j_common_ptr cinfo) 1.90 +{ 1.91 + JQUANT_TBL *tbl; 1.92 + 1.93 + tbl = (JQUANT_TBL *) 1.94 + (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); 1.95 + tbl->sent_table = FALSE; /* make sure this is false in any new table */ 1.96 + return tbl; 1.97 +} 1.98 + 1.99 + 1.100 +GLOBAL(JHUFF_TBL *) 1.101 +jpeg_alloc_huff_table (j_common_ptr cinfo) 1.102 +{ 1.103 + JHUFF_TBL *tbl; 1.104 + 1.105 + tbl = (JHUFF_TBL *) 1.106 + (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); 1.107 + tbl->sent_table = FALSE; /* make sure this is false in any new table */ 1.108 + return tbl; 1.109 +}