@@ -2649,21 +2649,17 @@ void ImageColorTint(Image *image, Color color)
26492649 float cB = (float )color .b /255 ;
26502650 float cA = (float )color .a /255 ;
26512651
2652- for (int y = 0 ; y < image -> height ; y ++ )
2652+ for (int i = 0 ; i < image -> width * image -> height ; i ++ )
26532653 {
2654- for (int x = 0 ; x < image -> width ; x ++ )
2655- {
2656- int index = y * image -> width + x ;
2657- unsigned char r = (unsigned char )(((float )pixels [index ].r /255 * cR )* 255.0f );
2658- unsigned char g = (unsigned char )(((float )pixels [index ].g /255 * cG )* 255.0f );
2659- unsigned char b = (unsigned char )(((float )pixels [index ].b /255 * cB )* 255.0f );
2660- unsigned char a = (unsigned char )(((float )pixels [index ].a /255 * cA )* 255.0f );
2661-
2662- pixels [index ].r = r ;
2663- pixels [index ].g = g ;
2664- pixels [index ].b = b ;
2665- pixels [index ].a = a ;
2666- }
2654+ unsigned char r = (unsigned char )(((float )pixels [i ].r /255 * cR )* 255.0f );
2655+ unsigned char g = (unsigned char )(((float )pixels [i ].g /255 * cG )* 255.0f );
2656+ unsigned char b = (unsigned char )(((float )pixels [i ].b /255 * cB )* 255.0f );
2657+ unsigned char a = (unsigned char )(((float )pixels [i ].a /255 * cA )* 255.0f );
2658+
2659+ pixels [i ].r = r ;
2660+ pixels [i ].g = g ;
2661+ pixels [i ].b = b ;
2662+ pixels [i ].a = a ;
26672663 }
26682664
26692665 int format = image -> format ;
@@ -2683,14 +2679,11 @@ void ImageColorInvert(Image *image)
26832679
26842680 Color * pixels = LoadImageColors (* image );
26852681
2686- for (int y = 0 ; y < image -> height ; y ++ )
2682+ for (int i = 0 ; i < image -> width * image -> height ; i ++ )
26872683 {
2688- for (int x = 0 ; x < image -> width ; x ++ )
2689- {
2690- pixels [y * image -> width + x ].r = 255 - pixels [y * image -> width + x ].r ;
2691- pixels [y * image -> width + x ].g = 255 - pixels [y * image -> width + x ].g ;
2692- pixels [y * image -> width + x ].b = 255 - pixels [y * image -> width + x ].b ;
2693- }
2684+ pixels [i ].r = 255 - pixels [i ].r ;
2685+ pixels [i ].g = 255 - pixels [i ].g ;
2686+ pixels [i ].b = 255 - pixels [i ].b ;
26942687 }
26952688
26962689 int format = image -> format ;
@@ -2723,38 +2716,35 @@ void ImageColorContrast(Image *image, float contrast)
27232716
27242717 Color * pixels = LoadImageColors (* image );
27252718
2726- for (int y = 0 ; y < image -> height ; y ++ )
2719+ for (int i = 0 ; i < image -> width * image -> height ; i ++ )
27272720 {
2728- for (int x = 0 ; x < image -> width ; x ++ )
2729- {
2730- float pR = (float )pixels [y * image -> width + x ].r /255.0f ;
2731- pR -= 0.5f ;
2732- pR *= contrast ;
2733- pR += 0.5f ;
2734- pR *= 255 ;
2735- if (pR < 0 ) pR = 0 ;
2736- if (pR > 255 ) pR = 255 ;
2737-
2738- float pG = (float )pixels [y * image -> width + x ].g /255.0f ;
2739- pG -= 0.5f ;
2740- pG *= contrast ;
2741- pG += 0.5f ;
2742- pG *= 255 ;
2743- if (pG < 0 ) pG = 0 ;
2744- if (pG > 255 ) pG = 255 ;
2745-
2746- float pB = (float )pixels [y * image -> width + x ].b /255.0f ;
2747- pB -= 0.5f ;
2748- pB *= contrast ;
2749- pB += 0.5f ;
2750- pB *= 255 ;
2751- if (pB < 0 ) pB = 0 ;
2752- if (pB > 255 ) pB = 255 ;
2753-
2754- pixels [y * image -> width + x ].r = (unsigned char )pR ;
2755- pixels [y * image -> width + x ].g = (unsigned char )pG ;
2756- pixels [y * image -> width + x ].b = (unsigned char )pB ;
2757- }
2721+ float pR = (float )pixels [i ].r /255.0f ;
2722+ pR -= 0.5f ;
2723+ pR *= contrast ;
2724+ pR += 0.5f ;
2725+ pR *= 255 ;
2726+ if (pR < 0 ) pR = 0 ;
2727+ if (pR > 255 ) pR = 255 ;
2728+
2729+ float pG = (float )pixels [i ].g /255.0f ;
2730+ pG -= 0.5f ;
2731+ pG *= contrast ;
2732+ pG += 0.5f ;
2733+ pG *= 255 ;
2734+ if (pG < 0 ) pG = 0 ;
2735+ if (pG > 255 ) pG = 255 ;
2736+
2737+ float pB = (float )pixels [i ].b /255.0f ;
2738+ pB -= 0.5f ;
2739+ pB *= contrast ;
2740+ pB += 0.5f ;
2741+ pB *= 255 ;
2742+ if (pB < 0 ) pB = 0 ;
2743+ if (pB > 255 ) pB = 255 ;
2744+
2745+ pixels [i ].r = (unsigned char )pR ;
2746+ pixels [i ].g = (unsigned char )pG ;
2747+ pixels [i ].b = (unsigned char )pB ;
27582748 }
27592749
27602750 int format = image -> format ;
@@ -2778,27 +2768,24 @@ void ImageColorBrightness(Image *image, int brightness)
27782768
27792769 Color * pixels = LoadImageColors (* image );
27802770
2781- for (int y = 0 ; y < image -> height ; y ++ )
2771+ for (int i = 0 ; i < image -> width * image -> height ; i ++ )
27822772 {
2783- for (int x = 0 ; x < image -> width ; x ++ )
2784- {
2785- int cR = pixels [y * image -> width + x ].r + brightness ;
2786- int cG = pixels [y * image -> width + x ].g + brightness ;
2787- int cB = pixels [y * image -> width + x ].b + brightness ;
2773+ int cR = pixels [i ].r + brightness ;
2774+ int cG = pixels [i ].g + brightness ;
2775+ int cB = pixels [i ].b + brightness ;
27882776
2789- if (cR < 0 ) cR = 1 ;
2790- if (cR > 255 ) cR = 255 ;
2777+ if (cR < 0 ) cR = 1 ;
2778+ if (cR > 255 ) cR = 255 ;
27912779
2792- if (cG < 0 ) cG = 1 ;
2793- if (cG > 255 ) cG = 255 ;
2780+ if (cG < 0 ) cG = 1 ;
2781+ if (cG > 255 ) cG = 255 ;
27942782
2795- if (cB < 0 ) cB = 1 ;
2796- if (cB > 255 ) cB = 255 ;
2783+ if (cB < 0 ) cB = 1 ;
2784+ if (cB > 255 ) cB = 255 ;
27972785
2798- pixels [y * image -> width + x ].r = (unsigned char )cR ;
2799- pixels [y * image -> width + x ].g = (unsigned char )cG ;
2800- pixels [y * image -> width + x ].b = (unsigned char )cB ;
2801- }
2786+ pixels [i ].r = (unsigned char )cR ;
2787+ pixels [i ].g = (unsigned char )cG ;
2788+ pixels [i ].b = (unsigned char )cB ;
28022789 }
28032790
28042791 int format = image -> format ;
@@ -2818,20 +2805,17 @@ void ImageColorReplace(Image *image, Color color, Color replace)
28182805
28192806 Color * pixels = LoadImageColors (* image );
28202807
2821- for (int y = 0 ; y < image -> height ; y ++ )
2808+ for (int i = 0 ; i < image -> width * image -> height ; i ++ )
28222809 {
2823- for (int x = 0 ; x < image -> width ; x ++ )
2810+ if ((pixels [i ].r == color .r ) &&
2811+ (pixels [i ].g == color .g ) &&
2812+ (pixels [i ].b == color .b ) &&
2813+ (pixels [i ].a == color .a ))
28242814 {
2825- if ((pixels [y * image -> width + x ].r == color .r ) &&
2826- (pixels [y * image -> width + x ].g == color .g ) &&
2827- (pixels [y * image -> width + x ].b == color .b ) &&
2828- (pixels [y * image -> width + x ].a == color .a ))
2829- {
2830- pixels [y * image -> width + x ].r = replace .r ;
2831- pixels [y * image -> width + x ].g = replace .g ;
2832- pixels [y * image -> width + x ].b = replace .b ;
2833- pixels [y * image -> width + x ].a = replace .a ;
2834- }
2815+ pixels [i ].r = replace .r ;
2816+ pixels [i ].g = replace .g ;
2817+ pixels [i ].b = replace .b ;
2818+ pixels [i ].a = replace .a ;
28352819 }
28362820 }
28372821
0 commit comments