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