jcinit.c 2.4 KB

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