1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
* jcomapi.c
|
|
|
|
*
|
2015-01-21 06:19:57 +03:00
|
|
|
* This file was part of the Independent JPEG Group's software:
|
2016-06-26 22:41:09 +03:00
|
|
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
2015-01-21 06:19:57 +03:00
|
|
|
* It was modified by The libjpeg-turbo Project to include only code relevant
|
|
|
|
* to libjpeg-turbo.
|
2016-06-26 22:41:09 +03:00
|
|
|
* For conditions of distribution and use, see the accompanying README.ijg
|
|
|
|
* file.
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
|
|
|
* This file contains application interface routines that are used for both
|
|
|
|
* compression and decompression.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define JPEG_INTERNALS
|
|
|
|
#include "jinclude.h"
|
|
|
|
#include "jpeglib.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abort processing of a JPEG compression or decompression operation,
|
|
|
|
* but don't destroy the object itself.
|
|
|
|
*
|
|
|
|
* For this, we merely clean up all the nonpermanent memory pools.
|
|
|
|
* Note that temp files (virtual arrays) are not allowed to belong to
|
|
|
|
* the permanent pool, so we will be able to close all temp files here.
|
|
|
|
* Closing a data source or destination, if necessary, is the application's
|
|
|
|
* responsibility.
|
|
|
|
*/
|
|
|
|
|
1998-07-23 01:15:59 +04:00
|
|
|
GLOBAL(void)
|
1998-03-28 05:44:41 +03:00
|
|
|
jpeg_abort (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
int pool;
|
|
|
|
|
1998-07-23 01:15:59 +04:00
|
|
|
/* Do nothing if called on a not-initialized or destroyed JPEG object. */
|
|
|
|
if (cinfo->mem == NULL)
|
|
|
|
return;
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/* Releasing pools in reverse order might help avoid fragmentation
|
|
|
|
* with some (brain-damaged) malloc libraries.
|
|
|
|
*/
|
|
|
|
for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
|
|
|
|
(*cinfo->mem->free_pool) (cinfo, pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset overall state for possible reuse of object */
|
1998-07-23 01:15:59 +04:00
|
|
|
if (cinfo->is_decompressor) {
|
|
|
|
cinfo->global_state = DSTATE_START;
|
|
|
|
/* Try to keep application from accessing now-deleted marker list.
|
|
|
|
* A bit kludgy to do it here, but this is the most central place.
|
|
|
|
*/
|
|
|
|
((j_decompress_ptr) cinfo)->marker_list = NULL;
|
|
|
|
} else {
|
|
|
|
cinfo->global_state = CSTATE_START;
|
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destruction of a JPEG object.
|
|
|
|
*
|
|
|
|
* Everything gets deallocated except the master jpeg_compress_struct itself
|
|
|
|
* and the error manager struct. Both of these are supplied by the application
|
|
|
|
* and must be freed, if necessary, by the application. (Often they are on
|
|
|
|
* the stack and so don't need to be freed anyway.)
|
|
|
|
* Closing a data source or destination, if necessary, is the application's
|
|
|
|
* responsibility.
|
|
|
|
*/
|
|
|
|
|
1998-07-23 01:15:59 +04:00
|
|
|
GLOBAL(void)
|
1998-03-28 05:44:41 +03:00
|
|
|
jpeg_destroy (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
/* We need only tell the memory manager to release everything. */
|
|
|
|
/* NB: mem pointer is NULL if memory mgr failed to initialize. */
|
|
|
|
if (cinfo->mem != NULL)
|
|
|
|
(*cinfo->mem->self_destruct) (cinfo);
|
2015-01-21 06:19:57 +03:00
|
|
|
cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
|
|
|
|
cinfo->global_state = 0; /* mark it destroyed */
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience routines for allocating quantization and Huffman tables.
|
|
|
|
* (Would jutils.c be a more reasonable place to put these?)
|
|
|
|
*/
|
|
|
|
|
1998-07-23 01:15:59 +04:00
|
|
|
GLOBAL(JQUANT_TBL *)
|
1998-03-28 05:44:41 +03:00
|
|
|
jpeg_alloc_quant_table (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
JQUANT_TBL *tbl;
|
|
|
|
|
|
|
|
tbl = (JQUANT_TBL *)
|
2015-01-21 06:19:57 +03:00
|
|
|
(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, sizeof(JQUANT_TBL));
|
|
|
|
tbl->sent_table = FALSE; /* make sure this is false in any new table */
|
1998-03-28 05:44:41 +03:00
|
|
|
return tbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-23 01:15:59 +04:00
|
|
|
GLOBAL(JHUFF_TBL *)
|
1998-03-28 05:44:41 +03:00
|
|
|
jpeg_alloc_huff_table (j_common_ptr cinfo)
|
|
|
|
{
|
|
|
|
JHUFF_TBL *tbl;
|
|
|
|
|
|
|
|
tbl = (JHUFF_TBL *)
|
2015-01-21 06:19:57 +03:00
|
|
|
(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, sizeof(JHUFF_TBL));
|
|
|
|
tbl->sent_table = FALSE; /* make sure this is false in any new table */
|
1998-03-28 05:44:41 +03:00
|
|
|
return tbl;
|
|
|
|
}
|