223 const double brightness,
const double contrast,
ExceptionInfo *exception)
225 #define BrightnessContastImageTag "BrightnessContast/Image" 239 assert(image != (
Image *) NULL);
244 slope=tan((
double) (
MagickPI*(alpha/100.0+1.0)/4.0));
247 intercept=brightness/100.0+((100-brightness)/200.0)*(1.0-slope);
248 coefficients[0]=slope;
249 coefficients[1]=intercept;
305 #define NumberCLAHEGrays (65536) 322 for (i=0; i < (ssize_t) number_bins; i++)
324 excess=(ssize_t) histogram[i]-(ssize_t) clip_limit;
326 cumulative_excess+=excess;
331 step=cumulative_excess/number_bins;
332 excess=(ssize_t) (clip_limit-step);
333 for (i=0; i < (ssize_t) number_bins; i++)
335 if ((
double) histogram[i] > clip_limit)
336 histogram[i]=(
size_t) clip_limit;
338 if ((ssize_t) histogram[i] > excess)
340 cumulative_excess-=histogram[i]-excess;
341 histogram[i]=(size_t) clip_limit;
345 cumulative_excess-=step;
360 previous_excess=cumulative_excess;
362 q=histogram+number_bins;
363 while ((cumulative_excess != 0) && (p < q))
365 step=number_bins/cumulative_excess;
368 for (p=histogram; (p < q) && (cumulative_excess != 0); p+=step)
369 if ((
double) *p < clip_limit)
376 }
while ((cumulative_excess != 0) && (cumulative_excess < previous_excess));
381 const unsigned short *lut,
const unsigned short *pixels,
size_t *histogram)
392 for (i=0; i < (ssize_t) number_bins; i++)
395 for (i=0; i < (ssize_t) tile_info->
height; i++)
400 q=p+tile_info->
width;
402 histogram[lut[*p++]]++;
403 q+=clahe_info->
width;
404 p=q-tile_info->
width;
409 const size_t *Q22,
const size_t *Q11,
const size_t *Q21,
410 const RectangleInfo *tile,
const unsigned short *lut,
unsigned short *pixels)
421 for (y=(ssize_t) tile->
height; y > 0; y--)
426 for (x=(ssize_t) tile->
width; x > 0; x--)
428 intensity=lut[*pixels];
430 tile->
height)*(y*((double) x*Q12[intensity]+(tile->
width-x)*
431 Q22[intensity])+(tile->
height-y)*((double) x*Q11[intensity]+
432 (tile->
width-x)*Q21[intensity])));
439 const size_t number_bins,
unsigned short *lut)
450 delta=(
unsigned short) ((range_info->
max-range_info->
min)/number_bins+1);
451 for (i=(ssize_t) range_info->
min; i <= (ssize_t) range_info->
max; i++)
452 lut[i]=(
unsigned short) ((i-range_info->
min)/delta);
456 const size_t number_bins,
const size_t number_pixels,
size_t *histogram)
468 scale=(double) (range_info->
max-range_info->
min)/number_pixels;
470 for (i=0; i < (ssize_t) number_bins; i++)
473 histogram[i]=(size_t) (range_info->
min+scale*sum);
474 if (histogram[i] > range_info->
max)
475 histogram[i]=range_info->
max;
481 const size_t number_bins,
const double clip_limit,
unsigned short *pixels)
502 if (clip_limit == 1.0)
505 clahe_info->
y*
sizeof(*tiles));
509 if (lut == (
unsigned short *) NULL)
515 limit=(size_t) (clip_limit*(tile_info->
width*tile_info->
height)/number_bins);
523 for (y=0; y < (ssize_t) clahe_info->
y; y++)
528 for (x=0; x < (ssize_t) clahe_info->
x; x++)
533 histogram=tiles+(number_bins*(y*clahe_info->
x+x));
537 tile_info->
height,histogram);
546 for (y=0; y <= (ssize_t) clahe_info->
y; y++)
570 if (y == (ssize_t) clahe_info->
y)
576 tile.
y=clahe_info->
y-1;
579 for (x=0; x <= (ssize_t) clahe_info->
x; x++)
594 if (x == (ssize_t) clahe_info->
x)
600 tile.
x=clahe_info->
x-1;
604 tiles+(number_bins*(tile.
y*clahe_info->
x+tile.
x)),
605 tiles+(number_bins*(tile.
y*clahe_info->
x+offset.
x)),
606 tiles+(number_bins*(offset.
y*clahe_info->
x+tile.
x)),
607 tiles+(number_bins*(offset.
y*clahe_info->
x+offset.
x)),
619 const size_t height,
const size_t number_bins,
const double clip_limit,
622 #define CLAHEImageTag "CLAHE/Image" 658 assert(image != (
Image *) NULL);
664 tile_info.
width=width;
665 if (tile_info.
width == 0)
668 if (tile_info.
height == 0)
678 clahe_info.
x=(ssize_t) clahe_info.
width/tile_info.
width;
699 for (y=0; y < (ssize_t) clahe_info.
height; y++)
710 (tile_info.
y >> 1),clahe_info.
width,1,exception);
711 if (p == (
const Quantum *) NULL)
716 for (x=0; x < (ssize_t) clahe_info.
width; x++)
718 pixels[n++]=ScaleQuantumToShort(p[0]);
734 status=
CLAHE(&clahe_info,&tile_info,&range_info,number_bins == 0 ?
735 (
size_t) 128 :
MagickMin(number_bins,256),clip_limit,pixels);
743 n=clahe_info.
width*(tile_info.
y >> 1);
744 for (y=0; y < (ssize_t) image->
rows; y++)
761 for (x=0; x < (ssize_t) image->
columns; x++)
763 q[0]=ScaleShortToQuantum(pixels[n++]);
836 #define ClutImageTag "Clut/Image" 857 assert(image != (
Image *) NULL);
859 assert(clut_image != (
Image *) NULL);
879 for (i=0; i <= (ssize_t)
MaxMap; i++)
890 #if defined(MAGICKCORE_OPENMP_SUPPORT) 891 #pragma omp parallel for schedule(static) shared(progress,status) \ 892 magick_number_threads(image,image,image->rows,1) 894 for (y=0; y < (ssize_t) image->
rows; y++)
914 for (x=0; x < (ssize_t) image->
columns; x++)
950 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1013 const char *color_correction_collection,
ExceptionInfo *exception)
1015 #define ColorDecisionListCorrectImageTag "ColorDecisionList/Image" 1017 typedef struct _Correction
1025 typedef struct _ColorCorrection
1073 assert(image != (
Image *) NULL);
1077 if (color_correction_collection == (
const char *) NULL)
1079 ccc=
NewXMLTree((
const char *) color_correction_collection,exception);
1088 color_correction.red.slope=1.0;
1089 color_correction.red.offset=0.0;
1090 color_correction.red.power=1.0;
1091 color_correction.green.slope=1.0;
1092 color_correction.green.offset=0.0;
1093 color_correction.green.power=1.0;
1094 color_correction.blue.slope=1.0;
1095 color_correction.blue.offset=0.0;
1096 color_correction.blue.power=1.0;
1097 color_correction.saturation=0.0;
1110 p=(
const char *) content;
1111 for (i=0; (*p !=
'\0') && (i < 3); i++)
1142 p=(
const char *) content;
1143 for (i=0; (*p !=
'\0') && (i < 3); i++)
1175 p=(
const char *) content;
1176 for (i=0; (*p !=
'\0') && (i < 3); i++)
1214 p=(
const char *) content;
1216 color_correction.saturation=
StringToDouble(token,(
char **) NULL);
1223 " Color Correction Collection:");
1225 " color_correction.red.slope: %g",color_correction.red.slope);
1227 " color_correction.red.offset: %g",color_correction.red.offset);
1229 " color_correction.red.power: %g",color_correction.red.power);
1231 " color_correction.green.slope: %g",color_correction.green.slope);
1233 " color_correction.green.offset: %g",color_correction.green.offset);
1235 " color_correction.green.power: %g",color_correction.green.power);
1237 " color_correction.blue.slope: %g",color_correction.blue.slope);
1239 " color_correction.blue.offset: %g",color_correction.blue.offset);
1241 " color_correction.blue.power: %g",color_correction.blue.power);
1243 " color_correction.saturation: %g",color_correction.saturation);
1249 for (i=0; i <= (ssize_t)
MaxMap; i++)
1251 cdl_map[i].
red=(double) ScaleMapToQuantum((
double)
1253 color_correction.red.offset,color_correction.red.power))));
1254 cdl_map[i].
green=(double) ScaleMapToQuantum((
double)
1256 color_correction.green.offset,color_correction.green.power))));
1257 cdl_map[i].
blue=(double) ScaleMapToQuantum((
double)
1259 color_correction.blue.offset,color_correction.blue.power))));
1262 for (i=0; i < (ssize_t) image->
colors; i++)
1272 image->
colormap[i].
red=luma+color_correction.saturation*cdl_map[
1274 image->
colormap[i].
green=luma+color_correction.saturation*cdl_map[
1276 image->
colormap[i].
blue=luma+color_correction.saturation*cdl_map[
1285 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1286 #pragma omp parallel for schedule(static) shared(progress,status) \ 1287 magick_number_threads(image,image,image->rows,1) 1289 for (y=0; y < (ssize_t) image->
rows; y++)
1308 for (x=0; x < (ssize_t) image->
columns; x++)
1313 (cdl_map[ScaleQuantumToMap(
GetPixelRed(image,q))].red-luma)),q);
1315 (cdl_map[ScaleQuantumToMap(
GetPixelGreen(image,q))].green-luma)),q);
1317 (cdl_map[ScaleQuantumToMap(
GetPixelBlue(image,q))].blue-luma)),q);
1327 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1332 progress,image->
rows);
1372 static void Contrast(
const int sign,
double *red,
double *green,
double *blue)
1382 assert(red != (
double *) NULL);
1383 assert(green != (
double *) NULL);
1384 assert(blue != (
double *) NULL);
1389 brightness+=0.5*sign*(0.5*(sin((
double) (
MagickPI*(brightness-0.5)))+1.0)-
1391 if (brightness > 1.0)
1394 if (brightness < 0.0)
1402 #define ContrastImageTag "Contrast/Image" 1422 assert(image != (
Image *) NULL);
1424 #if defined(MAGICKCORE_OPENCL_SUPPORT) 1425 if (AccelerateContrastImage(image,sharpen,exception) !=
MagickFalse)
1436 for (i=0; i < (ssize_t) image->
colors; i++)
1458 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1459 #pragma omp parallel for schedule(static) shared(progress,status) \ 1460 magick_number_threads(image,image,image->rows,1) 1462 for (y=0; y < (ssize_t) image->
rows; y++)
1483 for (x=0; x < (ssize_t) image->
columns; x++)
1501 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1552 const double black_point,
const double white_point,
ExceptionInfo *exception)
1554 #define MaxRange(color) ((double) ScaleQuantumToMap((Quantum) (color))) 1555 #define ContrastStretchImageTag "ContrastStretch/Image" 1584 assert(image != (
Image *) NULL);
1594 sizeof(*histogram));
1596 sizeof(*stretch_map));
1597 if ((black == (
double *) NULL) || (white == (
double *) NULL) ||
1598 (histogram == (
double *) NULL) || (stretch_map == (
double *) NULL))
1600 if (stretch_map != (
double *) NULL)
1602 if (histogram != (
double *) NULL)
1604 if (white != (
double *) NULL)
1606 if (black != (
double *) NULL)
1616 sizeof(*histogram));
1618 for (y=0; y < (ssize_t) image->
rows; y++)
1629 if (p == (
const Quantum *) NULL)
1634 for (x=0; x < (ssize_t) image->
columns; x++)
1643 pixel=(double) p[i];
1665 for (j=0; j <= (ssize_t)
MaxMap; j++)
1668 if (intensity > black_point)
1671 black[i]=(double) j;
1673 for (j=(ssize_t)
MaxMap; j != 0; j--)
1676 if (intensity > ((
double) image->
columns*image->
rows-white_point))
1679 white[i]=(double) j;
1686 sizeof(*stretch_map));
1692 for (j=0; j <= (ssize_t)
MaxMap; j++)
1698 if (j < (ssize_t) black[i])
1701 if (j > (ssize_t) white[i])
1704 if (black[i] != white[i])
1706 (
double) (
MaxMap*gamma*(j-black[i])));
1717 for (j=0; j < (ssize_t) image->
colors; j++)
1751 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1752 #pragma omp parallel for schedule(static) shared(progress,status) \ 1753 magick_number_threads(image,image,image->rows,1) 1755 for (y=0; y < (ssize_t) image->
rows; y++)
1771 for (x=0; x < (ssize_t) image->
columns; x++)
1782 if (black[j] == white[j])
1785 ScaleQuantumToMap(q[j])+j]);
1796 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1840 #define EnhanceImageTag "Enhance/Image" 1841 #define EnhancePixel(weight) \ 1842 mean=QuantumScale*((double) GetPixelRed(image,r)+pixel.red)/2.0; \ 1843 distance=QuantumScale*((double) GetPixelRed(image,r)-pixel.red); \ 1844 distance_squared=(4.0+mean)*distance*distance; \ 1845 mean=QuantumScale*((double) GetPixelGreen(image,r)+pixel.green)/2.0; \ 1846 distance=QuantumScale*((double) GetPixelGreen(image,r)-pixel.green); \ 1847 distance_squared+=(7.0-mean)*distance*distance; \ 1848 mean=QuantumScale*((double) GetPixelBlue(image,r)+pixel.blue)/2.0; \ 1849 distance=QuantumScale*((double) GetPixelBlue(image,r)-pixel.blue); \ 1850 distance_squared+=(5.0-mean)*distance*distance; \ 1851 mean=QuantumScale*((double) GetPixelBlack(image,r)+pixel.black)/2.0; \ 1852 distance=QuantumScale*((double) GetPixelBlack(image,r)-pixel.black); \ 1853 distance_squared+=(5.0-mean)*distance*distance; \ 1854 mean=QuantumScale*((double) GetPixelAlpha(image,r)+pixel.alpha)/2.0; \ 1855 distance=QuantumScale*((double) GetPixelAlpha(image,r)-pixel.alpha); \ 1856 distance_squared+=(5.0-mean)*distance*distance; \ 1857 if (distance_squared < 0.069) \ 1859 aggregate.red+=(weight)*GetPixelRed(image,r); \ 1860 aggregate.green+=(weight)*GetPixelGreen(image,r); \ 1861 aggregate.blue+=(weight)*GetPixelBlue(image,r); \ 1862 aggregate.black+=(weight)*GetPixelBlack(image,r); \ 1863 aggregate.alpha+=(weight)*GetPixelAlpha(image,r); \ 1864 total_weight+=(weight); \ 1866 r+=GetPixelChannels(image); 1887 assert(image != (
const Image *) NULL);
1895 if (enhance_image == (
Image *) NULL)
1896 return((
Image *) NULL);
1900 return((
Image *) NULL);
1909 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1910 #pragma omp parallel for schedule(static) shared(progress,status) \ 1911 magick_number_threads(image,enhance_image,image->rows,1) 1913 for (y=0; y < (ssize_t) image->
rows; y++)
1942 for (x=0; x < (ssize_t) image->
columns; x++)
1976 pixel.
red=((aggregate.
red+total_weight/2.0)/total_weight);
1977 pixel.
green=((aggregate.
green+total_weight/2.0)/total_weight);
1978 pixel.
blue=((aggregate.
blue+total_weight/2.0)/total_weight);
1979 pixel.
black=((aggregate.
black+total_weight/2.0)/total_weight);
1980 pixel.
alpha=((aggregate.
alpha+total_weight/2.0)/total_weight);
1993 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2006 return(enhance_image);
2036 #define EqualizeImageTag "Equalize/Image" 2063 assert(image != (
Image *) NULL);
2065 #if defined(MAGICKCORE_OPENCL_SUPPORT) 2066 if (AccelerateEqualizeImage(image,exception) !=
MagickFalse)
2072 sizeof(*equalize_map));
2074 sizeof(*histogram));
2076 if ((equalize_map == (
double *) NULL) || (histogram == (
double *) NULL) ||
2077 (map == (
double *) NULL))
2079 if (map != (
double *) NULL)
2081 if (histogram != (
double *) NULL)
2083 if (equalize_map != (
double *) NULL)
2093 sizeof(*histogram));
2095 for (y=0; y < (ssize_t) image->
rows; y++)
2106 if (p == (
const Quantum *) NULL)
2111 for (x=0; x < (ssize_t) image->
columns; x++)
2118 intensity=(double) p[i];
2140 for (j=0; j <= (ssize_t)
MaxMap; j++)
2147 sizeof(*equalize_map));
2148 (void) memset(black,0,
sizeof(*black));
2149 (void) memset(white,0,
sizeof(*white));
2157 if (black[i] != white[i])
2158 for (j=0; j <= (ssize_t)
MaxMap; j++)
2160 ScaleMapToQuantum((
double) ((
MaxMap*(map[
2173 for (j=0; j < (ssize_t) image->
colors; j++)
2179 if (black[channel] != white[channel])
2188 if (black[channel] != white[channel])
2197 if (black[channel] != white[channel])
2206 if (black[channel] != white[channel])
2218 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2219 #pragma omp parallel for schedule(static) shared(progress,status) \ 2220 magick_number_threads(image,image,image->rows,1) 2222 for (y=0; y < (ssize_t) image->
rows; y++)
2238 for (x=0; x < (ssize_t) image->
columns; x++)
2250 ScaleQuantumToMap(q[j])+j]);
2261 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2310 static inline double gamma_pow(
const double value,
const double gamma)
2312 return(value < 0.0 ? value : pow(value,gamma));
2318 #define GammaImageTag "Gamma/Image" 2341 assert(image != (
Image *) NULL);
2348 if (gamma_map == (
Quantum *) NULL)
2351 (void) memset(gamma_map,0,(
MaxMap+1)*
sizeof(*gamma_map));
2353 for (i=0; i <= (ssize_t)
MaxMap; i++)
2354 gamma_map[i]=ScaleMapToQuantum((
double) (
MaxMap*pow((
double) i/
2357 for (i=0; i < (ssize_t) image->
colors; i++)
2363 image->
colormap[i].
red=(double) gamma_map[ScaleQuantumToMap(
2366 image->
colormap[i].
green=(double) gamma_map[ScaleQuantumToMap(
2369 image->
colormap[i].
blue=(double) gamma_map[ScaleQuantumToMap(
2372 image->
colormap[i].
alpha=(double) gamma_map[ScaleQuantumToMap(
2381 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2382 #pragma omp parallel for schedule(static) shared(progress,status) \ 2383 magick_number_threads(image,image,image->rows,1) 2385 for (y=0; y < (ssize_t) image->
rows; y++)
2401 for (x=0; x < (ssize_t) image->
columns; x++)
2424 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2435 if (image->
gamma != 0.0)
2436 image->
gamma*=gamma;
2470 #define GrayscaleImageTag "Grayscale/Image" 2484 assert(image != (
Image *) NULL);
2495 #if defined(MAGICKCORE_OPENCL_SUPPORT) 2496 if (AccelerateGrayscaleImage(image,method,exception) !=
MagickFalse)
2512 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2513 #pragma omp parallel for schedule(static) shared(progress,status) \ 2514 magick_number_threads(image,image,image->rows,1) 2516 for (y=0; y < (ssize_t) image->
rows; y++)
2532 for (x=0; x < (ssize_t) image->
columns; x++)
2548 intensity=(red+green+blue)/3.0;
2576 intensity=0.298839*red+0.586811*green+0.114350*blue;
2587 intensity=0.298839*red+0.586811*green+0.114350*blue;
2599 intensity=0.212656*red+0.715158*green+0.072186*blue;
2610 intensity=0.212656*red+0.715158*green+0.072186*blue;
2616 blue*blue)/sqrt(3.0));
2630 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2682 #define HaldClutImageTag "Clut/Image" 2684 typedef struct _HaldInfo
2716 assert(image != (
Image *) NULL);
2720 assert(hald_image != (
Image *) NULL);
2733 for (level=2; (level*level*level) < length; level++) ;
2735 cube_size=level*level;
2736 width=(double) hald_image->
columns;
2740 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2741 #pragma omp parallel for schedule(static) shared(progress,status) \ 2742 magick_number_threads(image,image,image->rows,1) 2744 for (y=0; y < (ssize_t) image->
rows; y++)
2760 for (x=0; x < (ssize_t) image->
columns; x++)
2779 offset=point.x+level*floor(point.y)+cube_size*floor(point.z);
2780 point.x-=floor(point.x);
2781 point.y-=floor(point.y);
2782 point.z-=floor(point.z);
2785 fmod(offset,width),floor(offset/width),&pixel1,exception);
2790 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2796 area=(point.y < 0.5) ? 0.0 : 1.0;
2801 fmod(offset,width),floor(offset/width),&pixel1,exception);
2805 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2814 area=(point.z < 0.5)? 0.0 : 1.0;
2838 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2897 const double white_point,
const double gamma,
const double pixel)
2906 return(level_pixel);
2910 const double white_point,
const double gamma,
ExceptionInfo *exception)
2912 #define LevelImageTag "Level/Image" 2932 assert(image != (
Image *) NULL);
2937 for (i=0; i < (ssize_t) image->
colors; i++)
2961 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2962 #pragma omp parallel for schedule(static) shared(progress,status) \ 2963 magick_number_threads(image,image,image->rows,1) 2965 for (y=0; y < (ssize_t) image->
rows; y++)
2981 for (x=0; x < (ssize_t) image->
columns; x++)
3004 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3061 const double black_point,
const double white_point,
const double gamma,
3064 #define LevelizeImageTag "Levelize/Image" 3065 #define LevelizeValue(x) ClampToQuantum(((MagickRealType) gamma_pow((double) \ 3066 (QuantumScale*(x)),gamma))*(white_point-black_point)+black_point) 3086 assert(image != (
Image *) NULL);
3091 for (i=0; i < (ssize_t) image->
colors; i++)
3113 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3114 #pragma omp parallel for schedule(static) shared(progress,status) \ 3115 magick_number_threads(image,image,image->rows,1) 3117 for (y=0; y < (ssize_t) image->
rows; y++)
3133 for (x=0; x < (ssize_t) image->
columns; x++)
3155 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3222 assert(image != (
Image *) NULL);
3346 const double black_point,
const double white_point,
ExceptionInfo *exception)
3348 #define LinearStretchImageTag "LinearStretch/Image" 3368 assert(image != (
Image *) NULL);
3371 if (histogram == (
double *) NULL)
3377 (void) memset(histogram,0,(
MaxMap+1)*
sizeof(*histogram));
3379 for (y=0; y < (ssize_t) image->
rows; y++)
3388 if (p == (
const Quantum *) NULL)
3390 for (x=0; x < (ssize_t) image->
columns; x++)
3402 for (black=0; black < (ssize_t)
MaxMap; black++)
3404 intensity+=histogram[black];
3405 if (intensity >= black_point)
3409 for (white=(ssize_t)
MaxMap; white != 0; white--)
3411 intensity+=histogram[white];
3412 if (intensity >= white_point)
3417 (
double) ScaleMapToQuantum((
MagickRealType) white),1.0,exception);
3455 const double percent_chroma,
const double percent_luma,
double *red,
3456 double *green,
double *blue)
3467 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3468 chroma*=0.01*percent_chroma;
3469 luma*=0.01*percent_luma;
3474 const double percent_chroma,
const double percent_luma,
double *red,
3475 double *green,
double *blue)
3486 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3487 chroma*=0.01*percent_chroma;
3488 luma*=0.01*percent_luma;
3493 const double percent_saturation,
const double percent_brightness,
double *red,
3494 double *green,
double *blue)
3505 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3506 saturation*=0.01*percent_saturation;
3507 brightness*=0.01*percent_brightness;
3512 const double percent_saturation,
const double percent_intensity,
double *red,
3513 double *green,
double *blue)
3524 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3525 saturation*=0.01*percent_saturation;
3526 intensity*=0.01*percent_intensity;
3531 const double percent_saturation,
const double percent_lightness,
double *red,
3532 double *green,
double *blue)
3543 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3544 saturation*=0.01*percent_saturation;
3545 lightness*=0.01*percent_lightness;
3550 const double percent_saturation,
const double percent_value,
double *red,
3551 double *green,
double *blue)
3562 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3563 saturation*=0.01*percent_saturation;
3564 value*=0.01*percent_value;
3569 const double percent_whiteness,
const double percent_blackness,
double *red,
3570 double *green,
double *blue)
3581 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3582 blackness*=0.01*percent_blackness;
3583 whiteness*=0.01*percent_whiteness;
3588 const double percent_chroma,
const double percent_hue,
3589 const IlluminantType illuminant,
double *red,
double *green,
double *blue)
3600 luma*=0.01*percent_luma;
3601 chroma*=0.01*percent_chroma;
3602 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3607 const double percent_chroma,
const double percent_hue,
3608 const IlluminantType illuminant,
double *red,
double *green,
double *blue)
3619 luma*=0.01*percent_luma;
3620 chroma*=0.01*percent_chroma;
3621 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3628 #define ModulateImageTag "Modulate/Image" 3640 percent_brightness = 100.0,
3641 percent_hue = 100.0,
3642 percent_saturation = 100.0;
3668 assert(image != (
Image *) NULL);
3672 if (modulate == (
char *) NULL)
3678 percent_brightness=geometry_info.
rho;
3680 percent_saturation=geometry_info.
sigma;
3682 percent_hue=geometry_info.
xi;
3684 if (artifact != (
const char *) NULL)
3688 if (artifact != (
const char *) NULL)
3692 if ((ssize_t) illuminant < 0)
3699 for (i=0; i < (ssize_t) image->
colors; i++)
3716 ModulateHCL(percent_hue,percent_saturation,percent_brightness,
3722 ModulateHCLp(percent_hue,percent_saturation,percent_brightness,
3728 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
3734 ModulateHSI(percent_hue,percent_saturation,percent_brightness,
3741 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
3747 ModulateHSV(percent_hue,percent_saturation,percent_brightness,
3753 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
3760 ModulateLCHab(percent_brightness,percent_saturation,percent_hue,
3761 illuminant,&red,&green,&blue);
3766 ModulateLCHuv(percent_brightness,percent_saturation,percent_hue,
3767 illuminant,&red,&green,&blue);
3778 #if defined(MAGICKCORE_OPENCL_SUPPORT) 3779 if (AccelerateModulateImage(image,percent_brightness,percent_hue,
3780 percent_saturation,colorspace,exception) !=
MagickFalse)
3786 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3787 #pragma omp parallel for schedule(static) shared(progress,status) \ 3788 magick_number_threads(image,image,image->rows,1) 3790 for (y=0; y < (ssize_t) image->
rows; y++)
3806 for (x=0; x < (ssize_t) image->
columns; x++)
3820 ModulateHCL(percent_hue,percent_saturation,percent_brightness,
3826 ModulateHCLp(percent_hue,percent_saturation,percent_brightness,
3832 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
3839 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
3845 ModulateHSV(percent_hue,percent_saturation,percent_brightness,
3851 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
3857 ModulateLCHab(percent_brightness,percent_saturation,percent_hue,
3858 illuminant,&red,&green,&blue);
3864 ModulateLCHuv(percent_brightness,percent_saturation,percent_hue,
3865 illuminant,&red,&green,&blue);
3881 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3925 #define NegateImageTag "Negate/Image" 3942 assert(image != (
Image *) NULL);
3947 for (i=0; i < (ssize_t) image->
colors; i++)
3971 for (y=0; y < (ssize_t) image->
rows; y++)
3991 for (x=0; x < (ssize_t) image->
columns; x++)
4031 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4032 #pragma omp parallel for schedule(static) shared(progress,status) \ 4033 magick_number_threads(image,image,image->rows,1) 4035 for (y=0; y < (ssize_t) image->
rows; y++)
4051 for (x=0; x < (ssize_t) image->
columns; x++)
4073 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4119 black_point=(double) image->
columns*image->
rows*0.0015;
4120 white_point=(
double) image->
columns*image->
rows*0.9995;
4188 #if defined(MAGICKCORE_HAVE_ATANH) 4189 #define Sigmoidal(a,b,x) ( tanh((0.5*(a))*((x)-(b))) ) 4191 #define Sigmoidal(a,b,x) ( 1.0/(1.0+exp((a)*((b)-(x)))) ) 4210 #define ScaledSigmoidal(a,b,x) ( \ 4211 (Sigmoidal((a),(b),(x))-Sigmoidal((a),(b),0.0)) / \ 4212 (Sigmoidal((a),(b),1.0)-Sigmoidal((a),(b),0.0)) ) 4227 const double argument=(sig1-sig0)*x+sig0;
4228 const double clamped=
4230 #if defined(MAGICKCORE_HAVE_ATANH) 4237 return(b+(2.0/a)*atanh(clamped));
4245 return(b-log(1.0/clamped-1.0)/a);
4253 #define SigmoidalContrastImageTag "SigmoidalContrast/Image" 4254 #define ScaledSig(x) ( ClampToQuantum(QuantumRange* \ 4255 ScaledSigmoidal(contrast,QuantumScale*midpoint,QuantumScale*(x))) ) 4256 #define InverseScaledSig(x) ( ClampToQuantum(QuantumRange* \ 4257 InverseScaledSigmoidal(contrast,QuantumScale*midpoint,QuantumScale*(x))) ) 4274 assert(image != (
Image *) NULL);
4293 for (i=0; i < (ssize_t) image->
colors; i++)
4309 for (i=0; i < (ssize_t) image->
colors; i++)
4331 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4332 #pragma omp parallel for schedule(static) shared(progress,status) \ 4333 magick_number_threads(image,image,image->rows,1) 4335 for (y=0; y < (ssize_t) image->
rows; y++)
4351 for (x=0; x < (ssize_t) image->
columns; x++)
4376 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4419 #define WhiteBalanceImageTag "WhiteBalance/Image" 4443 assert(image != (
Image *) NULL);
4453 for (y=0; y < (ssize_t) image->
rows; y++)
4469 for (x=0; x < (ssize_t) image->
columns; x++)
4479 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4480 #pragma omp parallel for schedule(static) shared(progress,status) \ 4481 magick_number_threads(image,image,image->rows,1) 4483 for (y=0; y < (ssize_t) image->
rows; y++)
4499 for (x=0; x < (ssize_t) image->
columns; x++)
4521 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4532 if (artifact != (
const char *) NULL)
4551 black_point=geometry_info.
rho;
MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel)
MagickDoubleType MagickRealType
MagickExport MagickBooleanType NegateImage(Image *image, const MagickBooleanType grayscale, ExceptionInfo *exception)
PixelIntensityMethod intensity
MagickExport MagickBooleanType LevelizeImage(Image *image, const double black_point, const double white_point, const double gamma, ExceptionInfo *exception)
MagickExport CacheView * DestroyCacheView(CacheView *cache_view)
MagickExport MagickBooleanType LinearStretchImage(Image *image, const double black_point, const double white_point, ExceptionInfo *exception)
MagickExport MagickBooleanType AutoGammaImage(Image *image, ExceptionInfo *exception)
static ssize_t GetPixelChannelOffset(const Image *magick_restrict image, const PixelChannel channel)
static void ModulateHWB(const double percent_hue, const double percent_whiteness, const double percent_blackness, double *red, double *green, double *blue)
MagickExport void ConvertRGBToHSL(const double red, const double green, const double blue, double *hue, double *saturation, double *lightness)
MagickExport MemoryInfo * RelinquishVirtualMemory(MemoryInfo *memory_info)
MagickPrivate void ConvertHSIToRGB(const double, const double, const double, double *, double *, double *)
MagickExport XMLTreeInfo * DestroyXMLTree(XMLTreeInfo *xml_info)
MagickProgressMonitor progress_monitor
static PixelTrait GetPixelBlackTraits(const Image *magick_restrict image)
MagickExport MagickBooleanType SyncImage(Image *image, ExceptionInfo *exception)
static PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
MagickExport MagickBooleanType TransformImageColorspace(Image *image, const ColorspaceType colorspace, ExceptionInfo *exception)
#define Sigmoidal(a, b, x)
static PixelTrait GetPixelAlphaTraits(const Image *magick_restrict image)
static Quantum GetPixelRed(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static void GenerateCLAHEHistogram(const RectangleInfo *clahe_info, const RectangleInfo *tile_info, const size_t number_bins, const unsigned short *lut, const unsigned short *pixels, size_t *histogram)
MagickExport ssize_t ParseCommandOption(const CommandOption option, const MagickBooleanType list, const char *options)
MagickExport MagickBooleanType FunctionImage(Image *image, const MagickFunction function, const size_t number_parameters, const double *parameters, ExceptionInfo *exception)
static MagickBooleanType CLAHE(const RectangleInfo *clahe_info, const RectangleInfo *tile_info, const RangeInfo *range_info, const size_t number_bins, const double clip_limit, unsigned short *pixels)
static void ModulateHCLp(const double percent_hue, const double percent_chroma, const double percent_luma, double *red, double *green, double *blue)
MagickPrivate void ConvertLCHuvToRGB(const double, const double, const double, const IlluminantType, double *, double *, double *)
PixelInterpolateMethod interpolate
MagickExport MemoryInfo * AcquireVirtualMemory(const size_t count, const size_t quantum)
static double LevelPixel(const double black_point, const double white_point, const double gamma, const double pixel)
MagickPrivate void ConvertRGBToLCHuv(const double, const double, const double, const IlluminantType, double *, double *, double *)
static void SetPixelGray(const Image *magick_restrict image, const Quantum gray, Quantum *magick_restrict pixel)
MagickExport const char * GetImageArtifact(const Image *image, const char *artifact)
static PixelTrait GetPixelChannelTraits(const Image *magick_restrict image, const PixelChannel channel)
MagickExport MagickBooleanType EqualizeImage(Image *image, ExceptionInfo *exception)
MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image, const CacheView_ *image_view, const PixelInterpolateMethod method, const double x, const double y, PixelInfo *pixel, ExceptionInfo *exception)
static void SetPixelViaPixelInfo(const Image *magick_restrict image, const PixelInfo *magick_restrict pixel_info, Quantum *magick_restrict pixel)
static MagickBooleanType IsGrayColorspace(const ColorspaceType colorspace)
static Quantum GetPixela(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static void ModulateHSL(const double percent_hue, const double percent_saturation, const double percent_lightness, double *red, double *green, double *blue)
static void SetPixela(const Image *magick_restrict image, const Quantum a, Quantum *magick_restrict pixel)
MagickExport const Quantum * GetCacheViewVirtualPixels(const CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
static double gamma_pow(const double value, const double gamma)
MagickExport MagickBooleanType GrayscaleImage(Image *image, const PixelIntensityMethod method, ExceptionInfo *exception)
static Quantum GetPixelb(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport XMLTreeInfo * GetXMLTreeChild(XMLTreeInfo *xml_info, const char *tag)
static MagickBooleanType IsGrayImageType(const ImageType type)
#define ThrowBinaryException(severity, tag, context)
static Quantum ClampToQuantum(const MagickRealType quantum)
MagickExport void GetPixelInfo(const Image *image, PixelInfo *pixel)
MagickExport MagickBooleanType ColorDecisionListImage(Image *image, const char *color_correction_collection, ExceptionInfo *exception)
MagickPrivate void ConvertRGBToHSB(const double, const double, const double, double *, double *, double *)
MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
MagickExport MagickBooleanType ContrastImage(Image *image, const MagickBooleanType sharpen, ExceptionInfo *exception)
#define MagickCoreSignature
MagickExport MagickBooleanType WhiteBalanceImage(Image *image, ExceptionInfo *exception)
MagickExport Quantum * GetCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
MagickExport MagickBooleanType SetImageAlphaChannel(Image *image, const AlphaChannelOption alpha_type, ExceptionInfo *exception)
unsigned int MagickStatusType
MagickPrivate void ConvertLCHabToRGB(const double, const double, const double, const IlluminantType, double *, double *, double *)
static double PerceptibleReciprocal(const double x)
MagickExport Image * EnhanceImage(const Image *image, ExceptionInfo *exception)
#define GrayscaleImageTag
#define ContrastStretchImageTag
static MagickBooleanType IssRGBCompatibleColorspace(const ColorspaceType colorspace)
MagickExport MagickBooleanType NormalizeImage(Image *image, ExceptionInfo *exception)
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
MagickExport magick_hot_spot size_t GetNextToken(const char *magick_restrict start, const char **magick_restrict end, const size_t extent, char *magick_restrict token)
MagickExport MagickBooleanType ModulateImage(Image *image, const char *modulate, ExceptionInfo *exception)
static void Contrast(const int sign, double *red, double *green, double *blue)
MagickExport MagickBooleanType CLAHEImage(Image *image, const size_t width, const size_t height, const size_t number_bins, const double clip_limit, ExceptionInfo *exception)
MagickExport const char * GetXMLTreeContent(XMLTreeInfo *xml_info)
static Quantum GetPixelGreen(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static void CompositePixelInfoAreaBlend(const PixelInfo *p, const double alpha, const PixelInfo *q, const double beta, const double area, PixelInfo *composite)
static void InterpolateCLAHE(const RectangleInfo *clahe_info, const size_t *Q12, const size_t *Q22, const size_t *Q11, const size_t *Q21, const RectangleInfo *tile, const unsigned short *lut, unsigned short *pixels)
static void GetPixelInfoPixel(const Image *magick_restrict image, const Quantum *magick_restrict pixel, PixelInfo *magick_restrict pixel_info)
MagickExport MagickBooleanType IsEventLogging(void)
MagickPrivate void ConvertRGBToHSV(const double, const double, const double, double *, double *, double *)
#define EnhancePixel(weight)
MagickExport ChannelType SetImageChannelMask(Image *image, const ChannelType channel_mask)
MagickExport Quantum * QueueCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
static void ModulateHCL(const double percent_hue, const double percent_chroma, const double percent_luma, double *red, double *green, double *blue)
MagickPrivate void ConvertRGBToHSI(const double, const double, const double, double *, double *, double *)
static void ModulateHSI(const double percent_hue, const double percent_saturation, const double percent_intensity, double *red, double *green, double *blue)
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
static void * adjust(void *const p)
MagickExport MagickBooleanType LevelImageColors(Image *image, const PixelInfo *black_color, const PixelInfo *white_color, const MagickBooleanType invert, ExceptionInfo *exception)
MagickBooleanType(* MagickProgressMonitor)(const char *, const MagickOffsetType, const MagickSizeType, void *)
static MagickBooleanType IsPixelGray(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport ImageType IdentifyImageType(const Image *image, ExceptionInfo *exception)
static PixelTrait GetPixelGreenTraits(const Image *magick_restrict image)
static void SetPixelBlue(const Image *magick_restrict image, const Quantum blue, Quantum *magick_restrict pixel)
MagickExport MagickBooleanType SetImageStorageClass(Image *image, const ClassType storage_class, ExceptionInfo *exception)
struct _RangeInfo RangeInfo
MagickExport void ConvertHSLToRGB(const double hue, const double saturation, const double lightness, double *red, double *green, double *blue)
MagickExport MagickBooleanType GetImageMean(const Image *image, double *mean, double *standard_deviation, ExceptionInfo *exception)
MagickExport MagickBooleanType ClutImage(Image *image, const Image *clut_image, const PixelInterpolateMethod method, ExceptionInfo *exception)
static size_t GetPixelChannels(const Image *magick_restrict image)
MagickPrivate void ConvertHWBToRGB(const double, const double, const double, double *, double *, double *)
char filename[MagickPathExtent]
#define SigmoidalContrastImageTag
#define GetMagickModule()
#define InverseScaledSig(x)
static PixelChannel GetPixelChannelChannel(const Image *magick_restrict image, const ssize_t offset)
MagickExport CacheView * AcquireVirtualCacheView(const Image *image, ExceptionInfo *exception)
MagickExport MagickBooleanType MinMaxStretchImage(Image *image, const double black, const double white, const double gamma, ExceptionInfo *exception)
MagickExport MagickBooleanType SetImageColorspace(Image *image, const ColorspaceType colorspace, ExceptionInfo *exception)
MagickExport MagickBooleanType LevelImage(Image *image, const double black_point, const double white_point, const double gamma, ExceptionInfo *exception)
MagickPrivate void ConvertHSVToRGB(const double, const double, const double, double *, double *, double *)
MagickExport MagickStatusType ParseGeometry(const char *geometry, GeometryInfo *geometry_info)
static void ModulateHSV(const double percent_hue, const double percent_saturation, const double percent_value, double *red, double *green, double *blue)
static void ModulateHSB(const double percent_hue, const double percent_saturation, const double percent_brightness, double *red, double *green, double *blue)
static void SetPixelAlpha(const Image *magick_restrict image, const Quantum alpha, Quantum *magick_restrict pixel)
static double StringToDouble(const char *magick_restrict string, char *magick_restrict *sentinal)
MagickPrivate void ConvertHCLToRGB(const double, const double, const double, double *, double *, double *)
static void GenerateCLAHELut(const RangeInfo *range_info, const size_t number_bins, unsigned short *lut)
MagickPrivate void ConvertRGBToHWB(const double, const double, const double, double *, double *, double *)
static void ModulateLCHab(const double percent_luma, const double percent_chroma, const double percent_hue, const IlluminantType illuminant, double *red, double *green, double *blue)
MagickPrivate void ConvertHCLpToRGB(const double, const double, const double, double *, double *, double *)
MagickExport void * RelinquishMagickMemory(void *memory)
MagickExport MagickBooleanType HaldClutImage(Image *image, const Image *hald_image, ExceptionInfo *exception)
MagickExport MagickBooleanType GammaImage(Image *image, const double gamma, ExceptionInfo *exception)
MagickExport MagickBooleanType ClampImage(Image *image, ExceptionInfo *exception)
#define WhiteBalanceImageTag
static void SetPixelRed(const Image *magick_restrict image, const Quantum red, Quantum *magick_restrict pixel)
MagickExport MagickBooleanType AutoLevelImage(Image *image, ExceptionInfo *exception)
MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(CacheView *magick_restrict cache_view, ExceptionInfo *exception)
MagickPrivate void ConvertHSBToRGB(const double, const double, const double, double *, double *, double *)
MagickExport CacheView * AcquireAuthenticCacheView(const Image *image, ExceptionInfo *exception)
MagickExport MagickBooleanType SigmoidalContrastImage(Image *image, const MagickBooleanType sharpen, const double contrast, const double midpoint, ExceptionInfo *exception)
static void SetPixelb(const Image *magick_restrict image, const Quantum b, Quantum *magick_restrict pixel)
ColorspaceType colorspace
static void MapCLAHEHistogram(const RangeInfo *range_info, const size_t number_bins, const size_t number_pixels, size_t *histogram)
MagickPrivate void ConvertRGBToHCL(const double, const double, const double, double *, double *, double *)
static void SetPixelBlack(const Image *magick_restrict image, const Quantum black, Quantum *magick_restrict pixel)
static Quantum GetPixelBlue(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport void * GetVirtualMemoryBlob(const MemoryInfo *memory_info)
static double InverseScaledSigmoidal(const double a, const double b, const double x)
MagickExport MagickRealType GetPixelIntensity(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport MagickBooleanType ContrastStretchImage(Image *image, const double black_point, const double white_point, ExceptionInfo *exception)
static void ModulateLCHuv(const double percent_luma, const double percent_chroma, const double percent_hue, const IlluminantType illuminant, double *red, double *green, double *blue)
MagickPrivate void ConvertRGBToLCHab(const double, const double, const double, const IlluminantType, double *, double *, double *)
MagickExport Image * DestroyImage(Image *image)
#define ColorDecisionListCorrectImageTag
MagickExport Image * CloneImage(const Image *image, const size_t columns, const size_t rows, const MagickBooleanType detach, ExceptionInfo *exception)
ColorspaceType colorspace
static Quantum GetPixelL(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport XMLTreeInfo * NewXMLTree(const char *xml, ExceptionInfo *exception)
MagickExport MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
static void ClipCLAHEHistogram(const double clip_limit, const size_t number_bins, size_t *histogram)
MagickPrivate void ConvertRGBToHCLp(const double, const double, const double, double *, double *, double *)
static void SetPixelGreen(const Image *magick_restrict image, const Quantum green, Quantum *magick_restrict pixel)
MagickExport MagickBooleanType BrightnessContrastImage(Image *image, const double brightness, const double contrast, ExceptionInfo *exception)
static PixelTrait GetPixelBlueTraits(const Image *magick_restrict image)