Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jcmaster.c |
| 3 | * |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 4 | * Copyright (C) 1991, 1992, Thomas G. Lane. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 5 | * This file is part of the Independent JPEG Group's software. |
| 6 | * For conditions of distribution and use, see the accompanying README file. |
| 7 | * |
| 8 | * This file contains the main control for the JPEG compressor. |
| 9 | * The system-dependent (user interface) code should call jpeg_compress() |
| 10 | * after doing appropriate setup of the compress_info_struct parameter. |
| 11 | */ |
| 12 | |
| 13 | #include "jinclude.h" |
| 14 | |
| 15 | |
| 16 | METHODDEF void |
| 17 | c_per_scan_method_selection (compress_info_ptr cinfo) |
| 18 | /* Central point for per-scan method selection */ |
| 19 | { |
| 20 | /* Edge expansion */ |
| 21 | jselexpand(cinfo); |
| 22 | /* Subsampling of pixels */ |
| 23 | jselsubsample(cinfo); |
| 24 | /* MCU extraction */ |
| 25 | jselcmcu(cinfo); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | LOCAL void |
| 30 | c_initial_method_selection (compress_info_ptr cinfo) |
| 31 | /* Central point for initial method selection */ |
| 32 | { |
| 33 | /* Input image reading method selection is already done. */ |
| 34 | /* So is output file header formatting (both are done by user interface). */ |
| 35 | |
| 36 | /* Gamma and color space conversion */ |
| 37 | jselccolor(cinfo); |
| 38 | /* Entropy encoding: either Huffman or arithmetic coding. */ |
| 39 | #ifdef ARITH_CODING_SUPPORTED |
| 40 | jselcarithmetic(cinfo); |
| 41 | #else |
| 42 | cinfo->arith_code = FALSE; /* force Huffman mode */ |
| 43 | #endif |
| 44 | jselchuffman(cinfo); |
| 45 | /* Pipeline control */ |
| 46 | jselcpipeline(cinfo); |
| 47 | /* Overall control (that's me!) */ |
| 48 | cinfo->methods->c_per_scan_method_selection = c_per_scan_method_selection; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | LOCAL void |
| 53 | initial_setup (compress_info_ptr cinfo) |
| 54 | /* Do computations that are needed before initial method selection */ |
| 55 | { |
| 56 | short ci; |
| 57 | jpeg_component_info *compptr; |
| 58 | |
| 59 | /* Compute maximum sampling factors; check factor validity */ |
| 60 | cinfo->max_h_samp_factor = 1; |
| 61 | cinfo->max_v_samp_factor = 1; |
| 62 | for (ci = 0; ci < cinfo->num_components; ci++) { |
| 63 | compptr = &cinfo->comp_info[ci]; |
| 64 | if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || |
| 65 | compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) |
| 66 | ERREXIT(cinfo->emethods, "Bogus sampling factors"); |
| 67 | cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, |
| 68 | compptr->h_samp_factor); |
| 69 | cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, |
| 70 | compptr->v_samp_factor); |
| 71 | |
| 72 | } |
| 73 | |
| 74 | /* Compute logical subsampled dimensions of components */ |
| 75 | for (ci = 0; ci < cinfo->num_components; ci++) { |
| 76 | compptr = &cinfo->comp_info[ci]; |
| 77 | compptr->true_comp_width = (cinfo->image_width * compptr->h_samp_factor |
| 78 | + cinfo->max_h_samp_factor - 1) |
| 79 | / cinfo->max_h_samp_factor; |
| 80 | compptr->true_comp_height = (cinfo->image_height * compptr->v_samp_factor |
| 81 | + cinfo->max_v_samp_factor - 1) |
| 82 | / cinfo->max_v_samp_factor; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * This is the main entry point to the JPEG compressor. |
| 89 | */ |
| 90 | |
| 91 | |
| 92 | GLOBAL void |
| 93 | jpeg_compress (compress_info_ptr cinfo) |
| 94 | { |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 95 | /* Init pass counts to 0 --- total_passes is adjusted in method selection */ |
| 96 | cinfo->total_passes = 0; |
| 97 | cinfo->completed_passes = 0; |
| 98 | |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 99 | /* Read the input file header: determine image size & component count. |
| 100 | * NOTE: the user interface must have initialized the input_init method |
| 101 | * pointer (eg, by calling jselrppm) before calling me. |
| 102 | * The other file reading methods (get_input_row etc.) were probably |
| 103 | * set at the same time, but could be set up by input_init itself, |
| 104 | * or by c_ui_method_selection. |
| 105 | */ |
| 106 | (*cinfo->methods->input_init) (cinfo); |
| 107 | |
| 108 | /* Give UI a chance to adjust compression parameters and select */ |
| 109 | /* output file format based on results of input_init. */ |
| 110 | (*cinfo->methods->c_ui_method_selection) (cinfo); |
| 111 | |
| 112 | /* Now select methods for compression steps. */ |
| 113 | initial_setup(cinfo); |
| 114 | c_initial_method_selection(cinfo); |
| 115 | |
| 116 | /* Initialize the output file & other modules as needed */ |
| 117 | /* (entropy_encoder is inited by pipeline controller) */ |
| 118 | |
| 119 | (*cinfo->methods->colorin_init) (cinfo); |
| 120 | (*cinfo->methods->write_file_header) (cinfo); |
| 121 | |
| 122 | /* And let the pipeline controller do the rest. */ |
| 123 | (*cinfo->methods->c_pipeline_controller) (cinfo); |
| 124 | |
| 125 | /* Finish output file, release working storage, etc */ |
| 126 | (*cinfo->methods->write_file_trailer) (cinfo); |
| 127 | (*cinfo->methods->colorin_term) (cinfo); |
| 128 | (*cinfo->methods->input_term) (cinfo); |
| 129 | |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 130 | (*cinfo->emethods->free_all) (); |
| 131 | |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 132 | /* My, that was easy, wasn't it? */ |
| 133 | } |