isbn 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. data/.gitignore +4 -0
  2. data/README +9 -0
  3. data/Rakefile +13 -0
  4. data/VERSION +1 -0
  5. data/isbn.gemspec +329 -0
  6. data/lib/isbn.rb +90 -0
  7. data/src/gocr-0.48/.cvsignore +6 -0
  8. data/src/gocr-0.48/AUTHORS +7 -0
  9. data/src/gocr-0.48/BUGS +55 -0
  10. data/src/gocr-0.48/CREDITS +17 -0
  11. data/src/gocr-0.48/HISTORY +243 -0
  12. data/src/gocr-0.48/INSTALL +83 -0
  13. data/src/gocr-0.48/Makefile +193 -0
  14. data/src/gocr-0.48/Makefile.in +193 -0
  15. data/src/gocr-0.48/README +165 -0
  16. data/src/gocr-0.48/READMEde.txt +80 -0
  17. data/src/gocr-0.48/REMARK.txt +18 -0
  18. data/src/gocr-0.48/REVIEW +538 -0
  19. data/src/gocr-0.48/TODO +65 -0
  20. data/src/gocr-0.48/bin/.cvsignore +2 -0
  21. data/src/gocr-0.48/bin/create_db +38 -0
  22. data/src/gocr-0.48/bin/gocr.tcl +527 -0
  23. data/src/gocr-0.48/bin/gocr_chk.sh +44 -0
  24. data/src/gocr-0.48/configure +4689 -0
  25. data/src/gocr-0.48/configure.in +71 -0
  26. data/src/gocr-0.48/doc/.#Makefile.1.6 +39 -0
  27. data/src/gocr-0.48/doc/.cvsignore +2 -0
  28. data/src/gocr-0.48/doc/Makefile +39 -0
  29. data/src/gocr-0.48/doc/Makefile.in +39 -0
  30. data/src/gocr-0.48/doc/example.dtd +53 -0
  31. data/src/gocr-0.48/doc/example.xml +21 -0
  32. data/src/gocr-0.48/doc/examples.txt +67 -0
  33. data/src/gocr-0.48/doc/gocr.html +578 -0
  34. data/src/gocr-0.48/doc/unicode.txt +57 -0
  35. data/src/gocr-0.48/examples/.#Makefile.1.22 +166 -0
  36. data/src/gocr-0.48/examples/4x6.png +0 -0
  37. data/src/gocr-0.48/examples/4x6.txt +2 -0
  38. data/src/gocr-0.48/examples/5x7.png +0 -0
  39. data/src/gocr-0.48/examples/5x7.png.txt +2 -0
  40. data/src/gocr-0.48/examples/5x8.png +0 -0
  41. data/src/gocr-0.48/examples/5x8.png.txt +2 -0
  42. data/src/gocr-0.48/examples/Makefile +166 -0
  43. data/src/gocr-0.48/examples/color.fig +20 -0
  44. data/src/gocr-0.48/examples/ex.fig +16 -0
  45. data/src/gocr-0.48/examples/font.tex +22 -0
  46. data/src/gocr-0.48/examples/font1.tex +46 -0
  47. data/src/gocr-0.48/examples/font2.fig +27 -0
  48. data/src/gocr-0.48/examples/font_nw.tex +24 -0
  49. data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
  50. data/src/gocr-0.48/examples/handwrt1.txt +10 -0
  51. data/src/gocr-0.48/examples/inverse.fig +20 -0
  52. data/src/gocr-0.48/examples/matrix.jpg +0 -0
  53. data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
  54. data/src/gocr-0.48/examples/ocr-a-subset.png.txt +4 -0
  55. data/src/gocr-0.48/examples/ocr-a.png +0 -0
  56. data/src/gocr-0.48/examples/ocr-a.txt +6 -0
  57. data/src/gocr-0.48/examples/ocr-b.png +0 -0
  58. data/src/gocr-0.48/examples/ocr-b.png.txt +4 -0
  59. data/src/gocr-0.48/examples/polish.tex +28 -0
  60. data/src/gocr-0.48/examples/rotate45.fig +14 -0
  61. data/src/gocr-0.48/examples/score +36 -0
  62. data/src/gocr-0.48/examples/text.tex +28 -0
  63. data/src/gocr-0.48/gocr.spec +143 -0
  64. data/src/gocr-0.48/gpl.html +537 -0
  65. data/src/gocr-0.48/include/.cvsignore +2 -0
  66. data/src/gocr-0.48/include/config.h +36 -0
  67. data/src/gocr-0.48/include/config.h.in +36 -0
  68. data/src/gocr-0.48/include/version.h +2 -0
  69. data/src/gocr-0.48/install-sh +3 -0
  70. data/src/gocr-0.48/make.bat +57 -0
  71. data/src/gocr-0.48/man/.cvsignore +2 -0
  72. data/src/gocr-0.48/man/Makefile +29 -0
  73. data/src/gocr-0.48/man/Makefile.in +29 -0
  74. data/src/gocr-0.48/man/man1/gocr.1 +166 -0
  75. data/src/gocr-0.48/src/.cvsignore +4 -0
  76. data/src/gocr-0.48/src/Makefile +132 -0
  77. data/src/gocr-0.48/src/Makefile.in +132 -0
  78. data/src/gocr-0.48/src/amiga.h +31 -0
  79. data/src/gocr-0.48/src/barcode.c +846 -0
  80. data/src/gocr-0.48/src/barcode.c.orig +593 -0
  81. data/src/gocr-0.48/src/barcode.h +11 -0
  82. data/src/gocr-0.48/src/box.c +372 -0
  83. data/src/gocr-0.48/src/database.c +462 -0
  84. data/src/gocr-0.48/src/detect.c +943 -0
  85. data/src/gocr-0.48/src/gocr.c +373 -0
  86. data/src/gocr-0.48/src/gocr.h +288 -0
  87. data/src/gocr-0.48/src/jconv.c +168 -0
  88. data/src/gocr-0.48/src/job.c +84 -0
  89. data/src/gocr-0.48/src/lines.c +350 -0
  90. data/src/gocr-0.48/src/list.c +334 -0
  91. data/src/gocr-0.48/src/list.h +90 -0
  92. data/src/gocr-0.48/src/ocr0.c +6756 -0
  93. data/src/gocr-0.48/src/ocr0.h +63 -0
  94. data/src/gocr-0.48/src/ocr0n.c +1475 -0
  95. data/src/gocr-0.48/src/ocr1.c +85 -0
  96. data/src/gocr-0.48/src/ocr1.h +3 -0
  97. data/src/gocr-0.48/src/otsu.c +289 -0
  98. data/src/gocr-0.48/src/otsu.h +23 -0
  99. data/src/gocr-0.48/src/output.c +289 -0
  100. data/src/gocr-0.48/src/output.h +37 -0
  101. data/src/gocr-0.48/src/pcx.c +153 -0
  102. data/src/gocr-0.48/src/pcx.h +9 -0
  103. data/src/gocr-0.48/src/pgm2asc.c +2893 -0
  104. data/src/gocr-0.48/src/pgm2asc.h +105 -0
  105. data/src/gocr-0.48/src/pixel.c +537 -0
  106. data/src/gocr-0.48/src/pnm.c +533 -0
  107. data/src/gocr-0.48/src/pnm.h +35 -0
  108. data/src/gocr-0.48/src/progress.c +87 -0
  109. data/src/gocr-0.48/src/progress.h +42 -0
  110. data/src/gocr-0.48/src/remove.c +703 -0
  111. data/src/gocr-0.48/src/tga.c +87 -0
  112. data/src/gocr-0.48/src/tga.h +6 -0
  113. data/src/gocr-0.48/src/unicode.c +1314 -0
  114. data/src/gocr-0.48/src/unicode.h +1257 -0
  115. data/src/jpeg-7/Makefile.am +133 -0
  116. data/src/jpeg-7/Makefile.in +1089 -0
  117. data/src/jpeg-7/README +322 -0
  118. data/src/jpeg-7/aclocal.m4 +8990 -0
  119. data/src/jpeg-7/ansi2knr.1 +36 -0
  120. data/src/jpeg-7/ansi2knr.c +739 -0
  121. data/src/jpeg-7/cderror.h +132 -0
  122. data/src/jpeg-7/cdjpeg.c +181 -0
  123. data/src/jpeg-7/cdjpeg.h +187 -0
  124. data/src/jpeg-7/change.log +270 -0
  125. data/src/jpeg-7/cjpeg.1 +325 -0
  126. data/src/jpeg-7/cjpeg.c +616 -0
  127. data/src/jpeg-7/ckconfig.c +402 -0
  128. data/src/jpeg-7/coderules.txt +118 -0
  129. data/src/jpeg-7/config.guess +1561 -0
  130. data/src/jpeg-7/config.sub +1686 -0
  131. data/src/jpeg-7/configure +17139 -0
  132. data/src/jpeg-7/configure.ac +317 -0
  133. data/src/jpeg-7/depcomp +630 -0
  134. data/src/jpeg-7/djpeg.1 +251 -0
  135. data/src/jpeg-7/djpeg.c +617 -0
  136. data/src/jpeg-7/example.c +433 -0
  137. data/src/jpeg-7/filelist.txt +215 -0
  138. data/src/jpeg-7/install-sh +520 -0
  139. data/src/jpeg-7/install.txt +1097 -0
  140. data/src/jpeg-7/jaricom.c +148 -0
  141. data/src/jpeg-7/jcapimin.c +282 -0
  142. data/src/jpeg-7/jcapistd.c +161 -0
  143. data/src/jpeg-7/jcarith.c +921 -0
  144. data/src/jpeg-7/jccoefct.c +453 -0
  145. data/src/jpeg-7/jccolor.c +459 -0
  146. data/src/jpeg-7/jcdctmgr.c +482 -0
  147. data/src/jpeg-7/jchuff.c +1612 -0
  148. data/src/jpeg-7/jcinit.c +65 -0
  149. data/src/jpeg-7/jcmainct.c +293 -0
  150. data/src/jpeg-7/jcmarker.c +667 -0
  151. data/src/jpeg-7/jcmaster.c +770 -0
  152. data/src/jpeg-7/jcomapi.c +106 -0
  153. data/src/jpeg-7/jconfig.bcc +48 -0
  154. data/src/jpeg-7/jconfig.cfg +45 -0
  155. data/src/jpeg-7/jconfig.dj +38 -0
  156. data/src/jpeg-7/jconfig.mac +43 -0
  157. data/src/jpeg-7/jconfig.manx +43 -0
  158. data/src/jpeg-7/jconfig.mc6 +52 -0
  159. data/src/jpeg-7/jconfig.sas +43 -0
  160. data/src/jpeg-7/jconfig.st +42 -0
  161. data/src/jpeg-7/jconfig.txt +155 -0
  162. data/src/jpeg-7/jconfig.vc +45 -0
  163. data/src/jpeg-7/jconfig.vms +37 -0
  164. data/src/jpeg-7/jconfig.wat +38 -0
  165. data/src/jpeg-7/jcparam.c +632 -0
  166. data/src/jpeg-7/jcprepct.c +358 -0
  167. data/src/jpeg-7/jcsample.c +545 -0
  168. data/src/jpeg-7/jctrans.c +381 -0
  169. data/src/jpeg-7/jdapimin.c +396 -0
  170. data/src/jpeg-7/jdapistd.c +275 -0
  171. data/src/jpeg-7/jdarith.c +762 -0
  172. data/src/jpeg-7/jdatadst.c +151 -0
  173. data/src/jpeg-7/jdatasrc.c +212 -0
  174. data/src/jpeg-7/jdcoefct.c +736 -0
  175. data/src/jpeg-7/jdcolor.c +396 -0
  176. data/src/jpeg-7/jdct.h +393 -0
  177. data/src/jpeg-7/jddctmgr.c +382 -0
  178. data/src/jpeg-7/jdhuff.c +1309 -0
  179. data/src/jpeg-7/jdinput.c +384 -0
  180. data/src/jpeg-7/jdmainct.c +512 -0
  181. data/src/jpeg-7/jdmarker.c +1360 -0
  182. data/src/jpeg-7/jdmaster.c +663 -0
  183. data/src/jpeg-7/jdmerge.c +400 -0
  184. data/src/jpeg-7/jdpostct.c +290 -0
  185. data/src/jpeg-7/jdsample.c +361 -0
  186. data/src/jpeg-7/jdtrans.c +136 -0
  187. data/src/jpeg-7/jerror.c +252 -0
  188. data/src/jpeg-7/jerror.h +304 -0
  189. data/src/jpeg-7/jfdctflt.c +174 -0
  190. data/src/jpeg-7/jfdctfst.c +230 -0
  191. data/src/jpeg-7/jfdctint.c +4348 -0
  192. data/src/jpeg-7/jidctflt.c +242 -0
  193. data/src/jpeg-7/jidctfst.c +368 -0
  194. data/src/jpeg-7/jidctint.c +5137 -0
  195. data/src/jpeg-7/jinclude.h +91 -0
  196. data/src/jpeg-7/jmemansi.c +167 -0
  197. data/src/jpeg-7/jmemdos.c +638 -0
  198. data/src/jpeg-7/jmemdosa.asm +379 -0
  199. data/src/jpeg-7/jmemmac.c +289 -0
  200. data/src/jpeg-7/jmemmgr.c +1118 -0
  201. data/src/jpeg-7/jmemname.c +276 -0
  202. data/src/jpeg-7/jmemnobs.c +109 -0
  203. data/src/jpeg-7/jmemsys.h +198 -0
  204. data/src/jpeg-7/jmorecfg.h +369 -0
  205. data/src/jpeg-7/jpegint.h +395 -0
  206. data/src/jpeg-7/jpeglib.h +1135 -0
  207. data/src/jpeg-7/jpegtran.1 +272 -0
  208. data/src/jpeg-7/jpegtran.c +546 -0
  209. data/src/jpeg-7/jquant1.c +856 -0
  210. data/src/jpeg-7/jquant2.c +1310 -0
  211. data/src/jpeg-7/jutils.c +179 -0
  212. data/src/jpeg-7/jversion.h +14 -0
  213. data/src/jpeg-7/libjpeg.map +4 -0
  214. data/src/jpeg-7/libjpeg.txt +3067 -0
  215. data/src/jpeg-7/ltmain.sh +8406 -0
  216. data/src/jpeg-7/makcjpeg.st +36 -0
  217. data/src/jpeg-7/makdjpeg.st +36 -0
  218. data/src/jpeg-7/makeadsw.vc6 +77 -0
  219. data/src/jpeg-7/makeasln.vc9 +33 -0
  220. data/src/jpeg-7/makecdep.vc6 +82 -0
  221. data/src/jpeg-7/makecdsp.vc6 +130 -0
  222. data/src/jpeg-7/makecmak.vc6 +159 -0
  223. data/src/jpeg-7/makecvcp.vc9 +186 -0
  224. data/src/jpeg-7/makeddep.vc6 +82 -0
  225. data/src/jpeg-7/makeddsp.vc6 +130 -0
  226. data/src/jpeg-7/makedmak.vc6 +159 -0
  227. data/src/jpeg-7/makedvcp.vc9 +186 -0
  228. data/src/jpeg-7/makefile.ansi +220 -0
  229. data/src/jpeg-7/makefile.bcc +291 -0
  230. data/src/jpeg-7/makefile.dj +226 -0
  231. data/src/jpeg-7/makefile.manx +220 -0
  232. data/src/jpeg-7/makefile.mc6 +255 -0
  233. data/src/jpeg-7/makefile.mms +224 -0
  234. data/src/jpeg-7/makefile.sas +258 -0
  235. data/src/jpeg-7/makefile.unix +234 -0
  236. data/src/jpeg-7/makefile.vc +217 -0
  237. data/src/jpeg-7/makefile.vms +142 -0
  238. data/src/jpeg-7/makefile.wat +239 -0
  239. data/src/jpeg-7/makejdep.vc6 +423 -0
  240. data/src/jpeg-7/makejdsp.vc6 +285 -0
  241. data/src/jpeg-7/makejdsw.vc6 +29 -0
  242. data/src/jpeg-7/makejmak.vc6 +425 -0
  243. data/src/jpeg-7/makejsln.vc9 +17 -0
  244. data/src/jpeg-7/makejvcp.vc9 +328 -0
  245. data/src/jpeg-7/makeproj.mac +213 -0
  246. data/src/jpeg-7/makerdep.vc6 +6 -0
  247. data/src/jpeg-7/makerdsp.vc6 +78 -0
  248. data/src/jpeg-7/makermak.vc6 +110 -0
  249. data/src/jpeg-7/makervcp.vc9 +133 -0
  250. data/src/jpeg-7/maketdep.vc6 +43 -0
  251. data/src/jpeg-7/maketdsp.vc6 +122 -0
  252. data/src/jpeg-7/maketmak.vc6 +131 -0
  253. data/src/jpeg-7/maketvcp.vc9 +178 -0
  254. data/src/jpeg-7/makewdep.vc6 +6 -0
  255. data/src/jpeg-7/makewdsp.vc6 +78 -0
  256. data/src/jpeg-7/makewmak.vc6 +110 -0
  257. data/src/jpeg-7/makewvcp.vc9 +133 -0
  258. data/src/jpeg-7/makljpeg.st +68 -0
  259. data/src/jpeg-7/maktjpeg.st +30 -0
  260. data/src/jpeg-7/makvms.opt +4 -0
  261. data/src/jpeg-7/missing +376 -0
  262. data/src/jpeg-7/rdbmp.c +439 -0
  263. data/src/jpeg-7/rdcolmap.c +253 -0
  264. data/src/jpeg-7/rdgif.c +38 -0
  265. data/src/jpeg-7/rdjpgcom.1 +63 -0
  266. data/src/jpeg-7/rdjpgcom.c +515 -0
  267. data/src/jpeg-7/rdppm.c +459 -0
  268. data/src/jpeg-7/rdrle.c +387 -0
  269. data/src/jpeg-7/rdswitch.c +365 -0
  270. data/src/jpeg-7/rdtarga.c +500 -0
  271. data/src/jpeg-7/structure.txt +945 -0
  272. data/src/jpeg-7/testimg.bmp +0 -0
  273. data/src/jpeg-7/testimg.jpg +0 -0
  274. data/src/jpeg-7/testimg.ppm +4 -0
  275. data/src/jpeg-7/testimgp.jpg +0 -0
  276. data/src/jpeg-7/testorig.jpg +0 -0
  277. data/src/jpeg-7/testprog.jpg +0 -0
  278. data/src/jpeg-7/transupp.c +1533 -0
  279. data/src/jpeg-7/transupp.h +205 -0
  280. data/src/jpeg-7/usage.txt +605 -0
  281. data/src/jpeg-7/wizard.txt +211 -0
  282. data/src/jpeg-7/wrbmp.c +442 -0
  283. data/src/jpeg-7/wrgif.c +399 -0
  284. data/src/jpeg-7/wrjpgcom.1 +103 -0
  285. data/src/jpeg-7/wrjpgcom.c +583 -0
  286. data/src/jpeg-7/wrppm.c +269 -0
  287. data/src/jpeg-7/wrrle.c +305 -0
  288. data/src/jpeg-7/wrtarga.c +253 -0
  289. data/test/isbn_test.rb +7 -0
  290. data/test/test_helper.rb +7 -0
  291. metadata +345 -0
