Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
9.2 KiB

3 years ago
  1. unit imjmemnobs;
  2. { Delphi3 -- > jmemnobs from jmemwin }
  3. { This file provides an Win32-compatible implementation of the system-
  4. dependent portion of the JPEG memory manager. }
  5. { Check jmemnobs.c }
  6. { Copyright (C) 1996, Jacques Nomssi Nzali }
  7. interface
  8. {$I imjconfig.inc}
  9. uses
  10. imjmorecfg,
  11. imjdeferr,
  12. imjerror,
  13. imjpeglib;
  14. { The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
  15. be requested in a single call to jpeg_get_large (and jpeg_get_small for that
  16. matter, but that case should never come into play). This macro is needed
  17. to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
  18. On those machines, we expect that jconfig.h will provide a proper value.
  19. On machines with 32-bit flat address spaces, any large constant may be used.
  20. NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
  21. size_t and will be a multiple of sizeof(align_type). }
  22. const
  23. MAX_ALLOC_CHUNK = long(1000000000);
  24. {GLOBAL}
  25. procedure jpeg_open_backing_store (cinfo : j_common_ptr;
  26. info : backing_store_ptr;
  27. total_bytes_needed : long);
  28. { These routines take care of any system-dependent initialization and
  29. cleanup required. }
  30. {GLOBAL}
  31. function jpeg_mem_init (cinfo : j_common_ptr) : long;
  32. {GLOBAL}
  33. procedure jpeg_mem_term (cinfo : j_common_ptr);
  34. { These two functions are used to allocate and release small chunks of
  35. memory. (Typically the total amount requested through jpeg_get_small is
  36. no more than 20K or so; this will be requested in chunks of a few K each.)
  37. Behavior should be the same as for the standard library functions malloc
  38. and free; in particular, jpeg_get_small must return NIL on failure.
  39. On most systems, these ARE malloc and free. jpeg_free_small is passed the
  40. size of the object being freed, just in case it's needed.
  41. On an 80x86 machine using small-data memory model, these manage near heap. }
  42. { Near-memory allocation and freeing are controlled by the regular library
  43. routines malloc() and free(). }
  44. {GLOBAL}
  45. function jpeg_get_small (cinfo : j_common_ptr;
  46. sizeofobject : size_t) : pointer;
  47. {GLOBAL}
  48. {object is a reserved word in Borland Pascal }
  49. procedure jpeg_free_small (cinfo : j_common_ptr;
  50. an_object : pointer;
  51. sizeofobject : size_t);
  52. { These two functions are used to allocate and release large chunks of
  53. memory (up to the total free space designated by jpeg_mem_available).
  54. The interface is the same as above, except that on an 80x86 machine,
  55. far pointers are used. On most other machines these are identical to
  56. the jpeg_get/free_small routines; but we keep them separate anyway,
  57. in case a different allocation strategy is desirable for large chunks. }
  58. { "Large" objects are allocated in far memory, if possible }
  59. {GLOBAL}
  60. function jpeg_get_large (cinfo : j_common_ptr;
  61. sizeofobject : size_t) : voidp; {far}
  62. {GLOBAL}
  63. procedure jpeg_free_large (cinfo : j_common_ptr;
  64. {var?} an_object : voidp; {FAR}
  65. sizeofobject : size_t);
  66. { This routine computes the total memory space available for allocation.
  67. It's impossible to do this in a portable way; our current solution is
  68. to make the user tell us (with a default value set at compile time).
  69. If you can actually get the available space, it's a good idea to subtract
  70. a slop factor of 5% or so. }
  71. {GLOBAL}
  72. function jpeg_mem_available (cinfo : j_common_ptr;
  73. min_bytes_needed : long;
  74. max_bytes_needed : long;
  75. already_allocated : long) : long;
  76. implementation
  77. { This structure holds whatever state is needed to access a single
  78. backing-store object. The read/write/close method pointers are called
  79. by jmemmgr.c to manipulate the backing-store object; all other fields
  80. are private to the system-dependent backing store routines. }
  81. { These two functions are used to allocate and release small chunks of
  82. memory. (Typically the total amount requested through jpeg_get_small is
  83. no more than 20K or so; this will be requested in chunks of a few K each.)
  84. Behavior should be the same as for the standard library functions malloc
  85. and free; in particular, jpeg_get_small must return NIL on failure.
  86. On most systems, these ARE malloc and free. jpeg_free_small is passed the
  87. size of the object being freed, just in case it's needed.
  88. On an 80x86 machine using small-data memory model, these manage near heap. }
  89. { Near-memory allocation and freeing are controlled by the regular library
  90. routines malloc() and free(). }
  91. {GLOBAL}
  92. function jpeg_get_small (cinfo : j_common_ptr;
  93. sizeofobject : size_t) : pointer;
  94. var
  95. p : pointer;
  96. begin
  97. GetMem(p, sizeofobject);
  98. jpeg_get_small := p;
  99. end;
  100. {GLOBAL}
  101. {object is a reserved word in Object Pascal }
  102. procedure jpeg_free_small (cinfo : j_common_ptr;
  103. an_object : pointer;
  104. sizeofobject : size_t);
  105. begin
  106. FreeMem(an_object, sizeofobject);
  107. end;
  108. { These two functions are used to allocate and release large chunks of
  109. memory (up to the total free space designated by jpeg_mem_available).
  110. The interface is the same as above, except that on an 80x86 machine,
  111. far pointers are used. On most other machines these are identical to
  112. the jpeg_get/free_small routines; but we keep them separate anyway,
  113. in case a different allocation strategy is desirable for large chunks. }
  114. {GLOBAL}
  115. function jpeg_get_large (cinfo : j_common_ptr;
  116. sizeofobject : size_t) : voidp; {far}
  117. var
  118. p : pointer;
  119. begin
  120. GetMem(p, sizeofobject);
  121. jpeg_get_large := p;
  122. end;
  123. {GLOBAL}
  124. procedure jpeg_free_large (cinfo : j_common_ptr;
  125. {var?} an_object : voidp; {FAR}
  126. sizeofobject : size_t);
  127. begin
  128. Freemem(an_object, sizeofobject);
  129. end;
  130. { This routine computes the total space still available for allocation by
  131. jpeg_get_large. If more space than this is needed, backing store will be
  132. used. NOTE: any memory already allocated must not be counted.
  133. There is a minimum space requirement, corresponding to the minimum
  134. feasible buffer sizes; jmemmgr.c will request that much space even if
  135. jpeg_mem_available returns zero. The maximum space needed, enough to hold
  136. all working storage in memory, is also passed in case it is useful.
  137. Finally, the total space already allocated is passed. If no better
  138. method is available, cinfo^.mem^.max_memory_to_use - already_allocated
  139. is often a suitable calculation.
  140. It is OK for jpeg_mem_available to underestimate the space available
  141. (that'll just lead to more backing-store access than is really necessary).
  142. However, an overestimate will lead to failure. Hence it's wise to subtract
  143. a slop factor from the true available space. 5% should be enough.
  144. On machines with lots of virtual memory, any large constant may be returned.
  145. Conversely, zero may be returned to always use the minimum amount of memory.}
  146. { This routine computes the total memory space available for allocation.
  147. It's impossible to do this in a portable way; our current solution is
  148. to make the user tell us (with a default value set at compile time).
  149. If you can actually get the available space, it's a good idea to subtract
  150. a slop factor of 5% or so. }
  151. const
  152. DEFAULT_MAX_MEM = long(300000); { for total usage about 450K }
  153. {GLOBAL}
  154. function jpeg_mem_available (cinfo : j_common_ptr;
  155. min_bytes_needed : long;
  156. max_bytes_needed : long;
  157. already_allocated : long) : long;
  158. begin
  159. {jpeg_mem_available := cinfo^.mem^.max_memory_to_use - already_allocated;}
  160. jpeg_mem_available := max_bytes_needed;
  161. end;
  162. { Initial opening of a backing-store object. This must fill in the
  163. read/write/close pointers in the object. The read/write routines
  164. may take an error exit if the specified maximum file size is exceeded.
  165. (If jpeg_mem_available always returns a large value, this routine can
  166. just take an error exit.) }
  167. { Initial opening of a backing-store object. }
  168. {GLOBAL}
  169. procedure jpeg_open_backing_store (cinfo : j_common_ptr;
  170. info : backing_store_ptr;
  171. total_bytes_needed : long);
  172. begin
  173. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  174. end;
  175. { These routines take care of any system-dependent initialization and
  176. cleanup required. jpeg_mem_init will be called before anything is
  177. allocated (and, therefore, nothing in cinfo is of use except the error
  178. manager pointer). It should return a suitable default value for
  179. max_memory_to_use; this may subsequently be overridden by the surrounding
  180. application. (Note that max_memory_to_use is only important if
  181. jpeg_mem_available chooses to consult it ... no one else will.)
  182. jpeg_mem_term may assume that all requested memory has been freed and that
  183. all opened backing-store objects have been closed. }
  184. { These routines take care of any system-dependent initialization and
  185. cleanup required. }
  186. {GLOBAL}
  187. function jpeg_mem_init (cinfo : j_common_ptr) : long;
  188. begin
  189. jpeg_mem_init := DEFAULT_MAX_MEM; { default for max_memory_to_use }
  190. end;
  191. {GLOBAL}
  192. procedure jpeg_mem_term (cinfo : j_common_ptr);
  193. begin
  194. end;
  195. end.