| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#define JPEG_INTERNALS |
| 16 |
#include "jinclude.h" |
| 17 |
#include "jpeglib.h" |
| 18 |
#include "jmemsys.h" |
| 19 |
|
| 20 |
#ifndef HAVE_STDLIB_H |
| 21 |
extern void * malloc JPP((size_t size)); |
| 22 |
extern void free JPP((void *ptr)); |
| 23 |
#endif |
| 24 |
|
| 25 |
#ifndef SEEK_SET |
| 26 |
#define SEEK_SET 0 |
| 27 |
#endif |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
GLOBAL(void *) |
| 36 |
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) |
| 37 |
{ |
| 38 |
return (void *) malloc(sizeofobject); |
| 39 |
} |
| 40 |
|
| 41 |
GLOBAL(void) |
| 42 |
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) |
| 43 |
{ |
| 44 |
free(object); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
GLOBAL(void FAR *) |
| 56 |
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) |
| 57 |
{ |
| 58 |
return (void FAR *) malloc(sizeofobject); |
| 59 |
} |
| 60 |
|
| 61 |
GLOBAL(void) |
| 62 |
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) |
| 63 |
{ |
| 64 |
free(object); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
#ifndef DEFAULT_MAX_MEM |
| 77 |
#define DEFAULT_MAX_MEM 1000000L |
| 78 |
#endif |
| 79 |
|
| 80 |
GLOBAL(long) |
| 81 |
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, |
| 82 |
long max_bytes_needed, long already_allocated) |
| 83 |
{ |
| 84 |
return cinfo->mem->max_memory_to_use - already_allocated; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
METHODDEF(void) |
| 97 |
read_backing_store (j_common_ptr cinfo, backing_store_ptr info, |
| 98 |
void FAR * buffer_address, |
| 99 |
long file_offset, long byte_count) |
| 100 |
{ |
| 101 |
if (fseek(info->temp_file, file_offset, SEEK_SET)) |
| 102 |
ERREXIT(cinfo, JERR_TFILE_SEEK); |
| 103 |
if (JFREAD(info->temp_file, buffer_address, byte_count) |
| 104 |
!= (size_t) byte_count) |
| 105 |
ERREXIT(cinfo, JERR_TFILE_READ); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
METHODDEF(void) |
| 110 |
write_backing_store (j_common_ptr cinfo, backing_store_ptr info, |
| 111 |
void FAR * buffer_address, |
| 112 |
long file_offset, long byte_count) |
| 113 |
{ |
| 114 |
if (fseek(info->temp_file, file_offset, SEEK_SET)) |
| 115 |
ERREXIT(cinfo, JERR_TFILE_SEEK); |
| 116 |
if (JFWRITE(info->temp_file, buffer_address, byte_count) |
| 117 |
!= (size_t) byte_count) |
| 118 |
ERREXIT(cinfo, JERR_TFILE_WRITE); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
METHODDEF(void) |
| 123 |
close_backing_store (j_common_ptr cinfo, backing_store_ptr info) |
| 124 |
{ |
| 125 |
fclose(info->temp_file); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
GLOBAL(void) |
| 141 |
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, |
| 142 |
long total_bytes_needed) |
| 143 |
{ |
| 144 |
if ((info->temp_file = tmpfile()) == NULL) |
| 145 |
ERREXITS(cinfo, JERR_TFILE_CREATE, ""); |
| 146 |
info->read_backing_store = read_backing_store; |
| 147 |
info->write_backing_store = write_backing_store; |
| 148 |
info->close_backing_store = close_backing_store; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
GLOBAL(long) |
| 158 |
jpeg_mem_init (j_common_ptr cinfo) |
| 159 |
{ |
| 160 |
return DEFAULT_MAX_MEM; |
| 161 |
} |
| 162 |
|
| 163 |
GLOBAL(void) |
| 164 |
jpeg_mem_term (j_common_ptr cinfo) |
| 165 |
{ |
| 166 |
|
| 167 |
} |