00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "CUDA/CudaCutPaste.H"
00039 #include "CUDA/CudaMathOps.H"
00040 #include "CUDA/CudaImage.H"
00041 #include "Image/Pixels.H"
00042 #include "Util/Assert.H"
00043 #include <algorithm>
00044
00045
00046 CudaImage<float> cudaCrop(const CudaImage<float>& src, const Point2D<int>& pt, const Dims& dims,
00047 const bool zerofill)
00048 {
00049
00050 if (pt == Point2D<int>(0,0) && dims == src.getDims())
00051 return src;
00052
00053 const int dev = src.getMemoryDevice();
00054 const MemoryPolicy mp = src.getMemoryPolicy();
00055 ASSERT(mp != HOST_MEMORY);
00056 Dims tile = CudaDevices::getDeviceTileSize(dev);
00057
00058 CudaImage<float> result(dims, NO_INIT,mp,dev);
00059
00060 if(!zerofill)
00061 {
00062 ASSERT(src.coordsOk(pt));
00063 ASSERT(src.coordsOk(pt.i + dims.w() - 1, pt.j + dims.h() - 1));
00064 }
00065
00066 int endX = pt.i+dims.w(); int maxX = std::min(endX,src.getWidth());
00067 int endY = pt.j+dims.h(); int maxY = std::min(endY,src.getHeight());
00068 cuda_c_crop(src.getCudaArrayPtr(),result.getCudaArrayPtr(),src.getWidth(),src.getHeight(),pt.i,pt.j,endX,endY,maxX,maxY,tile.w(),tile.h());
00069 return result;
00070 }
00071
00072
00073 CudaImage<float> cudaCrop(const CudaImage<float>& src, const Rectangle& rect, const bool zerofill)
00074 {
00075 return cudaCrop(src,
00076 Point2D<int>(rect.left(), rect.top()),
00077 Dims(rect.width(), rect.height()),
00078 zerofill);
00079 }
00080
00081
00082 CudaImage<float> cudaShiftImage(const CudaImage<float>& src, const float dx, const float dy)
00083 {
00084
00085 ASSERT(src.initialized());
00086
00087
00088 Dims dim(src.getDims());
00089 const int dev = src.getMemoryDevice();
00090 const MemoryPolicy mp = src.getMemoryPolicy();
00091 CudaImage<float> result(dim, ZEROS,mp,dev);
00092 Dims tile = CudaDevices::getDeviceTileSize(dev);
00093 cuda_c_shiftImage(src.getCudaArrayPtr(),result.getCudaArrayPtr(),dim.w(),dim.h(),dx,dy,tile.w(),tile.h());
00094 return result;
00095 }
00096
00097
00098
00099
00100 CudaImage<float> cudaShiftClean(const CudaImage<float>& src, const int dx, const int dy,
00101 const float bgval)
00102 {
00103
00104 ASSERT(src.initialized());
00105
00106
00107 int w = src.getWidth(), h = src.getHeight();
00108 const int dev = src.getMemoryDevice();
00109 const MemoryPolicy mp = src.getMemoryPolicy();
00110 Dims tile = CudaDevices::getDeviceTileSize(dev);
00111
00112 CudaImage<float> result(w, h, NO_INIT, mp, dev); cudaClear(result,bgval);
00113
00114 return result;
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 }
00140
00141
00142
00143 void cudaInplacePaste(CudaImage<float>& dst,
00144 const CudaImage<float>& img, const Point2D<int>& pos)
00145 {
00146 int w = dst.getWidth(), h = dst.getHeight();
00147 int iw = img.getWidth(), ih=img.getHeight();
00148
00149 ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00150 const int dev = dst.getMemoryDevice();
00151 Dims tile = CudaDevices::getDeviceTileSize(dev);
00152 cuda_c_inplacePaste(dst.getCudaArrayPtr(),img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00153 }
00154
00155 void cudaInplacePaste(CudaImage<PixRGB<float> >& dst,
00156 const CudaImage<PixRGB<float> >& img, const Point2D<int>& pos)
00157 {
00158 int w = dst.getWidth(), h = dst.getHeight();
00159 int iw = img.getWidth(), ih=img.getHeight();
00160
00161 ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00162 const int dev = dst.getMemoryDevice();
00163 Dims tile = CudaDevices::getDeviceTileSize(dev);
00164 cuda_c_inplacePasteRGB((float3_t *)dst.getCudaArrayPtr(),(float3_t *)img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00165 }
00166
00167
00168 void cudaInplaceOverlay(CudaImage<float>& dst, const CudaImage<float>& img, const Point2D<int>& pos)
00169 {
00170 int w = dst.getWidth(), h = dst.getHeight();
00171 int iw = img.getWidth(), ih=img.getHeight();
00172
00173 ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00174 const int dev = dst.getMemoryDevice();
00175 Dims tile = CudaDevices::getDeviceTileSize(dev);
00176 cuda_c_inplaceOverlay(dst.getCudaArrayPtr(),img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00177 }
00178
00179
00180 void cudaInplaceOverlay(CudaImage<PixRGB<float> >&dst, const CudaImage<PixRGB<float> >&img, const Point2D<int>& pos)
00181 {
00182 int w = dst.getWidth(), h = dst.getHeight();
00183 int iw = img.getWidth(), ih=img.getHeight();
00184
00185 ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00186 const int dev = dst.getMemoryDevice();
00187 Dims tile = CudaDevices::getDeviceTileSize(dev);
00188 cuda_c_inplaceOverlayRGB((float3_t *)dst.getCudaArrayPtr(),(float3_t *)img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00189 }
00190