ReactOS 0.4.16-dev-2613-g9533ad7
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 581 of file jcmaster.c.

582{
583 my_master_ptr master = (my_master_ptr) cinfo->master;
584
585 /* The entropy coder always needs an end-of-pass call,
586 * either to analyze statistics or to flush its output buffer.
587 */
588 (*cinfo->entropy->finish_pass) (cinfo);
589
590 /* Update state for next pass */
591 switch (master->pass_type) {
592 case main_pass:
593 /* next pass is either output of scan 0 (after optimization)
594 * or output of scan 1 (if no optimization).
595 */
596 master->pass_type = output_pass;
597 if (! cinfo->optimize_coding)
598 master->scan_number++;
599 break;
600 case huff_opt_pass:
601 /* next pass is always output of current scan */
602 master->pass_type = output_pass;
603 break;
604 case output_pass:
605 /* next pass is either optimization or output of next scan */
606 if (cinfo->optimize_coding)
607 master->pass_type = huff_opt_pass;
608 master->scan_number++;
609 break;
610 }
611
612 master->pass_number++;
613}
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:452
struct jpeg_comp_master * master
Definition: jpeglib.h:444
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:252
#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:267
unsigned int JDIMENSION
Definition: jmorecfg.h:265
#define MAX_COMPONENTS
Definition: jmorecfg.h:81
#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:438
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:412

Referenced by jinit_c_master_control().

◆ jinit_c_master_control()

jinit_c_master_control ( j_compress_ptr  cinfo,
boolean  transcode_only 
)

Definition at line 621 of file jcmaster.c.

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

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

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));
432 cinfo->MCU_rows_in_scan = cinfo->total_iMCU_rows;
433
434 cinfo->blocks_in_MCU = 0;
435
436 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
437 compptr = cinfo->cur_comp_info[ci];
438 /* Sampling factors give # of blocks of component in each MCU */
443 /* Figure number of non-dummy blocks in last MCU column & row */
445 if (tmp == 0) tmp = compptr->MCU_width;
446 compptr->last_col_width = tmp;
448 if (tmp == 0) tmp = compptr->MCU_height;
450 /* Prepare array describing MCU composition */
451 mcublks = compptr->MCU_blocks;
452 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
453 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
454 while (mcublks-- > 0) {
455 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
456 }
457 }
458
459 }
460
461 /* Convert restart specified in rows to actual MCU count. */
462 /* Note that count must fit in 16 bits, so we provide limiting. */
463 if (cinfo->restart_in_rows > 0) {
464 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
465 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
466 }
467}
#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:424
unsigned int restart_interval
Definition: jpeglib.h:370
int MCU_membership[C_MAX_BLOCKS_IN_MCU]
Definition: jpeglib.h:431
JDIMENSION MCUs_per_row
Definition: jpeglib.h:427
JDIMENSION MCU_rows_in_scan
Definition: jpeglib.h:428

Referenced by prepare_for_pass().

◆ prepare_for_pass()

prepare_for_pass ( j_compress_ptr  cinfo)

Definition at line 479 of file jcmaster.c.

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

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}
for(i=0;i< ARRAY_SIZE(offsets);i++)

Referenced by prepare_for_pass().