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

mmsfb_fillrectangle_blend_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_fillrectangle_blend_ayuv(MMSFBSurfacePlanes *dst_planes, int dst_height,
00040                                     int dx, int dy, int dw, int dh, MMSFBColor color) {
00041     // first time?
00042     static bool firsttime = true;
00043     if (firsttime) {
00044         printf("DISKO: Using accelerated blend rectangle to AYUV.\n");
00045         firsttime = false;
00046     }
00047 
00048     // return immediately if alpha channel of the color is 0x00
00049     if (!color.a)
00050         return;
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 dst_pitch_pix = dst_pitch >> 2;
00058     dst+= dx + dy * dst_pitch_pix;
00059 
00060     unsigned int OLDDST = (*dst) + 1;
00061     unsigned int *dst_end = dst + dst_pitch_pix * dh;
00062     int dst_pitch_diff = dst_pitch_pix - dw;
00063     register unsigned int d;
00064 
00065     // prepare the color
00066     register unsigned int A = color.a;
00067     register unsigned int SRC;
00068     SRC =     (A << 24)
00069             | ((MMSFB_CONV_RGB2Y(color.r, color.g, color.b)) << 16)
00070             | ((MMSFB_CONV_RGB2U(color.r, color.g, color.b)) << 8)
00071             | MMSFB_CONV_RGB2V(color.r, color.g, color.b);
00072 
00073     if (color.a == 0xff) {
00074         // source pixel is not transparent, copy it directly to the destination
00075         // for all lines
00076         while (dst < dst_end) {
00077             // for all pixels in the line
00078 #ifdef __HAVE_SSE__
00079             // fill memory 4-byte-wise (much faster than loop see below)
00080 //          __asm__ __volatile__ ( "\trep stosl\n" : : "D" (dst), "a" (SRC), "c" (dw));
00081             short d0, d1, d2;
00082             __asm__ __volatile__ ( "\tcld\n\trep stosl" \
00083                     : "=&D" (d0), "=&a" (d1), "=&c" (d2) \
00084                     : "0" (dst), "1" (SRC), "2" (dw) \
00085                     : "memory", "cc");
00086 
00087             // go to the next line
00088             dst+= dst_pitch_pix;
00089 #else
00090             unsigned int *line_end = dst + dw;
00091             while (dst < line_end) {
00092                 *dst = SRC;
00093                 dst++;
00094             }
00095 
00096             // go to the next line
00097             dst+= dst_pitch_diff;
00098 #endif
00099         }
00100 
00101     }
00102     else {
00103         // source alpha is > 0x00 and < 0xff
00104         // for all lines
00105         while (dst < dst_end) {
00106             // for all pixels in the line
00107             unsigned int *line_end = dst + dw;
00108             while (dst < line_end) {
00109                 // read the destination
00110                 register unsigned int DST = *dst;
00111                 if (DST==OLDDST) {
00112                     // same pixel, use the previous value
00113                     *dst = d;
00114                     dst++;
00115                     continue;
00116                 }
00117                 OLDDST = DST;
00118 
00119                 register int SA= 0x100 - A;
00120                 unsigned int a = DST >> 24;
00121                 int y = (DST << 8) >> 24;
00122                 int u = (DST << 16) >> 24;
00123                 int v = DST & 0xff;
00124 
00125                 // we have to move the 0 point of the coordinate system
00126                 // this make it a little slower than ARGB to ARGB blending
00127                 MMSFB_CONV_PREPARE_YUVBLEND(y,u,v);
00128 
00129                 // invert src alpha
00130                 a = (SA * a) >> 8;
00131                 y = (SA * y) >> 8;
00132                 u = (SA * u) >> 8;
00133                 v = (SA * v) >> 8;
00134 
00135                 // add src to dst
00136                 a += A;
00137                 y += (SRC << 8) >> 24;
00138                 u += (SRC << 16) >> 24;
00139                 v += SRC & 0xff;
00140 
00141                 // build destination pixel, have to check for negative values
00142                 // this make it a little slower than ARGB to ARGB blending
00143                 d = ((a >> 8) ? 0xff000000 : (a << 24));
00144                 if (y > 0)
00145                     d |= ((y >> 8) ? 0xff0000 : (y << 16));
00146                 if (u > 0)
00147                     d |= ((u >> 8) ? 0xff00 : (u << 8));
00148                 if (v > 0)
00149                     d |= ((v >> 8) ? 0xff : v);
00150 
00151                 *dst = d;
00152 
00153                 dst++;
00154             }
00155 
00156             // go to the next line
00157             dst+= dst_pitch_diff;
00158         }
00159     }
00160 }
00161 
00162 #endif

Generated by doxygen