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

mmsfb_blit_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_ARGB_TO_ARGB3565(src, dst, alpha)    \
00041             SRC  = src;                                 \
00042             if (SRC==OLDSRC) {                          \
00043                 dst = d;                                \
00044                 alpha (SRC >> 29);                      \
00045             }                                           \
00046             else {                                      \
00047                 OLDSRC = SRC;                           \
00048                 unsigned int r = (SRC << 8) >> 27;      \
00049                 unsigned int g = (SRC << 16) >> 26;     \
00050                 unsigned int b = (SRC & 0xff) >> 3;     \
00051                 d =   (r << 11)                         \
00052                     | (g << 5)                          \
00053                     | b;                                \
00054                 dst = d;                                \
00055                 alpha (SRC >> 29);                      \
00056             }
00057 
00058 
00059 
00060 void mmsfb_blit_argb_to_argb3565(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00061                                  MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy) {
00062     // first time?
00063     static bool firsttime = true;
00064     if (firsttime) {
00065         printf("DISKO: Using accelerated conversion ARGB to ARGB3565.\n");
00066         firsttime = false;
00067     }
00068 
00069     // get the first source ptr/pitch
00070     unsigned int *src = (unsigned int *)src_planes->ptr;
00071     int src_pitch = src_planes->pitch;
00072 
00073     // DST: point to the first plane (RGB16/RGB565 format)
00074     unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00075     int dst_pitch = dst_planes->pitch;
00076 
00077     // DST: point to the second plane (3 bit alpha (2 pixels per byte, 4 bit per pixel))
00078     unsigned char *dst_a;
00079     int dst_a_pitch;
00080     if (dst_planes->ptr2) {
00081         // plane pointer given
00082         dst_a = (unsigned char *)dst_planes->ptr2;
00083         dst_a_pitch = dst_planes->pitch2;
00084     }
00085     else {
00086         // calc plane pointer (after the first plane)
00087         dst_a = ((unsigned char *)dst_planes->ptr) + dst_planes->pitch * dst_height;
00088         dst_a_pitch = dst_planes->pitch / 4;
00089     }
00090 
00091     // prepare...
00092     int src_pitch_pix = src_pitch >> 2;
00093     int dst_pitch_pix = dst_pitch >> 1;
00094     src+= sx + sy * src_pitch_pix;
00095     dst+= dx + dy * dst_pitch_pix;
00096     dst_a+= (dx >> 1) + dy * dst_a_pitch;
00097 
00098     // check the surface range
00099     if (dst_pitch_pix - dx < sw - sx)
00100         sw = dst_pitch_pix - dx - sx;
00101     if (dst_height - dy < sh - sy)
00102         sh = dst_height - dy - sy;
00103     if ((sw <= 0)||(sh <= 0))
00104         return;
00105 
00106     // check odd/even
00107     bool odd_left   = (dx & 0x01);
00108     bool odd_right  = ((dx + sw) & 0x01);
00109 
00110 
00111     //TODO: not even...
00112 
00113 
00114 
00115     // calc even positions...
00116     if (odd_left) {
00117         // odd left
00118         dx++;
00119         sw--;
00120         src++;
00121         dst++;
00122         dst_a++;
00123     }
00124 
00125     if (odd_right) {
00126         // odd right
00127         sw--;
00128     }
00129 
00130     // now we are even aligned and can go through a optimized loop
00131     ////////////////////////////////////////////////////////////////////////
00132     unsigned int OLDSRC  = (*src) + 1;
00133     unsigned int *src_end = src + src_pitch_pix * sh;
00134     int src_pitch_diff = src_pitch_pix - sw;
00135     int dst_pitch_diff = dst_pitch_pix - sw;
00136     int dst_a_pitch_diff = dst_a_pitch - (sw >> 1);
00137     register unsigned short int d;
00138 
00139 
00140     // for all lines
00141     while (src < src_end) {
00142         // for all pixels in the line
00143         unsigned int *line_end = src + sw;
00144         while (src < line_end) {
00145             register unsigned int SRC;
00146             unsigned char alpha;
00147 
00148             // process two pixels
00149             MMSFB_BLIT_ARGB_TO_ARGB3565(*src, *dst, alpha=);
00150             MMSFB_BLIT_ARGB_TO_ARGB3565(*(src+1), *(dst+1), alpha=(alpha<<4)|);
00151             dst+=2;
00152             src+=2;
00153 
00154             // set alpha value
00155             *dst_a = alpha;
00156             dst_a++;
00157         }
00158 
00159         // go to the next line
00160         src+= src_pitch_diff;
00161         dst+= dst_pitch_diff;
00162         dst_a+= dst_a_pitch_diff;
00163     }
00164 }
00165 
00166 #endif
00167 #endif

Generated by doxygen