
#define V(_coeff, _w, _x, _y)  (  \
    (_coeff) +                    \
    ( 64 * (_w) * ((_y)/8) ) +    \
    ( 64 * (_w) * ((_x)/8) ) +    \
    (8 * ((_y)&7)) + ((_x)&7)     \
  )


extent() {

  for(cid=0; cid<component_count_; ++cid) {
    y_ratio[cid] = 0;
  }

  for (iy=0; iy< coded_height; ++iy) {

    for(cid=0; cid<component_count_; ++cid) {
      x_ratio[cid] = 0;
    }

    for (ix=0; ix< coded_width; ++ix) {

      Y  = *V(coeff[0], hcount[0], cx[0], cy[0]);
      Cr = *V(coeff[1], hcount[1], cx[1], cy[1]);
      Cb = *V(coeff[2], hcount[2], cx[2], cy[2]);

      decoded_image_ + (bytes_per_line_ * iy) + (ix * bytes_per_pix);

      for(cid=0; cid<component_count_; ++cid) {
        x_ratio[cid] += horizontal_sampling_factor_[cid];
        if (x_ratio[cid] < horizontal_sampling_factor_max_) {
          x_ratio[cid] -= horizontal_sampling_factor_max_;
          ++cx[cid];
        }
      }

    }

    for(cid=0; cid<component_count_; ++cid) {
      y_ratio[cid] += vertical_sampling_factor_[cid];
      if (y_ratio[cid] < vertical_sampling_factor_max_) {
        y_ratio[cid] -= vertical_sampling_factor_max_;
        ++cy[cid];
      }
    }

  }

}

