void ccv_resample(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int rows, int cols, int type) { assert(rows > 0 && cols > 0); ccv_declare_derived_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_resample(%d,%d,%d)", rows, cols, type), a->sig, CCV_EOF_SIGN); btype = (btype == 0) ? CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type) : CCV_GET_DATA_TYPE(btype) | CCV_GET_CHANNEL(a->type); ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, rows, cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(a->type), btype, sig); ccv_object_return_if_cached(, db); if (a->rows == db->rows && a->cols == db->cols) { if (CCV_GET_CHANNEL(a->type) == CCV_GET_CHANNEL(db->type) && CCV_GET_DATA_TYPE(db->type) == CCV_GET_DATA_TYPE(a->type)) memcpy(db->data.u8, a->data.u8, a->rows * a->step); else { ccv_shift(a, (ccv_matrix_t**)&db, 0, 0, 0); } return; } if ((type & CCV_INTER_AREA) && a->rows >= db->rows && a->cols >= db->cols) { /* using the fast alternative (fix point scale, 0x100 to avoid overflow) */ if (CCV_GET_DATA_TYPE(a->type) == CCV_8U && CCV_GET_DATA_TYPE(db->type) == CCV_8U && a->rows * a->cols / (db->rows * db->cols) < 0x100) _ccv_resample_area_8u(a, db); else _ccv_resample_area(a, db); } else if (type & CCV_INTER_CUBIC) { if (CCV_GET_DATA_TYPE(db->type) == CCV_32F || CCV_GET_DATA_TYPE(db->type) == CCV_64F) _ccv_resample_cubic_float_only(a, db); else _ccv_resample_cubic_integer_only(a, db); } else if (type & CCV_INTER_LINEAR) { assert(0 && "CCV_INTER_LINEAR is not implemented"); } else if (type & CCV_INTER_LINEAR) { assert(0 && "CCV_INTER_LANCZOS is not implemented"); } }
void ccv_resample(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int rows, int cols, int type) { ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_resample(%d,%d,%d)", rows, cols, type), a->sig, 0); btype = (btype == 0) ? CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type) : CCV_GET_DATA_TYPE(btype) | CCV_GET_CHANNEL(a->type); ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, rows, cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(a->type), btype, sig); ccv_matrix_return_if_cached(, db); if (a->rows == db->rows && a->cols == db->cols) { if (CCV_GET_CHANNEL(a->type) == CCV_GET_CHANNEL(db->type) && CCV_GET_DATA_TYPE(db->type) == CCV_GET_DATA_TYPE(a->type)) memcpy(db->data.u8, a->data.u8, a->rows * a->step); else { ccv_shift(a, (ccv_matrix_t**)&db, 0, 0, 0); } return; } switch (type) { case CCV_INTER_AREA: if (a->rows > db->rows && a->cols > db->cols) { /* using the fast alternative (fix point scale, 0x100 to avoid overflow) */ if (CCV_GET_DATA_TYPE(a->type) == CCV_8U && CCV_GET_DATA_TYPE(db->type) == CCV_8U && a->rows * a->cols / (db->rows * db->cols) < 0x100) _ccv_resample_area_8u(a, db); else _ccv_resample_area(a, db); break; } case CCV_INTER_LINEAR: break; case CCV_INTER_CUBIC: break; case CCV_INTER_LANCZOS: break; } }