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

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

Generated by doxygen