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

mmsfb_fillrectangle_blend_rgb16.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_RGB16__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_fillrectangle_blend_rgb16(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 RGB16.\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 *dst_end = dst + dst_pitch_pix * dh;
00061     int dst_pitch_diff = dst_pitch_pix - dw;
00062 
00063     if (color.a == 0xff) {
00064         // source pixel is not transparent, copy it directly to the destination
00065         register unsigned short int SRC;
00066         SRC =     ((color.r >> 3) << 11)
00067                 | ((color.g >> 2) << 5)
00068                 |  (color.b >> 3);
00069 
00070         // for all lines
00071         while (dst < dst_end) {
00072             // for all pixels in the line
00073 #ifdef __HAVE_SSE__
00074             // fill memory 2-byte-wise (much faster than loop see below)
00075 //          __asm__ __volatile__ ( "\trep stosw\n" : : "D" (dst), "a" (SRC), "c" (dw));
00076             short d0, d1, d2;
00077             __asm__ __volatile__ ( "\tcld\n\trep stosw" \
00078                     : "=&D" (d0), "=&a" (d1), "=&c" (d2) \
00079                     : "0" (dst), "1" (SRC), "2" (dw) \
00080                     : "memory", "cc");
00081 
00082             // go to the next line
00083             dst+= dst_pitch_pix;
00084 #else
00085             unsigned short int *line_end = dst + dw;
00086             while (dst < line_end) {
00087                 *dst = SRC;
00088                 dst++;
00089             }
00090 
00091             // go to the next line
00092             dst+= dst_pitch_diff;
00093 #endif
00094         }
00095 
00096     }
00097     else {
00098         // source alpha is > 0x00 and < 0xff
00099         unsigned short int OLDDST = (*dst) + 1;
00100         register unsigned short int d;
00101         register unsigned short int A = color.a;
00102         register unsigned short int SRC;
00103         SRC =     (color.r << 16)
00104                 | (color.g << 8)
00105                 | color.b;
00106 
00107         // for all lines
00108         while (dst < dst_end) {
00109             // for all pixels in the line
00110             unsigned short int *line_end = dst + dw;
00111             while (dst < line_end) {
00112                 // read the destination
00113                 register unsigned short int DST = *dst;
00114                 if (DST==OLDDST) {
00115                     // same pixel, use the previous value
00116                     *dst = d;
00117                     dst++;
00118                     continue;
00119                 }
00120                 OLDDST = DST;
00121 
00122                 register int SA= 0x100 - A;
00123                 unsigned int r = DST >> 11;
00124                 unsigned int g = DST & 0x07e0;
00125                 unsigned int b = DST & 0x1f;
00126 
00127                 // invert src alpha
00128                 r = SA * r;
00129                 g = SA * g;
00130                 b = (SA * b) >> 5;
00131 
00132                 // add src to dst
00133                 r += (A*(SRC & 0xf80000)) >> 19;
00134                 g += (A*(SRC & 0xfc00)) >> 5;
00135                 b += (A*(SRC & 0xf8)) >> 8;
00136                 d =   ((r & 0xffe000)   ? 0xf800 : ((r >> 8) << 11))
00137                     | ((g & 0xfff80000) ? 0x07e0 : ((g >> 13) << 5))
00138                     | ((b & 0xff00)     ? 0x1f   : (b >> 3));
00139                 *dst = d;
00140 
00141                 dst++;
00142             }
00143 
00144             // go to the next line
00145             dst+= dst_pitch_diff;
00146         }
00147     }
00148 }
00149 
00150 #endif

Generated by doxygen