TestResize.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  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.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  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.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  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.
  26. //
  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.
  29. //
  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.
  40. //
  41. //M*/
  42. #include "test_precomp.hpp"
  43. template <class T>
  44. TestResize<T>::TestResize(std::string testName_, NCVTestSourceProvider<T> &src_,
  45. Ncv32u width_, Ncv32u height_, Ncv32u scaleFactor_, NcvBool bTextureCache_)
  46. :
  47. NCVTestProvider(testName_),
  48. src(src_),
  49. width(width_),
  50. height(height_),
  51. scaleFactor(scaleFactor_),
  52. bTextureCache(bTextureCache_)
  53. {
  54. }
  55. template <class T>
  56. bool TestResize<T>::toString(std::ofstream &strOut)
  57. {
  58. strOut << "sizeof(T)=" << sizeof(T) << std::endl;
  59. strOut << "width=" << width << std::endl;
  60. strOut << "scaleFactor=" << scaleFactor << std::endl;
  61. strOut << "bTextureCache=" << bTextureCache << std::endl;
  62. return true;
  63. }
  64. template <class T>
  65. bool TestResize<T>::init()
  66. {
  67. return true;
  68. }
  69. template <class T>
  70. bool TestResize<T>::process()
  71. {
  72. NCVStatus ncvStat;
  73. bool rcode = false;
  74. Ncv32s smallWidth = this->width / this->scaleFactor;
  75. Ncv32s smallHeight = this->height / this->scaleFactor;
  76. if (smallWidth == 0 || smallHeight == 0)
  77. {
  78. return true;
  79. }
  80. NcvSize32u srcSize(this->width, this->height);
  81. NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
  82. ncvAssertReturn(d_img.isMemAllocated(), false);
  83. NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
  84. ncvAssertReturn(h_img.isMemAllocated(), false);
  85. NCVMatrixAlloc<T> d_small(*this->allocatorGPU.get(), smallWidth, smallHeight);
  86. ncvAssertReturn(d_small.isMemAllocated(), false);
  87. NCVMatrixAlloc<T> h_small(*this->allocatorCPU.get(), smallWidth, smallHeight);
  88. ncvAssertReturn(h_small.isMemAllocated(), false);
  89. NCVMatrixAlloc<T> h_small_d(*this->allocatorCPU.get(), smallWidth, smallHeight);
  90. ncvAssertReturn(h_small_d.isMemAllocated(), false);
  91. NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
  92. NCV_SKIP_COND_BEGIN
  93. ncvAssertReturn(this->src.fill(h_img), false);
  94. NCV_SKIP_COND_END
  95. ncvStat = h_img.copySolid(d_img, 0);
  96. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  97. NCV_SKIP_COND_BEGIN
  98. if (sizeof(T) == sizeof(Ncv32u))
  99. {
  100. ncvStat = nppiStDecimate_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
  101. (Ncv32u *)d_small.ptr(), d_small.pitch(),
  102. srcSize, this->scaleFactor,
  103. this->bTextureCache);
  104. }
  105. else if (sizeof(T) == sizeof(Ncv64u))
  106. {
  107. ncvStat = nppiStDecimate_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
  108. (Ncv64u *)d_small.ptr(), d_small.pitch(),
  109. srcSize, this->scaleFactor,
  110. this->bTextureCache);
  111. }
  112. else
  113. {
  114. ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
  115. }
  116. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  117. NCV_SKIP_COND_END
  118. ncvStat = d_small.copySolid(h_small_d, 0);
  119. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  120. NCV_SKIP_COND_BEGIN
  121. if (sizeof(T) == sizeof(Ncv32u))
  122. {
  123. ncvStat = nppiStDecimate_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
  124. (Ncv32u *)h_small.ptr(), h_small.pitch(),
  125. srcSize, this->scaleFactor);
  126. }
  127. else if (sizeof(T) == sizeof(Ncv64u))
  128. {
  129. ncvStat = nppiStDecimate_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
  130. (Ncv64u *)h_small.ptr(), h_small.pitch(),
  131. srcSize, this->scaleFactor);
  132. }
  133. else
  134. {
  135. ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
  136. }
  137. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  138. NCV_SKIP_COND_END
  139. //bit-to-bit check
  140. bool bLoopVirgin = true;
  141. NCV_SKIP_COND_BEGIN
  142. //const Ncv64f relEPS = 0.005;
  143. for (Ncv32u i=0; bLoopVirgin && i < h_small.height(); i++)
  144. {
  145. for (Ncv32u j=0; bLoopVirgin && j < h_small.width(); j++)
  146. {
  147. if (h_small.ptr()[h_small.stride()*i+j] != h_small_d.ptr()[h_small_d.stride()*i+j])
  148. {
  149. bLoopVirgin = false;
  150. }
  151. }
  152. }
  153. NCV_SKIP_COND_END
  154. if (bLoopVirgin)
  155. {
  156. rcode = true;
  157. }
  158. return rcode;
  159. }
  160. template <class T>
  161. bool TestResize<T>::deinit()
  162. {
  163. return true;
  164. }
  165. template class TestResize<Ncv32u>;
  166. template class TestResize<Ncv64u>;