jcinit.c 2.5 KB

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