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

mmsfb_blit_blend_ayuv_to_rgb16.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_AYUV__
00036 #ifdef __HAVE_PF_RGB16__
00037 
00038 #include "mmstools/mmstools.h"
00039 
00040 void mmsfb_blit_blend_ayuv_to_rgb16(MMSFBExternalSurfaceBuffer *extbuf, int src_height, int sx, int sy, int sw, int sh,
00041                                     unsigned short int *dst, int dst_pitch, int dst_height, int dx, int dy) {
00042     // first time?
00043     static bool firsttime = true;
00044     if (firsttime) {
00045         printf("DISKO: Using accelerated blend AYUV to RGB16.\n");
00046         firsttime = false;
00047     }
00048 
00049     // get the first source ptr/pitch
00050     unsigned int *src = (unsigned int *)extbuf->ptr;
00051     int src_pitch = extbuf->pitch;
00052 
00053     // prepare...
00054     int src_pitch_pix = src_pitch >> 2;
00055     int dst_pitch_pix = dst_pitch >> 1;
00056     src+= sx + sy * src_pitch_pix;
00057     dst+= dx + dy * dst_pitch_pix;
00058 
00059     // check the surface range
00060     if (dst_pitch_pix - dx < sw - sx)
00061         sw = dst_pitch_pix - dx - sx;
00062     if (dst_height - dy < sh - sy)
00063         sh = dst_height - dy - sy;
00064     if ((sw <= 0)||(sh <= 0))
00065         return;
00066 
00067     unsigned short int OLDDST = (*dst) + 1;
00068     unsigned int OLDSRC  = (*src) + 1;
00069     unsigned int *src_end = src + src_pitch_pix * sh;
00070     int src_pitch_diff = src_pitch_pix - sw;
00071     int dst_pitch_diff = dst_pitch_pix - sw;
00072     register unsigned short int d;
00073 
00074 
00075     // for all lines
00076     while (src < src_end) {
00077         // for all pixels in the line
00078         unsigned int *line_end = src + sw;
00079         while (src < line_end) {
00080             // load pixel from memory and check if the previous pixel is the same
00081             register unsigned int SRC  = *src;
00082 
00083             // is the source alpha channel 0x00 or 0xff?
00084             register unsigned int A = SRC >> 24;
00085             if (A == 0xff) {
00086                 // source pixel is not transparent, copy it directly to the destination
00087                 unsigned int y = (SRC << 8) >> 24;
00088                 unsigned int u = (SRC << 16) >> 24;
00089                 unsigned int v = SRC & 0xff;
00090                 unsigned int R;
00091                 unsigned int G;
00092                 unsigned int B;
00093 
00094                 MMSFB_CONV_PREPARE_YUV2RGB(y,u,v);
00095                 MMSFB_CONV_YUV2R(y,u,v,R);
00096                 MMSFB_CONV_YUV2G(y,u,v,G);
00097                 MMSFB_CONV_YUV2B(y,u,v,B);
00098 
00099                 *dst =    ((R >> 3) << 11)
00100                         | ((G >> 2) << 5)
00101                         | (B >> 3);
00102             }
00103             else
00104             if (A) {
00105                 // source alpha is > 0x00 and < 0xff
00106                 register unsigned short int DST = *dst;
00107 
00108                 if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00109                     // same pixel, use the previous value
00110                     *dst = d;
00111                     dst++;
00112                     src++;
00113                     continue;
00114                 }
00115                 OLDDST = DST;
00116                 OLDSRC = SRC;
00117 
00118                 register unsigned int SA= 0x100 - A;
00119                 unsigned int r = (DST >> 11) << 3;
00120                 unsigned int g = (DST & 0x07e0) >> 3;
00121                 unsigned int b = (DST & 0x1f) << 3;
00122 
00123                 // invert src alpha
00124                 r = SA * r;
00125                 g = SA * g;
00126                 b = SA * b;
00127 
00128                 // convert source YUV to RGB colorspace
00129                 unsigned int y = (SRC << 8) >> 24;
00130                 unsigned int u = (SRC << 16) >> 24;
00131                 unsigned int v = SRC & 0xff;
00132                 unsigned int R;
00133                 unsigned int G;
00134                 unsigned int B;
00135                 MMSFB_CONV_PREPARE_YUV2RGB(y,u,v);
00136                 MMSFB_CONV_YUV2RX(y,u,v,R);
00137                 MMSFB_CONV_YUV2GX(y,u,v,G);
00138                 MMSFB_CONV_YUV2BX(y,u,v,B);
00139 
00140                 // add src to dst
00141                 r += (A*R) >> 8;
00142                 g += (A*G) >> 8;
00143                 b += (A*B) >> 8;
00144                 d =   ((r >> 16) ? 0xf800 : (r & 0xf800))
00145                     | ((g >> 16) ? 0x07e0 : ((g >> 10) << 5))
00146                     | ((b >> 16) ? 0x1f   : (b >> 11));
00147                 *dst = d;
00148             }
00149 
00150             dst++;
00151             src++;
00152         }
00153 
00154         // go to the next line
00155         src+= src_pitch_diff;
00156         dst+= dst_pitch_diff;
00157     }
00158 }
00159 
00160 #endif
00161 #endif

Generated by doxygen