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

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

Generated by doxygen