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

mmsfb_stretchblit_blend_ayuv_to_ayuv.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_AYUV__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_stretchblit_blend_ayuv_to_ayuv(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 AYUV to AYUV.\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 == 0xff) {
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) {
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 int SA= 0x100 - A;
00110                             register unsigned int DST = *dst;
00111                             unsigned int OLDDST = DST + 1;
00112                             register unsigned int d;
00113 
00114                             do {
00115                                 if (DST==OLDDST) {
00116                                     // same pixel, use the previous value
00117                                     if (A) {
00118                                         // source has an alpha
00119                                         *dst = d;
00120                                     }
00121                                     dst++;
00122                                     DST = *dst;
00123                                     horicnt-=0x10000;
00124                                     continue;
00125                                 }
00126                                 OLDDST = DST;
00127 
00128 
00129                                 // extract destination
00130                                 unsigned int a = DST >> 24;
00131                                 int y = (DST << 8) >> 24;
00132                                 int u = (DST << 16) >> 24;
00133                                 int v = DST & 0xff;
00134 
00135                                 // we have to move the 0 point of the coordinate system
00136                                 // this make it a little slower than ARGB to ARGB blending
00137                                 MMSFB_CONV_PREPARE_YUVBLEND(y,u,v);
00138 
00139                                 // invert src alpha
00140                                 a = (SA * a) >> 8;
00141                                 y = (SA * y) >> 8;
00142                                 u = (SA * u) >> 8;
00143                                 v = (SA * v) >> 8;
00144 
00145                                 // add src to dst
00146                                 a += A;
00147                                 y += (SRC << 8) >> 24;
00148                                 u += (SRC << 16) >> 24;
00149                                 v += SRC & 0xff;
00150 
00151                                 // build destination pixel, have to check for negative values
00152                                 // this make it a little slower than ARGB to ARGB blending
00153                                 d = ((a >> 8) ? 0xff000000 : (a << 24));
00154                                 if (y > 0)
00155                                     d |= ((y >> 8) ? 0xff0000 : (y << 16));
00156                                 if (u > 0)
00157                                     d |= ((u >> 8) ? 0xff00 : (u << 8));
00158                                 if (v > 0)
00159                                     d |= ((v >> 8) ? 0xff : v);
00160 
00161                                 *dst = d;
00162                                 dst++;
00163                                 DST = *dst;
00164                                 horicnt-=0x10000;
00165                             } while (horicnt & 0xffff0000);
00166                         }
00167                     }
00168 
00169                     src++;
00170                 }
00171                 src-=sw;
00172                 vertcnt-=0x10000;
00173                 dst = old_dst +  dst_pitch/4;
00174                 old_dst = dst;
00175             } while (vertcnt & 0xffff0000);
00176         }
00177 
00178         // next line
00179         src+=src_pitch/4;
00180     }
00181 
00182 }
00183 
00184 #endif

Generated by doxygen