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 #ifndef CUDA_COLOROPS_H_DEFINED
00039 #define CUDA_COLOROPS_H_DEFINED
00040
00041 #include <cuda.h>
00042 #include "CUDA/cutil.h"
00043 #include "cudadefs.h"
00044
00045
00046
00047
00048 __global__ void cuda_global_getRGBY(const float3_t *src, float *rgptr, float *byptr, const float thresh, const float min_range, const float max_range, const int w, const int h, const int tile_width, const int tile_height)
00049 {
00050 const int x_pos = IMUL(blockIdx.x,tile_width) + threadIdx.x;
00051 const int y_pos = IMUL(blockIdx.y,tile_height) + threadIdx.y;
00052 const int idx = IMUL(y_pos,w) + x_pos;
00053 float thresh3 = 3.0F * thresh;
00054
00055 if(x_pos < w && y_pos < h)
00056 {
00057 float r = src[idx].p[0], g = src[idx].p[1], b = src[idx].p[2];
00058
00059
00060 float lum = r + g + b;
00061 if (lum < thresh3)
00062 {
00063 rgptr[idx] = min_range;
00064 byptr[idx] = min_range;
00065 }
00066 else
00067 {
00068
00069 float fac = (max_range-min_range) / lum;
00070 r *= fac; g *= fac; b *= fac;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 float red = r - 0.5f * (g + b), green = g - 0.5f * (r + b);
00081 float blue = b - 0.5f * (r + g), yellow = -2.0f * (blue + fabs(r-g));
00082
00083 if (red < min_range) red = min_range;
00084 else if (red > max_range) red = max_range;
00085 if (green < min_range) green = min_range;
00086 else if (green > max_range) green = max_range;
00087 if (blue < min_range) blue = min_range;
00088 else if (blue > max_range) blue = max_range;
00089 if (yellow < min_range) yellow=min_range;
00090 else if (yellow > max_range) yellow=max_range;
00091
00092 rgptr[idx] = red - green;
00093 byptr[idx] = blue - yellow;
00094 }
00095 }
00096 }
00097
00098
00099
00100 __global__ void cuda_global_toRGB(float3_t *dst, const float *src, const int sz, const int tile_len)
00101 {
00102 const int idx = IMUL(blockIdx.x,tile_len) + threadIdx.x;
00103 if(idx < sz)
00104 {
00105 float val = src[idx];
00106 dst[idx].p[0] = val;
00107 dst[idx].p[1] = val;
00108 dst[idx].p[2] = val;
00109 }
00110 }
00111
00112
00113
00114
00115 __device__ void cuda_device_getComponents(const float3_t *aptr, float *rptr, float *gptr, float *bptr,
00116 const int w, const int h, const int idx)
00117 {
00118 if(idx < w*h)
00119 {
00120 rptr[idx] = aptr[idx].p[0];
00121 gptr[idx] = aptr[idx].p[1];
00122 bptr[idx] = aptr[idx].p[2];
00123 }
00124 }
00125
00126
00127
00128
00129
00130 __global__ void cuda_global_getComponents(const float3_t *aptr, float *rptr, float *gptr, float *bptr, int w, int h, int tile_width, int tile_height)
00131 {
00132
00133 const int idx = blockIdx.y*tile_height*w + threadIdx.y*w + blockIdx.x*tile_width + threadIdx.x;
00134 cuda_device_getComponents(aptr,rptr,gptr,bptr,w,h,idx);
00135 }
00136
00137
00138
00139
00140 __device__ void cuda_device_luminance(const float3_t *aptr, float *dptr, const int w, const int h, const int idx, const int secidx)
00141 {
00142 if(idx < w*h)
00143 dptr[idx] = (aptr[idx].p[0] + aptr[idx].p[1] + aptr[idx].p[2])/3.0F;
00144
00145
00146
00147 if(secidx >= 0 && secidx < w*h)
00148 dptr[secidx] = (aptr[secidx].p[0] + aptr[secidx].p[1] + aptr[secidx].p[2])/3.0F;
00149 }
00150
00151
00152
00153 __global__ void cuda_global_luminance(const float3_t *aptr, float *dptr, const int w, const int h, const int tile_width, const int tile_height)
00154 {
00155
00156 const int idx = blockIdx.y*tile_height*w + threadIdx.y*w + blockIdx.x*tile_width + threadIdx.x;
00157
00158 cuda_device_luminance(aptr,dptr,w,h,idx,-1);
00159 }
00160
00161
00162
00163
00164 __device__ void cuda_device_luminanceNTSC(const float3_t *aptr, float *dptr, const int w, const int h, const int idx, const int secidx)
00165 {
00166
00167
00168
00169 const float coef1 = 0.298936F,coef2 = 0.587043F, coef3 = 0.114021F;;
00170 if(idx < w*h)
00171 dptr[idx] = roundf(aptr[idx].p[0]*coef1 + aptr[idx].p[1]*coef2 + aptr[idx].p[2]*coef3);
00172
00173
00174
00175 if(secidx >= 0 && secidx < w*h)
00176 dptr[secidx] = roundf(aptr[secidx].p[0]*coef1 + aptr[secidx].p[1]*coef2 + aptr[secidx].p[2]*coef3);
00177 }
00178
00179
00180
00181 __global__ void cuda_global_luminanceNTSC(const float3_t *aptr, float *dptr, const int w, const int h, const int tile_width, const int tile_height)
00182 {
00183
00184 const int idx = blockIdx.y*tile_height*w + threadIdx.y*w + blockIdx.x*tile_width + threadIdx.x;
00185
00186 cuda_device_luminanceNTSC(aptr,dptr,w,h,idx,-1);
00187 }
00188
00189 #endif