jdcoefct.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * jdcoefct.h
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1994-1997, Thomas G. Lane.
  6. * libjpeg-turbo Modifications:
  7. * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  8. * Copyright (C) 2020, Google, Inc.
  9. * For conditions of distribution and use, see the accompanying README.ijg
  10. * file.
  11. */
  12. #define JPEG_INTERNALS
  13. #include "jpeglib.h"
  14. /* Block smoothing is only applicable for progressive JPEG, so: */
  15. #ifndef D_PROGRESSIVE_SUPPORTED
  16. #undef BLOCK_SMOOTHING_SUPPORTED
  17. #endif
  18. /* Private buffer controller object */
  19. typedef struct {
  20. struct jpeg_d_coef_controller pub; /* public fields */
  21. /* These variables keep track of the current location of the input side. */
  22. /* cinfo->input_iMCU_row is also used for this. */
  23. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  24. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  25. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  26. /* The output side's location is represented by cinfo->output_iMCU_row. */
  27. /* In single-pass modes, it's sufficient to buffer just one MCU.
  28. * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
  29. * and let the entropy decoder write into that workspace each time.
  30. * In multi-pass modes, this array points to the current MCU's blocks
  31. * within the virtual arrays; it is used only by the input side.
  32. */
  33. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  34. /* Temporary workspace for one MCU */
  35. JCOEF *workspace;
  36. #ifdef D_MULTISCAN_FILES_SUPPORTED
  37. /* In multi-pass modes, we need a virtual block array for each component. */
  38. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  39. #endif
  40. #ifdef BLOCK_SMOOTHING_SUPPORTED
  41. /* When doing block smoothing, we latch coefficient Al values here */
  42. int *coef_bits_latch;
  43. #define SAVED_COEFS 10 /* we save coef_bits[0..9] */
  44. #endif
  45. } my_coef_controller;
  46. typedef my_coef_controller *my_coef_ptr;
  47. LOCAL(void)
  48. start_iMCU_row(j_decompress_ptr cinfo)
  49. /* Reset within-iMCU-row counters for a new row (input side) */
  50. {
  51. my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
  52. /* In an interleaved scan, an MCU row is the same as an iMCU row.
  53. * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
  54. * But at the bottom of the image, process only what's left.
  55. */
  56. if (cinfo->comps_in_scan > 1) {
  57. coef->MCU_rows_per_iMCU_row = 1;
  58. } else {
  59. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows - 1))
  60. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  61. else
  62. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  63. }
  64. coef->MCU_ctr = 0;
  65. coef->MCU_vert_offset = 0;
  66. }