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

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v34i059:  jpeg - JPEG image compression, Part05/18
  4. Message-ID: <1992Dec17.041700.23384@sparky.imd.sterling.com>
  5. X-Md4-Signature: ece542448522b9ffc18afbf6155d885a
  6. Date: Thu, 17 Dec 1992 04:17:00 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 59
  11. Archive-name: jpeg/part05
  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:  ansi2knr.c jdpipe.c makvms.opt
  20. # Wrapped by kent@sparky on Wed Dec 16 20:52:26 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 5 (of 18)."'
  24. if test -f 'ansi2knr.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'ansi2knr.c'\"
  26. else
  27.   echo shar: Extracting \"'ansi2knr.c'\" \(16228 characters\)
  28.   sed "s/^X//" >'ansi2knr.c' <<'END_OF_FILE'
  29. X/* Copyright (C) 1989, 1991 Aladdin Enterprises.  All rights reserved.
  30. X   Distributed by Free Software Foundation, Inc.
  31. X
  32. XThis file is part of Ghostscript.
  33. X
  34. XGhostscript is distributed in the hope that it will be useful, but
  35. XWITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  36. Xto anyone for the consequences of using it or for whether it serves any
  37. Xparticular purpose or works at all, unless he says so in writing.  Refer
  38. Xto the Ghostscript General Public License for full details.
  39. X
  40. XEveryone is granted permission to copy, modify and redistribute
  41. XGhostscript, but only under the conditions described in the Ghostscript
  42. XGeneral Public License.  A copy of this license is supposed to have been
  43. Xgiven to you along with Ghostscript so you can know your rights and
  44. Xresponsibilities.  It should be in a file named COPYING.  Among other
  45. Xthings, the copyright notice and this notice must be preserved on all
  46. Xcopies.  */
  47. X
  48. X/*
  49. X---------- Here is the GhostScript file COPYING, referred to above ----------
  50. X----- These terms do NOT apply to the JPEG software itself; see README ------
  51. X
  52. X            GHOSTSCRIPT GENERAL PUBLIC LICENSE
  53. X            (Clarified 11 Feb 1988)
  54. X
  55. X Copyright (C) 1988 Richard M. Stallman
  56. X Everyone is permitted to copy and distribute verbatim copies of this
  57. X license, but changing it is not allowed.  You can also use this wording
  58. X to make the terms for other programs.
  59. X
  60. X  The license agreements of most software companies keep you at the
  61. Xmercy of those companies.  By contrast, our general public license is
  62. Xintended to give everyone the right to share Ghostscript.  To make sure
  63. Xthat you get the rights we want you to have, we need to make
  64. Xrestrictions that forbid anyone to deny you these rights or to ask you
  65. Xto surrender the rights.  Hence this license agreement.
  66. X
  67. X  Specifically, we want to make sure that you have the right to give
  68. Xaway copies of Ghostscript, that you receive source code or else can get
  69. Xit if you want it, that you can change Ghostscript or use pieces of it
  70. Xin new free programs, and that you know you can do these things.
  71. X
  72. X  To make sure that everyone has such rights, we have to forbid you to
  73. Xdeprive anyone else of these rights.  For example, if you distribute
  74. Xcopies of Ghostscript, you must give the recipients all the rights that
  75. Xyou have.  You must make sure that they, too, receive or can get the
  76. Xsource code.  And you must tell them their rights.
  77. X
  78. X  Also, for our own protection, we must make certain that everyone finds
  79. Xout that there is no warranty for Ghostscript.  If Ghostscript is
  80. Xmodified by someone else and passed on, we want its recipients to know
  81. Xthat what they have is not what we distributed, so that any problems
  82. Xintroduced by others will not reflect on our reputation.
  83. X
  84. X  Therefore we (Richard M. Stallman and the Free Software Foundation,
  85. XInc.) make the following terms which say what you must do to be allowed
  86. Xto distribute or change Ghostscript.
  87. X
  88. X
  89. X            COPYING POLICIES
  90. X
  91. X  1. You may copy and distribute verbatim copies of Ghostscript source
  92. Xcode as you receive it, in any medium, provided that you conspicuously
  93. Xand appropriately publish on each copy a valid copyright and license
  94. Xnotice "Copyright (C) 1989 Aladdin Enterprises.  All rights reserved.
  95. XDistributed by Free Software Foundation, Inc." (or with whatever year is
  96. Xappropriate); keep intact the notices on all files that refer to this
  97. XLicense Agreement and to the absence of any warranty; and give any other
  98. Xrecipients of the Ghostscript program a copy of this License Agreement
  99. Xalong with the program.  You may charge a distribution fee for the
  100. Xphysical act of transferring a copy.
  101. X
  102. X  2. You may modify your copy or copies of Ghostscript or any portion of
  103. Xit, and copy and distribute such modifications under the terms of
  104. XParagraph 1 above, provided that you also do the following:
  105. X
  106. X    a) cause the modified files to carry prominent notices stating
  107. X    that you changed the files and the date of any change; and
  108. X
  109. X    b) cause the whole of any work that you distribute or publish,
  110. X    that in whole or in part contains or is a derivative of Ghostscript
  111. X    or any part thereof, to be licensed at no charge to all third
  112. X    parties on terms identical to those contained in this License
  113. X    Agreement (except that you may choose to grant more extensive
  114. X    warranty protection to some or all third parties, at your option).
  115. X
  116. X    c) You may charge a distribution fee for the physical act of
  117. X    transferring a copy, and you may at your option offer warranty
  118. X    protection in exchange for a fee.
  119. X
  120. XMere aggregation of another unrelated program with this program (or its
  121. Xderivative) on a volume of a storage or distribution medium does not bring
  122. Xthe other program under the scope of these terms.
  123. X
  124. X  3. You may copy and distribute Ghostscript (or a portion or derivative
  125. Xof it, under Paragraph 2) in object code or executable form under the
  126. Xterms of Paragraphs 1 and 2 above provided that you also do one of the
  127. Xfollowing:
  128. X
  129. X    a) accompany it with the complete corresponding machine-readable
  130. X    source code, which must be distributed under the terms of
  131. X    Paragraphs 1 and 2 above; or,
  132. X
  133. X    b) accompany it with a written offer, valid for at least three
  134. X    years, to give any third party free (except for a nominal
  135. X    shipping charge) a complete machine-readable copy of the
  136. X    corresponding source code, to be distributed under the terms of
  137. X    Paragraphs 1 and 2 above; or,
  138. X
  139. X    c) accompany it with the information you received as to where the
  140. X    corresponding source code may be obtained.  (This alternative is
  141. X    allowed only for noncommercial distribution and only if you
  142. X    received the program in object code or executable form alone.)
  143. X
  144. XFor an executable file, complete source code means all the source code for
  145. Xall modules it contains; but, as a special exception, it need not include
  146. Xsource code for modules which are standard libraries that accompany the
  147. Xoperating system on which the executable file runs.
  148. X
  149. X  4. You may not copy, sublicense, distribute or transfer Ghostscript
  150. Xexcept as expressly provided under this License Agreement.  Any attempt
  151. Xotherwise to copy, sublicense, distribute or transfer Ghostscript is
  152. Xvoid and your rights to use the program under this License agreement
  153. Xshall be automatically terminated.  However, parties who have received
  154. Xcomputer software programs from you with this License Agreement will not
  155. Xhave their licenses terminated so long as such parties remain in full
  156. Xcompliance.
  157. X
  158. X  5. If you wish to incorporate parts of Ghostscript into other free
  159. Xprograms whose distribution conditions are different, write to the Free
  160. XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not
  161. Xyet worked out a simple rule that can be stated here, but we will often
  162. Xpermit this.  We will be guided by the two goals of preserving the free
  163. Xstatus of all derivatives of our free software and of promoting the
  164. Xsharing and reuse of software.
  165. X
  166. XYour comments and suggestions about our licensing policies and our
  167. Xsoftware are welcome!  Please contact the Free Software Foundation,
  168. XInc., 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
  169. X
  170. X               NO WARRANTY
  171. X
  172. X  BECAUSE GHOSTSCRIPT IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  173. XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  174. XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD
  175. XM. STALLMAN, ALADDIN ENTERPRISES, L. PETER DEUTSCH, AND/OR OTHER PARTIES
  176. XPROVIDE GHOSTSCRIPT "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
  177. XEXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  178. XWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE
  179. XENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF GHOSTSCRIPT IS WITH
  180. XYOU.  SHOULD GHOSTSCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
  181. XNECESSARY SERVICING, REPAIR OR CORRECTION.
  182. X
  183. X  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  184. XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., L. PETER DEUTSCH, ALADDIN
  185. XENTERPRISES, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE
  186. XGHOSTSCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
  187. XANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR
  188. XCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
  189. X(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
  190. XINACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
  191. XPROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
  192. XHAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
  193. XBY ANY OTHER PARTY.
  194. X-------------------- End of file COPYING ------------------------------
  195. X*/
  196. X
  197. X
  198. X/* ansi2knr.c */
  199. X/* Convert ANSI function declarations to K&R syntax */
  200. X
  201. X#include <stdio.h>
  202. X#include <ctype.h>
  203. X
  204. X#ifdef BSD
  205. X#include <strings.h>
  206. X#define strchr index
  207. X#else
  208. X#ifdef VMS
  209. X    extern char *strcat(), *strchr(), *strcpy(), *strupr();
  210. X    extern int strcmp(), strlen(), strncmp();
  211. X#else
  212. X#include <string.h>
  213. X#endif
  214. X#endif
  215. X
  216. X#ifdef MSDOS
  217. X#include <malloc.h>
  218. X#else
  219. X#ifdef VMS
  220. X     extern char *malloc();
  221. X     extern void free();
  222. X#else
  223. X     extern char *malloc();
  224. X     extern int free();
  225. X#endif
  226. X#endif
  227. X
  228. X/* Usage:
  229. X    ansi2knr input_file output_file
  230. X * If no output_file is supplied, output goes to stdout.
  231. X * There are no error messages.
  232. X *
  233. X * ansi2knr recognizes functions by seeing a non-keyword identifier
  234. X * at the left margin, followed by a left parenthesis,
  235. X * with a right parenthesis as the last character on the line.
  236. X * It will recognize a multi-line header if the last character
  237. X * on each line but the last is a left parenthesis or comma.
  238. X * These algorithms ignore whitespace and comments, except that
  239. X * the function name must be the first thing on the line.
  240. X * The following constructs will confuse it:
  241. X    - Any other construct that starts at the left margin and
  242. X        follows the above syntax (such as a macro or function call).
  243. X    - Macros that tinker with the syntax of the function header.
  244. X */
  245. X
  246. X/* Scanning macros */
  247. X#define isidchar(ch) (isalnum(ch) || (ch) == '_')
  248. X#define isidfirstchar(ch) (isalpha(ch) || (ch) == '_')
  249. X
  250. Xmain(argc, argv)
  251. X    int argc;
  252. X    char *argv[];
  253. X{    FILE *in, *out;
  254. X#define bufsize 5000            /* arbitrary size */
  255. X    char *buf;
  256. X    char *line;
  257. X    switch ( argc )
  258. X       {
  259. X    default:
  260. X        printf("Usage: ansi2knr input_file [output_file]\n");
  261. X        exit(0);
  262. X    case 2:
  263. X        out = stdout; break;
  264. X    case 3:
  265. X        out = fopen(argv[2], "w");
  266. X        if ( out == NULL )
  267. X           {    fprintf(stderr, "Cannot open %s\n", argv[2]);
  268. X            exit(1);
  269. X           }
  270. X       }
  271. X    in = fopen(argv[1], "r");
  272. X    if ( in == NULL )
  273. X       {    fprintf(stderr, "Cannot open %s\n", argv[1]);
  274. X        exit(1);
  275. X       }
  276. X    fprintf(out, "#line 1 \"%s\"\n", argv[1]);
  277. X    buf = malloc(bufsize);
  278. X    line = buf;
  279. X    while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
  280. X       {    switch ( test1(buf) )
  281. X           {
  282. X        case 1:            /* a function */
  283. X            convert1(buf, out);
  284. X            break;
  285. X        case -1:        /* maybe the start of a function */
  286. X            line = buf + strlen(buf);
  287. X            if ( line != buf + (bufsize - 1) ) /* overflow check */
  288. X                continue;
  289. X            /* falls through */
  290. X        default:        /* not a function */
  291. X            fputs(buf, out);
  292. X            break;
  293. X           }
  294. X        line = buf;
  295. X       }
  296. X    if ( line != buf ) fputs(buf, out);
  297. X    free(buf);
  298. X    fclose(out);
  299. X    fclose(in);
  300. X    return 0;
  301. X}
  302. X
  303. X/* Skip over space and comments, in either direction. */
  304. Xchar *
  305. Xskipspace(p, dir)
  306. X    register char *p;
  307. X    register int dir;            /* 1 for forward, -1 for backward */
  308. X{    for ( ; ; )
  309. X       {    while ( isspace(*p) ) p += dir;
  310. X        if ( !(*p == '/' && p[dir] == '*') ) break;
  311. X        p += dir;  p += dir;
  312. X        while ( !(*p == '*' && p[dir] == '/') )
  313. X           {    if ( *p == 0 ) return p;    /* multi-line comment?? */
  314. X            p += dir;
  315. X           }
  316. X        p += dir;  p += dir;
  317. X       }
  318. X    return p;
  319. X}
  320. X
  321. X/*
  322. X * Write blanks over part of a string.
  323. X */
  324. Xint
  325. Xwriteblanks(start, end)
  326. X    char *start;
  327. X    char *end;
  328. X{    char *p;
  329. X    for ( p = start; p < end; p++ ) *p = ' ';
  330. X    return 0;
  331. X}
  332. X
  333. X/*
  334. X * Test whether the string in buf is a function definition.
  335. X * The string may contain and/or end with a newline.
  336. X * Return as follows:
  337. X *    0 - definitely not a function definition;
  338. X *    1 - definitely a function definition;
  339. X *    -1 - may be the beginning of a function definition,
  340. X *        append another line and look again.
  341. X */
  342. Xint
  343. Xtest1(buf)
  344. X    char *buf;
  345. X{    register char *p = buf;
  346. X    char *bend;
  347. X    char *endfn;
  348. X    int contin;
  349. X    if ( !isidfirstchar(*p) )
  350. X        return 0;        /* no name at left margin */
  351. X    bend = skipspace(buf + strlen(buf) - 1, -1);
  352. X    switch ( *bend )
  353. X       {
  354. X    case ')': contin = 1; break;
  355. X    case '(':
  356. X    case ',': contin = -1; break;
  357. X    default: return 0;        /* not a function */
  358. X       }
  359. X    while ( isidchar(*p) ) p++;
  360. X    endfn = p;
  361. X    p = skipspace(p, 1);
  362. X    if ( *p++ != '(' )
  363. X        return 0;        /* not a function */
  364. X    p = skipspace(p, 1);
  365. X    if ( *p == ')' )
  366. X        return 0;        /* no parameters */
  367. X    /* Check that the apparent function name isn't a keyword. */
  368. X    /* We only need to check for keywords that could be followed */
  369. X    /* by a left parenthesis (which, unfortunately, is most of them). */
  370. X       {    static char *words[] =
  371. X           {    "asm", "auto", "case", "char", "const", "double",
  372. X            "extern", "float", "for", "if", "int", "long",
  373. X            "register", "return", "short", "signed", "sizeof",
  374. X            "static", "switch", "typedef", "unsigned",
  375. X            "void", "volatile", "while", 0
  376. X           };
  377. X        char **key = words;
  378. X        char *kp;
  379. X        int len = endfn - buf;
  380. X        while ( (kp = *key) != 0 )
  381. X           {    if ( strlen(kp) == len && !strncmp(kp, buf, len) )
  382. X                return 0;    /* name is a keyword */
  383. X            key++;
  384. X           }
  385. X       }
  386. X    return contin;
  387. X}
  388. X
  389. Xint
  390. Xconvert1(buf, out)
  391. X    char *buf;
  392. X    FILE *out;
  393. X{    char *endfn = strchr(buf, '(') + 1;
  394. X    register char *p;
  395. X    char **breaks;
  396. X    unsigned num_breaks = 2;    /* for testing */
  397. X    char **btop;
  398. X    char **bp;
  399. X    char **ap;
  400. Xtop:    p = endfn;
  401. X    breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
  402. X    if ( breaks == 0 )
  403. X       {    /* Couldn't allocate break table, give up */
  404. X        fprintf(stderr, "Unable to allocate break table!\n");
  405. X        fputs(buf, out);
  406. X        return -1;
  407. X       }
  408. X    btop = breaks + num_breaks * 2 - 2;
  409. X    bp = breaks;
  410. X    /* Parse the argument list */
  411. X    do
  412. X       {    int level = 0;
  413. X        char *end = NULL;
  414. X        if ( bp >= btop )
  415. X           {    /* Filled up break table. */
  416. X            /* Allocate a bigger one and start over. */
  417. X            free((char *)breaks);
  418. X            num_breaks <<= 1;
  419. X            goto top;
  420. X           }
  421. X        *bp++ = p;
  422. X        /* Find the end of the argument */
  423. X        for ( ; end == NULL; p++ )
  424. X           {    switch(*p)
  425. X               {
  426. X            case ',': if ( !level ) end = p; break;
  427. X            case '(': level++; break;
  428. X            case ')': if ( --level < 0 ) end = p; break;
  429. X            case '/': p = skipspace(p, 1) - 1; break;
  430. X            default: ;
  431. X               }
  432. X           }
  433. X        p--;            /* back up over terminator */
  434. X        /* Find the name being declared. */
  435. X        /* This is complicated because of procedure and */
  436. X        /* array modifiers. */
  437. X        for ( ; ; )
  438. X           {    p = skipspace(p - 1, -1);
  439. X            switch ( *p )
  440. X               {
  441. X            case ']':    /* skip array dimension(s) */
  442. X            case ')':    /* skip procedure args OR name */
  443. X               {    int level = 1;
  444. X                while ( level )
  445. X                 switch ( *--p )
  446. X                   {
  447. X                case ']': case ')': level++; break;
  448. X                case '[': case '(': level--; break;
  449. X                case '/': p = skipspace(p, -1) + 1; break;
  450. X                default: ;
  451. X                   }
  452. X               }
  453. X                if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
  454. X                   {    /* We found the name being declared */
  455. X                    while ( !isidfirstchar(*p) )
  456. X                        p = skipspace(p, 1) + 1;
  457. X                    goto found;
  458. X                   }
  459. X                break;
  460. X            default: goto found;
  461. X               }
  462. X           }
  463. Xfound:        if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
  464. X           {    p++;
  465. X            if ( bp == breaks + 1 )    /* sole argument */
  466. X                writeblanks(breaks[0], p);
  467. X            else
  468. X                writeblanks(bp[-1] - 1, p);
  469. X            bp--;
  470. X           }
  471. X        else
  472. X           {    while ( isidchar(*p) ) p--;
  473. X            *bp++ = p+1;
  474. X           }
  475. X        p = end;
  476. X       }
  477. X    while ( *p++ == ',' );
  478. X    *bp = p;
  479. X    /* Make a special check for 'void' arglist */
  480. X    if ( bp == breaks+2 )
  481. X       {    p = skipspace(breaks[0], 1);
  482. X        if ( !strncmp(p, "void", 4) )
  483. X           {    p = skipspace(p+4, 1);
  484. X            if ( p == breaks[2] - 1 )
  485. X               {    bp = breaks;    /* yup, pretend arglist is empty */
  486. X                writeblanks(breaks[0], p + 1);
  487. X               }
  488. X           }
  489. X       }
  490. X    /* Put out the function name */
  491. X    p = buf;
  492. X    while ( p != endfn ) putc(*p, out), p++;
  493. X    /* Put out the declaration */
  494. X    for ( ap = breaks+1; ap < bp; ap += 2 )
  495. X       {    p = *ap;
  496. X        while ( isidchar(*p) ) putc(*p, out), p++;
  497. X        if ( ap < bp - 1 ) fputs(", ", out);
  498. X       }
  499. X    fputs(")  ", out);
  500. X    /* Put out the argument declarations */
  501. X    for ( ap = breaks+2; ap <= bp; ap += 2 ) (*ap)[-1] = ';';
  502. X    fputs(breaks[0], out);
  503. X    free((char *)breaks);
  504. X    return 0;
  505. X}
  506. END_OF_FILE
  507.   if test 16228 -ne `wc -c <'ansi2knr.c'`; then
  508.     echo shar: \"'ansi2knr.c'\" unpacked with wrong size!
  509.   fi
  510.   # end of 'ansi2knr.c'
  511. fi
  512. if test -f 'jdpipe.c' -a "${1}" != "-c" ; then 
  513.   echo shar: Will not clobber existing file \"'jdpipe.c'\"
  514. else
  515.   echo shar: Extracting \"'jdpipe.c'\" \(38159 characters\)
  516.   sed "s/^X//" >'jdpipe.c' <<'END_OF_FILE'
  517. X/*
  518. X * jdpipe.c
  519. X *
  520. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  521. X * This file is part of the Independent JPEG Group's software.
  522. X * For conditions of distribution and use, see the accompanying README file.
  523. X *
  524. X * This file contains decompression pipeline controllers.
  525. X * These routines are invoked via the d_pipeline_controller method.
  526. X *
  527. X * There are two basic pipeline controllers.  The simpler one handles a
  528. X * single-scan JPEG file (single component or fully interleaved) with no
  529. X * color quantization or 1-pass quantization.  In this case, the file can
  530. X * be processed in one top-to-bottom pass.  The more complex controller is
  531. X * used when 2-pass color quantization is requested and/or the JPEG file
  532. X * has multiple scans (noninterleaved or partially interleaved).  In this
  533. X * case, the entire image must be buffered up in a "big" array.
  534. X *
  535. X * If you need to make a minimal implementation, the more complex controller
  536. X * can be compiled out by disabling the appropriate configuration options.
  537. X * We don't recommend this, since then you can't handle all legal JPEG files.
  538. X */
  539. X
  540. X#include "jinclude.h"
  541. X
  542. X
  543. X#ifdef D_MULTISCAN_FILES_SUPPORTED /* wish we could assume ANSI's defined() */
  544. X#define NEED_COMPLEX_CONTROLLER
  545. X#else
  546. X#ifdef QUANT_2PASS_SUPPORTED
  547. X#define NEED_COMPLEX_CONTROLLER
  548. X#endif
  549. X#endif
  550. X
  551. X
  552. X/*
  553. X * About the data structures:
  554. X *
  555. X * The processing chunk size for upsampling is referred to in this file as
  556. X * a "row group": a row group is defined as Vk (v_samp_factor) sample rows of
  557. X * any component while downsampled, or Vmax (max_v_samp_factor) unsubsampled
  558. X * rows.  In an interleaved scan each MCU row contains exactly DCTSIZE row
  559. X * groups of each component in the scan.  In a noninterleaved scan an MCU row
  560. X * is one row of blocks, which might not be an integral number of row groups;
  561. X * therefore, we read in Vk MCU rows to obtain the same amount of data as we'd
  562. X * have in an interleaved scan.
  563. X * To provide context for the upsampling step, we have to retain the last
  564. X * two row groups of the previous MCU row while reading in the next MCU row
  565. X * (or set of Vk MCU rows).  To do this without copying data about, we create
  566. X * a rather strange data structure.  Exactly DCTSIZE+2 row groups of samples
  567. X * are allocated, but we create two different sets of pointers to this array.
  568. X * The second set swaps the last two pairs of row groups.  By working
  569. X * alternately with the two sets of pointers, we can access the data in the
  570. X * desired order.
  571. X *
  572. X * Cross-block smoothing also needs context above and below the "current" row.
  573. X * Since this is an optional feature, I've implemented it in a way that is
  574. X * much simpler but requires more than the minimum amount of memory.  We
  575. X * simply allocate three extra MCU rows worth of coefficient blocks and use
  576. X * them to "read ahead" one MCU row in the file.  For a typical 1000-pixel-wide
  577. X * image with 2x2,1x1,1x1 sampling, each MCU row is about 50Kb; an 80x86
  578. X * machine may be unable to apply cross-block smoothing to wider images.
  579. X */
  580. X
  581. X
  582. X/*
  583. X * These variables are logically local to the pipeline controller,
  584. X * but we make them static so that scan_big_image can use them
  585. X * without having to pass them through the quantization routines.
  586. X */
  587. X
  588. Xstatic int rows_in_mem;        /* # of sample rows in full-size buffers */
  589. X/* Work buffer for data being passed to output module. */
  590. X/* This has color_out_comps components if not quantizing, */
  591. X/* but only one component when quantizing. */
  592. Xstatic JSAMPIMAGE output_workspace;
  593. X
  594. X#ifdef NEED_COMPLEX_CONTROLLER
  595. X/* Full-size image array holding upsampled, but not color-processed data. */
  596. Xstatic big_sarray_ptr *fullsize_image;
  597. Xstatic JSAMPIMAGE fullsize_ptrs; /* workspace for access_big_sarray() result */
  598. X#endif
  599. X
  600. X
  601. X/*
  602. X * Utility routines: common code for pipeline controllers
  603. X */
  604. X
  605. XLOCAL void
  606. Xinterleaved_scan_setup (decompress_info_ptr cinfo)
  607. X/* Compute all derived info for an interleaved (multi-component) scan */
  608. X/* On entry, cinfo->comps_in_scan and cinfo->cur_comp_info[] are set up */
  609. X{
  610. X  short ci, mcublks;
  611. X  jpeg_component_info *compptr;
  612. X
  613. X  if (cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  614. X    ERREXIT(cinfo->emethods, "Too many components for interleaved scan");
  615. X
  616. X  cinfo->MCUs_per_row = (cinfo->image_width
  617. X             + cinfo->max_h_samp_factor*DCTSIZE - 1)
  618. X            / (cinfo->max_h_samp_factor*DCTSIZE);
  619. X
  620. X  cinfo->MCU_rows_in_scan = (cinfo->image_height
  621. X                 + cinfo->max_v_samp_factor*DCTSIZE - 1)
  622. X                / (cinfo->max_v_samp_factor*DCTSIZE);
  623. X  
  624. X  cinfo->blocks_in_MCU = 0;
  625. X
  626. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  627. X    compptr = cinfo->cur_comp_info[ci];
  628. X    /* for interleaved scan, sampling factors give # of blocks per component */
  629. X    compptr->MCU_width = compptr->h_samp_factor;
  630. X    compptr->MCU_height = compptr->v_samp_factor;
  631. X    compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  632. X    /* compute physical dimensions of component */
  633. X    compptr->downsampled_width = jround_up(compptr->true_comp_width,
  634. X                       (long) (compptr->MCU_width*DCTSIZE));
  635. X    compptr->downsampled_height = jround_up(compptr->true_comp_height,
  636. X                        (long) (compptr->MCU_height*DCTSIZE));
  637. X    /* Sanity check */
  638. X    if (compptr->downsampled_width !=
  639. X    (cinfo->MCUs_per_row * (compptr->MCU_width*DCTSIZE)))
  640. X      ERREXIT(cinfo->emethods, "I'm confused about the image width");
  641. X    /* Prepare array describing MCU composition */
  642. X    mcublks = compptr->MCU_blocks;
  643. X    if (cinfo->blocks_in_MCU + mcublks > MAX_BLOCKS_IN_MCU)
  644. X      ERREXIT(cinfo->emethods, "Sampling factors too large for interleaved scan");
  645. X    while (mcublks-- > 0) {
  646. X      cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  647. X    }
  648. X  }
  649. X
  650. X  (*cinfo->methods->d_per_scan_method_selection) (cinfo);
  651. X}
  652. X
  653. X
  654. XLOCAL void
  655. Xnoninterleaved_scan_setup (decompress_info_ptr cinfo)
  656. X/* Compute all derived info for a noninterleaved (single-component) scan */
  657. X/* On entry, cinfo->comps_in_scan = 1 and cinfo->cur_comp_info[0] is set up */
  658. X{
  659. X  jpeg_component_info *compptr = cinfo->cur_comp_info[0];
  660. X
  661. X  /* for noninterleaved scan, always one block per MCU */
  662. X  compptr->MCU_width = 1;
  663. X  compptr->MCU_height = 1;
  664. X  compptr->MCU_blocks = 1;
  665. X  /* compute physical dimensions of component */
  666. X  compptr->downsampled_width = jround_up(compptr->true_comp_width,
  667. X                     (long) DCTSIZE);
  668. X  compptr->downsampled_height = jround_up(compptr->true_comp_height,
  669. X                      (long) DCTSIZE);
  670. X
  671. X  cinfo->MCUs_per_row = compptr->downsampled_width / DCTSIZE;
  672. X  cinfo->MCU_rows_in_scan = compptr->downsampled_height / DCTSIZE;
  673. X
  674. X  /* Prepare array describing MCU composition */
  675. X  cinfo->blocks_in_MCU = 1;
  676. X  cinfo->MCU_membership[0] = 0;
  677. X
  678. X  (*cinfo->methods->d_per_scan_method_selection) (cinfo);
  679. X}
  680. X
  681. X
  682. X
  683. XLOCAL JSAMPIMAGE
  684. Xalloc_sampimage (decompress_info_ptr cinfo,
  685. X         int num_comps, long num_rows, long num_cols)
  686. X/* Allocate an in-memory sample image (all components same size) */
  687. X{
  688. X  JSAMPIMAGE image;
  689. X  int ci;
  690. X
  691. X  image = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  692. X                (num_comps * SIZEOF(JSAMPARRAY));
  693. X  for (ci = 0; ci < num_comps; ci++) {
  694. X    image[ci] = (*cinfo->emethods->alloc_small_sarray) (num_cols, num_rows);
  695. X  }
  696. X  return image;
  697. X}
  698. X
  699. X
  700. X#if 0                /* this routine not currently needed */
  701. X
  702. XLOCAL void
  703. Xfree_sampimage (decompress_info_ptr cinfo, JSAMPIMAGE image, int num_comps)
  704. X/* Release a sample image created by alloc_sampimage */
  705. X{
  706. X  int ci;
  707. X
  708. X  for (ci = 0; ci < num_comps; ci++) {
  709. X      (*cinfo->emethods->free_small_sarray) (image[ci]);
  710. X  }
  711. X  (*cinfo->emethods->free_small) ((void *) image);
  712. X}
  713. X
  714. X#endif
  715. X
  716. X
  717. XLOCAL JBLOCKIMAGE
  718. Xalloc_MCU_row (decompress_info_ptr cinfo)
  719. X/* Allocate one MCU row's worth of coefficient blocks */
  720. X{
  721. X  JBLOCKIMAGE image;
  722. X  int ci;
  723. X
  724. X  image = (JBLOCKIMAGE) (*cinfo->emethods->alloc_small)
  725. X                (cinfo->comps_in_scan * SIZEOF(JBLOCKARRAY));
  726. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  727. X    image[ci] = (*cinfo->emethods->alloc_small_barray)
  728. X            (cinfo->cur_comp_info[ci]->downsampled_width / DCTSIZE,
  729. X             (long) cinfo->cur_comp_info[ci]->MCU_height);
  730. X  }
  731. X  return image;
  732. X}
  733. X
  734. X
  735. X#ifdef NEED_COMPLEX_CONTROLLER    /* not used by simple controller */
  736. X
  737. XLOCAL void
  738. Xfree_MCU_row (decompress_info_ptr cinfo, JBLOCKIMAGE image)
  739. X/* Release a coefficient block array created by alloc_MCU_row */
  740. X{
  741. X  int ci;
  742. X
  743. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  744. X    (*cinfo->emethods->free_small_barray) (image[ci]);
  745. X  }
  746. X  (*cinfo->emethods->free_small) ((void *) image);
  747. X}
  748. X
  749. X#endif
  750. X
  751. X
  752. XLOCAL void
  753. Xalloc_sampling_buffer (decompress_info_ptr cinfo, JSAMPIMAGE sampled_data[2])
  754. X/* Create a downsampled-data buffer having the desired structure */
  755. X/* (see comments at head of file) */
  756. X{
  757. X  short ci, vs, i;
  758. X
  759. X  /* Get top-level space for array pointers */
  760. X  sampled_data[0] = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  761. X                (cinfo->comps_in_scan * SIZEOF(JSAMPARRAY));
  762. X  sampled_data[1] = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  763. X                (cinfo->comps_in_scan * SIZEOF(JSAMPARRAY));
  764. X
  765. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  766. X    vs = cinfo->cur_comp_info[ci]->v_samp_factor; /* row group height */
  767. X    /* Allocate the real storage */
  768. X    sampled_data[0][ci] = (*cinfo->emethods->alloc_small_sarray)
  769. X                (cinfo->cur_comp_info[ci]->downsampled_width,
  770. X                (long) (vs * (DCTSIZE+2)));
  771. X    /* Create space for the scrambled-order pointers */
  772. X    sampled_data[1][ci] = (JSAMPARRAY) (*cinfo->emethods->alloc_small)
  773. X                (vs * (DCTSIZE+2) * SIZEOF(JSAMPROW));
  774. X    /* Duplicate the first DCTSIZE-2 row groups */
  775. X    for (i = 0; i < vs * (DCTSIZE-2); i++) {
  776. X      sampled_data[1][ci][i] = sampled_data[0][ci][i];
  777. X    }
  778. X    /* Copy the last four row groups in swapped order */
  779. X    for (i = 0; i < vs * 2; i++) {
  780. X      sampled_data[1][ci][vs*DCTSIZE + i] = sampled_data[0][ci][vs*(DCTSIZE-2) + i];
  781. X      sampled_data[1][ci][vs*(DCTSIZE-2) + i] = sampled_data[0][ci][vs*DCTSIZE + i];
  782. X    }
  783. X  }
  784. X}
  785. X
  786. X
  787. X#ifdef NEED_COMPLEX_CONTROLLER    /* not used by simple controller */
  788. X
  789. XLOCAL void
  790. Xfree_sampling_buffer (decompress_info_ptr cinfo, JSAMPIMAGE sampled_data[2])
  791. X/* Release a sampling buffer created by alloc_sampling_buffer */
  792. X{
  793. X  short ci;
  794. X
  795. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  796. X    /* Free the real storage */
  797. X    (*cinfo->emethods->free_small_sarray) (sampled_data[0][ci]);
  798. X    /* Free the scrambled-order pointers */
  799. X    (*cinfo->emethods->free_small) ((void *) sampled_data[1][ci]);
  800. X  }
  801. X
  802. X  /* Free the top-level space */
  803. X  (*cinfo->emethods->free_small) ((void *) sampled_data[0]);
  804. X  (*cinfo->emethods->free_small) ((void *) sampled_data[1]);
  805. X}
  806. X
  807. X#endif
  808. X
  809. X
  810. X/*
  811. X * Several decompression processes need to range-limit values to the range
  812. X * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
  813. X * due to noise introduced by quantization, roundoff error, etc.  These
  814. X * processes are inner loops and need to be as fast as possible.  On most
  815. X * machines, particularly CPUs with pipelines or instruction prefetch,
  816. X * a (range-check-less) C table lookup
  817. X *        x = sample_range_limit[x];
  818. X * is faster than explicit tests
  819. X *        if (x < 0)  x = 0;
  820. X *        else if (x > MAXJSAMPLE)  x = MAXJSAMPLE;
  821. X * These processes all use a common table prepared by the routine below.
  822. X *
  823. X * The table will work correctly for x within MAXJSAMPLE+1 of the legal
  824. X * range.  This is a much wider range than is needed for most cases,
  825. X * but the wide range is handy for color quantization.
  826. X * Note that the table is allocated in near data space on PCs; it's small
  827. X * enough and used often enough to justify this.
  828. X */
  829. X
  830. XLOCAL void
  831. Xprepare_range_limit_table (decompress_info_ptr cinfo)
  832. X/* Allocate and fill in the sample_range_limit table */
  833. X{
  834. X  JSAMPLE * table;
  835. X  int i;
  836. X
  837. X  table = (JSAMPLE *) (*cinfo->emethods->alloc_small)
  838. X            (3 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  839. X  cinfo->sample_range_limit = table + (MAXJSAMPLE+1);
  840. X  for (i = 0; i <= MAXJSAMPLE; i++) {
  841. X    table[i] = 0;            /* sample_range_limit[x] = 0 for x<0 */
  842. X    table[i+(MAXJSAMPLE+1)] = (JSAMPLE) i;    /* sample_range_limit[x] = x */
  843. X    table[i+(MAXJSAMPLE+1)*2] = MAXJSAMPLE;    /* x beyond MAXJSAMPLE */
  844. X  }
  845. X}
  846. X
  847. X
  848. XLOCAL void
  849. Xduplicate_row (JSAMPARRAY image_data,
  850. X           long num_cols, int source_row, int num_rows)
  851. X/* Duplicate the source_row at source_row+1 .. source_row+num_rows */
  852. X/* This happens only at the bottom of the image, */
  853. X/* so it needn't be super-efficient */
  854. X{
  855. X  register int row;
  856. X
  857. X  for (row = 1; row <= num_rows; row++) {
  858. X    jcopy_sample_rows(image_data, source_row, image_data, source_row + row,
  859. X              1, num_cols);
  860. X  }
  861. X}
  862. X
  863. X
  864. XLOCAL void
  865. Xexpand (decompress_info_ptr cinfo,
  866. X    JSAMPIMAGE sampled_data, JSAMPIMAGE fullsize_data,
  867. X    long fullsize_width,
  868. X    short above, short current, short below, short out)
  869. X/* Do upsampling expansion of a single row group (of each component). */
  870. X/* above, current, below are indexes of row groups in sampled_data;       */
  871. X/* out is the index of the target row group in fullsize_data.             */
  872. X/* Special case: above, below can be -1 to indicate top, bottom of image. */
  873. X{
  874. X  jpeg_component_info *compptr;
  875. X  JSAMPARRAY above_ptr, below_ptr;
  876. X  JSAMPROW dummy[MAX_SAMP_FACTOR]; /* for downsample expansion at top/bottom */
  877. X  short ci, vs, i;
  878. X
  879. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  880. X    compptr = cinfo->cur_comp_info[ci];
  881. X    vs = compptr->v_samp_factor; /* row group height */
  882. X
  883. X    if (above >= 0)
  884. X      above_ptr = sampled_data[ci] + above * vs;
  885. X    else {
  886. X      /* Top of image: make a dummy above-context with copies of 1st row */
  887. X      /* We assume current=0 in this case */
  888. X      for (i = 0; i < vs; i++)
  889. X    dummy[i] = sampled_data[ci][0];
  890. X      above_ptr = (JSAMPARRAY) dummy; /* possible near->far pointer conv */
  891. X    }
  892. X
  893. X    if (below >= 0)
  894. X      below_ptr = sampled_data[ci] + below * vs;
  895. X    else {
  896. X      /* Bot of image: make a dummy below-context with copies of last row */
  897. X      for (i = 0; i < vs; i++)
  898. X    dummy[i] = sampled_data[ci][(current+1)*vs-1];
  899. X      below_ptr = (JSAMPARRAY) dummy; /* possible near->far pointer conv */
  900. X    }
  901. X
  902. X    (*cinfo->methods->upsample[ci])
  903. X        (cinfo, (int) ci,
  904. X         compptr->downsampled_width, (int) vs,
  905. X         fullsize_width, (int) cinfo->max_v_samp_factor,
  906. X         above_ptr,
  907. X         sampled_data[ci] + current * vs,
  908. X         below_ptr,
  909. X         fullsize_data[ci] + out * cinfo->max_v_samp_factor);
  910. X  }
  911. X}
  912. X
  913. X
  914. XLOCAL void
  915. Xemit_1pass (decompress_info_ptr cinfo, int num_rows, JSAMPIMAGE fullsize_data,
  916. X        JSAMPARRAY dummy)
  917. X/* Do color processing and output of num_rows full-size rows. */
  918. X/* This is not used when doing 2-pass color quantization. */
  919. X/* The dummy argument simply lets this be called via scan_big_image. */
  920. X{
  921. X  if (cinfo->quantize_colors) {
  922. X    (*cinfo->methods->color_quantize) (cinfo, num_rows, fullsize_data,
  923. X                       output_workspace[0]);
  924. X  } else {
  925. X    (*cinfo->methods->color_convert) (cinfo, num_rows, cinfo->image_width,
  926. X                      fullsize_data, output_workspace);
  927. X  }
  928. X    
  929. X  (*cinfo->methods->put_pixel_rows) (cinfo, num_rows, output_workspace);
  930. X}
  931. X
  932. X
  933. X/*
  934. X * Support routines for complex controller.
  935. X */
  936. X
  937. X#ifdef NEED_COMPLEX_CONTROLLER
  938. X
  939. XMETHODDEF void
  940. Xscan_big_image (decompress_info_ptr cinfo, quantize_method_ptr quantize_method)
  941. X/* Apply quantize_method to entire image stored in fullsize_image[]. */
  942. X/* This is the "iterator" routine used by the 2-pass color quantizer. */
  943. X/* We also use it directly in some cases. */
  944. X{
  945. X  long pixel_rows_output;
  946. X  short ci;
  947. X
  948. X  for (pixel_rows_output = 0; pixel_rows_output < cinfo->image_height;
  949. X       pixel_rows_output += rows_in_mem) {
  950. X    (*cinfo->methods->progress_monitor) (cinfo, pixel_rows_output,
  951. X                     cinfo->image_height);
  952. X    /* Realign the big buffers */
  953. X    for (ci = 0; ci < cinfo->num_components; ci++) {
  954. X      fullsize_ptrs[ci] = (*cinfo->emethods->access_big_sarray)
  955. X    (fullsize_image[ci], pixel_rows_output, FALSE);
  956. X    }
  957. X    /* Let the quantizer have its way with the data.
  958. X     * Note that output_workspace is simply workspace for the quantizer;
  959. X     * when it's ready to output, it must call put_pixel_rows itself.
  960. X     */
  961. X    (*quantize_method) (cinfo,
  962. X            (int) MIN((long) rows_in_mem,
  963. X                  cinfo->image_height - pixel_rows_output),
  964. X            fullsize_ptrs, output_workspace[0]);
  965. X  }
  966. X
  967. X  cinfo->completed_passes++;
  968. X}
  969. X
  970. X#endif /* NEED_COMPLEX_CONTROLLER */
  971. X
  972. X
  973. X/*
  974. X * Support routines for cross-block smoothing.
  975. X */
  976. X
  977. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  978. X
  979. X
  980. XLOCAL void
  981. Xsmooth_mcu_row (decompress_info_ptr cinfo,
  982. X        JBLOCKIMAGE above, JBLOCKIMAGE input, JBLOCKIMAGE below,
  983. X        JBLOCKIMAGE output)
  984. X/* Apply cross-block smoothing to one MCU row's worth of coefficient blocks. */
  985. X/* above,below are NULL if at top/bottom of image. */
  986. X{
  987. X  jpeg_component_info *compptr;
  988. X  short ci, ri, last;
  989. X  JBLOCKROW prev;
  990. X
  991. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  992. X    compptr = cinfo->cur_comp_info[ci];
  993. X    last = compptr->MCU_height - 1;
  994. X
  995. X    if (above == NULL)
  996. X      prev = NULL;
  997. X    else
  998. X      prev = above[ci][last];
  999. X
  1000. X    for (ri = 0; ri < last; ri++) {
  1001. X      (*cinfo->methods->smooth_coefficients) (cinfo, compptr,
  1002. X                prev, input[ci][ri], input[ci][ri+1],
  1003. X                output[ci][ri]);
  1004. X      prev = input[ci][ri];
  1005. X    }
  1006. X
  1007. X    if (below == NULL)
  1008. X      (*cinfo->methods->smooth_coefficients) (cinfo, compptr,
  1009. X                prev, input[ci][last], (JBLOCKROW) NULL,
  1010. X                output[ci][last]);
  1011. X    else
  1012. X      (*cinfo->methods->smooth_coefficients) (cinfo, compptr,
  1013. X                prev, input[ci][last], below[ci][0],
  1014. X                output[ci][last]);
  1015. X  }
  1016. X}
  1017. X
  1018. X
  1019. XLOCAL void
  1020. Xget_smoothed_row (decompress_info_ptr cinfo, JBLOCKIMAGE coeff_data,
  1021. X          JBLOCKIMAGE bsmooth[3], int * whichb, long cur_mcu_row)
  1022. X/* Get an MCU row of coefficients, applying cross-block smoothing. */
  1023. X/* The output row is placed in coeff_data.  bsmooth and whichb hold */
  1024. X/* working state, and cur_row is needed to check for image top/bottom. */
  1025. X/* This routine just takes care of the buffering logic. */
  1026. X{
  1027. X  int prev, cur, next;
  1028. X  
  1029. X  /* Special case for top of image: need to pre-fetch a row & init whichb */
  1030. X  if (cur_mcu_row == 0) {
  1031. X    (*cinfo->methods->disassemble_MCU) (cinfo, bsmooth[0]);
  1032. X    if (cinfo->MCU_rows_in_scan > 1) {
  1033. X      (*cinfo->methods->disassemble_MCU) (cinfo, bsmooth[1]);
  1034. X      smooth_mcu_row(cinfo, (JBLOCKIMAGE) NULL, bsmooth[0], bsmooth[1],
  1035. X             coeff_data);
  1036. X    } else {
  1037. X      smooth_mcu_row(cinfo, (JBLOCKIMAGE) NULL, bsmooth[0], (JBLOCKIMAGE) NULL,
  1038. X             coeff_data);
  1039. X    }
  1040. X    *whichb = 1;        /* points to next bsmooth[] element to use */
  1041. X    return;
  1042. X  }
  1043. X  
  1044. X  cur = *whichb;        /* set up references */
  1045. X  prev = (cur == 0 ? 2 : cur - 1);
  1046. X  next = (cur == 2 ? 0 : cur + 1);
  1047. X  *whichb = next;        /* advance whichb for next time */
  1048. X  
  1049. X  /* Special case for bottom of image: don't read another row */
  1050. X  if (cur_mcu_row >= cinfo->MCU_rows_in_scan - 1) {
  1051. X    smooth_mcu_row(cinfo, bsmooth[prev], bsmooth[cur], (JBLOCKIMAGE) NULL,
  1052. X           coeff_data);
  1053. X    return;
  1054. X  }
  1055. X  
  1056. X  /* Normal case: read ahead a new row, smooth the one I got before */
  1057. X  (*cinfo->methods->disassemble_MCU) (cinfo, bsmooth[next]);
  1058. X  smooth_mcu_row(cinfo, bsmooth[prev], bsmooth[cur], bsmooth[next],
  1059. X         coeff_data);
  1060. X}
  1061. X
  1062. X
  1063. X#endif /* BLOCK_SMOOTHING_SUPPORTED */
  1064. X
  1065. X
  1066. X
  1067. X/*
  1068. X * Decompression pipeline controller used for single-scan files
  1069. X * without 2-pass color quantization.
  1070. X */
  1071. X
  1072. XMETHODDEF void
  1073. Xsimple_dcontroller (decompress_info_ptr cinfo)
  1074. X{
  1075. X  long fullsize_width;        /* # of samples per row in full-size buffers */
  1076. X  long cur_mcu_row;        /* counts # of MCU rows processed */
  1077. X  long pixel_rows_output;    /* # of pixel rows actually emitted */
  1078. X  int mcu_rows_per_loop;    /* # of MCU rows processed per outer loop */
  1079. X  /* Work buffer for dequantized coefficients (IDCT input) */
  1080. X  JBLOCKIMAGE coeff_data;
  1081. X  /* Work buffer for cross-block smoothing input */
  1082. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1083. X  JBLOCKIMAGE bsmooth[3];    /* this is optional */
  1084. X  int whichb;
  1085. X#endif
  1086. X  /* Work buffer for downsampled image data (see comments at head of file) */
  1087. X  JSAMPIMAGE sampled_data[2];
  1088. X  /* Work buffer for upsampled data */
  1089. X  JSAMPIMAGE fullsize_data;
  1090. X  int whichss, ri;
  1091. X  short i;
  1092. X
  1093. X  /* Compute dimensions of full-size pixel buffers */
  1094. X  /* Note these are the same whether interleaved or not. */
  1095. X  rows_in_mem = cinfo->max_v_samp_factor * DCTSIZE;
  1096. X  fullsize_width = jround_up(cinfo->image_width,
  1097. X                 (long) (cinfo->max_h_samp_factor * DCTSIZE));
  1098. X
  1099. X  /* Prepare for single scan containing all components */
  1100. X  if (cinfo->comps_in_scan == 1) {
  1101. X    noninterleaved_scan_setup(cinfo);
  1102. X    /* Need to read Vk MCU rows to obtain Vk block rows */
  1103. X    mcu_rows_per_loop = cinfo->cur_comp_info[0]->v_samp_factor;
  1104. X  } else {
  1105. X    interleaved_scan_setup(cinfo);
  1106. X    /* in an interleaved scan, one MCU row provides Vk block rows */
  1107. X    mcu_rows_per_loop = 1;
  1108. X  }
  1109. X  cinfo->total_passes++;
  1110. X
  1111. X  /* Allocate working memory: */
  1112. X  /* coeff_data holds a single MCU row of coefficient blocks */
  1113. X  coeff_data = alloc_MCU_row(cinfo);
  1114. X  /* if doing cross-block smoothing, need extra space for its input */
  1115. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1116. X  if (cinfo->do_block_smoothing) {
  1117. X    bsmooth[0] = alloc_MCU_row(cinfo);
  1118. X    bsmooth[1] = alloc_MCU_row(cinfo);
  1119. X    bsmooth[2] = alloc_MCU_row(cinfo);
  1120. X  }
  1121. X#endif
  1122. X  /* sampled_data is sample data before upsampling */
  1123. X  alloc_sampling_buffer(cinfo, sampled_data);
  1124. X  /* fullsize_data is sample data after upsampling */
  1125. X  fullsize_data = alloc_sampimage(cinfo, (int) cinfo->num_components,
  1126. X                  (long) rows_in_mem, fullsize_width);
  1127. X  /* output_workspace is the color-processed data */
  1128. X  output_workspace = alloc_sampimage(cinfo, (int) cinfo->final_out_comps,
  1129. X                     (long) rows_in_mem, fullsize_width);
  1130. X  prepare_range_limit_table(cinfo);
  1131. X
  1132. X  /* Tell the memory manager to instantiate big arrays.
  1133. X   * We don't need any big arrays in this controller,
  1134. X   * but some other module (like the output file writer) may need one.
  1135. X   */
  1136. X  (*cinfo->emethods->alloc_big_arrays)
  1137. X    ((long) 0,                /* no more small sarrays */
  1138. X     (long) 0,                /* no more small barrays */
  1139. X     (long) 0);                /* no more "medium" objects */
  1140. X  /* NB: if quantizer needs any "medium" size objects, it must get them */
  1141. X  /* at color_quant_init time */
  1142. X
  1143. X  /* Initialize to read scan data */
  1144. X
  1145. X  (*cinfo->methods->entropy_decode_init) (cinfo);
  1146. X  (*cinfo->methods->upsample_init) (cinfo);
  1147. X  (*cinfo->methods->disassemble_init) (cinfo);
  1148. X
  1149. X  /* Loop over scan's data: rows_in_mem pixel rows are processed per loop */
  1150. X
  1151. X  pixel_rows_output = 0;
  1152. X  whichss = 1;            /* arrange to start with sampled_data[0] */
  1153. X
  1154. X  for (cur_mcu_row = 0; cur_mcu_row < cinfo->MCU_rows_in_scan;
  1155. X       cur_mcu_row += mcu_rows_per_loop) {
  1156. X    (*cinfo->methods->progress_monitor) (cinfo, cur_mcu_row,
  1157. X                     cinfo->MCU_rows_in_scan);
  1158. X
  1159. X    whichss ^= 1;        /* switch to other downsampled-data buffer */
  1160. X
  1161. X    /* Obtain v_samp_factor block rows of each component in the scan. */
  1162. X    /* This is a single MCU row if interleaved, multiple MCU rows if not. */
  1163. X    /* In the noninterleaved case there might be fewer than v_samp_factor */
  1164. X    /* block rows remaining; if so, pad with copies of the last pixel row */
  1165. X    /* so that upsampling doesn't have to treat it as a special case. */
  1166. X
  1167. X    for (ri = 0; ri < mcu_rows_per_loop; ri++) {
  1168. X      if (cur_mcu_row + ri < cinfo->MCU_rows_in_scan) {
  1169. X    /* OK to actually read an MCU row. */
  1170. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1171. X    if (cinfo->do_block_smoothing)
  1172. X      get_smoothed_row(cinfo, coeff_data,
  1173. X               bsmooth, &whichb, cur_mcu_row + ri);
  1174. X    else
  1175. X#endif
  1176. X      (*cinfo->methods->disassemble_MCU) (cinfo, coeff_data);
  1177. X      
  1178. X    (*cinfo->methods->reverse_DCT) (cinfo, coeff_data,
  1179. X                    sampled_data[whichss],
  1180. X                    ri * DCTSIZE);
  1181. X      } else {
  1182. X    /* Need to pad out with copies of the last downsampled row. */
  1183. X    /* This can only happen if there is just one component. */
  1184. X    duplicate_row(sampled_data[whichss][0],
  1185. X              cinfo->cur_comp_info[0]->downsampled_width,
  1186. X              ri * DCTSIZE - 1, DCTSIZE);
  1187. X      }
  1188. X    }
  1189. X
  1190. X    /* Upsample the data */
  1191. X    /* First time through is a special case */
  1192. X
  1193. X    if (cur_mcu_row) {
  1194. X      /* Expand last row group of previous set */
  1195. X      expand(cinfo, sampled_data[whichss], fullsize_data, fullsize_width,
  1196. X         (short) DCTSIZE, (short) (DCTSIZE+1), (short) 0,
  1197. X         (short) (DCTSIZE-1));
  1198. X      /* and dump the previous set's expanded data */
  1199. X      emit_1pass (cinfo, rows_in_mem, fullsize_data, (JSAMPARRAY) NULL);
  1200. X      pixel_rows_output += rows_in_mem;
  1201. X      /* Expand first row group of this set */
  1202. X      expand(cinfo, sampled_data[whichss], fullsize_data, fullsize_width,
  1203. X         (short) (DCTSIZE+1), (short) 0, (short) 1,
  1204. X         (short) 0);
  1205. X    } else {
  1206. X      /* Expand first row group with dummy above-context */
  1207. X      expand(cinfo, sampled_data[whichss], fullsize_data, fullsize_width,
  1208. X         (short) (-1), (short) 0, (short) 1,
  1209. X         (short) 0);
  1210. X    }
  1211. X    /* Expand second through next-to-last row groups of this set */
  1212. X    for (i = 1; i <= DCTSIZE-2; i++) {
  1213. X      expand(cinfo, sampled_data[whichss], fullsize_data, fullsize_width,
  1214. X         (short) (i-1), (short) i, (short) (i+1),
  1215. X         (short) i);
  1216. X    }
  1217. X  } /* end of outer loop */
  1218. X
  1219. X  /* Expand the last row group with dummy below-context */
  1220. X  /* Note whichss points to last buffer side used */
  1221. X  expand(cinfo, sampled_data[whichss], fullsize_data, fullsize_width,
  1222. X     (short) (DCTSIZE-2), (short) (DCTSIZE-1), (short) (-1),
  1223. X     (short) (DCTSIZE-1));
  1224. X  /* and dump the remaining data (may be less than full height) */
  1225. X  emit_1pass (cinfo, (int) (cinfo->image_height - pixel_rows_output),
  1226. X          fullsize_data, (JSAMPARRAY) NULL);
  1227. X
  1228. X  /* Clean up after the scan */
  1229. X  (*cinfo->methods->disassemble_term) (cinfo);
  1230. X  (*cinfo->methods->upsample_term) (cinfo);
  1231. X  (*cinfo->methods->entropy_decode_term) (cinfo);
  1232. X  (*cinfo->methods->read_scan_trailer) (cinfo);
  1233. X  cinfo->completed_passes++;
  1234. X
  1235. X  /* Verify that we've seen the whole input file */
  1236. X  if ((*cinfo->methods->read_scan_header) (cinfo))
  1237. X    WARNMS(cinfo->emethods, "Didn't expect more than one scan");
  1238. X
  1239. X  /* Release working memory */
  1240. X  /* (no work -- we let free_all release what's needful) */
  1241. X}
  1242. X
  1243. X
  1244. X/*
  1245. X * Decompression pipeline controller used for multiple-scan files
  1246. X * and/or 2-pass color quantization.
  1247. X *
  1248. X * The current implementation places the "big" buffer at the stage of
  1249. X * upsampled, non-color-processed data.  This is the only place that
  1250. X * makes sense when doing 2-pass quantization.  For processing multiple-scan
  1251. X * files without 2-pass quantization, it would be possible to develop another
  1252. X * controller that buffers the downsampled data instead, thus reducing the size
  1253. X * of the temp files (by about a factor of 2 in typical cases).  However,
  1254. X * our present upsampling logic is dependent on the assumption that
  1255. X * upsampling occurs during a scan, so it's much easier to do the
  1256. X * enlargement as the JPEG file is read.  This also simplifies life for the
  1257. X * memory manager, which would otherwise have to deal with overlapping
  1258. X * access_big_sarray() requests.
  1259. X * At present it appears that most JPEG files will be single-scan,
  1260. X * so it doesn't seem worthwhile to worry about this optimization.
  1261. X */
  1262. X
  1263. X#ifdef NEED_COMPLEX_CONTROLLER
  1264. X
  1265. XMETHODDEF void
  1266. Xcomplex_dcontroller (decompress_info_ptr cinfo)
  1267. X{
  1268. X  long fullsize_width;        /* # of samples per row in full-size buffers */
  1269. X  long cur_mcu_row;        /* counts # of MCU rows processed */
  1270. X  long pixel_rows_output;    /* # of pixel rows actually emitted */
  1271. X  int mcu_rows_per_loop;    /* # of MCU rows processed per outer loop */
  1272. X  /* Work buffer for dequantized coefficients (IDCT input) */
  1273. X  JBLOCKIMAGE coeff_data;
  1274. X  /* Work buffer for cross-block smoothing input */
  1275. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1276. X  JBLOCKIMAGE bsmooth[3];    /* this is optional */
  1277. X  int whichb;
  1278. X#endif
  1279. X  /* Work buffer for downsampled image data (see comments at head of file) */
  1280. X  JSAMPIMAGE sampled_data[2];
  1281. X  int whichss, ri;
  1282. X  short ci, i;
  1283. X  boolean single_scan;
  1284. X
  1285. X  /* Compute dimensions of full-size pixel buffers */
  1286. X  /* Note these are the same whether interleaved or not. */
  1287. X  rows_in_mem = cinfo->max_v_samp_factor * DCTSIZE;
  1288. X  fullsize_width = jround_up(cinfo->image_width,
  1289. X                 (long) (cinfo->max_h_samp_factor * DCTSIZE));
  1290. X
  1291. X  /* Allocate all working memory that doesn't depend on scan info */
  1292. X  /* output_workspace is the color-processed data */
  1293. X  output_workspace = alloc_sampimage(cinfo, (int) cinfo->final_out_comps,
  1294. X                     (long) rows_in_mem, fullsize_width);
  1295. X  prepare_range_limit_table(cinfo);
  1296. X
  1297. X  /* Get a big image: fullsize_image is sample data after upsampling. */
  1298. X  fullsize_image = (big_sarray_ptr *) (*cinfo->emethods->alloc_small)
  1299. X            (cinfo->num_components * SIZEOF(big_sarray_ptr));
  1300. X  for (ci = 0; ci < cinfo->num_components; ci++) {
  1301. X    fullsize_image[ci] = (*cinfo->emethods->request_big_sarray)
  1302. X            (fullsize_width,
  1303. X             jround_up(cinfo->image_height, (long) rows_in_mem),
  1304. X             (long) rows_in_mem);
  1305. X  }
  1306. X  /* Also get an area for pointers to currently accessible chunks */
  1307. X  fullsize_ptrs = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  1308. X                (cinfo->num_components * SIZEOF(JSAMPARRAY));
  1309. X
  1310. X  /* Tell the memory manager to instantiate big arrays */
  1311. X  (*cinfo->emethods->alloc_big_arrays)
  1312. X     /* extra sarray space is for downsampled-data buffers: */
  1313. X    ((long) (fullsize_width            /* max width in samples */
  1314. X     * cinfo->max_v_samp_factor*(DCTSIZE+2)    /* max height */
  1315. X     * cinfo->num_components),        /* max components per scan */
  1316. X     /* extra barray space is for MCU-row buffers: */
  1317. X     (long) ((fullsize_width / DCTSIZE)    /* max width in blocks */
  1318. X     * cinfo->max_v_samp_factor        /* max height */
  1319. X     * cinfo->num_components        /* max components per scan */
  1320. X     * (cinfo->do_block_smoothing ? 4 : 1)),/* how many of these we need */
  1321. X     /* no extra "medium"-object space */
  1322. X     (long) 0);
  1323. X  /* NB: if quantizer needs any "medium" size objects, it must get them */
  1324. X  /* at color_quant_init time */
  1325. X
  1326. X  /* If file is single-scan, we can do color quantization prescan on-the-fly
  1327. X   * during the scan (we must be doing 2-pass quantization, else this method
  1328. X   * would not have been selected).  If it is multiple scans, we have to make
  1329. X   * a separate pass after we've collected all the components.  (We could save
  1330. X   * some I/O by doing CQ prescan during the last scan, but the extra logic
  1331. X   * doesn't seem worth the trouble.)
  1332. X   */
  1333. X
  1334. X  single_scan = (cinfo->comps_in_scan == cinfo->num_components);
  1335. X
  1336. X  /* Account for passes needed (color quantizer adds its passes separately).
  1337. X   * If multiscan file, we guess that each component has its own scan,
  1338. X   * and increment completed_passes by the number of components in the scan.
  1339. X   */
  1340. X
  1341. X  if (single_scan)
  1342. X    cinfo->total_passes++;    /* the single scan */
  1343. X  else {
  1344. X    cinfo->total_passes += cinfo->num_components; /* guessed # of scans */
  1345. X    if (cinfo->two_pass_quantize)
  1346. X      cinfo->total_passes++;    /* account for separate CQ prescan pass */
  1347. X  }
  1348. X  if (! cinfo->two_pass_quantize)
  1349. X    cinfo->total_passes++;    /* count output pass unless quantizer does it */
  1350. X
  1351. X  /* Loop over scans in file */
  1352. X
  1353. X  do {
  1354. X    
  1355. X    /* Prepare for this scan */
  1356. X    if (cinfo->comps_in_scan == 1) {
  1357. X      noninterleaved_scan_setup(cinfo);
  1358. X      /* Need to read Vk MCU rows to obtain Vk block rows */
  1359. X      mcu_rows_per_loop = cinfo->cur_comp_info[0]->v_samp_factor;
  1360. X    } else {
  1361. X      interleaved_scan_setup(cinfo);
  1362. X      /* in an interleaved scan, one MCU row provides Vk block rows */
  1363. X      mcu_rows_per_loop = 1;
  1364. X    }
  1365. X    
  1366. X    /* Allocate scan-local working memory */
  1367. X    /* coeff_data holds a single MCU row of coefficient blocks */
  1368. X    coeff_data = alloc_MCU_row(cinfo);
  1369. X    /* if doing cross-block smoothing, need extra space for its input */
  1370. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1371. X    if (cinfo->do_block_smoothing) {
  1372. X      bsmooth[0] = alloc_MCU_row(cinfo);
  1373. X      bsmooth[1] = alloc_MCU_row(cinfo);
  1374. X      bsmooth[2] = alloc_MCU_row(cinfo);
  1375. X    }
  1376. X#endif
  1377. X    /* sampled_data is sample data before upsampling */
  1378. X    alloc_sampling_buffer(cinfo, sampled_data);
  1379. X
  1380. X    /* line up the big buffers for components in this scan */
  1381. X    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  1382. X      fullsize_ptrs[ci] = (*cinfo->emethods->access_big_sarray)
  1383. X    (fullsize_image[cinfo->cur_comp_info[ci]->component_index],
  1384. X     (long) 0, TRUE);
  1385. X    }
  1386. X    
  1387. X    /* Initialize to read scan data */
  1388. X    
  1389. X    (*cinfo->methods->entropy_decode_init) (cinfo);
  1390. X    (*cinfo->methods->upsample_init) (cinfo);
  1391. X    (*cinfo->methods->disassemble_init) (cinfo);
  1392. X    
  1393. X    /* Loop over scan's data: rows_in_mem pixel rows are processed per loop */
  1394. X    
  1395. X    pixel_rows_output = 0;
  1396. X    whichss = 1;        /* arrange to start with sampled_data[0] */
  1397. X    
  1398. X    for (cur_mcu_row = 0; cur_mcu_row < cinfo->MCU_rows_in_scan;
  1399. X     cur_mcu_row += mcu_rows_per_loop) {
  1400. X      (*cinfo->methods->progress_monitor) (cinfo, cur_mcu_row,
  1401. X                       cinfo->MCU_rows_in_scan);
  1402. X
  1403. X      whichss ^= 1;        /* switch to other downsampled-data buffer */
  1404. X
  1405. X      /* Obtain v_samp_factor block rows of each component in the scan. */
  1406. X      /* This is a single MCU row if interleaved, multiple MCU rows if not. */
  1407. X      /* In the noninterleaved case there might be fewer than v_samp_factor */
  1408. X      /* block rows remaining; if so, pad with copies of the last pixel row */
  1409. X      /* so that upsampling doesn't have to treat it as a special case. */
  1410. X      
  1411. X      for (ri = 0; ri < mcu_rows_per_loop; ri++) {
  1412. X    if (cur_mcu_row + ri < cinfo->MCU_rows_in_scan) {
  1413. X      /* OK to actually read an MCU row. */
  1414. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1415. X      if (cinfo->do_block_smoothing)
  1416. X        get_smoothed_row(cinfo, coeff_data,
  1417. X                 bsmooth, &whichb, cur_mcu_row + ri);
  1418. X      else
  1419. X#endif
  1420. X        (*cinfo->methods->disassemble_MCU) (cinfo, coeff_data);
  1421. X      
  1422. X      (*cinfo->methods->reverse_DCT) (cinfo, coeff_data,
  1423. X                      sampled_data[whichss],
  1424. X                      ri * DCTSIZE);
  1425. X    } else {
  1426. X      /* Need to pad out with copies of the last downsampled row. */
  1427. X      /* This can only happen if there is just one component. */
  1428. X      duplicate_row(sampled_data[whichss][0],
  1429. X            cinfo->cur_comp_info[0]->downsampled_width,
  1430. X            ri * DCTSIZE - 1, DCTSIZE);
  1431. X    }
  1432. X      }
  1433. X      
  1434. X      /* Upsample the data */
  1435. X      /* First time through is a special case */
  1436. X      
  1437. X      if (cur_mcu_row) {
  1438. X    /* Expand last row group of previous set */
  1439. X    expand(cinfo, sampled_data[whichss], fullsize_ptrs, fullsize_width,
  1440. X           (short) DCTSIZE, (short) (DCTSIZE+1), (short) 0,
  1441. X           (short) (DCTSIZE-1));
  1442. X    /* If single scan, can do color quantization prescan on-the-fly */
  1443. X    if (single_scan)
  1444. X      (*cinfo->methods->color_quant_prescan) (cinfo, rows_in_mem,
  1445. X                          fullsize_ptrs,
  1446. X                          output_workspace[0]);
  1447. X    /* Realign the big buffers */
  1448. X    pixel_rows_output += rows_in_mem;
  1449. X    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  1450. X      fullsize_ptrs[ci] = (*cinfo->emethods->access_big_sarray)
  1451. X        (fullsize_image[cinfo->cur_comp_info[ci]->component_index],
  1452. X         pixel_rows_output, TRUE);
  1453. X    }
  1454. X    /* Expand first row group of this set */
  1455. X    expand(cinfo, sampled_data[whichss], fullsize_ptrs, fullsize_width,
  1456. X           (short) (DCTSIZE+1), (short) 0, (short) 1,
  1457. X           (short) 0);
  1458. X      } else {
  1459. X    /* Expand first row group with dummy above-context */
  1460. X    expand(cinfo, sampled_data[whichss], fullsize_ptrs, fullsize_width,
  1461. X           (short) (-1), (short) 0, (short) 1,
  1462. X           (short) 0);
  1463. X      }
  1464. X      /* Expand second through next-to-last row groups of this set */
  1465. X      for (i = 1; i <= DCTSIZE-2; i++) {
  1466. X    expand(cinfo, sampled_data[whichss], fullsize_ptrs, fullsize_width,
  1467. X           (short) (i-1), (short) i, (short) (i+1),
  1468. X           (short) i);
  1469. X      }
  1470. X    } /* end of loop over scan's data */
  1471. X    
  1472. X    /* Expand the last row group with dummy below-context */
  1473. X    /* Note whichss points to last buffer side used */
  1474. X    expand(cinfo, sampled_data[whichss], fullsize_ptrs, fullsize_width,
  1475. X       (short) (DCTSIZE-2), (short) (DCTSIZE-1), (short) (-1),
  1476. X       (short) (DCTSIZE-1));
  1477. X    /* If single scan, finish on-the-fly color quantization prescan */
  1478. X    if (single_scan)
  1479. X      (*cinfo->methods->color_quant_prescan) (cinfo,
  1480. X            (int) (cinfo->image_height - pixel_rows_output),
  1481. X            fullsize_ptrs, output_workspace[0]);
  1482. X    
  1483. X    /* Clean up after the scan */
  1484. X    (*cinfo->methods->disassemble_term) (cinfo);
  1485. X    (*cinfo->methods->upsample_term) (cinfo);
  1486. X    (*cinfo->methods->entropy_decode_term) (cinfo);
  1487. X    (*cinfo->methods->read_scan_trailer) (cinfo);
  1488. X    if (single_scan)
  1489. X      cinfo->completed_passes++;
  1490. X    else
  1491. X      cinfo->completed_passes += cinfo->comps_in_scan;
  1492. X
  1493. X    /* Release scan-local working memory */
  1494. X    free_MCU_row(cinfo, coeff_data);
  1495. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1496. X    if (cinfo->do_block_smoothing) {
  1497. X      free_MCU_row(cinfo, bsmooth[0]);
  1498. X      free_MCU_row(cinfo, bsmooth[1]);
  1499. X      free_MCU_row(cinfo, bsmooth[2]);
  1500. X    }
  1501. X#endif
  1502. X    free_sampling_buffer(cinfo, sampled_data);
  1503. X    
  1504. X    /* Repeat if there is another scan */
  1505. X  } while ((!single_scan) && (*cinfo->methods->read_scan_header) (cinfo));
  1506. X
  1507. X  if (single_scan) {
  1508. X    /* If we expected just one scan, make SURE there's just one */
  1509. X    if ((*cinfo->methods->read_scan_header) (cinfo))
  1510. X      WARNMS(cinfo->emethods, "Didn't expect more than one scan");
  1511. X    /* We did the CQ prescan on-the-fly, so we are all set. */
  1512. X  } else {
  1513. X    /* For multiple-scan file, do the CQ prescan as a separate pass. */
  1514. X    /* The main reason why prescan is passed the output_workspace is */
  1515. X    /* so that we can use scan_big_image to call it... */
  1516. X    if (cinfo->two_pass_quantize)
  1517. X      scan_big_image(cinfo, cinfo->methods->color_quant_prescan);
  1518. X  }
  1519. X
  1520. X  /* Now that we've collected the data, do color processing and output */
  1521. X  if (cinfo->two_pass_quantize)
  1522. X    (*cinfo->methods->color_quant_doit) (cinfo, scan_big_image);
  1523. X  else
  1524. X    scan_big_image(cinfo, emit_1pass);
  1525. X
  1526. X  /* Release working memory */
  1527. X  /* (no work -- we let free_all release what's needful) */
  1528. X}
  1529. X
  1530. X#endif /* NEED_COMPLEX_CONTROLLER */
  1531. X
  1532. X
  1533. X/*
  1534. X * The method selection routine for decompression pipeline controllers.
  1535. X * Note that at this point we've already read the JPEG header and first SOS,
  1536. X * so we can tell whether the input is one scan or not.
  1537. X */
  1538. X
  1539. XGLOBAL void
  1540. Xjseldpipeline (decompress_info_ptr cinfo)
  1541. X{
  1542. X  /* simplify subsequent tests on color quantization */
  1543. X  if (! cinfo->quantize_colors)
  1544. X    cinfo->two_pass_quantize = FALSE;
  1545. X  
  1546. X  if (cinfo->comps_in_scan == cinfo->num_components) {
  1547. X    /* It's a single-scan file */
  1548. X    if (cinfo->two_pass_quantize) {
  1549. X#ifdef NEED_COMPLEX_CONTROLLER
  1550. X      cinfo->methods->d_pipeline_controller = complex_dcontroller;
  1551. X#else
  1552. X      ERREXIT(cinfo->emethods, "2-pass quantization support was not compiled");
  1553. X#endif
  1554. X    } else
  1555. X      cinfo->methods->d_pipeline_controller = simple_dcontroller;
  1556. X  } else {
  1557. X    /* It's a multiple-scan file */
  1558. X#ifdef NEED_COMPLEX_CONTROLLER
  1559. X    cinfo->methods->d_pipeline_controller = complex_dcontroller;
  1560. X#else
  1561. X    ERREXIT(cinfo->emethods, "Multiple-scan support was not compiled");
  1562. X#endif
  1563. X  }
  1564. X}
  1565. END_OF_FILE
  1566.   if test 38159 -ne `wc -c <'jdpipe.c'`; then
  1567.     echo shar: \"'jdpipe.c'\" unpacked with wrong size!
  1568.   fi
  1569.   # end of 'jdpipe.c'
  1570. fi
  1571. if test -f 'makvms.opt' -a "${1}" != "-c" ; then 
  1572.   echo shar: Will not clobber existing file \"'makvms.opt'\"
  1573. else
  1574.   echo shar: Extracting \"'makvms.opt'\" \(142 characters\)
  1575.   sed "s/^X//" >'makvms.opt' <<'END_OF_FILE'
  1576. X! a pointer to the VAX/VMS C Run-Time Shareable Library
  1577. X! This file is needed by makefile.mms and makefile.vms
  1578. XSys$Library:VAXCRTL.EXE /Share
  1579. END_OF_FILE
  1580.   if test 142 -ne `wc -c <'makvms.opt'`; then
  1581.     echo shar: \"'makvms.opt'\" unpacked with wrong size!
  1582.   fi
  1583.   # end of 'makvms.opt'
  1584. fi
  1585. echo shar: End of archive 5 \(of 18\).
  1586. cp /dev/null ark5isdone
  1587. MISSING=""
  1588. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1589.     if test ! -f ark${I}isdone ; then
  1590.     MISSING="${MISSING} ${I}"
  1591.     fi
  1592. done
  1593. if test "${MISSING}" = "" ; then
  1594.     echo You have unpacked all 18 archives.
  1595.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1596. else
  1597.     echo You still must unpack the following archives:
  1598.     echo "        " ${MISSING}
  1599. fi
  1600. exit 0
  1601. exit 0 # Just in case...
  1602.