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

mmsfb_drawstring_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 #include "mmstools/mmstools.h"
00035 
00036 void mmsfb_drawstring_blend_argb4444(MMSFBSurfacePlanes *dst_planes, MMSFBFont *font,
00037                                      MMSFBRegion &clipreg, string &text, int len, int x, int y, MMSFBColor &color) {
00038     // first time?
00039     static bool firsttime = true;
00040     if (firsttime) {
00041         printf("DISKO: Using blend text ARGB4444.\n");
00042         firsttime = false;
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     // lock font and destination surface
00050     MMSFBSURFACE_BLIT_TEXT_INIT(1);
00051 
00052     // for all characters
00053     unsigned int OLDDST = 0;
00054     unsigned int OLDSRC = 0;
00055     register unsigned short int d = 0;
00056     register unsigned short int SRCPIX = 0xf000 | (((unsigned int)color.r >> 4) << 8) | (((unsigned int)color.g >> 4) << 4) | ((unsigned int)color.b >> 4);
00057     MMSFBFONT_GET_UNICODE_CHAR(text, len) {
00058         // load the glyph
00059         MMSFBSURFACE_BLIT_TEXT_LOAD_GLYPH(font, character);
00060 
00061         // start rendering of glyph to destination
00062         MMSFBSURFACE_BLIT_TEXT_START_RENDER(unsigned short int);
00063 
00064         // through the pixels
00065         while (src < src_end) {
00066             while (src < line_end) {
00067                 // load pixel from memory
00068                 register unsigned int SRC = *src;
00069 
00070                 // is the source alpha channel 0x00 or 0xff?
00071                 register unsigned int A = SRC;
00072                 if (A == 0xff) {
00073                     // source pixel is not transparent, copy it directly to the destination
00074                     *dst = SRCPIX;
00075                 }
00076                 else
00077                 if (A) {
00078                     // source alpha is > 0x00 and < 0xff
00079                     register unsigned short int DST = *dst;
00080 
00081                     if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00082                         // same pixel, use the previous value
00083                         *dst = d;
00084                         dst++;
00085                         src++;
00086                         continue;
00087                     }
00088                     OLDDST = DST;
00089                     OLDSRC = SRC;
00090 
00091                     register unsigned int SA= 0x100 - A;
00092                     unsigned int a = DST >> 12;
00093                     unsigned int r = DST & 0x0f00;
00094                     unsigned int g = DST & 0x00f0;
00095                     unsigned int b = DST & 0x000f;
00096 
00097                     // invert src alpha
00098                     a = (SA * a) >> 4;
00099                     r = (SA * r) >> 12;
00100                     g = (SA * g) >> 8;
00101                     b = (SA * b) >> 4;
00102 
00103                     // add src to dst
00104                     a += A;
00105                     A++;
00106                     r += (A * color.r) >> 8;
00107                     g += (A * color.g) >> 8;
00108                     b += (A * color.b) >> 8;
00109                     d =   ((a >> 8) ? 0xf000 : ((a >> 4) << 12))
00110                         | ((r >> 8) ? 0x0f00 : ((r >> 4) << 8))
00111                         | ((g >> 8) ? 0xf0   : ((g >> 4) << 4))
00112                         | ((b >> 8) ? 0x0f   :  (b >> 4));
00113                     *dst = d;
00114                 }
00115 
00116                 src++;
00117                 dst++;
00118             }
00119             line_end+= src_pitch_pix;
00120             src     += src_pitch_pix_diff;
00121             dst     += dst_pitch_pix_diff;
00122         }
00123 
00124         // prepare for next loop
00125         MMSFBSURFACE_BLIT_TEXT_END_RENDER;
00126     }}
00127 }
00128 

Generated by doxygen