Commit db1178b5 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

moved GpuMat implementation to separate file

parent 2153a148
This diff is collapsed.
......@@ -94,12 +94,58 @@ GpuMat::GpuMat(Size size_, int type_, Scalar s_)
}
}
inline
GpuMat::GpuMat(const GpuMat& m)
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend)
{
if (refcount)
CV_XADD(refcount, 1);
}
inline
GpuMat::GpuMat(const Mat& m) :
flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
{
upload(m);
}
inline
GpuMat::~GpuMat()
{
release();
}
inline
GpuMat& GpuMat::operator =(const GpuMat& m)
{
if (this != &m)
{
GpuMat temp(m);
swap(temp);
}
return *this;
}
inline
void GpuMat::create(Size size_, int type_)
{
create(size_.height, size_.width, type_);
}
inline
void GpuMat::swap(GpuMat& b)
{
std::swap(flags, b.flags);
std::swap(rows, b.rows);
std::swap(cols, b.cols);
std::swap(step, b.step);
std::swap(data, b.data);
std::swap(datastart, b.datastart);
std::swap(dataend, b.dataend);
std::swap(refcount, b.refcount);
}
inline
GpuMat GpuMat::clone() const
{
......@@ -118,15 +164,17 @@ void GpuMat::assignTo(GpuMat& m, int _type) const
}
inline
size_t GpuMat::step1() const
uchar* GpuMat::ptr(int y)
{
return step / elemSize1();
CV_DbgAssert( (unsigned)y < (unsigned)rows );
return data + step * y;
}
inline
bool GpuMat::empty() const
const uchar* GpuMat::ptr(int y) const
{
return data == 0;
CV_DbgAssert( (unsigned)y < (unsigned)rows );
return data + step * y;
}
template<typename _Tp> inline
......@@ -141,6 +189,18 @@ const _Tp* GpuMat::ptr(int y) const
return (const _Tp*)ptr(y);
}
template <class T> inline
GpuMat::operator PtrStepSz<T>() const
{
return PtrStepSz<T>(rows, cols, (T*)data, step);
}
template <class T> inline
GpuMat::operator PtrStep<T>() const
{
return PtrStep<T>((T*)data, step);
}
inline
GpuMat GpuMat::row(int y) const
{
......@@ -178,19 +238,13 @@ GpuMat GpuMat::colRange(Range r) const
}
inline
void GpuMat::create(Size size_, int type_)
{
create(size_.height, size_.width, type_);
}
inline
GpuMat GpuMat::operator()(Range _rowRange, Range _colRange) const
GpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const
{
return GpuMat(*this, _rowRange, _colRange);
return GpuMat(*this, rowRange_, colRange_);
}
inline
GpuMat GpuMat::operator()(Rect roi) const
GpuMat GpuMat::operator ()(Rect roi) const
{
return GpuMat(*this, roi);
}
......@@ -232,48 +286,21 @@ int GpuMat::channels() const
}
inline
Size GpuMat::size() const
{
return Size(cols, rows);
}
inline
uchar* GpuMat::ptr(int y)
size_t GpuMat::step1() const
{
CV_DbgAssert((unsigned)y < (unsigned)rows);
return data + step * y;
return step / elemSize1();
}
inline
const uchar* GpuMat::ptr(int y) const
Size GpuMat::size() const
{
CV_DbgAssert((unsigned)y < (unsigned)rows);
return data + step * y;
return Size(cols, rows);
}
inline
GpuMat& GpuMat::operator = (Scalar s)
{
setTo(s);
return *this;
}
template <class T> inline
GpuMat::operator PtrStepSz<T>() const
{
return PtrStepSz<T>(rows, cols, (T*)data, step);
}
template <class T> inline
GpuMat::operator PtrStep<T>() const
{
return PtrStep<T>((T*)data, step);
}
static inline
void swap(GpuMat& a, GpuMat& b)
bool GpuMat::empty() const
{
a.swap(b);
return data == 0;
}
static inline
......@@ -304,6 +331,23 @@ void ensureSizeIsEnough(Size size, int type, GpuMat& m)
ensureSizeIsEnough(size.height, size.width, type, m);
}
static inline
void swap(GpuMat& a, GpuMat& b)
{
a.swap(b);
}
}} // namespace cv { namespace gpu
namespace cv {
inline
Mat::Mat(const gpu::GpuMat& m)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0), datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
{
m.download(*this);
}
}
#endif // __OPENCV_CORE_GPUINL_HPP__
This diff is collapsed.
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/core/cuda/common.hpp"
namespace cv { namespace gpu { namespace cudev
{
void copyWithMask(PtrStepSzb src, PtrStepSzb dst, size_t elemSize1, int cn, PtrStepSzb mask, bool multiChannelMask, cudaStream_t stream);
template <typename T>
void set(PtrStepSz<T> mat, const T* scalar, int channels, cudaStream_t stream);
template <typename T>
void set(PtrStepSz<T> mat, const T* scalar, PtrStepSzb mask, int channels, cudaStream_t stream);
void convert(PtrStepSzb src, int sdepth, PtrStepSzb dst, int ddepth, double alpha, double beta, cudaStream_t stream);
}}}
This diff is collapsed.
This diff is collapsed.
......@@ -72,10 +72,10 @@ void cv::gpu::Stream::release() { throw_no_cuda(); }
namespace cv { namespace gpu
{
void copyWithMask(const GpuMat& src, GpuMat& dst, const GpuMat& mask, cudaStream_t stream);
void convertTo(const GpuMat& src, GpuMat& dst, double alpha, double beta, cudaStream_t stream);
void setTo(GpuMat& src, Scalar s, cudaStream_t stream);
void setTo(GpuMat& src, Scalar s, const GpuMat& mask, cudaStream_t stream);
void copyWithMask(const GpuMat& src, GpuMat& dst, const GpuMat& mask, cudaStream_t stream = 0);
void convert(const GpuMat& src, GpuMat& dst, double alpha, double beta, cudaStream_t stream = 0);
void set(GpuMat& m, Scalar s, cudaStream_t stream = 0);
void set(GpuMat& m, Scalar s, const GpuMat& mask, cudaStream_t stream = 0);
}}
struct Stream::Impl
......@@ -217,7 +217,7 @@ void cv::gpu::Stream::enqueueMemSet(GpuMat& src, Scalar val)
}
}
setTo(src, val, stream);
set(src, val, stream);
}
void cv::gpu::Stream::enqueueMemSet(GpuMat& src, Scalar val, const GpuMat& mask)
......@@ -234,7 +234,7 @@ void cv::gpu::Stream::enqueueMemSet(GpuMat& src, Scalar val, const GpuMat& mask)
cudaStream_t stream = Impl::getStream(impl);
setTo(src, val, mask, stream);
set(src, val, mask, stream);
}
void cv::gpu::Stream::enqueueConvert(const GpuMat& src, GpuMat& dst, int dtype, double alpha, double beta)
......@@ -265,7 +265,7 @@ void cv::gpu::Stream::enqueueConvert(const GpuMat& src, GpuMat& dst, int dtype,
dst.create(src.size(), dtype);
cudaStream_t stream = Impl::getStream(impl);
convertTo(src, dst, alpha, beta, stream);
convert(src, dst, alpha, beta, stream);
}
#if CUDART_VERSION >= 5000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment