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

mmsfb_blit_blend_argb_to_argb3565.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_ARGB3565__
00037 
00038 #include "mmstools/mmstools.h"
00039 
00040 #define MMSFB_BLIT_BLEND_ARGB_TO_ARGB3565(src, dst, dst_a, alpha)       \
00041             SRC  = src;                                                 \
00042             A    = SRC >> 24;                                           \
00043             if (A == 0xff) {                                            \
00044                 if (SRC==OLDSRC) {                                      \
00045                     dst = d;                                            \
00046                     alpha da;                                           \
00047                 }                                                       \
00048                 else {                                                  \
00049                     OLDSRC = SRC;                                       \
00050                     unsigned int r = (SRC << 8) >> 27;                  \
00051                     unsigned int g = (SRC << 16) >> 26;                 \
00052                     unsigned int b = (SRC & 0xff) >> 3;                 \
00053                     d =   (r << 11)                                     \
00054                         | (g << 5)                                      \
00055                         | b;                                            \
00056                     da = A >> 5;                                        \
00057                     dst = d;                                            \
00058                     alpha da;                                           \
00059                 }                                                       \
00060             }                                                           \
00061             else                                                        \
00062             if (!A) {                                                   \
00063                 alpha dst_a;                                            \
00064             }                                                           \
00065             else {                                                      \
00066                 register unsigned short int DST = dst;                  \
00067                 if ((DST==OLDDST)&&(dst_a==OLDDSTA)&&(SRC==OLDSRC)) {   \
00068                     dst = d;                                            \
00069                     alpha da;                                           \
00070                 }                                                       \
00071                 else  {                                                 \
00072                     OLDDST  = DST;                                      \
00073                     OLDDSTA = dst_a;                                    \
00074                     OLDSRC = SRC;                                       \
00075                     register unsigned int SA= 0x100 - A;                \
00076                     unsigned int a = dst_a;                             \
00077                     unsigned int r = DST >> 11;                         \
00078                     unsigned int g = (DST << 5) >> 10;                  \
00079                     unsigned int b = DST & 0x1f;                        \
00080                     a = (SA * a) >> 3;                                  \
00081                     r = (SA * r) >> 5;                                  \
00082                     g = (SA * g) >> 6;                                  \
00083                     b = (SA * b) >> 5;                                  \
00084                     a += A >> 5;                                        \
00085                     r += (SRC << 8) >> 27;                              \
00086                     g += (SRC << 16) >> 26;                             \
00087                     b += (SRC << 24) >> 27;                             \
00088                     d =   ((r >> 5) ? 0xf800    : (r << 11))            \
00089                         | ((g >> 6) ? 0x07e0    : (g << 5))             \
00090                         | ((b >> 5) ? 0x1f      : b);                   \
00091                     da = (a >> 8) ? 0x07 : a;                           \
00092                     dst = d;                                            \
00093                     alpha da;                                           \
00094                 }                                                       \
00095             }
00096 
00097 
00098 void mmsfb_blit_blend_argb_to_argb3565(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00099                                        MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy) {
00100     // first time?
00101     static bool firsttime = true;
00102     if (firsttime) {
00103         printf("DISKO: Using accelerated blend ARGB to ARGB3565.\n");
00104         firsttime = false;
00105     }
00106 
00107     // get the first source ptr/pitch
00108     unsigned int *src = (unsigned int *)src_planes->ptr;
00109     int src_pitch = src_planes->pitch;
00110 
00111     // DST: point to the first plane (RGB16/RGB565 format)
00112     unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00113     int dst_pitch = dst_planes->pitch;
00114 
00115     // DST: point to the second plane (3 bit alpha (2 pixels per byte, 4 bit per pixel))
00116     unsigned char *dst_a;
00117     int dst_a_pitch;
00118     if (dst_planes->ptr2) {
00119         // plane pointer given
00120         dst_a = (unsigned char *)dst_planes->ptr2;
00121         dst_a_pitch = dst_planes->pitch2;
00122     }
00123     else {
00124         // calc plane pointer (after the first plane)
00125         dst_a = ((unsigned char *)dst_planes->ptr) + dst_planes->pitch * dst_height;
00126         dst_a_pitch = dst_planes->pitch / 4;
00127     }
00128 
00129     // prepare...
00130     int src_pitch_pix = src_pitch >> 2;
00131     int dst_pitch_pix = dst_pitch >> 1;
00132     src+= sx + sy * src_pitch_pix;
00133     dst+= dx + dy * dst_pitch_pix;
00134     dst_a+= (dx >> 1) + dy * dst_a_pitch;
00135 
00136     // check the surface range
00137     if (dst_pitch_pix - dx < sw - sx)
00138         sw = dst_pitch_pix - dx - sx;
00139     if (dst_height - dy < sh - sy)
00140         sh = dst_height - dy - sy;
00141     if ((sw <= 0)||(sh <= 0))
00142         return;
00143 
00144     // check odd/even
00145     bool odd_left   = (dx & 0x01);
00146     bool odd_right  = ((dx + sw) & 0x01);
00147 
00148 
00149     //TODO: not even...
00150 
00151 
00152 
00153     // calc even positions...
00154     if (odd_left) {
00155         // odd left
00156         dx++;
00157         sw--;
00158         src++;
00159         dst++;
00160         dst_a++;
00161     }
00162 
00163     if (odd_right) {
00164         // odd right
00165         sw--;
00166     }
00167 
00168     // now we are even aligned and can go through a optimized loop
00169     ////////////////////////////////////////////////////////////////////////
00170     unsigned short int OLDDST  = (*dst) + 1;
00171     unsigned char      OLDDSTA = (*dst_a) + 1;
00172     unsigned int OLDSRC = (*src) + 1;
00173     unsigned int *src_end = src + src_pitch_pix * sh;
00174     int src_pitch_diff = src_pitch_pix - sw;
00175     int dst_pitch_diff = dst_pitch_pix - sw;
00176     int dst_a_pitch_diff = dst_a_pitch - (sw >> 1);
00177     register unsigned short int d;
00178     register unsigned char da;
00179 
00180 
00181     // for all lines
00182     while (src < src_end) {
00183         // for all pixels in the line
00184         unsigned int *line_end = src + sw;
00185         while (src < line_end) {
00186             register unsigned int SRC;
00187             register unsigned int A;
00188             unsigned char alpha;
00189 
00190             // process two pixels
00191             MMSFB_BLIT_BLEND_ARGB_TO_ARGB3565(*src, *dst, ((*dst_a) >> 4), alpha=);
00192             MMSFB_BLIT_BLEND_ARGB_TO_ARGB3565(*(src+1), *(dst+1), ((*dst_a)&0x0f), alpha=(alpha<<4)|);
00193             dst+=2;
00194             src+=2;
00195 
00196             // set alpha value
00197             *dst_a = alpha;
00198             dst_a++;
00199         }
00200 
00201         // go to the next line
00202         src+= src_pitch_diff;
00203         dst+= dst_pitch_diff;
00204         dst_a+= dst_a_pitch_diff;
00205     }
00206 }
00207 
00208 #endif
00209 #endif

Generated by doxygen