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

mmsfb_blit_blend_coloralpha_argb_to_bgr24.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_ARGB__
00036 #ifdef __HAVE_PF_BGR24__
00037 
00038 #include "mmstools/mmstools.h"
00039 
00040 void mmsfb_blit_blend_coloralpha_argb_to_bgr24(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_bgr24(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 BGR24.\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 char *dst = (unsigned char *)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 / 3;
00074     src+= sx + sy * src_pitch_pix;
00075     dst+= dx*3 + dy * dst_pitch;
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 *src_end = src + src_pitch_pix * sh;
00086     int src_pitch_diff = src_pitch_pix - sw;
00087     int dst_pitch_diff = dst_pitch - sw * 3;
00088 
00089     register unsigned int ALPHA = alpha;
00090     ALPHA++;
00091 
00092     // for all lines
00093     while (src < src_end) {
00094         // for all pixels in the line
00095         unsigned int *line_end = src + sw;
00096         while (src < line_end) {
00097             // load pixel from memory
00098             register unsigned int SRC  = *src;
00099 
00100             // is the source alpha channel != 0x00?
00101             register unsigned int A = SRC >> 24;
00102             if (A) {
00103                 // load source pixel and multiply it with given ALPHA
00104                 A = (ALPHA * A) >> 8;
00105                 register unsigned int SA= 0x100 - A;
00106 
00107                 unsigned int r = *dst;
00108                 unsigned int g = *(dst+1);
00109                 unsigned int b = *(dst+2);
00110 
00111                 // invert src alpha
00112                 r = (SA * r) >> 8;
00113                 g = (SA * g) >> 8;
00114                 b = (SA * b) >> 8;
00115 
00116                 // add src to dst
00117                 r += (A*(SRC & 0xff0000)) >> 24;
00118                 g += (A*(SRC & 0xff00)) >> 16;
00119                 b += (A*(SRC & 0xff)) >> 8;
00120                 *dst     = (r >> 8) ? 0xff : r;
00121                 *(dst+1) = (g >> 8) ? 0xff : g;
00122                 *(dst+2) = (b >> 8) ? 0xff : b;
00123             }
00124 
00125             dst+=3;
00126             src++;
00127         }
00128 
00129         // go to the next line
00130         src+= src_pitch_diff;
00131         dst+= dst_pitch_diff;
00132     }
00133 }
00134 
00135 #endif
00136 #endif

Generated by doxygen