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

mmsfb_blit_coloralpha_bgr24_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-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_BGR24__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_blit_coloralpha_bgr24_to_bgr24(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_bgr24_to_bgr24(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 blit coloralpha BGR24 to BGR24.\n");
00054         firsttime = false;
00055     }
00056 
00057     // get the first source ptr/pitch
00058     unsigned char *src = (unsigned char *)src_planes->ptr;
00059     int src_pitch = src_planes->pitch;
00060 
00061     // get the first destination ptr/pitch
00062     unsigned char *dst = (unsigned char *)dst_planes->ptr;
00063     int dst_pitch = dst_planes->pitch;
00064 
00065     // prepare...
00066 //  int src_pitch_pix = src_pitch / 3;
00067     int dst_pitch_pix = dst_pitch / 3;
00068     src+= sx*3 + sy * src_pitch;
00069     dst+= dx*3 + dy * dst_pitch;
00070 
00071     // check the surface range
00072     if (dst_pitch_pix - dx < sw - sx)
00073         sw = dst_pitch_pix - dx - sx;
00074     if (dst_height - dy < sh - sy)
00075         sh = dst_height - dy - sy;
00076     if ((sw <= 0)||(sh <= 0))
00077         return;
00078 
00079     unsigned char *src_end = src + src_pitch * sh;
00080     int src_pitch_diff = src_pitch - sw * 3;
00081     int dst_pitch_diff = dst_pitch - sw * 3;
00082 
00083     register unsigned int A = alpha;
00084     register unsigned int SA= 0x100 - A;
00085 
00086     // for all lines
00087     while (src < src_end) {
00088         // for all pixels in the line
00089         unsigned char *line_end = src + sw * 3;
00090         while (src < line_end) {
00091             // load source pixel
00092             unsigned int sr = *src;
00093             unsigned int sg = *(src+1);
00094             unsigned int sb = *(src+2);
00095 
00096             // load destination pixel
00097             unsigned int r = *dst;
00098             unsigned int g = *(dst+1);
00099             unsigned int b = *(dst+2);
00100 
00101             // invert src alpha
00102             r = (SA * r) >> 8;
00103             g = (SA * g) >> 8;
00104             b = (SA * b) >> 8;
00105 
00106             // add src to dst
00107             r += (A * sr) >> 8;
00108             g += (A * sg) >> 8;
00109             b += (A * sb) >> 8;
00110             *dst     = (r >> 8) ? 0xff : r;
00111             *(dst+1) = (g >> 8) ? 0xff : g;
00112             *(dst+2) = (b >> 8) ? 0xff : b;
00113 
00114             /*
00115             // load pixel from memory and check if the previous pixel is the same
00116             register unsigned int SRC  = *src;
00117 
00118             // is the source alpha channel 0x00 or 0xff?
00119             register unsigned int A = SRC >> 24;
00120             if (A == 0xff) {
00121                 // source pixel is not transparent, copy it directly to the destination
00122                 *dst     = (unsigned char)(SRC >> 16);
00123                 *(dst+1) = (unsigned char)(SRC >> 8);
00124                 *(dst+2) = (unsigned char)SRC;
00125             }
00126             else
00127             if (A) {
00128                 // source alpha is > 0x00 and < 0xff
00129                 register unsigned int SA= 0x100 - A;
00130                 unsigned int r = *dst;
00131                 unsigned int g = *(dst+1);
00132                 unsigned int b = *(dst+2);
00133 
00134                 // invert src alpha
00135                 r = (SA * r) >> 8;
00136                 g = (SA * g) >> 8;
00137                 b = (SA * b) >> 8;
00138 
00139                 // add src to dst
00140                 r += (A*(SRC & 0xff0000)) >> 24;
00141                 g += (A*(SRC & 0xff00)) >> 16;
00142                 b += (A*(SRC & 0xff)) >> 8;
00143                 *dst     = (r >> 8) ? 0xff : r;
00144                 *(dst+1) = (g >> 8) ? 0xff : g;
00145                 *(dst+2) = (b >> 8) ? 0xff : b;
00146             }*/
00147 
00148             dst+=3;
00149             src+=3;
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