| 3733 | |
| 3734 | |
| 3735 | void SparseMat::convertTo( SparseMat& m, int rtype, double alpha ) const |
| 3736 | { |
| 3737 | int cn = channels(); |
| 3738 | if( rtype < 0 ) |
| 3739 | rtype = type(); |
| 3740 | rtype = CV_MAKETYPE(rtype, cn); |
| 3741 | if( hdr == m.hdr && rtype != type() ) |
| 3742 | { |
| 3743 | SparseMat temp; |
| 3744 | convertTo(temp, rtype, alpha); |
| 3745 | m = temp; |
| 3746 | return; |
| 3747 | } |
| 3748 | |
| 3749 | CV_Assert(hdr != 0); |
| 3750 | if( hdr != m.hdr ) |
| 3751 | m.create( hdr->dims, hdr->size, rtype ); |
| 3752 | |
| 3753 | SparseMatConstIterator from = begin(); |
| 3754 | size_t i, N = nzcount(); |
| 3755 | |
| 3756 | if( alpha == 1 ) |
| 3757 | { |
| 3758 | ConvertData cvtfunc = getConvertElem(type(), rtype); |
| 3759 | for( i = 0; i < N; i++, ++from ) |
| 3760 | { |
| 3761 | const Node* n = from.node(); |
| 3762 | uchar* to = hdr == m.hdr ? from.ptr : m.newNode(n->idx, n->hashval); |
| 3763 | cvtfunc( from.ptr, to, cn ); |
| 3764 | } |
| 3765 | } |
| 3766 | else |
| 3767 | { |
| 3768 | ConvertScaleData cvtfunc = getConvertScaleElem(type(), rtype); |
| 3769 | for( i = 0; i < N; i++, ++from ) |
| 3770 | { |
| 3771 | const Node* n = from.node(); |
| 3772 | uchar* to = hdr == m.hdr ? from.ptr : m.newNode(n->idx, n->hashval); |
| 3773 | cvtfunc( from.ptr, to, cn, alpha, 0 ); |
| 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | |
| 3778 | |
| 3779 | void SparseMat::convertTo( Mat& m, int rtype, double alpha, double beta ) const |