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