update experimental gcc 6 patch to gcc 6.1.0 release
[AROS.git] / workbench / libs / cgfx / processpixelarray_opbrightness.c
blob7e789171a27277a5b87bbe1d8b3fddfe9c66c77a
1 /*
2 Copyright © 2013-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/cybergraphics.h>
8 #include <hidd/graphics.h>
9 #include <cybergraphx/cybergraphics.h>
10 #include <exec/types.h>
12 #include "cybergraphics_intern.h"
14 //#define DEBUG 1
15 #include <aros/debug.h>
17 // function is used for both brighen and darken
18 void ProcessPixelArrayBrightnessFunc(struct RastPort *opRast, struct Rectangle *opRect, LONG value, struct Library *CyberGfxBase)
20 D(bug("[Cgfx] %s(%d)\n", __PRETTY_FUNCTION__, value));
22 LONG x, y;
23 ULONG color;
24 LONG alpha, red, green, blue;
26 if (GetBitMapAttr(opRast->BitMap, BMA_DEPTH) < 15)
28 bug("[Cgfx] %s not possible for bitmap depth < 15\n", __PRETTY_FUNCTION__);
29 return;
32 for(x = opRect->MinX; x <= opRect->MaxX; x++)
34 for (y = opRect->MinY; y <= opRect->MaxY; y++)
36 color = ReadRGBPixel(opRast, x, y);
38 alpha = (color & 0xff);
39 red = (color & 0xff00) >> 8;
40 green = (color & 0xff0000) >> 16;
41 blue = (color & 0xff000000) >> 24;
43 D(bug("[Cgfx] %s x %d y %d old: alpha %d red %d green %d blue %d", __PRETTY_FUNCTION__, x, y, alpha, red, green, blue));
45 red += value;
46 green += value;
47 blue += value;
49 if (red > 255)
50 red = 255;
51 else if (red < 0)
52 red = 0;
53 if (green > 255)
54 green = 255;
55 else if (green < 0)
56 green = 0;
57 if (blue > 255)
58 blue = 255;
59 else if (blue < 0)
60 blue = 0;
62 D(bug(" new: alpha %d red %d green %d blue %d\n", alpha, red, green, blue));
64 color = alpha | (red << 8) | (green << 16) | (blue << 24);
66 WriteRGBPixel(opRast, x, y, color);