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

mmsfb_blit_blend_coloralpha_argb4444_to_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-2012 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_ARGB4444__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_blit_blend_coloralpha_argb4444_to_argb4444(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00040                                                       MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy,
00041                                                       unsigned char alpha) {
00042     // check for full alpha value
00043     if (alpha == 0xff) {
00044         // max alpha is specified, so i can ignore it and use faster routine
00045         mmsfb_blit_blend_argb4444_to_argb4444(src_planes, src_height, sx, sy, sw, sh,
00046                                               dst_planes, dst_height, dx, dy);
00047         return;
00048     }
00049 
00050     // first time?
00051     static bool firsttime = true;
00052     if (firsttime) {
00053         printf("DISKO: Using accelerated blend coloralpha ARGB4444 to ARGB4444.\n");
00054         firsttime = false;
00055     }
00056 
00057     // something to do?
00058     if (!alpha)
00059         // source should blitted full transparent, so leave destination as is
00060         return;
00061 
00062     // get the first source ptr/pitch
00063     unsigned short int *src = (unsigned short int *)src_planes->ptr;
00064     int src_pitch = src_planes->pitch;
00065 
00066     // get the first destination ptr/pitch
00067     unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00068     int dst_pitch = dst_planes->pitch;
00069 
00070     // prepare...
00071     int src_pitch_pix = src_pitch >> 1;
00072     int dst_pitch_pix = dst_pitch >> 1;
00073     src+= sx + sy * src_pitch_pix;
00074     dst+= dx + dy * dst_pitch_pix;
00075 
00076     // check the surface range
00077     if (dst_pitch_pix - dx < sw - sx)
00078         sw = dst_pitch_pix - dx - sx;
00079     if (dst_height - dy < sh - sy)
00080         sh = dst_height - dy - sy;
00081     if ((sw <= 0)||(sh <= 0))
00082         return;
00083 
00084     unsigned short int OLDDST = (*dst) + 1;
00085     unsigned short int OLDSRC  = (*src) + 1;
00086     unsigned short int *src_end = src + src_pitch_pix * sh;
00087     int src_pitch_diff = src_pitch_pix - sw;
00088     int dst_pitch_diff = dst_pitch_pix - sw;
00089     register unsigned short int d;
00090 
00091     register unsigned int ALPHA = alpha;
00092     ALPHA++;
00093 
00094     // for all lines
00095     while (src < src_end) {
00096         // for all pixels in the line
00097         unsigned short int *line_end = src + sw;
00098         while (src < line_end) {
00099             // load pixel from memory and check if the previous pixel is the same
00100             register unsigned short int SRC = *src;
00101 
00102             // is the source alpha channel 0x00 or 0x0f?
00103             register unsigned int A = SRC >> 12;
00104             if (A) {
00105                 // source alpha is > 0x00 and <= 0x0f
00106                 register unsigned short int DST = *dst;
00107 
00108                 if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00109                     // same pixel, use the previous value
00110                     *dst = d;
00111                     dst++;
00112                     src++;
00113                     continue;
00114                 }
00115                 OLDDST = DST;
00116                 OLDSRC = SRC;
00117 
00118                 // load source pixel and multiply it with given ALPHA
00119                 A = (ALPHA * A) >> 4;
00120                 unsigned int sr = (ALPHA * (SRC & 0x0f00)) >> 12;
00121                 unsigned int sg = (ALPHA * (SRC & 0x00f0)) >> 8;
00122                 unsigned int sb = (ALPHA * (SRC & 0x000f)) >> 4;
00123                 register unsigned int SA= 0x100 - A;
00124 
00125                 unsigned int a = DST >> 12;
00126                 unsigned int r = DST & 0x0f00;
00127                 unsigned int g = DST & 0x00f0;
00128                 unsigned int b = DST & 0x000f;
00129 
00130                 // invert src alpha
00131                 a = (SA * a) >> 4;
00132                 r = (SA * r) >> 12;
00133                 g = (SA * g) >> 8;
00134                 b = (SA * b) >> 4;
00135 
00136                 // add src to dst
00137                 a += A;
00138                 r += sr;
00139                 g += sg;
00140                 b += sb;
00141                 d =   ((a >> 8) ? 0xf000 : ((a >> 4) << 12))
00142                     | ((r >> 8) ? 0x0f00 : ((r >> 4) << 8))
00143                     | ((g >> 8) ? 0xf0   : ((g >> 4) << 4))
00144                     | ((b >> 8) ? 0x0f   :  (b >> 4));
00145                 *dst = d;
00146             }
00147 
00148             dst++;
00149             src++;
00150         }
00151 
00152         // go to the next line
00153         src+= src_pitch_diff;
00154         dst+= dst_pitch_diff;
00155     }
00156 }
00157 
00158 #endif

Generated by doxygen