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

mmsfb_stretchblit_blend_coloralpha_argb4444_to_argb4444.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-2012 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_ARGB4444__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_stretchblit_blend_coloralpha_argb4444_to_argb4444(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_argb4444_to_argb4444(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 ARGB4444 to ARGB4444.\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 short int *src = (unsigned short int *)src_planes->ptr;
00064     int src_pitch = src_planes->pitch;
00065 
00066     // get the first destination ptr/pitch
00067     unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00068     int dst_pitch = dst_planes->pitch;
00069 
00070     // prepare...
00071     int  src_pitch_pix = src_pitch >> 1;
00072     int  dst_pitch_pix = dst_pitch >> 1;
00073     unsigned short 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 short 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     int horifact = (dw<<16)/sw;
00081     int vertfact = (dh<<16)/sh;
00082 
00083     register unsigned int ALPHA = alpha;
00084     ALPHA++;
00085 
00086     // for all lines
00087     int vertcnt = 0x8000;
00088     while ((src < src_end)&&(dst < dst_end)) {
00089         // for all pixels in the line
00090         vertcnt+=vertfact;
00091         if (vertcnt & 0xffff0000) {
00092             unsigned short int *line_end = src + sw;
00093             unsigned short int *old_dst = dst;
00094 
00095             do {
00096                 int horicnt = 0x8000;
00097                 while (src < line_end) {
00098                     // load pixel from memory and check if the previous pixel is the same
00099 
00100                     horicnt+=horifact;
00101 
00102                     if (horicnt & 0xffff0000) {
00103                         register unsigned short int SRC = *src;
00104                         register unsigned int A = SRC >> 12;
00105 
00106                         if (!A) {
00107                             // source pixel is full transparent, do not change the destination
00108                             do {
00109                                 dst++;
00110                                 horicnt-=0x10000;
00111                             } while (horicnt & 0xffff0000);
00112                         }
00113                         else
00114                         {
00115                             // source alpha is > 0x00 and <= 0x0f
00116                             register unsigned short int DST = *dst;
00117                             unsigned short int OLDDST = DST + 1;
00118                             register unsigned short int d;
00119 
00120                             // load source pixel and multiply it with given ALPHA
00121                             A = (ALPHA * A) >> 4;
00122                             unsigned int sr = (ALPHA * (SRC & 0x0f00)) >> 12;
00123                             unsigned int sg = (ALPHA * (SRC & 0x00f0)) >> 8;
00124                             unsigned int sb = (ALPHA * (SRC & 0x000f)) >> 4;
00125                             register unsigned int SA= 0x100 - A;
00126 
00127                             do {
00128                                 if (DST==OLDDST) {
00129                                     // same pixel, use the previous value
00130                                     if (A) {
00131                                         // source has an alpha
00132                                         *dst = d;
00133                                     }
00134                                     dst++;
00135                                     DST = *dst;
00136                                     horicnt-=0x10000;
00137                                     continue;
00138                                 }
00139                                 OLDDST = DST;
00140 
00141                                 // extract destination
00142                                 unsigned int a = DST >> 12;
00143                                 unsigned int r = DST & 0x0f00;
00144                                 unsigned int g = DST & 0x00f0;
00145                                 unsigned int b = DST & 0x000f;
00146 
00147                                 // invert src alpha
00148                                 a = (SA * a) >> 4;
00149                                 r = (SA * r) >> 12;
00150                                 g = (SA * g) >> 8;
00151                                 b = (SA * b) >> 4;
00152 
00153                                 // add src to dst
00154                                 a += A;
00155                                 r += sr;
00156                                 g += sg;
00157                                 b += sb;
00158                                 d =   ((a >> 8) ? 0xf000 : ((a >> 4) << 12))
00159                                     | ((r >> 8) ? 0x0f00 : ((r >> 4) << 8))
00160                                     | ((g >> 8) ? 0xf0   : ((g >> 4) << 4))
00161                                     | ((b >> 8) ? 0x0f   :  (b >> 4));
00162                                 *dst = d;
00163                                 dst++;
00164                                 DST = *dst;
00165                                 horicnt-=0x10000;
00166                             } while (horicnt & 0xffff0000);
00167                         }
00168                     }
00169 
00170                     src++;
00171                 }
00172                 src-=sw;
00173                 vertcnt-=0x10000;
00174                 dst = old_dst +  dst_pitch_pix;
00175                 old_dst = dst;
00176             } while (vertcnt & 0xffff0000);
00177         }
00178 
00179         // next line
00180         src+=src_pitch_pix;
00181     }
00182 }
00183 
00184 #endif

Generated by doxygen