home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / flbrightness.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  3.8 KB  |  171 lines

  1. /* 
  2.  *  flbrightness.cpp 
  3.  *                                     
  4.  *
  5.  *    Copyright (C) Alberto Vigata - January 2000
  6.  *
  7.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  8.  *    
  9.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2, or (at your option)
  12.  *  any later version.
  13.  *   
  14.  *  FlasKMPEG is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *   
  19.  *  You should have received a copy of the GNU General Public License
  20.  *  along with GNU Make; see the file COPYING.  If not, write to
  21.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  22.  *
  23.  */
  24.  
  25. #include "flbrightness.h"
  26. #include "Debug.h"
  27.  
  28.  
  29. static const __int64 mmmask_0064 = 0x0040004000400040;
  30.  
  31. static void Luminance_Filter(unsigned char *src, int area, int LumGain, int LumOffset )
  32. {
  33.     __int64 LumGainMask = ((__int64)LumGain<<48) + 
  34.                         ((__int64)LumGain<<32) + 
  35.                         ((__int64)LumGain<<16) + 
  36.                          (__int64)LumGain;
  37.  
  38.     __int64 LumOffsetMask = ((__int64)LumOffset<<48) + 
  39.                           ((__int64)LumOffset<<32) + 
  40.                           ((__int64)LumOffset<<16) + 
  41.                            (__int64)LumOffset;
  42.  
  43.     __asm
  44.     {
  45.         mov            eax, [src]
  46.         mov            esi, 0x00
  47.         mov            edi, [area]
  48.         pxor        mm0, mm0
  49.         movq        mm5, [LumOffsetMask]
  50.         movq        mm6, [LumGainMask]
  51.         movq        mm7, [mmmask_0064]
  52.  
  53. lumconv:
  54.         movq        mm1, [eax+esi]
  55.         movq        mm2, mm1
  56.  
  57.         punpcklbw    mm1, mm0
  58.         punpckhbw    mm2, mm0
  59.  
  60.         ;pmullw        mm1, mm6
  61.         ;pmullw        mm2, mm6
  62.  
  63.         ;paddw        mm1, mm7
  64.         ;paddw        mm2, mm7
  65.  
  66.         ;psrlw        mm1, 7
  67.         ;psrlw        mm2, 7
  68.  
  69.         paddw        mm1, mm5
  70.         paddw        mm2, mm5
  71.  
  72.         packuswb    mm1, mm0
  73.         packuswb    mm2, mm0
  74.  
  75.         add            esi, 0x08
  76.         cmp            esi, edi
  77.         movd        [eax+esi-8], mm1
  78.         movd        [eax+esi-4], mm2
  79.         jl            lumconv
  80.     }
  81. }
  82.  
  83.  
  84. FlBrightness::FlBrightness()
  85. {
  86.   memset( &m_cfg, 0, sizeof m_cfg );
  87.   m_bConfigured = false;
  88. }
  89.  
  90. void FlBrightness::Luminance(CFrame *in) {
  91.   switch( in->GetFormat() ) {
  92.     case FRAME_YV12:
  93.       Luminance_Filter( in->GetBuffer(), in->GetWidth()*in->GetHeight(), 128, m_cfg.brightness-128 );
  94.       break;
  95.     default:
  96.       break;
  97.   }
  98. }
  99.  
  100. int FlBrightness::StartSimple()
  101. {
  102.   return m_bConfigured == true ? 1 : 0;
  103. }
  104.  
  105. int FlBrightness::Configure( void *conf, int confsize)
  106. {
  107.   FLASSERT( confsize==sizeof(TBrightnessCfg) )
  108.   TBrightnessCfg cfg = *(TBrightnessCfg *)conf;
  109.  
  110.   m_cfg = cfg;
  111.   m_bConfigured = true;
  112.   return flfil_ok;
  113. }
  114.  
  115. int FlBrightness::GetFilterConf( flfilter_conf *fc )
  116. {
  117.   if(!m_bConfigured)
  118.   {
  119.     DBG_STR((str, "FlBrightness::GetConf - You need to configure first\n"))
  120.     return 0;
  121.   }
  122.  
  123.   if(!fc)
  124.     return 0;
  125.  
  126.   *fc = m_fc;
  127.  
  128.   return 1;
  129. }
  130.  
  131. int FlBrightness::ValFilterConf( flfilter_conf *fc )
  132. {
  133.   if(!m_bConfigured)
  134.   {
  135.     DBG_STR((str, "FlBrightness::ValFilterConf - You need to configure first\n"))
  136.     return flfil_error;
  137.   }
  138.   
  139.   if( m_cfg.brightness < 0 || m_cfg.brightness>255) {
  140.     DBG_STR((str, "FlBrightness::ValFilterConf - Bad configuration\n"))
  141.     return flfil_error;
  142.   }
  143.   
  144.   if( fc->iw%8 != 0 ) {
  145.     DBG_STR((str, "FlBrightness::ValFilterConf - Width must be multiple of 8\n"))
  146.     return flfil_error;
  147.   }
  148.  
  149.   fc->od = fc->id;
  150.   fc->ow = fc->iw;
  151.   fc->oh = fc->ih;
  152.   fc->oprovided = 0;
  153.   fc->op = 1;
  154.   fc->ocanmodify = 1;
  155.  
  156.   m_fc = *fc;
  157.  
  158.   return 1;
  159. }
  160.  
  161. int FlBrightness::ProcessSimple( CFrame *in,  CFrame *out )
  162. {
  163.   FLASSERT( out==NULL )
  164.   Luminance( in );
  165.   return true;
  166. }
  167.  
  168. int FlBrightness::StopSimple()
  169. {
  170.   return 1;
  171. }