shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * jdmainct.h
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file was part of the Independent JPEG Group's software:
shun-iwasawa 82a8f5
 * Copyright (C) 1994-1996, Thomas G. Lane.
shun-iwasawa 82a8f5
 * For conditions of distribution and use, see the accompanying README.ijg
shun-iwasawa 82a8f5
 * file.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define JPEG_INTERNALS
shun-iwasawa 82a8f5
#include "jpeglib.h"
shun-iwasawa 82a8f5
#include "jpegcomp.h"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Private buffer controller object */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef struct {
shun-iwasawa 82a8f5
  struct jpeg_d_main_controller pub; /* public fields */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Pointer to allocated workspace (M or M+2 row groups). */
shun-iwasawa 82a8f5
  JSAMPARRAY buffer[MAX_COMPONENTS];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  boolean buffer_full;          /* Have we gotten an iMCU row from decoder? */
shun-iwasawa 82a8f5
  JDIMENSION rowgroup_ctr;      /* counts row groups output to postprocessor */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Remaining fields are only used in the context case. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* These are the master pointers to the funny-order pointer lists. */
shun-iwasawa 82a8f5
  JSAMPIMAGE xbuffer[2];        /* pointers to weird pointer lists */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  int whichptr;                 /* indicates which pointer set is now in use */
shun-iwasawa 82a8f5
  int context_state;            /* process_data state machine status */
shun-iwasawa 82a8f5
  JDIMENSION rowgroups_avail;   /* row groups available to postprocessor */
shun-iwasawa 82a8f5
  JDIMENSION iMCU_row_ctr;      /* counts iMCU rows to detect image top/bot */
shun-iwasawa 82a8f5
} my_main_controller;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef my_main_controller *my_main_ptr;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* context_state values: */
shun-iwasawa 82a8f5
#define CTX_PREPARE_FOR_IMCU    0       /* need to prepare for MCU row */
shun-iwasawa 82a8f5
#define CTX_PROCESS_IMCU        1       /* feeding iMCU to postprocessor */
shun-iwasawa 82a8f5
#define CTX_POSTPONED_ROW       2       /* feeding postponed row group */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
LOCAL(void)
shun-iwasawa 82a8f5
set_wraparound_pointers(j_decompress_ptr cinfo)
shun-iwasawa 82a8f5
/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
shun-iwasawa 82a8f5
 * This changes the pointer list state from top-of-image to the normal state.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
shun-iwasawa 82a8f5
  int ci, i, rgroup;
shun-iwasawa 82a8f5
  int M = cinfo->_min_DCT_scaled_size;
shun-iwasawa 82a8f5
  jpeg_component_info *compptr;
shun-iwasawa 82a8f5
  JSAMPARRAY xbuf0, xbuf1;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shun-iwasawa 82a8f5
       ci++, compptr++) {
shun-iwasawa 82a8f5
    rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
shun-iwasawa 82a8f5
      cinfo->_min_DCT_scaled_size; /* height of a row group of component */
shun-iwasawa 82a8f5
    xbuf0 = main_ptr->xbuffer[0][ci];
shun-iwasawa 82a8f5
    xbuf1 = main_ptr->xbuffer[1][ci];
shun-iwasawa 82a8f5
    for (i = 0; i < rgroup; i++) {
shun-iwasawa 82a8f5
      xbuf0[i - rgroup] = xbuf0[rgroup * (M + 1) + i];
shun-iwasawa 82a8f5
      xbuf1[i - rgroup] = xbuf1[rgroup * (M + 1) + i];
shun-iwasawa 82a8f5
      xbuf0[rgroup * (M + 2) + i] = xbuf0[i];
shun-iwasawa 82a8f5
      xbuf1[rgroup * (M + 2) + i] = xbuf1[i];
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}