Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/base/jmemcust.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
#if !defined(SHARE_JPEG) || SHARE_JPEG==0
17
18
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jerror.h"
21
#include "jmemcust.h"
22
23
GLOBAL(void *)
24
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
25
68.6k
{
26
68.6k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
27
28
68.6k
  return (void *) (cmem->j_mem_get_small)(cinfo, sizeofobject);
29
68.6k
}
30
31
GLOBAL(void)
32
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
33
68.6k
{
34
68.6k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
35
36
68.6k
  (cmem->j_mem_free_small)(cinfo, object, sizeofobject);
37
68.6k
}
38
39
/*
40
 * "Large" objects are treated the same as "small" ones.
41
 * NB: although we include FAR keywords in the routine declarations,
42
 * this file won't actually work in 80x86 small/medium model; at least,
43
 * you probably won't be able to process useful-size images in only 64KB.
44
 */
45
46
GLOBAL(void FAR *)
47
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
48
69.0k
{
49
69.0k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
50
51
69.0k
  return (void *) (cmem->j_mem_get_large)(cinfo, sizeofobject);
52
69.0k
}
53
54
GLOBAL(void)
55
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
56
69.0k
{
57
69.0k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
58
59
69.0k
  (cmem->j_mem_free_large)(cinfo, object, sizeofobject);
60
69.0k
}
61
62
/*
63
 * This routine computes the total memory space available for allocation.
64
 * Here we always say, "we got all you want bud!"
65
 */
66
67
GLOBAL(long)
68
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
69
                    long max_bytes_needed, long already_allocated)
70
1.36k
{
71
1.36k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
72
1.36k
  long ret = max_bytes_needed;
73
74
1.36k
  if (cmem->j_mem_avail)
75
0
    ret = (cmem->j_mem_avail)(cinfo);
76
77
1.36k
  return ret;
78
1.36k
}
79
80
/*
81
 * Backing store (temporary file) management.
82
 * Since jpeg_mem_available always promised the moon,
83
 * this should never be called and we can just error out.
84
 */
85
86
GLOBAL(void)
87
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
88
                         long total_bytes_needed)
89
0
{
90
0
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
91
92
0
  if (cmem->j_mem_open_backing_store) {
93
0
    (cmem->j_mem_open_backing_store)(cinfo, info, total_bytes_needed);
94
0
  }
95
0
  else
96
0
    ERREXIT(cinfo, JERR_NO_BACKING_STORE);
97
0
}
98
99
/*
100
 * These routines take care of any system-dependent initialization and
101
 * cleanup required.  Here, there isn't any.
102
 */
103
104
GLOBAL(long)
105
jpeg_mem_init (j_common_ptr cinfo)
106
19.5k
{
107
19.5k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
108
19.5k
  long ret = 0;
109
110
19.5k
  if (cmem->j_mem_init)
111
19.5k
    ret = (cmem->j_mem_init)(cinfo);
112
113
19.5k
  return ret;
114
19.5k
}
115
116
GLOBAL(void)
117
jpeg_mem_term (j_common_ptr cinfo)
118
19.5k
{
119
19.5k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
120
121
19.5k
  if (cmem->j_mem_term)
122
19.5k
    (cmem->j_mem_term)(cinfo);
123
19.5k
}
124
125
GLOBAL(jpeg_cust_mem_data *)
126
jpeg_cust_mem_init(jpeg_cust_mem_data *custm, void *priv,
127
    j_custmem_init_ptr               init,
128
    j_custmem_term_ptr               term,
129
    j_custmem_avail_ptr              avail,
130
    j_custmem_get_small_ptr          get_small,
131
    j_custmem_free_small_ptr         free_small,
132
    j_cust_mem_get_large_ptr         get_large,
133
    j_custmem_free_large_ptr         free_large,
134
    j_custmem_open_backing_store_ptr open_backing_store)
135
19.5k
{
136
19.5k
  jpeg_cust_mem_data *lcustm = NULL;
137
138
  /* We need at least the following for a viable memory manager */
139
19.5k
  if (get_small && free_small && get_large && free_large)
140
19.5k
  {
141
19.5k
    lcustm = custm;
142
143
19.5k
    lcustm->priv = priv;
144
19.5k
    lcustm->j_mem_init = init;
145
19.5k
    lcustm->j_mem_term = term;
146
19.5k
    lcustm->j_mem_avail = avail;
147
19.5k
    lcustm->j_mem_get_small = get_small;
148
19.5k
    lcustm->j_mem_free_small = free_small;
149
19.5k
    lcustm->j_mem_get_large = get_large;
150
19.5k
    lcustm->j_mem_free_large = free_large;
151
19.5k
    lcustm->j_mem_open_backing_store = open_backing_store;
152
19.5k
  }
153
19.5k
  return lcustm;
154
19.5k
}
155
156
GLOBAL(jpeg_cust_mem_data *)
157
jpeg_cust_mem_set_private(jpeg_cust_mem_data *custm, void *priv)
158
39.0k
{
159
39.0k
  if (custm)
160
39.0k
  {
161
39.0k
    custm->priv = priv;
162
39.0k
  }
163
39.0k
  return custm;
164
39.0k
}
165
166
#endif /* !defined(SHARE_JPEG) || SHARE_JPEG==0 */