1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#include "test_precomp.hpp"
47
TestResize<T>::TestResize(std::string testName_, NCVTestSourceProvider<T> &src_,
48
Ncv32u width_, Ncv32u height_, Ncv32u scaleFactor_, NcvBool bTextureCache_)
50
NCVTestProvider(testName_),
54
scaleFactor(scaleFactor_),
55
bTextureCache(bTextureCache_)
61
bool TestResize<T>::toString(std::ofstream &strOut)
63
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
64
strOut << "width=" << width << std::endl;
65
strOut << "scaleFactor=" << scaleFactor << std::endl;
66
strOut << "bTextureCache=" << bTextureCache << std::endl;
72
bool TestResize<T>::init()
79
bool TestResize<T>::process()
84
Ncv32s smallWidth = this->width / this->scaleFactor;
85
Ncv32s smallHeight = this->height / this->scaleFactor;
86
if (smallWidth == 0 || smallHeight == 0)
91
NcvSize32u srcSize(this->width, this->height);
93
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
94
ncvAssertReturn(d_img.isMemAllocated(), false);
95
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
96
ncvAssertReturn(h_img.isMemAllocated(), false);
98
NCVMatrixAlloc<T> d_small(*this->allocatorGPU.get(), smallWidth, smallHeight);
99
ncvAssertReturn(d_small.isMemAllocated(), false);
100
NCVMatrixAlloc<T> h_small(*this->allocatorCPU.get(), smallWidth, smallHeight);
101
ncvAssertReturn(h_small.isMemAllocated(), false);
102
NCVMatrixAlloc<T> h_small_d(*this->allocatorCPU.get(), smallWidth, smallHeight);
103
ncvAssertReturn(h_small_d.isMemAllocated(), false);
105
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
107
ncvAssertReturn(this->src.fill(h_img), false);
110
ncvStat = h_img.copySolid(d_img, 0);
111
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
113
if (sizeof(T) == sizeof(Ncv32u))
115
ncvStat = nppiStDecimate_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
116
(Ncv32u *)d_small.ptr(), d_small.pitch(),
117
srcSize, this->scaleFactor,
118
this->bTextureCache);
120
else if (sizeof(T) == sizeof(Ncv64u))
122
ncvStat = nppiStDecimate_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
123
(Ncv64u *)d_small.ptr(), d_small.pitch(),
124
srcSize, this->scaleFactor,
125
this->bTextureCache);
129
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
131
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
133
ncvStat = d_small.copySolid(h_small_d, 0);
134
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
137
if (sizeof(T) == sizeof(Ncv32u))
139
ncvStat = nppiStDecimate_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
140
(Ncv32u *)h_small.ptr(), h_small.pitch(),
141
srcSize, this->scaleFactor);
143
else if (sizeof(T) == sizeof(Ncv64u))
145
ncvStat = nppiStDecimate_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
146
(Ncv64u *)h_small.ptr(), h_small.pitch(),
147
srcSize, this->scaleFactor);
151
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
153
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
157
bool bLoopVirgin = true;
160
//const Ncv64f relEPS = 0.005;
161
for (Ncv32u i=0; bLoopVirgin && i < h_small.height(); i++)
163
for (Ncv32u j=0; bLoopVirgin && j < h_small.width(); j++)
165
if (h_small.ptr()[h_small.stride()*i+j] != h_small_d.ptr()[h_small_d.stride()*i+j])
183
bool TestResize<T>::deinit()
189
template class TestResize<Ncv32u>;
190
template class TestResize<Ncv64u>;