19 #ifndef MAGICKCORE_ACCELERATE_KERNELS_PRIVATE_H 20 #define MAGICKCORE_ACCELERATE_KERNELS_PRIVATE_H 22 #if defined(__cplusplus) || defined(c_plusplus) 26 #if defined(MAGICKCORE_OPENCL_SUPPORT) 31 #define OPENCL_DEFINE(VAR,...) "\n #""define " #VAR " " #__VA_ARGS__ " \n" 32 #define OPENCL_ELIF(...) "\n #""elif " #__VA_ARGS__ " \n" 33 #define OPENCL_ELSE() "\n #""else " " \n" 34 #define OPENCL_ENDIF() "\n #""endif " " \n" 35 #define OPENCL_IF(...) "\n #""if " #__VA_ARGS__ " \n" 36 #define STRINGIFY(...) #__VA_ARGS__ "\n" 38 const char* accelerateKernels =
52 OPENCL_DEFINE(
MagickMax(x, y), (((x) > (y)) ? (x) : (y)))
53 OPENCL_DEFINE(
MagickMin(x, y), (((x) < (y)) ? (x) : (y)))
274 inline CLQuantum ScaleCharToQuantum(
const unsigned char value)
276 return((CLQuantum) value);
283 inline CLQuantum ScaleCharToQuantum(
const unsigned char value)
285 return((CLQuantum) (257.0f*value));
292 inline CLQuantum ScaleCharToQuantum(
const unsigned char value)
294 return((CLQuantum) (16843009.0*value));
301 inline
int ClampToCanvas(const
int offset, const
int range)
303 return clamp(offset, (
int)0, range - 1);
308 inline int ClampToCanvasWithHalo(
const int offset,
const int range,
const int edge,
const int section)
310 return clamp(offset, section ? (
int)(0 - edge) : (
int)0, section ? (range - 1) : (range - 1 + edge));
317 return (CLQuantum)(clamp(value, 0.0f, (
float)
QuantumRange) + 0.5f);
322 inline uint ScaleQuantumToMap(CLQuantum value)
324 if (value >= (CLQuantum)
MaxMap)
327 return ((uint)value);
334 float sign = x < (float) 0.0 ? (
float)-1.0 : (float) 1.0;
342 return clamp(value, 0.0f, 1.0f);
348 inline CLQuantum getBlue(CLPixelType p) {
return p.x; }
349 inline void setBlue(CLPixelType* p, CLQuantum value) { (*p).x = value; }
350 inline float getBlueF4(float4 p) {
return p.x; }
351 inline void setBlueF4(float4* p,
float value) { (*p).x = value; }
353 inline CLQuantum getGreen(CLPixelType p) {
return p.y; }
354 inline void setGreen(CLPixelType* p, CLQuantum value) { (*p).y = value; }
355 inline float getGreenF4(float4 p) {
return p.y; }
356 inline void setGreenF4(float4* p,
float value) { (*p).y = value; }
358 inline CLQuantum getRed(CLPixelType p) {
return p.z; }
359 inline void setRed(CLPixelType* p, CLQuantum value) { (*p).z = value; }
360 inline float getRedF4(float4 p) {
return p.z; }
361 inline void setRedF4(float4* p,
float value) { (*p).z = value; }
363 inline CLQuantum getOpacity(CLPixelType p) {
return p.w; }
364 inline void setOpacity(CLPixelType* p, CLQuantum value) { (*p).w = value; }
365 inline float getOpacityF4(float4 p) {
return p.w; }
366 inline void setOpacityF4(float4* p,
float value) { (*p).w = value; }
368 inline void setGray(CLPixelType* p, CLQuantum value) { (*p).z = value; (*p).y = value; (*p).x = value; }
370 inline float GetPixelIntensity(
const int method,
const int colorspace, CLPixelType p)
372 float red = getRed(p);
373 float green = getGreen(p);
374 float blue = getBlue(p);
385 intensity = (red + green + blue) / 3.0;
401 intensity = (float)(((
float)red*red + green*green + blue*blue) /
415 intensity = 0.298839*red + 0.586811*green + 0.114350*blue;
428 intensity = 0.298839*red + 0.586811*green + 0.114350*blue;
442 intensity = 0.212656*red + 0.715158*green + 0.072186*blue;
455 intensity = 0.212656*red + 0.715158*green + 0.072186*blue;
460 intensity = (float)(sqrt((
float)red*red + green*green + blue*blue) /
493 ulong MWC_AddMod64(ulong a, ulong b, ulong M)
497 if( (v>=M) || (convert_float(v) < convert_float(a)) )
508 ulong MWC_MulMod64(ulong a, ulong b, ulong M)
513 r=MWC_AddMod64(r,b,M);
514 b=MWC_AddMod64(b,b,M);
525 ulong MWC_PowMod64(ulong a, ulong e, ulong M)
530 acc=MWC_MulMod64(acc,sqr,M);
531 sqr=MWC_MulMod64(sqr,sqr,M);
537 uint2 MWC_SkipImpl_Mod64(uint2 curr, ulong A, ulong M, ulong distance)
539 ulong m=MWC_PowMod64(A, distance, M);
540 ulong x=curr.x*(ulong)A+curr.y;
541 x=MWC_MulMod64(x, m, M);
542 return (uint2)((uint)(x/A), (uint)(x%A));
545 uint2 MWC_SeedImpl_Mod64(ulong A, ulong M, uint vecSize, uint vecOffset, ulong streamBase, ulong streamGap)
552 enum{ MWC_BASEID = 4077358422479273989UL };
554 ulong dist=streamBase + (get_global_id(0)*vecSize+vecOffset)*streamGap;
555 ulong m=MWC_PowMod64(A, dist, M);
557 ulong x=MWC_MulMod64(MWC_BASEID, m, M);
558 return (uint2)((uint)(x/A), (uint)(x%A));
562 typedef struct{ uint x; uint c; } mwc64x_state_t;
564 enum{ MWC64X_A = 4294883355U };
565 enum{ MWC64X_M = 18446383549859758079UL };
567 void MWC64X_Step(mwc64x_state_t *s)
571 uint Xn=MWC64X_A*X+C;
572 uint carry=(uint)(Xn<C);
573 uint Cn=mad_hi(MWC64X_A,X,carry);
579 void MWC64X_Skip(mwc64x_state_t *s, ulong distance)
581 uint2 tmp=MWC_SkipImpl_Mod64((uint2)(s->x,s->c), MWC64X_A, MWC64X_M, distance);
586 void MWC64X_SeedStreams(mwc64x_state_t *s, ulong baseOffset, ulong perStreamOffset)
588 uint2 tmp=MWC_SeedImpl_Mod64(MWC64X_A, MWC64X_M, 1, 0, baseOffset, perStreamOffset);
594 uint MWC64X_NextUint(mwc64x_state_t *s)
596 uint res=s->x ^ s->c;
605 float mwcReadPseudoRandomValue(mwc64x_state_t* rng) {
606 return (1.0f * MWC64X_NextUint(rng)) / (float)(0xffffffff);
610 float mwcGenerateDifferentialNoise(mwc64x_state_t* r, CLQuantum pixel, NoiseType noise_type,
float attenuate) {
619 alpha=mwcReadPseudoRandomValue(r);
635 beta=mwcReadPseudoRandomValue(r);
636 gamma=sqrt(-2.0f*log(alpha));
637 sigma=gamma*cospi((2.0f*beta));
638 tau=gamma*sinpi((2.0f*beta));
677 if (alpha > MagickEpsilon)
678 sigma=sqrt(-2.0f*log(alpha));
679 beta=mwcReadPseudoRandomValue(r);
681 cospi((
float) (2.0f*beta))/2.0f);
690 for (i=0; alpha > poisson; i++)
692 beta=mwcReadPseudoRandomValue(r);
709 void AddNoise(
const __global CLPixelType* inputImage, __global CLPixelType* filteredImage
710 ,
const unsigned int inputPixelCount,
const unsigned int pixelsPerWorkItem
712 ,
const NoiseType noise_type,
const float attenuate
713 ,
const unsigned int seed0,
const unsigned int seed1
714 ,
const unsigned int numRandomNumbersPerPixel) {
720 uint span = pixelsPerWorkItem * numRandomNumbersPerPixel;
721 uint offset = span * get_local_size(0) * get_group_id(0);
723 MWC64X_SeedStreams(&rng, offset, span);
725 uint pos = get_local_size(0) * get_group_id(0) * pixelsPerWorkItem + get_local_id(0);
727 uint count = pixelsPerWorkItem;
730 if (pos < inputPixelCount) {
731 CLPixelType p = inputImage[pos];
734 setRed(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getRed(p),noise_type,attenuate)));
738 setGreen(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getGreen(p),noise_type,attenuate)));
742 setBlue(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getBlue(p),noise_type,attenuate)));
746 setOpacity(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getOpacity(p),noise_type,attenuate)));
749 filteredImage[pos] = p;
752 pos += get_local_size(0);
778 __kernel
void BlurRow(__global CLPixelType *im, __global float4 *filtered_im,
779 const ChannelType channel, __constant
float *filter,
780 const unsigned int width,
781 const unsigned int imageColumns,
const unsigned int imageRows,
782 __local CLPixelType *temp)
784 const int x = get_global_id(0);
785 const int y = get_global_id(1);
787 const int columns = imageColumns;
789 const unsigned int radius = (width-1)/2;
790 const int wsize = get_local_size(0);
791 const unsigned int loadSize = wsize+width;
819 const int groupX=get_local_size(0)*get_group_id(0);
820 const int groupY=get_local_size(1)*get_group_id(1);
823 for (
int i=get_local_id(0); i < loadSize; i=i+get_local_size(0))
826 temp[i] = im[y * columns + ClampToCanvas(i+groupX-radius, columns)];
835 barrier(CLK_LOCAL_MEM_FENCE);
838 if (get_global_id(0) < columns)
841 float4 result = (float4) 0;
845 \n #ifndef UFACTOR \n
846 \n #define UFACTOR 8 \n
849 for ( ; i+UFACTOR < width; )
851 \n #pragma unroll UFACTOR\n
852 for (
int j=0; j < UFACTOR; j++, i++)
854 result+=filter[i]*convert_float4(temp[i+get_local_id(0)]);
858 for ( ; i < width; i++)
860 result+=filter[i]*convert_float4(temp[i+get_local_id(0)]);
869 filtered_im[y*columns+x] = result;
882 __kernel
void BlurColumn(
const __global float4 *blurRowData, __global CLPixelType *filtered_im,
883 const ChannelType channel, __constant
float *filter,
884 const unsigned int width,
885 const unsigned int imageColumns,
const unsigned int imageRows,
886 __local float4 *temp)
888 const int x = get_global_id(0);
889 const int y = get_global_id(1);
893 const int columns = imageColumns;
894 const int rows = imageRows;
896 unsigned int radius = (width-1)/2;
897 const int wsize = get_local_size(1);
898 const unsigned int loadSize = wsize+width;
901 const int groupX=get_local_size(0)*get_group_id(0);
902 const int groupY=get_local_size(1)*get_group_id(1);
907 for (
int i = get_local_id(1); i < loadSize; i=i+get_local_size(1))
909 temp[i] = blurRowData[ClampToCanvas(i+groupY-radius, rows) * columns + groupX];
913 barrier(CLK_LOCAL_MEM_FENCE);
916 if (get_global_id(1) < rows)
919 float4 result = (float4) 0;
923 \n #ifndef UFACTOR \n
924 \n #define UFACTOR 8 \n
927 for ( ; i+UFACTOR < width; )
929 \n #pragma unroll UFACTOR \n
930 for (
int j=0; j < UFACTOR; j++, i++)
932 result+=filter[i]*temp[i+get_local_id(1)];
936 for ( ; i < width; i++)
938 result+=filter[i]*temp[i+get_local_id(1)];
947 filtered_im[y*columns+x] = (CLPixelType) (result.x,result.y,result.z,result.w);
967 const float Sa,
const float Dca,
const float Da)
972 if ((Sca*Da+Dca*Sa) >= Sa*Da)
973 return(Sa*Da+Sca*(1.0-Da)+Dca*(1.0-Sa));
974 return(Dca*Sa*Sa/(Sa-Sca)+Sca*(1.0-Da)+Dca*(1.0-Sa));
1008 const float4 *q,float4 *composite) {
1019 gamma=
QuantumRange/(fabs(gamma) < MagickEpsilon ? MagickEpsilon : gamma);
1021 getRedF4(*q)*Da,Da));
1023 getGreenF4(*q)*Da,Da));
1025 getBlueF4(*q)*Da,Da));
1031 const float alpha,
const float4 *q,
1032 const float beta,float4 *composite)
1046 setOpacityF4(composite,(
float)
QuantumRange*(1.0-gamma));
1048 setRedF4(composite,gamma*(Sa*getRedF4(*p)+Da*getRedF4(*q)));
1049 setGreenF4(composite,gamma*(Sa*getGreenF4(*p)+Da*getGreenF4(*q)));
1050 setBlueF4(composite,gamma*(Sa*getBlueF4(*p)+Da*getBlueF4(*q)));
1056 const float alpha,
const float4 *q,
1057 const float beta,float4 *composite)
1067 void Composite(__global CLPixelType *image,
1068 const unsigned int imageWidth,
1069 const unsigned int imageHeight,
1070 const unsigned int imageMatte,
1071 const __global CLPixelType *compositeImage,
1072 const unsigned int compositeWidth,
1073 const unsigned int compositeHeight,
1074 const unsigned int compositeMatte,
1075 const unsigned int compose,
1077 const float destination_dissolve,
1078 const float source_dissolve) {
1081 index.x = get_global_id(0);
1082 index.y = get_global_id(1);
1085 if (index.x >= imageWidth
1086 || index.y >= imageHeight) {
1089 const CLPixelType inputPixel = image[index.y*imageWidth+index.x];
1091 setRedF4(&destination,getRed(inputPixel));
1092 setGreenF4(&destination,getGreen(inputPixel));
1093 setBlueF4(&destination,getBlue(inputPixel));
1096 const CLPixelType compositePixel
1097 = compositeImage[index.y*imageWidth+index.x];
1099 setRedF4(&source,getRed(compositePixel));
1100 setGreenF4(&source,getGreen(compositePixel));
1101 setBlueF4(&source,getBlue(compositePixel));
1103 if (imageMatte != 0) {
1104 setOpacityF4(&destination,getOpacity(inputPixel));
1107 setOpacityF4(&destination,0.0f);
1110 if (compositeMatte != 0) {
1111 setOpacityF4(&source,getOpacity(compositePixel));
1114 setOpacityF4(&source,0.0f);
1117 float4 composite=destination;
1126 destination_dissolve,&composite);
1133 CLPixelType outputPixel;
1137 setOpacity(&outputPixel,
ClampToQuantum(getOpacityF4(composite)));
1138 image[index.y*imageWidth+index.x] = outputPixel;
1157 float3 HueSaturationBrightness;
1158 HueSaturationBrightness.x = 0.0f;
1159 HueSaturationBrightness.y = 0.0f;
1160 HueSaturationBrightness.z = 0.0f;
1162 float r=(float) getRed(pixel);
1163 float g=(float) getGreen(pixel);
1164 float b=(float) getBlue(pixel);
1170 float delta=tmax-tmin;
1171 HueSaturationBrightness.y=delta/tmax;
1174 if (delta != 0.0f) {
1175 HueSaturationBrightness.x = ((r == tmax)?0.0f:((g == tmax)?2.0f:4.0f));
1176 HueSaturationBrightness.x += ((r == tmax)?(g-b):((g == tmax)?(b-r):(r-g)))/delta;
1177 HueSaturationBrightness.x/=6.0f;
1178 HueSaturationBrightness.x += (HueSaturationBrightness.x < 0.0f)?0.0f:1.0f;
1181 return HueSaturationBrightness;
1186 float hue = HueSaturationBrightness.x;
1187 float brightness = HueSaturationBrightness.z;
1188 float saturation = HueSaturationBrightness.y;
1192 if (saturation == 0.0f) {
1194 setGreen(&rgb,getRed(rgb));
1195 setBlue(&rgb,getRed(rgb));
1199 float h=6.0f*(hue-floor(hue));
1201 float p=brightness*(1.0f-saturation);
1202 float q=brightness*(1.0f-saturation*f);
1203 float t=brightness*(1.0f-(saturation*(1.0f-f)));
1210 setRed(&rgb, (ih == 1)?clamped_q:
1211 (ih == 2 || ih == 3)?clamped_p:
1212 (ih == 4)?clamped_t:
1215 setGreen(&rgb, (ih == 1 || ih == 2)?clampedBrightness:
1216 (ih == 3)?clamped_q:
1217 (ih == 4 || ih == 5)?clamped_p:
1220 setBlue(&rgb, (ih == 2)?clamped_t:
1221 (ih == 3 || ih == 4)?clampedBrightness:
1222 (ih == 5)?clamped_q:
1228 __kernel
void Contrast(__global CLPixelType *im,
const unsigned int sharpen)
1231 const int sign = sharpen!=0?1:-1;
1232 const int x = get_global_id(0);
1233 const int y = get_global_id(1);
1234 const int columns = get_global_size(0);
1235 const int c = x + y * columns;
1237 CLPixelType pixel = im[c];
1239 float brightness = HueSaturationBrightness.z;
1240 brightness+=0.5f*sign*(0.5f*(sinpi(brightness-0.5f)+1.0f)-brightness);
1241 brightness = clamp(brightness,0.0f,1.0f);
1242 HueSaturationBrightness.z = brightness;
1245 filteredPixel.w = pixel.w;
1246 im[c] = filteredPixel;
1265 __kernel
void Histogram(__global CLPixelType * restrict im,
1268 const int colorspace,
1269 __global uint4 * restrict histogram)
1271 const int x = get_global_id(0);
1272 const int y = get_global_id(1);
1273 const int columns = get_global_size(0);
1274 const int c = x + y * columns;
1279 atomic_inc((__global uint *)(&(histogram[pos]))+2);
1292 __kernel
void ContrastStretch(__global CLPixelType * restrict im,
1294 __global CLPixelType * restrict stretch_map,
1295 const float4 white,
const float4 black)
1297 const int x = get_global_id(0);
1298 const int y = get_global_id(1);
1299 const int columns = get_global_size(0);
1300 const int c = x + y * columns;
1303 CLPixelType oValue, eValue;
1304 CLQuantum red, green, blue, opacity;
1309 if ((channel & RedChannel) != 0)
1311 if (getRedF4(white) != getRedF4(black))
1313 ePos = ScaleQuantumToMap(getRed(oValue));
1314 eValue = stretch_map[ePos];
1315 red = getRed(eValue);
1319 if ((channel & GreenChannel) != 0)
1321 if (getGreenF4(white) != getGreenF4(black))
1323 ePos = ScaleQuantumToMap(getGreen(oValue));
1324 eValue = stretch_map[ePos];
1325 green = getGreen(eValue);
1329 if ((channel & BlueChannel) != 0)
1331 if (getBlueF4(white) != getBlueF4(black))
1333 ePos = ScaleQuantumToMap(getBlue(oValue));
1334 eValue = stretch_map[ePos];
1335 blue = getBlue(eValue);
1339 if ((channel & OpacityChannel) != 0)
1341 if (getOpacityF4(white) != getOpacityF4(black))
1343 ePos = ScaleQuantumToMap(getOpacity(oValue));
1344 eValue = stretch_map[ePos];
1345 opacity = getOpacity(eValue);
1350 im[c]=(CLPixelType)(blue, green, red, opacity);
1369 void ConvolveOptimized(
const __global CLPixelType *input, __global CLPixelType *output,
1370 const unsigned int imageWidth,
const unsigned int imageHeight,
1371 __constant
float *filter,
const unsigned int filterWidth,
const unsigned int filterHeight,
1372 const uint matte,
const ChannelType channel, __local CLPixelType *pixelLocalCache, __local
float* filterCache) {
1375 blockID.x = get_group_id(0);
1376 blockID.y = get_group_id(1);
1380 imageAreaOrg.x = blockID.x * get_local_size(0);
1381 imageAreaOrg.y = blockID.y * get_local_size(1);
1383 int2 midFilterDimen;
1384 midFilterDimen.x = (filterWidth-1)/2;
1385 midFilterDimen.y = (filterHeight-1)/2;
1387 int2 cachedAreaOrg = imageAreaOrg - midFilterDimen;
1390 int2 cachedAreaDimen;
1391 cachedAreaDimen.x = get_local_size(0) + filterWidth - 1;
1392 cachedAreaDimen.y = get_local_size(1) + filterHeight - 1;
1395 int localID = get_local_id(1)*get_local_size(0)+get_local_id(0);
1396 int cachedAreaNumPixels = cachedAreaDimen.x * cachedAreaDimen.y;
1397 int groupSize = get_local_size(0) * get_local_size(1);
1398 for (
int i = localID; i < cachedAreaNumPixels; i+=groupSize) {
1400 int2 cachedAreaIndex;
1401 cachedAreaIndex.x = i % cachedAreaDimen.x;
1402 cachedAreaIndex.y = i / cachedAreaDimen.x;
1404 int2 imagePixelIndex;
1405 imagePixelIndex = cachedAreaOrg + cachedAreaIndex;
1409 imagePixelIndex.x = ClampToCanvas(imagePixelIndex.x, imageWidth);
1410 imagePixelIndex.y = ClampToCanvas(imagePixelIndex.y, imageHeight);
1412 pixelLocalCache[i] = input[imagePixelIndex.y * imageWidth + imagePixelIndex.x];
1416 for (
int i = localID; i < filterHeight*filterWidth; i+=groupSize) {
1417 filterCache[i] = filter[i];
1419 barrier(CLK_LOCAL_MEM_FENCE);
1423 imageIndex.x = imageAreaOrg.x + get_local_id(0);
1424 imageIndex.y = imageAreaOrg.y + get_local_id(1);
1427 if (imageIndex.x >= imageWidth
1428 || imageIndex.y >= imageHeight) {
1432 int filterIndex = 0;
1433 float4 sum = (float4)0.0f;
1435 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
1436 int cacheIndexY = get_local_id(1);
1437 for (
int j = 0; j < filterHeight; j++) {
1438 int cacheIndexX = get_local_id(0);
1439 for (
int i = 0; i < filterWidth; i++) {
1440 CLPixelType p = pixelLocalCache[cacheIndexY*cachedAreaDimen.x + cacheIndexX];
1441 float f = filterCache[filterIndex];
1456 int cacheIndexY = get_local_id(1);
1457 for (
int j = 0; j < filterHeight; j++) {
1458 int cacheIndexX = get_local_id(0);
1459 for (
int i = 0; i < filterWidth; i++) {
1461 CLPixelType p = pixelLocalCache[cacheIndexY*cachedAreaDimen.x + cacheIndexX];
1463 float f = filterCache[filterIndex];
1464 float g = alpha * f;
1478 sum.xyz = gamma*sum.xyz;
1480 CLPixelType outputPixel;
1486 output[imageIndex.y * imageWidth + imageIndex.x] = outputPixel;
1492 void Convolve(
const __global CLPixelType *input, __global CLPixelType *output,
1493 const uint imageWidth,
const uint imageHeight,
1494 __constant
float *filter,
const unsigned int filterWidth,
const unsigned int filterHeight,
1498 imageIndex.x = get_global_id(0);
1499 imageIndex.y = get_global_id(1);
1505 if (imageIndex.x >= imageWidth
1506 || imageIndex.y >= imageHeight)
1509 int2 midFilterDimen;
1510 midFilterDimen.x = (filterWidth-1)/2;
1511 midFilterDimen.y = (filterHeight-1)/2;
1513 int filterIndex = 0;
1514 float4 sum = (float4)0.0f;
1516 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
1517 for (
int j = 0; j < filterHeight; j++) {
1518 int2 inputPixelIndex;
1519 inputPixelIndex.y = imageIndex.y - midFilterDimen.y + j;
1520 inputPixelIndex.y = ClampToCanvas(inputPixelIndex.y, imageHeight);
1521 for (
int i = 0; i < filterWidth; i++) {
1522 inputPixelIndex.x = imageIndex.x - midFilterDimen.x + i;
1523 inputPixelIndex.x = ClampToCanvas(inputPixelIndex.x, imageWidth);
1525 CLPixelType p = input[inputPixelIndex.y * imageWidth + inputPixelIndex.x];
1526 float f = filter[filterIndex];
1541 for (
int j = 0; j < filterHeight; j++) {
1542 int2 inputPixelIndex;
1543 inputPixelIndex.y = imageIndex.y - midFilterDimen.y + j;
1544 inputPixelIndex.y = ClampToCanvas(inputPixelIndex.y, imageHeight);
1545 for (
int i = 0; i < filterWidth; i++) {
1546 inputPixelIndex.x = imageIndex.x - midFilterDimen.x + i;
1547 inputPixelIndex.x = ClampToCanvas(inputPixelIndex.x, imageWidth);
1549 CLPixelType p = input[inputPixelIndex.y * imageWidth + inputPixelIndex.x];
1551 float f = filter[filterIndex];
1552 float g = alpha * f;
1566 sum.xyz = gamma*sum.xyz;
1569 CLPixelType outputPixel;
1575 output[imageIndex.y * imageWidth + imageIndex.x] = outputPixel;
1593 __kernel
void HullPass1(
const __global CLPixelType *inputImage, __global CLPixelType *outputImage
1594 ,
const unsigned int imageWidth,
const unsigned int imageHeight
1595 ,
const int2 offset,
const int polarity,
const int matte) {
1597 int x = get_global_id(0);
1598 int y = get_global_id(1);
1600 CLPixelType v = inputImage[y*imageWidth+x];
1603 neighbor.y = y + offset.y;
1604 neighbor.x = x + offset.x;
1606 int2 clampedNeighbor;
1607 clampedNeighbor.x = ClampToCanvas(neighbor.x, imageWidth);
1608 clampedNeighbor.y = ClampToCanvas(neighbor.y, imageHeight);
1610 CLPixelType r = (clampedNeighbor.x == neighbor.x
1611 && clampedNeighbor.y == neighbor.y)?inputImage[clampedNeighbor.y*imageWidth+clampedNeighbor.x]
1627 \n #pragma unroll 4\n
1628 for (
unsigned int i = 0; i < 4; i++) {
1629 sv[i] = (sr[i] >= (sv[i]+ScaleCharToQuantum(2)))?(sv[i]+ScaleCharToQuantum(1)):sv[i];
1633 \n #pragma unroll 4\n
1634 for (
unsigned int i = 0; i < 4; i++) {
1635 sv[i] = (sr[i] <= (sv[i]-ScaleCharToQuantum(2)))?(sv[i]-ScaleCharToQuantum(1)):sv[i];
1640 v.x = (CLQuantum)sv[0];
1641 v.y = (CLQuantum)sv[1];
1642 v.z = (CLQuantum)sv[2];
1645 v.w = (CLQuantum)sv[3];
1647 outputImage[y*imageWidth+x] = v;
1658 __kernel
void HullPass2(
const __global CLPixelType *inputImage, __global CLPixelType *outputImage
1659 ,
const unsigned int imageWidth,
const unsigned int imageHeight
1660 ,
const int2 offset,
const int polarity,
const int matte) {
1662 int x = get_global_id(0);
1663 int y = get_global_id(1);
1665 CLPixelType v = inputImage[y*imageWidth+x];
1667 int2 neighbor, clampedNeighbor;
1669 neighbor.y = y + offset.y;
1670 neighbor.x = x + offset.x;
1671 clampedNeighbor.x = ClampToCanvas(neighbor.x, imageWidth);
1672 clampedNeighbor.y = ClampToCanvas(neighbor.y, imageHeight);
1674 CLPixelType r = (clampedNeighbor.x == neighbor.x
1675 && clampedNeighbor.y == neighbor.y)?inputImage[clampedNeighbor.y*imageWidth+clampedNeighbor.x]
1679 neighbor.y = y - offset.y;
1680 neighbor.x = x - offset.x;
1681 clampedNeighbor.x = ClampToCanvas(neighbor.x, imageWidth);
1682 clampedNeighbor.y = ClampToCanvas(neighbor.y, imageHeight);
1684 CLPixelType s = (clampedNeighbor.x == neighbor.x
1685 && clampedNeighbor.y == neighbor.y)?inputImage[clampedNeighbor.y*imageWidth+clampedNeighbor.x]
1708 \n #pragma unroll 4\n
1709 for (
unsigned int i = 0; i < 4; i++) {
1714 sv[i] =(( (int)( ss[i] < (sv[i]+ScaleCharToQuantum(2))) + (int) ( sr[i] <= sv[i] ) ) !=0) ? sv[i]:(sv[i]+ScaleCharToQuantum(1));
1718 \n #pragma unroll 4\n
1719 for (
unsigned int i = 0; i < 4; i++) {
1723 sv[i] = (( (int)(ss[i] > (sv[i]-ScaleCharToQuantum(2))) + (int)( sr[i] >= sv[i] )) !=0) ? sv[i]:(sv[i]-ScaleCharToQuantum(1));
1727 v.x = (CLQuantum)sv[0];
1728 v.y = (CLQuantum)sv[1];
1729 v.z = (CLQuantum)sv[2];
1732 v.w = (CLQuantum)sv[3];
1734 outputImage[y*imageWidth+x] = v;
1756 __kernel
void Equalize(__global CLPixelType * restrict im,
1758 __global CLPixelType * restrict equalize_map,
1759 const float4 white,
const float4 black)
1761 const int x = get_global_id(0);
1762 const int y = get_global_id(1);
1763 const int columns = get_global_size(0);
1764 const int c = x + y * columns;
1767 CLPixelType oValue, eValue;
1768 CLQuantum red, green, blue, opacity;
1773 if ((channel & SyncChannels) != 0)
1775 if (getRedF4(white) != getRedF4(black))
1777 ePos = ScaleQuantumToMap(getRed(oValue));
1778 eValue = equalize_map[ePos];
1779 red = getRed(eValue);
1780 ePos = ScaleQuantumToMap(getGreen(oValue));
1781 eValue = equalize_map[ePos];
1782 green = getRed(eValue);
1783 ePos = ScaleQuantumToMap(getBlue(oValue));
1784 eValue = equalize_map[ePos];
1785 blue = getRed(eValue);
1786 ePos = ScaleQuantumToMap(getOpacity(oValue));
1787 eValue = equalize_map[ePos];
1788 opacity = getRed(eValue);
1791 im[c]=(CLPixelType)(blue, green, red, opacity);
1819 CLPixelType
ApplyFunction(CLPixelType pixel,
const MagickFunction
function,
1820 const unsigned int number_parameters,
1821 __constant
float *parameters)
1823 float4 result = (float4) 0.0f;
1828 for (
unsigned int i=0; i < number_parameters; i++)
1829 result = result*(float4)
QuantumScale*convert_float4(pixel) + parameters[i];
1835 float freq,phase,ampl,bias;
1836 freq = ( number_parameters >= 1 ) ? parameters[0] : 1.0f;
1837 phase = ( number_parameters >= 2 ) ? parameters[1] : 0.0f;
1838 ampl = ( number_parameters >= 3 ) ? parameters[2] : 0.5f;
1839 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5f;
1841 (freq*
QuantumScale*(
float)pixel.x + phase/360.0f)) + bias);
1843 (freq*
QuantumScale*(
float)pixel.y + phase/360.0f)) + bias);
1845 (freq*
QuantumScale*(
float)pixel.z + phase/360.0f)) + bias);
1847 (freq*
QuantumScale*(
float)pixel.w + phase/360.0f)) + bias);
1852 float width,range,center,bias;
1853 width = ( number_parameters >= 1 ) ? parameters[0] : 1.0f;
1854 center = ( number_parameters >= 2 ) ? parameters[1] : 0.5f;
1855 range = ( number_parameters >= 3 ) ? parameters[2] : 1.0f;
1856 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5f;
1858 result.x = 2.0f/width*(
QuantumScale*(float)pixel.x - center);
1859 result.x = range/
MagickPI*asin(result.x)+bias;
1860 result.x = ( result.x <= -1.0f ) ? bias - range/2.0f : result.x;
1861 result.x = ( result.x >= 1.0f ) ? bias + range/2.0f : result.x;
1863 result.y = 2.0f/width*(
QuantumScale*(float)pixel.y - center);
1864 result.y = range/
MagickPI*asin(result.y)+bias;
1865 result.y = ( result.y <= -1.0f ) ? bias - range/2.0f : result.y;
1866 result.y = ( result.y >= 1.0f ) ? bias + range/2.0f : result.y;
1868 result.z = 2.0f/width*(
QuantumScale*(float)pixel.z - center);
1869 result.z = range/
MagickPI*asin(result.z)+bias;
1870 result.z = ( result.z <= -1.0f ) ? bias - range/2.0f : result.x;
1871 result.z = ( result.z >= 1.0f ) ? bias + range/2.0f : result.x;
1874 result.w = 2.0f/width*(
QuantumScale*(float)pixel.w - center);
1875 result.w = range/
MagickPI*asin(result.w)+bias;
1876 result.w = ( result.w <= -1.0f ) ? bias - range/2.0f : result.w;
1877 result.w = ( result.w >= 1.0f ) ? bias + range/2.0f : result.w;
1884 float slope,range,center,bias;
1885 slope = ( number_parameters >= 1 ) ? parameters[0] : 1.0f;
1886 center = ( number_parameters >= 2 ) ? parameters[1] : 0.5f;
1887 range = ( number_parameters >= 3 ) ? parameters[2] : 1.0f;
1888 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5f;
1889 result = (float4)
MagickPI*(float4)slope*((float4)
QuantumScale*convert_float4(pixel)-(float4)center);
1909 __kernel
void ComputeFunction(__global CLPixelType *im,
1910 const ChannelType channel,
const MagickFunction
function,
1911 const unsigned int number_parameters, __constant
float *parameters)
1913 const int x = get_global_id(0);
1914 const int y = get_global_id(1);
1915 const int columns = get_global_size(0);
1916 const int c = x + y * columns;
1917 im[c] =
ApplyFunction(im[c],
function, number_parameters, parameters);
1934 __kernel
void Grayscale(__global CLPixelType *im,
1935 const int method,
const int colorspace)
1938 const int x = get_global_id(0);
1939 const int y = get_global_id(1);
1940 const int columns = get_global_size(0);
1941 const int c = x + y * columns;
1943 CLPixelType pixel = im[c];
1951 red=(float)getRed(pixel);
1952 green=(float)getGreen(pixel);
1953 blue=(float)getBlue(pixel);
1957 CLPixelType filteredPixel;
1963 intensity=(red+green+blue)/3.0;
1979 intensity=(float) (((
float) red*red+green*green+
1993 intensity=0.298839*red+0.586811*green+0.114350*blue;
2006 intensity=0.298839*red+0.586811*green+0.114350*blue;
2020 intensity=0.212656*red+0.715158*green+0.072186*blue;
2033 intensity=0.212656*red+0.715158*green+0.072186*blue;
2038 intensity=(float) (sqrt((
float) red*red+green*green+
2039 blue*blue)/sqrt(3.0));
2047 filteredPixel.w = pixel.w;
2049 im[c] = filteredPixel;
2066 inline int mirrorBottom(
int value)
2068 return (value < 0) ? - (value) : value;
2070 inline int mirrorTop(
int value,
int width)
2072 return (value >= width) ? (2 * width - value - 1) : value;
2075 __kernel
void LocalContrastBlurRow(__global CLPixelType *srcImage, __global CLPixelType *dstImage, __global
float *tmpImage,
2077 const int imageWidth,
2078 const int imageHeight)
2080 const float4 RGB = ((float4)(0.2126f, 0.7152f, 0.0722f, 0.0f));
2082 int x = get_local_id(0);
2083 int y = get_global_id(1);
2085 if ((x >= imageWidth) || (y >= imageHeight))
2088 global CLPixelType *src = srcImage + y * imageWidth;
2090 for (
int i = x; i < imageWidth; i += get_local_size(0)) {
2092 float weight = 1.0f;
2095 while ((j + 7) < i) {
2096 for (
int k = 0; k < 8; ++k)
2097 sum += (weight + k) * dot(RGB, convert_float4(src[mirrorBottom(j+k)]));
2102 sum += weight * dot(RGB, convert_float4(src[mirrorBottom(j)]));
2107 while ((j + 7) < radius + i) {
2108 for (
int k = 0; k < 8; ++k)
2109 sum += (weight - k) * dot(RGB, convert_float4(src[mirrorTop(j + k, imageWidth)]));
2113 while (j < radius + i) {
2114 sum += weight * dot(RGB, convert_float4(src[mirrorTop(j, imageWidth)]));
2119 tmpImage[i + y * imageWidth] = sum / ((radius + 1) * (radius + 1));
2125 __kernel
void LocalContrastBlurApplyColumn(__global CLPixelType *srcImage, __global CLPixelType *dstImage, __global
float *blurImage,
2127 const float strength,
2128 const int imageWidth,
2129 const int imageHeight)
2131 const float4 RGB = (float4)(0.2126f, 0.7152f, 0.0722f, 0.0f);
2133 int x = get_global_id(0);
2134 int y = get_global_id(1);
2136 if ((x >= imageWidth) || (y >= imageHeight))
2139 global
float *src = blurImage + x;
2142 float weight = 1.0f;
2145 while ((j + 7) < y) {
2146 for (
int k = 0; k < 8; ++k)
2147 sum += (weight + k) * src[mirrorBottom(j+k) * imageWidth];
2152 sum += weight * src[mirrorBottom(j) * imageWidth];
2157 while ((j + 7) < radius + y) {
2158 for (
int k = 0; k < 8; ++k)
2159 sum += (weight - k) * src[mirrorTop(j + k, imageHeight) * imageWidth];
2163 while (j < radius + y) {
2164 sum += weight * src[mirrorTop(j, imageHeight) * imageWidth];
2169 CLPixelType pixel = srcImage[x + y * imageWidth];
2170 float srcVal = dot(RGB, convert_float4(pixel));
2171 float mult = (srcVal - (sum / ((radius + 1) * (radius + 1)))) * (strength / 100.0f);
2172 mult = (srcVal + mult) / srcVal;
2178 dstImage[x + y * imageWidth] = pixel;
2196 inline void ConvertRGBToHSL(
const CLQuantum red,
const CLQuantum green,
const CLQuantum blue,
2197 float *hue,
float *saturation,
float *lightness)
2212 *lightness=(tmax+tmin)/2.0;
2233 if (*lightness <= 0.5)
2234 *saturation=c/(2.0*(*lightness));
2236 *saturation=c/(2.0-2.0*(*lightness));
2239 inline void ConvertHSLToRGB(
const float hue,
const float saturation,
const float lightness,
2240 CLQuantum *red,CLQuantum *green,CLQuantum *blue)
2255 if (lightness <= 0.5)
2256 c=2.0*lightness*saturation;
2258 c=(2.0-2.0*lightness)*saturation;
2259 tmin=lightness-0.5*c;
2260 h-=360.0*floor(h/360.0);
2262 x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
2263 switch ((
int) floor(h) % 6)
2319 inline void ModulateHSL(
const float percent_hue,
const float percent_saturation,
const float percent_lightness,
2320 CLQuantum *red,CLQuantum *green,CLQuantum *blue)
2331 hue+=0.5*(0.01*percent_hue-1.0);
2336 saturation*=0.01*percent_saturation;
2337 lightness*=0.01*percent_lightness;
2341 __kernel
void Modulate(__global CLPixelType *im,
2342 const float percent_brightness,
2343 const float percent_hue,
2344 const float percent_saturation,
2345 const int colorspace)
2348 const int x = get_global_id(0);
2349 const int y = get_global_id(1);
2350 const int columns = get_global_size(0);
2351 const int c = x + y * columns;
2353 CLPixelType pixel = im[c];
2361 green=getGreen(pixel);
2362 blue=getBlue(pixel);
2369 ModulateHSL(percent_hue, percent_saturation, percent_brightness,
2370 &red, &green, &blue);
2375 CLPixelType filteredPixel;
2377 setRed(&filteredPixel, red);
2378 setGreen(&filteredPixel, green);
2379 setBlue(&filteredPixel, blue);
2380 filteredPixel.w = pixel.w;
2382 im[c] = filteredPixel;
2400 void MotionBlur(
const __global CLPixelType *input, __global CLPixelType *output,
2401 const unsigned int imageWidth,
const unsigned int imageHeight,
2402 const __global
float *filter,
const unsigned int width,
const __global int2* offset,
2404 const ChannelType channel,
const unsigned int matte) {
2407 currentPixel.x = get_global_id(0);
2408 currentPixel.y = get_global_id(1);
2410 if (currentPixel.x >= imageWidth
2411 || currentPixel.y >= imageHeight)
2415 pixel.x = (float)bias.x;
2416 pixel.y = (
float)bias.y;
2417 pixel.z = (float)bias.z;
2418 pixel.w = (
float)bias.w;
2420 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
2422 for (
int i = 0; i < width; i++) {
2425 int2 samplePixel = currentPixel + offset[i];
2426 samplePixel.x = ClampToCanvas(samplePixel.x, imageWidth);
2427 samplePixel.y = ClampToCanvas(samplePixel.y, imageHeight);
2428 CLPixelType samplePixelValue = input[ samplePixel.y * imageWidth + samplePixel.x];
2430 pixel.x += (filter[i] * (float)samplePixelValue.x);
2431 pixel.y += (filter[i] * (float)samplePixelValue.y);
2432 pixel.z += (filter[i] * (float)samplePixelValue.z);
2433 pixel.w += (filter[i] * (float)samplePixelValue.w);
2436 CLPixelType outputPixel;
2441 output[currentPixel.y * imageWidth + currentPixel.x] = outputPixel;
2446 for (
int i = 0; i < width; i++) {
2449 int2 samplePixel = currentPixel + offset[i];
2450 samplePixel.x = ClampToCanvas(samplePixel.x, imageWidth);
2451 samplePixel.y = ClampToCanvas(samplePixel.y, imageHeight);
2453 CLPixelType samplePixelValue = input[ samplePixel.y * imageWidth + samplePixel.x];
2456 float k = filter[i];
2457 pixel.x = pixel.x + k * alpha * samplePixelValue.x;
2458 pixel.y = pixel.y + k * alpha * samplePixelValue.y;
2459 pixel.z = pixel.z + k * alpha * samplePixelValue.z;
2461 pixel.w += k * alpha * samplePixelValue.w;
2466 pixel.xyz = gamma*pixel.xyz;
2468 CLPixelType outputPixel;
2473 output[currentPixel.y * imageWidth + currentPixel.x] = outputPixel;
2491 __kernel
void RadialBlur(
const __global CLPixelType *im, __global CLPixelType *filtered_im,
2493 const unsigned int channel,
const unsigned int matte,
2494 const float2 blurCenter,
2495 __constant
float *cos_theta, __constant
float *sin_theta,
2496 const unsigned int cossin_theta_size)
2498 const int x = get_global_id(0);
2499 const int y = get_global_id(1);
2500 const int columns = get_global_size(0);
2501 const int rows = get_global_size(1);
2502 unsigned int step = 1;
2503 float center_x = (float) x - blurCenter.x;
2504 float center_y = (
float) y - blurCenter.y;
2505 float radius = hypot(center_x, center_y);
2508 float blur_radius = hypot(blurCenter.x, blurCenter.y);
2510 if (radius > MagickEpsilon)
2512 step = (
unsigned int) (blur_radius / radius);
2515 if (step >= cossin_theta_size)
2516 step = cossin_theta_size-1;
2520 result.x = (float)bias.x;
2521 result.y = (
float)bias.y;
2522 result.z = (float)bias.z;
2523 result.w = (
float)bias.w;
2524 float normalize = 0.0f;
2526 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
2527 for (
unsigned int i=0; i<cossin_theta_size; i+=step)
2529 result += convert_float4(im[
2530 ClampToCanvas(blurCenter.x+center_x*cos_theta[i]-center_y*sin_theta[i]+0.5f,columns)+
2531 ClampToCanvas(blurCenter.y+center_x*sin_theta[i]+center_y*cos_theta[i]+0.5f, rows)*columns]);
2535 result = result * normalize;
2539 for (
unsigned int i=0; i<cossin_theta_size; i+=step)
2541 float4 p = convert_float4(im[
2542 ClampToCanvas(blurCenter.x+center_x*cos_theta[i]-center_y*sin_theta[i]+0.5f,columns)+
2543 ClampToCanvas(blurCenter.y+center_x*sin_theta[i]+center_y*cos_theta[i]+0.5f, rows)*columns]);
2546 result.x += alpha * p.x;
2547 result.y += alpha * p.y;
2548 result.z += alpha * p.z;
2555 result.x = gamma*result.x;
2556 result.y = gamma*result.y;
2557 result.z = gamma*result.z;
2558 result.w = normalize*result.w;
2579 float BoxResizeFilter(
const float x)
2587 float CubicBC(
const float x,
const __global
float* resizeFilterCoefficients)
2619 return(resizeFilterCoefficients[0]+x*(x*
2620 (resizeFilterCoefficients[1]+x*resizeFilterCoefficients[2])));
2622 return(resizeFilterCoefficients[3]+x*(resizeFilterCoefficients[4]+x*
2623 (resizeFilterCoefficients[5]+x*resizeFilterCoefficients[6])));
2629 float Sinc(
const float x)
2633 const float alpha=(float) (
MagickPI*x);
2634 return sinpi(x)/alpha;
2648 return ((x<1.0f)?(1.0f-x):0.0f);
2660 const float cosine=cos((
MagickPI*x));
2661 return(0.5f+0.5f*cosine);
2672 const float cosine=cos((
MagickPI*x));
2673 return(0.54f+0.46f*cosine);
2687 const float cosine=cos((
MagickPI*x));
2688 return(0.34f+cosine*(0.5f+cosine*0.16f));
2696 inline float applyResizeFilter(
const float x,
const ResizeWeightingFunctionType filterType,
const __global
float* filterCoefficients)
2706 return CubicBC(x,filterCoefficients);
2708 return BoxResizeFilter(x);
2726 inline float getResizeFilterWeight(
const __global
float* resizeFilterCubicCoefficients,
const ResizeWeightingFunctionType resizeFilterType
2727 ,
const ResizeWeightingFunctionType resizeWindowType
2728 ,
const float resizeFilterScale,
const float resizeWindowSupport,
const float resizeFilterBlur,
const float x)
2731 float xBlur = fabs(x/resizeFilterBlur);
2732 if (resizeWindowSupport < MagickEpsilon
2739 scale = resizeFilterScale;
2740 scale = applyResizeFilter(xBlur*scale, resizeWindowType, resizeFilterCubicCoefficients);
2742 float weight = scale * applyResizeFilter(xBlur, resizeFilterType, resizeFilterCubicCoefficients);
2749 const char* accelerateKernels2 =
2753 inline unsigned int getNumWorkItemsPerPixel(
const unsigned int pixelPerWorkgroup,
const unsigned int numWorkItems) {
2754 return (numWorkItems/pixelPerWorkgroup);
2759 inline int pixelToCompute(
const unsigned itemID,
const unsigned int pixelPerWorkgroup,
const unsigned int numWorkItems) {
2760 const unsigned int numWorkItemsPerPixel = getNumWorkItemsPerPixel(pixelPerWorkgroup, numWorkItems);
2761 int pixelIndex = itemID/numWorkItemsPerPixel;
2762 pixelIndex = (pixelIndex<pixelPerWorkgroup)?pixelIndex:-1;
2769 __kernel __attribute__((reqd_work_group_size(256, 1, 1)))
2770 void ResizeHorizontalFilter(
const __global CLPixelType* inputImage,
const unsigned int inputColumns,
const unsigned int inputRows,
const unsigned int matte
2771 ,
const float xFactor, __global CLPixelType* filteredImage,
const unsigned int filteredColumns,
const unsigned int filteredRows
2772 ,
const int resizeFilterType,
const int resizeWindowType
2773 ,
const __global
float* resizeFilterCubicCoefficients
2774 ,
const float resizeFilterScale,
const float resizeFilterSupport,
const float resizeFilterWindowSupport,
const float resizeFilterBlur
2775 , __local CLPixelType* inputImageCache,
const int numCachedPixels,
const unsigned int pixelPerWorkgroup,
const unsigned int pixelChunkSize
2776 , __local float4* outputPixelCache, __local
float* densityCache, __local
float* gammaCache) {
2780 const unsigned int startX = get_group_id(0)*pixelPerWorkgroup;
2781 const unsigned int stopX =
MagickMin(startX + pixelPerWorkgroup,filteredColumns);
2782 const unsigned int actualNumPixelToCompute = stopX - startX;
2785 float scale =
MagickMax(1.0f/xFactor+MagickEpsilon ,1.0f);
2786 const float support =
MagickMax(scale*resizeFilterSupport,0.5f);
2789 const int cacheRangeStartX =
MagickMax((
int)((startX+0.5f)/xFactor+MagickEpsilon-support+0.5f),(
int)(0));
2790 const int cacheRangeEndX =
MagickMin((
int)(cacheRangeStartX + numCachedPixels), (
int)inputColumns);
2793 const unsigned int y = get_global_id(1);
2794 event_t e = async_work_group_copy(inputImageCache,inputImage+y*inputColumns+cacheRangeStartX,cacheRangeEndX-cacheRangeStartX,0);
2795 wait_group_events(1,&e);
2797 unsigned int totalNumChunks = (actualNumPixelToCompute+pixelChunkSize-1)/pixelChunkSize;
2798 for (
unsigned int chunk = 0; chunk < totalNumChunks; chunk++)
2801 const unsigned int chunkStartX = startX + chunk*pixelChunkSize;
2802 const unsigned int chunkStopX =
MagickMin(chunkStartX + pixelChunkSize, stopX);
2803 const unsigned int actualNumPixelInThisChunk = chunkStopX - chunkStartX;
2806 const unsigned int itemID = get_local_id(0);
2807 const unsigned int numItems = getNumWorkItemsPerPixel(actualNumPixelInThisChunk, get_local_size(0));
2809 const int pixelIndex = pixelToCompute(itemID, actualNumPixelInThisChunk, get_local_size(0));
2811 float4 filteredPixel = (float4)0.0f;
2812 float density = 0.0f;
2815 if (pixelIndex != -1) {
2818 const int x = chunkStartX + pixelIndex;
2822 const unsigned int start = (
unsigned int)
MagickMax(bisect-support+0.5f,0.0f);
2823 const unsigned int stop = (
unsigned int)
MagickMin(bisect+support+0.5f,(
float)inputColumns);
2824 const unsigned int n = stop - start;
2827 unsigned int numStepsPerWorkItem = n / numItems;
2828 numStepsPerWorkItem += ((numItems*numStepsPerWorkItem)==n?0:1);
2830 const unsigned int startStep = (itemID%numItems)*numStepsPerWorkItem;
2831 if (startStep < n) {
2832 const unsigned int stopStep =
MagickMin(startStep+numStepsPerWorkItem, n);
2834 unsigned int cacheIndex = start+startStep-cacheRangeStartX;
2837 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
2838 float4 cp = convert_float4(inputImageCache[cacheIndex]);
2840 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
2841 , (ResizeWeightingFunctionType)resizeWindowType
2842 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
2844 filteredPixel += ((float4)weight)*cp;
2851 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
2852 CLPixelType p = inputImageCache[cacheIndex];
2854 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
2855 , (ResizeWeightingFunctionType)resizeWindowType
2856 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
2859 float4 cp = convert_float4(p);
2861 filteredPixel.x += alpha * cp.x;
2862 filteredPixel.y += alpha * cp.y;
2863 filteredPixel.z += alpha * cp.z;
2864 filteredPixel.w += weight * cp.w;
2874 if (itemID < actualNumPixelInThisChunk) {
2875 outputPixelCache[itemID] = (float4)0.0f;
2876 densityCache[itemID] = 0.0f;
2878 gammaCache[itemID] = 0.0f;
2880 barrier(CLK_LOCAL_MEM_FENCE);
2883 for (
unsigned int i = 0; i < numItems; i++) {
2884 if (pixelIndex != -1) {
2885 if (itemID%numItems == i) {
2886 outputPixelCache[pixelIndex]+=filteredPixel;
2887 densityCache[pixelIndex]+=density;
2889 gammaCache[pixelIndex]+=gamma;
2893 barrier(CLK_LOCAL_MEM_FENCE);
2896 if (itemID < actualNumPixelInThisChunk) {
2898 float density = densityCache[itemID];
2899 float4 filteredPixel = outputPixelCache[itemID];
2900 if (density!= 0.0f && density != 1.0)
2903 filteredPixel *= (float4)density;
2905 filteredImage[y*filteredColumns+chunkStartX+itemID] = (CLPixelType) (
ClampToQuantum(filteredPixel.x)
2911 float density = densityCache[itemID];
2912 float gamma = gammaCache[itemID];
2913 float4 filteredPixel = outputPixelCache[itemID];
2915 if (density!= 0.0f && density != 1.0) {
2917 filteredPixel *= (float4)density;
2928 filteredImage[y*filteredColumns+chunkStartX+itemID] = fp;
2939 __kernel __attribute__((reqd_work_group_size(1, 256, 1)))
2940 void ResizeVerticalFilter(
const __global CLPixelType* inputImage,
const unsigned int inputColumns,
const unsigned int inputRows,
const unsigned int matte
2941 ,
const float yFactor, __global CLPixelType* filteredImage,
const unsigned int filteredColumns,
const unsigned int filteredRows
2942 ,
const int resizeFilterType,
const int resizeWindowType
2943 ,
const __global
float* resizeFilterCubicCoefficients
2944 ,
const float resizeFilterScale,
const float resizeFilterSupport,
const float resizeFilterWindowSupport,
const float resizeFilterBlur
2945 , __local CLPixelType* inputImageCache,
const int numCachedPixels,
const unsigned int pixelPerWorkgroup,
const unsigned int pixelChunkSize
2946 , __local float4* outputPixelCache, __local
float* densityCache, __local
float* gammaCache) {
2950 const unsigned int startY = get_group_id(1)*pixelPerWorkgroup;
2951 const unsigned int stopY =
MagickMin(startY + pixelPerWorkgroup,filteredRows);
2952 const unsigned int actualNumPixelToCompute = stopY - startY;
2955 float scale =
MagickMax(1.0f/yFactor+MagickEpsilon ,1.0f);
2956 const float support =
MagickMax(scale*resizeFilterSupport,0.5f);
2959 const int cacheRangeStartY =
MagickMax((
int)((startY+0.5f)/yFactor+MagickEpsilon-support+0.5f),(
int)(0));
2960 const int cacheRangeEndY =
MagickMin((
int)(cacheRangeStartY + numCachedPixels), (
int)inputRows);
2963 const unsigned int x = get_global_id(0);
2964 event_t e = async_work_group_strided_copy(inputImageCache, inputImage+cacheRangeStartY*inputColumns+x, cacheRangeEndY-cacheRangeStartY, inputColumns, 0);
2965 wait_group_events(1,&e);
2967 unsigned int totalNumChunks = (actualNumPixelToCompute+pixelChunkSize-1)/pixelChunkSize;
2968 for (
unsigned int chunk = 0; chunk < totalNumChunks; chunk++)
2971 const unsigned int chunkStartY = startY + chunk*pixelChunkSize;
2972 const unsigned int chunkStopY =
MagickMin(chunkStartY + pixelChunkSize, stopY);
2973 const unsigned int actualNumPixelInThisChunk = chunkStopY - chunkStartY;
2976 const unsigned int itemID = get_local_id(1);
2977 const unsigned int numItems = getNumWorkItemsPerPixel(actualNumPixelInThisChunk, get_local_size(1));
2979 const int pixelIndex = pixelToCompute(itemID, actualNumPixelInThisChunk, get_local_size(1));
2981 float4 filteredPixel = (float4)0.0f;
2982 float density = 0.0f;
2985 if (pixelIndex != -1) {
2988 const int y = chunkStartY + pixelIndex;
2992 const unsigned int start = (
unsigned int)
MagickMax(bisect-support+0.5f,0.0f);
2993 const unsigned int stop = (
unsigned int)
MagickMin(bisect+support+0.5f,(
float)inputRows);
2994 const unsigned int n = stop - start;
2997 unsigned int numStepsPerWorkItem = n / numItems;
2998 numStepsPerWorkItem += ((numItems*numStepsPerWorkItem)==n?0:1);
3000 const unsigned int startStep = (itemID%numItems)*numStepsPerWorkItem;
3001 if (startStep < n) {
3002 const unsigned int stopStep =
MagickMin(startStep+numStepsPerWorkItem, n);
3004 unsigned int cacheIndex = start+startStep-cacheRangeStartY;
3007 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
3008 float4 cp = convert_float4(inputImageCache[cacheIndex]);
3010 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
3011 , (ResizeWeightingFunctionType)resizeWindowType
3012 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
3014 filteredPixel += ((float4)weight)*cp;
3021 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
3022 CLPixelType p = inputImageCache[cacheIndex];
3024 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
3025 , (ResizeWeightingFunctionType)resizeWindowType
3026 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
3029 float4 cp = convert_float4(p);
3031 filteredPixel.x += alpha * cp.x;
3032 filteredPixel.y += alpha * cp.y;
3033 filteredPixel.z += alpha * cp.z;
3034 filteredPixel.w += weight * cp.w;
3044 if (itemID < actualNumPixelInThisChunk) {
3045 outputPixelCache[itemID] = (float4)0.0f;
3046 densityCache[itemID] = 0.0f;
3048 gammaCache[itemID] = 0.0f;
3050 barrier(CLK_LOCAL_MEM_FENCE);
3053 for (
unsigned int i = 0; i < numItems; i++) {
3054 if (pixelIndex != -1) {
3055 if (itemID%numItems == i) {
3056 outputPixelCache[pixelIndex]+=filteredPixel;
3057 densityCache[pixelIndex]+=density;
3059 gammaCache[pixelIndex]+=gamma;
3063 barrier(CLK_LOCAL_MEM_FENCE);
3066 if (itemID < actualNumPixelInThisChunk) {
3068 float density = densityCache[itemID];
3069 float4 filteredPixel = outputPixelCache[itemID];
3070 if (density!= 0.0f && density != 1.0)
3073 filteredPixel *= (float4)density;
3075 filteredImage[(chunkStartY+itemID)*filteredColumns+x] = (CLPixelType) (
ClampToQuantum(filteredPixel.x)
3081 float density = densityCache[itemID];
3082 float gamma = gammaCache[itemID];
3083 float4 filteredPixel = outputPixelCache[itemID];
3085 if (density!= 0.0f && density != 1.0) {
3087 filteredPixel *= (float4)density;
3098 filteredImage[(chunkStartY+itemID)*filteredColumns+x] = fp;
3120 __kernel
void UnsharpMaskBlurColumn(
const __global CLPixelType* inputImage,
3121 const __global float4 *blurRowData, __global CLPixelType *filtered_im,
3122 const unsigned int imageColumns,
const unsigned int imageRows,
3123 __local float4* cachedData, __local
float* cachedFilter,
3124 const ChannelType channel,
const __global
float *filter,
const unsigned int width,
3125 const float gain,
const float threshold)
3127 const unsigned int radius = (width-1)/2;
3130 const int groupX = get_group_id(0);
3131 const int groupStartY = get_group_id(1)*get_local_size(1) - radius;
3132 const int groupStopY = (get_group_id(1)+1)*get_local_size(1) + radius;
3134 if (groupStartY >= 0
3135 && groupStopY < imageRows) {
3136 event_t e = async_work_group_strided_copy(cachedData
3137 ,blurRowData+groupStartY*imageColumns+groupX
3138 ,groupStopY-groupStartY,imageColumns,0);
3139 wait_group_events(1,&e);
3142 for (
int i = get_local_id(1); i < (groupStopY - groupStartY); i+=get_local_size(1)) {
3143 cachedData[i] = blurRowData[ClampToCanvas(groupStartY+i,imageRows)*imageColumns+ groupX];
3145 barrier(CLK_LOCAL_MEM_FENCE);
3148 event_t e = async_work_group_copy(cachedFilter,filter,width,0);
3149 wait_group_events(1,&e);
3153 const int cy = get_global_id(1);
3155 if (cy < imageRows) {
3156 float4 blurredPixel = (float4) 0.0f;
3160 \n #ifndef UFACTOR \n
3161 \n #define UFACTOR 8 \n
3164 for ( ; i+UFACTOR < width; )
3166 \n #pragma unroll UFACTOR \n
3167 for (
int j=0; j < UFACTOR; j++, i++)
3169 blurredPixel+=cachedFilter[i]*cachedData[i+get_local_id(1)];
3173 for ( ; i < width; i++)
3175 blurredPixel+=cachedFilter[i]*cachedData[i+get_local_id(1)];
3181 float4 inputImagePixel = convert_float4(inputImage[cy*imageColumns+groupX]);
3182 float4 outputPixel = inputImagePixel - blurredPixel;
3186 int4 mask = isless(fabs(2.0f*outputPixel), (float4)quantumThreshold);
3187 outputPixel = select(inputImagePixel + outputPixel * gain, inputImagePixel, mask);
3200 __kernel
void UnsharpMask(__global CLPixelType *im, __global CLPixelType *filtered_im,
3201 __constant
float *filter,
3202 const unsigned int width,
3203 const unsigned int imageColumns,
const unsigned int imageRows,
3204 __local float4 *pixels,
3205 const float gain,
const float threshold,
const unsigned int justBlur)
3207 const int x = get_global_id(0);
3208 const int y = get_global_id(1);
3210 const unsigned int radius = (width - 1) / 2;
3212 int row = y - radius;
3213 int baseRow = get_group_id(1) * get_local_size(1) - radius;
3214 int endRow = (get_group_id(1) + 1) * get_local_size(1) + radius;
3216 while (row < endRow) {
3217 int srcy = (row < 0) ? -row : row;
3218 srcy = (srcy >= imageRows) ? (2 * imageRows - srcy - 1) : srcy;
3220 float4 value = 0.0f;
3222 int ix = x - radius;
3225 while (i + 7 < width) {
3226 for (
int j = 0; j < 8; ++j) {
3228 srcx = (srcx < 0) ? -srcx : srcx;
3229 srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx;
3230 value += filter[i + j] * convert_float4(im[srcx + srcy * imageColumns]);
3237 int srcx = (ix < 0) ? -ix : ix;
3238 srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx;
3239 value += filter[i] * convert_float4(im[srcx + srcy * imageColumns]);
3243 pixels[(row - baseRow) * get_local_size(0) + get_local_id(0)] = value;
3244 row += get_local_size(1);
3248 barrier(CLK_LOCAL_MEM_FENCE);
3251 const int px = get_local_id(0);
3252 const int py = get_local_id(1);
3253 const int prp = get_local_size(0);
3254 float4 value = (float4)(0.0f);
3257 while (i + 7 < width) {
3258 value += (float4)(filter[i]) * pixels[px + (py + i) * prp];
3259 value += (float4)(filter[i]) * pixels[px + (py + i + 1) * prp];
3260 value += (float4)(filter[i]) * pixels[px + (py + i + 2) * prp];
3261 value += (float4)(filter[i]) * pixels[px + (py + i + 3) * prp];
3262 value += (float4)(filter[i]) * pixels[px + (py + i + 4) * prp];
3263 value += (float4)(filter[i]) * pixels[px + (py + i + 5) * prp];
3264 value += (float4)(filter[i]) * pixels[px + (py + i + 6) * prp];
3265 value += (float4)(filter[i]) * pixels[px + (py + i + 7) * prp];
3269 value += (float4)(filter[i]) * pixels[px + (py + i) * prp];
3272 if ((x < imageColumns) && (y < imageRows)) {
3273 if (justBlur == 0) {
3274 float4 srcPixel = convert_float4(im[x + y * imageColumns]);
3275 float4 diff = srcPixel - value;
3279 int4 mask = isless(fabs(2.0f * diff), (float4)quantumThreshold);
3280 value = select(srcPixel + diff * gain, srcPixel, mask);
3288 __kernel __attribute__((reqd_work_group_size(64, 4, 1)))
void WaveletDenoise(__global CLPixelType *srcImage, __global CLPixelType *dstImage,
3289 const float threshold,
3291 const int imageWidth,
3292 const int imageHeight)
3294 const int pad = (1 << (passes - 1));
3295 const int tileSize = 64;
3296 const int tileRowPixels = 64;
3297 const float noise[] = { 0.8002, 0.2735, 0.1202, 0.0585, 0.0291, 0.0152, 0.0080, 0.0044 };
3299 CLPixelType stage[16];
3301 local
float buffer[64 * 64];
3303 int srcx = (get_group_id(0) + get_global_offset(0) / tileSize) * (tileSize - 2 * pad) - pad + get_local_id(0);
3304 int srcy = (get_group_id(1) + get_global_offset(1) / 4) * (tileSize - 2 * pad) - pad;
3306 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3307 stage[i / 4] = srcImage[mirrorTop(mirrorBottom(srcx), imageWidth) + (mirrorTop(mirrorBottom(srcy + i) , imageHeight)) * imageWidth];
3311 for (
int channel = 0; channel < 3; ++channel) {
3315 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3316 buffer[get_local_id(0) + i * tileRowPixels] = convert_float(stage[i / 4].s0);
3319 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3320 buffer[get_local_id(0) + i * tileRowPixels] = convert_float(stage[i / 4].s1);
3323 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3324 buffer[get_local_id(0) + i * tileRowPixels] = convert_float(stage[i / 4].s2);
3335 for (
int pass = 0; pass < passes; ++pass) {
3336 const int radius = 1 << pass;
3337 const int x = get_local_id(0);
3338 const float thresh = threshold * noise[pass];
3341 accum[0] = accum[1] = accum[2] = accum[3] = accum[4] = accum[5] = accum[6] = accum[6] = accum[7] = accum[8] = accum[9] = accum[10] = accum[11] = accum[12] = accum[13] = accum[14] = accum[15] = 0.0f;
3346 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3347 const int offset = i * tileRowPixels;
3349 tmp[i / 4] = buffer[x + offset];
3350 pixel = 0.5f * tmp[i / 4] + 0.25 * (buffer[mirrorBottom(x - radius) + offset] + buffer[mirrorTop(x + radius, tileSize) + offset]);
3351 barrier(CLK_LOCAL_MEM_FENCE);
3352 buffer[x + offset] = pixel;
3354 barrier(CLK_LOCAL_MEM_FENCE);
3356 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3357 pixel = 0.5f * buffer[x + i * tileRowPixels] + 0.25 * (buffer[x + mirrorBottom(i - radius) * tileRowPixels] + buffer[x + mirrorTop(i + radius, tileRowPixels) * tileRowPixels]);
3358 float delta = tmp[i / 4] - pixel;
3360 if (delta < -thresh)
3362 else if (delta > thresh)
3366 accum[i / 4] += delta;
3369 barrier(CLK_LOCAL_MEM_FENCE);
3370 if (pass < passes - 1)
3371 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3372 buffer[x + i * tileRowPixels] = tmp[i / 4];
3374 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3375 accum[i / 4] += tmp[i / 4];
3376 barrier(CLK_LOCAL_MEM_FENCE);
3381 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3385 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3389 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3394 barrier(CLK_LOCAL_MEM_FENCE);
3399 if ((get_local_id(0) >= pad) && (get_local_id(0) < tileSize - pad) && (srcx >= 0) && (srcx < imageWidth)) {
3401 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3402 if ((i >= pad) && (i < tileSize - pad) && (srcy + i >= 0) && (srcy + i < imageHeight)) {
3403 dstImage[srcx + (srcy + i) * imageWidth] = stage[i / 4];
3411 #endif // MAGICKCORE_OPENCL_SUPPORT 3413 #if defined(__cplusplus) || defined(c_plusplus) 3417 #endif // MAGICKCORE_ACCELERATE_PRIVATE_H Definition: composite.h:91
Definition: composite.h:94
Definition: composite.h:65
Definition: colorspace.h:44
Definition: resize-private.h:31
Definition: colorspace.h:36
Definition: resize-private.h:37
Definition: statistic.h:116
Definition: resize-private.h:33
Definition: magick-type.h:176
Definition: composite.h:75
Definition: colorspace.h:40
static void MagickPixelCompositeBlend(const MagickPixelPacket *p, const MagickRealType alpha, const MagickPixelPacket *q, const MagickRealType beta, MagickPixelPacket *composite)
Definition: composite-private.h:138
Definition: composite.h:31
Definition: composite.h:93
Definition: colorspace.h:45
Definition: colorspace.h:33
Definition: composite.h:80
Definition: composite.h:33
Definition: resize-private.h:40
Definition: composite.h:90
Definition: resize-private.h:29
static MagickRealType ColorDodge(const MagickRealType Sca, const MagickRealType Sa, const MagickRealType Dca, const MagickRealType Da)
Definition: composite.c:293
PixelIntensityMethod
Definition: pixel.h:67
Definition: magick-type.h:165
Definition: composite.h:95
Definition: colorspace.h:59
Definition: magick-type.h:171
Definition: composite.h:59
Definition: composite.h:89
Definition: magick-type.h:160
Definition: composite.h:27
Definition: colorspace.h:41
Definition: colorspace.h:37
static MagickRealType RoundToUnity(const MagickRealType value)
Definition: composite-private.h:33
Definition: composite.h:35
Definition: composite.h:87
#define MagickPI
Definition: image-private.h:39
Definition: colorspace.h:58
Definition: colorspace.h:50
static MagickRealType Hanning(const MagickRealType x, const ResizeFilter *magick_unused(resize_filter))
Definition: resize.c:287
Definition: colorspace.h:47
Definition: statistic.h:115
Definition: colorspace.h:31
#define MAGICKCORE_QUANTUM_DEPTH
Definition: magick-type.h:28
Definition: composite.h:53
Definition: colorspace.h:35
Definition: resize-private.h:38
#define MagickEpsilon
Definition: magick-type.h:115
MagickExport void ConvertRGBToHSL(const Quantum red, const Quantum green, const Quantum blue, double *hue, double *saturation, double *lightness)
Definition: gem.c:1127
Definition: magick-type.h:166
Definition: colorspace.h:48
Definition: statistic.h:117
Definition: magick-type.h:178
NoiseType
Definition: fx.h:27
Definition: colorspace.h:52
Definition: composite.h:47
static MagickRealType Hamming(const MagickRealType x, const ResizeFilter *magick_unused(resize_filter))
Definition: resize.c:301
Definition: resize-private.h:41
Definition: composite.h:73
Definition: composite.h:29
Definition: composite.h:72
Definition: composite.h:42
Definition: colorspace.h:43
Definition: composite.h:97
static void ModulateHSL(const double percent_hue, const double percent_saturation, const double percent_lightness, Quantum *red, Quantum *green, Quantum *blue)
Definition: enhance.c:3546
Definition: colorspace.h:34
Definition: colorspace.h:57
Definition: resize-private.h:30
static double PerceptibleReciprocal(const double x)
Definition: pixel-accessor.h:124
Definition: composite.h:54
#define GetPixelAlpha(pixel)
Definition: pixel-accessor.h:36
Definition: composite.h:38
Definition: composite.h:68
Definition: composite.h:96
Definition: magick-type.h:162
Definition: composite.h:71
Definition: resize-private.h:32
Definition: composite.h:55
Definition: composite.h:56
Definition: composite.h:69
static Quantum ApplyFunction(Quantum pixel, const MagickFunction function, const size_t number_parameters, const double *parameters, ExceptionInfo *exception)
Definition: statistic.c:938
Definition: colorspace.h:38
Definition: composite.h:86
Definition: resize-private.h:36
Definition: colorspace.h:30
#define SigmaMultiplicativeGaussian
Definition: composite.h:49
Definition: composite.h:44
MagickExport void ConvertRGBToHSB(const Quantum red, const Quantum green, const Quantum blue, double *hue, double *saturation, double *brightness)
Definition: gem.c:994
Definition: magick-type.h:164
static void Contrast(const int sign, Quantum *red, Quantum *green, Quantum *blue)
Definition: enhance.c:913
Definition: magick-type.h:179
Definition: composite.h:46
Definition: statistic.h:113
Definition: composite.h:28
Definition: magick-type.h:159
Definition: magick-type.h:168
Definition: colorspace.h:54
Definition: magick-type.h:167
Definition: resize-private.h:39
Definition: composite.h:78
Definition: resize-private.h:34
#define QuantumScale
Definition: magick-type.h:118
Definition: colorspace.h:55
Definition: composite.h:62
Definition: colorspace.h:39
#define MaxMap
Definition: magick-type.h:78
Definition: magick-type.h:175
#define MagickMax(x, y)
Definition: image-private.h:37
Definition: composite.h:98
Definition: composite.h:39
static void CompositeColorDodge(const MagickPixelPacket *p, const MagickPixelPacket *q, MagickPixelPacket *composite)
Definition: composite.c:330
MagickExport void ConvertHSBToRGB(const double hue, const double saturation, const double brightness, Quantum *red, Quantum *green, Quantum *blue)
Definition: gem.c:284
Definition: composite.h:45
ChannelType
Definition: magick-type.h:155
Definition: composite.h:70
Definition: colorspace.h:46
Definition: resize-private.h:28
Definition: composite.h:81
Definition: composite.h:41
Definition: composite.h:52
Definition: colorspace.h:49
MagickExport void ConvertHSLToRGB(const double hue, const double saturation, const double lightness, Quantum *red, Quantum *green, Quantum *blue)
Definition: gem.c:460
Definition: composite.h:77
static Quantum ClampToQuantum(const MagickRealType value)
Definition: quantum.h:87
Definition: colorspace.h:53
Definition: composite.h:61
Definition: magick-type.h:161
static void MagickPixelCompositePlus(const MagickPixelPacket *p, const MagickRealType alpha, const MagickPixelPacket *q, const MagickRealType beta, MagickPixelPacket *composite)
Definition: composite-private.h:111
Definition: composite.h:76
Definition: magick-type.h:157
Definition: colorspace.h:28
Definition: resize-private.h:42
Definition: composite.h:50
Definition: composite.h:36
Definition: composite.h:43
MagickExport MagickRealType GetPixelIntensity(const Image *image, const PixelPacket *magick_restrict pixel)
Definition: pixel.c:2285
static MagickRealType Sinc(const MagickRealType, const ResizeFilter *)
Definition: composite.h:37
Definition: composite.h:60
Definition: statistic.h:114
ResizeWeightingFunctionType
Definition: resize-private.h:25
static MagickRealType Blackman(const MagickRealType x, const ResizeFilter *magick_unused(resize_filter))
Definition: resize.c:148
Definition: colorspace.h:56
#define MagickMin(x, y)
Definition: image-private.h:38
ColorspaceType
Definition: colorspace.h:25
Definition: composite.h:32
Definition: colorspace.h:29
Definition: composite.h:88
Definition: colorspace.h:42
Definition: composite.h:48
Definition: composite.h:64
Definition: magick-type.h:163
Definition: colorspace.h:51
CompositeOperator
Definition: composite.h:25
Definition: composite.h:79
Definition: magick-type.h:170
Definition: colorspace.h:32
Definition: composite.h:66
Definition: composite.h:30
Definition: colorspace.h:60
Definition: magick-type.h:158
Definition: composite.h:63
Definition: composite.h:58
Definition: composite.h:92
Definition: magick-type.h:177
Definition: composite.h:34
static MagickRealType CubicBC(const MagickRealType x, const ResizeFilter *resize_filter)
Definition: resize.c:210
Definition: resize-private.h:27
Definition: composite.h:74
Definition: colorspace.h:27
MagickFunction
Definition: statistic.h:111
Definition: composite.h:40
Definition: composite.h:67
Definition: resize-private.h:35
#define QuantumRange
Definition: magick-type.h:86
static MagickRealType Triangle(const MagickRealType x, const ResizeFilter *magick_unused(resize_filter))
Definition: resize.c:514
Definition: composite.h:51
Definition: magick-type.h:169
Definition: composite.h:57