Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/libjpeg/jcomapi.c
Views: 11784
/*1* jcomapi.c2*3* Copyright (C) 1994-1997, Thomas G. Lane.4* This file is part of the Independent JPEG Group's software.5* For conditions of distribution and use, see the accompanying README file.6*7* This file contains application interface routines that are used for both8* compression and decompression.9*/1011#define JPEG_INTERNALS12#include "jinclude.h"13#include "jpeglib.h"141516/*17* Abort processing of a JPEG compression or decompression operation,18* but don't destroy the object itself.19*20* For this, we merely clean up all the nonpermanent memory pools.21* Note that temp files (virtual arrays) are not allowed to belong to22* the permanent pool, so we will be able to close all temp files here.23* Closing a data source or destination, if necessary, is the application's24* responsibility.25*/2627GLOBAL(void)28jpeg_abort (j_common_ptr cinfo)29{30int pool;3132/* Do nothing if called on a not-initialized or destroyed JPEG object. */33if (cinfo->mem == NULL)34return;3536/* Releasing pools in reverse order might help avoid fragmentation37* with some (brain-damaged) malloc libraries.38*/39for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {40(*cinfo->mem->free_pool) (cinfo, pool);41}4243/* Reset overall state for possible reuse of object */44if (cinfo->is_decompressor) {45cinfo->global_state = DSTATE_START;46/* Try to keep application from accessing now-deleted marker list.47* A bit kludgy to do it here, but this is the most central place.48*/49((j_decompress_ptr) cinfo)->marker_list = NULL;50} else {51cinfo->global_state = CSTATE_START;52}53}545556/*57* Destruction of a JPEG object.58*59* Everything gets deallocated except the master jpeg_compress_struct itself60* and the error manager struct. Both of these are supplied by the application61* and must be freed, if necessary, by the application. (Often they are on62* the stack and so don't need to be freed anyway.)63* Closing a data source or destination, if necessary, is the application's64* responsibility.65*/6667GLOBAL(void)68jpeg_destroy (j_common_ptr cinfo)69{70/* We need only tell the memory manager to release everything. */71/* NB: mem pointer is NULL if memory mgr failed to initialize. */72if (cinfo->mem != NULL)73(*cinfo->mem->self_destruct) (cinfo);74cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */75cinfo->global_state = 0; /* mark it destroyed */76}777879/*80* Convenience routines for allocating quantization and Huffman tables.81* (Would jutils.c be a more reasonable place to put these?)82*/8384GLOBAL(JQUANT_TBL *)85jpeg_alloc_quant_table (j_common_ptr cinfo)86{87JQUANT_TBL *tbl;8889tbl = (JQUANT_TBL *)90(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));91tbl->sent_table = FALSE; /* make sure this is false in any new table */92return tbl;93}949596GLOBAL(JHUFF_TBL *)97jpeg_alloc_huff_table (j_common_ptr cinfo)98{99JHUFF_TBL *tbl;100101tbl = (JHUFF_TBL *)102(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));103tbl->sent_table = FALSE; /* make sure this is false in any new table */104return tbl;105}106107108