ReactOS 0.4.15-dev-7958-gcd0bb1a
jcmaster.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
Include dependency graph for jcmaster.c:

Go to the source code of this file.

Classes

struct  my_comp_master
 

Macros

#define JPEG_INTERNALS
 

Typedefs

typedef my_comp_mastermy_master_ptr
 

Enumerations

enum  c_pass_type { main_pass , huff_opt_pass , output_pass }
 

Functions

 initial_setup (j_compress_ptr cinfo)
 
 select_scan_parameters (j_compress_ptr cinfo)
 
 per_scan_setup (j_compress_ptr cinfo)
 
 prepare_for_pass (j_compress_ptr cinfo)
 
 pass_startup (j_compress_ptr cinfo)
 
 finish_pass_master (j_compress_ptr cinfo)
 
 jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
 

Macro Definition Documentation

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 15 of file jcmaster.c.

Typedef Documentation

◆ my_master_ptr

Definition at line 39 of file jcmaster.c.

Enumeration Type Documentation

◆ c_pass_type

Enumerator
main_pass 
huff_opt_pass 
output_pass 

Definition at line 22 of file jcmaster.c.

22 {
23 main_pass, /* input data, also do first output step */
24 huff_opt_pass, /* Huffman code optimization pass */
25 output_pass /* data output pass */
c_pass_type
Definition: jcmaster.c:22
@ output_pass
Definition: jcmaster.c:25
@ huff_opt_pass
Definition: jcmaster.c:24
@ main_pass
Definition: jcmaster.c:23

Function Documentation

◆ finish_pass_master()

finish_pass_master ( j_compress_ptr  cinfo)

Definition at line 583 of file jcmaster.c.

584{
585 my_master_ptr master = (my_master_ptr) cinfo->master;
586
587 /* The entropy coder always needs an end-of-pass call,
588 * either to analyze statistics or to flush its output buffer.
589 */
590 (*cinfo->entropy->finish_pass) (cinfo);
591
592 /* Update state for next pass */
593 switch (master->pass_type) {
594 case main_pass:
595 /* next pass is either output of scan 0 (after optimization)
596 * or output of scan 1 (if no optimization).
597 */
598 master->pass_type = output_pass;
599 if (! cinfo->optimize_coding)
600 master->scan_number++;
601 break;
602 case huff_opt_pass:
603 /* next pass is always output of current scan */
604 master->pass_type = output_pass;
605 break;
606 case output_pass:
607 /* next pass is either optimization or output of next scan */
608 if (cinfo->optimize_coding)
609 master->pass_type = huff_opt_pass;
610 master->scan_number++;
611 break;
612 }
613
614 master->pass_number++;
615}
my_comp_master * my_master_ptr
Definition: jcmaster.c:39
boolean optimize_coding
Definition: jpeglib.h:359
struct jpeg_entropy_encoder * entropy
Definition: jpeglib.h:451
struct jpeg_comp_master * master
Definition: jpeglib.h:443
int pass_number
Definition: jcmaster.c:33
int scan_number
Definition: jcmaster.c:36
c_pass_type pass_type
Definition: jcmaster.c:31

Referenced by jinit_c_master_control().

◆ initial_setup()

initial_setup ( j_compress_ptr  cinfo)

Definition at line 47 of file jcmaster.c.

49{
50 int ci, ssize;
52
53 /* Sanity check on block_size */
54 if (cinfo->block_size < 1 || cinfo->block_size > 16)
55 ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size);
56
57 /* Derive natural_order from block_size */
58 switch (cinfo->block_size) {
59 case 2: cinfo->natural_order = jpeg_natural_order2; break;
60 case 3: cinfo->natural_order = jpeg_natural_order3; break;
61 case 4: cinfo->natural_order = jpeg_natural_order4; break;
62 case 5: cinfo->natural_order = jpeg_natural_order5; break;
63 case 6: cinfo->natural_order = jpeg_natural_order6; break;
64 case 7: cinfo->natural_order = jpeg_natural_order7; break;
65 default: cinfo->natural_order = jpeg_natural_order;
66 }
67
68 /* Derive lim_Se from block_size */
69 cinfo->lim_Se = cinfo->block_size < DCTSIZE ?
70 cinfo->block_size * cinfo->block_size - 1 : DCTSIZE2-1;
71
72 /* Sanity check on image dimensions */
73 if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||
74 cinfo->num_components <= 0)
75 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
76
77 /* Make sure image isn't bigger than I can handle */
78 if ((long) cinfo->jpeg_height > (long) JPEG_MAX_DIMENSION ||
79 (long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)
80 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
81
82 /* Only 8 to 12 bits data precision are supported for DCT based JPEG */
83 if (cinfo->data_precision < 8 || cinfo->data_precision > 12)
84 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
85
86 /* Check that number of components won't exceed internal array sizes */
87 if (cinfo->num_components > MAX_COMPONENTS)
88 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
90
91 /* Compute maximum sampling factors; check factor validity */
92 cinfo->max_h_samp_factor = 1;
93 cinfo->max_v_samp_factor = 1;
94 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
95 ci++, compptr++) {
98 ERREXIT(cinfo, JERR_BAD_SAMPLING);
103 }
104
105 /* Compute dimensions of components */
106 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
107 ci++, compptr++) {
108 /* Fill in the correct component_index value; don't rely on application */
110 /* In selecting the actual DCT scaling for each component, we try to
111 * scale down the chroma components via DCT scaling rather than downsampling.
112 * This saves time if the downsampler gets to use 1:1 scaling.
113 * Note this code adapts subsampling ratios which are powers of 2.
114 */
115 ssize = 1;
116#ifdef DCT_SCALING_SUPPORTED
117 if (! cinfo->raw_data_in)
118 while (cinfo->min_DCT_h_scaled_size * ssize <=
119 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
120 (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) ==
121 0) {
122 ssize = ssize * 2;
123 }
124#endif
126 ssize = 1;
127#ifdef DCT_SCALING_SUPPORTED
128 if (! cinfo->raw_data_in)
129 while (cinfo->min_DCT_v_scaled_size * ssize <=
130 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
131 (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) ==
132 0) {
133 ssize = ssize * 2;
134 }
135#endif
137
138 /* We don't support DCT ratios larger than 2. */
143
144 /* Size in DCT blocks */
147 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
150 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
151 /* Size in samples */
153 jdiv_round_up((long) cinfo->jpeg_width *
155 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
157 jdiv_round_up((long) cinfo->jpeg_height *
159 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
160 /* Don't need quantization scale after DCT,
161 * until color conversion says otherwise.
162 */
164 }
165
166 /* Compute number of fully interleaved MCU rows (number of times that
167 * main controller will call coefficient controller).
168 */
169 cinfo->total_iMCU_rows = (JDIMENSION)
170 jdiv_round_up((long) cinfo->jpeg_height,
171 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
172}
#define MAX(x, y)
Definition: rdesktop.h:175
#define FALSE
Definition: types.h:117
jpeg_component_info * compptr
Definition: jdct.h:238
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:216
#define JPEG_MAX_DIMENSION
Definition: jmorecfg.h:231
unsigned int JDIMENSION
Definition: jmorecfg.h:229
#define MAX_COMPONENTS
Definition: jmorecfg.h:45
#define DCTSIZE
Definition: jpeglib.h:50
#define MAX_SAMP_FACTOR
Definition: jpeglib.h:56
#define DCTSIZE2
Definition: jpeglib.h:51
jdiv_round_up(long a, long b)
Definition: jutils.c:124
const int jpeg_natural_order4[4 *4+16]
Definition: jutils.c:98
const int jpeg_natural_order[DCTSIZE2+16]
Definition: jutils.c:54
const int jpeg_natural_order2[2 *2+16]
Definition: jutils.c:112
const int jpeg_natural_order5[5 *5+16]
Definition: jutils.c:89
const int jpeg_natural_order7[7 *7+16]
Definition: jutils.c:67
const int jpeg_natural_order6[6 *6+16]
Definition: jutils.c:79
const int jpeg_natural_order3[3 *3+16]
Definition: jutils.c:105
#define long
Definition: qsort.c:33
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
JDIMENSION downsampled_height
Definition: jpeglib.h:165
JDIMENSION width_in_blocks
Definition: jpeglib.h:148
JDIMENSION height_in_blocks
Definition: jpeglib.h:149
boolean component_needed
Definition: jpeglib.h:174
JDIMENSION downsampled_width
Definition: jpeglib.h:164
const int * natural_order
Definition: jpeglib.h:437
jpeg_component_info * comp_info
Definition: jpeglib.h:333
boolean do_fancy_downsampling
Definition: jpeglib.h:361
boolean raw_data_in
Definition: jpeglib.h:357
JDIMENSION jpeg_width
Definition: jpeglib.h:319
JDIMENSION jpeg_height
Definition: jpeglib.h:320
JDIMENSION total_iMCU_rows
Definition: jpeglib.h:411

Referenced by jinit_c_master_control().

◆ jinit_c_master_control()

jinit_c_master_control ( j_compress_ptr  cinfo,
boolean  transcode_only 
)

Definition at line 623 of file jcmaster.c.

624{
625 my_master_ptr master;
626
627 master = (my_master_ptr) (*cinfo->mem->alloc_small)
629 cinfo->master = &master->pub;
630 master->pub.prepare_for_pass = prepare_for_pass;
631 master->pub.pass_startup = pass_startup;
632 master->pub.finish_pass = finish_pass_master;
633 master->pub.is_last_pass = FALSE;
634
635 /* Validate parameters, determine derived values */
636 initial_setup(cinfo);
637
638 if (cinfo->scan_info != NULL) {
639#ifdef C_MULTISCAN_FILES_SUPPORTED
640 validate_script(cinfo);
641 if (cinfo->block_size < DCTSIZE)
642 reduce_script(cinfo);
643#else
644 ERREXIT(cinfo, JERR_NOT_COMPILED);
645#endif
646 } else {
647 cinfo->progressive_mode = FALSE;
648 cinfo->num_scans = 1;
649 }
650
651 if (cinfo->optimize_coding)
652 cinfo->arith_code = FALSE; /* disable arithmetic coding */
653 else if (! cinfo->arith_code &&
654 (cinfo->progressive_mode ||
655 (cinfo->block_size > 1 && cinfo->block_size < DCTSIZE)))
656 /* TEMPORARY HACK ??? */
657 /* assume default tables no good for progressive or reduced AC mode */
658 cinfo->optimize_coding = TRUE; /* force Huffman optimization */
659
660 /* Initialize my private state */
661 if (transcode_only) {
662 /* no main pass in transcoding */
663 if (cinfo->optimize_coding)
664 master->pass_type = huff_opt_pass;
665 else
666 master->pass_type = output_pass;
667 } else {
668 /* for normal compression, first pass is always this type: */
669 master->pass_type = main_pass;
670 }
671 master->scan_number = 0;
672 master->pass_number = 0;
673 if (cinfo->optimize_coding)
674 master->total_passes = cinfo->num_scans * 2;
675 else
676 master->total_passes = cinfo->num_scans;
677}
#define SIZEOF(_ar)
Definition: calc.h:97
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
pass_startup(j_compress_ptr cinfo)
Definition: jcmaster.c:569
prepare_for_pass(j_compress_ptr cinfo)
Definition: jcmaster.c:481
finish_pass_master(j_compress_ptr cinfo)
Definition: jcmaster.c:583
initial_setup(j_compress_ptr cinfo)
Definition: jcmaster.c:47
boolean transcode_only
Definition: jpegint.h:382
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:284
#define JPOOL_IMAGE
Definition: jpeglib.h:808
const jpeg_scan_info * scan_info
Definition: jpeglib.h:351
boolean arith_code
Definition: jpeglib.h:358
boolean progressive_mode
Definition: jpeglib.h:404
struct jpeg_comp_master pub
Definition: jcmaster.c:29
int total_passes
Definition: jcmaster.c:34

Referenced by jinit_compress_master(), and transencode_master_selection().

◆ pass_startup()

pass_startup ( j_compress_ptr  cinfo)

Definition at line 569 of file jcmaster.c.

570{
571 cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
572
573 (*cinfo->marker->write_frame_header) (cinfo);
574 (*cinfo->marker->write_scan_header) (cinfo);
575}
struct jpeg_marker_writer * marker
Definition: jpeglib.h:447

Referenced by jinit_c_master_control().

◆ per_scan_setup()

per_scan_setup ( j_compress_ptr  cinfo)

Definition at line 388 of file jcmaster.c.

391{
392 int ci, mcublks, tmp;
394
395 if (cinfo->comps_in_scan == 1) {
396
397 /* Noninterleaved (single-component) scan */
398 compptr = cinfo->cur_comp_info[0];
399
400 /* Overall image size in MCUs */
403
404 /* For noninterleaved scan, always one block per MCU */
405 compptr->MCU_width = 1;
406 compptr->MCU_height = 1;
407 compptr->MCU_blocks = 1;
410 /* For noninterleaved scans, it is convenient to define last_row_height
411 * as the number of block rows present in the last iMCU row.
412 */
414 if (tmp == 0) tmp = compptr->v_samp_factor;
416
417 /* Prepare array describing MCU composition */
418 cinfo->blocks_in_MCU = 1;
419 cinfo->MCU_membership[0] = 0;
420
421 } else {
422
423 /* Interleaved (multi-component) scan */
424 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
425 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
427
428 /* Overall image size in MCUs */
429 cinfo->MCUs_per_row = (JDIMENSION)
430 jdiv_round_up((long) cinfo->jpeg_width,
431 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
433 jdiv_round_up((long) cinfo->jpeg_height,
434 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
435
436 cinfo->blocks_in_MCU = 0;
437
438 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
439 compptr = cinfo->cur_comp_info[ci];
440 /* Sampling factors give # of blocks of component in each MCU */
445 /* Figure number of non-dummy blocks in last MCU column & row */
447 if (tmp == 0) tmp = compptr->MCU_width;
448 compptr->last_col_width = tmp;
450 if (tmp == 0) tmp = compptr->MCU_height;
452 /* Prepare array describing MCU composition */
453 mcublks = compptr->MCU_blocks;
454 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
455 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
456 while (mcublks-- > 0) {
457 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
458 }
459 }
460
461 }
462
463 /* Convert restart specified in rows to actual MCU count. */
464 /* Note that count must fit in 16 bits, so we provide limiting. */
465 if (cinfo->restart_in_rows > 0) {
466 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
467 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
468 }
469}
#define MIN(x, y)
Definition: rdesktop.h:171
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define C_MAX_BLOCKS_IN_MCU
Definition: jpeglib.h:64
#define MAX_COMPS_IN_SCAN
Definition: jpeglib.h:55
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
Definition: jpeglib.h:423
unsigned int restart_interval
Definition: jpeglib.h:370
int MCU_membership[C_MAX_BLOCKS_IN_MCU]
Definition: jpeglib.h:430
JDIMENSION MCUs_per_row
Definition: jpeglib.h:426
JDIMENSION MCU_rows_in_scan
Definition: jpeglib.h:427

Referenced by prepare_for_pass().

◆ prepare_for_pass()

prepare_for_pass ( j_compress_ptr  cinfo)

Definition at line 481 of file jcmaster.c.

482{
483 my_master_ptr master = (my_master_ptr) cinfo->master;
484
485 switch (master->pass_type) {
486 case main_pass:
487 /* Initial pass: will collect input data, and do either Huffman
488 * optimization or data output for the first scan.
489 */
491 per_scan_setup(cinfo);
492 if (! cinfo->raw_data_in) {
493 (*cinfo->cconvert->start_pass) (cinfo);
494 (*cinfo->downsample->start_pass) (cinfo);
495 (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
496 }
497 (*cinfo->fdct->start_pass) (cinfo);
498 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
499 (*cinfo->coef->start_pass) (cinfo,
500 (master->total_passes > 1 ?
502 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
503 if (cinfo->optimize_coding) {
504 /* No immediate data output; postpone writing frame/scan headers */
505 master->pub.call_pass_startup = FALSE;
506 } else {
507 /* Will write frame/scan headers at first jpeg_write_scanlines call */
508 master->pub.call_pass_startup = TRUE;
509 }
510 break;
511#ifdef ENTROPY_OPT_SUPPORTED
512 case huff_opt_pass:
513 /* Do Huffman optimization for a scan after the first one. */
515 per_scan_setup(cinfo);
516 if (cinfo->Ss != 0 || cinfo->Ah == 0) {
517 (*cinfo->entropy->start_pass) (cinfo, TRUE);
518 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
519 master->pub.call_pass_startup = FALSE;
520 break;
521 }
522 /* Special case: Huffman DC refinement scans need no Huffman table
523 * and therefore we can skip the optimization pass for them.
524 */
525 master->pass_type = output_pass;
526 master->pass_number++;
527 /*FALLTHROUGH*/
528#endif
529 case output_pass:
530 /* Do a data-output pass. */
531 /* We need not repeat per-scan setup if prior optimization pass did it. */
532 if (! cinfo->optimize_coding) {
534 per_scan_setup(cinfo);
535 }
536 (*cinfo->entropy->start_pass) (cinfo, FALSE);
537 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
538 /* We emit frame/scan headers now */
539 if (master->scan_number == 0)
540 (*cinfo->marker->write_frame_header) (cinfo);
541 (*cinfo->marker->write_scan_header) (cinfo);
542 master->pub.call_pass_startup = FALSE;
543 break;
544 default:
545 ERREXIT(cinfo, JERR_NOT_COMPILED);
546 }
547
548 master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
549
550 /* Set up progress monitor's pass info if present */
551 if (cinfo->progress != NULL) {
552 cinfo->progress->completed_passes = master->pass_number;
553 cinfo->progress->total_passes = master->total_passes;
554 }
555}
switch(r->id)
Definition: btrfs.c:3046
per_scan_setup(j_compress_ptr cinfo)
Definition: jcmaster.c:388
select_scan_parameters(j_compress_ptr cinfo)
Definition: jcmaster.c:344
@ JBUF_PASS_THRU
Definition: jpegint.h:18
@ JBUF_SAVE_AND_PASS
Definition: jpegint.h:22
@ JBUF_CRANK_DEST
Definition: jpegint.h:21
struct jpeg_downsampler * downsample
Definition: jpeglib.h:449
struct jpeg_c_prep_controller * prep
Definition: jpeglib.h:445
struct jpeg_color_converter * cconvert
Definition: jpeglib.h:448
struct jpeg_c_main_controller * main
Definition: jpeglib.h:444
struct jpeg_forward_dct * fdct
Definition: jpeglib.h:450
struct jpeg_c_coef_controller * coef
Definition: jpeglib.h:446

Referenced by jinit_c_master_control().

◆ select_scan_parameters()

select_scan_parameters ( j_compress_ptr  cinfo)

Definition at line 344 of file jcmaster.c.

346{
347 int ci;
348
349#ifdef C_MULTISCAN_FILES_SUPPORTED
350 if (cinfo->scan_info != NULL) {
351 /* Prepare for current scan --- the script is already validated */
352 my_master_ptr master = (my_master_ptr) cinfo->master;
353 const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
354
355 cinfo->comps_in_scan = scanptr->comps_in_scan;
356 for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
357 cinfo->cur_comp_info[ci] =
358 &cinfo->comp_info[scanptr->component_index[ci]];
359 }
360 if (cinfo->progressive_mode) {
361 cinfo->Ss = scanptr->Ss;
362 cinfo->Se = scanptr->Se;
363 cinfo->Ah = scanptr->Ah;
364 cinfo->Al = scanptr->Al;
365 return;
366 }
367 }
368 else
369#endif
370 {
371 /* Prepare for single sequential-JPEG scan containing all components */
373 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
375 cinfo->comps_in_scan = cinfo->num_components;
376 for (ci = 0; ci < cinfo->num_components; ci++) {
377 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
378 }
379 }
380 cinfo->Ss = 0;
381 cinfo->Se = cinfo->block_size * cinfo->block_size - 1;
382 cinfo->Ah = 0;
383 cinfo->Al = 0;
384}
#define for
Definition: utility.h:88

Referenced by prepare_for_pass().