jcinit.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * jcinit.c
  3. *
  4. * Copyright (C) 1991-1997, Thomas G. Lane.
  5. * This file is part of the Independent JPEG Group's software.
  6. * mozjpeg Modifications:
  7. * Copyright (C) 2014, Mozilla Corporation.
  8. * For conditions of distribution and use, see the accompanying README file.
  9. *
  10. * This file contains initialization logic for the JPEG compressor.
  11. * This routine is in charge of selecting the modules to be executed and
  12. * making an initialization call to each one.
  13. *
  14. * Logically, this code belongs in jcmaster.c. It's split out because
  15. * linking this routine implies linking the entire compression library.
  16. * For a transcoding-only application, we want to be able to use jcmaster.c
  17. * without linking in the whole library.
  18. */
  19. #define JPEG_INTERNALS
  20. #include "jinclude.h"
  21. #include "jpeglib.h"
  22. /*
  23. * Master selection of compression modules.
  24. * This is done once at the start of processing an image. We determine
  25. * which modules will be used and give them appropriate initialization calls.
  26. */
  27. GLOBAL(void)
  28. jinit_compress_master (j_compress_ptr cinfo)
  29. {
  30. /* Initialize master control (includes parameter checking/processing) */
  31. jinit_c_master_control(cinfo, FALSE /* full compression */);
  32. /* Preprocessing */
  33. if (! cinfo->raw_data_in) {
  34. jinit_color_converter(cinfo);
  35. jinit_downsampler(cinfo);
  36. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  37. }
  38. /* Forward DCT */
  39. jinit_forward_dct(cinfo);
  40. /* Entropy encoding: either Huffman or arithmetic coding. */
  41. if (cinfo->arith_code) {
  42. #ifdef C_ARITH_CODING_SUPPORTED
  43. jinit_arith_encoder(cinfo);
  44. #else
  45. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  46. #endif
  47. } else {
  48. if (cinfo->progressive_mode) {
  49. #ifdef C_PROGRESSIVE_SUPPORTED
  50. jinit_phuff_encoder(cinfo);
  51. #else
  52. ERREXIT(cinfo, JERR_NOT_COMPILED);
  53. #endif
  54. } else
  55. jinit_huff_encoder(cinfo);
  56. }
  57. /* Need a full-image coefficient buffer in any multi-pass mode. */
  58. jinit_c_coef_controller(cinfo,
  59. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding ||
  60. cinfo->master->optimize_scans || cinfo->master->trellis_quant));
  61. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  62. jinit_marker_writer(cinfo);
  63. /* We can now tell the memory manager to allocate virtual arrays. */
  64. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  65. /* Write the datastream header (SOI) immediately.
  66. * Frame and scan headers are postponed till later.
  67. * This lets application insert special markers after the SOI.
  68. */
  69. (*cinfo->marker->write_file_header) (cinfo);
  70. }