Doxygen Source Code Documentation
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>Go to the source code of this file.
Defines | |
| #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 | |
| int | next_file_num |
Define Documentation
|
|
|
|
|
Definition at line 68 of file jmemmac.c. Referenced by jpeg_open_backing_store(). |
Function Documentation
|
||||||||||||
|
Definition at line 190 of file jmemmac.c. References backing_store_struct::temp_file. Referenced by jpeg_open_backing_store().
00191 {
00192 FSClose ( info->temp_file );
00193 FSpDelete ( &(info->tempSpec) );
00194 }
|
|
||||||||||||||||
|
Definition at line 108 of file jmemmac.c. References object, and sizeofobject.
00109 {
00110 DisposePtr((Ptr) object);
00111 }
|
|
||||||||||||||||
|
Definition at line 88 of file jmemmac.c. References object, and sizeofobject.
00089 {
00090 DisposePtr((Ptr) object);
00091 }
|
|
||||||||||||
|
Definition at line 102 of file jmemmac.c. References sizeofobject.
00103 {
00104 return (void FAR *) NewPtr(sizeofobject);
00105 }
|
|
||||||||||||
|
Definition at line 82 of file jmemmac.c. References sizeofobject.
00083 {
00084 return (void *) NewPtr(sizeofobject);
00085 }
|
|
||||||||||||||||||||
|
Definition at line 119 of file jmemmac.c. References already_allocated, L, limit, max_bytes_needed, and min_bytes_needed.
00121 {
00122 long limit = cinfo->mem->max_memory_to_use - already_allocated;
00123 long slop, mem;
00124
00125 /* Don't ask for more than what application has told us we may use */
00126 if (max_bytes_needed > limit && limit > 0)
00127 max_bytes_needed = limit;
00128 /* Find whether there's a big enough free block in the heap.
00129 * CompactMem tries to create a contiguous block of the requested size,
00130 * and then returns the size of the largest free block (which could be
00131 * much more or much less than we asked for).
00132 * We add some slop to ensure we don't use up all available memory.
00133 */
00134 slop = max_bytes_needed / 16 + 32768L;
00135 mem = CompactMem(max_bytes_needed + slop) - slop;
00136 if (mem < 0)
00137 mem = 0; /* sigh, couldn't even get the slop */
00138 /* Don't take more than the application says we can have */
00139 if (mem > limit && limit > 0)
00140 mem = limit;
00141 return mem;
00142 }
|
|
|
Definition at line 272 of file jmemmac.c. References next_file_num.
00273 {
00274 next_file_num = 0;
00275
00276 /* max_memory_to_use will be initialized to FreeMem()'s result;
00277 * the calling application might later reduce it, for example
00278 * to leave room to invoke multiple JPEG objects.
00279 * Note that FreeMem returns the total number of free bytes;
00280 * it may not be possible to allocate a single block of this size.
00281 */
00282 return FreeMem();
00283 }
|
|
|
Definition at line 286 of file jmemmac.c.
00287 {
00288 /* no work */
00289 }
|
|
||||||||||||||||
|
Definition at line 205 of file jmemmac.c. References close_backing_store(), ERREXITS, next_file_num, read_backing_store(), backing_store_struct::temp_file, TEMP_FILE_NAME, backing_store_struct::temp_name, total_bytes_needed, TRACEMSS, and write_backing_store().
00207 {
00208 short tmpRef, vRefNum;
00209 long dirID;
00210 FInfo finderInfo;
00211 FSSpec theSpec;
00212 Str255 fName;
00213 OSErr osErr;
00214 long gestaltResponse = 0;
00215
00216 /* Check that FSSpec calls are available. */
00217 osErr = Gestalt( gestaltFSAttr, &gestaltResponse );
00218 if ( ( osErr != noErr )
00219 || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) )
00220 ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required");
00221 /* TO DO: add a proper error message to jerror.h. */
00222
00223 /* Check that FindFolder is available. */
00224 osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse );
00225 if ( ( osErr != noErr )
00226 || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) )
00227 ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required.");
00228 /* TO DO: add a proper error message to jerror.h. */
00229
00230 osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
00231 &vRefNum, &dirID );
00232 if ( osErr != noErr )
00233 ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable");
00234 /* TO DO: Try putting the temp files somewhere else. */
00235
00236 /* Keep generating file names till we find one that's not in use */
00237 for (;;) {
00238 next_file_num++; /* advance counter */
00239
00240 sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num);
00241 strcpy ( (Ptr)fName+1, info->temp_name );
00242 *fName = strlen (info->temp_name);
00243 osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec );
00244
00245 if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr )
00246 break;
00247 }
00248
00249 osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript );
00250 if ( osErr != noErr )
00251 ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
00252
00253 osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) );
00254 if ( osErr != noErr )
00255 ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
00256
00257 info->tempSpec = theSpec;
00258
00259 info->read_backing_store = read_backing_store;
00260 info->write_backing_store = write_backing_store;
00261 info->close_backing_store = close_backing_store;
00262 TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
00263 }
|
|
||||||||||||||||||||||||
|
Definition at line 154 of file jmemmac.c. References ERREXIT, and backing_store_struct::temp_file. Referenced by jpeg_open_backing_store().
00157 {
00158 long bytes = byte_count;
00159 long retVal;
00160
00161 if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
00162 ERREXIT(cinfo, JERR_TFILE_SEEK);
00163
00164 retVal = FSRead ( info->temp_file, &bytes,
00165 (unsigned char *) buffer_address );
00166 if ( retVal != noErr || bytes != byte_count )
00167 ERREXIT(cinfo, JERR_TFILE_READ);
00168 }
|
|
||||||||||||||||||||||||
|
Definition at line 172 of file jmemmac.c. References ERREXIT, JERR_TFILE_WRITE, and backing_store_struct::temp_file. Referenced by jpeg_open_backing_store().
00175 {
00176 long bytes = byte_count;
00177 long retVal;
00178
00179 if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
00180 ERREXIT(cinfo, JERR_TFILE_SEEK);
00181
00182 retVal = FSWrite ( info->temp_file, &bytes,
00183 (unsigned char *) buffer_address );
00184 if ( retVal != noErr || bytes != byte_count )
00185 ERREXIT(cinfo, JERR_TFILE_WRITE);
00186 }
|
Variable Documentation
|
|
Definition at line 71 of file jmemmac.c. Referenced by jpeg_mem_init(), and jpeg_open_backing_store(). |