File size: 13,886 Bytes
9375c9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
169
170
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - jmemansi.c</title></head><body bgcolor='white'><pre>
<font color='#009900'>/*
 * jmemansi.c
 *
 * Copyright (C) 1992-1996, Thomas G. Lane.
 * This file is part of the Independent JPEG Group's software.
 * For conditions of distribution and use, see the accompanying README file.
 *
 * This file provides a simple generic implementation of the system-
 * dependent portion of the JPEG memory manager.  This implementation
 * assumes that you have the ANSI-standard library routine tmpfile().
 * Also, the problem of determining the amount of memory available
 * is shoved onto the user.
 */</font>

<font color='#0000FF'>#define</font> JPEG_INTERNALS
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='jinclude.h.html'>jinclude.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='jpeglib.h.html'>jpeglib.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='jmemsys.h.html'>jmemsys.h</a>"		<font color='#009900'>/* import the system-dependent declarations */</font>

<font color='#0000FF'>#ifndef</font> HAVE_STDLIB_H		<font color='#009900'>/* &lt;stdlib.h&gt; should declare malloc(),free() */</font>
<font color='#0000FF'>extern</font> <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font> malloc <b><a name='JPP'></a>JPP</b><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> size<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>extern</font> <font color='#0000FF'><u>void</u></font> free <b><a name='JPP'></a>JPP</b><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font>ptr<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>

<font color='#0000FF'>#ifndef</font> SEEK_SET		<font color='#009900'>/* pre-ANSI systems may not define this; */</font>
<font color='#0000FF'>#define</font> SEEK_SET  <font color='#979000'>0</font>		<font color='#009900'>/* if not, assume 0 is correct */</font>
<font color='#0000FF'>#endif</font>


<font color='#009900'>/*
 * Memory allocation and freeing are controlled by the regular library
 * routines malloc() and free().
 */</font>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font><font face='Lucida Console'>)</font>
<b><a name='jpeg_get_small'></a>jpeg_get_small</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, <font color='#0000FF'><u>size_t</u></font> sizeofobject<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font><font face='Lucida Console'>)</font> <font color='#BB00BB'>malloc</font><font face='Lucida Console'>(</font>sizeofobject<font face='Lucida Console'>)</font>;
<b>}</b>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='jpeg_free_small'></a>jpeg_free_small</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font> object, <font color='#0000FF'><u>size_t</u></font> sizeofobject<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#BB00BB'>free</font><font face='Lucida Console'>(</font>object<font face='Lucida Console'>)</font>;
<b>}</b>


<font color='#009900'>/*
 * "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.
 */</font>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font> FAR <font color='#5555FF'>*</font><font face='Lucida Console'>)</font>
<b><a name='jpeg_get_large'></a>jpeg_get_large</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, <font color='#0000FF'><u>size_t</u></font> sizeofobject<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font> FAR <font color='#5555FF'>*</font><font face='Lucida Console'>)</font> <font color='#BB00BB'>malloc</font><font face='Lucida Console'>(</font>sizeofobject<font face='Lucida Console'>)</font>;
<b>}</b>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='jpeg_free_large'></a>jpeg_free_large</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, <font color='#0000FF'><u>void</u></font> FAR <font color='#5555FF'>*</font> object, <font color='#0000FF'><u>size_t</u></font> sizeofobject<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#BB00BB'>free</font><font face='Lucida Console'>(</font>object<font face='Lucida Console'>)</font>;
<b>}</b>


<font color='#009900'>/*
 * This routine computes the total memory space available for allocation.
 * It's impossible to do this in a portable way; our current solution is
 * to make the user tell us (with a default value set at compile time).
 * If you can actually get the available space, it's a good idea to subtract
 * a slop factor of 5% or so.
 */</font>

<font color='#0000FF'>#ifndef</font> DEFAULT_MAX_MEM		<font color='#009900'>/* so can override from makefile */</font>
<font color='#0000FF'>#define</font> DEFAULT_MAX_MEM		<font color='#979000'>1000000</font>L <font color='#009900'>/* default: one megabyte */</font>
<font color='#0000FF'>#endif</font>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
<b><a name='jpeg_mem_available'></a>jpeg_mem_available</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, <font color='#0000FF'><u>long</u></font> min_bytes_needed,
		    <font color='#0000FF'><u>long</u></font> max_bytes_needed, <font color='#0000FF'><u>long</u></font> already_allocated<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>return</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mem<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_memory_to_use <font color='#5555FF'>-</font> already_allocated;
