Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsfb_blit_blend_coloralpha_airgb_to_airgb.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsgui/fb/mmsfbconv.h"
00034 
00035 #ifdef __HAVE_PF_AiRGB__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_blit_blend_coloralpha_airgb_to_airgb(MMSFBExternalSurfaceBuffer *extbuf, int src_height, int sx, int sy, int sw, int sh,
00040                                                 unsigned int *dst, int dst_pitch, int dst_height, int dx, int dy,
00041                                                 unsigned char alpha) {
00042     // check for full alpha value
00043     if (alpha == 0xff) {
00044         // max alpha is specified, so i can ignore it and use faster routine
00045         mmsfb_blit_blend_airgb_to_airgb(extbuf, src_height, sx, sy, sw, sh,
00046                                         dst, dst_pitch, dst_height, dx, dy);
00047         return;
00048     }
00049 
00050     // first time?
00051     static bool firsttime = true;
00052     if (firsttime) {
00053         printf("DISKO: Using accelerated blend coloralpha AiRGB to AiRGB.\n");
00054         firsttime = false;
00055     }
00056 
00057     // something to do?
00058     if (!alpha)
00059         // source should blitted full transparent, so leave destination as is
00060         return;
00061 
00062     // get the first source ptr/pitch
00063     unsigned int *src = (unsigned int *)extbuf->ptr;
00064     int src_pitch = extbuf->pitch;
00065 
00066     // prepare...
00067     int src_pitch_pix = src_pitch >> 2;
00068     int dst_pitch_pix = dst_pitch >> 2;
00069     src+= sx + sy * src_pitch_pix;
00070     dst+= dx + dy * dst_pitch_pix;
00071 
00072     // check the surface range
00073     if (dst_pitch_pix - dx < sw - sx)
00074         sw = dst_pitch_pix - dx - sx;
00075     if (dst_height - dy < sh - sy)
00076         sh = dst_height - dy - sy;
00077     if ((sw <= 0)||(sh <= 0))
00078         return;
00079 
00080     unsigned int OLDDST = (*dst) + 1;
00081     unsigned int OLDSRC  = (*src) + 1;
00082     unsigned int *src_end = src + src_pitch_pix * sh;
00083     int src_pitch_diff = src_pitch_pix - sw;
00084     int dst_pitch_diff = dst_pitch_pix - sw;
00085     register unsigned int d;
00086 
00087     register unsigned int ALPHA = alpha;
00088     ALPHA++;
00089 
00090     // for all lines
00091     while (src < src_end) {
00092         // for all pixels in the line
00093         unsigned int *line_end = src + sw;
00094         while (src < line_end) {
00095             // load pixel from memory and check if the previous pixel is the same
00096             register unsigned int SRC = *src;
00097 
00098             // is the source alpha channel 0x00 or 0xff?
00099             register unsigned int A = SRC >> 24;
00100             if (A < 0xff) {
00101                 // source alpha is >= 0x00 and < 0xff
00102                 register unsigned int DST = *dst;
00103 
00104                 if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00105                     // same pixel, use the previous value
00106                     *dst = d;
00107                     dst++;
00108                     src++;
00109                     continue;
00110                 }
00111                 OLDDST = DST;
00112                 OLDSRC = SRC;
00113 
00114                 // load source pixel and multiply it with given ALPHA
00115                 A = 0x100 - ((ALPHA * (0x100 - A)) >> 8);
00116                 unsigned int sr = (ALPHA * (SRC & 0xff0000)) >> 24;
00117                 unsigned int sg = (ALPHA * (SRC & 0xff00)) >> 16;
00118                 unsigned int sb = (ALPHA * (SRC & 0xff)) >> 8;
00119 
00120                 unsigned int a = DST >> 24;
00121                 unsigned int r = (DST << 8) >> 24;
00122                 unsigned int g = (DST << 16) >> 24;
00123                 unsigned int b = DST & 0xff;
00124 
00125                 // invert src alpha
00126                 a = (A * (0x100 - a)) >> 8;
00127                 r = (A * r) >> 8;
00128                 g = (A * g) >> 8;
00129                 b = (A * b) >> 8;
00130 
00131                 // add src to dst
00132                 a += 0x100 - A;
00133                 r += sr;
00134                 g += sg;
00135                 b += sb;
00136                 d =   ((r >> 8) ? 0xff0000   : (r << 16))
00137                     | ((g >> 8) ? 0xff00     : (g << 8))
00138                     | ((b >> 8) ? 0xff       :  b);
00139                 if (!(a >> 8)) d |= (0x100 - a) << 24;
00140                 *dst = d;
00141             }
00142 
00143             dst++;
00144             src++;
00145         }
00146 
00147         // go to the next line
00148         src+= src_pitch_diff;
00149         dst+= dst_pitch_diff;
00150     }
00151 }
00152 
00153 #endif

Generated by doxygen