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

mmsfb_drawline_blend_argb.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 #include "mmstools/mmstools.h"
00035 
00036 #define MMSFB_DRAWLINE_BLEND_PIXEL \
00037     if ((x >= clipreg.x1)&&(x <= clipreg.x2)&&(y >= clipreg.y1)&&(y <= clipreg.y2)) { \
00038         register unsigned int DST = dst[x+y*dst_pitch_pix]; \
00039         if (DST==OLDDST) dst[x+y*dst_pitch_pix] = d;  else { \
00040         OLDDST = DST; \
00041         register int SA= 0x100 - A; \
00042         unsigned int a = DST >> 24; \
00043         unsigned int r = (DST << 8) >> 24; \
00044         unsigned int g = (DST << 16) >> 24; \
00045         unsigned int b = DST & 0xff; \
00046         a = (SA * a) >> 8; \
00047         r = (SA * r) >> 8; \
00048         g = (SA * g) >> 8; \
00049         b = (SA * b) >> 8; \
00050         a += A; \
00051         r += (SRC << 8) >> 24; \
00052         g += (SRC << 16) >> 24; \
00053         b += SRC & 0xff; \
00054         d =   ((a >> 8) ? 0xff000000 : (a << 24)) \
00055             | ((r >> 8) ? 0xff0000   : (r << 16)) \
00056             | ((g >> 8) ? 0xff00     : (g << 8)) \
00057             | ((b >> 8) ? 0xff       :  b); \
00058         dst[x+y*dst_pitch_pix] = d; } }
00059 
00060 void mmsfb_drawline_blend_argb(MMSFBSurfacePlanes *dst_planes, int dst_height,
00061                                MMSFBRegion &clipreg, int x1, int y1, int x2, int y2, MMSFBColor &color) {
00062     if (color.a == 0xff) {
00063         // source pixel is not transparent
00064         mmsfb_drawline_argb(dst_planes, dst_height, clipreg, x1, y1, x2, y2, color);
00065         return;
00066     }
00067 
00068     // first time?
00069     static bool firsttime = true;
00070     if (firsttime) {
00071         printf("DISKO: Using accelerated blend line to ARGB.\n");
00072         firsttime = false;
00073     }
00074 
00075     // return immediately if alpha channel of the color is 0x00
00076     if (!color.a)
00077         return;
00078 
00079     // get the first destination ptr/pitch
00080     unsigned int *dst = (unsigned int *)dst_planes->ptr;
00081     int dst_pitch = dst_planes->pitch;
00082 
00083     // prepare...
00084     int dst_pitch_pix = dst_pitch >> 2;
00085     unsigned int OLDDST = 0;
00086     register unsigned int d = 0;
00087 
00088     // prepare the color
00089     register unsigned int A = color.a;
00090     register unsigned int SRC;
00091     SRC =     (A << 24)
00092             | (color.r << 16)
00093             | (color.g << 8)
00094             | color.b;
00095     d = SRC;
00096 
00097     // draw a line with Bresenham-Algorithm
00098     MMSFB_DRAWLINE_BRESENHAM(MMSFB_DRAWLINE_BLEND_PIXEL);
00099 }
00100 

Generated by doxygen