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);
861 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" 1581 assert(image != (
Image *) NULL);
1590 sizeof(*histogram));
1592 sizeof(*stretch_map));
1593 if ((black == (
double *) NULL) || (white == (
double *) NULL) ||
1594 (histogram == (
double *) NULL) || (stretch_map == (
double *) NULL))
1596 if (stretch_map != (
double *) NULL)
1598 if (histogram != (
double *) NULL)
1600 if (white != (
double *) NULL)
1602 if (black != (
double *) NULL)
1612 sizeof(*histogram));
1614 for (y=0; y < (ssize_t) image->
rows; y++)
1625 if (p == (
const Quantum *) NULL)
1630 for (x=0; x < (ssize_t) image->
columns; x++)
1639 pixel=(double) p[i];
1661 for (j=0; j <= (ssize_t)
MaxMap; j++)
1664 if (intensity > black_point)
1667 black[i]=(double) j;
1669 for (j=(ssize_t)
MaxMap; j != 0; j--)
1672 if (intensity > ((
double) image->
columns*image->
rows-white_point))
1675 white[i]=(double) j;
1682 sizeof(*stretch_map));
1688 for (j=0; j <= (ssize_t)
MaxMap; j++)
1694 if (j < (ssize_t) black[i])
1697 if (j > (ssize_t) white[i])
1700 if (black[i] != white[i])
1702 (
double) (
MaxMap*gamma*(j-black[i])));
1713 for (j=0; j < (ssize_t) image->
colors; j++)
1747 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1748 #pragma omp parallel for schedule(static) shared(progress,status) \ 1749 magick_number_threads(image,image,image->rows,1) 1751 for (y=0; y < (ssize_t) image->
rows; y++)
1767 for (x=0; x < (ssize_t) image->
columns; x++)
1778 if (black[j] == white[j])
1781 ScaleQuantumToMap(q[j])+j]);
1792 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1836 #define EnhanceImageTag "Enhance/Image" 1837 #define EnhancePixel(weight) \ 1838 mean=QuantumScale*((double) GetPixelRed(image,r)+pixel.red)/2.0; \ 1839 distance=QuantumScale*((double) GetPixelRed(image,r)-pixel.red); \ 1840 distance_squared=(4.0+mean)*distance*distance; \ 1841 mean=QuantumScale*((double) GetPixelGreen(image,r)+pixel.green)/2.0; \ 1842 distance=QuantumScale*((double) GetPixelGreen(image,r)-pixel.green); \ 1843 distance_squared+=(7.0-mean)*distance*distance; \ 1844 mean=QuantumScale*((double) GetPixelBlue(image,r)+pixel.blue)/2.0; \ 1845 distance=QuantumScale*((double) GetPixelBlue(image,r)-pixel.blue); \ 1846 distance_squared+=(5.0-mean)*distance*distance; \ 1847 mean=QuantumScale*((double) GetPixelBlack(image,r)+pixel.black)/2.0; \ 1848 distance=QuantumScale*((double) GetPixelBlack(image,r)-pixel.black); \ 1849 distance_squared+=(5.0-mean)*distance*distance; \ 1850 mean=QuantumScale*((double) GetPixelAlpha(image,r)+pixel.alpha)/2.0; \ 1851 distance=QuantumScale*((double) GetPixelAlpha(image,r)-pixel.alpha); \ 1852 distance_squared+=(5.0-mean)*distance*distance; \ 1853 if (distance_squared < 0.069) \ 1855 aggregate.red+=(weight)*GetPixelRed(image,r); \ 1856 aggregate.green+=(weight)*GetPixelGreen(image,r); \ 1857 aggregate.blue+=(weight)*GetPixelBlue(image,r); \ 1858 aggregate.black+=(weight)*GetPixelBlack(image,r); \ 1859 aggregate.alpha+=(weight)*GetPixelAlpha(image,r); \ 1860 total_weight+=(weight); \ 1862 r+=GetPixelChannels(image); 1883 assert(image != (
const Image *) NULL);
1891 if (enhance_image == (
Image *) NULL)
1892 return((
Image *) NULL);
1896 return((
Image *) NULL);
1905 #if defined(MAGICKCORE_OPENMP_SUPPORT) 1906 #pragma omp parallel for schedule(static) shared(progress,status) \ 1907 magick_number_threads(image,enhance_image,image->rows,1) 1909 for (y=0; y < (ssize_t) image->
rows; y++)
1938 for (x=0; x < (ssize_t) image->
columns; x++)
1972 pixel.
red=((aggregate.
red+total_weight/2.0)/total_weight);
1973 pixel.
green=((aggregate.
green+total_weight/2.0)/total_weight);
1974 pixel.
blue=((aggregate.
blue+total_weight/2.0)/total_weight);
1975 pixel.
black=((aggregate.
black+total_weight/2.0)/total_weight);
1976 pixel.
alpha=((aggregate.
alpha+total_weight/2.0)/total_weight);
1989 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2002 return(enhance_image);
2032 #define EqualizeImageTag "Equalize/Image" 2059 assert(image != (
Image *) NULL);
2061 #if defined(MAGICKCORE_OPENCL_SUPPORT) 2062 if (AccelerateEqualizeImage(image,exception) !=
MagickFalse)
2068 sizeof(*equalize_map));
2070 sizeof(*histogram));
2072 if ((equalize_map == (
double *) NULL) || (histogram == (
double *) NULL) ||
2073 (map == (
double *) NULL))
2075 if (map != (
double *) NULL)
2077 if (histogram != (
double *) NULL)
2079 if (equalize_map != (
double *) NULL)
2089 sizeof(*histogram));
2091 for (y=0; y < (ssize_t) image->
rows; y++)
2102 if (p == (
const Quantum *) NULL)
2107 for (x=0; x < (ssize_t) image->
columns; x++)
2114 intensity=(double) p[i];
2136 for (j=0; j <= (ssize_t)
MaxMap; j++)
2143 sizeof(*equalize_map));
2144 (void) memset(black,0,
sizeof(*black));
2145 (void) memset(white,0,
sizeof(*white));
2153 if (black[i] != white[i])
2154 for (j=0; j <= (ssize_t)
MaxMap; j++)
2156 ScaleMapToQuantum((
double) ((
MaxMap*(map[
2169 for (j=0; j < (ssize_t) image->
colors; j++)
2175 if (black[channel] != white[channel])
2184 if (black[channel] != white[channel])
2193 if (black[channel] != white[channel])
2202 if (black[channel] != white[channel])
2214 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2215 #pragma omp parallel for schedule(static) shared(progress,status) \ 2216 magick_number_threads(image,image,image->rows,1) 2218 for (y=0; y < (ssize_t) image->
rows; y++)
2234 for (x=0; x < (ssize_t) image->
columns; x++)
2246 ScaleQuantumToMap(q[j])+j]);
2257 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2306 static inline double gamma_pow(
const double value,
const double gamma)
2308 return(value < 0.0 ? value : pow(value,gamma));
2314 #define GammaImageTag "Gamma/Image" 2337 assert(image != (
Image *) NULL);
2344 if (gamma_map == (
Quantum *) NULL)
2347 (void) memset(gamma_map,0,(
MaxMap+1)*
sizeof(*gamma_map));
2349 for (i=0; i <= (ssize_t)
MaxMap; i++)
2350 gamma_map[i]=ScaleMapToQuantum((
double) (
MaxMap*pow((
double) i/
2353 for (i=0; i < (ssize_t) image->
colors; i++)
2359 image->
colormap[i].
red=(double) gamma_map[ScaleQuantumToMap(
2362 image->
colormap[i].
green=(double) gamma_map[ScaleQuantumToMap(
2365 image->
colormap[i].
blue=(double) gamma_map[ScaleQuantumToMap(
2368 image->
colormap[i].
alpha=(double) gamma_map[ScaleQuantumToMap(
2377 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2378 #pragma omp parallel for schedule(static) shared(progress,status) \ 2379 magick_number_threads(image,image,image->rows,1) 2381 for (y=0; y < (ssize_t) image->
rows; y++)
2397 for (x=0; x < (ssize_t) image->
columns; x++)
2420 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2431 if (image->
gamma != 0.0)
2432 image->
gamma*=gamma;
2466 #define GrayscaleImageTag "Grayscale/Image" 2480 assert(image != (
Image *) NULL);
2491 #if defined(MAGICKCORE_OPENCL_SUPPORT) 2492 if (AccelerateGrayscaleImage(image,method,exception) !=
MagickFalse)
2508 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2509 #pragma omp parallel for schedule(static) shared(progress,status) \ 2510 magick_number_threads(image,image,image->rows,1) 2512 for (y=0; y < (ssize_t) image->
rows; y++)
2528 for (x=0; x < (ssize_t) image->
columns; x++)
2544 intensity=(red+green+blue)/3.0;
2572 intensity=0.298839*red+0.586811*green+0.114350*blue;
2583 intensity=0.298839*red+0.586811*green+0.114350*blue;
2595 intensity=0.212656*red+0.715158*green+0.072186*blue;
2606 intensity=0.212656*red+0.715158*green+0.072186*blue;
2612 blue*blue)/sqrt(3.0));
2626 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2678 #define HaldClutImageTag "Clut/Image" 2680 typedef struct _HaldInfo
2712 assert(image != (
Image *) NULL);
2716 assert(hald_image != (
Image *) NULL);
2729 for (level=2; (level*level*level) < length; level++) ;
2731 cube_size=level*level;
2732 width=(double) hald_image->
columns;
2736 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2737 #pragma omp parallel for schedule(static) shared(progress,status) \ 2738 magick_number_threads(image,image,image->rows,1) 2740 for (y=0; y < (ssize_t) image->
rows; y++)
2756 for (x=0; x < (ssize_t) image->
columns; x++)
2775 offset=point.x+level*floor(point.y)+cube_size*floor(point.z);
2776 point.x-=floor(point.x);
2777 point.y-=floor(point.y);
2778 point.z-=floor(point.z);
2781 fmod(offset,width),floor(offset/width),&pixel1,exception);
2786 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2792 area=(point.y < 0.5) ? 0.0 : 1.0;
2797 fmod(offset,width),floor(offset/width),&pixel1,exception);
2801 fmod(offset+level,width),floor((offset+level)/width),&pixel2,exception);
2810 area=(point.z < 0.5)? 0.0 : 1.0;
2834 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2893 const double white_point,
const double gamma,
const double pixel)
2902 return(level_pixel);
2906 const double white_point,
const double gamma,
ExceptionInfo *exception)
2908 #define LevelImageTag "Level/Image" 2928 assert(image != (
Image *) NULL);
2933 for (i=0; i < (ssize_t) image->
colors; i++)
2957 #if defined(MAGICKCORE_OPENMP_SUPPORT) 2958 #pragma omp parallel for schedule(static) shared(progress,status) \ 2959 magick_number_threads(image,image,image->rows,1) 2961 for (y=0; y < (ssize_t) image->
rows; y++)
2977 for (x=0; x < (ssize_t) image->
columns; x++)
3000 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3057 const double black_point,
const double white_point,
const double gamma,
3060 #define LevelizeImageTag "Levelize/Image" 3061 #define LevelizeValue(x) ClampToQuantum(((MagickRealType) gamma_pow((double) \ 3062 (QuantumScale*(x)),gamma))*(white_point-black_point)+black_point) 3082 assert(image != (
Image *) NULL);
3087 for (i=0; i < (ssize_t) image->
colors; i++)
3109 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3110 #pragma omp parallel for schedule(static) shared(progress,status) \ 3111 magick_number_threads(image,image,image->rows,1) 3113 for (y=0; y < (ssize_t) image->
rows; y++)
3129 for (x=0; x < (ssize_t) image->
columns; x++)
3151 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3218 assert(image != (
Image *) NULL);
3342 const double black_point,
const double white_point,
ExceptionInfo *exception)
3344 #define LinearStretchImageTag "LinearStretch/Image" 3364 assert(image != (
Image *) NULL);
3367 if (histogram == (
double *) NULL)
3373 (void) memset(histogram,0,(
MaxMap+1)*
sizeof(*histogram));
3375 for (y=0; y < (ssize_t) image->
rows; y++)
3384 if (p == (
const Quantum *) NULL)
3386 for (x=0; x < (ssize_t) image->
columns; x++)
3398 for (black=0; black < (ssize_t)
MaxMap; black++)
3400 intensity+=histogram[black];
3401 if (intensity >= black_point)
3405 for (white=(ssize_t)
MaxMap; white != 0; white--)
3407 intensity+=histogram[white];
3408 if (intensity >= white_point)
3413 (
double) ScaleMapToQuantum((
MagickRealType) white),1.0,exception);
3451 const double percent_chroma,
const double percent_luma,
double *red,
3452 double *green,
double *blue)
3463 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3464 chroma*=0.01*percent_chroma;
3465 luma*=0.01*percent_luma;
3470 const double percent_chroma,
const double percent_luma,
double *red,
3471 double *green,
double *blue)
3482 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3483 chroma*=0.01*percent_chroma;
3484 luma*=0.01*percent_luma;
3489 const double percent_saturation,
const double percent_brightness,
double *red,
3490 double *green,
double *blue)
3501 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3502 saturation*=0.01*percent_saturation;
3503 brightness*=0.01*percent_brightness;
3508 const double percent_saturation,
const double percent_intensity,
double *red,
3509 double *green,
double *blue)
3520 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3521 saturation*=0.01*percent_saturation;
3522 intensity*=0.01*percent_intensity;
3527 const double percent_saturation,
const double percent_lightness,
double *red,
3528 double *green,
double *blue)
3539 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3540 saturation*=0.01*percent_saturation;
3541 lightness*=0.01*percent_lightness;
3546 const double percent_saturation,
const double percent_value,
double *red,
3547 double *green,
double *blue)
3558 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3559 saturation*=0.01*percent_saturation;
3560 value*=0.01*percent_value;
3565 const double percent_whiteness,
const double percent_blackness,
double *red,
3566 double *green,
double *blue)
3577 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3578 blackness*=0.01*percent_blackness;
3579 whiteness*=0.01*percent_whiteness;
3584 const double percent_chroma,
const double percent_hue,
double *red,
3585 double *green,
double *blue)
3596 luma*=0.01*percent_luma;
3597 chroma*=0.01*percent_chroma;
3598 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3603 const double percent_chroma,
const double percent_hue,
double *red,
3604 double *green,
double *blue)
3615 luma*=0.01*percent_luma;
3616 chroma*=0.01*percent_chroma;
3617 hue+=fmod((percent_hue-100.0),200.0)/200.0;
3624 #define ModulateImageTag "Modulate/Image" 3661 assert(image != (
Image *) NULL);
3665 if (modulate == (
char *) NULL)
3670 percent_brightness=geometry_info.
rho;
3671 percent_saturation=geometry_info.
sigma;
3673 percent_saturation=100.0;
3674 percent_hue=geometry_info.
xi;
3679 if (artifact != (
const char *) NULL)
3683 for (i=0; i < (ssize_t) image->
colors; i++)
3700 ModulateHCL(percent_hue,percent_saturation,percent_brightness,
3706 ModulateHCLp(percent_hue,percent_saturation,percent_brightness,
3712 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
3718 ModulateHSI(percent_hue,percent_saturation,percent_brightness,
3725 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
3731 ModulateHSV(percent_hue,percent_saturation,percent_brightness,
3737 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
3744 ModulateLCHab(percent_brightness,percent_saturation,percent_hue,
3750 ModulateLCHuv(percent_brightness,percent_saturation,percent_hue,
3762 #if defined(MAGICKCORE_OPENCL_SUPPORT) 3763 if (AccelerateModulateImage(image,percent_brightness,percent_hue,
3764 percent_saturation,colorspace,exception) !=
MagickFalse)
3770 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3771 #pragma omp parallel for schedule(static) shared(progress,status) \ 3772 magick_number_threads(image,image,image->rows,1) 3774 for (y=0; y < (ssize_t) image->
rows; y++)
3790 for (x=0; x < (ssize_t) image->
columns; x++)
3804 ModulateHCL(percent_hue,percent_saturation,percent_brightness,
3810 ModulateHCLp(percent_hue,percent_saturation,percent_brightness,
3816 ModulateHSB(percent_hue,percent_saturation,percent_brightness,
3823 ModulateHSL(percent_hue,percent_saturation,percent_brightness,
3829 ModulateHSV(percent_hue,percent_saturation,percent_brightness,
3835 ModulateHWB(percent_hue,percent_saturation,percent_brightness,
3841 ModulateLCHab(percent_brightness,percent_saturation,percent_hue,
3848 ModulateLCHuv(percent_brightness,percent_saturation,percent_hue,
3865 #if defined(MAGICKCORE_OPENMP_SUPPORT) 3909 #define NegateImageTag "Negate/Image" 3926 assert(image != (
Image *) NULL);
3931 for (i=0; i < (ssize_t) image->
colors; i++)
3955 for (y=0; y < (ssize_t) image->
rows; y++)
3975 for (x=0; x < (ssize_t) image->
columns; x++)
4015 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4016 #pragma omp parallel for schedule(static) shared(progress,status) \ 4017 magick_number_threads(image,image,image->rows,1) 4019 for (y=0; y < (ssize_t) image->
rows; y++)
4035 for (x=0; x < (ssize_t) image->
columns; x++)
4057 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4103 black_point=(double) image->
columns*image->
rows*0.0015;
4104 white_point=(
double) image->
columns*image->
rows*0.9995;
4172 #if defined(MAGICKCORE_HAVE_ATANH) 4173 #define Sigmoidal(a,b,x) ( tanh((0.5*(a))*((x)-(b))) ) 4175 #define Sigmoidal(a,b,x) ( 1.0/(1.0+exp((a)*((b)-(x)))) ) 4194 #define ScaledSigmoidal(a,b,x) ( \ 4195 (Sigmoidal((a),(b),(x))-Sigmoidal((a),(b),0.0)) / \ 4196 (Sigmoidal((a),(b),1.0)-Sigmoidal((a),(b),0.0)) ) 4211 const double argument=(sig1-sig0)*x+sig0;
4212 const double clamped=
4214 #if defined(MAGICKCORE_HAVE_ATANH) 4221 return(b+(2.0/a)*atanh(clamped));
4229 return(b-log(1.0/clamped-1.0)/a);
4237 #define SigmoidalContrastImageTag "SigmoidalContrast/Image" 4238 #define ScaledSig(x) ( ClampToQuantum(QuantumRange* \ 4239 ScaledSigmoidal(contrast,QuantumScale*midpoint,QuantumScale*(x))) ) 4240 #define InverseScaledSig(x) ( ClampToQuantum(QuantumRange* \ 4241 InverseScaledSigmoidal(contrast,QuantumScale*midpoint,QuantumScale*(x))) ) 4258 assert(image != (
Image *) NULL);
4277 for (i=0; i < (ssize_t) image->
colors; i++)
4293 for (i=0; i < (ssize_t) image->
colors; i++)
4315 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4316 #pragma omp parallel for schedule(static) shared(progress,status) \ 4317 magick_number_threads(image,image,image->rows,1) 4319 for (y=0; y < (ssize_t) image->
rows; y++)
4335 for (x=0; x < (ssize_t) image->
columns; x++)
4360 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4403 #define WhiteBalanceImageTag "WhiteBalance/Image" 4427 assert(image != (
Image *) NULL);
4437 for (y=0; y < (ssize_t) image->
rows; y++)
4453 for (x=0; x < (ssize_t) image->
columns; x++)
4463 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4464 #pragma omp parallel for schedule(static) shared(progress,status) \ 4465 magick_number_threads(image,image,image->rows,1) 4467 for (y=0; y < (ssize_t) image->
rows; y++)
4483 for (x=0; x < (ssize_t) image->
columns; x++)
4505 #if defined(MAGICKCORE_OPENMP_SUPPORT) 4516 if (artifact != (
const char *) NULL)
4534 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)
MagickPrivate void ConvertLCHabToRGB(const double, const double, const double, double *, double *, double *)
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)
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)
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 double StringToDouble(const char *magick_restrict string, char **magick_restrict sentinal)
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)
#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 MagickBooleanType SetImageGray(Image *image, ExceptionInfo *exception)
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
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)
static void ModulateLCHuv(const double percent_luma, const double percent_chroma, const double percent_hue, double *red, double *green, double *blue)
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)
static void ModulateLCHab(const double percent_luma, const double percent_chroma, const double percent_hue, double *red, double *green, double *blue)
MagickPrivate void ConvertLCHuvToRGB(const double, const double, const double, double *, double *, double *)
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)
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)
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)
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 *)
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
MagickPrivate void ConvertRGBToLCHab(const double, const double, const double, double *, double *, double *)
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)
MagickPrivate void ConvertRGBToLCHuv(const double, const double, const double, double *, double *, double *)
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)
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)