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

mmsfb_drawstring_blend_coloralpha_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 #include "mmstools/mmstools.h"
00035 
00036 void mmsfb_drawstring_blend_coloralpha_rgb16(MMSFBSurfacePlanes *dst_planes, MMSFBFont *font,
00037                                              MMSFBRegion &clipreg, string &text, int len, int x, int y, MMSFBColor &color) {
00038     // check for full alpha value
00039     if (color.a == 0xff) {
00040         // max alpha is specified, so i can ignore it and use faster routine
00041         mmsfb_drawstring_blend_rgb16(dst_planes, font, clipreg, text, len, x, y, color);
00042         return;
00043     }
00044 
00045     // get the first destination ptr/pitch
00046     void *dst_ptr = dst_planes->ptr;
00047     int dst_pitch = dst_planes->pitch;
00048 
00049     // first time?
00050     static bool firsttime = true;
00051     if (firsttime) {
00052         printf("DISKO: Using blend text coloralpha RGB16.\n");
00053         firsttime = false;
00054     }
00055 
00056     // something to do?
00057     if (!color.a)
00058         // source should blitted full transparent, so leave destination as is
00059         return;
00060 
00061     // lock font and destination surface
00062     MMSFBSURFACE_BLIT_TEXT_INIT(1);
00063 
00064     // for all characters
00065     unsigned int OLDDST = 0;
00066     unsigned int OLDSRC = 0;
00067     register unsigned short int d = 0;
00068     register unsigned int ALPHA = color.a;
00069     ALPHA++;
00070     MMSFBFONT_GET_UNICODE_CHAR(text, len) {
00071         // load the glyph
00072         MMSFBSURFACE_BLIT_TEXT_LOAD_GLYPH(font, character);
00073 
00074         // start rendering of glyph to destination
00075         MMSFBSURFACE_BLIT_TEXT_START_RENDER(unsigned short int);
00076 
00077         // through the pixels
00078         while (src < src_end) {
00079             while (src < line_end) {
00080                 // load pixel from memory
00081                 register unsigned int SRC = *src;
00082 
00083                 // is the source alpha channel 0x00 or 0xff?
00084                 register unsigned int A = SRC;
00085                 if (A) {
00086                     // source alpha is > 0x00 and < 0xff
00087                     register unsigned short int DST = *dst;
00088 
00089                     if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00090                         // same pixel, use the previous value
00091                         *dst = d;
00092                         dst++;
00093                         src++;
00094                         continue;
00095                     }
00096                     OLDDST = DST;
00097                     OLDSRC = SRC;
00098 
00099                     A = (ALPHA * A) >> 8;
00100                     register unsigned int SA= 0x100 - A;
00101                     unsigned int r = DST >> 11;
00102                     unsigned int g = DST & 0x07e0;
00103                     unsigned int b = DST & 0x1f;
00104 
00105                     // invert src alpha
00106                     r = SA * r;
00107                     g = SA * g;
00108                     b = (SA * b) >> 5;
00109 
00110                     // add src to dst
00111                     A++;
00112                     r += (A * color.r) >> 3;
00113                     g += (A * color.g) << 3;
00114                     b += (A * color.b) >> 8;
00115                     d =   ((r & 0xffe000)   ? 0xf800 : ((r >> 8) << 11))
00116                         | ((g & 0xfff80000) ? 0x07e0 : ((g >> 13) << 5))
00117                         | ((b & 0xff00)     ? 0x1f   : (b >> 3));
00118                     *dst = d;
00119 
00120                 }
00121 
00122                 src++;
00123                 dst++;
00124             }
00125             line_end+= src_pitch_pix;
00126             src     += src_pitch_pix_diff;
00127             dst     += dst_pitch_pix_diff;
00128         }
00129 
00130         // prepare for next loop
00131         MMSFBSURFACE_BLIT_TEXT_END_RENDER;
00132     }}
00133 }
00134 

Generated by doxygen