⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmemdos.c

📁 linux下的jpeg解码库
💻 C
📖 第 1 页 / 共 2 页
字号:
typedef struct {		/* XMS move specification structure */	long length;	XMSH src_handle;	XMSPTR src;	XMSH dst_handle;	XMSPTR dst;      } XMSspec;#define ODD(X)	(((X) & 1L) != 0)METHODDEF(void)read_xms_store (j_common_ptr cinfo, backing_store_ptr info,		void FAR * buffer_address,		long file_offset, long byte_count){  XMScontext ctx;  XMSspec spec;  char endbuffer[2];  /* The XMS driver can't cope with an odd length, so handle the last byte   * specially if byte_count is odd.  We don't expect this to be common.   */  spec.length = byte_count & (~ 1L);  spec.src_handle = info->handle.xms_handle;  spec.src.offset = file_offset;  spec.dst_handle = 0;  spec.dst.ptr = buffer_address;    ctx.ds_si = (void far *) & spec;  ctx.ax = 0x0b00;		/* EMB move */  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);  if (ctx.ax != 1)    ERREXIT(cinfo, JERR_XMS_READ);  if (ODD(byte_count)) {    read_xms_store(cinfo, info, (void FAR *) endbuffer,		   file_offset + byte_count - 1L, 2L);    ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];  }}METHODDEF(void)write_xms_store (j_common_ptr cinfo, backing_store_ptr info,		 void FAR * buffer_address,		 long file_offset, long byte_count){  XMScontext ctx;  XMSspec spec;  char endbuffer[2];  /* The XMS driver can't cope with an odd length, so handle the last byte   * specially if byte_count is odd.  We don't expect this to be common.   */  spec.length = byte_count & (~ 1L);  spec.src_handle = 0;  spec.src.ptr = buffer_address;  spec.dst_handle = info->handle.xms_handle;  spec.dst.offset = file_offset;  ctx.ds_si = (void far *) & spec;  ctx.ax = 0x0b00;		/* EMB move */  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);  if (ctx.ax != 1)    ERREXIT(cinfo, JERR_XMS_WRITE);  if (ODD(byte_count)) {    read_xms_store(cinfo, info, (void FAR *) endbuffer,		   file_offset + byte_count - 1L, 2L);    endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];    write_xms_store(cinfo, info, (void FAR *) endbuffer,		    file_offset + byte_count - 1L, 2L);  }}METHODDEF(void)close_xms_store (j_common_ptr cinfo, backing_store_ptr info){  XMScontext ctx;  ctx.dx = info->handle.xms_handle;  ctx.ax = 0x0a00;  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);  TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);  /* we ignore any error return from the driver */}LOCAL(boolean)open_xms_store (j_common_ptr cinfo, backing_store_ptr info,		long total_bytes_needed){  XMScontext ctx;  /* Get address of XMS driver */  jxms_getdriver((XMSDRIVER far *) & xms_driver);  if (xms_driver == NULL)    return FALSE;		/* no driver to be had */  /* Get version number, must be >= 2.00 */  ctx.ax = 0x0000;  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);  if (ctx.ax < (unsigned short) 0x0200)    return FALSE;  /* Try to get space (expressed in kilobytes) */  ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);  ctx.ax = 0x0900;  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);  if (ctx.ax != 1)    return FALSE;  /* Succeeded, save the handle and away we go */  info->handle.xms_handle = ctx.dx;  info->read_backing_store = read_xms_store;  info->write_backing_store = write_xms_store;  info->close_backing_store = close_xms_store;  TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);  return TRUE;			/* succeeded */}#endif /* XMS_SUPPORTED *//* * Access methods for expanded memory. */#if EMS_SUPPORTED/* The EMS move specification structure requires word and long fields aligned * at odd byte boundaries.  Some compilers will align struct fields at even * byte boundaries.  While it's usually possible to force byte alignment, * that causes an overall performance penalty and may pose problems in merging * JPEG into a larger application.  Instead we accept some rather dirty code * here.  Note this code would fail if the hardware did not allow odd-byte * word & long accesses, but all 80x86 CPUs do. */typedef void far * EMSPTR;typedef union {			/* EMS move specification structure */	long length;		/* It's easy to access first 4 bytes */	char bytes[18];		/* Misaligned fields in here! */      } EMSspec;/* Macros for accessing misaligned fields */#define FIELD_AT(spec,offset,type)  (*((type *) &(spec.bytes[offset])))#define SRC_TYPE(spec)		FIELD_AT(spec,4,char)#define SRC_HANDLE(spec)	FIELD_AT(spec,5,EMSH)#define SRC_OFFSET(spec)	FIELD_AT(spec,7,unsigned short)#define SRC_PAGE(spec)		FIELD_AT(spec,9,unsigned short)#define SRC_PTR(spec)		FIELD_AT(spec,7,EMSPTR)#define DST_TYPE(spec)		FIELD_AT(spec,11,char)#define DST_HANDLE(spec)	FIELD_AT(spec,12,EMSH)#define DST_OFFSET(spec)	FIELD_AT(spec,14,unsigned short)#define DST_PAGE(spec)		FIELD_AT(spec,16,unsigned short)#define DST_PTR(spec)		FIELD_AT(spec,14,EMSPTR)#define EMSPAGESIZE	16384L	/* gospel, see the EMS specs */#define HIBYTE(W)  (((W) >> 8) & 0xFF)#define LOBYTE(W)  ((W) & 0xFF)METHODDEF(void)read_ems_store (j_common_ptr cinfo, backing_store_ptr info,		void FAR * buffer_address,		long file_offset, long byte_count){  EMScontext ctx;  EMSspec spec;  spec.length = byte_count;  SRC_TYPE(spec) = 1;  SRC_HANDLE(spec) = info->handle.ems_handle;  SRC_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);  SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);  DST_TYPE(spec) = 0;  DST_HANDLE(spec) = 0;  DST_PTR(spec)    = buffer_address;    ctx.ds_si = (void far *) & spec;  ctx.ax = 0x5700;		/* move memory region */  jems_calldriver((EMScontext far *) & ctx);  if (HIBYTE(ctx.ax) != 0)    ERREXIT(cinfo, JERR_EMS_READ);}METHODDEF(void)write_ems_store (j_common_ptr cinfo, backing_store_ptr info,		 void FAR * buffer_address,		 long file_offset, long byte_count){  EMScontext ctx;  EMSspec spec;  spec.length = byte_count;  SRC_TYPE(spec) = 0;  SRC_HANDLE(spec) = 0;  SRC_PTR(spec)    = buffer_address;  DST_TYPE(spec) = 1;  DST_HANDLE(spec) = info->handle.ems_handle;  DST_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);  DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);    ctx.ds_si = (void far *) & spec;  ctx.ax = 0x5700;		/* move memory region */  jems_calldriver((EMScontext far *) & ctx);  if (HIBYTE(ctx.ax) != 0)    ERREXIT(cinfo, JERR_EMS_WRITE);}METHODDEF(void)close_ems_store (j_common_ptr cinfo, backing_store_ptr info){  EMScontext ctx;  ctx.ax = 0x4500;  ctx.dx = info->handle.ems_handle;  jems_calldriver((EMScontext far *) & ctx);  TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);  /* we ignore any error return from the driver */}LOCAL(boolean)open_ems_store (j_common_ptr cinfo, backing_store_ptr info,		long total_bytes_needed){  EMScontext ctx;  /* Is EMS driver there? */  if (! jems_available())    return FALSE;  /* Get status, make sure EMS is OK */  ctx.ax = 0x4000;  jems_calldriver((EMScontext far *) & ctx);  if (HIBYTE(ctx.ax) != 0)    return FALSE;  /* Get version, must be >= 4.0 */  ctx.ax = 0x4600;  jems_calldriver((EMScontext far *) & ctx);  if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)    return FALSE;  /* Try to allocate requested space */  ctx.ax = 0x4300;  ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);  jems_calldriver((EMScontext far *) & ctx);  if (HIBYTE(ctx.ax) != 0)    return FALSE;  /* Succeeded, save the handle and away we go */  info->handle.ems_handle = ctx.dx;  info->read_backing_store = read_ems_store;  info->write_backing_store = write_ems_store;  info->close_backing_store = close_ems_store;  TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);  return TRUE;			/* succeeded */}#endif /* EMS_SUPPORTED *//* * Initial opening of a backing-store object. */GLOBAL(void)jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,			 long total_bytes_needed){  /* Try extended memory, then expanded memory, then regular file. */#if XMS_SUPPORTED  if (open_xms_store(cinfo, info, total_bytes_needed))    return;#endif#if EMS_SUPPORTED  if (open_ems_store(cinfo, info, total_bytes_needed))    return;#endif  if (open_file_store(cinfo, info, total_bytes_needed))    return;  ERREXITS(cinfo, JERR_TFILE_CREATE, "");}/* * These routines take care of any system-dependent initialization and * cleanup required. */GLOBAL(long)jpeg_mem_init (j_common_ptr cinfo){  next_file_num = 0;		/* initialize temp file name generator */  return DEFAULT_MAX_MEM;	/* default for max_memory_to_use */}GLOBAL(void)jpeg_mem_term (j_common_ptr cinfo){  /* Microsoft C, at least in v6.00A, will not successfully reclaim freed   * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:   */#ifdef NEED_FHEAPMIN  _fheapmin();#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -