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