ReactOS  0.4.14-dev-315-gbb6fece
jmemmac.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jmemsys.h"
#include <Memory.h>
#include <Files.h>
#include <Folders.h>
#include <Script.h>
#include <Gestalt.h>
Include dependency graph for jmemmac.c:

Go to the source code of this file.

Macros

#define JPEG_INTERNALS
 
#define TEMP_FILE_NAME   "JPG%03d.TMP"
 

Functions

 jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
 
 jpeg_free_small (j_common_ptr cinfo, void *object, size_t sizeofobject)
 
 jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
 
 jpeg_free_large (j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
 
 jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
 
 read_backing_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 write_backing_store (j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
 
 close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
 
 jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
 
 jpeg_mem_init (j_common_ptr cinfo)
 
 jpeg_mem_term (j_common_ptr cinfo)
 

Variables

static int next_file_num
 

Macro Definition Documentation

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 52 of file jmemmac.c.

◆ TEMP_FILE_NAME

#define TEMP_FILE_NAME   "JPG%03d.TMP"

Definition at line 68 of file jmemmac.c.

Function Documentation

◆ close_backing_store()

close_backing_store ( j_common_ptr  cinfo,
backing_store_ptr  info 
)

Definition at line 190 of file jmemmac.c.

191 {
192  FSClose ( info->temp_file );
193  FSpDelete ( &(info->tempSpec) );
194 }

Referenced by jpeg_open_backing_store().

◆ jpeg_free_large()

jpeg_free_large ( j_common_ptr  cinfo,
void FAR object,
size_t  sizeofobject 
)

Definition at line 108 of file jmemmac.c.

109 {
110  DisposePtr((Ptr) object);
111 }
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898

◆ jpeg_free_small()

jpeg_free_small ( j_common_ptr  cinfo,
void object,
size_t  sizeofobject 
)

Definition at line 88 of file jmemmac.c.

89 {
90  DisposePtr((Ptr) object);
91 }
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898

◆ jpeg_get_large()

jpeg_get_large ( j_common_ptr  cinfo,
size_t  sizeofobject 
)

Definition at line 102 of file jmemmac.c.

103 {
104  return (void FAR *) NewPtr(sizeofobject);
105 }
size_t sizeofobject
Definition: jmemsys.h:47
#define FAR
Definition: guiddef.h:36

◆ jpeg_get_small()

jpeg_get_small ( j_common_ptr  cinfo,
size_t  sizeofobject 
)

Definition at line 82 of file jmemmac.c.

83 {
84  return (void *) NewPtr(sizeofobject);
85 }
size_t sizeofobject
Definition: jmemsys.h:47

◆ jpeg_mem_available()

jpeg_mem_available ( j_common_ptr  cinfo,
long  min_bytes_needed,
long  max_bytes_needed,
long  already_allocated 
)

Definition at line 119 of file jmemmac.c.

121 {
122  long limit = cinfo->mem->max_memory_to_use - already_allocated;
123  long slop, mem;
124 
125  /* Don't ask for more than what application has told us we may use */
126  if (max_bytes_needed > limit && limit > 0)
128  /* Find whether there's a big enough free block in the heap.
129  * CompactMem tries to create a contiguous block of the requested size,
130  * and then returns the size of the largest free block (which could be
131  * much more or much less than we asked for).
132  * We add some slop to ensure we don't use up all available memory.
133  */
134  slop = max_bytes_needed / 16 + 32768L;
135  mem = CompactMem(max_bytes_needed + slop) - slop;
136  if (mem < 0)
137  mem = 0; /* sigh, couldn't even get the slop */
138  /* Don't take more than the application says we can have */
139  if (mem > limit && limit > 0)
140  mem = limit;
141  return mem;
142 }
long long max_bytes_needed
Definition: jmemsys.h:104
GLint limit
Definition: glext.h:10326
static const WCHAR L[]
Definition: oid.c:1250
long long long already_allocated
Definition: jmemsys.h:104
Definition: mem.c:156

◆ jpeg_mem_init()

jpeg_mem_init ( j_common_ptr  cinfo)

Definition at line 272 of file jmemmac.c.

273 {
274  next_file_num = 0;
275 
276  /* max_memory_to_use will be initialized to FreeMem()'s result;
277  * the calling application might later reduce it, for example
278  * to leave room to invoke multiple JPEG objects.
279  * Note that FreeMem returns the total number of free bytes;
280  * it may not be possible to allocate a single block of this size.
281  */
282  return FreeMem();
283 }
static int next_file_num
Definition: jmemmac.c:71

◆ jpeg_mem_term()

jpeg_mem_term ( j_common_ptr  cinfo)

Definition at line 286 of file jmemmac.c.

287 {
288  /* no work */
289 }

◆ jpeg_open_backing_store()

jpeg_open_backing_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
long  total_bytes_needed 
)

Definition at line 205 of file jmemmac.c.

207 {
208  short tmpRef, vRefNum;
209  long dirID;
210  FInfo finderInfo;
211  FSSpec theSpec;
212  Str255 fName;
213  OSErr osErr;
214  long gestaltResponse = 0;
215 
216  /* Check that FSSpec calls are available. */
217  osErr = Gestalt( gestaltFSAttr, &gestaltResponse );
218  if ( ( osErr != noErr )
219  || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) )
220  ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required");
221  /* TO DO: add a proper error message to jerror.h. */
222 
223  /* Check that FindFolder is available. */
224  osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse );
225  if ( ( osErr != noErr )
226  || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) )
227  ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required.");
228  /* TO DO: add a proper error message to jerror.h. */
229 
230  osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
231  &vRefNum, &dirID );
232  if ( osErr != noErr )
233  ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable");
234  /* TO DO: Try putting the temp files somewhere else. */
235 
236  /* Keep generating file names till we find one that's not in use */
237  for (;;) {
238  next_file_num++; /* advance counter */
239 
241  strcpy ( (Ptr)fName+1, info->temp_name );
242  *fName = strlen (info->temp_name);
243  osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec );
244 
245  if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr )
246  break;
247  }
248 
249  osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript );
250  if ( osErr != noErr )
251  ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
252 
253  osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) );
254  if ( osErr != noErr )
255  ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
256 
257  info->tempSpec = theSpec;
258 
259  info->read_backing_store = read_backing_store;
260  info->write_backing_store = write_backing_store;
261  info->close_backing_store = close_backing_store;
262  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
263 }
static int next_file_num
Definition: jmemmac.c:71
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define TRACEMSS(cinfo, lvl, code, str)
Definition: jerror.h:299
write_backing_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemmac.c:172
read_backing_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
Definition: jmemmac.c:154
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
close_backing_store(j_common_ptr cinfo, backing_store_ptr info)
Definition: jmemmac.c:190
#define TEMP_FILE_NAME
Definition: jmemmac.c:68
#define ERREXITS(cinfo, code, str)
Definition: jerror.h:243