@@ -0,0 +1,276 @@
1
+ /*
2
+ * jmemname.c
3
+ *
4
+ * Copyright (C) 1992-1997, Thomas G. Lane.
5
+ * This file is part of the Independent JPEG Group's software.
6
+ * For conditions of distribution and use, see the accompanying README file.
7
+ *
8
+ * This file provides a generic implementation of the system-dependent
9
+ * portion of the JPEG memory manager. This implementation assumes that
10
+ * you must explicitly construct a name for each temp file.
11
+ * Also, the problem of determining the amount of memory available
12
+ * is shoved onto the user.
13
+ */
14
+
15
+ #define JPEG_INTERNALS
16
+ #include "jinclude.h"
17
+ #include "jpeglib.h"
18
+ #include "jmemsys.h" /* import the system-dependent declarations */
19
+
20
+ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
21
+ extern void * malloc JPP((size_t size));
22
+ extern void free JPP((void *ptr));
23
+ #endif
24
+
25
+ #ifndef SEEK_SET /* pre-ANSI systems may not define this; */
26
+ #define SEEK_SET 0 /* if not, assume 0 is correct */
27
+ #endif
28
+
29
+ #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
30
+ #define READ_BINARY "r"
31
+ #define RW_BINARY "w+"
32
+ #else
33
+ #ifdef VMS /* VMS is very nonstandard */
34
+ #define READ_BINARY "rb", "ctx=stm"
35
+ #define RW_BINARY "w+b", "ctx=stm"
36
+ #else /* standard ANSI-compliant case */
37
+ #define READ_BINARY "rb"
38
+ #define RW_BINARY "w+b"
39
+ #endif
40
+ #endif
41
+
42
+
43
+ /*
44
+ * Selection of a file name for a temporary file.
45
+ * This is system-dependent!
46
+ *
47
+ * The code as given is suitable for most Unix systems, and it is easily
48
+ * modified for most non-Unix systems. Some notes:
49
+ * 1. The temp file is created in the directory named by TEMP_DIRECTORY.
50
+ * The default value is /usr/tmp, which is the conventional place for
51
+ * creating large temp files on Unix. On other systems you'll probably
52
+ * want to change the file location. You can do this by editing the
53
+ * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h.
54
+ *
55
+ * 2. If you need to change the file name as well as its location,
56
+ * you can override the TEMP_FILE_NAME macro. (Note that this is
57
+ * actually a printf format string; it must contain %s and %d.)
58
+ * Few people should need to do this.
59
+ *
60
+ * 3. mktemp() is used to ensure that multiple processes running
61
+ * simultaneously won't select the same file names. If your system
62
+ * doesn't have mktemp(), define NO_MKTEMP to do it the hard way.
63
+ * (If you don't have <errno.h>, also define NO_ERRNO_H.)
64
+ *
65
+ * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c
66
+ * will cause the temp files to be removed if you stop the program early.
67
+ */
68
+
69
+ #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */
70
+ #define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */
71
+ #endif
72
+
73
+ static int next_file_num; /* to distinguish among several temp files */
74
+
75
+ #ifdef NO_MKTEMP
76
+
77
+ #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
78
+ #define TEMP_FILE_NAME "%sJPG%03d.TMP"
79
+ #endif
80
+
81
+ #ifndef NO_ERRNO_H
82
+ #include <errno.h> /* to define ENOENT */
83
+ #endif
84
+
85
+ /* ANSI C specifies that errno is a macro, but on older systems it's more
86
+ * likely to be a plain int variable. And not all versions of errno.h
87
+ * bother to declare it, so we have to in order to be most portable. Thus:
88
+ */
89
+ #ifndef errno
90
+ extern int errno;
91
+ #endif
92
+
93
+
94
+ LOCAL(void)
95
+ select_file_name (char * fname)
96
+ {
97
+ FILE * tfile;
98
+
99
+ /* Keep generating file names till we find one that's not in use */
100
+ for (;;) {
101
+ next_file_num++; /* advance counter */
102
+ sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
103
+ if ((tfile = fopen(fname, READ_BINARY)) == NULL) {
104
+ /* fopen could have failed for a reason other than the file not
105
+ * being there; for example, file there but unreadable.
106
+ * If <errno.h> isn't available, then we cannot test the cause.
107
+ */
108
+ #ifdef ENOENT
109
+ if (errno != ENOENT)
110
+ continue;
111
+ #endif
112
+ break;
113
+ }
114
+ fclose(tfile); /* oops, it's there; close tfile & try again */
115
+ }
116
+ }
117
+
118
+ #else /* ! NO_MKTEMP */
119
+
120
+ /* Note that mktemp() requires the initial filename to end in six X's */
121
+ #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
122
+ #define TEMP_FILE_NAME "%sJPG%dXXXXXX"
123
+ #endif
124
+
125
+ LOCAL(void)
126
+ select_file_name (char * fname)
127
+ {
128
+ next_file_num++; /* advance counter */
129
+ sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
130
+ mktemp(fname); /* make sure file name is unique */
131
+ /* mktemp replaces the trailing XXXXXX with a unique string of characters */
132
+ }
133
+
134
+ #endif /* NO_MKTEMP */
135
+
136
+
137
+ /*
138
+ * Memory allocation and freeing are controlled by the regular library
139
+ * routines malloc() and free().
140
+ */
141
+
142
+ GLOBAL(void *)
143
+ jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
144
+ {
145
+ return (void *) malloc(sizeofobject);
146
+ }
147
+
148
+ GLOBAL(void)
149
+ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
150
+ {
151
+ free(object);
152
+ }
153
+
154
+
155
+ /*
156
+ * "Large" objects are treated the same as "small" ones.
157
+ * NB: although we include FAR keywords in the routine declarations,
158
+ * this file won't actually work in 80x86 small/medium model; at least,
159
+ * you probably won't be able to process useful-size images in only 64KB.
160
+ */
161
+
162
+ GLOBAL(void FAR *)
163
+ jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
164
+ {
165
+ return (void FAR *) malloc(sizeofobject);
166
+ }
167
+
168
+ GLOBAL(void)
169
+ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
170
+ {
171
+ free(object);
172
+ }
173
+
174
+
175
+ /*
176
+ * This routine computes the total memory space available for allocation.
177
+ * It's impossible to do this in a portable way; our current solution is
178
+ * to make the user tell us (with a default value set at compile time).
179
+ * If you can actually get the available space, it's a good idea to subtract
180
+ * a slop factor of 5% or so.
181
+ */
182
+
183
+ #ifndef DEFAULT_MAX_MEM /* so can override from makefile */
184
+ #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */
185
+ #endif
186
+
187
+ GLOBAL(long)
188
+ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
189
+ long max_bytes_needed, long already_allocated)
190
+ {
191
+ return cinfo->mem->max_memory_to_use - already_allocated;
192
+ }
193
+
194
+
195
+ /*
196
+ * Backing store (temporary file) management.
197
+ * Backing store objects are only used when the value returned by
198
+ * jpeg_mem_available is less than the total space needed. You can dispense
199
+ * with these routines if you have plenty of virtual memory; see jmemnobs.c.
200
+ */
201
+
202
+
203
+ METHODDEF(void)
204
+ read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
205
+ void FAR * buffer_address,
206
+ long file_offset, long byte_count)
207
+ {
208
+ if (fseek(info->temp_file, file_offset, SEEK_SET))
209
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
210
+ if (JFREAD(info->temp_file, buffer_address, byte_count)
211
+ != (size_t) byte_count)
212
+ ERREXIT(cinfo, JERR_TFILE_READ);
213
+ }
214
+
215
+
216
+ METHODDEF(void)
217
+ write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
218
+ void FAR * buffer_address,
219
+ long file_offset, long byte_count)
220
+ {
221
+ if (fseek(info->temp_file, file_offset, SEEK_SET))
222
+ ERREXIT(cinfo, JERR_TFILE_SEEK);
223
+ if (JFWRITE(info->temp_file, buffer_address, byte_count)
224
+ != (size_t) byte_count)
225
+ ERREXIT(cinfo, JERR_TFILE_WRITE);
226
+ }
227
+
228
+
229
+ METHODDEF(void)
230
+ close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
231
+ {
232
+ fclose(info->temp_file); /* close the file */
233
+ unlink(info->temp_name); /* delete the file */
234
+ /* If your system doesn't have unlink(), use remove() instead.
235
+ * remove() is the ANSI-standard name for this function, but if
236
+ * your system was ANSI you'd be using jmemansi.c, right?
237
+ */
238
+ TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
239
+ }
240
+
241
+
242
+ /*
243
+ * Initial opening of a backing-store object.
244
+ */
245
+
246
+ GLOBAL(void)
247
+ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
248
+ long total_bytes_needed)
249
+ {
250
+ select_file_name(info->temp_name);
251
+ if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL)
252
+ ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
253
+ info->read_backing_store = read_backing_store;
254
+ info->write_backing_store = write_backing_store;
255
+ info->close_backing_store = close_backing_store;
256
+ TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
257
+ }
258
+
259
+
260
+ /*
261
+ * These routines take care of any system-dependent initialization and
262
+ * cleanup required.
263
+ */
264
+
265
+ GLOBAL(long)
266
+ jpeg_mem_init (j_common_ptr cinfo)
267
+ {
268
+ next_file_num = 0; /* initialize temp file name generator */
269
+ return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
270
+ }
271
+
272
+ GLOBAL(void)
273
+ jpeg_mem_term (j_common_ptr cinfo)
274
+ {
275
+ /* no work */
276
+ }
@@ -0,0 +1,109 @@
1
+ /*
2
+ * jmemnobs.c
3
+ *
4
+ * Copyright (C) 1992-1996, Thomas G. Lane.
5
+ * This file is part of the Independent JPEG Group's software.
6
+ * For conditions of distribution and use, see the accompanying README file.
7
+ *
8
+ * This file provides a really simple implementation of the system-
9
+ * dependent portion of the JPEG memory manager. This implementation
10
+ * assumes that no backing-store files are needed: all required space
11
+ * can be obtained from malloc().
12
+ * This is very portable in the sense that it'll compile on almost anything,
13
+ * but you'd better have lots of main memory (or virtual memory) if you want
14
+ * to process big images.
15
+ * Note that the max_memory_to_use option is ignored by this implementation.
16
+ */
17
+
18
+ #define JPEG_INTERNALS
19
+ #include "jinclude.h"
20
+ #include "jpeglib.h"
21
+ #include "jmemsys.h" /* import the system-dependent declarations */
22
+
23
+ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
24
+ extern void * malloc JPP((size_t size));
25
+ extern void free JPP((void *ptr));
26
+ #endif
27
+
28
+
29
+ /*
30
+ * Memory allocation and freeing are controlled by the regular library
31
+ * routines malloc() and free().
32
+ */
33
+
34
+ GLOBAL(void *)
35
+ jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
36
+ {
37
+ return (void *) malloc(sizeofobject);
38
+ }
39
+
40
+ GLOBAL(void)
41
+ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
42
+ {
43
+ free(object);
44
+ }
45
+
46
+
47
+ /*
48
+ * "Large" objects are treated the same as "small" ones.
49
+ * NB: although we include FAR keywords in the routine declarations,
50
+ * this file won't actually work in 80x86 small/medium model; at least,
51
+ * you probably won't be able to process useful-size images in only 64KB.
52
+ */
53
+
54
+ GLOBAL(void FAR *)
55
+ jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
56
+ {
57
+ return (void FAR *) malloc(sizeofobject);
58
+ }
59
+
60
+ GLOBAL(void)
61
+ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
62
+ {
63
+ free(object);
64
+ }
65
+
66
+
67
+ /*
68
+ * This routine computes the total memory space available for allocation.
69
+ * Here we always say, "we got all you want bud!"
70
+ */
71
+
72
+ GLOBAL(long)
73
+ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
74
+ long max_bytes_needed, long already_allocated)
75
+ {
76
+ return max_bytes_needed;
77
+ }
78
+
79
+
80
+ /*
81
+ * Backing store (temporary file) management.
82
+ * Since jpeg_mem_available always promised the moon,
83
+ * this should never be called and we can just error out.
84
+ */
85
+
86
+ GLOBAL(void)
87
+ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
88
+ long total_bytes_needed)
89
+ {
90
+ ERREXIT(cinfo, JERR_NO_BACKING_STORE);
91
+ }
92
+
93
+
94
+ /*
95
+ * These routines take care of any system-dependent initialization and
96
+ * cleanup required. Here, there isn't any.
97
+ */
98
+
99
+ GLOBAL(long)
100
+ jpeg_mem_init (j_common_ptr cinfo)
101
+ {
102
+ return 0; /* just set max_memory_to_use to 0 */
103
+ }
104
+
105
+ GLOBAL(void)
106
+ jpeg_mem_term (j_common_ptr cinfo)
107
+ {
108
+ /* no work */
109
+ }
@@ -0,0 +1,198 @@
1
+ /*
2
+ * jmemsys.h
3
+ *
4
+ * Copyright (C) 1992-1997, Thomas G. Lane.
5
+ * This file is part of the Independent JPEG Group's software.
6
+ * For conditions of distribution and use, see the accompanying README file.
7
+ *
8
+ * This include file defines the interface between the system-independent
9
+ * and system-dependent portions of the JPEG memory manager. No other
10
+ * modules need include it. (The system-independent portion is jmemmgr.c;
11
+ * there are several different versions of the system-dependent portion.)
12
+ *
13
+ * This file works as-is for the system-dependent memory managers supplied
14
+ * in the IJG distribution. You may need to modify it if you write a
15
+ * custom memory manager. If system-dependent changes are needed in
16
+ * this file, the best method is to #ifdef them based on a configuration
17
+ * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR
18
+ * and USE_MAC_MEMMGR.
19
+ */
20
+
21
+
22
+ /* Short forms of external names for systems with brain-damaged linkers. */
23
+
24
+ #ifdef NEED_SHORT_EXTERNAL_NAMES
25
+ #define jpeg_get_small jGetSmall
26
+ #define jpeg_free_small jFreeSmall
27
+ #define jpeg_get_large jGetLarge
28
+ #define jpeg_free_large jFreeLarge
29
+ #define jpeg_mem_available jMemAvail
30
+ #define jpeg_open_backing_store jOpenBackStore
31
+ #define jpeg_mem_init jMemInit
32
+ #define jpeg_mem_term jMemTerm
33
+ #endif /* NEED_SHORT_EXTERNAL_NAMES */
34
+
35
+
36
+ /*
37
+ * These two functions are used to allocate and release small chunks of
38
+ * memory. (Typically the total amount requested through jpeg_get_small is
39
+ * no more than 20K or so; this will be requested in chunks of a few K each.)
40
+ * Behavior should be the same as for the standard library functions malloc
41
+ * and free; in particular, jpeg_get_small must return NULL on failure.
42
+ * On most systems, these ARE malloc and free. jpeg_free_small is passed the
43
+ * size of the object being freed, just in case it's needed.
44
+ * On an 80x86 machine using small-data memory model, these manage near heap.
45
+ */
46
+
47
+ EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
48
+ EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
49
+ size_t sizeofobject));
50
+
51
+ /*
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
+ */
59
+
60
+ EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
61
+ size_t sizeofobject));
62
+ EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
63
+ size_t sizeofobject));
64
+
65
+ /*
66
+ * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
67
+ * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
68
+ * matter, but that case should never come into play). This macro is needed
69
+ * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
70
+ * On those machines, we expect that jconfig.h will provide a proper value.
71
+ * On machines with 32-bit flat address spaces, any large constant may be used.
72
+ *
73
+ * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
74
+ * size_t and will be a multiple of sizeof(align_type).
75
+ */
76
+
77
+ #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
78
+ #define MAX_ALLOC_CHUNK 1000000000L
79
+ #endif
80
+
81
+ /*
82
+ * This routine computes the total space still available for allocation by
83
+ * jpeg_get_large. If more space than this is needed, backing store will be
84
+ * used. NOTE: any memory already allocated must not be counted.
85
+ *
86
+ * There is a minimum space requirement, corresponding to the minimum
87
+ * feasible buffer sizes; jmemmgr.c will request that much space even if
88
+ * jpeg_mem_available returns zero. The maximum space needed, enough to hold
89
+ * all working storage in memory, is also passed in case it is useful.
90
+ * Finally, the total space already allocated is passed. If no better
91
+ * method is available, cinfo->mem->max_memory_to_use - already_allocated
92
+ * is often a suitable calculation.
93
+ *
94
+ * It is OK for jpeg_mem_available to underestimate the space available
95
+ * (that'll just lead to more backing-store access than is really necessary).
96
+ * However, an overestimate will lead to failure. Hence it's wise to subtract
97
+ * a slop factor from the true available space. 5% should be enough.
98
+ *
99
+ * On machines with lots of virtual memory, any large constant may be returned.
100
+ * Conversely, zero may be returned to always use the minimum amount of memory.
101
+ */
102
+
103
+ EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
104
+ long min_bytes_needed,
105
+ long max_bytes_needed,
106
+ long already_allocated));
107
+
108
+
109
+ /*
110
+ * This structure holds whatever state is needed to access a single
111
+ * backing-store object. The read/write/close method pointers are called
112
+ * by jmemmgr.c to manipulate the backing-store object; all other fields
113
+ * are private to the system-dependent backing store routines.
114
+ */
115
+
116
+ #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
117
+
118
+
119
+ #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
120
+
121
+ typedef unsigned short XMSH; /* type of extended-memory handles */
122
+ typedef unsigned short EMSH; /* type of expanded-memory handles */
123
+
124
+ typedef union {
125
+ short file_handle; /* DOS file handle if it's a temp file */
126
+ XMSH xms_handle; /* handle if it's a chunk of XMS */
127
+ EMSH ems_handle; /* handle if it's a chunk of EMS */
128
+ } handle_union;
129
+
130
+ #endif /* USE_MSDOS_MEMMGR */
131
+
132
+ #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
133
+ #include <Files.h>
134
+ #endif /* USE_MAC_MEMMGR */
135
+
136
+
137
+ typedef struct backing_store_struct * backing_store_ptr;
138
+
139
+ typedef struct backing_store_struct {
140
+ /* Methods for reading/writing/closing this backing-store object */
141
+ JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
142
+ backing_store_ptr info,
143
+ void FAR * buffer_address,
144
+ long file_offset, long byte_count));
145
+ JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
146
+ backing_store_ptr info,
147
+ void FAR * buffer_address,
148
+ long file_offset, long byte_count));
149
+ JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
150
+ backing_store_ptr info));
151
+
152
+ /* Private fields for system-dependent backing-store management */
153
+ #ifdef USE_MSDOS_MEMMGR
154
+ /* For the MS-DOS manager (jmemdos.c), we need: */
155
+ handle_union handle; /* reference to backing-store storage object */
156
+ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
157
+ #else
158
+ #ifdef USE_MAC_MEMMGR
159
+ /* For the Mac manager (jmemmac.c), we need: */
160
+ short temp_file; /* file reference number to temp file */
161
+ FSSpec tempSpec; /* the FSSpec for the temp file */
162
+ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
163
+ #else
164
+ /* For a typical implementation with temp files, we need: */
165
+ FILE * temp_file; /* stdio reference to temp file */
166
+ char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
167
+ #endif
168
+ #endif
169
+ } backing_store_info;
170
+
171
+
172
+ /*
173
+ * Initial opening of a backing-store object. This must fill in the
174
+ * read/write/close pointers in the object. The read/write routines
175
+ * may take an error exit if the specified maximum file size is exceeded.
176
+ * (If jpeg_mem_available always returns a large value, this routine can
177
+ * just take an error exit.)
178
+ */
179
+
180
+ EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
181
+ backing_store_ptr info,
182
+ long total_bytes_needed));
183
+
184
+
185
+ /*
186
+ * These routines take care of any system-dependent initialization and
187
+ * cleanup required. jpeg_mem_init will be called before anything is
188
+ * allocated (and, therefore, nothing in cinfo is of use except the error
189
+ * manager pointer). It should return a suitable default value for
190
+ * max_memory_to_use; this may subsequently be overridden by the surrounding
191
+ * application. (Note that max_memory_to_use is only important if
192
+ * jpeg_mem_available chooses to consult it ... no one else will.)
193
+ * jpeg_mem_term may assume that all requested memory has been freed and that
194
+ * all opened backing-store objects have been closed.
195
+ */
196
+
197
+ EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
198
+ EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));