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

mmsfb_stretchblit_blend_coloralpha_argb_to_argb.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_ARGB__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_stretchblit_blend_coloralpha_argb_to_argb(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00040                                                      MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy, int dw, int dh,
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_stretchblit_blend_argb_to_argb(src_planes, src_height, sx, sy, sw, sh,
00046                                              dst_planes, dst_height, dx, dy, dw, dh);
00047         return;
00048     }
00049 
00050     // first time?
00051     static bool firsttime = true;
00052     if (firsttime) {
00053         printf("DISKO: Using accelerated stretch & blend coloralpha ARGB to ARGB.\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 *)src_planes->ptr;
00064     int src_pitch = src_planes->pitch;
00065 
00066     // get the first destination ptr/pitch
00067     unsigned int *dst = (unsigned int *)dst_planes->ptr;
00068     int dst_pitch = dst_planes->pitch;
00069 
00070     // prepare...
00071     int  src_pitch_pix = src_pitch >> 2;
00072     int  dst_pitch_pix = dst_pitch >> 2;
00073     unsigned int *src_end = src + sx + src_pitch_pix * (sy + sh);
00074     if (src_end > src + src_pitch_pix * src_height)
00075         src_end = src + src_pitch_pix * src_height;
00076     unsigned int *dst_end = dst + dst_pitch_pix * dst_height;
00077     src+=sx + sy * src_pitch_pix;
00078     dst+=dx + dy * dst_pitch_pix;
00079 
00080 
00081 //  printf("sw=%d,sh=%d\n", sw,sh);
00082 
00083     int horifact = (dw<<16)/sw;
00084     int vertfact = (dh<<16)/sh;
00085 
00086 
00087     register unsigned int ALPHA = alpha;
00088     ALPHA++;
00089 
00090 
00091     // for all lines
00092     int vertcnt = 0x8000;
00093     while ((src < src_end)&&(dst < dst_end)) {
00094         // for all pixels in the line
00095         vertcnt+=vertfact;
00096         if (vertcnt & 0xffff0000) {
00097             unsigned int *line_end = src + sw;
00098             unsigned int *old_dst = dst;
00099 
00100             do {
00101                 int horicnt = 0x8000;
00102                 while (src < line_end) {
00103                     // load pixel from memory and check if the previous pixel is the same
00104 
00105                     horicnt+=horifact;
00106 
00107                     if (horicnt & 0xffff0000) {
00108                         register unsigned int SRC = *src;
00109                         register unsigned int A = SRC >> 24;
00110 
00111                         if (!A) {
00112                             // source pixel is full transparent, do not change the destination
00113                             do {
00114                                 dst++;
00115                                 horicnt-=0x10000;
00116                             } while (horicnt & 0xffff0000);
00117                         }
00118                         else
00119                         {
00120                             // source alpha is > 0x00 and <= 0xff
00121                             register unsigned int DST = *dst;
00122                             unsigned int OLDDST = DST + 1;
00123                             register unsigned int d;
00124 
00125                             // load source pixel and multiply it with given ALPHA
00126                             A = (ALPHA * A) >> 8;
00127                             unsigned int sr = (ALPHA * (SRC & 0xff0000)) >> 24;
00128                             unsigned int sg = (ALPHA * (SRC & 0xff00)) >> 16;
00129                             unsigned int sb = (ALPHA * (SRC & 0xff)) >> 8;
00130                             register unsigned int SA= 0x100 - A;
00131 
00132                             do {
00133                                 if (DST==OLDDST) {
00134                                     // same pixel, use the previous value
00135                                     if (A) {
00136                                         // source has an alpha
00137                                         *dst = d;
00138                                     }
00139                                     dst++;
00140                                     DST = *dst;
00141                                     horicnt-=0x10000;
00142                                     continue;
00143                                 }
00144                                 OLDDST = DST;
00145 
00146                                 // extract destination
00147                                 unsigned int a = DST >> 24;
00148                                 unsigned int r = (DST << 8) >> 24;
00149                                 unsigned int g = (DST << 16) >> 24;
00150                                 unsigned int b = DST & 0xff;
00151 
00152                                 // invert src alpha
00153                                 a = (SA * a) >> 8;
00154                                 r = (SA * r) >> 8;
00155                                 g = (SA * g) >> 8;
00156                                 b = (SA * b) >> 8;
00157 
00158                                 // add src to dst
00159                                 a += A;
00160                                 r += sr;
00161                                 g += sg;
00162                                 b += sb;
00163                                 d =   ((a >> 8) ? 0xff000000 : (a << 24))
00164                                     | ((r >> 8) ? 0xff0000   : (r << 16))
00165                                     | ((g >> 8) ? 0xff00     : (g << 8))
00166                                     | ((b >> 8) ? 0xff       :  b);
00167                                 *dst = d;
00168                                 dst++;
00169                                 DST = *dst;
00170                                 horicnt-=0x10000;
00171                             } while (horicnt & 0xffff0000);
00172                         }
00173                     }
00174 
00175                     src++;
00176                 }
00177                 src-=sw;
00178                 vertcnt-=0x10000;
00179                 dst = old_dst +  dst_pitch/4;
00180                 old_dst = dst;
00181             } while (vertcnt & 0xffff0000);
00182         }
00183 
00184         // next line
00185         src+=src_pitch/4;
00186     }
00187 }
00188 
00189 #endif

Generated by doxygen