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

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

Generated by doxygen