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)))
275 inline CLQuantum ScaleCharToQuantum(
const unsigned char value)
277 return((CLQuantum) value);
284 inline CLQuantum ScaleCharToQuantum(
const unsigned char value)
286 return((CLQuantum) (257.0f*value));
293 inline CLQuantum ScaleCharToQuantum(
const unsigned char value)
295 return((CLQuantum) (16843009.0*value));
302 inline
int ClampToCanvas(const
int offset, const
int range)
304 return clamp(offset, (
int)0, range - 1);
309 inline int ClampToCanvasWithHalo(
const int offset,
const int range,
const int edge,
const int section)
311 return clamp(offset, section ? (
int)(0 - edge) : (
int)0, section ? (range - 1) : (range - 1 + edge));
318 return (CLQuantum)(clamp(value, 0.0f, (
float)
QuantumRange) + 0.5f);
323 inline uint ScaleQuantumToMap(CLQuantum value)
325 if (value >= (CLQuantum)
MaxMap)
328 return ((uint)value);
335 float sign = x < (float) 0.0 ? (
float)-1.0 : (float) 1.0;
343 return clamp(value, 0.0f, 1.0f);
349 inline CLQuantum getBlue(CLPixelType p) {
return p.x; }
350 inline void setBlue(CLPixelType* p, CLQuantum value) { (*p).x = value; }
351 inline float getBlueF4(float4 p) {
return p.x; }
352 inline void setBlueF4(float4* p,
float value) { (*p).x = value; }
354 inline CLQuantum getGreen(CLPixelType p) {
return p.y; }
355 inline void setGreen(CLPixelType* p, CLQuantum value) { (*p).y = value; }
356 inline float getGreenF4(float4 p) {
return p.y; }
357 inline void setGreenF4(float4* p,
float value) { (*p).y = value; }
359 inline CLQuantum getRed(CLPixelType p) {
return p.z; }
360 inline void setRed(CLPixelType* p, CLQuantum value) { (*p).z = value; }
361 inline float getRedF4(float4 p) {
return p.z; }
362 inline void setRedF4(float4* p,
float value) { (*p).z = value; }
364 inline CLQuantum getOpacity(CLPixelType p) {
return p.w; }
365 inline void setOpacity(CLPixelType* p, CLQuantum value) { (*p).w = value; }
366 inline float getOpacityF4(float4 p) {
return p.w; }
367 inline void setOpacityF4(float4* p,
float value) { (*p).w = value; }
369 inline void setGray(CLPixelType* p, CLQuantum value) { (*p).z = value; (*p).y = value; (*p).x = value; }
371 inline float GetPixelIntensity(
const int method,
const int colorspace, CLPixelType p)
373 float red = getRed(p);
374 float green = getGreen(p);
375 float blue = getBlue(p);
386 intensity = (red + green + blue) / 3.0;
402 intensity = (float)(((
float)red*red + green*green + blue*blue) /
416 intensity = 0.298839*red + 0.586811*green + 0.114350*blue;
429 intensity = 0.298839*red + 0.586811*green + 0.114350*blue;
443 intensity = 0.212656*red + 0.715158*green + 0.072186*blue;
456 intensity = 0.212656*red + 0.715158*green + 0.072186*blue;
461 intensity = (float)(sqrt((
float)red*red + green*green + blue*blue) /
494 ulong MWC_AddMod64(ulong a, ulong b, ulong M)
498 if( (v>=M) || (convert_float(v) < convert_float(a)) )
509 ulong MWC_MulMod64(ulong a, ulong b, ulong M)
514 r=MWC_AddMod64(r,b,M);
515 b=MWC_AddMod64(b,b,M);
526 ulong MWC_PowMod64(ulong a, ulong e, ulong M)
531 acc=MWC_MulMod64(acc,sqr,M);
532 sqr=MWC_MulMod64(sqr,sqr,M);
538 uint2 MWC_SkipImpl_Mod64(uint2 curr, ulong A, ulong M, ulong distance)
540 ulong m=MWC_PowMod64(A, distance, M);
541 ulong x=curr.x*(ulong)A+curr.y;
542 x=MWC_MulMod64(x, m, M);
543 return (uint2)((uint)(x/A), (uint)(x%A));
546 uint2 MWC_SeedImpl_Mod64(ulong A, ulong M, uint vecSize, uint vecOffset, ulong streamBase, ulong streamGap)
553 enum{ MWC_BASEID = 4077358422479273989UL };
555 ulong dist=streamBase + (get_global_id(0)*vecSize+vecOffset)*streamGap;
556 ulong m=MWC_PowMod64(A, dist, M);
558 ulong x=MWC_MulMod64(MWC_BASEID, m, M);
559 return (uint2)((uint)(x/A), (uint)(x%A));
563 typedef struct{ uint x; uint c; } mwc64x_state_t;
565 enum{ MWC64X_A = 4294883355U };
566 enum{ MWC64X_M = 18446383549859758079UL };
568 void MWC64X_Step(mwc64x_state_t *s)
572 uint Xn=MWC64X_A*X+C;
573 uint carry=(uint)(Xn<C);
574 uint Cn=mad_hi(MWC64X_A,X,carry);
580 void MWC64X_Skip(mwc64x_state_t *s, ulong distance)
582 uint2 tmp=MWC_SkipImpl_Mod64((uint2)(s->x,s->c), MWC64X_A, MWC64X_M, distance);
587 void MWC64X_SeedStreams(mwc64x_state_t *s, ulong baseOffset, ulong perStreamOffset)
589 uint2 tmp=MWC_SeedImpl_Mod64(MWC64X_A, MWC64X_M, 1, 0, baseOffset, perStreamOffset);
595 uint MWC64X_NextUint(mwc64x_state_t *s)
597 uint res=s->x ^ s->c;
606 float mwcReadPseudoRandomValue(mwc64x_state_t* rng) {
607 return (1.0f * MWC64X_NextUint(rng)) / (float)(0xffffffff);
611 float mwcGenerateDifferentialNoise(mwc64x_state_t* r, CLQuantum pixel, NoiseType noise_type,
float attenuate) {
620 alpha=mwcReadPseudoRandomValue(r);
636 beta=mwcReadPseudoRandomValue(r);
637 gamma=sqrt(-2.0f*log(alpha));
638 sigma=gamma*cospi((2.0f*beta));
639 tau=gamma*sinpi((2.0f*beta));
678 if (alpha > MagickEpsilon)
679 sigma=sqrt(-2.0f*log(alpha));
680 beta=mwcReadPseudoRandomValue(r);
682 cospi((
float) (2.0f*beta))/2.0f);
691 for (i=0; alpha > poisson; i++)
693 beta=mwcReadPseudoRandomValue(r);
710 void AddNoise(
const __global CLPixelType* inputImage, __global CLPixelType* filteredImage
711 ,
const unsigned int inputPixelCount,
const unsigned int pixelsPerWorkItem
713 ,
const NoiseType noise_type,
const float attenuate
714 ,
const unsigned int seed0,
const unsigned int seed1
715 ,
const unsigned int numRandomNumbersPerPixel) {
721 uint span = pixelsPerWorkItem * numRandomNumbersPerPixel;
722 uint offset = span * get_local_size(0) * get_group_id(0);
724 MWC64X_SeedStreams(&rng, offset, span);
726 uint pos = get_local_size(0) * get_group_id(0) * pixelsPerWorkItem + get_local_id(0);
728 uint count = pixelsPerWorkItem;
731 if (pos < inputPixelCount) {
732 CLPixelType p = inputImage[pos];
735 setRed(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getRed(p),noise_type,attenuate)));
739 setGreen(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getGreen(p),noise_type,attenuate)));
743 setBlue(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getBlue(p),noise_type,attenuate)));
747 setOpacity(&p,
ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getOpacity(p),noise_type,attenuate)));
750 filteredImage[pos] = p;
753 pos += get_local_size(0);
779 __kernel
void BlurRow(__global CLPixelType *im, __global float4 *filtered_im,
780 const ChannelType channel, __constant
float *filter,
781 const unsigned int width,
782 const unsigned int imageColumns,
const unsigned int imageRows,
783 __local CLPixelType *temp)
785 const int x = get_global_id(0);
786 const int y = get_global_id(1);
788 const int columns = imageColumns;
790 const unsigned int radius = (width-1)/2;
791 const int wsize = get_local_size(0);
792 const unsigned int loadSize = wsize+width;
820 const int groupX=get_local_size(0)*get_group_id(0);
821 const int groupY=get_local_size(1)*get_group_id(1);
824 for (
int i=get_local_id(0); i < loadSize; i=i+get_local_size(0))
827 temp[i] = im[y * columns + ClampToCanvas(i+groupX-radius, columns)];
836 barrier(CLK_LOCAL_MEM_FENCE);
839 if (get_global_id(0) < columns)
842 float4 result = (float4) 0;
846 \n #ifndef UFACTOR \n
847 \n #define UFACTOR 8 \n
850 for ( ; i+UFACTOR < width; )
852 \n #pragma unroll UFACTOR\n
853 for (
int j=0; j < UFACTOR; j++, i++)
855 result+=filter[i]*convert_float4(temp[i+get_local_id(0)]);
859 for ( ; i < width; i++)
861 result+=filter[i]*convert_float4(temp[i+get_local_id(0)]);
870 filtered_im[y*columns+x] = result;
883 __kernel
void BlurColumn(
const __global float4 *blurRowData, __global CLPixelType *filtered_im,
884 const ChannelType channel, __constant
float *filter,
885 const unsigned int width,
886 const unsigned int imageColumns,
const unsigned int imageRows,
887 __local float4 *temp)
889 const int x = get_global_id(0);
890 const int y = get_global_id(1);
894 const int columns = imageColumns;
895 const int rows = imageRows;
897 unsigned int radius = (width-1)/2;
898 const int wsize = get_local_size(1);
899 const unsigned int loadSize = wsize+width;
902 const int groupX=get_local_size(0)*get_group_id(0);
903 const int groupY=get_local_size(1)*get_group_id(1);
908 for (
int i = get_local_id(1); i < loadSize; i=i+get_local_size(1))
910 temp[i] = blurRowData[ClampToCanvas(i+groupY-radius, rows) * columns + groupX];
914 barrier(CLK_LOCAL_MEM_FENCE);
917 if (get_global_id(1) < rows)
920 float4 result = (float4) 0;
924 \n #ifndef UFACTOR \n
925 \n #define UFACTOR 8 \n
928 for ( ; i+UFACTOR < width; )
930 \n #pragma unroll UFACTOR \n
931 for (
int j=0; j < UFACTOR; j++, i++)
933 result+=filter[i]*temp[i+get_local_id(1)];
937 for ( ; i < width; i++)
939 result+=filter[i]*temp[i+get_local_id(1)];
948 filtered_im[y*columns+x] = (CLPixelType) (result.x,result.y,result.z,result.w);
968 const float Sa,
const float Dca,
const float Da)
973 if ((Sca*Da+Dca*Sa) >= Sa*Da)
974 return(Sa*Da+Sca*(1.0-Da)+Dca*(1.0-Sa));
975 return(Dca*Sa*Sa/(Sa-Sca)+Sca*(1.0-Da)+Dca*(1.0-Sa));
1009 const float4 *q,float4 *composite) {
1022 getRedF4(*q)*Da,Da));
1024 getGreenF4(*q)*Da,Da));
1026 getBlueF4(*q)*Da,Da));
1032 const float alpha,
const float4 *q,
1033 const float beta,float4 *composite)
1047 setOpacityF4(composite,(
float)
QuantumRange*(1.0-gamma));
1049 setRedF4(composite,gamma*(Sa*getRedF4(*p)+Da*getRedF4(*q)));
1050 setGreenF4(composite,gamma*(Sa*getGreenF4(*p)+Da*getGreenF4(*q)));
1051 setBlueF4(composite,gamma*(Sa*getBlueF4(*p)+Da*getBlueF4(*q)));
1057 const float alpha,
const float4 *q,
1058 const float beta,float4 *composite)
1068 void Composite(__global CLPixelType *image,
1069 const unsigned int imageWidth,
1070 const unsigned int imageHeight,
1071 const unsigned int imageMatte,
1072 const __global CLPixelType *compositeImage,
1073 const unsigned int compositeWidth,
1074 const unsigned int compositeHeight,
1075 const unsigned int compositeMatte,
1076 const unsigned int compose,
1078 const float destination_dissolve,
1079 const float source_dissolve) {
1082 index.x = get_global_id(0);
1083 index.y = get_global_id(1);
1086 if (index.x >= imageWidth
1087 || index.y >= imageHeight) {
1090 const CLPixelType inputPixel = image[index.y*imageWidth+index.x];
1092 setRedF4(&destination,getRed(inputPixel));
1093 setGreenF4(&destination,getGreen(inputPixel));
1094 setBlueF4(&destination,getBlue(inputPixel));
1097 const CLPixelType compositePixel
1098 = compositeImage[index.y*imageWidth+index.x];
1100 setRedF4(&source,getRed(compositePixel));
1101 setGreenF4(&source,getGreen(compositePixel));
1102 setBlueF4(&source,getBlue(compositePixel));
1104 if (imageMatte != 0) {
1105 setOpacityF4(&destination,getOpacity(inputPixel));
1108 setOpacityF4(&destination,0.0f);
1111 if (compositeMatte != 0) {
1112 setOpacityF4(&source,getOpacity(compositePixel));
1115 setOpacityF4(&source,0.0f);
1118 float4 composite=destination;
1127 destination_dissolve,&composite);
1134 CLPixelType outputPixel;
1138 setOpacity(&outputPixel,
ClampToQuantum(getOpacityF4(composite)));
1139 image[index.y*imageWidth+index.x] = outputPixel;
1158 float3 HueSaturationBrightness;
1159 HueSaturationBrightness.x = 0.0f;
1160 HueSaturationBrightness.y = 0.0f;
1161 HueSaturationBrightness.z = 0.0f;
1163 float r=(float) getRed(pixel);
1164 float g=(float) getGreen(pixel);
1165 float b=(float) getBlue(pixel);
1171 float delta=tmax-tmin;
1172 HueSaturationBrightness.y=delta/tmax;
1175 if (delta != 0.0f) {
1176 HueSaturationBrightness.x = ((r == tmax)?0.0f:((g == tmax)?2.0f:4.0f));
1177 HueSaturationBrightness.x += ((r == tmax)?(g-b):((g == tmax)?(b-r):(r-g)))/delta;
1178 HueSaturationBrightness.x/=6.0f;
1179 HueSaturationBrightness.x += (HueSaturationBrightness.x < 0.0f)?0.0f:1.0f;
1182 return HueSaturationBrightness;
1187 float hue = HueSaturationBrightness.x;
1188 float brightness = HueSaturationBrightness.z;
1189 float saturation = HueSaturationBrightness.y;
1193 if (saturation == 0.0f) {
1195 setGreen(&rgb,getRed(rgb));
1196 setBlue(&rgb,getRed(rgb));
1200 float h=6.0f*(hue-floor(hue));
1202 float p=brightness*(1.0f-saturation);
1203 float q=brightness*(1.0f-saturation*f);
1204 float t=brightness*(1.0f-(saturation*(1.0f-f)));
1211 setRed(&rgb, (ih == 1)?clamped_q:
1212 (ih == 2 || ih == 3)?clamped_p:
1213 (ih == 4)?clamped_t:
1216 setGreen(&rgb, (ih == 1 || ih == 2)?clampedBrightness:
1217 (ih == 3)?clamped_q:
1218 (ih == 4 || ih == 5)?clamped_p:
1221 setBlue(&rgb, (ih == 2)?clamped_t:
1222 (ih == 3 || ih == 4)?clampedBrightness:
1223 (ih == 5)?clamped_q:
1229 __kernel
void Contrast(__global CLPixelType *im,
const unsigned int sharpen)
1232 const int sign = sharpen!=0?1:-1;
1233 const int x = get_global_id(0);
1234 const int y = get_global_id(1);
1235 const int columns = get_global_size(0);
1236 const int c = x + y * columns;
1238 CLPixelType pixel = im[c];
1240 float brightness = HueSaturationBrightness.z;
1241 brightness+=0.5f*sign*(0.5f*(sinpi(brightness-0.5f)+1.0f)-brightness);
1242 brightness = clamp(brightness,0.0f,1.0f);
1243 HueSaturationBrightness.z = brightness;
1246 filteredPixel.w = pixel.w;
1247 im[c] = filteredPixel;
1266 __kernel
void Histogram(__global CLPixelType * restrict im,
1269 const int colorspace,
1270 __global uint4 * restrict histogram)
1272 const int x = get_global_id(0);
1273 const int y = get_global_id(1);
1274 const int columns = get_global_size(0);
1275 const int c = x + y * columns;
1280 atomic_inc((__global uint *)(&(histogram[pos]))+2);
1293 __kernel
void ContrastStretch(__global CLPixelType * restrict im,
1295 __global CLPixelType * restrict stretch_map,
1296 const float4 white,
const float4 black)
1298 const int x = get_global_id(0);
1299 const int y = get_global_id(1);
1300 const int columns = get_global_size(0);
1301 const int c = x + y * columns;
1304 CLPixelType oValue, eValue;
1305 CLQuantum red, green, blue, opacity;
1310 if ((channel & RedChannel) != 0)
1312 if (getRedF4(white) != getRedF4(black))
1314 ePos = ScaleQuantumToMap(getRed(oValue));
1315 eValue = stretch_map[ePos];
1316 red = getRed(eValue);
1320 if ((channel & GreenChannel) != 0)
1322 if (getGreenF4(white) != getGreenF4(black))
1324 ePos = ScaleQuantumToMap(getGreen(oValue));
1325 eValue = stretch_map[ePos];
1326 green = getGreen(eValue);
1330 if ((channel & BlueChannel) != 0)
1332 if (getBlueF4(white) != getBlueF4(black))
1334 ePos = ScaleQuantumToMap(getBlue(oValue));
1335 eValue = stretch_map[ePos];
1336 blue = getBlue(eValue);
1340 if ((channel & OpacityChannel) != 0)
1342 if (getOpacityF4(white) != getOpacityF4(black))
1344 ePos = ScaleQuantumToMap(getOpacity(oValue));
1345 eValue = stretch_map[ePos];
1346 opacity = getOpacity(eValue);
1351 im[c]=(CLPixelType)(blue, green, red, opacity);
1370 void ConvolveOptimized(
const __global CLPixelType *input, __global CLPixelType *output,
1371 const unsigned int imageWidth,
const unsigned int imageHeight,
1372 __constant
float *filter,
const unsigned int filterWidth,
const unsigned int filterHeight,
1373 const uint matte,
const ChannelType channel, __local CLPixelType *pixelLocalCache, __local
float* filterCache) {
1376 blockID.x = get_group_id(0);
1377 blockID.y = get_group_id(1);
1381 imageAreaOrg.x = blockID.x * get_local_size(0);
1382 imageAreaOrg.y = blockID.y * get_local_size(1);
1384 int2 midFilterDimen;
1385 midFilterDimen.x = (filterWidth-1)/2;
1386 midFilterDimen.y = (filterHeight-1)/2;
1388 int2 cachedAreaOrg = imageAreaOrg - midFilterDimen;
1391 int2 cachedAreaDimen;
1392 cachedAreaDimen.x = get_local_size(0) + filterWidth - 1;
1393 cachedAreaDimen.y = get_local_size(1) + filterHeight - 1;
1396 int localID = get_local_id(1)*get_local_size(0)+get_local_id(0);
1397 int cachedAreaNumPixels = cachedAreaDimen.x * cachedAreaDimen.y;
1398 int groupSize = get_local_size(0) * get_local_size(1);
1399 for (
int i = localID; i < cachedAreaNumPixels; i+=groupSize) {
1401 int2 cachedAreaIndex;
1402 cachedAreaIndex.x = i % cachedAreaDimen.x;
1403 cachedAreaIndex.y = i / cachedAreaDimen.x;
1405 int2 imagePixelIndex;
1406 imagePixelIndex = cachedAreaOrg + cachedAreaIndex;
1410 imagePixelIndex.x = ClampToCanvas(imagePixelIndex.x, imageWidth);
1411 imagePixelIndex.y = ClampToCanvas(imagePixelIndex.y, imageHeight);
1413 pixelLocalCache[i] = input[imagePixelIndex.y * imageWidth + imagePixelIndex.x];
1417 for (
int i = localID; i < filterHeight*filterWidth; i+=groupSize) {
1418 filterCache[i] = filter[i];
1420 barrier(CLK_LOCAL_MEM_FENCE);
1424 imageIndex.x = imageAreaOrg.x + get_local_id(0);
1425 imageIndex.y = imageAreaOrg.y + get_local_id(1);
1428 if (imageIndex.x >= imageWidth
1429 || imageIndex.y >= imageHeight) {
1433 int filterIndex = 0;
1434 float4 sum = (float4)0.0f;
1436 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
1437 int cacheIndexY = get_local_id(1);
1438 for (
int j = 0; j < filterHeight; j++) {
1439 int cacheIndexX = get_local_id(0);
1440 for (
int i = 0; i < filterWidth; i++) {
1441 CLPixelType p = pixelLocalCache[cacheIndexY*cachedAreaDimen.x + cacheIndexX];
1442 float f = filterCache[filterIndex];
1457 int cacheIndexY = get_local_id(1);
1458 for (
int j = 0; j < filterHeight; j++) {
1459 int cacheIndexX = get_local_id(0);
1460 for (
int i = 0; i < filterWidth; i++) {
1462 CLPixelType p = pixelLocalCache[cacheIndexY*cachedAreaDimen.x + cacheIndexX];
1464 float f = filterCache[filterIndex];
1465 float g = alpha * f;
1479 sum.xyz = gamma*sum.xyz;
1481 CLPixelType outputPixel;
1487 output[imageIndex.y * imageWidth + imageIndex.x] = outputPixel;
1493 void Convolve(
const __global CLPixelType *input, __global CLPixelType *output,
1494 const uint imageWidth,
const uint imageHeight,
1495 __constant
float *filter,
const unsigned int filterWidth,
const unsigned int filterHeight,
1499 imageIndex.x = get_global_id(0);
1500 imageIndex.y = get_global_id(1);
1506 if (imageIndex.x >= imageWidth
1507 || imageIndex.y >= imageHeight)
1510 int2 midFilterDimen;
1511 midFilterDimen.x = (filterWidth-1)/2;
1512 midFilterDimen.y = (filterHeight-1)/2;
1514 int filterIndex = 0;
1515 float4 sum = (float4)0.0f;
1517 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
1518 for (
int j = 0; j < filterHeight; j++) {
1519 int2 inputPixelIndex;
1520 inputPixelIndex.y = imageIndex.y - midFilterDimen.y + j;
1521 inputPixelIndex.y = ClampToCanvas(inputPixelIndex.y, imageHeight);
1522 for (
int i = 0; i < filterWidth; i++) {
1523 inputPixelIndex.x = imageIndex.x - midFilterDimen.x + i;
1524 inputPixelIndex.x = ClampToCanvas(inputPixelIndex.x, imageWidth);
1526 CLPixelType p = input[inputPixelIndex.y * imageWidth + inputPixelIndex.x];
1527 float f = filter[filterIndex];
1542 for (
int j = 0; j < filterHeight; j++) {
1543 int2 inputPixelIndex;
1544 inputPixelIndex.y = imageIndex.y - midFilterDimen.y + j;
1545 inputPixelIndex.y = ClampToCanvas(inputPixelIndex.y, imageHeight);
1546 for (
int i = 0; i < filterWidth; i++) {
1547 inputPixelIndex.x = imageIndex.x - midFilterDimen.x + i;
1548 inputPixelIndex.x = ClampToCanvas(inputPixelIndex.x, imageWidth);
1550 CLPixelType p = input[inputPixelIndex.y * imageWidth + inputPixelIndex.x];
1552 float f = filter[filterIndex];
1553 float g = alpha * f;
1567 sum.xyz = gamma*sum.xyz;
1570 CLPixelType outputPixel;
1576 output[imageIndex.y * imageWidth + imageIndex.x] = outputPixel;
1594 __kernel
void HullPass1(
const __global CLPixelType *inputImage, __global CLPixelType *outputImage
1595 ,
const unsigned int imageWidth,
const unsigned int imageHeight
1596 ,
const int2 offset,
const int polarity,
const int matte) {
1598 int x = get_global_id(0);
1599 int y = get_global_id(1);
1601 CLPixelType v = inputImage[y*imageWidth+x];
1604 neighbor.y = y + offset.y;
1605 neighbor.x = x + offset.x;
1607 int2 clampedNeighbor;
1608 clampedNeighbor.x = ClampToCanvas(neighbor.x, imageWidth);
1609 clampedNeighbor.y = ClampToCanvas(neighbor.y, imageHeight);
1611 CLPixelType r = (clampedNeighbor.x == neighbor.x
1612 && clampedNeighbor.y == neighbor.y)?inputImage[clampedNeighbor.y*imageWidth+clampedNeighbor.x]
1628 \n #pragma unroll 4\n
1629 for (
unsigned int i = 0; i < 4; i++) {
1630 sv[i] = (sr[i] >= (sv[i]+ScaleCharToQuantum(2)))?(sv[i]+ScaleCharToQuantum(1)):sv[i];
1634 \n #pragma unroll 4\n
1635 for (
unsigned int i = 0; i < 4; i++) {
1636 sv[i] = (sr[i] <= (sv[i]-ScaleCharToQuantum(2)))?(sv[i]-ScaleCharToQuantum(1)):sv[i];
1641 v.x = (CLQuantum)sv[0];
1642 v.y = (CLQuantum)sv[1];
1643 v.z = (CLQuantum)sv[2];
1646 v.w = (CLQuantum)sv[3];
1648 outputImage[y*imageWidth+x] = v;
1659 __kernel
void HullPass2(
const __global CLPixelType *inputImage, __global CLPixelType *outputImage
1660 ,
const unsigned int imageWidth,
const unsigned int imageHeight
1661 ,
const int2 offset,
const int polarity,
const int matte) {
1663 int x = get_global_id(0);
1664 int y = get_global_id(1);
1666 CLPixelType v = inputImage[y*imageWidth+x];
1668 int2 neighbor, clampedNeighbor;
1670 neighbor.y = y + offset.y;
1671 neighbor.x = x + offset.x;
1672 clampedNeighbor.x = ClampToCanvas(neighbor.x, imageWidth);
1673 clampedNeighbor.y = ClampToCanvas(neighbor.y, imageHeight);
1675 CLPixelType r = (clampedNeighbor.x == neighbor.x
1676 && clampedNeighbor.y == neighbor.y)?inputImage[clampedNeighbor.y*imageWidth+clampedNeighbor.x]
1680 neighbor.y = y - offset.y;
1681 neighbor.x = x - offset.x;
1682 clampedNeighbor.x = ClampToCanvas(neighbor.x, imageWidth);
1683 clampedNeighbor.y = ClampToCanvas(neighbor.y, imageHeight);
1685 CLPixelType s = (clampedNeighbor.x == neighbor.x
1686 && clampedNeighbor.y == neighbor.y)?inputImage[clampedNeighbor.y*imageWidth+clampedNeighbor.x]
1709 \n #pragma unroll 4\n
1710 for (
unsigned int i = 0; i < 4; i++) {
1715 sv[i] =(( (int)( ss[i] < (sv[i]+ScaleCharToQuantum(2))) + (int) ( sr[i] <= sv[i] ) ) !=0) ? sv[i]:(sv[i]+ScaleCharToQuantum(1));
1719 \n #pragma unroll 4\n
1720 for (
unsigned int i = 0; i < 4; i++) {
1724 sv[i] = (( (int)(ss[i] > (sv[i]-ScaleCharToQuantum(2))) + (int)( sr[i] >= sv[i] )) !=0) ? sv[i]:(sv[i]-ScaleCharToQuantum(1));
1728 v.x = (CLQuantum)sv[0];
1729 v.y = (CLQuantum)sv[1];
1730 v.z = (CLQuantum)sv[2];
1733 v.w = (CLQuantum)sv[3];
1735 outputImage[y*imageWidth+x] = v;
1757 __kernel
void Equalize(__global CLPixelType * restrict im,
1759 __global CLPixelType * restrict equalize_map,
1760 const float4 white,
const float4 black)
1762 const int x = get_global_id(0);
1763 const int y = get_global_id(1);
1764 const int columns = get_global_size(0);
1765 const int c = x + y * columns;
1768 CLPixelType oValue, eValue;
1769 CLQuantum red, green, blue, opacity;
1774 if ((channel & SyncChannels) != 0)
1776 if (getRedF4(white) != getRedF4(black))
1778 ePos = ScaleQuantumToMap(getRed(oValue));
1779 eValue = equalize_map[ePos];
1780 red = getRed(eValue);
1781 ePos = ScaleQuantumToMap(getGreen(oValue));
1782 eValue = equalize_map[ePos];
1783 green = getRed(eValue);
1784 ePos = ScaleQuantumToMap(getBlue(oValue));
1785 eValue = equalize_map[ePos];
1786 blue = getRed(eValue);
1787 ePos = ScaleQuantumToMap(getOpacity(oValue));
1788 eValue = equalize_map[ePos];
1789 opacity = getRed(eValue);
1792 im[c]=(CLPixelType)(blue, green, red, opacity);
1820 CLPixelType
ApplyFunction(CLPixelType pixel,
const MagickFunction
function,
1821 const unsigned int number_parameters,
1822 __constant
float *parameters)
1824 float4 result = (float4) 0.0f;
1829 for (
unsigned int i=0; i < number_parameters; i++)
1830 result = result*(float4)
QuantumScale*convert_float4(pixel) + parameters[i];
1836 float freq,phase,ampl,bias;
1837 freq = ( number_parameters >= 1 ) ? parameters[0] : 1.0f;
1838 phase = ( number_parameters >= 2 ) ? parameters[1] : 0.0f;
1839 ampl = ( number_parameters >= 3 ) ? parameters[2] : 0.5f;
1840 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5f;
1842 (freq*
QuantumScale*(
float)pixel.x + phase/360.0f)) + bias);
1844 (freq*
QuantumScale*(
float)pixel.y + phase/360.0f)) + bias);
1846 (freq*
QuantumScale*(
float)pixel.z + phase/360.0f)) + bias);
1848 (freq*
QuantumScale*(
float)pixel.w + phase/360.0f)) + bias);
1853 float width,range,center,bias;
1854 width = ( number_parameters >= 1 ) ? parameters[0] : 1.0f;
1855 center = ( number_parameters >= 2 ) ? parameters[1] : 0.5f;
1856 range = ( number_parameters >= 3 ) ? parameters[2] : 1.0f;
1857 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5f;
1859 result.x = 2.0f/width*(
QuantumScale*(float)pixel.x - center);
1860 result.x = range/
MagickPI*asin(result.x)+bias;
1861 result.x = ( result.x <= -1.0f ) ? bias - range/2.0f : result.x;
1862 result.x = ( result.x >= 1.0f ) ? bias + range/2.0f : result.x;
1864 result.y = 2.0f/width*(
QuantumScale*(float)pixel.y - center);
1865 result.y = range/
MagickPI*asin(result.y)+bias;
1866 result.y = ( result.y <= -1.0f ) ? bias - range/2.0f : result.y;
1867 result.y = ( result.y >= 1.0f ) ? bias + range/2.0f : result.y;
1869 result.z = 2.0f/width*(
QuantumScale*(float)pixel.z - center);
1870 result.z = range/
MagickPI*asin(result.z)+bias;
1871 result.z = ( result.z <= -1.0f ) ? bias - range/2.0f : result.x;
1872 result.z = ( result.z >= 1.0f ) ? bias + range/2.0f : result.x;
1875 result.w = 2.0f/width*(
QuantumScale*(float)pixel.w - center);
1876 result.w = range/
MagickPI*asin(result.w)+bias;
1877 result.w = ( result.w <= -1.0f ) ? bias - range/2.0f : result.w;
1878 result.w = ( result.w >= 1.0f ) ? bias + range/2.0f : result.w;
1885 float slope,range,center,bias;
1886 slope = ( number_parameters >= 1 ) ? parameters[0] : 1.0f;
1887 center = ( number_parameters >= 2 ) ? parameters[1] : 0.5f;
1888 range = ( number_parameters >= 3 ) ? parameters[2] : 1.0f;
1889 bias = ( number_parameters >= 4 ) ? parameters[3] : 0.5f;
1890 result = (float4)
MagickPI*(float4)slope*((float4)
QuantumScale*convert_float4(pixel)-(float4)center);
1910 __kernel
void ComputeFunction(__global CLPixelType *im,
1911 const ChannelType channel,
const MagickFunction
function,
1912 const unsigned int number_parameters, __constant
float *parameters)
1914 const int x = get_global_id(0);
1915 const int y = get_global_id(1);
1916 const int columns = get_global_size(0);
1917 const int c = x + y * columns;
1918 im[c] =
ApplyFunction(im[c],
function, number_parameters, parameters);
1935 __kernel
void Grayscale(__global CLPixelType *im,
1936 const int method,
const int colorspace)
1939 const int x = get_global_id(0);
1940 const int y = get_global_id(1);
1941 const int columns = get_global_size(0);
1942 const int c = x + y * columns;
1944 CLPixelType pixel = im[c];
1952 red=(float)getRed(pixel);
1953 green=(float)getGreen(pixel);
1954 blue=(float)getBlue(pixel);
1958 CLPixelType filteredPixel;
1964 intensity=(red+green+blue)/3.0;
1980 intensity=(float) (((
float) red*red+green*green+
1994 intensity=0.298839*red+0.586811*green+0.114350*blue;
2007 intensity=0.298839*red+0.586811*green+0.114350*blue;
2021 intensity=0.212656*red+0.715158*green+0.072186*blue;
2034 intensity=0.212656*red+0.715158*green+0.072186*blue;
2039 intensity=(float) (sqrt((
float) red*red+green*green+
2040 blue*blue)/sqrt(3.0));
2048 filteredPixel.w = pixel.w;
2050 im[c] = filteredPixel;
2067 inline int mirrorBottom(
int value)
2069 return (value < 0) ? - (value) : value;
2071 inline int mirrorTop(
int value,
int width)
2073 return (value >= width) ? (2 * width - value - 1) : value;
2076 __kernel
void LocalContrastBlurRow(__global CLPixelType *srcImage, __global CLPixelType *dstImage, __global
float *tmpImage,
2078 const int imageWidth,
2079 const int imageHeight)
2081 const float4 RGB = ((float4)(0.2126f, 0.7152f, 0.0722f, 0.0f));
2083 int x = get_local_id(0);
2084 int y = get_global_id(1);
2086 if ((x >= imageWidth) || (y >= imageHeight))
2089 global CLPixelType *src = srcImage + y * imageWidth;
2091 for (
int i = x; i < imageWidth; i += get_local_size(0)) {
2093 float weight = 1.0f;
2096 while ((j + 7) < i) {
2097 for (
int k = 0; k < 8; ++k)
2098 sum += (weight + k) * dot(RGB, convert_float4(src[mirrorBottom(j+k)]));
2103 sum += weight * dot(RGB, convert_float4(src[mirrorBottom(j)]));
2108 while ((j + 7) < radius + i) {
2109 for (
int k = 0; k < 8; ++k)
2110 sum += (weight - k) * dot(RGB, convert_float4(src[mirrorTop(j + k, imageWidth)]));
2114 while (j < radius + i) {
2115 sum += weight * dot(RGB, convert_float4(src[mirrorTop(j, imageWidth)]));
2120 tmpImage[i + y * imageWidth] = sum / ((radius + 1) * (radius + 1));
2126 __kernel
void LocalContrastBlurApplyColumn(__global CLPixelType *srcImage, __global CLPixelType *dstImage, __global
float *blurImage,
2128 const float strength,
2129 const int imageWidth,
2130 const int imageHeight)
2132 const float4 RGB = (float4)(0.2126f, 0.7152f, 0.0722f, 0.0f);
2134 int x = get_global_id(0);
2135 int y = get_global_id(1);
2137 if ((x >= imageWidth) || (y >= imageHeight))
2140 global
float *src = blurImage + x;
2143 float weight = 1.0f;
2146 while ((j + 7) < y) {
2147 for (
int k = 0; k < 8; ++k)
2148 sum += (weight + k) * src[mirrorBottom(j+k) * imageWidth];
2153 sum += weight * src[mirrorBottom(j) * imageWidth];
2158 while ((j + 7) < radius + y) {
2159 for (
int k = 0; k < 8; ++k)
2160 sum += (weight - k) * src[mirrorTop(j + k, imageHeight) * imageWidth];
2164 while (j < radius + y) {
2165 sum += weight * src[mirrorTop(j, imageHeight) * imageWidth];
2170 CLPixelType pixel = srcImage[x + y * imageWidth];
2171 float srcVal = dot(RGB, convert_float4(pixel));
2172 float mult = (srcVal - (sum / ((radius + 1) * (radius + 1)))) * (strength / 100.0f);
2173 mult = (srcVal + mult) / srcVal;
2179 dstImage[x + y * imageWidth] = pixel;
2197 inline void ConvertRGBToHSL(
const CLQuantum red,
const CLQuantum green,
const CLQuantum blue,
2198 float *hue,
float *saturation,
float *lightness)
2213 *lightness=(tmax+tmin)/2.0;
2234 if (*lightness <= 0.5)
2235 *saturation=c/(2.0*(*lightness));
2237 *saturation=c/(2.0-2.0*(*lightness));
2240 inline void ConvertHSLToRGB(
const float hue,
const float saturation,
const float lightness,
2241 CLQuantum *red,CLQuantum *green,CLQuantum *blue)
2256 if (lightness <= 0.5)
2257 c=2.0*lightness*saturation;
2259 c=(2.0-2.0*lightness)*saturation;
2260 tmin=lightness-0.5*c;
2261 h-=360.0*floor(h/360.0);
2263 x=c*(1.0-fabs(h-2.0*floor(h/2.0)-1.0));
2264 switch ((
int) floor(h) % 6)
2320 inline void ModulateHSL(
const float percent_hue,
const float percent_saturation,
const float percent_lightness,
2321 CLQuantum *red,CLQuantum *green,CLQuantum *blue)
2332 hue+=0.5*(0.01*percent_hue-1.0);
2337 saturation*=0.01*percent_saturation;
2338 lightness*=0.01*percent_lightness;
2342 __kernel
void Modulate(__global CLPixelType *im,
2343 const float percent_brightness,
2344 const float percent_hue,
2345 const float percent_saturation,
2346 const int colorspace)
2349 const int x = get_global_id(0);
2350 const int y = get_global_id(1);
2351 const int columns = get_global_size(0);
2352 const int c = x + y * columns;
2354 CLPixelType pixel = im[c];
2362 green=getGreen(pixel);
2363 blue=getBlue(pixel);
2370 ModulateHSL(percent_hue, percent_saturation, percent_brightness,
2371 &red, &green, &blue);
2376 CLPixelType filteredPixel;
2378 setRed(&filteredPixel, red);
2379 setGreen(&filteredPixel, green);
2380 setBlue(&filteredPixel, blue);
2381 filteredPixel.w = pixel.w;
2383 im[c] = filteredPixel;
2401 void MotionBlur(
const __global CLPixelType *input, __global CLPixelType *output,
2402 const unsigned int imageWidth,
const unsigned int imageHeight,
2403 const __global
float *filter,
const unsigned int width,
const __global int2* offset,
2405 const ChannelType channel,
const unsigned int matte) {
2408 currentPixel.x = get_global_id(0);
2409 currentPixel.y = get_global_id(1);
2411 if (currentPixel.x >= imageWidth
2412 || currentPixel.y >= imageHeight)
2416 pixel.x = (float)bias.x;
2417 pixel.y = (
float)bias.y;
2418 pixel.z = (float)bias.z;
2419 pixel.w = (
float)bias.w;
2421 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
2423 for (
int i = 0; i < width; i++) {
2426 int2 samplePixel = currentPixel + offset[i];
2427 samplePixel.x = ClampToCanvas(samplePixel.x, imageWidth);
2428 samplePixel.y = ClampToCanvas(samplePixel.y, imageHeight);
2429 CLPixelType samplePixelValue = input[ samplePixel.y * imageWidth + samplePixel.x];
2431 pixel.x += (filter[i] * (float)samplePixelValue.x);
2432 pixel.y += (filter[i] * (float)samplePixelValue.y);
2433 pixel.z += (filter[i] * (float)samplePixelValue.z);
2434 pixel.w += (filter[i] * (float)samplePixelValue.w);
2437 CLPixelType outputPixel;
2442 output[currentPixel.y * imageWidth + currentPixel.x] = outputPixel;
2447 for (
int i = 0; i < width; i++) {
2450 int2 samplePixel = currentPixel + offset[i];
2451 samplePixel.x = ClampToCanvas(samplePixel.x, imageWidth);
2452 samplePixel.y = ClampToCanvas(samplePixel.y, imageHeight);
2454 CLPixelType samplePixelValue = input[ samplePixel.y * imageWidth + samplePixel.x];
2457 float k = filter[i];
2458 pixel.x = pixel.x + k * alpha * samplePixelValue.x;
2459 pixel.y = pixel.y + k * alpha * samplePixelValue.y;
2460 pixel.z = pixel.z + k * alpha * samplePixelValue.z;
2462 pixel.w += k * alpha * samplePixelValue.w;
2467 pixel.xyz = gamma*pixel.xyz;
2469 CLPixelType outputPixel;
2474 output[currentPixel.y * imageWidth + currentPixel.x] = outputPixel;
2492 __kernel
void RadialBlur(
const __global CLPixelType *im, __global CLPixelType *filtered_im,
2494 const unsigned int channel,
const unsigned int matte,
2495 const float2 blurCenter,
2496 __constant
float *cos_theta, __constant
float *sin_theta,
2497 const unsigned int cossin_theta_size)
2499 const int x = get_global_id(0);
2500 const int y = get_global_id(1);
2501 const int columns = get_global_size(0);
2502 const int rows = get_global_size(1);
2503 unsigned int step = 1;
2504 float center_x = (float) x - blurCenter.x;
2505 float center_y = (
float) y - blurCenter.y;
2506 float radius = hypot(center_x, center_y);
2509 float blur_radius = hypot(blurCenter.x, blurCenter.y);
2511 if (radius > MagickEpsilon)
2513 step = (
unsigned int) (blur_radius / radius);
2516 if (step >= cossin_theta_size)
2517 step = cossin_theta_size-1;
2521 result.x = (float)bias.x;
2522 result.y = (
float)bias.y;
2523 result.z = (float)bias.z;
2524 result.w = (
float)bias.w;
2525 float normalize = 0.0f;
2527 if (((channel & OpacityChannel) == 0) || (matte == 0)) {
2528 for (
unsigned int i=0; i<cossin_theta_size; i+=step)
2530 result += convert_float4(im[
2531 ClampToCanvas(blurCenter.x+center_x*cos_theta[i]-center_y*sin_theta[i]+0.5f,columns)+
2532 ClampToCanvas(blurCenter.y+center_x*sin_theta[i]+center_y*cos_theta[i]+0.5f, rows)*columns]);
2536 result = result * normalize;
2540 for (
unsigned int i=0; i<cossin_theta_size; i+=step)
2542 float4 p = convert_float4(im[
2543 ClampToCanvas(blurCenter.x+center_x*cos_theta[i]-center_y*sin_theta[i]+0.5f,columns)+
2544 ClampToCanvas(blurCenter.y+center_x*sin_theta[i]+center_y*cos_theta[i]+0.5f, rows)*columns]);
2547 result.x += alpha * p.x;
2548 result.y += alpha * p.y;
2549 result.z += alpha * p.z;
2556 result.x = gamma*result.x;
2557 result.y = gamma*result.y;
2558 result.z = gamma*result.z;
2559 result.w = normalize*result.w;
2580 float BoxResizeFilter(
const float x)
2588 float CubicBC(
const float x,
const __global
float* resizeFilterCoefficients)
2620 return(resizeFilterCoefficients[0]+x*(x*
2621 (resizeFilterCoefficients[1]+x*resizeFilterCoefficients[2])));
2623 return(resizeFilterCoefficients[3]+x*(resizeFilterCoefficients[4]+x*
2624 (resizeFilterCoefficients[5]+x*resizeFilterCoefficients[6])));
2630 float Sinc(
const float x)
2634 const float alpha=(float) (
MagickPI*x);
2635 return sinpi(x)/alpha;
2649 return ((x<1.0f)?(1.0f-x):0.0f);
2661 const float cosine=cos((
MagickPI*x));
2662 return(0.5f+0.5f*cosine);
2673 const float cosine=cos((
MagickPI*x));
2674 return(0.54f+0.46f*cosine);
2688 const float cosine=cos((
MagickPI*x));
2689 return(0.34f+cosine*(0.5f+cosine*0.16f));
2697 inline float applyResizeFilter(
const float x,
const ResizeWeightingFunctionType filterType,
const __global
float* filterCoefficients)
2707 return CubicBC(x,filterCoefficients);
2709 return BoxResizeFilter(x);
2727 inline float getResizeFilterWeight(
const __global
float* resizeFilterCubicCoefficients,
const ResizeWeightingFunctionType resizeFilterType
2728 ,
const ResizeWeightingFunctionType resizeWindowType
2729 ,
const float resizeFilterScale,
const float resizeWindowSupport,
const float resizeFilterBlur,
const float x)
2732 float xBlur = fabs(x/resizeFilterBlur);
2733 if (resizeWindowSupport < MagickEpsilon
2740 scale = resizeFilterScale;
2741 scale = applyResizeFilter(xBlur*scale, resizeWindowType, resizeFilterCubicCoefficients);
2743 float weight = scale * applyResizeFilter(xBlur, resizeFilterType, resizeFilterCubicCoefficients);
2750 const char* accelerateKernels2 =
2754 inline unsigned int getNumWorkItemsPerPixel(
const unsigned int pixelPerWorkgroup,
const unsigned int numWorkItems) {
2755 return (numWorkItems/pixelPerWorkgroup);
2760 inline int pixelToCompute(
const unsigned itemID,
const unsigned int pixelPerWorkgroup,
const unsigned int numWorkItems) {
2761 const unsigned int numWorkItemsPerPixel = getNumWorkItemsPerPixel(pixelPerWorkgroup, numWorkItems);
2762 int pixelIndex = itemID/numWorkItemsPerPixel;
2763 pixelIndex = (pixelIndex<pixelPerWorkgroup)?pixelIndex:-1;
2770 __kernel __attribute__((reqd_work_group_size(256, 1, 1)))
2771 void ResizeHorizontalFilter(
const __global CLPixelType* inputImage,
const unsigned int inputColumns,
const unsigned int inputRows,
const unsigned int matte
2772 ,
const float xFactor, __global CLPixelType* filteredImage,
const unsigned int filteredColumns,
const unsigned int filteredRows
2773 ,
const int resizeFilterType,
const int resizeWindowType
2774 ,
const __global
float* resizeFilterCubicCoefficients
2775 ,
const float resizeFilterScale,
const float resizeFilterSupport,
const float resizeFilterWindowSupport,
const float resizeFilterBlur
2776 , __local CLPixelType* inputImageCache,
const int numCachedPixels,
const unsigned int pixelPerWorkgroup,
const unsigned int pixelChunkSize
2777 , __local float4* outputPixelCache, __local
float* densityCache, __local
float* gammaCache) {
2781 const unsigned int startX = get_group_id(0)*pixelPerWorkgroup;
2782 const unsigned int stopX =
MagickMin(startX + pixelPerWorkgroup,filteredColumns);
2783 const unsigned int actualNumPixelToCompute = stopX - startX;
2786 float scale =
MagickMax(1.0f/xFactor+MagickEpsilon ,1.0f);
2787 const float support =
MagickMax(scale*resizeFilterSupport,0.5f);
2790 const int cacheRangeStartX =
MagickMax((
int)((startX+0.5f)/xFactor+MagickEpsilon-support+0.5f),(
int)(0));
2791 const int cacheRangeEndX =
MagickMin((
int)(cacheRangeStartX + numCachedPixels), (
int)inputColumns);
2794 const unsigned int y = get_global_id(1);
2795 event_t e = async_work_group_copy(inputImageCache,inputImage+y*inputColumns+cacheRangeStartX,cacheRangeEndX-cacheRangeStartX,0);
2796 wait_group_events(1,&e);
2798 unsigned int totalNumChunks = (actualNumPixelToCompute+pixelChunkSize-1)/pixelChunkSize;
2799 for (
unsigned int chunk = 0; chunk < totalNumChunks; chunk++)
2802 const unsigned int chunkStartX = startX + chunk*pixelChunkSize;
2803 const unsigned int chunkStopX =
MagickMin(chunkStartX + pixelChunkSize, stopX);
2804 const unsigned int actualNumPixelInThisChunk = chunkStopX - chunkStartX;
2807 const unsigned int itemID = get_local_id(0);
2808 const unsigned int numItems = getNumWorkItemsPerPixel(actualNumPixelInThisChunk, get_local_size(0));
2810 const int pixelIndex = pixelToCompute(itemID, actualNumPixelInThisChunk, get_local_size(0));
2812 float4 filteredPixel = (float4)0.0f;
2813 float density = 0.0f;
2816 if (pixelIndex != -1) {
2819 const int x = chunkStartX + pixelIndex;
2823 const unsigned int start = (
unsigned int)
MagickMax(bisect-support+0.5f,0.0f);
2824 const unsigned int stop = (
unsigned int)
MagickMin(bisect+support+0.5f,(
float)inputColumns);
2825 const unsigned int n = stop - start;
2828 unsigned int numStepsPerWorkItem = n / numItems;
2829 numStepsPerWorkItem += ((numItems*numStepsPerWorkItem)==n?0:1);
2831 const unsigned int startStep = (itemID%numItems)*numStepsPerWorkItem;
2832 if (startStep < n) {
2833 const unsigned int stopStep =
MagickMin(startStep+numStepsPerWorkItem, n);
2835 unsigned int cacheIndex = start+startStep-cacheRangeStartX;
2838 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
2839 float4 cp = convert_float4(inputImageCache[cacheIndex]);
2841 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
2842 , (ResizeWeightingFunctionType)resizeWindowType
2843 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
2845 filteredPixel += ((float4)weight)*cp;
2852 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
2853 CLPixelType p = inputImageCache[cacheIndex];
2855 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
2856 , (ResizeWeightingFunctionType)resizeWindowType
2857 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
2860 float4 cp = convert_float4(p);
2862 filteredPixel.x += alpha * cp.x;
2863 filteredPixel.y += alpha * cp.y;
2864 filteredPixel.z += alpha * cp.z;
2865 filteredPixel.w += weight * cp.w;
2875 if (itemID < actualNumPixelInThisChunk) {
2876 outputPixelCache[itemID] = (float4)0.0f;
2877 densityCache[itemID] = 0.0f;
2879 gammaCache[itemID] = 0.0f;
2881 barrier(CLK_LOCAL_MEM_FENCE);
2884 for (
unsigned int i = 0; i < numItems; i++) {
2885 if (pixelIndex != -1) {
2886 if (itemID%numItems == i) {
2887 outputPixelCache[pixelIndex]+=filteredPixel;
2888 densityCache[pixelIndex]+=density;
2890 gammaCache[pixelIndex]+=gamma;
2894 barrier(CLK_LOCAL_MEM_FENCE);
2897 if (itemID < actualNumPixelInThisChunk) {
2899 float density = densityCache[itemID];
2900 float4 filteredPixel = outputPixelCache[itemID];
2901 if (density!= 0.0f && density != 1.0)
2904 filteredPixel *= (float4)density;
2906 filteredImage[y*filteredColumns+chunkStartX+itemID] = (CLPixelType) (
ClampToQuantum(filteredPixel.x)
2912 float density = densityCache[itemID];
2913 float gamma = gammaCache[itemID];
2914 float4 filteredPixel = outputPixelCache[itemID];
2916 if (density!= 0.0f && density != 1.0) {
2918 filteredPixel *= (float4)density;
2929 filteredImage[y*filteredColumns+chunkStartX+itemID] = fp;
2940 __kernel __attribute__((reqd_work_group_size(1, 256, 1)))
2941 void ResizeVerticalFilter(
const __global CLPixelType* inputImage,
const unsigned int inputColumns,
const unsigned int inputRows,
const unsigned int matte
2942 ,
const float yFactor, __global CLPixelType* filteredImage,
const unsigned int filteredColumns,
const unsigned int filteredRows
2943 ,
const int resizeFilterType,
const int resizeWindowType
2944 ,
const __global
float* resizeFilterCubicCoefficients
2945 ,
const float resizeFilterScale,
const float resizeFilterSupport,
const float resizeFilterWindowSupport,
const float resizeFilterBlur
2946 , __local CLPixelType* inputImageCache,
const int numCachedPixels,
const unsigned int pixelPerWorkgroup,
const unsigned int pixelChunkSize
2947 , __local float4* outputPixelCache, __local
float* densityCache, __local
float* gammaCache) {
2951 const unsigned int startY = get_group_id(1)*pixelPerWorkgroup;
2952 const unsigned int stopY =
MagickMin(startY + pixelPerWorkgroup,filteredRows);
2953 const unsigned int actualNumPixelToCompute = stopY - startY;
2956 float scale =
MagickMax(1.0f/yFactor+MagickEpsilon ,1.0f);
2957 const float support =
MagickMax(scale*resizeFilterSupport,0.5f);
2960 const int cacheRangeStartY =
MagickMax((
int)((startY+0.5f)/yFactor+MagickEpsilon-support+0.5f),(
int)(0));
2961 const int cacheRangeEndY =
MagickMin((
int)(cacheRangeStartY + numCachedPixels), (
int)inputRows);
2964 const unsigned int x = get_global_id(0);
2965 event_t e = async_work_group_strided_copy(inputImageCache, inputImage+cacheRangeStartY*inputColumns+x, cacheRangeEndY-cacheRangeStartY, inputColumns, 0);
2966 wait_group_events(1,&e);
2968 unsigned int totalNumChunks = (actualNumPixelToCompute+pixelChunkSize-1)/pixelChunkSize;
2969 for (
unsigned int chunk = 0; chunk < totalNumChunks; chunk++)
2972 const unsigned int chunkStartY = startY + chunk*pixelChunkSize;
2973 const unsigned int chunkStopY =
MagickMin(chunkStartY + pixelChunkSize, stopY);
2974 const unsigned int actualNumPixelInThisChunk = chunkStopY - chunkStartY;
2977 const unsigned int itemID = get_local_id(1);
2978 const unsigned int numItems = getNumWorkItemsPerPixel(actualNumPixelInThisChunk, get_local_size(1));
2980 const int pixelIndex = pixelToCompute(itemID, actualNumPixelInThisChunk, get_local_size(1));
2982 float4 filteredPixel = (float4)0.0f;
2983 float density = 0.0f;
2986 if (pixelIndex != -1) {
2989 const int y = chunkStartY + pixelIndex;
2993 const unsigned int start = (
unsigned int)
MagickMax(bisect-support+0.5f,0.0f);
2994 const unsigned int stop = (
unsigned int)
MagickMin(bisect+support+0.5f,(
float)inputRows);
2995 const unsigned int n = stop - start;
2998 unsigned int numStepsPerWorkItem = n / numItems;
2999 numStepsPerWorkItem += ((numItems*numStepsPerWorkItem)==n?0:1);
3001 const unsigned int startStep = (itemID%numItems)*numStepsPerWorkItem;
3002 if (startStep < n) {
3003 const unsigned int stopStep =
MagickMin(startStep+numStepsPerWorkItem, n);
3005 unsigned int cacheIndex = start+startStep-cacheRangeStartY;
3008 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
3009 float4 cp = convert_float4(inputImageCache[cacheIndex]);
3011 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
3012 , (ResizeWeightingFunctionType)resizeWindowType
3013 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
3015 filteredPixel += ((float4)weight)*cp;
3022 for (
unsigned int i = startStep; i < stopStep; i++,cacheIndex++) {
3023 CLPixelType p = inputImageCache[cacheIndex];
3025 float weight = getResizeFilterWeight(resizeFilterCubicCoefficients,(ResizeWeightingFunctionType)resizeFilterType
3026 , (ResizeWeightingFunctionType)resizeWindowType
3027 , resizeFilterScale, resizeFilterWindowSupport, resizeFilterBlur,scale*(start+i-bisect+0.5));
3030 float4 cp = convert_float4(p);
3032 filteredPixel.x += alpha * cp.x;
3033 filteredPixel.y += alpha * cp.y;
3034 filteredPixel.z += alpha * cp.z;
3035 filteredPixel.w += weight * cp.w;
3045 if (itemID < actualNumPixelInThisChunk) {
3046 outputPixelCache[itemID] = (float4)0.0f;
3047 densityCache[itemID] = 0.0f;
3049 gammaCache[itemID] = 0.0f;
3051 barrier(CLK_LOCAL_MEM_FENCE);
3054 for (
unsigned int i = 0; i < numItems; i++) {
3055 if (pixelIndex != -1) {
3056 if (itemID%numItems == i) {
3057 outputPixelCache[pixelIndex]+=filteredPixel;
3058 densityCache[pixelIndex]+=density;
3060 gammaCache[pixelIndex]+=gamma;
3064 barrier(CLK_LOCAL_MEM_FENCE);
3067 if (itemID < actualNumPixelInThisChunk) {
3069 float density = densityCache[itemID];
3070 float4 filteredPixel = outputPixelCache[itemID];
3071 if (density!= 0.0f && density != 1.0)
3074 filteredPixel *= (float4)density;
3076 filteredImage[(chunkStartY+itemID)*filteredColumns+x] = (CLPixelType) (
ClampToQuantum(filteredPixel.x)
3082 float density = densityCache[itemID];
3083 float gamma = gammaCache[itemID];
3084 float4 filteredPixel = outputPixelCache[itemID];
3086 if (density!= 0.0f && density != 1.0) {
3088 filteredPixel *= (float4)density;
3099 filteredImage[(chunkStartY+itemID)*filteredColumns+x] = fp;
3121 __kernel
void UnsharpMaskBlurColumn(
const __global CLPixelType* inputImage,
3122 const __global float4 *blurRowData, __global CLPixelType *filtered_im,
3123 const unsigned int imageColumns,
const unsigned int imageRows,
3124 __local float4* cachedData, __local
float* cachedFilter,
3125 const ChannelType channel,
const __global
float *filter,
const unsigned int width,
3126 const float gain,
const float threshold)
3128 const unsigned int radius = (width-1)/2;
3131 const int groupX = get_group_id(0);
3132 const int groupStartY = get_group_id(1)*get_local_size(1) - radius;
3133 const int groupStopY = (get_group_id(1)+1)*get_local_size(1) + radius;
3135 if (groupStartY >= 0
3136 && groupStopY < imageRows) {
3137 event_t e = async_work_group_strided_copy(cachedData
3138 ,blurRowData+groupStartY*imageColumns+groupX
3139 ,groupStopY-groupStartY,imageColumns,0);
3140 wait_group_events(1,&e);
3143 for (
int i = get_local_id(1); i < (groupStopY - groupStartY); i+=get_local_size(1)) {
3144 cachedData[i] = blurRowData[ClampToCanvas(groupStartY+i,imageRows)*imageColumns+ groupX];
3146 barrier(CLK_LOCAL_MEM_FENCE);
3149 event_t e = async_work_group_copy(cachedFilter,filter,width,0);
3150 wait_group_events(1,&e);
3154 const int cy = get_global_id(1);
3156 if (cy < imageRows) {
3157 float4 blurredPixel = (float4) 0.0f;
3161 \n #ifndef UFACTOR \n
3162 \n #define UFACTOR 8 \n
3165 for ( ; i+UFACTOR < width; )
3167 \n #pragma unroll UFACTOR \n
3168 for (
int j=0; j < UFACTOR; j++, i++)
3170 blurredPixel+=cachedFilter[i]*cachedData[i+get_local_id(1)];
3174 for ( ; i < width; i++)
3176 blurredPixel+=cachedFilter[i]*cachedData[i+get_local_id(1)];
3182 float4 inputImagePixel = convert_float4(inputImage[cy*imageColumns+groupX]);
3183 float4 outputPixel = inputImagePixel - blurredPixel;
3187 int4 mask = isless(fabs(2.0f*outputPixel), (float4)quantumThreshold);
3188 outputPixel = select(inputImagePixel + outputPixel * gain, inputImagePixel, mask);
3201 __kernel
void UnsharpMask(__global CLPixelType *im, __global CLPixelType *filtered_im,
3202 __constant
float *filter,
3203 const unsigned int width,
3204 const unsigned int imageColumns,
const unsigned int imageRows,
3205 __local float4 *pixels,
3206 const float gain,
const float threshold,
const unsigned int justBlur)
3208 const int x = get_global_id(0);
3209 const int y = get_global_id(1);
3211 const unsigned int radius = (width - 1) / 2;
3213 int row = y - radius;
3214 int baseRow = get_group_id(1) * get_local_size(1) - radius;
3215 int endRow = (get_group_id(1) + 1) * get_local_size(1) + radius;
3217 while (row < endRow) {
3218 int srcy = (row < 0) ? -row : row;
3219 srcy = (srcy >= imageRows) ? (2 * imageRows - srcy - 1) : srcy;
3221 float4 value = 0.0f;
3223 int ix = x - radius;
3226 while (i + 7 < width) {
3227 for (
int j = 0; j < 8; ++j) {
3229 srcx = (srcx < 0) ? -srcx : srcx;
3230 srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx;
3231 value += filter[i + j] * convert_float4(im[srcx + srcy * imageColumns]);
3238 int srcx = (ix < 0) ? -ix : ix;
3239 srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx;
3240 value += filter[i] * convert_float4(im[srcx + srcy * imageColumns]);
3244 pixels[(row - baseRow) * get_local_size(0) + get_local_id(0)] = value;
3245 row += get_local_size(1);
3249 barrier(CLK_LOCAL_MEM_FENCE);
3252 const int px = get_local_id(0);
3253 const int py = get_local_id(1);
3254 const int prp = get_local_size(0);
3255 float4 value = (float4)(0.0f);
3258 while (i + 7 < width) {
3259 value += (float4)(filter[i]) * pixels[px + (py + i) * prp];
3260 value += (float4)(filter[i]) * pixels[px + (py + i + 1) * prp];
3261 value += (float4)(filter[i]) * pixels[px + (py + i + 2) * prp];
3262 value += (float4)(filter[i]) * pixels[px + (py + i + 3) * prp];
3263 value += (float4)(filter[i]) * pixels[px + (py + i + 4) * prp];
3264 value += (float4)(filter[i]) * pixels[px + (py + i + 5) * prp];
3265 value += (float4)(filter[i]) * pixels[px + (py + i + 6) * prp];
3266 value += (float4)(filter[i]) * pixels[px + (py + i + 7) * prp];
3270 value += (float4)(filter[i]) * pixels[px + (py + i) * prp];
3273 if ((x < imageColumns) && (y < imageRows)) {
3274 if (justBlur == 0) {
3275 float4 srcPixel = convert_float4(im[x + y * imageColumns]);
3276 float4 diff = srcPixel - value;
3280 int4 mask = isless(fabs(2.0f * diff), (float4)quantumThreshold);
3281 value = select(srcPixel + diff * gain, srcPixel, mask);
3289 __kernel __attribute__((reqd_work_group_size(64, 4, 1)))
void WaveletDenoise(__global CLPixelType *srcImage, __global CLPixelType *dstImage,
3290 const float threshold,
3292 const int imageWidth,
3293 const int imageHeight)
3295 const int pad = (1 << (passes - 1));
3296 const int tileSize = 64;
3297 const int tileRowPixels = 64;
3298 const float noise[] = { 0.8002, 0.2735, 0.1202, 0.0585, 0.0291, 0.0152, 0.0080, 0.0044 };
3300 CLPixelType stage[16];
3302 local
float buffer[64 * 64];
3304 int srcx = (get_group_id(0) + get_global_offset(0) / tileSize) * (tileSize - 2 * pad) - pad + get_local_id(0);
3305 int srcy = (get_group_id(1) + get_global_offset(1) / 4) * (tileSize - 2 * pad) - pad;
3307 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3308 stage[i / 4] = srcImage[mirrorTop(mirrorBottom(srcx), imageWidth) + (mirrorTop(mirrorBottom(srcy + i) , imageHeight)) * imageWidth];
3312 for (
int channel = 0; channel < 3; ++channel) {
3316 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3317 buffer[get_local_id(0) + i * tileRowPixels] = convert_float(stage[i / 4].s0);
3320 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3321 buffer[get_local_id(0) + i * tileRowPixels] = convert_float(stage[i / 4].s1);
3324 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3325 buffer[get_local_id(0) + i * tileRowPixels] = convert_float(stage[i / 4].s2);
3336 for (
int pass = 0; pass < passes; ++pass) {
3337 const int radius = 1 << pass;
3338 const int x = get_local_id(0);
3339 const float thresh = threshold * noise[pass];
3342 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;
3347 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3348 const int offset = i * tileRowPixels;
3350 tmp[i / 4] = buffer[x + offset];
3351 pixel = 0.5f * tmp[i / 4] + 0.25 * (buffer[mirrorBottom(x - radius) + offset] + buffer[mirrorTop(x + radius, tileSize) + offset]);
3352 barrier(CLK_LOCAL_MEM_FENCE);
3353 buffer[x + offset] = pixel;
3355 barrier(CLK_LOCAL_MEM_FENCE);
3357 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3358 pixel = 0.5f * buffer[x + i * tileRowPixels] + 0.25 * (buffer[x + mirrorBottom(i - radius) * tileRowPixels] + buffer[x + mirrorTop(i + radius, tileRowPixels) * tileRowPixels]);
3359 float delta = tmp[i / 4] - pixel;
3361 if (delta < -thresh)
3363 else if (delta > thresh)
3367 accum[i / 4] += delta;
3370 barrier(CLK_LOCAL_MEM_FENCE);
3371 if (pass < passes - 1)
3372 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3373 buffer[x + i * tileRowPixels] = tmp[i / 4];
3375 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3376 accum[i / 4] += tmp[i / 4];
3377 barrier(CLK_LOCAL_MEM_FENCE);
3382 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3386 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3390 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1))
3395 barrier(CLK_LOCAL_MEM_FENCE);
3400 if ((get_local_id(0) >= pad) && (get_local_id(0) < tileSize - pad) && (srcx >= 0) && (srcx < imageWidth)) {
3402 for (
int i = get_local_id(1); i < tileSize; i += get_local_size(1)) {
3403 if ((i >= pad) && (i < tileSize - pad) && (srcy + i >= 0) && (srcy + i < imageHeight)) {
3404 dstImage[srcx + (srcy + i) * imageWidth] = stage[i / 4];
3412 #endif // MAGICKCORE_OPENCL_SUPPORT 3414 #if defined(__cplusplus) || defined(c_plusplus) 3418 #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:28
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:3569
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:976
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:915
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:26
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:2301
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:27
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: colorspace.h:62
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