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

mmsfb_fillrectangle_blend_argb4444.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_ARGB4444__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_fillrectangle_blend_argb4444(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 ARGB4444.\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 short int *dst = (unsigned short int *)dst_planes->ptr;
00054     int dst_pitch = dst_planes->pitch;
00055 
00056     // prepare...
00057     int dst_pitch_pix = dst_pitch >> 1;
00058     dst+= dx + dy * dst_pitch_pix;
00059 
00060     unsigned short int OLDDST = (*dst) + 1;
00061     unsigned short int *dst_end = dst + dst_pitch_pix * dh;
00062     int dst_pitch_diff = dst_pitch_pix - dw;
00063     register unsigned short int d;
00064 
00065     // prepare the color
00066     register unsigned short int A = color.a;
00067     register unsigned short int SRC;
00068     SRC =     ((A >> 4) << 12)
00069             | ((color.r >> 4) << 8)
00070             | ((color.g >> 4) << 4)
00071             |  (color.b >> 4);
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 2-byte-wise (much faster than loop see below)
00080 //          __asm__ __volatile__ ( "\trep stosw\n" : : "D" (dst), "a" (SRC), "c" (dw));
00081             short d0, d1, d2;
00082             __asm__ __volatile__ ( "\tcld\n\trep stosw" \
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 short 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 short int *line_end = dst + dw;
00108             while (dst < line_end) {
00109                 // read the destination
00110                 register unsigned short 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 >> 12;
00121                 unsigned int r = DST & 0x0f00;
00122                 unsigned int g = DST & 0x00f0;
00123                 unsigned int b = DST & 0x000f;
00124 
00125                 // invert src alpha
00126                 a = (SA * a) >> 4;
00127                 r = (SA * r) >> 12;
00128                 g = (SA * g) >> 8;
00129                 b = (SA * b) >> 4;
00130 
00131                 // add src to dst
00132                 a += A;
00133                 r += (SRC & 0x0f00) >> 4;
00134                 g +=  SRC & 0x00f0;
00135                 b += (SRC & 0x000f) << 4;
00136                 d =   ((a >> 8) ? 0xf000 : ((a >> 4) << 12))
00137                     | ((r >> 8) ? 0x0f00 : ((r >> 4) << 8))
00138                     | ((g >> 8) ? 0xf0   : ((g >> 4) << 4))
00139                     | ((b >> 8) ? 0x0f   :  (b >> 4));
00140                 *dst = d;
00141 
00142                 dst++;
00143             }
00144 
00145             // go to the next line
00146             dst+= dst_pitch_diff;
00147         }
00148     }
00149 }
00150 
00151 #endif

Generated by doxygen