<b>}</b>


<font color='#009900'>/*
 * Backing store (temporary file) management.
 * Backing store objects are only used when the value returned by
 * jpeg_mem_available is less than the total space needed.  You can dispense
 * with these routines if you have plenty of virtual memory; see jmemnobs.c.
 */</font>


<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='read_backing_store'></a>read_backing_store</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, backing_store_ptr info,
		    <font color='#0000FF'><u>void</u></font> FAR <font color='#5555FF'>*</font> buffer_address,
		    <font color='#0000FF'><u>long</u></font> file_offset, <font color='#0000FF'><u>long</u></font> byte_count<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>fseek</font><font face='Lucida Console'>(</font>info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>temp_file, file_offset, SEEK_SET<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
    <font color='#BB00BB'>ERREXIT</font><font face='Lucida Console'>(</font>cinfo, JERR_TFILE_SEEK<font face='Lucida Console'>)</font>;
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>JFREAD</font><font face='Lucida Console'>(</font>info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>temp_file, buffer_address, byte_count<font face='Lucida Console'>)</font>
      <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font><font face='Lucida Console'>)</font> byte_count<font face='Lucida Console'>)</font>
    <font color='#BB00BB'>ERREXIT</font><font face='Lucida Console'>(</font>cinfo, JERR_TFILE_READ<font face='Lucida Console'>)</font>;
<b>}</b>


<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='write_backing_store'></a>write_backing_store</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, backing_store_ptr info,
		     <font color='#0000FF'><u>void</u></font> FAR <font color='#5555FF'>*</font> buffer_address,
		     <font color='#0000FF'><u>long</u></font> file_offset, <font color='#0000FF'><u>long</u></font> byte_count<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>fseek</font><font face='Lucida Console'>(</font>info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>temp_file, file_offset, SEEK_SET<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
    <font color='#BB00BB'>ERREXIT</font><font face='Lucida Console'>(</font>cinfo, JERR_TFILE_SEEK<font face='Lucida Console'>)</font>;
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>JFWRITE</font><font face='Lucida Console'>(</font>info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>temp_file, buffer_address, byte_count<font face='Lucida Console'>)</font>
      <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font><font face='Lucida Console'>)</font> byte_count<font face='Lucida Console'>)</font>
    <font color='#BB00BB'>ERREXIT</font><font face='Lucida Console'>(</font>cinfo, JERR_TFILE_WRITE<font face='Lucida Console'>)</font>;
<b>}</b>


<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='close_backing_store'></a>close_backing_store</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, backing_store_ptr info<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font>info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>temp_file<font face='Lucida Console'>)</font>;
  <font color='#009900'>/* Since this implementation uses tmpfile() to create the file,
   * no explicit file deletion is needed.
   */</font>
<b>}</b>


<font color='#009900'>/*
 * Initial opening of a backing-store object.
 *
 * This version uses tmpfile(), which constructs a suitable file name
 * behind the scenes.  We don't have to use info-&gt;temp_name[] at all;
 * indeed, we can't even find out the actual name of the temp file.
 */</font>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='jpeg_open_backing_store'></a>jpeg_open_backing_store</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo, backing_store_ptr info,
			 <font color='#0000FF'><u>long</u></font> total_bytes_needed<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>temp_file <font color='#5555FF'>=</font> <font color='#BB00BB'>tmpfile</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
    <font color='#BB00BB'>ERREXITS</font><font face='Lucida Console'>(</font>cinfo, JERR_TFILE_CREATE, "<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
  info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>read_backing_store <font color='#5555FF'>=</font> read_backing_store;
  info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>write_backing_store <font color='#5555FF'>=</font> write_backing_store;
  info<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>close_backing_store <font color='#5555FF'>=</font> close_backing_store;
<b>}</b>


<font color='#009900'>/*
 * These routines take care of any system-dependent initialization and
 * cleanup required.
 */</font>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
<b><a name='jpeg_mem_init'></a>jpeg_mem_init</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#0000FF'>return</font> DEFAULT_MAX_MEM;	<font color='#009900'>/* default for max_memory_to_use */</font>
<b>}</b>

<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
<b><a name='jpeg_mem_term'></a>jpeg_mem_term</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#009900'>/* no work */</font>
<b>}</b>

</pre></body></html>