Merging NList MCC 0.119 into the main branch.
[AROS.git] / workbench / classes / zune / nlist / nbitmap_mcc / WritePixelArrayAlpha.c
blobbf15030b7ab43cbb737fa93418792d517c6bbd2a
1 /***************************************************************************
3 NBitmap.mcc - New Bitmap MUI Custom Class
4 Copyright (C) 2006 by Daniel Allsopp
5 Copyright (C) 2007-2013 by NList Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 NList classes Support Site: http://www.sf.net/projects/nlist-classes
19 $Id$
21 ***************************************************************************/
23 #include <proto/exec.h>
24 #include <proto/cybergraphics.h>
25 #include <proto/graphics.h>
26 #include <cybergraphx/cybergraphics.h>
28 #include "private.h"
30 static LONG do_alpha(LONG a, LONG v)
32 LONG tmp = (a*v);
33 return ((tmp<<8) + tmp + 32768)>>16;
36 ULONG _WPAA(APTR src, UWORD srcx, UWORD srcy, UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty, UWORD width, UWORD height, ULONG globalalpha)
38 ULONG pixels = 0;
40 ENTER();
42 if(width > 0 && height > 0)
44 ULONG *buf;
46 if((buf = AllocVecShared(width * 4, MEMF_ANY)) != NULL)
48 ULONG x, y;
50 // Incorrect but cant bother with alpha channel math for now
51 globalalpha = 255 - (globalalpha >> 24);
53 for(y = 0; y < height; y++)
55 ULONG *spix;
56 ULONG *dpix;
58 ReadPixelArray(buf, 0, 0, width * 4, rp, destx, desty + y, width, 1, RECTFMT_ARGB);
60 spix = (ULONG *)((ULONG)src + (srcy + y) * srcmod + srcx * sizeof(ULONG));
61 dpix = buf;
63 for(x = 0; x < width; x++)
65 ULONG srcpix, dstpix, a, r, g, b;
67 srcpix = *spix++;
68 dstpix = *dpix;
70 a = (srcpix >> 24) & 0xff;
71 r = (srcpix >> 16) & 0xff;
72 g = (srcpix >> 8) & 0xff;
73 b = (srcpix >> 0) & 0xff;
75 a = a - globalalpha;
77 if(a > 0)
79 ULONG dest_r, dest_g, dest_b;
81 dest_r = (dstpix >> 16) & 0xff;
82 dest_g = (dstpix >> 8) & 0xff;
83 dest_b = (dstpix >> 0) & 0xff;
85 dest_r += do_alpha(a, r - dest_r);
86 dest_g += do_alpha(a, g - dest_g);
87 dest_b += do_alpha(a, b - dest_b);
89 dstpix = 0xff000000 | dest_r << 16 | dest_g << 8 | dest_b;
92 *dpix++ = dstpix;
93 pixels++;
96 WritePixelArray(buf, 0, 0, width * 4, rp, destx, desty + y, width, 1, RECTFMT_ARGB);
99 FreeVec(buf);
103 RETURN(pixels);
104 return pixels;