isbn 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/README +9 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/isbn.gemspec +329 -0
- data/lib/isbn.rb +90 -0
- data/src/gocr-0.48/.cvsignore +6 -0
- data/src/gocr-0.48/AUTHORS +7 -0
- data/src/gocr-0.48/BUGS +55 -0
- data/src/gocr-0.48/CREDITS +17 -0
- data/src/gocr-0.48/HISTORY +243 -0
- data/src/gocr-0.48/INSTALL +83 -0
- data/src/gocr-0.48/Makefile +193 -0
- data/src/gocr-0.48/Makefile.in +193 -0
- data/src/gocr-0.48/README +165 -0
- data/src/gocr-0.48/READMEde.txt +80 -0
- data/src/gocr-0.48/REMARK.txt +18 -0
- data/src/gocr-0.48/REVIEW +538 -0
- data/src/gocr-0.48/TODO +65 -0
- data/src/gocr-0.48/bin/.cvsignore +2 -0
- data/src/gocr-0.48/bin/create_db +38 -0
- data/src/gocr-0.48/bin/gocr.tcl +527 -0
- data/src/gocr-0.48/bin/gocr_chk.sh +44 -0
- data/src/gocr-0.48/configure +4689 -0
- data/src/gocr-0.48/configure.in +71 -0
- data/src/gocr-0.48/doc/.#Makefile.1.6 +39 -0
- data/src/gocr-0.48/doc/.cvsignore +2 -0
- data/src/gocr-0.48/doc/Makefile +39 -0
- data/src/gocr-0.48/doc/Makefile.in +39 -0
- data/src/gocr-0.48/doc/example.dtd +53 -0
- data/src/gocr-0.48/doc/example.xml +21 -0
- data/src/gocr-0.48/doc/examples.txt +67 -0
- data/src/gocr-0.48/doc/gocr.html +578 -0
- data/src/gocr-0.48/doc/unicode.txt +57 -0
- data/src/gocr-0.48/examples/.#Makefile.1.22 +166 -0
- data/src/gocr-0.48/examples/4x6.png +0 -0
- data/src/gocr-0.48/examples/4x6.txt +2 -0
- data/src/gocr-0.48/examples/5x7.png +0 -0
- data/src/gocr-0.48/examples/5x7.png.txt +2 -0
- data/src/gocr-0.48/examples/5x8.png +0 -0
- data/src/gocr-0.48/examples/5x8.png.txt +2 -0
- data/src/gocr-0.48/examples/Makefile +166 -0
- data/src/gocr-0.48/examples/color.fig +20 -0
- data/src/gocr-0.48/examples/ex.fig +16 -0
- data/src/gocr-0.48/examples/font.tex +22 -0
- data/src/gocr-0.48/examples/font1.tex +46 -0
- data/src/gocr-0.48/examples/font2.fig +27 -0
- data/src/gocr-0.48/examples/font_nw.tex +24 -0
- data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
- data/src/gocr-0.48/examples/handwrt1.txt +10 -0
- data/src/gocr-0.48/examples/inverse.fig +20 -0
- data/src/gocr-0.48/examples/matrix.jpg +0 -0
- data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
- data/src/gocr-0.48/examples/ocr-a-subset.png.txt +4 -0
- data/src/gocr-0.48/examples/ocr-a.png +0 -0
- data/src/gocr-0.48/examples/ocr-a.txt +6 -0
- data/src/gocr-0.48/examples/ocr-b.png +0 -0
- data/src/gocr-0.48/examples/ocr-b.png.txt +4 -0
- data/src/gocr-0.48/examples/polish.tex +28 -0
- data/src/gocr-0.48/examples/rotate45.fig +14 -0
- data/src/gocr-0.48/examples/score +36 -0
- data/src/gocr-0.48/examples/text.tex +28 -0
- data/src/gocr-0.48/gocr.spec +143 -0
- data/src/gocr-0.48/gpl.html +537 -0
- data/src/gocr-0.48/include/.cvsignore +2 -0
- data/src/gocr-0.48/include/config.h +36 -0
- data/src/gocr-0.48/include/config.h.in +36 -0
- data/src/gocr-0.48/include/version.h +2 -0
- data/src/gocr-0.48/install-sh +3 -0
- data/src/gocr-0.48/make.bat +57 -0
- data/src/gocr-0.48/man/.cvsignore +2 -0
- data/src/gocr-0.48/man/Makefile +29 -0
- data/src/gocr-0.48/man/Makefile.in +29 -0
- data/src/gocr-0.48/man/man1/gocr.1 +166 -0
- data/src/gocr-0.48/src/.cvsignore +4 -0
- data/src/gocr-0.48/src/Makefile +132 -0
- data/src/gocr-0.48/src/Makefile.in +132 -0
- data/src/gocr-0.48/src/amiga.h +31 -0
- data/src/gocr-0.48/src/barcode.c +846 -0
- data/src/gocr-0.48/src/barcode.c.orig +593 -0
- data/src/gocr-0.48/src/barcode.h +11 -0
- data/src/gocr-0.48/src/box.c +372 -0
- data/src/gocr-0.48/src/database.c +462 -0
- data/src/gocr-0.48/src/detect.c +943 -0
- data/src/gocr-0.48/src/gocr.c +373 -0
- data/src/gocr-0.48/src/gocr.h +288 -0
- data/src/gocr-0.48/src/jconv.c +168 -0
- data/src/gocr-0.48/src/job.c +84 -0
- data/src/gocr-0.48/src/lines.c +350 -0
- data/src/gocr-0.48/src/list.c +334 -0
- data/src/gocr-0.48/src/list.h +90 -0
- data/src/gocr-0.48/src/ocr0.c +6756 -0
- data/src/gocr-0.48/src/ocr0.h +63 -0
- data/src/gocr-0.48/src/ocr0n.c +1475 -0
- data/src/gocr-0.48/src/ocr1.c +85 -0
- data/src/gocr-0.48/src/ocr1.h +3 -0
- data/src/gocr-0.48/src/otsu.c +289 -0
- data/src/gocr-0.48/src/otsu.h +23 -0
- data/src/gocr-0.48/src/output.c +289 -0
- data/src/gocr-0.48/src/output.h +37 -0
- data/src/gocr-0.48/src/pcx.c +153 -0
- data/src/gocr-0.48/src/pcx.h +9 -0
- data/src/gocr-0.48/src/pgm2asc.c +2893 -0
- data/src/gocr-0.48/src/pgm2asc.h +105 -0
- data/src/gocr-0.48/src/pixel.c +537 -0
- data/src/gocr-0.48/src/pnm.c +533 -0
- data/src/gocr-0.48/src/pnm.h +35 -0
- data/src/gocr-0.48/src/progress.c +87 -0
- data/src/gocr-0.48/src/progress.h +42 -0
- data/src/gocr-0.48/src/remove.c +703 -0
- data/src/gocr-0.48/src/tga.c +87 -0
- data/src/gocr-0.48/src/tga.h +6 -0
- data/src/gocr-0.48/src/unicode.c +1314 -0
- data/src/gocr-0.48/src/unicode.h +1257 -0
- data/src/jpeg-7/Makefile.am +133 -0
- data/src/jpeg-7/Makefile.in +1089 -0
- data/src/jpeg-7/README +322 -0
- data/src/jpeg-7/aclocal.m4 +8990 -0
- data/src/jpeg-7/ansi2knr.1 +36 -0
- data/src/jpeg-7/ansi2knr.c +739 -0
- data/src/jpeg-7/cderror.h +132 -0
- data/src/jpeg-7/cdjpeg.c +181 -0
- data/src/jpeg-7/cdjpeg.h +187 -0
- data/src/jpeg-7/change.log +270 -0
- data/src/jpeg-7/cjpeg.1 +325 -0
- data/src/jpeg-7/cjpeg.c +616 -0
- data/src/jpeg-7/ckconfig.c +402 -0
- data/src/jpeg-7/coderules.txt +118 -0
- data/src/jpeg-7/config.guess +1561 -0
- data/src/jpeg-7/config.sub +1686 -0
- data/src/jpeg-7/configure +17139 -0
- data/src/jpeg-7/configure.ac +317 -0
- data/src/jpeg-7/depcomp +630 -0
- data/src/jpeg-7/djpeg.1 +251 -0
- data/src/jpeg-7/djpeg.c +617 -0
- data/src/jpeg-7/example.c +433 -0
- data/src/jpeg-7/filelist.txt +215 -0
- data/src/jpeg-7/install-sh +520 -0
- data/src/jpeg-7/install.txt +1097 -0
- data/src/jpeg-7/jaricom.c +148 -0
- data/src/jpeg-7/jcapimin.c +282 -0
- data/src/jpeg-7/jcapistd.c +161 -0
- data/src/jpeg-7/jcarith.c +921 -0
- data/src/jpeg-7/jccoefct.c +453 -0
- data/src/jpeg-7/jccolor.c +459 -0
- data/src/jpeg-7/jcdctmgr.c +482 -0
- data/src/jpeg-7/jchuff.c +1612 -0
- data/src/jpeg-7/jcinit.c +65 -0
- data/src/jpeg-7/jcmainct.c +293 -0
- data/src/jpeg-7/jcmarker.c +667 -0
- data/src/jpeg-7/jcmaster.c +770 -0
- data/src/jpeg-7/jcomapi.c +106 -0
- data/src/jpeg-7/jconfig.bcc +48 -0
- data/src/jpeg-7/jconfig.cfg +45 -0
- data/src/jpeg-7/jconfig.dj +38 -0
- data/src/jpeg-7/jconfig.mac +43 -0
- data/src/jpeg-7/jconfig.manx +43 -0
- data/src/jpeg-7/jconfig.mc6 +52 -0
- data/src/jpeg-7/jconfig.sas +43 -0
- data/src/jpeg-7/jconfig.st +42 -0
- data/src/jpeg-7/jconfig.txt +155 -0
- data/src/jpeg-7/jconfig.vc +45 -0
- data/src/jpeg-7/jconfig.vms +37 -0
- data/src/jpeg-7/jconfig.wat +38 -0
- data/src/jpeg-7/jcparam.c +632 -0
- data/src/jpeg-7/jcprepct.c +358 -0
- data/src/jpeg-7/jcsample.c +545 -0
- data/src/jpeg-7/jctrans.c +381 -0
- data/src/jpeg-7/jdapimin.c +396 -0
- data/src/jpeg-7/jdapistd.c +275 -0
- data/src/jpeg-7/jdarith.c +762 -0
- data/src/jpeg-7/jdatadst.c +151 -0
- data/src/jpeg-7/jdatasrc.c +212 -0
- data/src/jpeg-7/jdcoefct.c +736 -0
- data/src/jpeg-7/jdcolor.c +396 -0
- data/src/jpeg-7/jdct.h +393 -0
- data/src/jpeg-7/jddctmgr.c +382 -0
- data/src/jpeg-7/jdhuff.c +1309 -0
- data/src/jpeg-7/jdinput.c +384 -0
- data/src/jpeg-7/jdmainct.c +512 -0
- data/src/jpeg-7/jdmarker.c +1360 -0
- data/src/jpeg-7/jdmaster.c +663 -0
- data/src/jpeg-7/jdmerge.c +400 -0
- data/src/jpeg-7/jdpostct.c +290 -0
- data/src/jpeg-7/jdsample.c +361 -0
- data/src/jpeg-7/jdtrans.c +136 -0
- data/src/jpeg-7/jerror.c +252 -0
- data/src/jpeg-7/jerror.h +304 -0
- data/src/jpeg-7/jfdctflt.c +174 -0
- data/src/jpeg-7/jfdctfst.c +230 -0
- data/src/jpeg-7/jfdctint.c +4348 -0
- data/src/jpeg-7/jidctflt.c +242 -0
- data/src/jpeg-7/jidctfst.c +368 -0
- data/src/jpeg-7/jidctint.c +5137 -0
- data/src/jpeg-7/jinclude.h +91 -0
- data/src/jpeg-7/jmemansi.c +167 -0
- data/src/jpeg-7/jmemdos.c +638 -0
- data/src/jpeg-7/jmemdosa.asm +379 -0
- data/src/jpeg-7/jmemmac.c +289 -0
- data/src/jpeg-7/jmemmgr.c +1118 -0
- data/src/jpeg-7/jmemname.c +276 -0
- data/src/jpeg-7/jmemnobs.c +109 -0
- data/src/jpeg-7/jmemsys.h +198 -0
- data/src/jpeg-7/jmorecfg.h +369 -0
- data/src/jpeg-7/jpegint.h +395 -0
- data/src/jpeg-7/jpeglib.h +1135 -0
- data/src/jpeg-7/jpegtran.1 +272 -0
- data/src/jpeg-7/jpegtran.c +546 -0
- data/src/jpeg-7/jquant1.c +856 -0
- data/src/jpeg-7/jquant2.c +1310 -0
- data/src/jpeg-7/jutils.c +179 -0
- data/src/jpeg-7/jversion.h +14 -0
- data/src/jpeg-7/libjpeg.map +4 -0
- data/src/jpeg-7/libjpeg.txt +3067 -0
- data/src/jpeg-7/ltmain.sh +8406 -0
- data/src/jpeg-7/makcjpeg.st +36 -0
- data/src/jpeg-7/makdjpeg.st +36 -0
- data/src/jpeg-7/makeadsw.vc6 +77 -0
- data/src/jpeg-7/makeasln.vc9 +33 -0
- data/src/jpeg-7/makecdep.vc6 +82 -0
- data/src/jpeg-7/makecdsp.vc6 +130 -0
- data/src/jpeg-7/makecmak.vc6 +159 -0
- data/src/jpeg-7/makecvcp.vc9 +186 -0
- data/src/jpeg-7/makeddep.vc6 +82 -0
- data/src/jpeg-7/makeddsp.vc6 +130 -0
- data/src/jpeg-7/makedmak.vc6 +159 -0
- data/src/jpeg-7/makedvcp.vc9 +186 -0
- data/src/jpeg-7/makefile.ansi +220 -0
- data/src/jpeg-7/makefile.bcc +291 -0
- data/src/jpeg-7/makefile.dj +226 -0
- data/src/jpeg-7/makefile.manx +220 -0
- data/src/jpeg-7/makefile.mc6 +255 -0
- data/src/jpeg-7/makefile.mms +224 -0
- data/src/jpeg-7/makefile.sas +258 -0
- data/src/jpeg-7/makefile.unix +234 -0
- data/src/jpeg-7/makefile.vc +217 -0
- data/src/jpeg-7/makefile.vms +142 -0
- data/src/jpeg-7/makefile.wat +239 -0
- data/src/jpeg-7/makejdep.vc6 +423 -0
- data/src/jpeg-7/makejdsp.vc6 +285 -0
- data/src/jpeg-7/makejdsw.vc6 +29 -0
- data/src/jpeg-7/makejmak.vc6 +425 -0
- data/src/jpeg-7/makejsln.vc9 +17 -0
- data/src/jpeg-7/makejvcp.vc9 +328 -0
- data/src/jpeg-7/makeproj.mac +213 -0
- data/src/jpeg-7/makerdep.vc6 +6 -0
- data/src/jpeg-7/makerdsp.vc6 +78 -0
- data/src/jpeg-7/makermak.vc6 +110 -0
- data/src/jpeg-7/makervcp.vc9 +133 -0
- data/src/jpeg-7/maketdep.vc6 +43 -0
- data/src/jpeg-7/maketdsp.vc6 +122 -0
- data/src/jpeg-7/maketmak.vc6 +131 -0
- data/src/jpeg-7/maketvcp.vc9 +178 -0
- data/src/jpeg-7/makewdep.vc6 +6 -0
- data/src/jpeg-7/makewdsp.vc6 +78 -0
- data/src/jpeg-7/makewmak.vc6 +110 -0
- data/src/jpeg-7/makewvcp.vc9 +133 -0
- data/src/jpeg-7/makljpeg.st +68 -0
- data/src/jpeg-7/maktjpeg.st +30 -0
- data/src/jpeg-7/makvms.opt +4 -0
- data/src/jpeg-7/missing +376 -0
- data/src/jpeg-7/rdbmp.c +439 -0
- data/src/jpeg-7/rdcolmap.c +253 -0
- data/src/jpeg-7/rdgif.c +38 -0
- data/src/jpeg-7/rdjpgcom.1 +63 -0
- data/src/jpeg-7/rdjpgcom.c +515 -0
- data/src/jpeg-7/rdppm.c +459 -0
- data/src/jpeg-7/rdrle.c +387 -0
- data/src/jpeg-7/rdswitch.c +365 -0
- data/src/jpeg-7/rdtarga.c +500 -0
- data/src/jpeg-7/structure.txt +945 -0
- data/src/jpeg-7/testimg.bmp +0 -0
- data/src/jpeg-7/testimg.jpg +0 -0
- data/src/jpeg-7/testimg.ppm +4 -0
- data/src/jpeg-7/testimgp.jpg +0 -0
- data/src/jpeg-7/testorig.jpg +0 -0
- data/src/jpeg-7/testprog.jpg +0 -0
- data/src/jpeg-7/transupp.c +1533 -0
- data/src/jpeg-7/transupp.h +205 -0
- data/src/jpeg-7/usage.txt +605 -0
- data/src/jpeg-7/wizard.txt +211 -0
- data/src/jpeg-7/wrbmp.c +442 -0
- data/src/jpeg-7/wrgif.c +399 -0
- data/src/jpeg-7/wrjpgcom.1 +103 -0
- data/src/jpeg-7/wrjpgcom.c +583 -0
- data/src/jpeg-7/wrppm.c +269 -0
- data/src/jpeg-7/wrrle.c +305 -0
- data/src/jpeg-7/wrtarga.c +253 -0
- data/test/isbn_test.rb +7 -0
- data/test/test_helper.rb +7 -0
- metadata +345 -0
@@ -0,0 +1,663 @@
|
|
1
|
+
/*
|
2
|
+
* jdmaster.c
|
3
|
+
*
|
4
|
+
* Copyright (C) 1991-1997, Thomas G. Lane.
|
5
|
+
* Modified 2002-2008 by Guido Vollbeding.
|
6
|
+
* This file is part of the Independent JPEG Group's software.
|
7
|
+
* For conditions of distribution and use, see the accompanying README file.
|
8
|
+
*
|
9
|
+
* This file contains master control logic for the JPEG decompressor.
|
10
|
+
* These routines are concerned with selecting the modules to be executed
|
11
|
+
* and with determining the number of passes and the work to be done in each
|
12
|
+
* pass.
|
13
|
+
*/
|
14
|
+
|
15
|
+
#define JPEG_INTERNALS
|
16
|
+
#include "jinclude.h"
|
17
|
+
#include "jpeglib.h"
|
18
|
+
|
19
|
+
|
20
|
+
/* Private state */
|
21
|
+
|
22
|
+
typedef struct {
|
23
|
+
struct jpeg_decomp_master pub; /* public fields */
|
24
|
+
|
25
|
+
int pass_number; /* # of passes completed */
|
26
|
+
|
27
|
+
boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
|
28
|
+
|
29
|
+
/* Saved references to initialized quantizer modules,
|
30
|
+
* in case we need to switch modes.
|
31
|
+
*/
|
32
|
+
struct jpeg_color_quantizer * quantizer_1pass;
|
33
|
+
struct jpeg_color_quantizer * quantizer_2pass;
|
34
|
+
} my_decomp_master;
|
35
|
+
|
36
|
+
typedef my_decomp_master * my_master_ptr;
|
37
|
+
|
38
|
+
|
39
|
+
/*
|
40
|
+
* Determine whether merged upsample/color conversion should be used.
|
41
|
+
* CRUCIAL: this must match the actual capabilities of jdmerge.c!
|
42
|
+
*/
|
43
|
+
|
44
|
+
LOCAL(boolean)
|
45
|
+
use_merged_upsample (j_decompress_ptr cinfo)
|
46
|
+
{
|
47
|
+
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
48
|
+
/* Merging is the equivalent of plain box-filter upsampling */
|
49
|
+
if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
|
50
|
+
return FALSE;
|
51
|
+
/* jdmerge.c only supports YCC=>RGB color conversion */
|
52
|
+
if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
|
53
|
+
cinfo->out_color_space != JCS_RGB ||
|
54
|
+
cinfo->out_color_components != RGB_PIXELSIZE)
|
55
|
+
return FALSE;
|
56
|
+
/* and it only handles 2h1v or 2h2v sampling ratios */
|
57
|
+
if (cinfo->comp_info[0].h_samp_factor != 2 ||
|
58
|
+
cinfo->comp_info[1].h_samp_factor != 1 ||
|
59
|
+
cinfo->comp_info[2].h_samp_factor != 1 ||
|
60
|
+
cinfo->comp_info[0].v_samp_factor > 2 ||
|
61
|
+
cinfo->comp_info[1].v_samp_factor != 1 ||
|
62
|
+
cinfo->comp_info[2].v_samp_factor != 1)
|
63
|
+
return FALSE;
|
64
|
+
/* furthermore, it doesn't work if we've scaled the IDCTs differently */
|
65
|
+
if (cinfo->comp_info[0].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
|
66
|
+
cinfo->comp_info[1].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
|
67
|
+
cinfo->comp_info[2].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
|
68
|
+
cinfo->comp_info[0].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
|
69
|
+
cinfo->comp_info[1].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
|
70
|
+
cinfo->comp_info[2].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size)
|
71
|
+
return FALSE;
|
72
|
+
/* ??? also need to test for upsample-time rescaling, when & if supported */
|
73
|
+
return TRUE; /* by golly, it'll work... */
|
74
|
+
#else
|
75
|
+
return FALSE;
|
76
|
+
#endif
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Compute output image dimensions and related values.
|
82
|
+
* NOTE: this is exported for possible use by application.
|
83
|
+
* Hence it mustn't do anything that can't be done twice.
|
84
|
+
* Also note that it may be called before the master module is initialized!
|
85
|
+
*/
|
86
|
+
|
87
|
+
GLOBAL(void)
|
88
|
+
jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
89
|
+
/* Do computations that are needed before master selection phase */
|
90
|
+
{
|
91
|
+
#ifdef IDCT_SCALING_SUPPORTED
|
92
|
+
int ci;
|
93
|
+
jpeg_component_info *compptr;
|
94
|
+
#endif
|
95
|
+
|
96
|
+
/* Prevent application from calling me at wrong times */
|
97
|
+
if (cinfo->global_state != DSTATE_READY)
|
98
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
99
|
+
|
100
|
+
#ifdef IDCT_SCALING_SUPPORTED
|
101
|
+
|
102
|
+
/* Compute actual output image dimensions and DCT scaling choices. */
|
103
|
+
if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
|
104
|
+
/* Provide 1/8 scaling */
|
105
|
+
cinfo->output_width = (JDIMENSION)
|
106
|
+
jdiv_round_up((long) cinfo->image_width, 8L);
|
107
|
+
cinfo->output_height = (JDIMENSION)
|
108
|
+
jdiv_round_up((long) cinfo->image_height, 8L);
|
109
|
+
cinfo->min_DCT_h_scaled_size = 1;
|
110
|
+
cinfo->min_DCT_v_scaled_size = 1;
|
111
|
+
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
|
112
|
+
/* Provide 1/4 scaling */
|
113
|
+
cinfo->output_width = (JDIMENSION)
|
114
|
+
jdiv_round_up((long) cinfo->image_width, 4L);
|
115
|
+
cinfo->output_height = (JDIMENSION)
|
116
|
+
jdiv_round_up((long) cinfo->image_height, 4L);
|
117
|
+
cinfo->min_DCT_h_scaled_size = 2;
|
118
|
+
cinfo->min_DCT_v_scaled_size = 2;
|
119
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 3) {
|
120
|
+
/* Provide 3/8 scaling */
|
121
|
+
cinfo->output_width = (JDIMENSION)
|
122
|
+
jdiv_round_up((long) cinfo->image_width * 3L, 8L);
|
123
|
+
cinfo->output_height = (JDIMENSION)
|
124
|
+
jdiv_round_up((long) cinfo->image_height * 3L, 8L);
|
125
|
+
cinfo->min_DCT_h_scaled_size = 3;
|
126
|
+
cinfo->min_DCT_v_scaled_size = 3;
|
127
|
+
} else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
|
128
|
+
/* Provide 1/2 scaling */
|
129
|
+
cinfo->output_width = (JDIMENSION)
|
130
|
+
jdiv_round_up((long) cinfo->image_width, 2L);
|
131
|
+
cinfo->output_height = (JDIMENSION)
|
132
|
+
jdiv_round_up((long) cinfo->image_height, 2L);
|
133
|
+
cinfo->min_DCT_h_scaled_size = 4;
|
134
|
+
cinfo->min_DCT_v_scaled_size = 4;
|
135
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 5) {
|
136
|
+
/* Provide 5/8 scaling */
|
137
|
+
cinfo->output_width = (JDIMENSION)
|
138
|
+
jdiv_round_up((long) cinfo->image_width * 5L, 8L);
|
139
|
+
cinfo->output_height = (JDIMENSION)
|
140
|
+
jdiv_round_up((long) cinfo->image_height * 5L, 8L);
|
141
|
+
cinfo->min_DCT_h_scaled_size = 5;
|
142
|
+
cinfo->min_DCT_v_scaled_size = 5;
|
143
|
+
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 3) {
|
144
|
+
/* Provide 3/4 scaling */
|
145
|
+
cinfo->output_width = (JDIMENSION)
|
146
|
+
jdiv_round_up((long) cinfo->image_width * 3L, 4L);
|
147
|
+
cinfo->output_height = (JDIMENSION)
|
148
|
+
jdiv_round_up((long) cinfo->image_height * 3L, 4L);
|
149
|
+
cinfo->min_DCT_h_scaled_size = 6;
|
150
|
+
cinfo->min_DCT_v_scaled_size = 6;
|
151
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 7) {
|
152
|
+
/* Provide 7/8 scaling */
|
153
|
+
cinfo->output_width = (JDIMENSION)
|
154
|
+
jdiv_round_up((long) cinfo->image_width * 7L, 8L);
|
155
|
+
cinfo->output_height = (JDIMENSION)
|
156
|
+
jdiv_round_up((long) cinfo->image_height * 7L, 8L);
|
157
|
+
cinfo->min_DCT_h_scaled_size = 7;
|
158
|
+
cinfo->min_DCT_v_scaled_size = 7;
|
159
|
+
} else if (cinfo->scale_num <= cinfo->scale_denom) {
|
160
|
+
/* Provide 1/1 scaling */
|
161
|
+
cinfo->output_width = cinfo->image_width;
|
162
|
+
cinfo->output_height = cinfo->image_height;
|
163
|
+
cinfo->min_DCT_h_scaled_size = DCTSIZE;
|
164
|
+
cinfo->min_DCT_v_scaled_size = DCTSIZE;
|
165
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 9) {
|
166
|
+
/* Provide 9/8 scaling */
|
167
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
168
|
+
jdiv_round_up((long) cinfo->image_width, 8L);
|
169
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
170
|
+
jdiv_round_up((long) cinfo->image_height, 8L);
|
171
|
+
cinfo->min_DCT_h_scaled_size = 9;
|
172
|
+
cinfo->min_DCT_v_scaled_size = 9;
|
173
|
+
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 5) {
|
174
|
+
/* Provide 5/4 scaling */
|
175
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
176
|
+
jdiv_round_up((long) cinfo->image_width, 4L);
|
177
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
178
|
+
jdiv_round_up((long) cinfo->image_height, 4L);
|
179
|
+
cinfo->min_DCT_h_scaled_size = 10;
|
180
|
+
cinfo->min_DCT_v_scaled_size = 10;
|
181
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 11) {
|
182
|
+
/* Provide 11/8 scaling */
|
183
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
184
|
+
jdiv_round_up((long) cinfo->image_width * 3L, 8L);
|
185
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
186
|
+
jdiv_round_up((long) cinfo->image_height * 3L, 8L);
|
187
|
+
cinfo->min_DCT_h_scaled_size = 11;
|
188
|
+
cinfo->min_DCT_v_scaled_size = 11;
|
189
|
+
} else if (cinfo->scale_num * 2 <= cinfo->scale_denom * 3) {
|
190
|
+
/* Provide 3/2 scaling */
|
191
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
192
|
+
jdiv_round_up((long) cinfo->image_width, 2L);
|
193
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
194
|
+
jdiv_round_up((long) cinfo->image_height, 2L);
|
195
|
+
cinfo->min_DCT_h_scaled_size = 12;
|
196
|
+
cinfo->min_DCT_v_scaled_size = 12;
|
197
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 13) {
|
198
|
+
/* Provide 13/8 scaling */
|
199
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
200
|
+
jdiv_round_up((long) cinfo->image_width * 5L, 8L);
|
201
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
202
|
+
jdiv_round_up((long) cinfo->image_height * 5L, 8L);
|
203
|
+
cinfo->min_DCT_h_scaled_size = 13;
|
204
|
+
cinfo->min_DCT_v_scaled_size = 13;
|
205
|
+
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 7) {
|
206
|
+
/* Provide 7/4 scaling */
|
207
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
208
|
+
jdiv_round_up((long) cinfo->image_width * 3L, 4L);
|
209
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
210
|
+
jdiv_round_up((long) cinfo->image_height * 3L, 4L);
|
211
|
+
cinfo->min_DCT_h_scaled_size = 14;
|
212
|
+
cinfo->min_DCT_v_scaled_size = 14;
|
213
|
+
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 15) {
|
214
|
+
/* Provide 15/8 scaling */
|
215
|
+
cinfo->output_width = cinfo->image_width + (JDIMENSION)
|
216
|
+
jdiv_round_up((long) cinfo->image_width * 7L, 8L);
|
217
|
+
cinfo->output_height = cinfo->image_height + (JDIMENSION)
|
218
|
+
jdiv_round_up((long) cinfo->image_height * 7L, 8L);
|
219
|
+
cinfo->min_DCT_h_scaled_size = 15;
|
220
|
+
cinfo->min_DCT_v_scaled_size = 15;
|
221
|
+
} else {
|
222
|
+
/* Provide 2/1 scaling */
|
223
|
+
cinfo->output_width = cinfo->image_width << 1;
|
224
|
+
cinfo->output_height = cinfo->image_height << 1;
|
225
|
+
cinfo->min_DCT_h_scaled_size = 16;
|
226
|
+
cinfo->min_DCT_v_scaled_size = 16;
|
227
|
+
}
|
228
|
+
/* In selecting the actual DCT scaling for each component, we try to
|
229
|
+
* scale up the chroma components via IDCT scaling rather than upsampling.
|
230
|
+
* This saves time if the upsampler gets to use 1:1 scaling.
|
231
|
+
* Note this code adapts subsampling ratios which are powers of 2.
|
232
|
+
*/
|
233
|
+
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
234
|
+
ci++, compptr++) {
|
235
|
+
int ssize = 1;
|
236
|
+
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
237
|
+
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
238
|
+
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
|
239
|
+
ssize = ssize * 2;
|
240
|
+
}
|
241
|
+
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
242
|
+
ssize = 1;
|
243
|
+
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
244
|
+
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
245
|
+
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
|
246
|
+
ssize = ssize * 2;
|
247
|
+
}
|
248
|
+
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
249
|
+
|
250
|
+
/* We don't support IDCT ratios larger than 2. */
|
251
|
+
if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
|
252
|
+
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
|
253
|
+
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
|
254
|
+
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
|
255
|
+
}
|
256
|
+
|
257
|
+
/* Recompute downsampled dimensions of components;
|
258
|
+
* application needs to know these if using raw downsampled data.
|
259
|
+
*/
|
260
|
+
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
261
|
+
ci++, compptr++) {
|
262
|
+
/* Size in samples, after IDCT scaling */
|
263
|
+
compptr->downsampled_width = (JDIMENSION)
|
264
|
+
jdiv_round_up((long) cinfo->image_width *
|
265
|
+
(long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),
|
266
|
+
(long) (cinfo->max_h_samp_factor * DCTSIZE));
|
267
|
+
compptr->downsampled_height = (JDIMENSION)
|
268
|
+
jdiv_round_up((long) cinfo->image_height *
|
269
|
+
(long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
|
270
|
+
(long) (cinfo->max_v_samp_factor * DCTSIZE));
|
271
|
+
}
|
272
|
+
|
273
|
+
#else /* !IDCT_SCALING_SUPPORTED */
|
274
|
+
|
275
|
+
/* Hardwire it to "no scaling" */
|
276
|
+
cinfo->output_width = cinfo->image_width;
|
277
|
+
cinfo->output_height = cinfo->image_height;
|
278
|
+
/* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
|
279
|
+
* and has computed unscaled downsampled_width and downsampled_height.
|
280
|
+
*/
|
281
|
+
|
282
|
+
#endif /* IDCT_SCALING_SUPPORTED */
|
283
|
+
|
284
|
+
/* Report number of components in selected colorspace. */
|
285
|
+
/* Probably this should be in the color conversion module... */
|
286
|
+
switch (cinfo->out_color_space) {
|
287
|
+
case JCS_GRAYSCALE:
|
288
|
+
cinfo->out_color_components = 1;
|
289
|
+
break;
|
290
|
+
case JCS_RGB:
|
291
|
+
#if RGB_PIXELSIZE != 3
|
292
|
+
cinfo->out_color_components = RGB_PIXELSIZE;
|
293
|
+
break;
|
294
|
+
#endif /* else share code with YCbCr */
|
295
|
+
case JCS_YCbCr:
|
296
|
+
cinfo->out_color_components = 3;
|
297
|
+
break;
|
298
|
+
case JCS_CMYK:
|
299
|
+
case JCS_YCCK:
|
300
|
+
cinfo->out_color_components = 4;
|
301
|
+
break;
|
302
|
+
default: /* else must be same colorspace as in file */
|
303
|
+
cinfo->out_color_components = cinfo->num_components;
|
304
|
+
break;
|
305
|
+
}
|
306
|
+
cinfo->output_components = (cinfo->quantize_colors ? 1 :
|
307
|
+
cinfo->out_color_components);
|
308
|
+
|
309
|
+
/* See if upsampler will want to emit more than one row at a time */
|
310
|
+
if (use_merged_upsample(cinfo))
|
311
|
+
cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
|
312
|
+
else
|
313
|
+
cinfo->rec_outbuf_height = 1;
|
314
|
+
}
|
315
|
+
|
316
|
+
|
317
|
+
/*
|
318
|
+
* Several decompression processes need to range-limit values to the range
|
319
|
+
* 0..MAXJSAMPLE; the input value may fall somewhat outside this range
|
320
|
+
* due to noise introduced by quantization, roundoff error, etc. These
|
321
|
+
* processes are inner loops and need to be as fast as possible. On most
|
322
|
+
* machines, particularly CPUs with pipelines or instruction prefetch,
|
323
|
+
* a (subscript-check-less) C table lookup
|
324
|
+
* x = sample_range_limit[x];
|
325
|
+
* is faster than explicit tests
|
326
|
+
* if (x < 0) x = 0;
|
327
|
+
* else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
|
328
|
+
* These processes all use a common table prepared by the routine below.
|
329
|
+
*
|
330
|
+
* For most steps we can mathematically guarantee that the initial value
|
331
|
+
* of x is within MAXJSAMPLE+1 of the legal range, so a table running from
|
332
|
+
* -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
|
333
|
+
* limiting step (just after the IDCT), a wildly out-of-range value is
|
334
|
+
* possible if the input data is corrupt. To avoid any chance of indexing
|
335
|
+
* off the end of memory and getting a bad-pointer trap, we perform the
|
336
|
+
* post-IDCT limiting thus:
|
337
|
+
* x = range_limit[x & MASK];
|
338
|
+
* where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
|
339
|
+
* samples. Under normal circumstances this is more than enough range and
|
340
|
+
* a correct output will be generated; with bogus input data the mask will
|
341
|
+
* cause wraparound, and we will safely generate a bogus-but-in-range output.
|
342
|
+
* For the post-IDCT step, we want to convert the data from signed to unsigned
|
343
|
+
* representation by adding CENTERJSAMPLE at the same time that we limit it.
|
344
|
+
* So the post-IDCT limiting table ends up looking like this:
|
345
|
+
* CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
|
346
|
+
* MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
|
347
|
+
* 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
|
348
|
+
* 0,1,...,CENTERJSAMPLE-1
|
349
|
+
* Negative inputs select values from the upper half of the table after
|
350
|
+
* masking.
|
351
|
+
*
|
352
|
+
* We can save some space by overlapping the start of the post-IDCT table
|
353
|
+
* with the simpler range limiting table. The post-IDCT table begins at
|
354
|
+
* sample_range_limit + CENTERJSAMPLE.
|
355
|
+
*
|
356
|
+
* Note that the table is allocated in near data space on PCs; it's small
|
357
|
+
* enough and used often enough to justify this.
|
358
|
+
*/
|
359
|
+
|
360
|
+
LOCAL(void)
|
361
|
+
prepare_range_limit_table (j_decompress_ptr cinfo)
|
362
|
+
/* Allocate and fill in the sample_range_limit table */
|
363
|
+
{
|
364
|
+
JSAMPLE * table;
|
365
|
+
int i;
|
366
|
+
|
367
|
+
table = (JSAMPLE *)
|
368
|
+
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
369
|
+
(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
370
|
+
table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
|
371
|
+
cinfo->sample_range_limit = table;
|
372
|
+
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
|
373
|
+
MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
|
374
|
+
/* Main part of "simple" table: limit[x] = x */
|
375
|
+
for (i = 0; i <= MAXJSAMPLE; i++)
|
376
|
+
table[i] = (JSAMPLE) i;
|
377
|
+
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
|
378
|
+
/* End of simple table, rest of first half of post-IDCT table */
|
379
|
+
for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
|
380
|
+
table[i] = MAXJSAMPLE;
|
381
|
+
/* Second half of post-IDCT table */
|
382
|
+
MEMZERO(table + (2 * (MAXJSAMPLE+1)),
|
383
|
+
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
384
|
+
MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
|
385
|
+
cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
|
386
|
+
}
|
387
|
+
|
388
|
+
|
389
|
+
/*
|
390
|
+
* Master selection of decompression modules.
|
391
|
+
* This is done once at jpeg_start_decompress time. We determine
|
392
|
+
* which modules will be used and give them appropriate initialization calls.
|
393
|
+
* We also initialize the decompressor input side to begin consuming data.
|
394
|
+
*
|
395
|
+
* Since jpeg_read_header has finished, we know what is in the SOF
|
396
|
+
* and (first) SOS markers. We also have all the application parameter
|
397
|
+
* settings.
|
398
|
+
*/
|
399
|
+
|
400
|
+
LOCAL(void)
|
401
|
+
master_selection (j_decompress_ptr cinfo)
|
402
|
+
{
|
403
|
+
my_master_ptr master = (my_master_ptr) cinfo->master;
|
404
|
+
boolean use_c_buffer;
|
405
|
+
long samplesperrow;
|
406
|
+
JDIMENSION jd_samplesperrow;
|
407
|
+
|
408
|
+
/* Initialize dimensions and other stuff */
|
409
|
+
jpeg_calc_output_dimensions(cinfo);
|
410
|
+
prepare_range_limit_table(cinfo);
|
411
|
+
|
412
|
+
/* Width of an output scanline must be representable as JDIMENSION. */
|
413
|
+
samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
|
414
|
+
jd_samplesperrow = (JDIMENSION) samplesperrow;
|
415
|
+
if ((long) jd_samplesperrow != samplesperrow)
|
416
|
+
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
417
|
+
|
418
|
+
/* Initialize my private state */
|
419
|
+
master->pass_number = 0;
|
420
|
+
master->using_merged_upsample = use_merged_upsample(cinfo);
|
421
|
+
|
422
|
+
/* Color quantizer selection */
|
423
|
+
master->quantizer_1pass = NULL;
|
424
|
+
master->quantizer_2pass = NULL;
|
425
|
+
/* No mode changes if not using buffered-image mode. */
|
426
|
+
if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
|
427
|
+
cinfo->enable_1pass_quant = FALSE;
|
428
|
+
cinfo->enable_external_quant = FALSE;
|
429
|
+
cinfo->enable_2pass_quant = FALSE;
|
430
|
+
}
|
431
|
+
if (cinfo->quantize_colors) {
|
432
|
+
if (cinfo->raw_data_out)
|
433
|
+
ERREXIT(cinfo, JERR_NOTIMPL);
|
434
|
+
/* 2-pass quantizer only works in 3-component color space. */
|
435
|
+
if (cinfo->out_color_components != 3) {
|
436
|
+
cinfo->enable_1pass_quant = TRUE;
|
437
|
+
cinfo->enable_external_quant = FALSE;
|
438
|
+
cinfo->enable_2pass_quant = FALSE;
|
439
|
+
cinfo->colormap = NULL;
|
440
|
+
} else if (cinfo->colormap != NULL) {
|
441
|
+
cinfo->enable_external_quant = TRUE;
|
442
|
+
} else if (cinfo->two_pass_quantize) {
|
443
|
+
cinfo->enable_2pass_quant = TRUE;
|
444
|
+
} else {
|
445
|
+
cinfo->enable_1pass_quant = TRUE;
|
446
|
+
}
|
447
|
+
|
448
|
+
if (cinfo->enable_1pass_quant) {
|
449
|
+
#ifdef QUANT_1PASS_SUPPORTED
|
450
|
+
jinit_1pass_quantizer(cinfo);
|
451
|
+
master->quantizer_1pass = cinfo->cquantize;
|
452
|
+
#else
|
453
|
+
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
454
|
+
#endif
|
455
|
+
}
|
456
|
+
|
457
|
+
/* We use the 2-pass code to map to external colormaps. */
|
458
|
+
if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
|
459
|
+
#ifdef QUANT_2PASS_SUPPORTED
|
460
|
+
jinit_2pass_quantizer(cinfo);
|
461
|
+
master->quantizer_2pass = cinfo->cquantize;
|
462
|
+
#else
|
463
|
+
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
464
|
+
#endif
|
465
|
+
}
|
466
|
+
/* If both quantizers are initialized, the 2-pass one is left active;
|
467
|
+
* this is necessary for starting with quantization to an external map.
|
468
|
+
*/
|
469
|
+
}
|
470
|
+
|
471
|
+
/* Post-processing: in particular, color conversion first */
|
472
|
+
if (! cinfo->raw_data_out) {
|
473
|
+
if (master->using_merged_upsample) {
|
474
|
+
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
475
|
+
jinit_merged_upsampler(cinfo); /* does color conversion too */
|
476
|
+
#else
|
477
|
+
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
478
|
+
#endif
|
479
|
+
} else {
|
480
|
+
jinit_color_deconverter(cinfo);
|
481
|
+
jinit_upsampler(cinfo);
|
482
|
+
}
|
483
|
+
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
|
484
|
+
}
|
485
|
+
/* Inverse DCT */
|
486
|
+
jinit_inverse_dct(cinfo);
|
487
|
+
/* Entropy decoding: either Huffman or arithmetic coding. */
|
488
|
+
if (cinfo->arith_code) {
|
489
|
+
jinit_arith_decoder(cinfo);
|
490
|
+
} else {
|
491
|
+
jinit_huff_decoder(cinfo);
|
492
|
+
}
|
493
|
+
|
494
|
+
/* Initialize principal buffer controllers. */
|
495
|
+
use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
|
496
|
+
jinit_d_coef_controller(cinfo, use_c_buffer);
|
497
|
+
|
498
|
+
if (! cinfo->raw_data_out)
|
499
|
+
jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
|
500
|
+
|
501
|
+
/* We can now tell the memory manager to allocate virtual arrays. */
|
502
|
+
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
|
503
|
+
|
504
|
+
/* Initialize input side of decompressor to consume first scan. */
|
505
|
+
(*cinfo->inputctl->start_input_pass) (cinfo);
|
506
|
+
|
507
|
+
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
508
|
+
/* If jpeg_start_decompress will read the whole file, initialize
|
509
|
+
* progress monitoring appropriately. The input step is counted
|
510
|
+
* as one pass.
|
511
|
+
*/
|
512
|
+
if (cinfo->progress != NULL && ! cinfo->buffered_image &&
|
513
|
+
cinfo->inputctl->has_multiple_scans) {
|
514
|
+
int nscans;
|
515
|
+
/* Estimate number of scans to set pass_limit. */
|
516
|
+
if (cinfo->progressive_mode) {
|
517
|
+
/* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
|
518
|
+
nscans = 2 + 3 * cinfo->num_components;
|
519
|
+
} else {
|
520
|
+
/* For a nonprogressive multiscan file, estimate 1 scan per component. */
|
521
|
+
nscans = cinfo->num_components;
|
522
|
+
}
|
523
|
+
cinfo->progress->pass_counter = 0L;
|
524
|
+
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
|
525
|
+
cinfo->progress->completed_passes = 0;
|
526
|
+
cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
|
527
|
+
/* Count the input pass as done */
|
528
|
+
master->pass_number++;
|
529
|
+
}
|
530
|
+
#endif /* D_MULTISCAN_FILES_SUPPORTED */
|
531
|
+
}
|
532
|
+
|
533
|
+
|
534
|
+
/*
|
535
|
+
* Per-pass setup.
|
536
|
+
* This is called at the beginning of each output pass. We determine which
|
537
|
+
* modules will be active during this pass and give them appropriate
|
538
|
+
* start_pass calls. We also set is_dummy_pass to indicate whether this
|
539
|
+
* is a "real" output pass or a dummy pass for color quantization.
|
540
|
+
* (In the latter case, jdapistd.c will crank the pass to completion.)
|
541
|
+
*/
|
542
|
+
|
543
|
+
METHODDEF(void)
|
544
|
+
prepare_for_output_pass (j_decompress_ptr cinfo)
|
545
|
+
{
|
546
|
+
my_master_ptr master = (my_master_ptr) cinfo->master;
|
547
|
+
|
548
|
+
if (master->pub.is_dummy_pass) {
|
549
|
+
#ifdef QUANT_2PASS_SUPPORTED
|
550
|
+
/* Final pass of 2-pass quantization */
|
551
|
+
master->pub.is_dummy_pass = FALSE;
|
552
|
+
(*cinfo->cquantize->start_pass) (cinfo, FALSE);
|
553
|
+
(*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
|
554
|
+
(*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
|
555
|
+
#else
|
556
|
+
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
557
|
+
#endif /* QUANT_2PASS_SUPPORTED */
|
558
|
+
} else {
|
559
|
+
if (cinfo->quantize_colors && cinfo->colormap == NULL) {
|
560
|
+
/* Select new quantization method */
|
561
|
+
if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
|
562
|
+
cinfo->cquantize = master->quantizer_2pass;
|
563
|
+
master->pub.is_dummy_pass = TRUE;
|
564
|
+
} else if (cinfo->enable_1pass_quant) {
|
565
|
+
cinfo->cquantize = master->quantizer_1pass;
|
566
|
+
} else {
|
567
|
+
ERREXIT(cinfo, JERR_MODE_CHANGE);
|
568
|
+
}
|
569
|
+
}
|
570
|
+
(*cinfo->idct->start_pass) (cinfo);
|
571
|
+
(*cinfo->coef->start_output_pass) (cinfo);
|
572
|
+
if (! cinfo->raw_data_out) {
|
573
|
+
if (! master->using_merged_upsample)
|
574
|
+
(*cinfo->cconvert->start_pass) (cinfo);
|
575
|
+
(*cinfo->upsample->start_pass) (cinfo);
|
576
|
+
if (cinfo->quantize_colors)
|
577
|
+
(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
|
578
|
+
(*cinfo->post->start_pass) (cinfo,
|
579
|
+
(master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
|
580
|
+
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
|
581
|
+
}
|
582
|
+
}
|
583
|
+
|
584
|
+
/* Set up progress monitor's pass info if present */
|
585
|
+
if (cinfo->progress != NULL) {
|
586
|
+
cinfo->progress->completed_passes = master->pass_number;
|
587
|
+
cinfo->progress->total_passes = master->pass_number +
|
588
|
+
(master->pub.is_dummy_pass ? 2 : 1);
|
589
|
+
/* In buffered-image mode, we assume one more output pass if EOI not
|
590
|
+
* yet reached, but no more passes if EOI has been reached.
|
591
|
+
*/
|
592
|
+
if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
|
593
|
+
cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
}
|
597
|
+
|
598
|
+
|
599
|
+
/*
|
600
|
+
* Finish up at end of an output pass.
|
601
|
+
*/
|
602
|
+
|
603
|
+
METHODDEF(void)
|
604
|
+
finish_output_pass (j_decompress_ptr cinfo)
|
605
|
+
{
|
606
|
+
my_master_ptr master = (my_master_ptr) cinfo->master;
|
607
|
+
|
608
|
+
if (cinfo->quantize_colors)
|
609
|
+
(*cinfo->cquantize->finish_pass) (cinfo);
|
610
|
+
master->pass_number++;
|
611
|
+
}
|
612
|
+
|
613
|
+
|
614
|
+
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
615
|
+
|
616
|
+
/*
|
617
|
+
* Switch to a new external colormap between output passes.
|
618
|
+
*/
|
619
|
+
|
620
|
+
GLOBAL(void)
|
621
|
+
jpeg_new_colormap (j_decompress_ptr cinfo)
|
622
|
+
{
|
623
|
+
my_master_ptr master = (my_master_ptr) cinfo->master;
|
624
|
+
|
625
|
+
/* Prevent application from calling me at wrong times */
|
626
|
+
if (cinfo->global_state != DSTATE_BUFIMAGE)
|
627
|
+
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
628
|
+
|
629
|
+
if (cinfo->quantize_colors && cinfo->enable_external_quant &&
|
630
|
+
cinfo->colormap != NULL) {
|
631
|
+
/* Select 2-pass quantizer for external colormap use */
|
632
|
+
cinfo->cquantize = master->quantizer_2pass;
|
633
|
+
/* Notify quantizer of colormap change */
|
634
|
+
(*cinfo->cquantize->new_color_map) (cinfo);
|
635
|
+
master->pub.is_dummy_pass = FALSE; /* just in case */
|
636
|
+
} else
|
637
|
+
ERREXIT(cinfo, JERR_MODE_CHANGE);
|
638
|
+
}
|
639
|
+
|
640
|
+
#endif /* D_MULTISCAN_FILES_SUPPORTED */
|
641
|
+
|
642
|
+
|
643
|
+
/*
|
644
|
+
* Initialize master decompression control and select active modules.
|
645
|
+
* This is performed at the start of jpeg_start_decompress.
|
646
|
+
*/
|
647
|
+
|
648
|
+
GLOBAL(void)
|
649
|
+
jinit_master_decompress (j_decompress_ptr cinfo)
|
650
|
+
{
|
651
|
+
my_master_ptr master;
|
652
|
+
|
653
|
+
master = (my_master_ptr)
|
654
|
+
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
655
|
+
SIZEOF(my_decomp_master));
|
656
|
+
cinfo->master = (struct jpeg_decomp_master *) master;
|
657
|
+
master->pub.prepare_for_output_pass = prepare_for_output_pass;
|
658
|
+
master->pub.finish_output_pass = finish_output_pass;
|
659
|
+
|
660
|
+
master->pub.is_dummy_pass = FALSE;
|
661
|
+
|
662
|
+
master_selection(cinfo);
|
663
|
+
}
|