grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / cgfx / processpixelarray_opbrightness.c
blobc6f2c7a75c03b887ace7213ee454b32fc99368fb
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;
25 LONG width, height;
26 ULONG * buffer, *ptr;
28 if (GetBitMapAttr(opRast->BitMap, BMA_DEPTH) < 15)
30 bug("[Cgfx] %s not possible for bitmap depth < 15\n", __PRETTY_FUNCTION__);
31 return;
34 width = opRect->MaxX - opRect->MinX + 1;
35 height = opRect->MaxY - opRect->MinY + 1;
37 ptr = buffer = AllocMem(width * height * 4, MEMF_ANY);
38 ReadPixelArray(buffer, 0, 0, width * 4, opRast, opRect->MinX, opRect->MinY, width, height, RECTFMT_ARGB);
40 for (y = 0; y < height; y++)
42 for(x = 0; x < width; x++)
44 color = *ptr;
46 alpha = (color & 0xff);
47 red = (color & 0xff00) >> 8;
48 green = (color & 0xff0000) >> 16;
49 blue = (color & 0xff000000) >> 24;
51 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));
53 red += value;
54 green += value;
55 blue += value;
57 if (red > 255)
58 red = 255;
59 else if (red < 0)
60 red = 0;
61 if (green > 255)
62 green = 255;
63 else if (green < 0)
64 green = 0;
65 if (blue > 255)
66 blue = 255;
67 else if (blue < 0)
68 blue = 0;
70 D(bug(" new: alpha %d red %d green %d blue %d\n", alpha, red, green, blue));
72 color = alpha | (red << 8) | (green << 16) | (blue << 24);
74 *ptr = color;
75 ptr++;
79 WritePixelArray(buffer, 0, 0, width * 4, opRast, opRect->MinX, opRect->MinY, width, height, RECTFMT_ARGB);
80 FreeMem(buffer, width * height * 4);