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

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

Generated by doxygen