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

mmsfbbase.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/mmsfbbase.h"
00034 #include "mmstools/tools.h"
00035 #include <string.h>
00036 
00037 // stores the last error text
00038 string MMSFB_LastErrorString;
00039 
00040 // screen should be rotated by 180°?
00041 bool MMSFBBase_rotate180 = false;
00042 
00043 
00044 string MMSFB_ErrorString(const int rc, const string msg) {
00045     if (rc)
00046     {
00047 #ifdef  __HAVE_DIRECTFB__
00048         string s1 = msg;
00049         string s2 = DirectFBErrorString((DFBResult)rc);
00050         return s1 + " [" + s2 + "]";
00051 #else
00052         return msg;
00053 #endif
00054     }
00055     else
00056         return msg;
00057 }
00058 
00059 void MMSFB_SetError(const int rc, const string msg) {
00060     MMSFB_LastErrorString = MMSFB_ErrorString(rc, msg);
00061     DEBUGMSG("MMSGUI", MMSFB_LastErrorString);
00062 }
00063 
00064 bool isAlphaPixelFormat(MMSFBSurfacePixelFormat pf) {
00065     if   ((pf == MMSFB_PF_RGB16)
00066         ||(pf == MMSFB_PF_RGB24)
00067         ||(pf == MMSFB_PF_RGB32)
00068         ||(pf == MMSFB_PF_YV12)
00069         ||(pf == MMSFB_PF_YUY2)
00070         ||(pf == MMSFB_PF_UYVY)
00071         ||(pf == MMSFB_PF_LUT8)
00072         ||(pf == MMSFB_PF_NV12)
00073         ||(pf == MMSFB_PF_NV16)
00074         ||(pf == MMSFB_PF_NV21)
00075         ||(pf == MMSFB_PF_I420)
00076         ||(pf == MMSFB_PF_RGB18)
00077         ||(pf == MMSFB_PF_LUT2)
00078         ||(pf == MMSFB_PF_RGB444)
00079         ||(pf == MMSFB_PF_RGB555)
00080         ||(pf == MMSFB_PF_BGR24)
00081         ||(pf == MMSFB_PF_BGR555))
00082         return false;
00083     return true;
00084 }
00085 
00086 bool isIndexedPixelFormat(MMSFBSurfacePixelFormat pf) {
00087     if   ((pf == MMSFB_PF_ALUT44)
00088         ||(pf == MMSFB_PF_LUT8))
00089         return true;
00090     return false;
00091 }
00092 
00093 bool isRGBPixelFormat(MMSFBSurfacePixelFormat pf) {
00094     if   ((pf == MMSFB_PF_YV12)
00095         ||(pf == MMSFB_PF_AYUV)
00096         ||(pf == MMSFB_PF_YUY2)
00097         ||(pf == MMSFB_PF_UYVY)
00098         ||(pf == MMSFB_PF_I420)
00099         ||(pf == MMSFB_PF_NV12)
00100         ||(pf == MMSFB_PF_NV16)
00101         ||(pf == MMSFB_PF_NV21)
00102         ||(pf == MMSFB_PF_LUT2))
00103         return false;
00104     return true;
00105 }
00106 
00107 void getBitsPerPixel(MMSFBSurfacePixelFormat pf, MMSFBPixelDef *pixeldef) {
00108 
00109     if (!pixeldef)
00110         return;
00111 
00112     pixeldef->bits = 0;
00113     pixeldef->red_length = 0;
00114     pixeldef->red_offset = 0;
00115     pixeldef->green_length = 0;
00116     pixeldef->green_offset = 0;
00117     pixeldef->blue_length = 0;
00118     pixeldef->blue_offset = 0;
00119     pixeldef->transp_length = 0;
00120     pixeldef->transp_offset = 0;
00121 
00122     if(pf == MMSFB_PF_RGB16) {
00123         pixeldef->bits          = 2*8;
00124         pixeldef->red_length    = 5;
00125         pixeldef->green_length  = 6;
00126         pixeldef->blue_length   = 5;
00127         pixeldef->red_offset    = 11;
00128         pixeldef->green_offset  = 5;
00129         pixeldef->blue_offset   = 0;
00130         return;
00131     }
00132     else
00133     if(pf == MMSFB_PF_RGB24) {
00134         pixeldef->bits          = 3*8;
00135         pixeldef->red_length    = 8;
00136         pixeldef->green_length  = 8;
00137         pixeldef->blue_length   = 8;
00138         pixeldef->red_offset    = 16;
00139         pixeldef->green_offset  = 8;
00140         pixeldef->blue_offset   = 0;
00141         return;
00142     }
00143     else
00144     if(pf == MMSFB_PF_RGB32) {
00145         pixeldef->bits          = 4*8;
00146         pixeldef->red_length    = 8;
00147         pixeldef->green_length  = 8;
00148         pixeldef->blue_length   = 8;
00149         pixeldef->red_offset    = 16;
00150         pixeldef->green_offset  = 8;
00151         pixeldef->blue_offset   = 0;
00152         return;
00153     }
00154     else
00155     if(pf == MMSFB_PF_ARGB) {
00156         pixeldef->bits          = 4*8;
00157         pixeldef->transp_length = 8;
00158         pixeldef->red_length    = 8;
00159         pixeldef->green_length  = 8;
00160         pixeldef->blue_length   = 8;
00161         pixeldef->transp_offset = 24;
00162         pixeldef->red_offset    = 16;
00163         pixeldef->green_offset  = 8;
00164         pixeldef->blue_offset   = 0;
00165         return;
00166     }
00167     else
00168     if(pf == MMSFB_PF_A8) {
00169         pixeldef->bits = 1*8;
00170         return;
00171     }
00172     else
00173     if(pf == MMSFB_PF_YUY2) {
00174         pixeldef->bits = 2*8;
00175         return;
00176     }
00177     else
00178     if(pf == MMSFB_PF_UYVY) {
00179         pixeldef->bits = 2*8;
00180         return;
00181     }
00182     else
00183     if(pf == MMSFB_PF_I420) {
00184         pixeldef->bits = 12;
00185         return;
00186     }
00187     else
00188     if(pf == MMSFB_PF_YV12) {
00189         pixeldef->bits = 12;
00190         return;
00191     }
00192     else
00193     if(pf == MMSFB_PF_AiRGB) {
00194         pixeldef->bits          = 4*8;
00195         pixeldef->transp_length = 8;
00196         pixeldef->red_length    = 8;
00197         pixeldef->green_length  = 8;
00198         pixeldef->blue_length   = 8;
00199         pixeldef->transp_offset = 24;
00200         pixeldef->red_offset    = 16;
00201         pixeldef->green_offset  = 8;
00202         pixeldef->blue_offset   = 0;
00203         return;
00204     }
00205     else
00206     if(pf == MMSFB_PF_A1) {
00207         pixeldef->bits = 1;
00208         return;
00209     }
00210     else
00211     if(pf == MMSFB_PF_NV12) {
00212         pixeldef->bits = 1*8;
00213         return;
00214     }
00215     else
00216     if(pf == MMSFB_PF_NV16) {
00217         pixeldef->bits = 1*8;
00218         return;
00219     }
00220     else
00221     if (pf == MMSFB_PF_NV21) {
00222         pixeldef->bits = 1*8;
00223         return;
00224     }
00225     else
00226     if (pf == MMSFB_PF_AYUV) {
00227         pixeldef->bits = 4*8;
00228         return;
00229     }
00230     else
00231     if (pf == MMSFB_PF_A4) {
00232         pixeldef->bits = 4;
00233         return;
00234     }
00235     else
00236     if (pf == MMSFB_PF_ARGB1666) {
00237         pixeldef->bits = 3*8;
00238         return;
00239     }
00240     else
00241     if (pf == MMSFB_PF_ARGB6666) {
00242         pixeldef->bits = 3*8;
00243         return;
00244     }
00245     else
00246     if (pf == MMSFB_PF_RGB18) {
00247         pixeldef->bits = 3*8;
00248         return;
00249     }
00250     else
00251     if (pf == MMSFB_PF_LUT2) {
00252         pixeldef->bits = 2;
00253         return;
00254     }
00255     else
00256     if (pf == MMSFB_PF_RGB444) {
00257         pixeldef->bits = 2*8;
00258         return;
00259     }
00260     else
00261     if (pf == MMSFB_PF_RGB555) {
00262         pixeldef->bits = 2*8;
00263         return;
00264     }
00265     else
00266     if(pf == MMSFB_PF_ARGB1555) {
00267         pixeldef->bits = 2*8;
00268         return;
00269     }
00270     else
00271     if(pf == MMSFB_PF_RGB332) {
00272         pixeldef->bits = 1*8;
00273         return;
00274     }
00275     else
00276     if(pf == MMSFB_PF_ALUT44) {
00277         pixeldef->bits = 1*8;
00278         return;
00279     }
00280     else
00281     if(pf == MMSFB_PF_LUT8) {
00282         pixeldef->bits = 1*8;
00283         return;
00284     }
00285     else
00286     if(pf == MMSFB_PF_ARGB2554) {
00287         pixeldef->bits = 2*8;
00288         return;
00289     }
00290     else
00291     if(pf == MMSFB_PF_ARGB4444) {
00292         pixeldef->bits = 2*8;
00293         return;
00294     }
00295     else
00296     if(pf == MMSFB_PF_ARGB3565) {
00297         pixeldef->bits          = 20;
00298         pixeldef->transp_length = 3;
00299         pixeldef->red_length    = 5;
00300         pixeldef->green_length  = 6;
00301         pixeldef->blue_length   = 5;
00302         pixeldef->transp_offset = 16;
00303         pixeldef->red_offset    = 11;
00304         pixeldef->green_offset  = 5;
00305         pixeldef->blue_offset   = 0;
00306         return;
00307     }
00308     else
00309     if(pf == MMSFB_PF_BGR24) {
00310         pixeldef->bits          = 3*8;
00311         pixeldef->red_length    = 8;
00312         pixeldef->green_length  = 8;
00313         pixeldef->blue_length   = 8;
00314         pixeldef->red_offset    = 0;
00315         pixeldef->green_offset  = 8;
00316         pixeldef->blue_offset   = 16;
00317         return;
00318     }
00319     else
00320     if(pf == MMSFB_PF_BGR555) {
00321         pixeldef->bits          = 2*8;
00322         pixeldef->red_length    = 5;
00323         pixeldef->green_length  = 5;
00324         pixeldef->blue_length   = 5;
00325         pixeldef->red_offset    = 0;
00326         pixeldef->green_offset  = 5;
00327         pixeldef->blue_offset   = 10;
00328         return;
00329     }
00330     else
00331     if(pf == MMSFB_PF_ABGR) {
00332         pixeldef->bits          = 4*8;
00333         pixeldef->transp_length = 8;
00334         pixeldef->red_length    = 8;
00335         pixeldef->green_length  = 8;
00336         pixeldef->blue_length   = 8;
00337         pixeldef->transp_offset = 24;
00338         pixeldef->red_offset    = 0;
00339         pixeldef->green_offset  = 8;
00340         pixeldef->blue_offset   = 16;
00341         return;
00342     }
00343 }
00344 
00345 #ifdef  __HAVE_DIRECTFB__
00346 MMSFBSurfacePixelFormat getMMSFBPixelFormatFromDFBPixelFormat(DFBSurfacePixelFormat pf) {
00347     switch (pf) {
00348     case DSPF_RGB16:    return MMSFB_PF_RGB16;
00349     case DSPF_RGB24:    return MMSFB_PF_RGB24;
00350     case DSPF_RGB32:    return MMSFB_PF_RGB32;
00351     case DSPF_ARGB:     return MMSFB_PF_ARGB;
00352     case DSPF_A8:       return MMSFB_PF_A8;
00353     case DSPF_YUY2:     return MMSFB_PF_YUY2;
00354     case DSPF_UYVY:     return MMSFB_PF_UYVY;
00355     case DSPF_I420:     return MMSFB_PF_I420;
00356     case DSPF_YV12:     return MMSFB_PF_YV12;
00357     case DSPF_AiRGB:    return MMSFB_PF_AiRGB;
00358     case DSPF_A1:       return MMSFB_PF_A1;
00359     case DSPF_NV12:     return MMSFB_PF_NV12;
00360     case DSPF_NV16:     return MMSFB_PF_NV16;
00361     case DSPF_NV21:     return MMSFB_PF_NV21;
00362     case DSPF_AYUV:     return MMSFB_PF_AYUV;
00363     case DSPF_A4:       return MMSFB_PF_A4;
00364     case DSPF_ARGB1666: return MMSFB_PF_ARGB1666;
00365     case DSPF_ARGB6666: return MMSFB_PF_ARGB6666;
00366     case DSPF_RGB18:    return MMSFB_PF_RGB18;
00367     case DSPF_LUT2:     return MMSFB_PF_LUT2;
00368     case DSPF_RGB444:   return MMSFB_PF_RGB444;
00369     case DSPF_RGB555:   return MMSFB_PF_RGB555;
00370     case DSPF_ARGB1555: return MMSFB_PF_ARGB1555;
00371     case DSPF_RGB332:   return MMSFB_PF_RGB332;
00372     case DSPF_ALUT44:   return MMSFB_PF_ALUT44;
00373     case DSPF_LUT8:     return MMSFB_PF_LUT8;
00374     case DSPF_ARGB2554: return MMSFB_PF_ARGB2554;
00375     case DSPF_ARGB4444: return MMSFB_PF_ARGB4444;
00376     default:            return MMSFB_PF_NONE;
00377     }
00378 }
00379 
00380 DFBSurfacePixelFormat getDFBPixelFormatFromMMSFBPixelFormat(MMSFBSurfacePixelFormat pf) {
00381     switch (pf) {
00382     case MMSFB_PF_RGB16:    return DSPF_RGB16;
00383     case MMSFB_PF_RGB24:    return DSPF_RGB24;
00384     case MMSFB_PF_RGB32:    return DSPF_RGB32;
00385     case MMSFB_PF_ARGB:     return DSPF_ARGB;
00386     case MMSFB_PF_A8:       return DSPF_A8;
00387     case MMSFB_PF_YUY2:     return DSPF_YUY2;
00388     case MMSFB_PF_UYVY:     return DSPF_UYVY;
00389     case MMSFB_PF_I420:     return DSPF_I420;
00390     case MMSFB_PF_YV12:     return DSPF_YV12;
00391     case MMSFB_PF_AiRGB:    return DSPF_AiRGB;
00392     case MMSFB_PF_A1:       return DSPF_A1;
00393     case MMSFB_PF_NV12:     return DSPF_NV12;
00394     case MMSFB_PF_NV16:     return DSPF_NV16;
00395     case MMSFB_PF_NV21:     return DSPF_NV21;
00396     case MMSFB_PF_AYUV:     return DSPF_AYUV;
00397     case MMSFB_PF_A4:       return DSPF_A4;
00398     case MMSFB_PF_ARGB1666: return DSPF_ARGB1666;
00399     case MMSFB_PF_ARGB6666: return DSPF_ARGB6666;
00400     case MMSFB_PF_RGB18:    return DSPF_RGB18;
00401     case MMSFB_PF_LUT2:     return DSPF_LUT2;
00402     case MMSFB_PF_RGB444:   return DSPF_RGB444;
00403     case MMSFB_PF_RGB555:   return DSPF_RGB555;
00404     case MMSFB_PF_ARGB1555: return DSPF_ARGB1555;
00405     case MMSFB_PF_RGB332:   return DSPF_RGB332;
00406     case MMSFB_PF_ALUT44:   return DSPF_ALUT44;
00407     case MMSFB_PF_LUT8:     return DSPF_LUT8;
00408     case MMSFB_PF_ARGB2554: return DSPF_ARGB2554;
00409     case MMSFB_PF_ARGB4444: return DSPF_ARGB4444;
00410     default:                return DSPF_UNKNOWN;
00411     }
00412 }
00413 
00414 
00415 
00416 string getDFBLayerBufferModeString(DFBDisplayLayerBufferMode bm) {
00417     string ret = MMSFB_BM_NONE;
00418 
00419     if(bm & DLBM_FRONTONLY)
00420         ret = ret + "|" + MMSFB_BM_FRONTONLY;
00421 
00422     if(bm & DLBM_BACKVIDEO)
00423         ret = ret + "|" + MMSFB_BM_BACKVIDEO;
00424     if(bm & DLBM_BACKSYSTEM)
00425         ret = ret + "|" + MMSFB_BM_BACKSYSTEM;
00426     if(bm & DLBM_TRIPLE)
00427         ret = ret + "|" + MMSFB_BM_TRIPLE;
00428     if(bm & DLBM_WINDOWS)
00429         ret = ret + "|" + MMSFB_BM_WINDOWS;
00430 
00431     if (ret!=MMSFB_BM_NONE)
00432         return ret.substr(1);
00433     else
00434         return MMSFB_BM_NONE;
00435 }
00436 
00437 DFBDisplayLayerBufferMode getDFBLayerBufferModeFromString(string bm) {
00438     DFBDisplayLayerBufferMode b = DLBM_UNKNOWN;
00439 
00440     if (bm == MMSFB_BM_NONE)
00441         return b;
00442     if(strstr(bm.c_str(),MMSFB_BM_FRONTONLY))
00443         b = (DFBDisplayLayerBufferMode)(b | DLBM_FRONTONLY);
00444 
00445     if(strstr(bm.c_str(),MMSFB_BM_BACKVIDEO))
00446         b = (DFBDisplayLayerBufferMode)(b | DLBM_BACKVIDEO);
00447     if(strstr(bm.c_str(),MMSFB_BM_BACKSYSTEM))
00448         b = (DFBDisplayLayerBufferMode)(b | DLBM_BACKSYSTEM);
00449     if(strstr(bm.c_str(),MMSFB_BM_TRIPLE))
00450         b = (DFBDisplayLayerBufferMode)(b | DLBM_TRIPLE);
00451     if(strstr(bm.c_str(),MMSFB_BM_WINDOWS))
00452         b = (DFBDisplayLayerBufferMode)(b | DLBM_WINDOWS);
00453     return b;
00454 }
00455 
00456 string getDFBLayerOptionsString(DFBDisplayLayerOptions opts) {
00457     string ret = MMSFB_LO_NONE;
00458 
00459     if(opts & DLOP_ALPHACHANNEL)
00460         ret = ret + "|" + MMSFB_LO_ALPHACHANNEL;
00461     if(opts & DLOP_FLICKER_FILTERING)
00462         ret = ret + "|" + MMSFB_LO_FLICKER_FILTERING;
00463     if(opts & DLOP_DEINTERLACING)
00464         ret = ret + "|" + MMSFB_LO_DEINTERLACING;
00465     if(opts & DLOP_SRC_COLORKEY)
00466         ret = ret + "|" + MMSFB_LO_SRC_COLORKEY;
00467     if(opts & DLOP_DST_COLORKEY)
00468         ret = ret + "|" + MMSFB_LO_DST_COLORKEY;
00469     if(opts & DLOP_OPACITY)
00470         ret = ret + "|" + MMSFB_LO_OPACITY;
00471     if(opts & DLOP_FIELD_PARITY)
00472         ret = ret + "|" + MMSFB_LO_FIELD_PARITY;
00473 
00474     if (ret!=MMSFB_LO_NONE)
00475         return ret.substr(1);
00476     else
00477         return MMSFB_LO_NONE;
00478 }
00479 
00480 DFBDisplayLayerOptions getDFBLayerOptionsFromString(string opts) {
00481     DFBDisplayLayerOptions  o = DLOP_NONE;
00482 
00483     if (opts == MMSFB_LO_NONE)
00484         return o;
00485     if(strstr(opts.c_str(),MMSFB_LO_ALPHACHANNEL))
00486         o = (DFBDisplayLayerOptions)(o | DLOP_ALPHACHANNEL);
00487     if(strstr(opts.c_str(),MMSFB_LO_FLICKER_FILTERING))
00488         o = (DFBDisplayLayerOptions)(o | DLOP_FLICKER_FILTERING);
00489     if(strstr(opts.c_str(),MMSFB_LO_DEINTERLACING))
00490         o = (DFBDisplayLayerOptions)(o | DLOP_DEINTERLACING);
00491     if(strstr(opts.c_str(),MMSFB_LO_SRC_COLORKEY))
00492         o = (DFBDisplayLayerOptions)(o | DLOP_SRC_COLORKEY);
00493     if(strstr(opts.c_str(),MMSFB_LO_DST_COLORKEY))
00494         o = (DFBDisplayLayerOptions)(o | DLOP_DST_COLORKEY);
00495     if(strstr(opts.c_str(),MMSFB_LO_OPACITY))
00496         o = (DFBDisplayLayerOptions)(o | DLOP_OPACITY);
00497     if(strstr(opts.c_str(),MMSFB_LO_FIELD_PARITY))
00498         o = (DFBDisplayLayerOptions)(o | DLOP_FIELD_PARITY);
00499     return o;
00500 }
00501 
00502 
00503 DFBSurfaceBlittingFlags getDFBSurfaceBlittingFlagsFromMMSFBBlittingFlags(MMSFBBlittingFlags flags) {
00504     DFBSurfaceBlittingFlags retflags = DSBLIT_NOFX;
00505     if (flags & MMSFB_BLIT_BLEND_ALPHACHANNEL)
00506         retflags = (DFBSurfaceBlittingFlags)(retflags | DSBLIT_BLEND_ALPHACHANNEL);
00507     if (flags & MMSFB_BLIT_BLEND_COLORALPHA)
00508         retflags = (DFBSurfaceBlittingFlags)(retflags | DSBLIT_BLEND_COLORALPHA);
00509     if (flags & MMSFB_BLIT_COLORIZE)
00510         retflags = (DFBSurfaceBlittingFlags)(retflags | DSBLIT_COLORIZE);
00511     if (flags & MMSFB_BLIT_SRC_PREMULTIPLY)
00512         retflags = (DFBSurfaceBlittingFlags)(retflags | DSBLIT_SRC_PREMULTIPLY);
00513     if (flags & MMSFB_BLIT_SRC_PREMULTCOLOR)
00514         retflags = (DFBSurfaceBlittingFlags)(retflags | DSBLIT_SRC_PREMULTCOLOR);
00515     return retflags;
00516 }
00517 
00518 DFBSurfaceDrawingFlags getDFBSurfaceDrawingFlagsFromMMSFBDrawingFlags(MMSFBDrawingFlags flags) {
00519     DFBSurfaceDrawingFlags retflags = DSDRAW_NOFX;
00520     if (flags & MMSFB_DRAW_BLEND)
00521         retflags = (DFBSurfaceDrawingFlags)(retflags | DSDRAW_BLEND);
00522     if (flags & MMSFB_DRAW_SRC_PREMULTIPLY)
00523         retflags = (DFBSurfaceDrawingFlags)(retflags | DSDRAW_SRC_PREMULTIPLY);
00524     return retflags;
00525 }
00526 
00527 DFBSurfaceFlipFlags getDFBSurfaceFlipFlagsFromMMSFBFlipFlags(MMSFBFlipFlags flags) {
00528     DFBSurfaceFlipFlags retflags = DSFLIP_NONE;
00529     if (flags & MMSFB_FLIP_WAIT)
00530         retflags = (DFBSurfaceFlipFlags)(retflags | DSFLIP_WAIT);
00531     if (flags & MMSFB_FLIP_ONSYNC)
00532         retflags = (DFBSurfaceFlipFlags)(retflags | DSFLIP_ONSYNC);
00533     if (flags & MMSFB_FLIP_WAITFORSYNC)
00534         retflags = (DFBSurfaceFlipFlags)(retflags | DSFLIP_WAITFORSYNC);
00535     return retflags;
00536 }
00537 
00538 DFBSurfaceLockFlags getDFBSurfaceLockFlagsFromMMSFBLockFlags(MMSFBLockFlags flags) {
00539     DFBSurfaceLockFlags retflags = DSLF_READ;
00540     if (flags & MMSFB_LOCK_WRITE)
00541         retflags = (DFBSurfaceLockFlags)(retflags | DSLF_WRITE);
00542     return retflags;
00543 }
00544 
00545 
00546 #endif
00547 
00548 
00549 void calcAspectRatio(int sw, int sh, int dw, int dh, MMSFBRectangle &dest, bool aspect_ratio, bool even_aligned) {
00550     if (aspect_ratio) {
00551         // calc aspect ratio
00552         dest.h = dw * sh / sw;
00553         if (dest.h <= dh) {
00554             dest.w = dw;
00555         }
00556         else {
00557             dest.w = dh * sw / sh;
00558             dest.h = dh;
00559         }
00560     }
00561     else {
00562         // using full dest dimension
00563         dest.w = dw;
00564         dest.h = dh;
00565     }
00566 
00567     // calc pos
00568     dest.x = (dw - dest.w) / 2;
00569     dest.y = (dh - dest.h) / 2;
00570 
00571     if (even_aligned) {
00572         // even pos and dimension
00573         dest.x &= ~0x01;
00574         dest.y &= ~0x01;
00575         dest.w &= ~0x01;
00576         dest.h &= ~0x01;
00577     }
00578 }
00579 

Generated by doxygen