◆ read_backing_store()

read_backing_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 154 of file jmemmac.c.

157 {
158  long bytes = byte_count;
159  long retVal;
160 
161  if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
162  ERREXIT(cinfo, JERR_TFILE_SEEK);
163 
164  retVal = FSRead ( info->temp_file, &bytes,
165  (unsigned char *) buffer_address );
166  if ( retVal != noErr || bytes != byte_count )
167  ERREXIT(cinfo, JERR_TFILE_READ);
168 }
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
static unsigned char bytes[4]
Definition: adnsresfilter.c:74

Referenced by jpeg_open_backing_store().

◆ write_backing_store()

write_backing_store ( j_common_ptr  cinfo,
backing_store_ptr  info,
void FAR buffer_address,
long  file_offset,
long  byte_count 
)

Definition at line 172 of file jmemmac.c.

175 {
176  long bytes = byte_count;
177  long retVal;
178 
179  if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
180  ERREXIT(cinfo, JERR_TFILE_SEEK);
181 
182  retVal = FSWrite ( info->temp_file, &bytes,
183  (unsigned char *) buffer_address );
184  if ( retVal != noErr || bytes != byte_count )
185  ERREXIT(cinfo, JERR_TFILE_WRITE);
186 }
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
static unsigned char bytes[4]
Definition: adnsresfilter.c:74

Referenced by jpeg_open_backing_store().

Variable Documentation

◆ next_file_num

int next_file_num
static

Definition at line 71 of file jmemmac.c.

Referenced by jpeg_mem_init(), and jpeg_open_backing_store().