Example #1
0
static int
filter_func_ctrl (st_filter_chain_t *fc, void *o, int operation, const char *operation_s)
{
  // set current op
  fc->op = operation;

  switch (operation)
    {
      case FILTER_CLOSE:
        for (fc->pos = fc->total; fc->pos-- > 0;) // reverse
          if (filter_func (fc, o, operation, operation_s) == -1)
            return -1;
        break;
      
      default:
        for (fc->pos = 0; fc->pos < fc->total; fc->pos++)
          if (filter_func (fc, o, operation, operation_s) == -1)
            return -1;
    }

  return 0;
}
Example #2
0
static int EncodeAlphaInternal(const uint8_t* const data, int width, int height,
                               int method, int filter, int reduce_levels,
                               int effort_level,  // in [0..6] range
                               uint8_t* const tmp_alpha,
                               VP8BitWriter* const bw,
                               WebPAuxStats* const stats) {
  int ok = 0;
  const uint8_t* alpha_src;
  WebPFilterFunc filter_func;
  uint8_t header;
  size_t expected_size;
  const size_t data_size = width * height;

  assert((uint64_t)data_size == (uint64_t)width * height);  // as per spec
  assert(filter >= 0 && filter < WEBP_FILTER_LAST);
  assert(method >= ALPHA_NO_COMPRESSION);
  assert(method <= ALPHA_LOSSLESS_COMPRESSION);
  assert(sizeof(header) == ALPHA_HEADER_LEN);
  // TODO(skal): have a common function and #define's to validate alpha params.

  expected_size =
      (method == ALPHA_NO_COMPRESSION) ? (ALPHA_HEADER_LEN + data_size)
                                       : (data_size >> 5);
  header = method | (filter << 2);
  if (reduce_levels) header |= ALPHA_PREPROCESSED_LEVELS << 4;

  VP8BitWriterInit(bw, expected_size);
  VP8BitWriterAppend(bw, &header, ALPHA_HEADER_LEN);

  filter_func = WebPFilters[filter];
  if (filter_func) {
    filter_func(data, width, height, 1, width, tmp_alpha);
    alpha_src = tmp_alpha;
  }  else {
    alpha_src = data;
  }

  if (method == ALPHA_NO_COMPRESSION) {
    ok = VP8BitWriterAppend(bw, alpha_src, width * height);
    ok = ok && !bw->error_;
  } else {
    ok = EncodeLossless(alpha_src, width, height, effort_level, bw, stats);
    VP8BitWriterFinish(bw);
  }
  return ok;
}
Example #3
0
// This function always returns an initialized 'bw' object, even upon error.
static int EncodeAlphaInternal(const uint8_t* const data, int width, int height,
                               int method, int filter, int reduce_levels,
                               int effort_level,  // in [0..6] range
                               uint8_t* const tmp_alpha,
                               FilterTrial* result) {
  int ok = 0;
  const uint8_t* alpha_src;
  WebPFilterFunc filter_func;
  uint8_t header;
  const size_t data_size = width * height;
  const uint8_t* output = NULL;
  size_t output_size = 0;
  VP8LBitWriter tmp_bw;

  assert((uint64_t)data_size == (uint64_t)width * height);  // as per spec
  assert(filter >= 0 && filter < WEBP_FILTER_LAST);
  assert(method >= ALPHA_NO_COMPRESSION);
  assert(method <= ALPHA_LOSSLESS_COMPRESSION);
  assert(sizeof(header) == ALPHA_HEADER_LEN);
  // TODO(skal): have a common function and #define's to validate alpha params.

  filter_func = WebPFilters[filter];
  if (filter_func != NULL) {
    filter_func(data, width, height, width, tmp_alpha);
    alpha_src = tmp_alpha;
  }  else {
    alpha_src = data;
  }

  if (method != ALPHA_NO_COMPRESSION) {
    ok = VP8LBitWriterInit(&tmp_bw, data_size >> 3);
    ok = ok && EncodeLossless(alpha_src, width, height, effort_level,
                              &tmp_bw, &result->stats);
    if (ok) {
      output = VP8LBitWriterFinish(&tmp_bw);
      output_size = VP8LBitWriterNumBytes(&tmp_bw);
      if (output_size > data_size) {
        // compressed size is larger than source! Revert to uncompressed mode.
        method = ALPHA_NO_COMPRESSION;
        VP8LBitWriterDestroy(&tmp_bw);
      }
    } else {
      VP8LBitWriterDestroy(&tmp_bw);
      return 0;
    }
  }
Example #4
0
File: main.cpp Project: CCJY/coliru
const bool IgnoreFields(const some_row_concept_class& srcc,
                        const boost::sub_range<std::vector<std::string> >& fields_to_ignore,
                        const int float_accuracy)
{
    typedef const bool (filter_signature)(const some_class&);
    typedef boost::function<filter_signature> fil_func_sig;
    
    fil_func_sig filter_func(boost::bind(&FieldNotInRangeFilter,
                                         _1,
                                         fields_to_ignore.begin(),
                                         fields_to_ignore.end(),
                                         float_accuracy));
    
    typedef boost::filter_iterator<fil_func_sig,
                                   std::vector<some_class>::const_iterator> filter_iterator_;
    
    return std::find_if(filter_iterator_(filter_func,
                                         srcc.row_values.begin()),
                        filter_iterator_(),
                        &pair_match<some_class>) != filter_iterator_();
}
Example #5
0
File: main.cpp Project: CCJY/coliru
const std::vector<some_row_concept_class> OutputFilteredRows(const boost::sub_range<std::vector<some_row_concept_class> >& rows,
                                                             std::ostream& output_stream,
                                                             const boost::sub_range<std::vector<std::string> >& fields_to_ignore,
                                                             const int accuracy_filter)
{
    typedef const bool (filter_signature)(const some_row_concept_class&);
    typedef boost::function<filter_signature> fil_func_sig;
    
    fil_func_sig filter_func(boost::bind(&IgnoreFields,
                                         _1,
                                         fields_to_ignore,
                                         accuracy_filter));
    
    typedef boost::filter_iterator<fil_func_sig,
                                   boost::sub_range<std::vector<some_row_concept_class> >::const_iterator> filter_iterator_;
    typedef boost::iterator_range<filter_iterator_> filtered_range;
    
    return OutputFilteredRowsT(filtered_range(filter_iterator_(filter_func,
                                                               rows.begin()),
                                              filter_iterator_()),
                               output_stream);
}