diff options
| author | Ray <[email protected]> | 2018-07-03 00:57:58 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2018-07-03 00:57:58 +0200 |
| commit | 74fd0e7ca4faaa428c248a9ae714e2e7371e6ed4 (patch) | |
| tree | d961bc6eeba4a7682574e71831592c8170d7d7f8 /src/textures.c | |
| parent | 7b971e06236c581087a851c8ecda11bb7be12839 (diff) | |
| download | raylib-74fd0e7ca4faaa428c248a9ae714e2e7371e6ed4.tar.gz raylib-74fd0e7ca4faaa428c248a9ae714e2e7371e6ed4.zip | |
Added function: ImageColorReplace()
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c index 81bbbf3c..f2dc7ca3 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1901,6 +1901,36 @@ void ImageColorBrightness(Image *image, int brightness) image->data = processed.data; } + +// Modify image color: replace color +void ImageColorReplace(Image *image, Color color, Color replace) +{ + Color *pixels = GetImageData(*image); + + for (int y = 0; y < image->height; y++) + { + for (int x = 0; x < image->width; x++) + { + if ((pixels[y*image->width + x].r == color.r) && + (pixels[y*image->width + x].g == color.g) && + (pixels[y*image->width + x].b == color.b) && + (pixels[y*image->width + x].a == color.a)) + { + pixels[y*image->width + x].r = replace.r; + pixels[y*image->width + x].g = replace.g; + pixels[y*image->width + x].b = replace.b; + pixels[y*image->width + x].a = replace.a; + } + } + } + + Image processed = LoadImageEx(pixels, image->width, image->height); + ImageFormat(&processed, image->format); + UnloadImage(*image); + free(pixels); + + image->data = processed.data; +} #endif // SUPPORT_IMAGE_MANIPULATION #if defined(SUPPORT_IMAGE_GENERATION) |
