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

mmsfb_fillrectangle_argb3565.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_ARGB3565__
00036 
00037 #include <cstring>
00038 #include "mmstools/mmstools.h"
00039 
00040 void mmsfb_fillrectangle_argb3565(MMSFBSurfacePlanes *dst_planes, int dst_height,
00041                                   int dx, int dy, int dw, int dh, MMSFBColor color) {
00042     // first time?
00043     static bool firsttime = true;
00044     if (firsttime) {
00045         printf("DISKO: Using accelerated fill rectangle to ARGB3565.\n");
00046         firsttime = false;
00047     }
00048 
00049     // fill first plane (RGB16/RGB565 format)
00050     /////////////////////////////////////////
00051     unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00052     int dst_pitch = dst_planes->pitch;
00053 
00054     // prepare...
00055     int dst_pitch_pix = dst_pitch >> 1;
00056     dst+= dx + dy * dst_pitch_pix;
00057 
00058     unsigned short int *dst_end = dst + dst_pitch_pix * dh;
00059 #ifndef __HAVE_SSE__
00060     int dst_pitch_diff = dst_pitch_pix - dw;
00061 #endif
00062 
00063     // prepare the color
00064     register unsigned short int SRC;
00065     unsigned int r = color.r >> 3;
00066     unsigned int g = color.g >> 2;
00067     unsigned int b = color.b >> 3;
00068     SRC =     (r << 11)
00069             | (g << 5)
00070             | b;
00071 
00072     // copy pixel directly to the destination
00073     // for all lines
00074     while (dst < dst_end) {
00075         // for all pixels in the line
00076 #ifdef __HAVE_SSE__
00077         // fill memory 2-byte-wise (much faster than loop see below)
00078 //      __asm__ __volatile__ ( "\trep stosw\n" : : "D" (dst), "a" (SRC), "c" (dw));
00079         short d0, d1, d2;
00080         __asm__ __volatile__ ( "\tcld\n\trep stosw" \
00081                 : "=&D" (d0), "=&a" (d1), "=&c" (d2) \
00082                 : "0" (dst), "1" (SRC), "2" (dw) \
00083                 : "memory", "cc");
00084 
00085         // go to the next line
00086         dst+= dst_pitch_pix;
00087 #else
00088         unsigned short int *line_end = dst + dw;
00089         while (dst < line_end) {
00090             *dst = SRC;
00091             dst++;
00092         }
00093 
00094         // go to the next line
00095         dst+= dst_pitch_diff;
00096 #endif
00097     }
00098 
00099 
00100     // fill second plane (3 bit alpha (2 pixels per byte, 4 bit per pixel))
00101     ///////////////////////////////////////////////////////////////////////
00102     unsigned char *dst_a;
00103     int dst_a_pitch;
00104     if (dst_planes->ptr2) {
00105         // plane pointer given
00106         dst_a = (unsigned char *)dst_planes->ptr2;
00107         dst_a_pitch = dst_planes->pitch2;
00108     }
00109     else {
00110         // calc plane pointer (after the first plane)
00111         dst_a = (unsigned char *)(((unsigned char *)dst_planes->ptr) + dst_planes->pitch * dst_height);
00112         dst_a_pitch = dst_planes->pitch / 4;
00113     }
00114     dst_a+= (dx >> 1) + dy * dst_a_pitch;
00115 
00116     // check odd/even
00117     bool odd_left   = (dx & 0x01);
00118     bool odd_right  = ((dx + dw) & 0x01);
00119 
00120     //TODO: not even...
00121 
00122 
00123 
00124     // calc even positions...
00125     if (odd_left) {
00126         // odd left
00127         dx++;
00128         dw--;
00129         dst_a++;
00130     }
00131 
00132     if (odd_right) {
00133         // odd right
00134         dw--;
00135     }
00136 
00137     // now we are even aligned and can go through a optimized loop
00138     ////////////////////////////////////////////////////////////////////////
00139     dst_end = (unsigned short int *)(dst_a + dst_a_pitch * dh);
00140 
00141     // set two alpha values into one byte
00142     SRC = color.a >> 29;
00143     SRC|= SRC << 4;
00144 
00145     // for all lines
00146     while (dst_a < (unsigned char *)dst_end) {
00147         // for all pixels in the line
00148         memset(dst_a, SRC, dw >> 1);
00149 
00150         // go to the next line
00151         dst_a+= dst_a_pitch;
00152     }
00153 }
00154 
00155 #endif

Generated by doxygen