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

mmsfb_blit_blend_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-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_ARGB4444__
00036 
00037 #include "mmstools/mmstools.h"
00038 
00039 void mmsfb_blit_blend_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     // first time?
00042     static bool firsttime = true;
00043     if (firsttime) {
00044         printf("DISKO: Using accelerated blend ARGB4444 to ARGB4444.\n");
00045         firsttime = false;
00046     }
00047 
00048     // get the first source ptr/pitch
00049     unsigned short int *src = (unsigned short int *)src_planes->ptr;
00050     int src_pitch = src_planes->pitch;
00051 
00052     // get the first destination ptr/pitch
00053     unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00054     int dst_pitch = dst_planes->pitch;
00055 
00056     // prepare...
00057     int src_pitch_pix = src_pitch >> 1;
00058     int dst_pitch_pix = dst_pitch >> 1;
00059     src+= sx + sy * src_pitch_pix;
00060     dst+= dx + dy * dst_pitch_pix;
00061 
00062     // check the surface range
00063     if (dst_pitch_pix - dx < sw - sx)
00064         sw = dst_pitch_pix - dx - sx;
00065     if (dst_height - dy < sh - sy)
00066         sh = dst_height - dy - sy;
00067     if ((sw <= 0)||(sh <= 0))
00068         return;
00069 
00070     unsigned short int OLDDST = (*dst) + 1;
00071     unsigned short int OLDSRC  = (*src) + 1;
00072     unsigned short int *src_end = src + src_pitch_pix * sh;
00073     int src_pitch_diff = src_pitch_pix - sw;
00074     int dst_pitch_diff = dst_pitch_pix - sw;
00075     register unsigned short int d;
00076 
00077     // for all lines
00078     while (src < src_end) {
00079         // for all pixels in the line
00080         unsigned short int *line_end = src + sw;
00081         while (src < line_end) {
00082             // load pixel from memory and check if the previous pixel is the same
00083             register unsigned short int SRC = *src;
00084 
00085             // is the source alpha channel 0x00 or 0x0f?
00086             register unsigned int A = SRC >> 12;
00087             if (A == 0x0f) {
00088                 // source pixel is not transparent, copy it directly to the destination
00089                 *dst = SRC;
00090             }
00091             else
00092             if (A) {
00093                 // source alpha is > 0x00 and < 0x0f
00094                 register unsigned short int DST = *dst;
00095 
00096                 if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00097                     // same pixel, use the previous value
00098                     *dst = d;
00099                     dst++;
00100                     src++;
00101                     continue;
00102                 }
00103                 OLDDST = DST;
00104                 OLDSRC = SRC;
00105 
00106                 register unsigned int SA= 0x10 - A;
00107                 unsigned int a = DST >> 12;
00108                 unsigned int r = DST & 0x0f00;
00109                 unsigned int g = DST & 0x00f0;
00110                 unsigned int b = DST & 0x000f;
00111 
00112                 // invert src alpha
00113                 a = SA * a;
00114                 r = (SA * r) >> 8;
00115                 g = (SA * g) >> 4;
00116                 b = SA * b;
00117 
00118                 // add src to dst
00119                 a += A << 4;
00120                 r += (SRC & 0x0f00) >> 4;
00121                 g +=  SRC & 0x00f0;
00122                 b += (SRC & 0x000f) << 4;
00123                 d =   ((a >> 8) ? 0xf000 : ((a >> 4) << 12))
00124                     | ((r >> 8) ? 0x0f00 : ((r >> 4) << 8))
00125                     | ((g >> 8) ? 0xf0   : ((g >> 4) << 4))
00126                     | ((b >> 8) ? 0x0f   :  (b >> 4));
00127                 *dst = d;
00128             }
00129 
00130             dst++;
00131             src++;
00132         }
00133 
00134         // go to the next line
00135         src+= src_pitch_diff;
00136         dst+= dst_pitch_diff;
00137     }
00138 }
00139 
00140 #endif

Generated by doxygen