35 #define XMS_SUPPORTED 1
38 #define EMS_SUPPORTED 1
42 #define JPEG_INTERNALS
48 extern void * malloc
JPP((
size_t size));
49 extern void free
JPP((
void *ptr));
50 extern char * getenv
JPP((
const char *
name));
53 #ifdef NEED_FAR_POINTERS
58 #define far_malloc(x) farmalloc(x)
59 #define far_free(x) farfree(x)
63 #define far_malloc(x) _fmalloc(x)
64 #define far_free(x) _ffree(x)
69 #define far_malloc(x) malloc(x)
70 #define far_free(x) free(x)
74 #ifdef DONT_USE_B_MODE
75 #define READ_BINARY "r"
77 #define READ_BINARY "rb"
80 #if MAX_ALLOC_CHUNK >= 65535L
95 unsigned short ax,
dx, bx;
99 unsigned short ax,
dx, bx;
103 EXTERN short far jdos_open
JPP((
short far * handle,
char far * filename));
104 EXTERN short far jdos_close
JPP((
short handle));
107 unsigned short count));
109 unsigned short count));
110 EXTERN void far jxms_getdriver
JPP((XMSDRIVER far *));
112 EXTERN short far jems_available
JPP((
void));
121 static int next_file_num;
135 if ((env = (
const char *) getenv(
"TMP")) ==
NULL)
136 if ((env = (
const char *) getenv(
"TEMP")) ==
NULL)
143 if (ptr[-1] !=
'\\' && ptr[-1] !=
'/')
147 sprintf(ptr,
"JPG%03d.TMP", next_file_num);
164 return (
void *) malloc(sizeofobject);
199 #ifndef DEFAULT_MAX_MEM
200 #define DEFAULT_MAX_MEM 300000L
205 long max_bytes_needed,
long already_allocated)
207 return cinfo->mem->max_memory_to_use - already_allocated;
240 void FAR * buffer_address,
241 long file_offset,
long byte_count)
243 if (jdos_seek(info->handle.file_handle, file_offset))
244 ERREXIT(cinfo, JERR_TFILE_SEEK);
246 if (byte_count > 65535
L)
247 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
248 if (jdos_read(info->handle.file_handle, buffer_address,
249 (
unsigned short) byte_count))
250 ERREXIT(cinfo, JERR_TFILE_READ);
256 void FAR * buffer_address,
257 long file_offset,
long byte_count)
259 if (jdos_seek(info->handle.file_handle, file_offset))
260 ERREXIT(cinfo, JERR_TFILE_SEEK);
262 if (byte_count > 65535
L)
263 ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
264 if (jdos_write(info->handle.file_handle, buffer_address,
265 (
unsigned short) byte_count))
266 ERREXIT(cinfo, JERR_TFILE_WRITE);
273 jdos_close(info->handle.file_handle);
285 long total_bytes_needed)
290 if (jdos_open((
short far *) & handle, (
char far *) info->
temp_name)) {
295 info->handle.file_handle = handle;
310 static XMSDRIVER xms_driver;
325 #define ODD(X) (((X) & 1L) != 0)
330 void FAR * buffer_address,
331 long file_offset,
long byte_count)
341 spec.
length = byte_count & (~ 1
L);
345 spec.
dst.
ptr = buffer_address;
347 ctx.
ds_si = (
void far *) & spec;
349 jxms_calldriver(xms_driver, (
XMScontext far *) & ctx);
353 if (
ODD(byte_count)) {
355 file_offset + byte_count - 1
L, 2
L);
356 ((
char FAR *) buffer_address)[byte_count - 1
L] = endbuffer[0];
363 void FAR * buffer_address,
364 long file_offset,
long byte_count)
374 spec.
length = byte_count & (~ 1
L);
376 spec.
src.
ptr = buffer_address;
380 ctx.
ds_si = (
void far *) & spec;
382 jxms_calldriver(xms_driver, (
XMScontext far *) & ctx);
384 ERREXIT(cinfo, JERR_XMS_WRITE);
386 if (
ODD(byte_count)) {
388 file_offset + byte_count - 1
L, 2
L);
389 endbuffer[0] = ((
char FAR *) buffer_address)[byte_count - 1
L];
391 file_offset + byte_count - 1
L, 2
L);
401 ctx.
dx = info->handle.xms_handle;
403 jxms_calldriver(xms_driver, (
XMScontext far *) & ctx);
404 TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
411 long total_bytes_needed)
416 jxms_getdriver((XMSDRIVER far *) & xms_driver);
417 if (xms_driver ==
NULL)
422 jxms_calldriver(xms_driver, (
XMScontext far *) & ctx);
423 if (ctx.
ax < (
unsigned short) 0x0200)
427 ctx.
dx = (
unsigned short) ((total_bytes_needed + 1023
L) >> 10);
429 jxms_calldriver(xms_driver, (
XMScontext far *) & ctx);
434 info->handle.xms_handle = ctx.
dx;
468 #define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset])))
469 #define SRC_TYPE(spec) FIELD_AT(spec,4,char)
470 #define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH)
471 #define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short)
472 #define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short)
473 #define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR)
474 #define DST_TYPE(spec) FIELD_AT(spec,11,char)
475 #define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH)
476 #define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short)
477 #define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short)
478 #define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR)
480 #define EMSPAGESIZE 16384L
482 #define HIBYTE(W) (((W) >> 8) & 0xFF)
483 #define LOBYTE(W) ((W) & 0xFF)
488 void FAR * buffer_address,
489 long file_offset,
long byte_count)
501 DST_PTR(spec) = buffer_address;
503 ctx.
ds_si = (
void far *) & spec;
513 void FAR * buffer_address,
514 long file_offset,
long byte_count)
522 SRC_PTR(spec) = buffer_address;
528 ctx.
ds_si = (
void far *) & spec;
532 ERREXIT(cinfo, JERR_EMS_WRITE);
542 ctx.
dx = info->handle.ems_handle;
544 TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
551 long total_bytes_needed)
556 if (! jems_available())
579 info->handle.ems_handle = ctx.
dx;
596 long total_bytes_needed)
609 ERREXITS(cinfo, JERR_TFILE_CREATE,
"");
GLOBAL void jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
char temp_name[TEMP_NAME_LENGTH]
GLOBAL void * jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject)
GLOBAL void FAR * jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject)
METHODDEF void read_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
METHODDEF void close_file_store(j_common_ptr cinfo, backing_store_ptr info)
GLOBAL void jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject)
METHODDEF void write_ems_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
#define ERREXIT(cinfo, code)
MAX_ALLOC_CHUNK should be less than typedef void far * XMSDRIVER
LOCAL void select_file_name(char *fname)
METHODDEF void write_xms_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
EXTERN short far jdos_open JPP((short far *handle, char far *filename))
#define TRACEMS1(cinfo, lvl, code, p1)
GLuint GLuint GLsizei count
METHODDEF void close_ems_store(j_common_ptr cinfo, backing_store_ptr info)
#define TRACEMSS(cinfo, lvl, code, str)
GLOBAL void jpeg_mem_term(j_common_ptr cinfo)
GLOBAL long jpeg_mem_init(j_common_ptr cinfo)
METHODDEF void write_file_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
LOCAL boolean open_file_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
METHODDEF void close_xms_store(j_common_ptr cinfo, backing_store_ptr info)
LOCAL boolean open_ems_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
LOCAL boolean open_xms_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed)
GLOBAL long jpeg_mem_available(j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated)
int sprintf(idStr &string, const char *fmt,...)
METHODDEF void read_ems_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)
#define ERREXITS(cinfo, code, str)
GLOBAL void jpeg_free_large(j_common_ptr cinfo, void FAR *object, size_t sizeofobject)
METHODDEF void read_file_store(j_common_ptr cinfo, backing_store_ptr info, void FAR *buffer_address, long file_offset, long byte_count)