4 * This file was part of the Independent JPEG Group's software:
5 * Copyright (C) 1994-1996, Thomas G. Lane.
6 * libjpeg-turbo Modifications:
7 * Copyright (C) 2022, D. R. Commander.
8 * For conditions of distribution and use, see the accompanying README.ijg
12 #define JPEG_INTERNALS
14 #include "jpegapicomp.h"
15 #include "jsamplecomp.h"
18 #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
20 /* Private buffer controller object */
23 struct jpeg_d_main_controller pub; /* public fields */
25 /* Pointer to allocated workspace (M or M+2 row groups). */
26 _JSAMPARRAY buffer[MAX_COMPONENTS];
28 boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
29 JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
31 /* Remaining fields are only used in the context case. */
33 /* These are the master pointers to the funny-order pointer lists. */
34 _JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
36 int whichptr; /* indicates which pointer set is now in use */
37 int context_state; /* process_data state machine status */
38 JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
39 JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
42 typedef my_main_controller *my_main_ptr;
45 /* context_state values: */
46 #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
47 #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
48 #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
52 set_wraparound_pointers(j_decompress_ptr cinfo)
53 /* Set up the "wraparound" pointers at top and bottom of the pointer lists.
54 * This changes the pointer list state from top-of-image to the normal state.
57 my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
59 int M = cinfo->_min_DCT_scaled_size;
60 jpeg_component_info *compptr;
61 _JSAMPARRAY xbuf0, xbuf1;
63 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
65 rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
66 cinfo->_min_DCT_scaled_size; /* height of a row group of component */
67 xbuf0 = main_ptr->xbuffer[0][ci];
68 xbuf1 = main_ptr->xbuffer[1][ci];
69 for (i = 0; i < rgroup; i++) {
70 xbuf0[i - rgroup] = xbuf0[rgroup * (M + 1) + i];
71 xbuf1[i - rgroup] = xbuf1[rgroup * (M + 1) + i];
72 xbuf0[rgroup * (M + 2) + i] = xbuf0[i];
73 xbuf1[rgroup * (M + 2) + i] = xbuf1[i];
78 #endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */