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

mmsfb_stretchblit_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_stretchblit_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, int dw, int dh) {
00041     // first time?
00042     static bool firsttime = true;
00043     if (firsttime) {
00044         printf("DISKO: Using accelerated stretch & 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     unsigned short int *src_end = src + sx + src_pitch_pix * (sy + sh);
00060     if (src_end > src + src_pitch_pix * src_height)
00061         src_end = src + src_pitch_pix * src_height;
00062     unsigned short int *dst_end = dst + dst_pitch_pix * dst_height;
00063     src+=sx + sy * src_pitch_pix;
00064     dst+=dx + dy * dst_pitch_pix;
00065 
00066     int horifact = (dw<<16)/sw;
00067     int vertfact = (dh<<16)/sh;
00068 
00069     // for all lines
00070     int vertcnt = 0x8000;
00071     while ((src < src_end)&&(dst < dst_end)) {
00072         // for all pixels in the line
00073         vertcnt+=vertfact;
00074         if (vertcnt & 0xffff0000) {
00075             unsigned short int *line_end = src + sw;
00076             unsigned short int *old_dst = dst;
00077 
00078             do {
00079                 int horicnt = 0x8000;
00080                 while (src < line_end) {
00081                     // load pixel from memory and check if the previous pixel is the same
00082                     horicnt+=horifact;
00083 
00084                     if (horicnt & 0xffff0000) {
00085                         register unsigned short int SRC  = *src;
00086                         register unsigned int A = SRC >> 12;
00087 
00088                         if (A == 0x0f) {
00089                             // source pixel is not transparent, copy it directly to the destination
00090                             do {
00091                                 *dst = SRC;
00092                                 dst++;
00093                                 horicnt-=0x10000;
00094                             } while (horicnt & 0xffff0000);
00095                         }
00096                         else
00097                         if (!A) {
00098                             // source pixel is full transparent, do not change the destination
00099                             do {
00100                                 dst++;
00101                                 horicnt-=0x10000;
00102                             } while (horicnt & 0xffff0000);
00103                         }
00104                         else
00105                         {
00106                             // source alpha is > 0x00 and < 0x0f
00107                             register unsigned int SA= 0x10 - A;
00108                             register unsigned short int DST = *dst;
00109                             unsigned short int OLDDST = DST + 1;
00110                             register unsigned short int d;
00111 
00112                             do {
00113                                 if (DST==OLDDST) {
00114                                     // same pixel, use the previous value
00115                                     if (A) {
00116                                         // source has an alpha
00117                                         *dst = d;
00118                                     }
00119                                     dst++;
00120                                     DST = *dst;
00121                                     horicnt-=0x10000;
00122                                     continue;
00123                                 }
00124                                 OLDDST = DST;
00125 
00126                                 // extract destination
00127                                 unsigned int a = DST >> 12;
00128                                 unsigned int r = DST & 0x0f00;
00129                                 unsigned int g = DST & 0x00f0;
00130                                 unsigned int b = DST & 0x000f;
00131 
00132                                 // invert src alpha
00133                                 a = SA * a;
00134                                 r = (SA * r) >> 8;
00135                                 g = (SA * g) >> 4;
00136                                 b = SA * b;
00137 
00138                                 // add src to dst
00139                                 a += A << 4;
00140                                 r += (SRC & 0x0f00) >> 4;
00141                                 g +=  SRC & 0x00f0;
00142                                 b += (SRC & 0x000f) << 4;
00143                                 d =   ((a >> 8) ? 0xf000 : ((a >> 4) << 12))
00144                                     | ((r >> 8) ? 0x0f00 : ((r >> 4) << 8))
00145                                     | ((g >> 8) ? 0xf0   : ((g >> 4) << 4))
00146                                     | ((b >> 8) ? 0x0f   :  (b >> 4));
00147                                 *dst = d;
00148                                 dst++;
00149                                 DST = *dst;
00150                                 horicnt-=0x10000;
00151                             } while (horicnt & 0xffff0000);
00152                         }
00153                     }
00154 
00155                     src++;
00156                 }
00157                 src-=sw;
00158                 vertcnt-=0x10000;
00159                 dst = old_dst + dst_pitch_pix;
00160                 old_dst = dst;
00161             } while (vertcnt & 0xffff0000);
00162         }
00163 
00164         // next line
00165         src+=src_pitch_pix;
00166     }
00167 }
00168 
00169 #endif

Generated by doxygen