home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / jpeg / part14 < prev    next >
Encoding:
Text File  |  1992-12-16  |  58.1 KB  |  1,759 lines

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v34i068:  jpeg - JPEG image compression, Part14/18
  4. Message-ID: <1992Dec17.165025.6732@sparky.imd.sterling.com>
  5. X-Md4-Signature: 01119ec83fcad38b2fc2682c428fa68d
  6. Date: Thu, 17 Dec 1992 16:50:25 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jpeg-info@uunet.uu.net (Independent JPEG Group)
  10. Posting-number: Volume 34, Issue 68
  11. Archive-name: jpeg/part14
  12. Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
  13. Supersedes: jpeg: Volume 29, Issue 1-18
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # Contents:  jconfig.h jfwddct.c jrdrle.c jwrjfif.c makefile.mc6
  20. # Wrapped by kent@sparky on Wed Dec 16 20:52:30 1992
  21. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 14 (of 18)."'
  24. if test -f 'jconfig.h' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'jconfig.h'\"
  26. else
  27.   echo shar: Extracting \"'jconfig.h'\" \(12022 characters\)
  28.   sed "s/^X//" >'jconfig.h' <<'END_OF_FILE'
  29. X/*
  30. X * jconfig.h
  31. X *
  32. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  33. X * This file is part of the Independent JPEG Group's software.
  34. X * For conditions of distribution and use, see the accompanying README file.
  35. X *
  36. X * This file contains preprocessor declarations that help customize
  37. X * the JPEG software for a particular application, machine, or compiler.
  38. X * Edit these declarations as needed (or add -D flags to the Makefile).
  39. X */
  40. X
  41. X
  42. X/*
  43. X * These symbols indicate the properties of your machine or compiler.
  44. X * The conditional definitions given may do the right thing already,
  45. X * but you'd best look them over closely, especially if your compiler
  46. X * does not handle full ANSI C.  An ANSI-compliant C compiler should
  47. X * provide all the necessary features; __STDC__ is supposed to be
  48. X * predefined by such compilers.
  49. X */
  50. X
  51. X/*
  52. X * HAVE_STDC is tested below to see whether ANSI features are available.
  53. X * We avoid testing __STDC__ directly for arcane reasons of portability.
  54. X * (On some compilers, __STDC__ is only defined if a switch is given,
  55. X * but the switch also disables machine-specific features we need to get at.
  56. X * In that case, -DHAVE_STDC in the Makefile is a convenient solution.)
  57. X */
  58. X
  59. X#ifdef __STDC__            /* if compiler claims to be ANSI, believe it */
  60. X#define HAVE_STDC
  61. X#endif
  62. X
  63. X
  64. X/* Does your compiler support function prototypes? */
  65. X/* (If not, you also need to use ansi2knr, see SETUP) */
  66. X
  67. X#ifdef HAVE_STDC        /* ANSI C compilers always have prototypes */
  68. X#define PROTO
  69. X#else
  70. X#ifdef __cplusplus        /* So do C++ compilers */
  71. X#define PROTO
  72. X#endif
  73. X#endif
  74. X
  75. X/* Does your compiler support the declaration "unsigned char" ? */
  76. X/* How about "unsigned short" ? */
  77. X
  78. X#ifdef HAVE_STDC        /* ANSI C compilers must support both */
  79. X#define HAVE_UNSIGNED_CHAR
  80. X#define HAVE_UNSIGNED_SHORT
  81. X#endif
  82. X
  83. X/* Define this if an ordinary "char" type is unsigned.
  84. X * If you're not sure, leaving it undefined will work at some cost in speed.
  85. X * If you defined HAVE_UNSIGNED_CHAR then it doesn't matter very much.
  86. X */
  87. X
  88. X/* #define CHAR_IS_UNSIGNED */
  89. X
  90. X/* Define this if your compiler implements ">>" on signed values as a logical
  91. X * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
  92. X * which is the normal and rational definition.
  93. X */
  94. X
  95. X/* #define RIGHT_SHIFT_IS_UNSIGNED */
  96. X
  97. X/* Define "void" as "char" if your compiler doesn't know about type void.
  98. X * NOTE: be sure to define void such that "void *" represents the most general
  99. X * pointer type, e.g., that returned by malloc().
  100. X */
  101. X
  102. X/* #define void char */
  103. X
  104. X/* Define const as empty if your compiler doesn't know the "const" keyword. */
  105. X/* (Even if it does, defining const as empty won't break anything.) */
  106. X
  107. X#ifndef HAVE_STDC        /* ANSI C and C++ compilers should know it. */
  108. X#ifndef __cplusplus
  109. X#define const
  110. X#endif
  111. X#endif
  112. X
  113. X/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
  114. X * unless you are using a large-data memory model or 80386 flat-memory mode.
  115. X * On less brain-damaged CPUs this symbol must not be defined.
  116. X * (Defining this symbol causes large data structures to be referenced through
  117. X * "far" pointers and to be allocated with a special version of malloc.)
  118. X */
  119. X
  120. X#ifdef MSDOS
  121. X#define NEED_FAR_POINTERS
  122. X#endif
  123. X
  124. X
  125. X/* The next three symbols only affect the system-dependent user interface
  126. X * modules (jcmain.c, jdmain.c).  You can ignore these if you are supplying
  127. X * your own user interface code.
  128. X */
  129. X
  130. X/* Define this if you want to name both input and output files on the command
  131. X * line, rather than using stdout and optionally stdin.  You MUST do this if
  132. X * your system can't cope with binary I/O to stdin/stdout.  See comments at
  133. X * head of jcmain.c or jdmain.c.
  134. X */
  135. X
  136. X#ifdef MSDOS            /* two-file style is needed for PCs */
  137. X#ifndef USE_SETMODE        /* unless you have setmode() */
  138. X#define TWO_FILE_COMMANDLINE
  139. X#endif
  140. X#endif
  141. X#ifdef THINK_C            /* it's needed for Macintosh too */
  142. X#define TWO_FILE_COMMANDLINE
  143. X#endif
  144. X
  145. X/* Define this if your system needs explicit cleanup of temporary files.
  146. X * This is crucial under MS-DOS, where the temporary "files" may be areas
  147. X * of extended memory; on most other systems it's not as important.
  148. X */
  149. X
  150. X#ifdef MSDOS
  151. X#define NEED_SIGNAL_CATCHER
  152. X#endif
  153. X
  154. X/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
  155. X * This is necessary on systems that distinguish text files from binary files,
  156. X * and is harmless on most systems that don't.  If you have one of the rare
  157. X * systems that complains about the "b" spec, define this symbol.
  158. X */
  159. X
  160. X/* #define DONT_USE_B_MODE */
  161. X
  162. X
  163. X/* If you're getting bored, that's the end of the symbols you HAVE to
  164. X * worry about.  Go fix the makefile and compile.
  165. X */
  166. X
  167. X
  168. X/* If your compiler supports inline functions, define INLINE
  169. X * as the inline keyword; otherwise define it as empty.
  170. X */
  171. X
  172. X#ifdef __GNUC__            /* for instance, GNU C knows about inline */
  173. X#define INLINE __inline__
  174. X#endif
  175. X#ifndef INLINE            /* default is to define it as empty */
  176. X#define INLINE
  177. X#endif
  178. X
  179. X/* On a few systems, type boolean and/or macros FALSE, TRUE may appear
  180. X * in standard header files.  Or you may have conflicts with application-
  181. X * specific header files that you want to include together with these files.
  182. X * In that case you need only comment out these definitions.
  183. X */
  184. X
  185. Xtypedef int boolean;
  186. X#undef FALSE            /* in case these macros already exist */
  187. X#undef TRUE
  188. X#define FALSE    0        /* values of boolean */
  189. X#define TRUE    1
  190. X
  191. X/* This defines the size of the I/O buffers for entropy compression
  192. X * and decompression; you could reduce it if memory is tight.
  193. X */
  194. X
  195. X#define JPEG_BUF_SIZE    4096 /* bytes */
  196. X
  197. X
  198. X
  199. X/* These symbols determine the JPEG functionality supported. */
  200. X
  201. X/*
  202. X * These defines indicate whether to include various optional functions.
  203. X * Undefining some of these symbols will produce a smaller but less capable
  204. X * program file.  Note that you can leave certain source files out of the
  205. X * compilation/linking process if you've #undef'd the corresponding symbols.
  206. X * (You may HAVE to do that if your compiler doesn't like null source files.)
  207. X */
  208. X
  209. X/* Arithmetic coding is unsupported for legal reasons.  Complaints to IBM. */
  210. X
  211. X/* Encoder capability options: */
  212. X#undef  C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
  213. X#undef  C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files?  (NYI) */
  214. X#define ENTROPY_OPT_SUPPORTED        /* Optimization of entropy coding parms? */
  215. X#define INPUT_SMOOTHING_SUPPORTED   /* Input image smoothing option? */
  216. X/* Decoder capability options: */
  217. X#undef  D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
  218. X#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  219. X#define BLOCK_SMOOTHING_SUPPORTED   /* Block smoothing during decoding? */
  220. X#define QUANT_1PASS_SUPPORTED    /* 1-pass color quantization? */
  221. X#define QUANT_2PASS_SUPPORTED    /* 2-pass color quantization? */
  222. X/* these defines indicate which JPEG file formats are allowed */
  223. X#define JFIF_SUPPORTED        /* JFIF or "raw JPEG" files */
  224. X#undef  JTIFF_SUPPORTED        /* JPEG-in-TIFF (not yet implemented) */
  225. X/* these defines indicate which image (non-JPEG) file formats are allowed */
  226. X#define GIF_SUPPORTED        /* GIF image file format */
  227. X/* #define RLE_SUPPORTED */    /* RLE image file format (by default, no) */
  228. X#define PPM_SUPPORTED        /* PPM/PGM image file format */
  229. X#define TARGA_SUPPORTED        /* Targa image file format */
  230. X#undef  TIFF_SUPPORTED        /* TIFF image file format (not yet impl.) */
  231. X
  232. X/* more capability options later, no doubt */
  233. X
  234. X
  235. X/*
  236. X * Define exactly one of these three symbols to indicate whether you want
  237. X * 8-bit, 12-bit, or 16-bit sample (pixel component) values.  8-bit is the
  238. X * default and is nearly always the right thing to use.  You can use 12-bit if
  239. X * you need to support image formats with more than 8 bits of resolution in a
  240. X * color value.  16-bit should only be used for the lossless JPEG mode (not
  241. X * currently supported).  Note that 12- and 16-bit values take up twice as
  242. X * much memory as 8-bit!
  243. X * Note: if you select 12- or 16-bit precision, it is dangerous to turn off
  244. X * ENTROPY_OPT_SUPPORTED.  The standard Huffman tables are only good for 8-bit
  245. X * precision, so jchuff.c normally uses entropy optimization to compute
  246. X * usable tables for higher precision.  If you don't want to do optimization,
  247. X * you'll have to supply different default Huffman tables.
  248. X */
  249. X
  250. X#define EIGHT_BIT_SAMPLES
  251. X#undef  TWELVE_BIT_SAMPLES
  252. X#undef  SIXTEEN_BIT_SAMPLES
  253. X
  254. X
  255. X
  256. X/*
  257. X * The remaining definitions don't need to be hand-edited in most cases.
  258. X * You may need to change these if you have a machine with unusual data
  259. X * types; for example, "char" not 8 bits, "short" not 16 bits,
  260. X * or "long" not 32 bits.  We don't care whether "int" is 16 or 32 bits,
  261. X * but it had better be at least 16.
  262. X */
  263. X
  264. X/* First define the representation of a single pixel element value. */
  265. X
  266. X#ifdef EIGHT_BIT_SAMPLES
  267. X/* JSAMPLE should be the smallest type that will hold the values 0..255.
  268. X * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
  269. X * If you have only signed chars, and you are more worried about speed than
  270. X * memory usage, it might be a win to make JSAMPLE be short.
  271. X */
  272. X
  273. X#ifdef HAVE_UNSIGNED_CHAR
  274. X
  275. Xtypedef unsigned char JSAMPLE;
  276. X#define GETJSAMPLE(value)  (value)
  277. X
  278. X#else /* not HAVE_UNSIGNED_CHAR */
  279. X#ifdef CHAR_IS_UNSIGNED
  280. X
  281. Xtypedef char JSAMPLE;
  282. X#define GETJSAMPLE(value)  (value)
  283. X
  284. X#else /* not CHAR_IS_UNSIGNED */
  285. X
  286. Xtypedef char JSAMPLE;
  287. X#define GETJSAMPLE(value)  ((value) & 0xFF)
  288. X
  289. X#endif /* CHAR_IS_UNSIGNED */
  290. X#endif /* HAVE_UNSIGNED_CHAR */
  291. X
  292. X#define BITS_IN_JSAMPLE   8
  293. X#define MAXJSAMPLE    255
  294. X#define CENTERJSAMPLE    128
  295. X
  296. X#endif /* EIGHT_BIT_SAMPLES */
  297. X
  298. X
  299. X#ifdef TWELVE_BIT_SAMPLES
  300. X/* JSAMPLE should be the smallest type that will hold the values 0..4095. */
  301. X/* On nearly all machines "short" will do nicely. */
  302. X
  303. Xtypedef short JSAMPLE;
  304. X#define GETJSAMPLE(value)  (value)
  305. X
  306. X#define BITS_IN_JSAMPLE   12
  307. X#define MAXJSAMPLE    4095
  308. X#define CENTERJSAMPLE    2048
  309. X
  310. X#endif /* TWELVE_BIT_SAMPLES */
  311. X
  312. X
  313. X#ifdef SIXTEEN_BIT_SAMPLES
  314. X/* JSAMPLE should be the smallest type that will hold the values 0..65535. */
  315. X
  316. X#ifdef HAVE_UNSIGNED_SHORT
  317. X
  318. Xtypedef unsigned short JSAMPLE;
  319. X#define GETJSAMPLE(value)  (value)
  320. X
  321. X#else /* not HAVE_UNSIGNED_SHORT */
  322. X
  323. X/* If int is 32 bits this'll be horrendously inefficient storage-wise.
  324. X * But since we don't actually support 16-bit samples (ie lossless coding) yet,
  325. X * I'm not going to worry about making a smarter definition ...
  326. X */
  327. Xtypedef unsigned int JSAMPLE;
  328. X#define GETJSAMPLE(value)  (value)
  329. X
  330. X#endif /* HAVE_UNSIGNED_SHORT */
  331. X
  332. X#define BITS_IN_JSAMPLE    16
  333. X#define MAXJSAMPLE    65535
  334. X#define CENTERJSAMPLE    32768
  335. X
  336. X#endif /* SIXTEEN_BIT_SAMPLES */
  337. X
  338. X
  339. X/* Here we define the representation of a DCT frequency coefficient.
  340. X * This should be a signed 16-bit value; "short" is usually right.
  341. X * It's important that this be exactly 16 bits, no more and no less;
  342. X * more will cost you a BIG hit of memory, less will give wrong answers.
  343. X */
  344. X
  345. Xtypedef short JCOEF;
  346. X
  347. X
  348. X/* The remaining typedefs are used for various table entries and so forth.
  349. X * They must be at least as wide as specified; but making them too big
  350. X * won't cost a huge amount of memory, so we don't provide special
  351. X * extraction code like we did for JSAMPLE.  (In other words, these
  352. X * typedefs live at a different point on the speed/space tradeoff curve.)
  353. X */
  354. X
  355. X/* UINT8 must hold at least the values 0..255. */
  356. X
  357. X#ifdef HAVE_UNSIGNED_CHAR
  358. Xtypedef unsigned char UINT8;
  359. X#else /* not HAVE_UNSIGNED_CHAR */
  360. X#ifdef CHAR_IS_UNSIGNED
  361. Xtypedef char UINT8;
  362. X#else /* not CHAR_IS_UNSIGNED */
  363. Xtypedef short UINT8;
  364. X#endif /* CHAR_IS_UNSIGNED */
  365. X#endif /* HAVE_UNSIGNED_CHAR */
  366. X
  367. X/* UINT16 must hold at least the values 0..65535. */
  368. X
  369. X#ifdef HAVE_UNSIGNED_SHORT
  370. Xtypedef unsigned short UINT16;
  371. X#else /* not HAVE_UNSIGNED_SHORT */
  372. Xtypedef unsigned int UINT16;
  373. X#endif /* HAVE_UNSIGNED_SHORT */
  374. X
  375. X/* INT16 must hold at least the values -32768..32767. */
  376. X
  377. X#ifndef XMD_H            /* X11/xmd.h correctly defines INT16 */
  378. Xtypedef short INT16;
  379. X#endif
  380. X
  381. X/* INT32 must hold signed 32-bit values; if your machine happens */
  382. X/* to have 64-bit longs, you might want to change this. */
  383. X
  384. X#ifndef XMD_H            /* X11/xmd.h correctly defines INT32 */
  385. Xtypedef long INT32;
  386. X#endif
  387. END_OF_FILE
  388.   if test 12022 -ne `wc -c <'jconfig.h'`; then
  389.     echo shar: \"'jconfig.h'\" unpacked with wrong size!
  390.   fi
  391.   # end of 'jconfig.h'
  392. fi
  393. if test -f 'jfwddct.c' -a "${1}" != "-c" ; then 
  394.   echo shar: Will not clobber existing file \"'jfwddct.c'\"
  395. else
  396.   echo shar: Extracting \"'jfwddct.c'\" \(11760 characters\)
  397.   sed "s/^X//" >'jfwddct.c' <<'END_OF_FILE'
  398. X/*
  399. X * jfwddct.c
  400. X *
  401. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  402. X * This file is part of the Independent JPEG Group's software.
  403. X * For conditions of distribution and use, see the accompanying README file.
  404. X *
  405. X * This file contains the basic DCT (Discrete Cosine Transform)
  406. X * transformation subroutine.
  407. X *
  408. X * This implementation is based on an algorithm described in
  409. X *   C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
  410. X *   Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
  411. X *   Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
  412. X * The primary algorithm described there uses 11 multiplies and 29 adds.
  413. X * We use their alternate method with 12 multiplies and 32 adds.
  414. X * The advantage of this method is that no data path contains more than one
  415. X * multiplication; this allows a very simple and accurate implementation in
  416. X * scaled fixed-point arithmetic, with a minimal number of shifts.
  417. X */
  418. X
  419. X#include "jinclude.h"
  420. X
  421. X/*
  422. X * This routine is specialized to the case DCTSIZE = 8.
  423. X */
  424. X
  425. X#if DCTSIZE != 8
  426. X  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  427. X#endif
  428. X
  429. X
  430. X/*
  431. X * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
  432. X * on each column.  Direct algorithms are also available, but they are
  433. X * much more complex and seem not to be any faster when reduced to code.
  434. X *
  435. X * The poop on this scaling stuff is as follows:
  436. X *
  437. X * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
  438. X * larger than the true DCT outputs.  The final outputs are therefore
  439. X * a factor of N larger than desired; since N=8 this can be cured by
  440. X * a simple right shift at the end of the algorithm.  The advantage of
  441. X * this arrangement is that we save two multiplications per 1-D DCT,
  442. X * because the y0 and y4 outputs need not be divided by sqrt(N).
  443. X *
  444. X * We have to do addition and subtraction of the integer inputs, which
  445. X * is no problem, and multiplication by fractional constants, which is
  446. X * a problem to do in integer arithmetic.  We multiply all the constants
  447. X * by CONST_SCALE and convert them to integer constants (thus retaining
  448. X * CONST_BITS bits of precision in the constants).  After doing a
  449. X * multiplication we have to divide the product by CONST_SCALE, with proper
  450. X * rounding, to produce the correct output.  This division can be done
  451. X * cheaply as a right shift of CONST_BITS bits.  We postpone shifting
  452. X * as long as possible so that partial sums can be added together with
  453. X * full fractional precision.
  454. X *
  455. X * The outputs of the first pass are scaled up by PASS1_BITS bits so that
  456. X * they are represented to better-than-integral precision.  These outputs
  457. X * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
  458. X * with the recommended scaling.  (To scale up 12-bit sample data, an
  459. X * intermediate INT32 array would be needed.)
  460. X *
  461. X * To avoid overflow of the 32-bit intermediate results in pass 2, we must
  462. X * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 25.  Error analysis
  463. X * shows that the values given below are the most effective.
  464. X */
  465. X
  466. X#ifdef EIGHT_BIT_SAMPLES
  467. X#define CONST_BITS  13
  468. X#define PASS1_BITS  2
  469. X#else
  470. X#define CONST_BITS  13
  471. X#define PASS1_BITS  0        /* lose a little precision to avoid overflow */
  472. X#endif
  473. X
  474. X#define ONE    ((INT32) 1)
  475. X
  476. X#define CONST_SCALE (ONE << CONST_BITS)
  477. X
  478. X/* Convert a positive real constant to an integer scaled by CONST_SCALE. */
  479. X
  480. X#define FIX(x)    ((INT32) ((x) * CONST_SCALE + 0.5))
  481. X
  482. X/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
  483. X * causing a lot of useless floating-point operations at run time.
  484. X * To get around this we use the following pre-calculated constants.
  485. X * If you change CONST_BITS you may want to add appropriate values.
  486. X * (With a reasonable C compiler, you can just rely on the FIX() macro...)
  487. X */
  488. X
  489. X#if CONST_BITS == 13
  490. X#define FIX_0_298631336  ((INT32)  2446)    /* FIX(0.298631336) */
  491. X#define FIX_0_390180644  ((INT32)  3196)    /* FIX(0.390180644) */
  492. X#define FIX_0_541196100  ((INT32)  4433)    /* FIX(0.541196100) */
  493. X#define FIX_0_765366865  ((INT32)  6270)    /* FIX(0.765366865) */
  494. X#define FIX_0_899976223  ((INT32)  7373)    /* FIX(0.899976223) */
  495. X#define FIX_1_175875602  ((INT32)  9633)    /* FIX(1.175875602) */
  496. X#define FIX_1_501321110  ((INT32)  12299)    /* FIX(1.501321110) */
  497. X#define FIX_1_847759065  ((INT32)  15137)    /* FIX(1.847759065) */
  498. X#define FIX_1_961570560  ((INT32)  16069)    /* FIX(1.961570560) */
  499. X#define FIX_2_053119869  ((INT32)  16819)    /* FIX(2.053119869) */
  500. X#define FIX_2_562915447  ((INT32)  20995)    /* FIX(2.562915447) */
  501. X#define FIX_3_072711026  ((INT32)  25172)    /* FIX(3.072711026) */
  502. X#else
  503. X#define FIX_0_298631336  FIX(0.298631336)
  504. X#define FIX_0_390180644  FIX(0.390180644)
  505. X#define FIX_0_541196100  FIX(0.541196100)
  506. X#define FIX_0_765366865  FIX(0.765366865)
  507. X#define FIX_0_899976223  FIX(0.899976223)
  508. X#define FIX_1_175875602  FIX(1.175875602)
  509. X#define FIX_1_501321110  FIX(1.501321110)
  510. X#define FIX_1_847759065  FIX(1.847759065)
  511. X#define FIX_1_961570560  FIX(1.961570560)
  512. X#define FIX_2_053119869  FIX(2.053119869)
  513. X#define FIX_2_562915447  FIX(2.562915447)
  514. X#define FIX_3_072711026  FIX(3.072711026)
  515. X#endif
  516. X
  517. X
  518. X/* Descale and correctly round an INT32 value that's scaled by N bits.
  519. X * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
  520. X * the fudge factor is correct for either sign of X.
  521. X */
  522. X
  523. X#define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  524. X
  525. X/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
  526. X * For 8-bit samples with the recommended scaling, all the variable
  527. X * and constant values involved are no more than 16 bits wide, so a
  528. X * 16x16->32 bit multiply can be used instead of a full 32x32 multiply;
  529. X * this provides a useful speedup on many machines.
  530. X * There is no way to specify a 16x16->32 multiply in portable C, but
  531. X * some C compilers will do the right thing if you provide the correct
  532. X * combination of casts.
  533. X * NB: for 12-bit samples, a full 32-bit multiplication will be needed.
  534. X */
  535. X
  536. X#ifdef EIGHT_BIT_SAMPLES
  537. X#ifdef SHORTxSHORT_32        /* may work if 'int' is 32 bits */
  538. X#define MULTIPLY(var,const)  (((INT16) (var)) * ((INT16) (const)))
  539. X#endif
  540. X#ifdef SHORTxLCONST_32        /* known to work with Microsoft C 6.0 */
  541. X#define MULTIPLY(var,const)  (((INT16) (var)) * ((INT32) (const)))
  542. X#endif
  543. X#endif
  544. X
  545. X#ifndef MULTIPLY        /* default definition */
  546. X#define MULTIPLY(var,const)  ((var) * (const))
  547. X#endif
  548. X
  549. X
  550. X/*
  551. X * Perform the forward DCT on one block of samples.
  552. X */
  553. X
  554. XGLOBAL void
  555. Xj_fwd_dct (DCTBLOCK data)
  556. X{
  557. X  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  558. X  INT32 tmp10, tmp11, tmp12, tmp13;
  559. X  INT32 z1, z2, z3, z4, z5;
  560. X  register DCTELEM *dataptr;
  561. X  int rowctr;
  562. X  SHIFT_TEMPS
  563. X
  564. X  /* Pass 1: process rows. */
  565. X  /* Note results are scaled up by sqrt(8) compared to a true DCT; */
  566. X  /* furthermore, we scale the results by 2**PASS1_BITS. */
  567. X
  568. X  dataptr = data;
  569. X  for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  570. X    tmp0 = dataptr[0] + dataptr[7];
  571. X    tmp7 = dataptr[0] - dataptr[7];
  572. X    tmp1 = dataptr[1] + dataptr[6];
  573. X    tmp6 = dataptr[1] - dataptr[6];
  574. X    tmp2 = dataptr[2] + dataptr[5];
  575. X    tmp5 = dataptr[2] - dataptr[5];
  576. X    tmp3 = dataptr[3] + dataptr[4];
  577. X    tmp4 = dataptr[3] - dataptr[4];
  578. X    
  579. X    /* Even part per LL&M figure 1 --- note that published figure is faulty;
  580. X     * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
  581. X     */
  582. X    
  583. X    tmp10 = tmp0 + tmp3;
  584. X    tmp13 = tmp0 - tmp3;
  585. X    tmp11 = tmp1 + tmp2;
  586. X    tmp12 = tmp1 - tmp2;
  587. X    
  588. X    dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  589. X    dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  590. X    
  591. X    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  592. X    dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  593. X                   CONST_BITS-PASS1_BITS);
  594. X    dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  595. X                   CONST_BITS-PASS1_BITS);
  596. X    
  597. X    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  598. X     * cK represents cos(K*pi/16).
  599. X     * i0..i3 in the paper are tmp4..tmp7 here.
  600. X     */
  601. X    
  602. X    z1 = tmp4 + tmp7;
  603. X    z2 = tmp5 + tmp6;
  604. X    z3 = tmp4 + tmp6;
  605. X    z4 = tmp5 + tmp7;
  606. X    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  607. X    
  608. X    tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  609. X    tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  610. X    tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  611. X    tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  612. X    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  613. X    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  614. X    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  615. X    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  616. X    
  617. X    z3 += z5;
  618. X    z4 += z5;
  619. X    
  620. X    dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  621. X    dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  622. X    dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  623. X    dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  624. X    
  625. X    dataptr += DCTSIZE;        /* advance pointer to next row */
  626. X  }
  627. X
  628. X  /* Pass 2: process columns. */
  629. X  /* Note that we must descale the results by a factor of 8 == 2**3, */
  630. X  /* and also undo the PASS1_BITS scaling. */
  631. X
  632. X  dataptr = data;
  633. X  for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  634. X    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  635. X    tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  636. X    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  637. X    tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  638. X    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  639. X    tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  640. X    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  641. X    tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  642. X    
  643. X    /* Even part per LL&M figure 1 --- note that published figure is faulty;
  644. X     * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
  645. X     */
  646. X    
  647. X    tmp10 = tmp0 + tmp3;
  648. X    tmp13 = tmp0 - tmp3;
  649. X    tmp11 = tmp1 + tmp2;
  650. X    tmp12 = tmp1 - tmp2;
  651. X    
  652. X    dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS+3);
  653. X    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS+3);
  654. X    
  655. X    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  656. X    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  657. X                       CONST_BITS+PASS1_BITS+3);
  658. X    dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  659. X                       CONST_BITS+PASS1_BITS+3);
  660. X    
  661. X    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
  662. X     * cK represents cos(K*pi/16).
  663. X     * i0..i3 in the paper are tmp4..tmp7 here.
  664. X     */
  665. X    
  666. X    z1 = tmp4 + tmp7;
  667. X    z2 = tmp5 + tmp6;
  668. X    z3 = tmp4 + tmp6;
  669. X    z4 = tmp5 + tmp7;
  670. X    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  671. X    
  672. X    tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  673. X    tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  674. X    tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  675. X    tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  676. X    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  677. X    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  678. X    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  679. X    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  680. X    
  681. X    z3 += z5;
  682. X    z4 += z5;
  683. X    
  684. X    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  685. X                       CONST_BITS+PASS1_BITS+3);
  686. X    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  687. X                       CONST_BITS+PASS1_BITS+3);
  688. X    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  689. X                       CONST_BITS+PASS1_BITS+3);
  690. X    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  691. X                       CONST_BITS+PASS1_BITS+3);
  692. X    
  693. X    dataptr++;            /* advance pointer to next column */
  694. X  }
  695. X}
  696. END_OF_FILE
  697.   if test 11760 -ne `wc -c <'jfwddct.c'`; then
  698.     echo shar: \"'jfwddct.c'\" unpacked with wrong size!
  699.   fi
  700.   # end of 'jfwddct.c'
  701. fi
  702. if test -f 'jrdrle.c' -a "${1}" != "-c" ; then 
  703.   echo shar: Will not clobber existing file \"'jrdrle.c'\"
  704. else
  705.   echo shar: Extracting \"'jrdrle.c'\" \(11363 characters\)
  706.   sed "s/^X//" >'jrdrle.c' <<'END_OF_FILE'
  707. X/*
  708. X * jrdrle.c
  709. X *
  710. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  711. X * This file is part of the Independent JPEG Group's software.
  712. X * For conditions of distribution and use, see the accompanying README file.
  713. X *
  714. X * This file contains routines to read input images in Utah RLE format.
  715. X * The Utah Raster Toolkit library is required (version 3.0).
  716. X *
  717. X * These routines may need modification for non-Unix environments or
  718. X * specialized applications.  As they stand, they assume input from
  719. X * an ordinary stdio stream.  They further assume that reading begins
  720. X * at the start of the file; input_init may need work if the
  721. X * user interface has already read some data (e.g., to determine that
  722. X * the file is indeed RLE format).
  723. X *
  724. X * These routines are invoked via the methods get_input_row
  725. X * and input_init/term.
  726. X *
  727. X * Based on code contributed by Mike Lijewski.
  728. X */
  729. X
  730. X#include "jinclude.h"
  731. X
  732. X#ifdef RLE_SUPPORTED
  733. X
  734. X/* rle.h is provided by the Utah Raster Toolkit. */
  735. X
  736. X#include <rle.h>
  737. X
  738. X
  739. X/*
  740. X * load_image assumes that JSAMPLE has the same representation as rle_pixel,
  741. X * to wit, "unsigned char".  Hence we can't cope with 12- or 16-bit samples.
  742. X */
  743. X
  744. X#ifndef EIGHT_BIT_SAMPLES
  745. X  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
  746. X#endif
  747. X
  748. X
  749. X/*
  750. X * We support the following types of RLE files:
  751. X *   
  752. X *   GRAYSCALE   - 8 bits, no colormap
  753. X *   PSEUDOCOLOR - 8 bits, colormap
  754. X *   TRUECOLOR   - 24 bits, colormap
  755. X *   DIRECTCOLOR - 24 bits, no colormap
  756. X *
  757. X * For now, we ignore any alpha channel in the image.
  758. X */
  759. X
  760. Xtypedef enum { GRAYSCALE, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
  761. X
  762. Xstatic rle_kind visual;        /* actual type of input file */
  763. X
  764. X/*
  765. X * Since RLE stores scanlines bottom-to-top, we have to invert the image
  766. X * to conform to JPEG's top-to-bottom order.  To do this, we read the
  767. X * incoming image into a virtual array on the first get_input_row call,
  768. X * then fetch the required row from the virtual array on subsequent calls.
  769. X */
  770. X
  771. Xstatic big_sarray_ptr image;    /* single array for GRAYSCALE/PSEUDOCOLOR */
  772. Xstatic big_sarray_ptr red_channel; /* three arrays for TRUECOLOR/DIRECTCOLOR */
  773. Xstatic big_sarray_ptr green_channel;
  774. Xstatic big_sarray_ptr blue_channel;
  775. Xstatic long cur_row_number;    /* last row# read from virtual array */
  776. X
  777. Xstatic rle_hdr header;        /* Input file information */
  778. Xstatic rle_map *colormap;    /* RLE colormap, if any */
  779. X
  780. X
  781. X/*
  782. X * Read the file header; return image size and component count.
  783. X */
  784. X
  785. XMETHODDEF void
  786. Xinput_init (compress_info_ptr cinfo)
  787. X{
  788. X  long width, height;
  789. X
  790. X  /* Use RLE library routine to get the header info */
  791. X  header.rle_file = cinfo->input_file;
  792. X  switch (rle_get_setup(&header)) {
  793. X  case RLE_SUCCESS:
  794. X    /* A-OK */
  795. X    break;
  796. X  case RLE_NOT_RLE:
  797. X    ERREXIT(cinfo->emethods, "Not an RLE file");
  798. X    break;
  799. X  case RLE_NO_SPACE:
  800. X    ERREXIT(cinfo->emethods, "Insufficient memory for RLE header");
  801. X    break;
  802. X  case RLE_EMPTY:
  803. X    ERREXIT(cinfo->emethods, "Empty RLE file");
  804. X    break;
  805. X  case RLE_EOF:
  806. X    ERREXIT(cinfo->emethods, "Premature EOF in RLE header");
  807. X    break;
  808. X  default:
  809. X    ERREXIT(cinfo->emethods, "Bogus RLE error code");
  810. X    break;
  811. X  }
  812. X
  813. X  /* Figure out what we have, set private vars and return values accordingly */
  814. X  
  815. X  width  = header.xmax - header.xmin + 1;
  816. X  height = header.ymax - header.ymin + 1;
  817. X  header.xmin = 0;        /* realign horizontally */
  818. X  header.xmax = width-1;
  819. X
  820. X  cinfo->image_width      = width;
  821. X  cinfo->image_height     = height;
  822. X  cinfo->data_precision   = 8;  /* we can only handle 8 bit data */
  823. X
  824. X  if (header.ncolors == 1 && header.ncmap == 0) {
  825. X    visual     = GRAYSCALE;
  826. X    TRACEMS(cinfo->emethods, 1, "Gray-scale RLE file");
  827. X  } else if (header.ncolors == 1 && header.ncmap == 3) {
  828. X    visual     = PSEUDOCOLOR;
  829. X    colormap   = header.cmap;
  830. X    TRACEMS1(cinfo->emethods, 1, "Colormapped RLE file with map of length %d",
  831. X         1 << header.cmaplen);
  832. X  } else if (header.ncolors == 3 && header.ncmap == 3) {
  833. X    visual     = TRUECOLOR;
  834. X    colormap   = header.cmap;
  835. X    TRACEMS1(cinfo->emethods, 1, "Full-color RLE file with map of length %d",
  836. X         1 << header.cmaplen);
  837. X  } else if (header.ncolors == 3 && header.ncmap == 0) {
  838. X    visual     = DIRECTCOLOR;
  839. X    TRACEMS(cinfo->emethods, 1, "Full-color RLE file");
  840. X  } else
  841. X    ERREXIT(cinfo->emethods, "Can't handle this RLE setup");
  842. X  
  843. X  switch (visual) {
  844. X  case GRAYSCALE:
  845. X    /* request one big array to hold the grayscale image */
  846. X    image = (*cinfo->emethods->request_big_sarray) (width, height, 1L);
  847. X    cinfo->in_color_space   = CS_GRAYSCALE;
  848. X    cinfo->input_components = 1;
  849. X    break;
  850. X  case PSEUDOCOLOR:
  851. X    /* request one big array to hold the pseudocolor image */
  852. X    image = (*cinfo->emethods->request_big_sarray) (width, height, 1L);
  853. X    cinfo->in_color_space   = CS_RGB;
  854. X    cinfo->input_components = 3;
  855. X    break;
  856. X  case TRUECOLOR:
  857. X  case DIRECTCOLOR:
  858. X    /* request three big arrays to hold the RGB channels */
  859. X    red_channel   = (*cinfo->emethods->request_big_sarray) (width, height, 1L);
  860. X    green_channel = (*cinfo->emethods->request_big_sarray) (width, height, 1L);
  861. X    blue_channel  = (*cinfo->emethods->request_big_sarray) (width, height, 1L);
  862. X    cinfo->in_color_space   = CS_RGB;
  863. X    cinfo->input_components = 3;
  864. X    break;
  865. X  }
  866. X
  867. X  cinfo->total_passes++;    /* count file reading as separate pass */
  868. X}
  869. X
  870. X
  871. X/*
  872. X * Read one row of pixels.
  873. X * These are called only after load_image has read the image into
  874. X * the virtual array(s).
  875. X */
  876. X
  877. X
  878. XMETHODDEF void
  879. Xget_grayscale_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  880. X/* This is used for GRAYSCALE images */
  881. X{
  882. X  JSAMPROW inputrows[1];    /* a pseudo JSAMPARRAY structure */
  883. X
  884. X  cur_row_number--;        /* work down in array */
  885. X  
  886. X  inputrows[0] = *((*cinfo->emethods->access_big_sarray)
  887. X            (image, cur_row_number, FALSE));
  888. X
  889. X  jcopy_sample_rows(inputrows, 0, pixel_row, 0, 1, cinfo->image_width);
  890. X}
  891. X
  892. X
  893. XMETHODDEF void
  894. Xget_pseudocolor_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  895. X/* This is used for PSEUDOCOLOR images */
  896. X{
  897. X  long col;
  898. X  JSAMPROW image_ptr, ptr0, ptr1, ptr2;
  899. X  int val;
  900. X
  901. X  cur_row_number--;        /* work down in array */
  902. X  
  903. X  image_ptr = *((*cinfo->emethods->access_big_sarray)
  904. X        (image, cur_row_number, FALSE));
  905. X
  906. X  ptr0 = pixel_row[0];
  907. X  ptr1 = pixel_row[1];
  908. X  ptr2 = pixel_row[2];
  909. X  
  910. X  for (col = cinfo->image_width; col > 0; col--) {
  911. X    val = GETJSAMPLE(*image_ptr++);
  912. X    *ptr0++ = colormap[val      ] >> 8;
  913. X    *ptr1++ = colormap[val + 256] >> 8;
  914. X    *ptr2++ = colormap[val + 512] >> 8;
  915. X  }
  916. X}
  917. X
  918. X
  919. XMETHODDEF void
  920. Xget_truecolor_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  921. X/* This is used for TRUECOLOR images */
  922. X/* The colormap consists of 3 independent lookup tables */
  923. X{
  924. X  long col;
  925. X  JSAMPROW red_ptr, green_ptr, blue_ptr, ptr0, ptr1, ptr2;
  926. X  
  927. X  cur_row_number--;        /* work down in array */
  928. X  
  929. X  red_ptr   = *((*cinfo->emethods->access_big_sarray)
  930. X        (red_channel, cur_row_number, FALSE));
  931. X  green_ptr = *((*cinfo->emethods->access_big_sarray)
  932. X        (green_channel, cur_row_number, FALSE));
  933. X  blue_ptr  = *((*cinfo->emethods->access_big_sarray)
  934. X        (blue_channel, cur_row_number, FALSE));
  935. X  
  936. X  ptr0 = pixel_row[0];
  937. X  ptr1 = pixel_row[1];
  938. X  ptr2 = pixel_row[2];
  939. X  
  940. X  for (col = cinfo->image_width; col > 0; col--) {
  941. X    *ptr0++ = colormap[GETJSAMPLE(*red_ptr++)        ] >> 8;
  942. X    *ptr1++ = colormap[GETJSAMPLE(*green_ptr++) + 256] >> 8;
  943. X    *ptr2++ = colormap[GETJSAMPLE(*blue_ptr++)  + 512] >> 8;
  944. X  }
  945. X}
  946. X
  947. X
  948. XMETHODDEF void
  949. Xget_directcolor_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  950. X/* This is used for DIRECTCOLOR images */
  951. X{
  952. X  JSAMPROW inputrows[3];    /* a pseudo JSAMPARRAY structure */
  953. X
  954. X  cur_row_number--;        /* work down in array */
  955. X  
  956. X  inputrows[0] = *((*cinfo->emethods->access_big_sarray)
  957. X            (red_channel, cur_row_number, FALSE));
  958. X  inputrows[1] = *((*cinfo->emethods->access_big_sarray)
  959. X            (green_channel, cur_row_number, FALSE));
  960. X  inputrows[2] = *((*cinfo->emethods->access_big_sarray)
  961. X            (blue_channel, cur_row_number, FALSE));
  962. X
  963. X  jcopy_sample_rows(inputrows, 0, pixel_row, 0, 3, cinfo->image_width);
  964. X}
  965. X
  966. X
  967. X/*
  968. X * Load the color channels into separate arrays.  We have to do
  969. X * this because RLE files start at the lower left while the JPEG standard
  970. X * has them starting in the upper left.  This is called the first time
  971. X * we want to get a row of input.  What we do is load the RLE data into
  972. X * big arrays and then call the appropriate routine to read one row from
  973. X * the big arrays.  We also change cinfo->methods->get_input_row so that
  974. X * subsequent calls go straight to the row-reading routine.
  975. X */
  976. X
  977. XMETHODDEF void
  978. Xload_image (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
  979. X{
  980. X  long row;
  981. X  rle_pixel *rle_row[3];
  982. X  
  983. X  /* Read the RLE data into our virtual array(s).
  984. X   * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
  985. X   * and (b) we are not on a machine where FAR pointers differ from regular.
  986. X   */
  987. X  RLE_CLR_BIT(header, RLE_ALPHA); /* don't read the alpha channel */
  988. X
  989. X  switch (visual) {
  990. X  case GRAYSCALE:
  991. X  case PSEUDOCOLOR:
  992. X    for (row = 0; row < cinfo->image_height; row++) {
  993. X      (*cinfo->methods->progress_monitor) (cinfo, row, cinfo->image_height);
  994. X      /*
  995. X       * Read a row of the image directly into our big array.
  996. X       * Too bad this doesn't seem to return any indication of errors :-(.
  997. X       */
  998. X      rle_row[0] = (rle_pixel *) *((*cinfo->emethods->access_big_sarray)
  999. X                    (image, row, TRUE));
  1000. X      rle_getrow(&header, rle_row);
  1001. X    }
  1002. X    break;
  1003. X  case TRUECOLOR:
  1004. X  case DIRECTCOLOR:
  1005. X    for (row = 0; row < cinfo->image_height; row++) {
  1006. X      (*cinfo->methods->progress_monitor) (cinfo, row, cinfo->image_height);
  1007. X      /*
  1008. X       * Read a row of the image directly into our big arrays.
  1009. X       * Too bad this doesn't seem to return any indication of errors :-(.
  1010. X       */
  1011. X      rle_row[0] = (rle_pixel *) *((*cinfo->emethods->access_big_sarray)
  1012. X                    (red_channel, row, TRUE));
  1013. X      rle_row[1] = (rle_pixel *) *((*cinfo->emethods->access_big_sarray)
  1014. X                    (green_channel, row, TRUE));
  1015. X      rle_row[2] = (rle_pixel *) *((*cinfo->emethods->access_big_sarray)
  1016. X                    (blue_channel, row, TRUE));
  1017. X      rle_getrow(&header, rle_row);
  1018. X    }
  1019. X    break;
  1020. X  }
  1021. X  cinfo->completed_passes++;
  1022. X  
  1023. X  /* Set up to call proper row-extraction routine in future */
  1024. X  switch (visual) {
  1025. X  case GRAYSCALE:
  1026. X    cinfo->methods->get_input_row = get_grayscale_row;
  1027. X    break;
  1028. X  case PSEUDOCOLOR:
  1029. X    cinfo->methods->get_input_row = get_pseudocolor_row;
  1030. X    break;
  1031. X  case TRUECOLOR:
  1032. X    cinfo->methods->get_input_row = get_truecolor_row;
  1033. X    break;
  1034. X  case DIRECTCOLOR:
  1035. X    cinfo->methods->get_input_row = get_directcolor_row;
  1036. X    break;
  1037. X  }
  1038. X
  1039. X  /* And fetch the topmost (bottommost) row */
  1040. X  cur_row_number = cinfo->image_height;
  1041. X  (*cinfo->methods->get_input_row) (cinfo, pixel_row);   
  1042. X}
  1043. X
  1044. X
  1045. X/*
  1046. X * Finish up at the end of the file.
  1047. X */
  1048. X
  1049. XMETHODDEF void
  1050. Xinput_term (compress_info_ptr cinfo)
  1051. X{
  1052. X  /* no work (we let free_all release the workspace) */
  1053. X}
  1054. X
  1055. X
  1056. X/*
  1057. X * The method selection routine for RLE format input.
  1058. X * Note that this must be called by the user interface before calling
  1059. X * jpeg_compress.  If multiple input formats are supported, the
  1060. X * user interface is responsible for discovering the file format and
  1061. X * calling the appropriate method selection routine.
  1062. X */
  1063. X
  1064. XGLOBAL void
  1065. Xjselrrle (compress_info_ptr cinfo)
  1066. X{
  1067. X  cinfo->methods->input_init    = input_init;
  1068. X  cinfo->methods->get_input_row = load_image; /* until first call */
  1069. X  cinfo->methods->input_term    = input_term;
  1070. X}
  1071. X
  1072. X#endif /* RLE_SUPPORTED */
  1073. END_OF_FILE
  1074.   if test 11363 -ne `wc -c <'jrdrle.c'`; then
  1075.     echo shar: \"'jrdrle.c'\" unpacked with wrong size!
  1076.   fi
  1077.   # end of 'jrdrle.c'
  1078. fi
  1079. if test -f 'jwrjfif.c' -a "${1}" != "-c" ; then 
  1080.   echo shar: Will not clobber existing file \"'jwrjfif.c'\"
  1081. else
  1082.   echo shar: Extracting \"'jwrjfif.c'\" \(11967 characters\)
  1083.   sed "s/^X//" >'jwrjfif.c' <<'END_OF_FILE'
  1084. X/*
  1085. X * jwrjfif.c
  1086. X *
  1087. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  1088. X * This file is part of the Independent JPEG Group's software.
  1089. X * For conditions of distribution and use, see the accompanying README file.
  1090. X *
  1091. X * This file contains routines to write standard JPEG file headers/markers.
  1092. X * The file format created is a raw JPEG data stream with (optionally) an
  1093. X * APP0 marker per the JFIF spec.  This will handle baseline and
  1094. X * JFIF-convention JPEG files, although there is currently no provision
  1095. X * for inserting a thumbnail image in the JFIF header.
  1096. X *
  1097. X * These routines may need modification for non-Unix environments or
  1098. X * specialized applications.  As they stand, they assume output to
  1099. X * an ordinary stdio stream.  However, the changes to write to something
  1100. X * else are localized in the macros appearing just below.
  1101. X *
  1102. X * These routines are invoked via the methods write_file_header,
  1103. X * write_scan_header, write_jpeg_data, write_scan_trailer, and
  1104. X * write_file_trailer.
  1105. X */
  1106. X
  1107. X#include "jinclude.h"
  1108. X
  1109. X#ifdef JFIF_SUPPORTED
  1110. X
  1111. X
  1112. X/*
  1113. X * To output to something other than a stdio stream, you'd need to redefine
  1114. X * these macros.
  1115. X */
  1116. X
  1117. X/* Write a single byte */
  1118. X#define emit_byte(cinfo,x)  putc((x), cinfo->output_file)
  1119. X
  1120. X/* Write some bytes from a (char *) buffer */
  1121. X#define WRITE_BYTES(cinfo,dataptr,datacount)  \
  1122. X  { if (JFWRITE(cinfo->output_file, dataptr, datacount) \
  1123. X    != (size_t) (datacount)) \
  1124. X      ERREXIT(cinfo->emethods, "Output file write error"); }
  1125. X
  1126. X/* Clean up and verify successful output */
  1127. X#define CHECK_OUTPUT(cinfo)  \
  1128. X  { fflush(cinfo->output_file); \
  1129. X    if (ferror(cinfo->output_file)) \
  1130. X      ERREXIT(cinfo->emethods, "Output file write error"); }
  1131. X
  1132. X
  1133. X/* End of stdio-specific code. */
  1134. X
  1135. X
  1136. Xtypedef enum {            /* JPEG marker codes */
  1137. X  M_SOF0  = 0xc0,
  1138. X  M_SOF1  = 0xc1,
  1139. X  M_SOF2  = 0xc2,
  1140. X  M_SOF3  = 0xc3,
  1141. X  
  1142. X  M_SOF5  = 0xc5,
  1143. X  M_SOF6  = 0xc6,
  1144. X  M_SOF7  = 0xc7,
  1145. X  
  1146. X  M_JPG   = 0xc8,
  1147. X  M_SOF9  = 0xc9,
  1148. X  M_SOF10 = 0xca,
  1149. X  M_SOF11 = 0xcb,
  1150. X  
  1151. X  M_SOF13 = 0xcd,
  1152. X  M_SOF14 = 0xce,
  1153. X  M_SOF15 = 0xcf,
  1154. X  
  1155. X  M_DHT   = 0xc4,
  1156. X  
  1157. X  M_DAC   = 0xcc,
  1158. X  
  1159. X  M_RST0  = 0xd0,
  1160. X  M_RST1  = 0xd1,
  1161. X  M_RST2  = 0xd2,
  1162. X  M_RST3  = 0xd3,
  1163. X  M_RST4  = 0xd4,
  1164. X  M_RST5  = 0xd5,
  1165. X  M_RST6  = 0xd6,
  1166. X  M_RST7  = 0xd7,
  1167. X  
  1168. X  M_SOI   = 0xd8,
  1169. X  M_EOI   = 0xd9,
  1170. X  M_SOS   = 0xda,
  1171. X  M_DQT   = 0xdb,
  1172. X  M_DNL   = 0xdc,
  1173. X  M_DRI   = 0xdd,
  1174. X  M_DHP   = 0xde,
  1175. X  M_EXP   = 0xdf,
  1176. X  
  1177. X  M_APP0  = 0xe0,
  1178. X  M_APP15 = 0xef,
  1179. X  
  1180. X  M_JPG0  = 0xf0,
  1181. X  M_JPG13 = 0xfd,
  1182. X  M_COM   = 0xfe,
  1183. X  
  1184. X  M_TEM   = 0x01,
  1185. X  
  1186. X  M_ERROR = 0x100
  1187. X} JPEG_MARKER;
  1188. X
  1189. X
  1190. XLOCAL void
  1191. Xemit_marker (compress_info_ptr cinfo, JPEG_MARKER mark)
  1192. X/* Emit a marker code */
  1193. X{
  1194. X  emit_byte(cinfo, 0xFF);
  1195. X  emit_byte(cinfo, mark);
  1196. X}
  1197. X
  1198. X
  1199. XLOCAL void
  1200. Xemit_2bytes (compress_info_ptr cinfo, int value)
  1201. X/* Emit a 2-byte integer; these are always MSB first in JPEG files */
  1202. X{
  1203. X  emit_byte(cinfo, (value >> 8) & 0xFF);
  1204. X  emit_byte(cinfo, value & 0xFF);
  1205. X}
  1206. X
  1207. X
  1208. XLOCAL int
  1209. Xemit_dqt (compress_info_ptr cinfo, int index)
  1210. X/* Emit a DQT marker */
  1211. X/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
  1212. X{
  1213. X  QUANT_TBL_PTR data = cinfo->quant_tbl_ptrs[index];
  1214. X  int prec = 0;
  1215. X  int i;
  1216. X  
  1217. X  for (i = 0; i < DCTSIZE2; i++) {
  1218. X    if (data[i] > 255)
  1219. X      prec = 1;
  1220. X  }
  1221. X
  1222. X  emit_marker(cinfo, M_DQT);
  1223. X  
  1224. X  emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  1225. X  
  1226. X  emit_byte(cinfo, index + (prec<<4));
  1227. X  
  1228. X  for (i = 0; i < DCTSIZE2; i++) {
  1229. X    if (prec)
  1230. X      emit_byte(cinfo, data[i] >> 8);
  1231. X    emit_byte(cinfo, data[i] & 0xFF);
  1232. X  }
  1233. X
  1234. X  return prec;
  1235. X}
  1236. X
  1237. X
  1238. XLOCAL void
  1239. Xemit_dht (compress_info_ptr cinfo, int index, boolean is_ac)
  1240. X/* Emit a DHT marker */
  1241. X{
  1242. X  HUFF_TBL * htbl;
  1243. X  int length, i;
  1244. X  
  1245. X  if (is_ac) {
  1246. X    htbl = cinfo->ac_huff_tbl_ptrs[index];
  1247. X    index += 0x10;        /* output index has AC bit set */
  1248. X  } else {
  1249. X    htbl = cinfo->dc_huff_tbl_ptrs[index];
  1250. X  }
  1251. X
  1252. X  if (htbl == NULL)
  1253. X    ERREXIT1(cinfo->emethods, "Huffman table 0x%02x was not defined", index);
  1254. X  
  1255. X  if (! htbl->sent_table) {
  1256. X    emit_marker(cinfo, M_DHT);
  1257. X    
  1258. X    length = 0;
  1259. X    for (i = 1; i <= 16; i++)
  1260. X      length += htbl->bits[i];
  1261. X    
  1262. X    emit_2bytes(cinfo, length + 2 + 1 + 16);
  1263. X    emit_byte(cinfo, index);
  1264. X    
  1265. X    for (i = 1; i <= 16; i++)
  1266. X      emit_byte(cinfo, htbl->bits[i]);
  1267. X    
  1268. X    for (i = 0; i < length; i++)
  1269. X      emit_byte(cinfo, htbl->huffval[i]);
  1270. X    
  1271. X    htbl->sent_table = TRUE;
  1272. X  }
  1273. X}
  1274. X
  1275. X
  1276. XLOCAL void
  1277. Xemit_dac (compress_info_ptr cinfo)
  1278. X/* Emit a DAC marker */
  1279. X/* Since the useful info is so small, we want to emit all the tables in */
  1280. X/* one DAC marker.  Therefore this routine does its own scan of the table. */
  1281. X{
  1282. X  char dc_in_use[NUM_ARITH_TBLS];
  1283. X  char ac_in_use[NUM_ARITH_TBLS];
  1284. X  int length, i;
  1285. X  
  1286. X  for (i = 0; i < NUM_ARITH_TBLS; i++)
  1287. X    dc_in_use[i] = ac_in_use[i] = 0;
  1288. X  
  1289. X  for (i = 0; i < cinfo->num_components; i++) {
  1290. X    dc_in_use[cinfo->comp_info[i].dc_tbl_no] = 1;
  1291. X    ac_in_use[cinfo->comp_info[i].ac_tbl_no] = 1;
  1292. X  }
  1293. X  
  1294. X  length = 0;
  1295. X  for (i = 0; i < NUM_ARITH_TBLS; i++)
  1296. X    length += dc_in_use[i] + ac_in_use[i];
  1297. X  
  1298. X  emit_marker(cinfo, M_DAC);
  1299. X  
  1300. X  emit_2bytes(cinfo, length*2 + 2);
  1301. X  
  1302. X  for (i = 0; i < NUM_ARITH_TBLS; i++) {
  1303. X    if (dc_in_use[i]) {
  1304. X      emit_byte(cinfo, i);
  1305. X      emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  1306. X    }
  1307. X    if (ac_in_use[i]) {
  1308. X      emit_byte(cinfo, i + 0x10);
  1309. X      emit_byte(cinfo, cinfo->arith_ac_K[i]);
  1310. X    }
  1311. X  }
  1312. X}
  1313. X
  1314. X
  1315. XLOCAL void
  1316. Xemit_dri (compress_info_ptr cinfo)
  1317. X/* Emit a DRI marker */
  1318. X{
  1319. X  emit_marker(cinfo, M_DRI);
  1320. X  
  1321. X  emit_2bytes(cinfo, 4);    /* fixed length */
  1322. X
  1323. X  emit_2bytes(cinfo, (int) cinfo->restart_interval);
  1324. X}
  1325. X
  1326. X
  1327. XLOCAL void
  1328. Xemit_sof (compress_info_ptr cinfo, JPEG_MARKER code)
  1329. X/* Emit a SOF marker */
  1330. X{
  1331. X  int i;
  1332. X  
  1333. X  emit_marker(cinfo, code);
  1334. X  
  1335. X  emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  1336. X
  1337. X  if (cinfo->image_height > 65535L || cinfo->image_width > 65535L)
  1338. X    ERREXIT(cinfo->emethods, "Maximum image dimension for JFIF is 65535 pixels");
  1339. X
  1340. X  emit_byte(cinfo, cinfo->data_precision);
  1341. X  emit_2bytes(cinfo, (int) cinfo->image_height);
  1342. X  emit_2bytes(cinfo, (int) cinfo->image_width);
  1343. X
  1344. X  emit_byte(cinfo, cinfo->num_components);
  1345. X
  1346. X  for (i = 0; i < cinfo->num_components; i++) {
  1347. X    emit_byte(cinfo, cinfo->comp_info[i].component_id);
  1348. X    emit_byte(cinfo, (cinfo->comp_info[i].h_samp_factor << 4)
  1349. X             + cinfo->comp_info[i].v_samp_factor);
  1350. X    emit_byte(cinfo, cinfo->comp_info[i].quant_tbl_no);
  1351. X  }
  1352. X}
  1353. X
  1354. X
  1355. XLOCAL void
  1356. Xemit_sos (compress_info_ptr cinfo)
  1357. X/* Emit a SOS marker */
  1358. X{
  1359. X  int i;
  1360. X  
  1361. X  emit_marker(cinfo, M_SOS);
  1362. X  
  1363. X  emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  1364. X  
  1365. X  emit_byte(cinfo, cinfo->comps_in_scan);
  1366. X  
  1367. X  for (i = 0; i < cinfo->comps_in_scan; i++) {
  1368. X    emit_byte(cinfo, cinfo->cur_comp_info[i]->component_id);
  1369. X    emit_byte(cinfo, (cinfo->cur_comp_info[i]->dc_tbl_no << 4)
  1370. X             + cinfo->cur_comp_info[i]->ac_tbl_no);
  1371. X  }
  1372. X
  1373. X  emit_byte(cinfo, 0);        /* Spectral selection start */
  1374. X  emit_byte(cinfo, DCTSIZE2-1);    /* Spectral selection end */
  1375. X  emit_byte(cinfo, 0);        /* Successive approximation */
  1376. X}
  1377. X
  1378. X
  1379. XLOCAL void
  1380. Xemit_jfif_app0 (compress_info_ptr cinfo)
  1381. X/* Emit a JFIF-compliant APP0 marker */
  1382. X{
  1383. X  /*
  1384. X   * Length of APP0 block    (2 bytes)
  1385. X   * Block ID            (4 bytes - ASCII "JFIF")
  1386. X   * Zero byte            (1 byte to terminate the ID string)
  1387. X   * Version Major, Minor    (2 bytes - 0x01, 0x01)
  1388. X   * Units            (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
  1389. X   * Xdpu            (2 bytes - dots per unit horizontal)
  1390. X   * Ydpu            (2 bytes - dots per unit vertical)
  1391. X   * Thumbnail X size        (1 byte)
  1392. X   * Thumbnail Y size        (1 byte)
  1393. X   */
  1394. X  
  1395. X  emit_marker(cinfo, M_APP0);
  1396. X  
  1397. X  emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  1398. X
  1399. X  emit_byte(cinfo, 0x4A);    /* Identifier: ASCII "JFIF" */
  1400. X  emit_byte(cinfo, 0x46);
  1401. X  emit_byte(cinfo, 0x49);
  1402. X  emit_byte(cinfo, 0x46);
  1403. X  emit_byte(cinfo, 0);
  1404. X  emit_byte(cinfo, 1);        /* Major version */
  1405. X  emit_byte(cinfo, 1);        /* Minor version */
  1406. X  emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  1407. X  emit_2bytes(cinfo, (int) cinfo->X_density);
  1408. X  emit_2bytes(cinfo, (int) cinfo->Y_density);
  1409. X  emit_byte(cinfo, 0);        /* No thumbnail image */
  1410. X  emit_byte(cinfo, 0);
  1411. X}
  1412. X
  1413. X
  1414. X/*
  1415. X * Write the file header.
  1416. X */
  1417. X
  1418. X
  1419. XMETHODDEF void
  1420. Xwrite_file_header (compress_info_ptr cinfo)
  1421. X{
  1422. X  char qt_in_use[NUM_QUANT_TBLS];
  1423. X  int i, prec;
  1424. X  boolean is_baseline;
  1425. X  
  1426. X  emit_marker(cinfo, M_SOI);    /* first the SOI */
  1427. X
  1428. X  if (cinfo->write_JFIF_header)    /* next an optional JFIF APP0 */
  1429. X    emit_jfif_app0(cinfo);
  1430. X
  1431. X  /* Emit DQT for each quantization table. */
  1432. X  /* Note that doing it here means we can't adjust the QTs on-the-fly. */
  1433. X  /* If we did want to do that, we'd have a problem with checking precision */
  1434. X  /* for the is_baseline determination. */
  1435. X
  1436. X  for (i = 0; i < NUM_QUANT_TBLS; i++)
  1437. X    qt_in_use[i] = 0;
  1438. X
  1439. X  for (i = 0; i < cinfo->num_components; i++)
  1440. X    qt_in_use[cinfo->comp_info[i].quant_tbl_no] = 1;
  1441. X
  1442. X  prec = 0;
  1443. X  for (i = 0; i < NUM_QUANT_TBLS; i++) {
  1444. X    if (qt_in_use[i])
  1445. X      prec += emit_dqt(cinfo, i);
  1446. X  }
  1447. X  /* now prec is nonzero iff there are any 16-bit quant tables. */
  1448. X
  1449. X  /* Check for a non-baseline specification. */
  1450. X  /* Note we assume that Huffman table numbers won't be changed later. */
  1451. X  is_baseline = TRUE;
  1452. X  if (cinfo->arith_code || (cinfo->data_precision != 8))
  1453. X    is_baseline = FALSE;
  1454. X  for (i = 0; i < cinfo->num_components; i++) {
  1455. X    if (cinfo->comp_info[i].dc_tbl_no > 1 || cinfo->comp_info[i].ac_tbl_no > 1)
  1456. X      is_baseline = FALSE;
  1457. X  }
  1458. X  if (prec && is_baseline) {
  1459. X    is_baseline = FALSE;
  1460. X    /* If it's baseline except for quantizer size, warn the user */
  1461. X    TRACEMS(cinfo->emethods, 0,
  1462. X        "Caution: quantization tables are too coarse for baseline JPEG");
  1463. X  }
  1464. X
  1465. X
  1466. X  /* Emit the proper SOF marker */
  1467. X  if (cinfo->arith_code)
  1468. X    emit_sof(cinfo, M_SOF9);    /* SOF code for arithmetic coding */
  1469. X  else if (is_baseline)
  1470. X    emit_sof(cinfo, M_SOF0);    /* SOF code for baseline implementation */
  1471. X  else
  1472. X    emit_sof(cinfo, M_SOF1);    /* SOF code for non-baseline Huffman file */
  1473. X}
  1474. X
  1475. X
  1476. X/*
  1477. X * Write the start of a scan (everything through the SOS marker).
  1478. X */
  1479. X
  1480. XMETHODDEF void
  1481. Xwrite_scan_header (compress_info_ptr cinfo)
  1482. X{
  1483. X  int i;
  1484. X
  1485. X  if (cinfo->arith_code) {
  1486. X    /* Emit arith conditioning info.  We will have some duplication
  1487. X     * if the file has multiple scans, but it's so small it's hardly
  1488. X     * worth worrying about.
  1489. X     */
  1490. X    emit_dac(cinfo);
  1491. X  } else {
  1492. X    /* Emit Huffman tables.  Note that emit_dht takes care of
  1493. X     * suppressing duplicate tables.
  1494. X     */
  1495. X    for (i = 0; i < cinfo->comps_in_scan; i++) {
  1496. X      emit_dht(cinfo, cinfo->cur_comp_info[i]->dc_tbl_no, FALSE);
  1497. X      emit_dht(cinfo, cinfo->cur_comp_info[i]->ac_tbl_no, TRUE);
  1498. X    }
  1499. X  }
  1500. X
  1501. X  /* Emit DRI if required --- note that DRI value could change for each scan.
  1502. X   * If it doesn't, a tiny amount of space is wasted in multiple-scan files.
  1503. X   * We assume DRI will never be nonzero for one scan and zero for a later one.
  1504. X   */
  1505. X  if (cinfo->restart_interval)
  1506. X    emit_dri(cinfo);
  1507. X
  1508. X  emit_sos(cinfo);
  1509. X}
  1510. X
  1511. X
  1512. X/*
  1513. X * Write some bytes of compressed data within a scan.
  1514. X */
  1515. X
  1516. XMETHODDEF void
  1517. Xwrite_jpeg_data (compress_info_ptr cinfo, char *dataptr, int datacount)
  1518. X{
  1519. X  WRITE_BYTES(cinfo, dataptr, datacount);
  1520. X}
  1521. X
  1522. X
  1523. X/*
  1524. X * Finish up after a compressed scan (series of write_jpeg_data calls).
  1525. X */
  1526. X
  1527. XMETHODDEF void
  1528. Xwrite_scan_trailer (compress_info_ptr cinfo)
  1529. X{
  1530. X  /* no work needed in this format */
  1531. X}
  1532. X
  1533. X
  1534. X/*
  1535. X * Finish up at the end of the file.
  1536. X */
  1537. X
  1538. XMETHODDEF void
  1539. Xwrite_file_trailer (compress_info_ptr cinfo)
  1540. X{
  1541. X  emit_marker(cinfo, M_EOI);
  1542. X  /* Make sure we wrote the output file OK */
  1543. X  CHECK_OUTPUT(cinfo);
  1544. X}
  1545. X
  1546. X
  1547. X/*
  1548. X * The method selection routine for standard JPEG header writing.
  1549. X * This should be called from c_ui_method_selection if appropriate.
  1550. X */
  1551. X
  1552. XGLOBAL void
  1553. Xjselwjfif (compress_info_ptr cinfo)
  1554. X{
  1555. X  cinfo->methods->write_file_header = write_file_header;
  1556. X  cinfo->methods->write_scan_header = write_scan_header;
  1557. X  cinfo->methods->write_jpeg_data = write_jpeg_data;
  1558. X  cinfo->methods->write_scan_trailer = write_scan_trailer;
  1559. X  cinfo->methods->write_file_trailer = write_file_trailer;
  1560. X}
  1561. X
  1562. X#endif /* JFIF_SUPPORTED */
  1563. END_OF_FILE
  1564.   if test 11967 -ne `wc -c <'jwrjfif.c'`; then
  1565.     echo shar: \"'jwrjfif.c'\" unpacked with wrong size!
  1566.   fi
  1567.   # end of 'jwrjfif.c'
  1568. fi
  1569. if test -f 'makefile.mc6' -a "${1}" != "-c" ; then 
  1570.   echo shar: Will not clobber existing file \"'makefile.mc6'\"
  1571. else
  1572.   echo shar: Extracting \"'makefile.mc6'\" \(7388 characters\)
  1573.   sed "s/^X//" >'makefile.mc6' <<'END_OF_FILE'
  1574. X# Makefile for Independent JPEG Group's software
  1575. X
  1576. X# This makefile is for Microsoft C for MS-DOS, version 6.00A and up.
  1577. X# Use NMAKE, not Microsoft's brain-damaged MAKE.
  1578. X# Thanks to Alan Wright and Chris Turner of Olivetti Research Ltd.
  1579. X
  1580. X# Read SETUP instructions before saying "nmake" !!
  1581. X
  1582. X# compiler flags. -D gives a #define to the sources:
  1583. X#       -AS             small memory model (or use -AM for medium model)
  1584. X#       -Ox             maximum safe optimisation
  1585. X#       -W3             warning level 3
  1586. X#       -Za             ANSI conformance, defines __STDC__ but undefines far
  1587. X#                       and near, so we DON'T use it.
  1588. X#       -DHAVE_STDC     indicate we do have all the ANSI language features
  1589. X#       -DINCLUDES_ARE_ANSI    and all the ANSI include files.
  1590. X#       -DMSDOS         we are on an MSDOS machine
  1591. X#       -DUSE_FMEM      we have _fmemcpy() and _fmemset()
  1592. X#       -DSHORTxLCONST_32      enables compiler-specific multiply optimization
  1593. X#       -DMEM_STATS     enable memory usage statistics (optional)
  1594. X# You might also want to add -G2 if you have an 80286, etc.
  1595. X
  1596. XCFLAGS = -AS -Ox -W3 -DHAVE_STDC -DINCLUDES_ARE_ANSI -DMSDOS -DUSE_FMEM -DSHORTxLCONST_32
  1597. X
  1598. X# need linker response file because file list > 128 chars
  1599. XRFILE = libjpeg.ans
  1600. X
  1601. X
  1602. X# source files (independently compilable files)
  1603. XSOURCES= jbsmooth.c jcarith.c jccolor.c jcdeflts.c jcexpand.c jchuff.c \
  1604. X        jcmain.c jcmaster.c jcmcu.c jcpipe.c jcsample.c jdarith.c jdcolor.c \
  1605. X        jddeflts.c jdhuff.c jdmain.c jdmaster.c jdmcu.c jdpipe.c jdsample.c \
  1606. X        jerror.c jquant1.c jquant2.c jfwddct.c jrevdct.c jutils.c jmemmgr.c \
  1607. X        jrdjfif.c jrdgif.c jrdppm.c jrdrle.c jrdtarga.c jwrjfif.c jwrgif.c \
  1608. X        jwrppm.c jwrrle.c jwrtarga.c
  1609. X# virtual source files (not present in distribution file, see SETUP)
  1610. XVIRTSOURCES= jmemsys.c
  1611. X# system-dependent implementations of virtual source files
  1612. XSYSDEPFILES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemdos.h \
  1613. X        jmemdosa.asm
  1614. X# files included by source files
  1615. XINCLUDES= jinclude.h jconfig.h jpegdata.h jversion.h jmemsys.h
  1616. X# documentation, test, and support files
  1617. XDOCS= README SETUP USAGE CHANGELOG cjpeg.1 djpeg.1 architecture codingrules
  1618. XMAKEFILES= makefile.ansi makefile.unix makefile.manx makefile.sas \
  1619. X        makcjpeg.st makdjpeg.st makljpeg.st makefile.mc5 makefile.mc6 \
  1620. X        makefile.bcc makefile.mms makefile.vms makvms.opt
  1621. XOTHERFILES= ansi2knr.c ckconfig.c example.c
  1622. XTESTFILES= testorig.jpg testimg.ppm testimg.gif testimg.jpg
  1623. XDISTFILES= $(DOCS) $(MAKEFILES) $(SOURCES) $(SYSDEPFILES) $(INCLUDES) \
  1624. X        $(OTHERFILES) $(TESTFILES)
  1625. X# objectfiles common to cjpeg and djpeg
  1626. XCOMOBJECTS= jutils.obj jerror.obj jmemmgr.obj jmemsys.obj jmemdosa.obj
  1627. X# compression objectfiles
  1628. XCLIBOBJECTS= jcmaster.obj jcdeflts.obj jcarith.obj jccolor.obj jcexpand.obj \
  1629. X        jchuff.obj jcmcu.obj jcpipe.obj jcsample.obj jfwddct.obj \
  1630. X        jwrjfif.obj jrdgif.obj jrdppm.obj jrdrle.obj jrdtarga.obj
  1631. XCOBJECTS= jcmain.obj $(CLIBOBJECTS) $(COMOBJECTS)
  1632. X# decompression objectfiles
  1633. XDLIBOBJECTS= jdmaster.obj jddeflts.obj jbsmooth.obj jdarith.obj jdcolor.obj \
  1634. X        jdhuff.obj jdmcu.obj jdpipe.obj jdsample.obj jquant1.obj \
  1635. X        jquant2.obj jrevdct.obj jrdjfif.obj jwrgif.obj jwrppm.obj \
  1636. X        jwrrle.obj jwrtarga.obj
  1637. XDOBJECTS= jdmain.obj $(DLIBOBJECTS) $(COMOBJECTS)
  1638. X# These objectfiles are included in libjpeg.lib
  1639. XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
  1640. X
  1641. X
  1642. Xall: cjpeg.exe djpeg.exe
  1643. X
  1644. X
  1645. X# libjpeg.lib is useful if you are including the JPEG software in a larger
  1646. X# program; you'd include it in your link, rather than the individual modules.
  1647. Xlibjpeg.lib: $(LIBOBJECTS) $(RFILE)
  1648. X    del libjpeg.lib
  1649. X    lib @$(RFILE) ;
  1650. X
  1651. X# linker response file for same
  1652. X$(RFILE) : Makefile
  1653. X    del $(RFILE)
  1654. X    echo libjpeg.lib >$(RFILE)
  1655. X# silly want-to-create-it prompt:
  1656. X    echo y >>$(RFILE)
  1657. X    echo +jcmaster.obj +jcdeflts.obj +jcarith.obj +jccolor.obj & >>$(RFILE)
  1658. X    echo +jcexpand.obj +jchuff.obj +jcmcu.obj +jcpipe.obj & >>$(RFILE)
  1659. X    echo +jcsample.obj +jfwddct.obj +jwrjfif.obj +jrdgif.obj & >>$(RFILE)
  1660. X    echo +jrdppm.obj +jrdrle.obj +jrdtarga.obj +jdmaster.obj & >>$(RFILE)
  1661. X    echo +jddeflts.obj +jbsmooth.obj +jdarith.obj +jdcolor.obj & >>$(RFILE)
  1662. X    echo +jdhuff.obj +jdmcu.obj +jdpipe.obj +jdsample.obj & >>$(RFILE)
  1663. X    echo +jquant1.obj +jquant2.obj +jrevdct.obj +jrdjfif.obj & >>$(RFILE)
  1664. X    echo +jwrgif.obj +jwrppm.obj +jwrrle.obj +jwrtarga.obj & >>$(RFILE)
  1665. X    echo +jutils.obj +jerror.obj +jmemmgr.obj +jmemsys.obj & >>$(RFILE)
  1666. X    echo +jmemdosa.obj >>$(RFILE)
  1667. X
  1668. Xcjpeg.exe: jcmain.obj libjpeg.lib
  1669. X    link /STACK:4096 /EXEPACK jcmain.obj, cjpeg.exe, , libjpeg.lib, ;
  1670. X
  1671. Xdjpeg.exe: jdmain.obj libjpeg.lib
  1672. X    link /STACK:4096 /EXEPACK jdmain.obj, djpeg.exe, , libjpeg.lib, ;
  1673. X
  1674. Xjmemsys.c:
  1675. X    echo You must select a system-dependent jmemsys.c file.
  1676. X    echo Please read the SETUP directions.
  1677. X    exit 1
  1678. X
  1679. Xclean:
  1680. X    del *.obj
  1681. X    del libjpeg.lib
  1682. X    del cjpeg.exe
  1683. X    del djpeg.exe
  1684. X    del testout.*
  1685. X
  1686. Xtest:
  1687. X        del testout.*
  1688. X        djpeg testorig.jpg testout.ppm
  1689. X        djpeg -gif testorig.jpg testout.gif
  1690. X        cjpeg testimg.ppm testout.jpg
  1691. X        fc testimg.ppm testout.ppm
  1692. X        fc testimg.gif testout.gif
  1693. X        fc testimg.jpg testout.jpg
  1694. X
  1695. X
  1696. Xjbsmooth.obj : jbsmooth.c jinclude.h jconfig.h jpegdata.h
  1697. Xjcarith.obj : jcarith.c jinclude.h jconfig.h jpegdata.h
  1698. Xjccolor.obj : jccolor.c jinclude.h jconfig.h jpegdata.h
  1699. Xjcdeflts.obj : jcdeflts.c jinclude.h jconfig.h jpegdata.h
  1700. Xjcexpand.obj : jcexpand.c jinclude.h jconfig.h jpegdata.h
  1701. Xjchuff.obj : jchuff.c jinclude.h jconfig.h jpegdata.h
  1702. Xjcmain.obj : jcmain.c jinclude.h jconfig.h jpegdata.h jversion.h
  1703. Xjcmaster.obj : jcmaster.c jinclude.h jconfig.h jpegdata.h
  1704. Xjcmcu.obj : jcmcu.c jinclude.h jconfig.h jpegdata.h
  1705. Xjcpipe.obj : jcpipe.c jinclude.h jconfig.h jpegdata.h
  1706. Xjcsample.obj : jcsample.c jinclude.h jconfig.h jpegdata.h
  1707. Xjdarith.obj : jdarith.c jinclude.h jconfig.h jpegdata.h
  1708. Xjdcolor.obj : jdcolor.c jinclude.h jconfig.h jpegdata.h
  1709. Xjddeflts.obj : jddeflts.c jinclude.h jconfig.h jpegdata.h
  1710. Xjdhuff.obj : jdhuff.c jinclude.h jconfig.h jpegdata.h
  1711. Xjdmain.obj : jdmain.c jinclude.h jconfig.h jpegdata.h jversion.h
  1712. Xjdmaster.obj : jdmaster.c jinclude.h jconfig.h jpegdata.h
  1713. Xjdmcu.obj : jdmcu.c jinclude.h jconfig.h jpegdata.h
  1714. Xjdpipe.obj : jdpipe.c jinclude.h jconfig.h jpegdata.h
  1715. Xjdsample.obj : jdsample.c jinclude.h jconfig.h jpegdata.h
  1716. Xjerror.obj : jerror.c jinclude.h jconfig.h jpegdata.h
  1717. Xjquant1.obj : jquant1.c jinclude.h jconfig.h jpegdata.h
  1718. Xjquant2.obj : jquant2.c jinclude.h jconfig.h jpegdata.h
  1719. Xjfwddct.obj : jfwddct.c jinclude.h jconfig.h jpegdata.h
  1720. Xjrevdct.obj : jrevdct.c jinclude.h jconfig.h jpegdata.h
  1721. Xjutils.obj : jutils.c jinclude.h jconfig.h jpegdata.h
  1722. Xjmemmgr.obj : jmemmgr.c jinclude.h jconfig.h jpegdata.h jmemsys.h
  1723. Xjrdjfif.obj : jrdjfif.c jinclude.h jconfig.h jpegdata.h
  1724. Xjrdgif.obj : jrdgif.c jinclude.h jconfig.h jpegdata.h
  1725. Xjrdppm.obj : jrdppm.c jinclude.h jconfig.h jpegdata.h
  1726. Xjrdrle.obj : jrdrle.c jinclude.h jconfig.h jpegdata.h
  1727. Xjrdtarga.obj : jrdtarga.c jinclude.h jconfig.h jpegdata.h
  1728. Xjwrjfif.obj : jwrjfif.c jinclude.h jconfig.h jpegdata.h
  1729. Xjwrgif.obj : jwrgif.c jinclude.h jconfig.h jpegdata.h
  1730. Xjwrppm.obj : jwrppm.c jinclude.h jconfig.h jpegdata.h
  1731. Xjwrrle.obj : jwrrle.c jinclude.h jconfig.h jpegdata.h
  1732. Xjwrtarga.obj : jwrtarga.c jinclude.h jconfig.h jpegdata.h
  1733. Xjmemsys.obj : jmemsys.c jinclude.h jconfig.h jpegdata.h jmemsys.h
  1734. Xjmemdosa.obj : jmemdosa.asm
  1735. X    masm /mx $*;
  1736. END_OF_FILE
  1737.   if test 7388 -ne `wc -c <'makefile.mc6'`; then
  1738.     echo shar: \"'makefile.mc6'\" unpacked with wrong size!
  1739.   fi
  1740.   # end of 'makefile.mc6'
  1741. fi
  1742. echo shar: End of archive 14 \(of 18\).
  1743. cp /dev/null ark14isdone
  1744. MISSING=""
  1745. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1746.     if test ! -f ark${I}isdone ; then
  1747.     MISSING="${MISSING} ${I}"
  1748.     fi
  1749. done
  1750. if test "${MISSING}" = "" ; then
  1751.     echo You have unpacked all 18 archives.
  1752.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1753. else
  1754.     echo You still must unpack the following archives:
  1755.     echo "        " ${MISSING}
  1756. fi
  1757. exit 0
  1758. exit 0 # Just in case...
  1759.