Beispiel #1
0
  /// Subordinate pass of EZW algorithm.  see Shapiro, 1993 for info.
  bool ezw_decoder::subordinate_pass(ibitstream& in) {
    for (size_t i=0; i < sub_list_.size(); i++) {
      sub_elt e = sub_list_[i];

      if (in.read_bit()) {
        if (!in.good()) return false;

        // check bounds in case we're creating reduced-size output,
        // where we'd ignore things that are out of bounds.
        if (matrix_utils::in_bounds(*decoded_, e.row, e.col)) {
          if ((*decoded_)(e.row, e.col) < 0) {
            (*decoded_)(e.row, e.col) -= threshold_;
          } else {
            (*decoded_)(e.row, e.col) += threshold_;
          }

        }
        DBG_OUT(1);
	
      } else {
        if (!in.good()) return false;
        DBG_OUT(0);
      }
    }
    return true;
  }
Beispiel #2
0
  ezw_code ezw_decoder::decode_value(const dom_elt& e, ibitstream& in) {
    bool hi = in.read_bit();   // tells whether POS/NEG or not
    bool lo = in.read_bit();   // ZERO_TREE or ZERO

    if (!in.good()) {    // make sure end of file wasn't reached early
      return STOP;
    }

    if (hi) {
      sub_list_.push_back(sub_elt(e.row, e.col));

      if (lo) {
        DBG_OUT('p');
        // check size in case of reduced-size output.
        if (matrix_utils::in_bounds(*decoded_, e.row, e.col)) {
          (*decoded_)(e.row, e.col) = threshold_;
        }
        return POSITIVE;

      } else {
        DBG_OUT('n');
        // check size in case of reduced-size output.
        if (matrix_utils::in_bounds(*decoded_, e.row, e.col)) {
          (*decoded_)(e.row, e.col) = -threshold_;
        }
        return NEGATIVE;
      }

    } else {
      DBG_OUT(lo ? 'z' : 't');
      return lo ? ZERO : ZERO_TREE;
    }
  }