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

mmsfb_blit_yuy2_to_yv12.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_YUY2__
00036 #ifdef __HAVE_PF_YV12__
00037 
00038 #include "mmstools/mmstools.h"
00039 
00040 void mmsfb_blit_yuy2_to_yv12(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00041                              MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy) {
00042     // first time?
00043     static bool firsttime = true;
00044     if (firsttime) {
00045         printf("DISKO: Using accelerated conversion YUY2 to YV12.\n");
00046         firsttime = false;
00047     }
00048 
00049     // get the first source ptr/pitch
00050     unsigned short int *src = (unsigned short int *)src_planes->ptr;
00051     int src_pitch = src_planes->pitch;
00052 
00053     // get the first destination ptr/pitch
00054     unsigned char *dst = (unsigned char *)dst_planes->ptr;
00055     int dst_pitch = dst_planes->pitch;
00056 
00057     // source/dest x and w must be multiple of two
00058     // reason: YUY2 codes U/V values separated in two horizontal pixels
00059     if (sx & 0x01) {
00060         sx++;
00061         sw--;
00062         dx++;
00063     }
00064     if (sw & 0x01) {
00065         sw--;
00066         if (dx & 0x01) {
00067             dx++;
00068         }
00069     }
00070     else
00071     if (dx & 0x01) {
00072         dx++;
00073         sw-=2;
00074     }
00075 
00076     // prepare...
00077     int src_pitch_pix       = src_pitch >> 1;
00078     int dst_pitch_pix       = dst_pitch;
00079     int dst_pitch_pix_half  = dst_pitch_pix >> 1;
00080 
00081     src+= sx + sy * src_pitch_pix;
00082 
00083     // check the surface range
00084     if (dst_pitch_pix - dx < sw - sx)
00085         sw = dst_pitch_pix - dx - sx;
00086     if (dst_height - dy < sh - sy)
00087         sh = dst_height - dy - sy;
00088     if ((sw <= 0)||(sh <= 0))
00089         return;
00090 
00091     int  src_pixels = src_pitch_pix * sh;
00092 
00093     // check odd/even
00094     bool odd_top    = (dy & 0x01);
00095     bool odd_bottom = ((dy + sh) & 0x01);
00096 
00097     // pointer to the pixel components of the first destination pixel
00098     unsigned char *dst_y = dst + dx + dy * dst_pitch_pix;
00099     unsigned char *dst_u;
00100     unsigned char *dst_v;
00101     if ((dst_planes->ptr2)&&(dst_planes->ptr3)) {
00102         dst_u = (unsigned char *)dst_planes->ptr2 + (dx >> 1) + (dy >> 1) * dst_pitch_pix_half;
00103         dst_v = (unsigned char *)dst_planes->ptr3 + (dx >> 1) + (dy >> 1) * dst_pitch_pix_half;
00104     }
00105     else {
00106         dst_u = dst + dst_pitch_pix * dst_height + dst_pitch_pix_half * (dst_height >> 1) + (dx >> 1) + (dy >> 1) * dst_pitch_pix_half;
00107         dst_v = dst + dst_pitch_pix * dst_height                                          + (dx >> 1) + (dy >> 1) * dst_pitch_pix_half;
00108     }
00109 
00110     // offsets to the other three pixels
00111     unsigned int dst_y2_offs = 1;
00112     unsigned int dst_y3_offs = dst_pitch;
00113     unsigned int dst_y4_offs = dst_y3_offs + 1;
00114     unsigned int src2_offs = 1;
00115     unsigned int src3_offs = src_pitch_pix;
00116     unsigned int src4_offs = src3_offs + 1;
00117 
00118     // arithmetic mean
00119     register unsigned int d_u;
00120     register unsigned int d_v;
00121 
00122     if (odd_top) {
00123         // odd top line
00124         MMSFB_CONV_YUY2_TO_YV12_PUSHPTR;
00125 
00126         // calculate start and end
00127         unsigned short int *line_end = src + sw;
00128 
00129         // through the line
00130         while (src < line_end) {
00131             register unsigned short int SRC;
00132 
00133             // for arithmetic mean we have to set U and V from pixels outside the current rectangle
00134             d_u = (*dst_u) << 1;
00135             d_v = (*dst_v) << 1;
00136 
00137             // calculate my two pixels...
00138             MMSFB_CONV_YUY2_TO_YV12_PIXEL_2(*src, *dst_y, d_u+=);
00139             MMSFB_CONV_YUY2_TO_YV12_PIXEL_2(src[src2_offs], dst_y[dst_y2_offs], d_v+=);
00140 
00141             // calulate the arithmetic mean
00142             *dst_u = d_u >> 2;
00143             *dst_v = d_v >> 2;
00144 
00145             // go to the next two pixels
00146             src+=2;
00147             dst_y+=2;
00148             dst_u++;
00149             dst_v++;
00150         }
00151 
00152         // restore the pointers
00153         MMSFB_CONV_YUY2_TO_YV12_POPPTR;
00154     }
00155 
00156     if (odd_bottom) {
00157         // odd bottom line
00158         MMSFB_CONV_YUY2_TO_YV12_PUSHPTR;
00159 
00160         // calculate start and end
00161         src   += src_pitch_pix * (sh-1);
00162         dst_y += dst_pitch_pix * (sh-1);
00163         if (odd_top) {
00164             dst_u += dst_pitch_pix_half * (sh >> 1);
00165             dst_v += dst_pitch_pix_half * (sh >> 1);
00166         }
00167         else {
00168             dst_u += dst_pitch_pix_half * ((sh-1) >> 1);
00169             dst_v += dst_pitch_pix_half * ((sh-1) >> 1);
00170         }
00171 
00172         unsigned short int *line_end = src + sw;
00173 
00174         // through the line
00175         while (src < line_end) {
00176             register unsigned short int SRC;
00177 
00178             // for arithmetic mean we have to set U and V from pixels outside the current rectangle
00179             d_u = (*dst_u) << 1;
00180             d_v = (*dst_v) << 1;
00181 
00182             // calculate my two pixels...
00183             MMSFB_CONV_YUY2_TO_YV12_PIXEL_2(*src, *dst_y, d_u+=);
00184             MMSFB_CONV_YUY2_TO_YV12_PIXEL_2(src[src2_offs], dst_y[dst_y2_offs], d_v+=);
00185 
00186             // calulate the arithmetic mean
00187             *dst_u = d_u >> 2;
00188             *dst_v = d_v >> 2;
00189 
00190             // go to the next two pixels
00191             src+=2;
00192             dst_y+=2;
00193             dst_u++;
00194             dst_v++;
00195         }
00196 
00197         // restore the pointers
00198         MMSFB_CONV_YUY2_TO_YV12_POPPTR;
00199     }
00200 
00201     // calc even positions...
00202     if (odd_top) {
00203         // odd top
00204         dy++;
00205         sh--;
00206         src+=src_pitch_pix;
00207         src_pixels-=src_pitch_pix;
00208         dst_y+=dst_pitch;
00209         dst_u+=dst_pitch >> 1;
00210         dst_v+=dst_pitch >> 1;
00211     }
00212 
00213     if (odd_bottom) {
00214         // odd bottom
00215         src_height--;
00216         src_pixels-=src_pitch_pix;
00217     }
00218 
00219     // now we are even aligned and can go through a optimized loop
00220     ////////////////////////////////////////////////////////////////////////
00221     unsigned short int *src_end = src + src_pixels;
00222     int src_pitch_diff = (src_pitch_pix << 1) - sw;
00223     int dst_pitch_diff = (dst_pitch_pix << 1) - sw;
00224     int dst_pitch_uvdiff = (dst_pitch_pix - sw) >> 1;
00225 
00226     // for all lines
00227     while (src < src_end) {
00228         // for all pixels in the line
00229         unsigned short int *line_end = src + sw;
00230 
00231         // go through two lines in parallel (square 2x2 pixel)
00232         while (src < line_end) {
00233             register unsigned short int SRC;
00234 
00235             // calculate the four pixels...
00236             MMSFB_CONV_YUY2_TO_YV12_PIXEL(*src, *dst_y, d_u=);
00237             MMSFB_CONV_YUY2_TO_YV12_PIXEL(src[src2_offs], dst_y[dst_y2_offs], d_v=);
00238             MMSFB_CONV_YUY2_TO_YV12_PIXEL(src[src3_offs], dst_y[dst_y3_offs], d_u+=);
00239             MMSFB_CONV_YUY2_TO_YV12_PIXEL(src[src4_offs], dst_y[dst_y4_offs], d_v+=);
00240 
00241             // calulate the arithmetic mean
00242             *dst_u = d_u >> 1;
00243             *dst_v = d_v >> 1;
00244 
00245             // go to the next two pixels
00246             src  +=2;
00247             dst_y+=2;
00248             dst_u++;
00249             dst_v++;
00250         }
00251 
00252         // go to the next two lines
00253         src   += src_pitch_diff;
00254         dst_y += dst_pitch_diff;
00255         dst_u += dst_pitch_uvdiff;
00256         dst_v += dst_pitch_uvdiff;
00257     }
00258 }
00259 
00260 #endif
00261 #endif

Generated by doxygen