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

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v34i058:  jpeg - JPEG image compression, Part04/18
  4. Message-ID: <1992Dec17.041632.23308@sparky.imd.sterling.com>
  5. X-Md4-Signature: f8daf6fd58453424059aebbbc37d87f1
  6. Date: Thu, 17 Dec 1992 04:16:32 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 58
  11. Archive-name: jpeg/part04
  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:  jcsample.c jpegdata.h
  20. # Wrapped by kent@sparky on Wed Dec 16 20:52:25 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 4 (of 18)."'
  24. if test -f 'jcsample.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'jcsample.c'\"
  26. else
  27.   echo shar: Extracting \"'jcsample.c'\" \(16472 characters\)
  28.   sed "s/^X//" >'jcsample.c' <<'END_OF_FILE'
  29. X/*
  30. X * jcsample.c
  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 downsampling routines.
  37. X * These routines are invoked via the downsample and
  38. X * downsample_init/term methods.
  39. X *
  40. X * An excellent reference for image resampling is
  41. X *   Digital Image Warping, George Wolberg, 1990.
  42. X *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
  43. X *
  44. X * The downsampling algorithm used here is a simple average of the source
  45. X * pixels covered by the output pixel.  The hi-falutin sampling literature
  46. X * refers to this as a "box filter".  In general the characteristics of a box
  47. X * filter are not very good, but for the specific cases we normally use (1:1
  48. X * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
  49. X * nearly so bad.  If you intend to use other sampling ratios, you'd be well
  50. X * advised to improve this code.
  51. X *
  52. X * A simple input-smoothing capability is provided.  This is mainly intended
  53. X * for cleaning up color-dithered GIF input files (if you find it inadequate,
  54. X * we suggest using an external filtering program such as pnmconvol).  When
  55. X * enabled, each input pixel P is replaced by a weighted sum of itself and its
  56. X * eight neighbors.  P's weight is 1-8*SF and each neighbor's weight is SF,
  57. X * where SF = (smoothing_factor / 1024).
  58. X * Currently, smoothing is only supported for 2h2v sampling factors.
  59. X */
  60. X
  61. X#include "jinclude.h"
  62. X
  63. X
  64. X/*
  65. X * Initialize for downsampling a scan.
  66. X */
  67. X
  68. XMETHODDEF void
  69. Xdownsample_init (compress_info_ptr cinfo)
  70. X{
  71. X  /* no work for now */
  72. X}
  73. X
  74. X
  75. X/*
  76. X * Downsample pixel values of a single component.
  77. X * This version handles arbitrary integral sampling ratios, without smoothing.
  78. X * Note that this version is not actually used for customary sampling ratios.
  79. X */
  80. X
  81. XMETHODDEF void
  82. Xint_downsample (compress_info_ptr cinfo, int which_component,
  83. X        long input_cols, int input_rows,
  84. X        long output_cols, int output_rows,
  85. X        JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  86. X        JSAMPARRAY output_data)
  87. X{
  88. X  jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
  89. X  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  90. X  long outcol, outcol_h;    /* outcol_h == outcol*h_expand */
  91. X  JSAMPROW inptr, outptr;
  92. X  INT32 outvalue;
  93. X
  94. X#ifdef DEBUG            /* for debugging pipeline controller */
  95. X  if (output_rows != compptr->v_samp_factor ||
  96. X      input_rows != cinfo->max_v_samp_factor ||
  97. X      (output_cols % compptr->h_samp_factor) != 0 ||
  98. X      (input_cols % cinfo->max_h_samp_factor) != 0 ||
  99. X      input_cols*compptr->h_samp_factor != output_cols*cinfo->max_h_samp_factor)
  100. X    ERREXIT(cinfo->emethods, "Bogus downsample parameters");
  101. X#endif
  102. X
  103. X  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  104. X  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  105. X  numpix = h_expand * v_expand;
  106. X  numpix2 = numpix/2;
  107. X
  108. X  inrow = 0;
  109. X  for (outrow = 0; outrow < output_rows; outrow++) {
  110. X    outptr = output_data[outrow];
  111. X    for (outcol = 0, outcol_h = 0; outcol < output_cols;
  112. X     outcol++, outcol_h += h_expand) {
  113. X      outvalue = 0;
  114. X      for (v = 0; v < v_expand; v++) {
  115. X    inptr = input_data[inrow+v] + outcol_h;
  116. X    for (h = 0; h < h_expand; h++) {
  117. X      outvalue += (INT32) GETJSAMPLE(*inptr++);
  118. X    }
  119. X      }
  120. X      *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  121. X    }
  122. X    inrow += v_expand;
  123. X  }
  124. X}
  125. X
  126. X
  127. X/*
  128. X * Downsample pixel values of a single component.
  129. X * This version handles the common case of 2:1 horizontal and 1:1 vertical,
  130. X * without smoothing.
  131. X */
  132. X
  133. XMETHODDEF void
  134. Xh2v1_downsample (compress_info_ptr cinfo, int which_component,
  135. X         long input_cols, int input_rows,
  136. X         long output_cols, int output_rows,
  137. X         JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  138. X         JSAMPARRAY output_data)
  139. X{
  140. X  int outrow;
  141. X  long outcol;
  142. X  register JSAMPROW inptr, outptr;
  143. X
  144. X#ifdef DEBUG            /* for debugging pipeline controller */
  145. X  jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
  146. X  if (output_rows != compptr->v_samp_factor ||
  147. X      input_rows != cinfo->max_v_samp_factor ||
  148. X      (output_cols % compptr->h_samp_factor) != 0 ||
  149. X      (input_cols % cinfo->max_h_samp_factor) != 0 ||
  150. X      input_cols*compptr->h_samp_factor != output_cols*cinfo->max_h_samp_factor)
  151. X    ERREXIT(cinfo->emethods, "Bogus downsample parameters");
  152. X#endif
  153. X
  154. X  for (outrow = 0; outrow < output_rows; outrow++) {
  155. X    outptr = output_data[outrow];
  156. X    inptr = input_data[outrow];
  157. X    for (outcol = 0; outcol < output_cols; outcol++) {
  158. X      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  159. X                  + 1) >> 1);
  160. X      inptr += 2;
  161. X    }
  162. X  }
  163. X}
  164. X
  165. X
  166. X/*
  167. X * Downsample pixel values of a single component.
  168. X * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  169. X * without smoothing.
  170. X */
  171. X
  172. XMETHODDEF void
  173. Xh2v2_downsample (compress_info_ptr cinfo, int which_component,
  174. X         long input_cols, int input_rows,
  175. X         long output_cols, int output_rows,
  176. X         JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  177. X         JSAMPARRAY output_data)
  178. X{
  179. X  int inrow, outrow;
  180. X  long outcol;
  181. X  register JSAMPROW inptr0, inptr1, outptr;
  182. X
  183. X#ifdef DEBUG            /* for debugging pipeline controller */
  184. X  jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
  185. X  if (output_rows != compptr->v_samp_factor ||
  186. X      input_rows != cinfo->max_v_samp_factor ||
  187. X      (output_cols % compptr->h_samp_factor) != 0 ||
  188. X      (input_cols % cinfo->max_h_samp_factor) != 0 ||
  189. X      input_cols*compptr->h_samp_factor != output_cols*cinfo->max_h_samp_factor)
  190. X    ERREXIT(cinfo->emethods, "Bogus downsample parameters");
  191. X#endif
  192. X
  193. X  inrow = 0;
  194. X  for (outrow = 0; outrow < output_rows; outrow++) {
  195. X    outptr = output_data[outrow];
  196. X    inptr0 = input_data[inrow];
  197. X    inptr1 = input_data[inrow+1];
  198. X    for (outcol = 0; outcol < output_cols; outcol++) {
  199. X      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  200. X                  GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  201. X                  + 2) >> 2);
  202. X      inptr0 += 2; inptr1 += 2;
  203. X    }
  204. X    inrow += 2;
  205. X  }
  206. X}
  207. X
  208. X
  209. X/*
  210. X * Downsample pixel values of a single component.
  211. X * This version handles the special case of a full-size component,
  212. X * without smoothing.
  213. X */
  214. X
  215. XMETHODDEF void
  216. Xfullsize_downsample (compress_info_ptr cinfo, int which_component,
  217. X             long input_cols, int input_rows,
  218. X             long output_cols, int output_rows,
  219. X             JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  220. X             JSAMPARRAY output_data)
  221. X{
  222. X#ifdef DEBUG            /* for debugging pipeline controller */
  223. X  if (input_cols != output_cols || input_rows != output_rows)
  224. X    ERREXIT(cinfo->emethods, "Pipeline controller messed up");
  225. X#endif
  226. X
  227. X  jcopy_sample_rows(input_data, 0, output_data, 0, output_rows, output_cols);
  228. X}
  229. X
  230. X
  231. X#ifdef INPUT_SMOOTHING_SUPPORTED
  232. X
  233. X/*
  234. X * Downsample pixel values of a single component.
  235. X * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  236. X * with smoothing.
  237. X */
  238. X
  239. XMETHODDEF void
  240. Xh2v2_smooth_downsample (compress_info_ptr cinfo, int which_component,
  241. X            long input_cols, int input_rows,
  242. X            long output_cols, int output_rows,
  243. X            JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  244. X            JSAMPARRAY output_data)
  245. X{
  246. X  int inrow, outrow;
  247. X  long colctr;
  248. X  register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  249. X  INT32 membersum, neighsum, memberscale, neighscale;
  250. X
  251. X#ifdef DEBUG            /* for debugging pipeline controller */
  252. X  jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
  253. X  if (output_rows != compptr->v_samp_factor ||
  254. X      input_rows != cinfo->max_v_samp_factor ||
  255. X      (output_cols % compptr->h_samp_factor) != 0 ||
  256. X      (input_cols % cinfo->max_h_samp_factor) != 0 ||
  257. X      input_cols*compptr->h_samp_factor != output_cols*cinfo->max_h_samp_factor)
  258. X    ERREXIT(cinfo->emethods, "Bogus downsample parameters");
  259. X#endif
  260. X
  261. X  /* We don't bother to form the individual "smoothed" input pixel values;
  262. X   * we can directly compute the output which is the average of the four
  263. X   * smoothed values.  Each of the four member pixels contributes a fraction
  264. X   * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
  265. X   * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
  266. X   * output.  The four corner-adjacent neighbor pixels contribute a fraction
  267. X   * SF to just one smoothed pixel, or SF/4 to the final output; while the
  268. X   * eight edge-adjacent neighbors contribute SF to each of two smoothed
  269. X   * pixels, or SF/2 overall.  In order to use integer arithmetic, these
  270. X   * factors are scaled by 2^16 = 65536.
  271. X   * Also recall that SF = smoothing_factor / 1024.
  272. X   */
  273. X
  274. X  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  275. X  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  276. X
  277. X  inrow = 0;
  278. X  for (outrow = 0; outrow < output_rows; outrow++) {
  279. X    outptr = output_data[outrow];
  280. X    inptr0 = input_data[inrow];
  281. X    inptr1 = input_data[inrow+1];
  282. X    if (inrow == 0)
  283. X      above_ptr = above[input_rows-1];
  284. X    else
  285. X      above_ptr = input_data[inrow-1];
  286. X    if (inrow >= input_rows-2)
  287. X      below_ptr = below[0];
  288. X    else
  289. X      below_ptr = input_data[inrow+2];
  290. X
  291. X    /* Special case for first column: pretend column -1 is same as column 0 */
  292. X    membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  293. X        GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  294. X    neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  295. X           GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  296. X           GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  297. X           GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  298. X    neighsum += neighsum;
  299. X    neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  300. X        GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  301. X    membersum = membersum * memberscale + neighsum * neighscale;
  302. X    *outptr++ = (JSAMPLE) ((membersum + 32768L) >> 16);
  303. X    inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  304. X
  305. X    for (colctr = output_cols - 2; colctr > 0; colctr--) {
  306. X      /* sum of pixels directly mapped to this output element */
  307. X      membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  308. X          GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  309. X      /* sum of edge-neighbor pixels */
  310. X      neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  311. X         GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  312. X         GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  313. X         GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  314. X      /* The edge-neighbors count twice as much as corner-neighbors */
  315. X      neighsum += neighsum;
  316. X      /* Add in the corner-neighbors */
  317. X      neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  318. X          GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  319. X      /* form final output scaled up by 2^16 */
  320. X      membersum = membersum * memberscale + neighsum * neighscale;
  321. X      /* round, descale and output it */
  322. X      *outptr++ = (JSAMPLE) ((membersum + 32768L) >> 16);
  323. X      inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  324. X    }
  325. X
  326. X    /* Special case for last column */
  327. X    membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  328. X        GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  329. X    neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  330. X           GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  331. X           GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  332. X           GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  333. X    neighsum += neighsum;
  334. X    neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  335. X        GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  336. X    membersum = membersum * memberscale + neighsum * neighscale;
  337. X    *outptr = (JSAMPLE) ((membersum + 32768L) >> 16);
  338. X
  339. X    inrow += 2;
  340. X  }
  341. X}
  342. X
  343. X
  344. X/*
  345. X * Downsample pixel values of a single component.
  346. X * This version handles the special case of a full-size component,
  347. X * with smoothing.
  348. X */
  349. X
  350. XMETHODDEF void
  351. Xfullsize_smooth_downsample (compress_info_ptr cinfo, int which_component,
  352. X                long input_cols, int input_rows,
  353. X                long output_cols, int output_rows,
  354. X                JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  355. X                JSAMPARRAY output_data)
  356. X{
  357. X  int outrow;
  358. X  long colctr;
  359. X  register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  360. X  INT32 membersum, neighsum, memberscale, neighscale;
  361. X  int colsum, lastcolsum, nextcolsum;
  362. X
  363. X#ifdef DEBUG            /* for debugging pipeline controller */
  364. X  if (input_cols != output_cols || input_rows != output_rows)
  365. X    ERREXIT(cinfo->emethods, "Pipeline controller messed up");
  366. X#endif
  367. X
  368. X  /* Each of the eight neighbor pixels contributes a fraction SF to the
  369. X   * smoothed pixel, while the main pixel contributes (1-8*SF).  In order
  370. X   * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
  371. X   * Also recall that SF = smoothing_factor / 1024.
  372. X   */
  373. X
  374. X  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  375. X  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  376. X
  377. X  for (outrow = 0; outrow < output_rows; outrow++) {
  378. X    outptr = output_data[outrow];
  379. X    inptr = input_data[outrow];
  380. X    if (outrow == 0)
  381. X      above_ptr = above[input_rows-1];
  382. X    else
  383. X      above_ptr = input_data[outrow-1];
  384. X    if (outrow >= input_rows-1)
  385. X      below_ptr = below[0];
  386. X    else
  387. X      below_ptr = input_data[outrow+1];
  388. X
  389. X    /* Special case for first column */
  390. X    colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  391. X         GETJSAMPLE(*inptr);
  392. X    membersum = GETJSAMPLE(*inptr++);
  393. X    nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  394. X         GETJSAMPLE(*inptr);
  395. X    neighsum = colsum + (colsum - membersum) + nextcolsum;
  396. X    membersum = membersum * memberscale + neighsum * neighscale;
  397. X    *outptr++ = (JSAMPLE) ((membersum + 32768L) >> 16);
  398. X    lastcolsum = colsum; colsum = nextcolsum;
  399. X
  400. X    for (colctr = output_cols - 2; colctr > 0; colctr--) {
  401. X      membersum = GETJSAMPLE(*inptr++);
  402. X      above_ptr++; below_ptr++;
  403. X      nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  404. X           GETJSAMPLE(*inptr);
  405. X      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  406. X      membersum = membersum * memberscale + neighsum * neighscale;
  407. X      *outptr++ = (JSAMPLE) ((membersum + 32768L) >> 16);
  408. X      lastcolsum = colsum; colsum = nextcolsum;
  409. X    }
  410. X
  411. X    /* Special case for last column */
  412. X    membersum = GETJSAMPLE(*inptr);
  413. X    neighsum = lastcolsum + (colsum - membersum) + colsum;
  414. X    membersum = membersum * memberscale + neighsum * neighscale;
  415. X    *outptr = (JSAMPLE) ((membersum + 32768L) >> 16);
  416. X
  417. X  }
  418. X}
  419. X
  420. X#endif /* INPUT_SMOOTHING_SUPPORTED */
  421. X
  422. X
  423. X/*
  424. X * Clean up after a scan.
  425. X */
  426. X
  427. XMETHODDEF void
  428. Xdownsample_term (compress_info_ptr cinfo)
  429. X{
  430. X  /* no work for now */
  431. X}
  432. X
  433. X
  434. X
  435. X/*
  436. X * The method selection routine for downsampling.
  437. X * Note that we must select a routine for each component.
  438. X */
  439. X
  440. XGLOBAL void
  441. Xjseldownsample (compress_info_ptr cinfo)
  442. X{
  443. X  short ci;
  444. X  jpeg_component_info * compptr;
  445. X  boolean smoothok = TRUE;
  446. X
  447. X  if (cinfo->CCIR601_sampling)
  448. X    ERREXIT(cinfo->emethods, "CCIR601 downsampling not implemented yet");
  449. X
  450. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  451. X    compptr = cinfo->cur_comp_info[ci];
  452. X    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  453. X    compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  454. X#ifdef INPUT_SMOOTHING_SUPPORTED
  455. X      if (cinfo->smoothing_factor)
  456. X    cinfo->methods->downsample[ci] = fullsize_smooth_downsample;
  457. X      else
  458. X#endif
  459. X    cinfo->methods->downsample[ci] = fullsize_downsample;
  460. X    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  461. X         compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  462. X      smoothok = FALSE;
  463. X      cinfo->methods->downsample[ci] = h2v1_downsample;
  464. X    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  465. X         compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  466. X#ifdef INPUT_SMOOTHING_SUPPORTED
  467. X      if (cinfo->smoothing_factor)
  468. X    cinfo->methods->downsample[ci] = h2v2_smooth_downsample;
  469. X      else
  470. X#endif
  471. X    cinfo->methods->downsample[ci] = h2v2_downsample;
  472. X    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  473. X         (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  474. X      smoothok = FALSE;
  475. X      cinfo->methods->downsample[ci] = int_downsample;
  476. X    } else
  477. X      ERREXIT(cinfo->emethods, "Fractional downsampling not implemented yet");
  478. X  }
  479. X
  480. X#ifdef INPUT_SMOOTHING_SUPPORTED
  481. X  if (cinfo->smoothing_factor && !smoothok)
  482. X    TRACEMS(cinfo->emethods, 0,
  483. X        "Smoothing not supported with nonstandard sampling ratios");
  484. X#endif
  485. X
  486. X  cinfo->methods->downsample_init = downsample_init;
  487. X  cinfo->methods->downsample_term = downsample_term;
  488. X}
  489. END_OF_FILE
  490.   if test 16472 -ne `wc -c <'jcsample.c'`; then
  491.     echo shar: \"'jcsample.c'\" unpacked with wrong size!
  492.   fi
  493.   # end of 'jcsample.c'
  494. fi
  495. if test -f 'jpegdata.h' -a "${1}" != "-c" ; then 
  496.   echo shar: Will not clobber existing file \"'jpegdata.h'\"
  497. else
  498.   echo shar: Extracting \"'jpegdata.h'\" \(39469 characters\)
  499.   sed "s/^X//" >'jpegdata.h' <<'END_OF_FILE'
  500. X/*
  501. X * jpegdata.h
  502. X *
  503. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  504. X * This file is part of the Independent JPEG Group's software.
  505. X * For conditions of distribution and use, see the accompanying README file.
  506. X *
  507. X * This file defines shared data structures for the various JPEG modules.
  508. X */
  509. X
  510. X
  511. X/*
  512. X * You might need to change some of the following declarations if you are
  513. X * using the JPEG software within a surrounding application program
  514. X * or porting it to an unusual system.
  515. X */
  516. X
  517. X
  518. X/* If the source or destination of image data is not to be stdio streams,
  519. X * these types may need work.  You can replace them with some kind of
  520. X * pointer or indicator that is useful to you, or just ignore 'em.
  521. X * Note that the user interface and the various jrdxxx/jwrxxx modules
  522. X * will also need work for non-stdio input/output.
  523. X */
  524. X
  525. Xtypedef FILE * JFILEREF;    /* source or dest of JPEG-compressed data */
  526. X
  527. Xtypedef FILE * IFILEREF;    /* source or dest of non-JPEG image data */
  528. X
  529. X
  530. X/* These defines are used in all function definitions and extern declarations.
  531. X * You could modify them if you need to change function linkage conventions,
  532. X * as is shown below for use with C++.  Another application would be to make
  533. X * all functions global for use with code profilers that require it.
  534. X * NOTE: the C++ test does the right thing if you are reading this include
  535. X * file in a C++ application to link to JPEG code that's been compiled with a
  536. X * regular C compiler.  I'm not sure it works if you try to compile the JPEG
  537. X * code with C++.
  538. X */
  539. X
  540. X#define METHODDEF static    /* a function called through method pointers */
  541. X#define LOCAL      static    /* a function used only in its module */
  542. X#define GLOBAL            /* a function referenced thru EXTERNs */
  543. X#ifdef __cplusplus
  544. X#define EXTERN      extern "C"    /* a reference to a GLOBAL function */
  545. X#else
  546. X#define EXTERN      extern    /* a reference to a GLOBAL function */
  547. X#endif
  548. X
  549. X
  550. X/* Here is the pseudo-keyword for declaring pointers that must be "far"
  551. X * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
  552. X * by just saying "FAR *" where such a pointer is needed.  In a few places
  553. X * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
  554. X */
  555. X
  556. X#ifdef NEED_FAR_POINTERS
  557. X#define FAR  far
  558. X#else
  559. X#define FAR
  560. X#endif
  561. X
  562. X
  563. X
  564. X/* The remaining declarations are not system-dependent, we hope. */
  565. X
  566. X
  567. X/*
  568. X * NOTE: if you have an ancient, strict-K&R C compiler, it may choke on the
  569. X * similarly-named fields in Compress_info_struct and Decompress_info_struct.
  570. X * If this happens, you can get around it by rearranging the two structs so
  571. X * that the similarly-named fields appear first and in the same order in
  572. X * each struct.  Since such compilers are now pretty rare, we haven't done
  573. X * this in the portable code, preferring to maintain a logical ordering.
  574. X */
  575. X
  576. X
  577. X
  578. X/* This macro is used to declare a "method", that is, a function pointer. */
  579. X/* We want to supply prototype parameters if the compiler can cope. */
  580. X/* Note that the arglist parameter must be parenthesized! */
  581. X
  582. X#ifdef PROTO
  583. X#define METHOD(type,methodname,arglist)  type (*methodname) arglist
  584. X#else
  585. X#define METHOD(type,methodname,arglist)  type (*methodname) ()
  586. X#endif
  587. X
  588. X/* Forward references to lists of method pointers */
  589. Xtypedef struct External_methods_struct * external_methods_ptr;
  590. Xtypedef struct Compress_methods_struct * compress_methods_ptr;
  591. Xtypedef struct Decompress_methods_struct * decompress_methods_ptr;
  592. X
  593. X
  594. X/* Data structures for images containing either samples or coefficients. */
  595. X/* Note that the topmost (leftmost) index is always color component. */
  596. X/* On 80x86 machines, the image arrays are too big for near pointers, */
  597. X/* but the pointer arrays can fit in near memory. */
  598. X
  599. Xtypedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  600. Xtypedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  601. Xtypedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  602. X
  603. X
  604. X#define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  605. X#define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  606. X
  607. Xtypedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  608. Xtypedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  609. Xtypedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  610. Xtypedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  611. X
  612. Xtypedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  613. X
  614. X
  615. X/* The input and output data of the DCT transform subroutines are of
  616. X * the following type, which need not be the same as JCOEF.
  617. X * For example, on a machine with fast floating point, it might make sense
  618. X * to recode the DCT routines to use floating point; then DCTELEM would be
  619. X * 'float' or 'double'.
  620. X */
  621. X
  622. Xtypedef JCOEF DCTELEM;
  623. Xtypedef DCTELEM DCTBLOCK[DCTSIZE2];
  624. X
  625. X
  626. X/* Types for JPEG compression parameters and working tables. */
  627. X
  628. X
  629. Xtypedef enum {            /* defines known color spaces */
  630. X    CS_UNKNOWN,        /* error/unspecified */
  631. X    CS_GRAYSCALE,        /* monochrome (only 1 component) */
  632. X    CS_RGB,            /* red/green/blue */
  633. X    CS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  634. X    CS_YIQ,            /* Y/I/Q */
  635. X    CS_CMYK            /* C/M/Y/K */
  636. X} COLOR_SPACE;
  637. X
  638. X
  639. Xtypedef struct {        /* Basic info about one component */
  640. X  /* These values are fixed over the whole image */
  641. X  /* For compression, they must be supplied by the user interface; */
  642. X  /* for decompression, they are read from the SOF marker. */
  643. X    short component_id;    /* identifier for this component (0..255) */
  644. X    short component_index;    /* its index in SOF or cinfo->comp_info[] */
  645. X    short h_samp_factor;    /* horizontal sampling factor (1..4) */
  646. X    short v_samp_factor;    /* vertical sampling factor (1..4) */
  647. X    short quant_tbl_no;    /* quantization table selector (0..3) */
  648. X  /* These values may vary between scans */
  649. X  /* For compression, they must be supplied by the user interface; */
  650. X  /* for decompression, they are read from the SOS marker. */
  651. X    short dc_tbl_no;    /* DC entropy table selector (0..3) */
  652. X    short ac_tbl_no;    /* AC entropy table selector (0..3) */
  653. X  /* These values are computed during compression or decompression startup */
  654. X    long true_comp_width;    /* component's image width in samples */
  655. X    long true_comp_height;    /* component's image height in samples */
  656. X    /* the above are the logical dimensions of the downsampled image */
  657. X  /* These values are computed before starting a scan of the component */
  658. X    short MCU_width;    /* number of blocks per MCU, horizontally */
  659. X    short MCU_height;    /* number of blocks per MCU, vertically */
  660. X    short MCU_blocks;    /* MCU_width * MCU_height */
  661. X    long downsampled_width;    /* image width in samples, after expansion */
  662. X    long downsampled_height; /* image height in samples, after expansion */
  663. X    /* the above are the true_comp_xxx values rounded up to multiples of */
  664. X    /* the MCU dimensions; these are the working dimensions of the array */
  665. X    /* as it is passed through the DCT or IDCT step.  NOTE: these values */
  666. X    /* differ depending on whether the component is interleaved or not!! */
  667. X} jpeg_component_info;
  668. X
  669. X
  670. X/* DCT coefficient quantization tables.
  671. X * For 8-bit precision, 'INT16' should be good enough for quantization values;
  672. X * for more precision, we go for the full 16 bits.  'INT16' provides a useful
  673. X * speedup on many machines (multiplication & division of JCOEFs by
  674. X * quantization values is a significant chunk of the runtime).
  675. X * Note: the values in a QUANT_TBL are always given in zigzag order.
  676. X */
  677. X#ifdef EIGHT_BIT_SAMPLES
  678. Xtypedef INT16 QUANT_VAL;    /* element of a quantization table */
  679. X#else
  680. Xtypedef UINT16 QUANT_VAL;    /* element of a quantization table */
  681. X#endif
  682. Xtypedef QUANT_VAL QUANT_TBL[DCTSIZE2];    /* A quantization table */
  683. Xtypedef QUANT_VAL * QUANT_TBL_PTR;    /* pointer to same */
  684. X
  685. X
  686. Xtypedef struct {        /* A Huffman coding table */
  687. X  /* These two fields directly represent the contents of a JPEG DHT marker */
  688. X    UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  689. X                /* length k bits; bits[0] is unused */
  690. X    UINT8 huffval[256];    /* The symbols, in order of incr code length */
  691. X  /* This field is used only during compression.  It's initialized FALSE when
  692. X   * the table is created, and set TRUE when it's been output to the file.
  693. X   */
  694. X    boolean sent_table;    /* TRUE when table has been output */
  695. X  /* The remaining fields are computed from the above to allow more efficient
  696. X   * coding and decoding.  These fields should be considered private to the
  697. X   * Huffman compression & decompression modules.
  698. X   */
  699. X    /* encoding tables: */
  700. X    UINT16 ehufco[256];    /* code for each symbol */
  701. X    char ehufsi[256];    /* length of code for each symbol */
  702. X    /* decoding tables: (element [0] of each array is unused) */
  703. X    UINT16 mincode[17];    /* smallest code of length k */
  704. X    INT32 maxcode[18];    /* largest code of length k (-1 if none) */
  705. X    /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
  706. X    short valptr[17];    /* huffval[] index of 1st symbol of length k */
  707. X} HUFF_TBL;
  708. X
  709. X
  710. X#define NUM_QUANT_TBLS      4    /* quantization tables are numbered 0..3 */
  711. X#define NUM_HUFF_TBLS       4    /* Huffman tables are numbered 0..3 */
  712. X#define NUM_ARITH_TBLS      16    /* arith-coding tables are numbered 0..15 */
  713. X#define MAX_COMPS_IN_SCAN   4    /* JPEG limit on # of components in one scan */
  714. X#define MAX_SAMP_FACTOR     4    /* JPEG limit on sampling factors */
  715. X#define MAX_BLOCKS_IN_MCU   10    /* JPEG limit on # of blocks in an MCU */
  716. X
  717. X
  718. X/* Working data for compression */
  719. X
  720. Xstruct Compress_info_struct {
  721. X/*
  722. X * All of these fields shall be established by the user interface before
  723. X * calling jpeg_compress, or by the input_init or c_ui_method_selection
  724. X * methods.
  725. X * Most parameters can be set to reasonable defaults by j_c_defaults.
  726. X * Note that the UI must supply the storage for the main methods struct,
  727. X * though it sets only a few of the methods there.
  728. X */
  729. X    compress_methods_ptr methods; /* Points to list of methods to use */
  730. X
  731. X    external_methods_ptr emethods; /* Points to list of methods to use */
  732. X
  733. X    IFILEREF input_file;    /* tells input routines where to read image */
  734. X    JFILEREF output_file;    /* tells output routines where to write JPEG */
  735. X
  736. X    long image_width;    /* input image width */
  737. X    long image_height;    /* input image height */
  738. X    short input_components;    /* # of color components in input image */
  739. X
  740. X    short data_precision;    /* bits of precision in image data */
  741. X
  742. X    COLOR_SPACE in_color_space; /* colorspace of input file */
  743. X    COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
  744. X
  745. X    double input_gamma;    /* image gamma of input file */
  746. X
  747. X    boolean write_JFIF_header; /* should a JFIF marker be written? */
  748. X    /* These three values are not used by the JPEG code, only copied */
  749. X    /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
  750. X    /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
  751. X    /* ratio is defined by X_density/Y_density even when density_unit=0. */
  752. X    UINT8 density_unit;    /* JFIF code for pixel size units */
  753. X    UINT16 X_density;    /* Horizontal pixel density */
  754. X    UINT16 Y_density;    /* Vertical pixel density */
  755. X
  756. X    short num_components;    /* # of color components in JPEG image */
  757. X    jpeg_component_info * comp_info;
  758. X    /* comp_info[i] describes component that appears i'th in SOF */
  759. X
  760. X    QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
  761. X    /* ptrs to coefficient quantization tables, or NULL if not defined */
  762. X
  763. X    HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  764. X    HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  765. X    /* ptrs to Huffman coding tables, or NULL if not defined */
  766. X
  767. X    UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arithmetic-coding tables */
  768. X    UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arithmetic-coding tables */
  769. X    UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arithmetic-coding tables */
  770. X
  771. X    boolean arith_code;    /* TRUE=arithmetic coding, FALSE=Huffman */
  772. X    boolean interleave;    /* TRUE=interleaved output, FALSE=not */
  773. X    boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  774. X    boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  775. X    int smoothing_factor;    /* 1..100, or 0 for no input smoothing */
  776. X
  777. X    /* The restart interval can be specified in absolute MCUs by setting
  778. X     * restart_interval, or in MCU rows by setting restart_in_rows
  779. X     * (in which case the correct restart_interval will be figured
  780. X     * for each scan).
  781. X     */
  782. X    UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
  783. X    int restart_in_rows;    /* if > 0, MCU rows per restart interval */
  784. X
  785. X/*
  786. X * These fields are computed during jpeg_compress startup
  787. X */
  788. X    short max_h_samp_factor; /* largest h_samp_factor */
  789. X    short max_v_samp_factor; /* largest v_samp_factor */
  790. X
  791. X/*
  792. X * These fields may be useful for progress monitoring
  793. X */
  794. X
  795. X    int total_passes;    /* number of passes expected */
  796. X    int completed_passes;    /* number of passes completed so far */
  797. X
  798. X/*
  799. X * These fields are valid during any one scan
  800. X */
  801. X    short comps_in_scan;    /* # of JPEG components output this time */
  802. X    jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  803. X    /* *cur_comp_info[i] describes component that appears i'th in SOS */
  804. X
  805. X    long MCUs_per_row;    /* # of MCUs across the image */
  806. X    long MCU_rows_in_scan;    /* # of MCU rows in the image */
  807. X
  808. X    short blocks_in_MCU;    /* # of DCT blocks per MCU */
  809. X    short MCU_membership[MAX_BLOCKS_IN_MCU];
  810. X    /* MCU_membership[i] is index in cur_comp_info of component owning */
  811. X    /* i'th block in an MCU */
  812. X
  813. X    /* these fields are private data for the entropy encoder */
  814. X    JCOEF last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each comp */
  815. X    JCOEF last_dc_diff[MAX_COMPS_IN_SCAN]; /* last DC diff for each comp */
  816. X    UINT16 restarts_to_go;    /* MCUs left in this restart interval */
  817. X    short next_restart_num;    /* # of next RSTn marker (0..7) */
  818. X};
  819. X
  820. Xtypedef struct Compress_info_struct * compress_info_ptr;
  821. X
  822. X
  823. X/* Working data for decompression */
  824. X
  825. Xstruct Decompress_info_struct {
  826. X/*
  827. X * These fields shall be established by the user interface before
  828. X * calling jpeg_decompress.
  829. X * Most parameters can be set to reasonable defaults by j_d_defaults.
  830. X * Note that the UI must supply the storage for the main methods struct,
  831. X * though it sets only a few of the methods there.
  832. X */
  833. X    decompress_methods_ptr methods; /* Points to list of methods to use */
  834. X
  835. X    external_methods_ptr emethods; /* Points to list of methods to use */
  836. X
  837. X    JFILEREF input_file;    /* tells input routines where to read JPEG */
  838. X    IFILEREF output_file;    /* tells output routines where to write image */
  839. X
  840. X    /* these can be set at d_ui_method_selection time: */
  841. X
  842. X    COLOR_SPACE out_color_space; /* colorspace of output */
  843. X
  844. X    double output_gamma;    /* image gamma wanted in output */
  845. X
  846. X    boolean quantize_colors; /* T if output is a colormapped format */
  847. X    /* the following are ignored if not quantize_colors: */
  848. X    boolean two_pass_quantize;    /* use two-pass color quantization? */
  849. X    boolean use_dithering;        /* want color dithering? */
  850. X    int desired_number_of_colors;    /* max number of colors to use */
  851. X
  852. X    boolean do_block_smoothing; /* T = apply cross-block smoothing */
  853. X    boolean do_pixel_smoothing; /* T = apply post-upsampling smoothing */
  854. X
  855. X/*
  856. X * These fields are used for efficient buffering of data between read_jpeg_data
  857. X * and the entropy decoding object.  By using a shared buffer, we avoid copying
  858. X * data and eliminate the need for an "unget" operation at the end of a scan.
  859. X * The actual source of the data is known only to read_jpeg_data; see the
  860. X * JGETC macro, below.
  861. X * Note: the user interface is expected to allocate the input_buffer and
  862. X * initialize bytes_in_buffer to 0.  Also, for JFIF/raw-JPEG input, the UI
  863. X * actually supplies the read_jpeg_data method.  This is all handled by
  864. X * j_d_defaults in a typical implementation.
  865. X */
  866. X    char * input_buffer;    /* start of buffer (private to input code) */
  867. X    char * next_input_byte;    /* => next byte to read from buffer */
  868. X    int bytes_in_buffer;    /* # of bytes remaining in buffer */
  869. X
  870. X/*
  871. X * These fields are set by read_file_header or read_scan_header
  872. X */
  873. X    long image_width;    /* overall image width */
  874. X    long image_height;    /* overall image height */
  875. X
  876. X    short data_precision;    /* bits of precision in image data */
  877. X
  878. X    COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
  879. X
  880. X        /* These three values are not used by the JPEG code, merely copied */
  881. X    /* from the JFIF APP0 marker (if any). */
  882. X    UINT8 density_unit;    /* JFIF code for pixel size units */
  883. X    UINT16 X_density;    /* Horizontal pixel density */
  884. X    UINT16 Y_density;    /* Vertical pixel density */
  885. X
  886. X    short num_components;    /* # of color components in JPEG image */
  887. X    jpeg_component_info * comp_info;
  888. X    /* comp_info[i] describes component that appears i'th in SOF */
  889. X
  890. X    QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
  891. X    /* ptrs to coefficient quantization tables, or NULL if not defined */
  892. X
  893. X    HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  894. X    HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  895. X    /* ptrs to Huffman coding tables, or NULL if not defined */
  896. X
  897. X    UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  898. X    UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  899. X    UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  900. X
  901. X    boolean arith_code;    /* TRUE=arithmetic coding, FALSE=Huffman */
  902. X    boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  903. X
  904. X    UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
  905. X
  906. X/*
  907. X * These fields are computed during jpeg_decompress startup
  908. X */
  909. X    short max_h_samp_factor; /* largest h_samp_factor */
  910. X    short max_v_samp_factor; /* largest v_samp_factor */
  911. X
  912. X    short color_out_comps;    /* # of color components output by color_convert */
  913. X                /* (need not match num_components) */
  914. X    short final_out_comps;    /* # of color components sent to put_pixel_rows */
  915. X    /* (1 when quantizing colors, else same as color_out_comps) */
  916. X
  917. X    JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  918. X
  919. X/*
  920. X * When quantizing colors, the color quantizer leaves a pointer to the output
  921. X * colormap in these fields.  The colormap is valid from the time put_color_map
  922. X * is called (must be before any put_pixel_rows calls) until shutdown (more
  923. X * specifically, until free_all is called to release memory).
  924. X */
  925. X    int actual_number_of_colors; /* actual number of entries */
  926. X    JSAMPARRAY colormap;    /* NULL if not valid */
  927. X    /* map has color_out_comps rows * actual_number_of_colors columns */
  928. X
  929. X/*
  930. X * These fields may be useful for progress monitoring
  931. X */
  932. X
  933. X    int total_passes;    /* number of passes expected */
  934. X    int completed_passes;    /* number of passes completed so far */
  935. X
  936. X/*
  937. X * These fields are valid during any one scan
  938. X */
  939. X    short comps_in_scan;    /* # of JPEG components input this time */
  940. X    jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  941. X    /* *cur_comp_info[i] describes component that appears i'th in SOS */
  942. X
  943. X    long MCUs_per_row;    /* # of MCUs across the image */
  944. X    long MCU_rows_in_scan;    /* # of MCU rows in the image */
  945. X
  946. X    short blocks_in_MCU;    /* # of DCT blocks per MCU */
  947. X    short MCU_membership[MAX_BLOCKS_IN_MCU];
  948. X    /* MCU_membership[i] is index in cur_comp_info of component owning */
  949. X    /* i'th block in an MCU */
  950. X
  951. X    /* these fields are private data for the entropy encoder */
  952. X    JCOEF last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each comp */
  953. X    JCOEF last_dc_diff[MAX_COMPS_IN_SCAN]; /* last DC diff for each comp */
  954. X    UINT16 restarts_to_go;    /* MCUs left in this restart interval */
  955. X    short next_restart_num;    /* # of next RSTn marker (0..7) */
  956. X};
  957. X
  958. Xtypedef struct Decompress_info_struct * decompress_info_ptr;
  959. X
  960. X
  961. X/* Macros for reading data from the decompression input buffer */
  962. X
  963. X#ifdef CHAR_IS_UNSIGNED
  964. X#define JGETC(cinfo)    ( --(cinfo)->bytes_in_buffer < 0 ? \
  965. X             (*(cinfo)->methods->read_jpeg_data) (cinfo) : \
  966. X             (int) (*(cinfo)->next_input_byte++) )
  967. X#else
  968. X#define JGETC(cinfo)    ( --(cinfo)->bytes_in_buffer < 0 ? \
  969. X             (*(cinfo)->methods->read_jpeg_data) (cinfo) : \
  970. X             (int) (*(cinfo)->next_input_byte++) & 0xFF )
  971. X#endif
  972. X
  973. X#define JUNGETC(ch,cinfo)  ((cinfo)->bytes_in_buffer++, \
  974. X                *(--((cinfo)->next_input_byte)) = (char) (ch))
  975. X
  976. X#define MIN_UNGET    4    /* may always do at least 4 JUNGETCs */
  977. X
  978. X
  979. X/* A virtual image has a control block whose contents are private to the
  980. X * memory manager module (and may differ between managers).  The rest of the
  981. X * code only refers to virtual images by these pointer types, and never
  982. X * dereferences the pointer.
  983. X */
  984. X
  985. Xtypedef struct big_sarray_control * big_sarray_ptr;
  986. Xtypedef struct big_barray_control * big_barray_ptr;
  987. X
  988. X/* Although a real ANSI C compiler can deal perfectly well with pointers to
  989. X * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
  990. X * and pseudo-ANSI compilers get confused.  To keep one of these bozos happy,
  991. X * add -DINCOMPLETE_TYPES_BROKEN to CFLAGS in your Makefile.  Then we will
  992. X * pseudo-define the structs as containing a single "dummy" field.
  993. X * The memory managers #define AM_MEMORY_MANAGER before including this file,
  994. X * so that they can make their own definitions of the structs.
  995. X */
  996. X
  997. X#ifdef INCOMPLETE_TYPES_BROKEN
  998. X#ifndef AM_MEMORY_MANAGER
  999. Xstruct big_sarray_control { long dummy; };
  1000. Xstruct big_barray_control { long dummy; };
  1001. X#endif
  1002. X#endif
  1003. X
  1004. X
  1005. X/* Method types that need typedefs */
  1006. X
  1007. Xtypedef METHOD(void, MCU_output_method_ptr, (compress_info_ptr cinfo,
  1008. X                         JBLOCK *MCU_data));
  1009. Xtypedef METHOD(void, MCU_output_caller_ptr, (compress_info_ptr cinfo,
  1010. X                         MCU_output_method_ptr output_method));
  1011. Xtypedef METHOD(void, downsample_ptr, (compress_info_ptr cinfo,
  1012. X                      int which_component,
  1013. X                      long input_cols, int input_rows,
  1014. X                      long output_cols, int output_rows,
  1015. X                      JSAMPARRAY above,
  1016. X                      JSAMPARRAY input_data,
  1017. X                      JSAMPARRAY below,
  1018. X                      JSAMPARRAY output_data));
  1019. Xtypedef METHOD(void, upsample_ptr, (decompress_info_ptr cinfo,
  1020. X                    int which_component,
  1021. X                    long input_cols, int input_rows,
  1022. X                    long output_cols, int output_rows,
  1023. X                    JSAMPARRAY above,
  1024. X                    JSAMPARRAY input_data,
  1025. X                    JSAMPARRAY below,
  1026. X                    JSAMPARRAY output_data));
  1027. Xtypedef METHOD(void, quantize_method_ptr, (decompress_info_ptr cinfo,
  1028. X                       int num_rows,
  1029. X                       JSAMPIMAGE input_data,
  1030. X                       JSAMPARRAY output_workspace));
  1031. Xtypedef METHOD(void, quantize_caller_ptr, (decompress_info_ptr cinfo,
  1032. X                       quantize_method_ptr quantize_method));
  1033. X
  1034. X
  1035. X/* These structs contain function pointers for the various JPEG methods. */
  1036. X
  1037. X/* Routines to be provided by the surrounding application, rather than the
  1038. X * portable JPEG code proper.  These are the same for compression and
  1039. X * decompression.
  1040. X */
  1041. X
  1042. Xstruct External_methods_struct {
  1043. X    /* User interface: error exit and trace message routines */
  1044. X    /* NOTE: the string msgtext parameters will eventually be replaced
  1045. X     * by an enumerated-type code so that non-English error messages
  1046. X     * can be substituted easily.  This will not be done until all the
  1047. X     * code is in place, so that we know what messages are needed.
  1048. X     */
  1049. X    METHOD(void, error_exit, (const char *msgtext));
  1050. X    METHOD(void, trace_message, (const char *msgtext));
  1051. X
  1052. X    /* Working data for error/trace facility */
  1053. X    /* See macros below for the usage of these variables */
  1054. X    int trace_level;    /* level of detail of tracing messages */
  1055. X    /* Use level 0 for important warning messages (nonfatal errors) */
  1056. X    /* Use levels 1, 2, 3 for successively more detailed trace options */
  1057. X
  1058. X    /* For recoverable corrupt-data errors, we emit a warning message and
  1059. X     * keep going.  A surrounding application can check for bad data by
  1060. X     * seeing if num_warnings is nonzero at the end of processing.
  1061. X     */
  1062. X    long num_warnings;    /* number of corrupt-data warnings */
  1063. X    int first_warning_level; /* trace level for first warning */
  1064. X    int more_warning_level;    /* trace level for subsequent warnings */
  1065. X
  1066. X    int message_parm[8];    /* store numeric parms for messages here */
  1067. X
  1068. X    /* Memory management */
  1069. X    /* NB: alloc routines never return NULL. They exit to */
  1070. X    /* error_exit if not successful. */
  1071. X    METHOD(void *, alloc_small, (size_t sizeofobject));
  1072. X    METHOD(void, free_small, (void *ptr));
  1073. X    METHOD(void FAR *, alloc_medium, (size_t sizeofobject));
  1074. X    METHOD(void, free_medium, (void FAR *ptr));
  1075. X    METHOD(JSAMPARRAY, alloc_small_sarray, (long samplesperrow,
  1076. X                        long numrows));
  1077. X    METHOD(void, free_small_sarray, (JSAMPARRAY ptr));
  1078. X    METHOD(JBLOCKARRAY, alloc_small_barray, (long blocksperrow,
  1079. X                         long numrows));
  1080. X    METHOD(void, free_small_barray, (JBLOCKARRAY ptr));
  1081. X    METHOD(big_sarray_ptr, request_big_sarray, (long samplesperrow,
  1082. X                            long numrows,
  1083. X                            long unitheight));
  1084. X    METHOD(big_barray_ptr, request_big_barray, (long blocksperrow,
  1085. X                            long numrows,
  1086. X                            long unitheight));
  1087. X    METHOD(void, alloc_big_arrays, (long extra_small_samples,
  1088. X                    long extra_small_blocks,
  1089. X                    long extra_medium_space));
  1090. X    METHOD(JSAMPARRAY, access_big_sarray, (big_sarray_ptr ptr,
  1091. X                           long start_row,
  1092. X                           boolean writable));
  1093. X    METHOD(JBLOCKARRAY, access_big_barray, (big_barray_ptr ptr,
  1094. X                        long start_row,
  1095. X                        boolean writable));
  1096. X    METHOD(void, free_big_sarray, (big_sarray_ptr ptr));
  1097. X    METHOD(void, free_big_barray, (big_barray_ptr ptr));
  1098. X    METHOD(void, free_all, (void));
  1099. X
  1100. X    long max_memory_to_use;    /* maximum amount of memory to use */
  1101. X};
  1102. X
  1103. X/* Macros to simplify using the error and trace message stuff */
  1104. X/* The first parameter is generally cinfo->emethods */
  1105. X
  1106. X/* Fatal errors (print message and exit) */
  1107. X#define ERREXIT(emeth,msg)        ((*(emeth)->error_exit) (msg))
  1108. X#define ERREXIT1(emeth,msg,p1)        ((emeth)->message_parm[0] = (p1), \
  1109. X                     (*(emeth)->error_exit) (msg))
  1110. X#define ERREXIT2(emeth,msg,p1,p2)    ((emeth)->message_parm[0] = (p1), \
  1111. X                     (emeth)->message_parm[1] = (p2), \
  1112. X                     (*(emeth)->error_exit) (msg))
  1113. X#define ERREXIT3(emeth,msg,p1,p2,p3)    ((emeth)->message_parm[0] = (p1), \
  1114. X                     (emeth)->message_parm[1] = (p2), \
  1115. X                     (emeth)->message_parm[2] = (p3), \
  1116. X                     (*(emeth)->error_exit) (msg))
  1117. X#define ERREXIT4(emeth,msg,p1,p2,p3,p4) ((emeth)->message_parm[0] = (p1), \
  1118. X                     (emeth)->message_parm[1] = (p2), \
  1119. X                     (emeth)->message_parm[2] = (p3), \
  1120. X                     (emeth)->message_parm[3] = (p4), \
  1121. X                     (*(emeth)->error_exit) (msg))
  1122. X
  1123. X#define MAKESTMT(stuff)        do { stuff } while (0)
  1124. X
  1125. X/* Nonfatal errors (we'll keep going, but the data is probably corrupt) */
  1126. X/* Note that warning count is incremented as a side-effect! */
  1127. X#define WARNMS(emeth,msg)    \
  1128. X  MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  1129. X        (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  1130. X        (*(emeth)->trace_message) (msg); } )
  1131. X#define WARNMS1(emeth,msg,p1)    \
  1132. X  MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  1133. X        (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  1134. X        (emeth)->message_parm[0] = (p1); \
  1135. X        (*(emeth)->trace_message) (msg); } )
  1136. X#define WARNMS2(emeth,msg,p1,p2)    \
  1137. X  MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  1138. X        (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  1139. X        (emeth)->message_parm[0] = (p1); \
  1140. X        (emeth)->message_parm[1] = (p2); \
  1141. X        (*(emeth)->trace_message) (msg); } )
  1142. X
  1143. X/* Informational/debugging messages */
  1144. X#define TRACEMS(emeth,lvl,msg)    \
  1145. X  MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  1146. X        (*(emeth)->trace_message) (msg); } )
  1147. X#define TRACEMS1(emeth,lvl,msg,p1)    \
  1148. X  MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  1149. X        (emeth)->message_parm[0] = (p1); \
  1150. X        (*(emeth)->trace_message) (msg); } )
  1151. X#define TRACEMS2(emeth,lvl,msg,p1,p2)    \
  1152. X  MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  1153. X        (emeth)->message_parm[0] = (p1); \
  1154. X        (emeth)->message_parm[1] = (p2); \
  1155. X        (*(emeth)->trace_message) (msg); } )
  1156. X#define TRACEMS3(emeth,lvl,msg,p1,p2,p3)    \
  1157. X  MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  1158. X        int * _mp = (emeth)->message_parm; \
  1159. X        *_mp++ = (p1); *_mp++ = (p2); *_mp = (p3); \
  1160. X        (*(emeth)->trace_message) (msg); } )
  1161. X#define TRACEMS4(emeth,lvl,msg,p1,p2,p3,p4)    \
  1162. X  MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  1163. X        int * _mp = (emeth)->message_parm; \
  1164. X        *_mp++ = (p1); *_mp++ = (p2); *_mp++ = (p3); *_mp = (p4); \
  1165. X        (*(emeth)->trace_message) (msg); } )
  1166. X#define TRACEMS8(emeth,lvl,msg,p1,p2,p3,p4,p5,p6,p7,p8)    \
  1167. X  MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  1168. X        int * _mp = (emeth)->message_parm; \
  1169. X        *_mp++ = (p1); *_mp++ = (p2); *_mp++ = (p3); *_mp++ = (p4); \
  1170. X        *_mp++ = (p5); *_mp++ = (p6); *_mp++ = (p7); *_mp = (p8); \
  1171. X        (*(emeth)->trace_message) (msg); } )
  1172. X
  1173. X
  1174. X/* Methods used during JPEG compression. */
  1175. X
  1176. Xstruct Compress_methods_struct {
  1177. X    /* Hook for user interface to get control after input_init */
  1178. X    METHOD(void, c_ui_method_selection, (compress_info_ptr cinfo));
  1179. X    /* Hook for user interface to do progress monitoring */
  1180. X    METHOD(void, progress_monitor, (compress_info_ptr cinfo,
  1181. X                    long loopcounter, long looplimit));
  1182. X    /* Input image reading & conversion to standard form */
  1183. X    METHOD(void, input_init, (compress_info_ptr cinfo));
  1184. X    METHOD(void, get_input_row, (compress_info_ptr cinfo,
  1185. X                     JSAMPARRAY pixel_row));
  1186. X    METHOD(void, input_term, (compress_info_ptr cinfo));
  1187. X    /* Color space and gamma conversion */
  1188. X    METHOD(void, colorin_init, (compress_info_ptr cinfo));
  1189. X    METHOD(void, get_sample_rows, (compress_info_ptr cinfo,
  1190. X                       int rows_to_read,
  1191. X                       JSAMPIMAGE image_data));
  1192. X    METHOD(void, colorin_term, (compress_info_ptr cinfo));
  1193. X    /* Expand picture data at edges */
  1194. X    METHOD(void, edge_expand, (compress_info_ptr cinfo,
  1195. X                   long input_cols, int input_rows,
  1196. X                   long output_cols, int output_rows,
  1197. X                   JSAMPIMAGE image_data));
  1198. X    /* Downsample pixel values of a single component */
  1199. X    /* There can be a different downsample method for each component */
  1200. X    METHOD(void, downsample_init, (compress_info_ptr cinfo));
  1201. X    downsample_ptr downsample[MAX_COMPS_IN_SCAN];
  1202. X    METHOD(void, downsample_term, (compress_info_ptr cinfo));
  1203. X    /* Extract samples in MCU order, process & hand off to output_method */
  1204. X    /* The input is always exactly N MCU rows worth of data */
  1205. X    METHOD(void, extract_init, (compress_info_ptr cinfo));
  1206. X    METHOD(void, extract_MCUs, (compress_info_ptr cinfo,
  1207. X                    JSAMPIMAGE image_data,
  1208. X                    int num_mcu_rows,
  1209. X                    MCU_output_method_ptr output_method));
  1210. X    METHOD(void, extract_term, (compress_info_ptr cinfo));
  1211. X    /* Entropy encoding parameter optimization */
  1212. X    METHOD(void, entropy_optimize, (compress_info_ptr cinfo,
  1213. X                    MCU_output_caller_ptr source_method));
  1214. X    /* Entropy encoding */
  1215. X    METHOD(void, entropy_encode_init, (compress_info_ptr cinfo));
  1216. X    METHOD(void, entropy_encode, (compress_info_ptr cinfo,
  1217. X                      JBLOCK *MCU_data));
  1218. X    METHOD(void, entropy_encode_term, (compress_info_ptr cinfo));
  1219. X    /* JPEG file header construction */
  1220. X    METHOD(void, write_file_header, (compress_info_ptr cinfo));
  1221. X    METHOD(void, write_scan_header, (compress_info_ptr cinfo));
  1222. X    METHOD(void, write_jpeg_data, (compress_info_ptr cinfo,
  1223. X                       char *dataptr,
  1224. X                       int datacount));
  1225. X    METHOD(void, write_scan_trailer, (compress_info_ptr cinfo));
  1226. X    METHOD(void, write_file_trailer, (compress_info_ptr cinfo));
  1227. X    /* Pipeline control */
  1228. X    METHOD(void, c_pipeline_controller, (compress_info_ptr cinfo));
  1229. X    METHOD(void, entropy_output, (compress_info_ptr cinfo,
  1230. X                      char *dataptr,
  1231. X                      int datacount));
  1232. X    /* Overall control */
  1233. X    METHOD(void, c_per_scan_method_selection, (compress_info_ptr cinfo));
  1234. X};
  1235. X
  1236. X/* Methods used during JPEG decompression. */
  1237. X
  1238. Xstruct Decompress_methods_struct {
  1239. X    /* Hook for user interface to get control after reading file header */
  1240. X    METHOD(void, d_ui_method_selection, (decompress_info_ptr cinfo));
  1241. X    /* Hook for user interface to do progress monitoring */
  1242. X    METHOD(void, progress_monitor, (decompress_info_ptr cinfo,
  1243. X                    long loopcounter, long looplimit));
  1244. X    /* JPEG file scanning */
  1245. X    METHOD(void, read_file_header, (decompress_info_ptr cinfo));
  1246. X    METHOD(boolean, read_scan_header, (decompress_info_ptr cinfo));
  1247. X    METHOD(int, read_jpeg_data, (decompress_info_ptr cinfo));
  1248. X    METHOD(void, resync_to_restart, (decompress_info_ptr cinfo,
  1249. X                     int marker));
  1250. X    METHOD(void, read_scan_trailer, (decompress_info_ptr cinfo));
  1251. X    METHOD(void, read_file_trailer, (decompress_info_ptr cinfo));
  1252. X    /* Entropy decoding */
  1253. X    METHOD(void, entropy_decode_init, (decompress_info_ptr cinfo));
  1254. X    METHOD(void, entropy_decode, (decompress_info_ptr cinfo,
  1255. X                      JBLOCKROW *MCU_data));
  1256. X    METHOD(void, entropy_decode_term, (decompress_info_ptr cinfo));
  1257. X    /* MCU disassembly: fetch MCUs from entropy_decode, build coef array */
  1258. X    /* The reverse_DCT step is in the same module for symmetry reasons */
  1259. X    METHOD(void, disassemble_init, (decompress_info_ptr cinfo));
  1260. X    METHOD(void, disassemble_MCU, (decompress_info_ptr cinfo,
  1261. X                       JBLOCKIMAGE image_data));
  1262. X    METHOD(void, reverse_DCT, (decompress_info_ptr cinfo,
  1263. X                   JBLOCKIMAGE coeff_data,
  1264. X                   JSAMPIMAGE output_data, int start_row));
  1265. X    METHOD(void, disassemble_term, (decompress_info_ptr cinfo));
  1266. X    /* Cross-block smoothing */
  1267. X    METHOD(void, smooth_coefficients, (decompress_info_ptr cinfo,
  1268. X                       jpeg_component_info *compptr,
  1269. X                       JBLOCKROW above,
  1270. X                       JBLOCKROW currow,
  1271. X                       JBLOCKROW below,
  1272. X                       JBLOCKROW output));
  1273. X    /* Upsample pixel values of a single component */
  1274. X    /* There can be a different upsample method for each component */
  1275. X    METHOD(void, upsample_init, (decompress_info_ptr cinfo));
  1276. X    upsample_ptr upsample[MAX_COMPS_IN_SCAN];
  1277. X    METHOD(void, upsample_term, (decompress_info_ptr cinfo));
  1278. X    /* Color space and gamma conversion */
  1279. X    METHOD(void, colorout_init, (decompress_info_ptr cinfo));
  1280. X    METHOD(void, color_convert, (decompress_info_ptr cinfo,
  1281. X                     int num_rows, long num_cols,
  1282. X                     JSAMPIMAGE input_data,
  1283. X                     JSAMPIMAGE output_data));
  1284. X    METHOD(void, colorout_term, (decompress_info_ptr cinfo));
  1285. X    /* Color quantization */
  1286. X    METHOD(void, color_quant_init, (decompress_info_ptr cinfo));
  1287. X    METHOD(void, color_quantize, (decompress_info_ptr cinfo,
  1288. X                      int num_rows,
  1289. X                      JSAMPIMAGE input_data,
  1290. X                      JSAMPARRAY output_data));
  1291. X    METHOD(void, color_quant_prescan, (decompress_info_ptr cinfo,
  1292. X                       int num_rows,
  1293. X                       JSAMPIMAGE image_data,
  1294. X                       JSAMPARRAY workspace));
  1295. X    METHOD(void, color_quant_doit, (decompress_info_ptr cinfo,
  1296. X                    quantize_caller_ptr source_method));
  1297. X    METHOD(void, color_quant_term, (decompress_info_ptr cinfo));
  1298. X    /* Output image writing */
  1299. X    METHOD(void, output_init, (decompress_info_ptr cinfo));
  1300. X    METHOD(void, put_color_map, (decompress_info_ptr cinfo,
  1301. X                     int num_colors, JSAMPARRAY colormap));
  1302. X    METHOD(void, put_pixel_rows, (decompress_info_ptr cinfo,
  1303. X                      int num_rows,
  1304. X                      JSAMPIMAGE pixel_data));
  1305. X    METHOD(void, output_term, (decompress_info_ptr cinfo));
  1306. X    /* Pipeline control */
  1307. X    METHOD(void, d_pipeline_controller, (decompress_info_ptr cinfo));
  1308. X    /* Overall control */
  1309. X    METHOD(void, d_per_scan_method_selection, (decompress_info_ptr cinfo));
  1310. X};
  1311. X
  1312. X
  1313. X/* External declarations for routines that aren't called via method ptrs. */
  1314. X/* Note: use "j" as first char of names to minimize namespace pollution. */
  1315. X/* The PP macro hides prototype parameters from compilers that can't cope. */
  1316. X
  1317. X#ifdef PROTO
  1318. X#define PP(arglist)    arglist
  1319. X#else
  1320. X#define PP(arglist)    ()
  1321. X#endif
  1322. X
  1323. X
  1324. X/* main entry for compression */
  1325. XEXTERN void jpeg_compress PP((compress_info_ptr cinfo));
  1326. X
  1327. X/* default parameter setup for compression */
  1328. XEXTERN void j_c_defaults PP((compress_info_ptr cinfo, int quality,
  1329. X                 boolean force_baseline));
  1330. XEXTERN void j_monochrome_default PP((compress_info_ptr cinfo));
  1331. XEXTERN void j_set_quality PP((compress_info_ptr cinfo, int quality,
  1332. X                  boolean force_baseline));
  1333. X/* advanced compression parameter setup aids */
  1334. XEXTERN void j_add_quant_table PP((compress_info_ptr cinfo, int which_tbl,
  1335. X                  const QUANT_VAL *basic_table,
  1336. X                  int scale_factor, boolean force_baseline));
  1337. XEXTERN int j_quality_scaling PP((int quality));
  1338. X
  1339. X/* main entry for decompression */
  1340. XEXTERN void jpeg_decompress PP((decompress_info_ptr cinfo));
  1341. X
  1342. X/* default parameter setup for decompression */
  1343. XEXTERN void j_d_defaults PP((decompress_info_ptr cinfo,
  1344. X                 boolean standard_buffering));
  1345. X
  1346. X/* forward DCT */
  1347. XEXTERN void j_fwd_dct PP((DCTBLOCK data));
  1348. X/* inverse DCT */
  1349. XEXTERN void j_rev_dct PP((DCTBLOCK data));
  1350. X
  1351. X/* utility routines in jutils.c */
  1352. XEXTERN long jround_up PP((long a, long b));
  1353. XEXTERN void jcopy_sample_rows PP((JSAMPARRAY input_array, int source_row,
  1354. X                  JSAMPARRAY output_array, int dest_row,
  1355. X                  int num_rows, long num_cols));
  1356. XEXTERN void jcopy_block_row PP((JBLOCKROW input_row, JBLOCKROW output_row,
  1357. X                long num_blocks));
  1358. XEXTERN void jzero_far PP((void FAR * target, size_t bytestozero));
  1359. X
  1360. X/* method selection routines for compression modules */
  1361. XEXTERN void jselcpipeline PP((compress_info_ptr cinfo)); /* jcpipe.c */
  1362. XEXTERN void jselchuffman PP((compress_info_ptr cinfo)); /* jchuff.c */
  1363. XEXTERN void jselcarithmetic PP((compress_info_ptr cinfo)); /* jcarith.c */
  1364. XEXTERN void jselexpand PP((compress_info_ptr cinfo)); /* jcexpand.c */
  1365. XEXTERN void jseldownsample PP((compress_info_ptr cinfo)); /* jcsample.c */
  1366. XEXTERN void jselcmcu PP((compress_info_ptr cinfo)); /* jcmcu.c */
  1367. XEXTERN void jselccolor PP((compress_info_ptr cinfo));    /* jccolor.c */
  1368. X/* The user interface should call one of these to select input format: */
  1369. XEXTERN void jselrgif PP((compress_info_ptr cinfo)); /* jrdgif.c */
  1370. XEXTERN void jselrppm PP((compress_info_ptr cinfo)); /* jrdppm.c */
  1371. XEXTERN void jselrrle PP((compress_info_ptr cinfo)); /* jrdrle.c */
  1372. XEXTERN void jselrtarga PP((compress_info_ptr cinfo)); /* jrdtarga.c */
  1373. X/* and one of these to select output header format: */
  1374. XEXTERN void jselwjfif PP((compress_info_ptr cinfo)); /* jwrjfif.c */
  1375. X
  1376. X/* method selection routines for decompression modules */
  1377. XEXTERN void jseldpipeline PP((decompress_info_ptr cinfo)); /* jdpipe.c */
  1378. XEXTERN void jseldhuffman PP((decompress_info_ptr cinfo)); /* jdhuff.c */
  1379. XEXTERN void jseldarithmetic PP((decompress_info_ptr cinfo)); /* jdarith.c */
  1380. XEXTERN void jseldmcu PP((decompress_info_ptr cinfo)); /* jdmcu.c */
  1381. XEXTERN void jselbsmooth PP((decompress_info_ptr cinfo)); /* jbsmooth.c */
  1382. XEXTERN void jselupsample PP((decompress_info_ptr cinfo)); /* jdsample.c */
  1383. XEXTERN void jseldcolor PP((decompress_info_ptr cinfo));    /* jdcolor.c */
  1384. XEXTERN void jsel1quantize PP((decompress_info_ptr cinfo)); /* jquant1.c */
  1385. XEXTERN void jsel2quantize PP((decompress_info_ptr cinfo)); /* jquant2.c */
  1386. X/* The user interface should call one of these to select input format: */
  1387. XEXTERN void jselrjfif PP((decompress_info_ptr cinfo)); /* jrdjfif.c */
  1388. X/* and one of these to select output image format: */
  1389. XEXTERN void jselwgif PP((decompress_info_ptr cinfo)); /* jwrgif.c */
  1390. XEXTERN void jselwppm PP((decompress_info_ptr cinfo)); /* jwrppm.c */
  1391. XEXTERN void jselwrle PP((decompress_info_ptr cinfo)); /* jwrrle.c */
  1392. XEXTERN void jselwtarga PP((decompress_info_ptr cinfo)); /* jwrtarga.c */
  1393. X
  1394. X/* method selection routines for system-dependent modules */
  1395. XEXTERN void jselerror PP((external_methods_ptr emethods)); /* jerror.c */
  1396. XEXTERN void jselmemmgr PP((external_methods_ptr emethods)); /* jmemmgr.c */
  1397. X
  1398. X
  1399. X/* We assume that right shift corresponds to signed division by 2 with
  1400. X * rounding towards minus infinity.  This is correct for typical "arithmetic
  1401. X * shift" instructions that shift in copies of the sign bit.  But some
  1402. X * C compilers implement >> with an unsigned shift.  For these machines you
  1403. X * must define RIGHT_SHIFT_IS_UNSIGNED.
  1404. X * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
  1405. X * It is only applied with constant shift counts.  SHIFT_TEMPS must be
  1406. X * included in the variables of any routine using RIGHT_SHIFT.
  1407. X */
  1408. X
  1409. X#ifdef RIGHT_SHIFT_IS_UNSIGNED
  1410. X#define SHIFT_TEMPS    INT32 shift_temp;
  1411. X#define RIGHT_SHIFT(x,shft)  \
  1412. X    ((shift_temp = (x)) < 0 ? \
  1413. X     (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  1414. X     (shift_temp >> (shft)))
  1415. X#else
  1416. X#define SHIFT_TEMPS
  1417. X#define RIGHT_SHIFT(x,shft)    ((x) >> (shft))
  1418. X#endif
  1419. X
  1420. X
  1421. X/* Miscellaneous useful macros */
  1422. X
  1423. X#undef MAX
  1424. X#define MAX(a,b)    ((a) > (b) ? (a) : (b))
  1425. X#undef MIN
  1426. X#define MIN(a,b)    ((a) < (b) ? (a) : (b))
  1427. X
  1428. X
  1429. X#define RST0    0xD0        /* RST0 marker code */
  1430. END_OF_FILE
  1431.   if test 39469 -ne `wc -c <'jpegdata.h'`; then
  1432.     echo shar: \"'jpegdata.h'\" unpacked with wrong size!
  1433.   fi
  1434.   # end of 'jpegdata.h'
  1435. fi
  1436. echo shar: End of archive 4 \(of 18\).
  1437. cp /dev/null ark4isdone
  1438. MISSING=""
  1439. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1440.     if test ! -f ark${I}isdone ; then
  1441.     MISSING="${MISSING} ${I}"
  1442.     fi
  1443. done
  1444. if test "${MISSING}" = "" ; then
  1445.     echo You have unpacked all 18 archives.
  1446.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1447. else
  1448.     echo You still must unpack the following archives:
  1449.     echo "        " ${MISSING}
  1450. fi
  1451. exit 0
  1452. exit 0 # Just in case...
  1453.