Project

General

Profile

Bug #104 » XBMC4Xbox_AmbiLightPatch3.patch

All previous patches are incomplete, here's a recent complete patch. - lagwagon667, 04/09/2010 09:23 AM

View differences:

skin/Project Mayhem III/PAL/Home.xml (working copy)
<onright>96</onright>
<onup>9</onup>
<ondown>5</ondown>
<onfocus>XBMC.System.PWMControl(#FF0000)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>30</textoffsetx>
......
<onright>96</onright>
<onup>2</onup>
<ondown>3</ondown>
<onfocus>XBMC.System.PWMControl(#00FF00)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>30</textoffsetx>
......
<onright>96</onright>
<onup>5</onup>
<ondown>4</ondown>
<onfocus>XBMC.System.PWMControl(#FFFFFF,#000000,#000000,#000000,firework,500)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>30</textoffsetx>
......
<onright>96</onright>
<onup>3</onup>
<ondown>7</ondown>
<onfocus>XBMC.System.PWMControl(#FF00FF)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>30</textoffsetx>
......
<onright>96</onright>
<onup>4</onup>
<ondown>9</ondown>
<onfocus>XBMC.System.PWMControl(#FFFF00)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>30</textoffsetx>
......
<onright>6</onright>
<onup>10</onup>
<ondown>5</ondown>
<onfocus>XBMC.System.PWMControl(#00FFFF)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>20</textoffsetx>
......
<onright>96</onright>
<onup>10</onup>
<ondown>5</ondown>
<onfocus>XBMC.System.PWMControl(#FFFFFF)</onfocus>
<texturefocus>home-focus.gif</texturefocus>
<texturenofocus>-</texturenofocus>
<textoffsetx>20</textoffsetx>
userdata/AdvancedSettings.xml (revision 0)
<advancedsettings>
<ambilight>
<enabled>true</enabled>
<spaceBetweenPixels>30</spaceBetweenPixels>
<FloatingAverageFrames>1</FloatingAverageFrames>
<GammaR>1.2</GammaR>
<GammaG>1.0</GammaG>
<GammaB>0.8</GammaB>
<MinRGB>2</MinRGB>
<FilterThreshold>50</FilterThreshold>
<DarknessLimit>20</DarknessLimit>
</ambilight>
</advancedsettings>
xbmc/AdvancedSettings.cpp (working copy)
m_bAutoFatxLimit = true;
m_bgInfoLoaderMaxThreads = 1;
m_ambiLight = false;
m_ambiLightSpaceBetweenPixels = 30;
m_ambiLightFloatingAverageFrames = 1;
m_ambiLightMinRGB = 2;
m_ambiLightMaxRGB = 255;
m_ambiLightMode = "linear";
m_ambiLightPosition = "all";
m_ambiLightGammaR = 1.2f;
m_ambiLightGammaG = 1.0f;
m_ambiLightGammaB = 0.8f;
m_ambiLightIntensityR = 1.0f;
m_ambiLightIntensityG = 1.0f;
m_ambiLightIntensityB = 1.0f;
m_ambiLightFilterThreshold = 50;
m_ambiLightDarknessLimit = 20;
}
bool CAdvancedSettings::Load()
......
XMLUtils::GetBoolean(pElement, "verbose", m_bPythonVerbose);
}
pElement = pRootElement->FirstChildElement("ambilight");
if (pElement)
{
XMLUtils::GetBoolean(pElement, "enabled", m_ambiLight);
XMLUtils::GetInt(pElement, "spaceBetweenPixels", m_ambiLightSpaceBetweenPixels);
XMLUtils::GetInt(pElement, "floatingAverageFrames", m_ambiLightFloatingAverageFrames);
XMLUtils::GetInt(pElement, "minRGB", m_ambiLightMinRGB);
XMLUtils::GetInt(pElement, "maxRGB", m_ambiLightMaxRGB);
XMLUtils::GetString(pElement, "mode", m_ambiLightMode);
XMLUtils::GetString(pElement, "position", m_ambiLightPosition);
XMLUtils::GetFloat(pElement, "gammaR", m_ambiLightGammaR);
XMLUtils::GetFloat(pElement, "gammaG", m_ambiLightGammaG);
XMLUtils::GetFloat(pElement, "gammaB", m_ambiLightGammaB);
XMLUtils::GetFloat(pElement, "intensityR", m_ambiLightIntensityR);
XMLUtils::GetFloat(pElement, "intensityG", m_ambiLightIntensityG);
XMLUtils::GetFloat(pElement, "intensityB", m_ambiLightIntensityB);
XMLUtils::GetInt(pElement, "filterThreshold", m_ambiLightFilterThreshold);
XMLUtils::GetInt(pElement, "darknessLimit", m_ambiLightDarknessLimit);
}
XMLUtils::GetBoolean(pRootElement, "autofatxlimit", m_bAutoFatxLimit);
XMLUtils::GetString(pRootElement, "cddbaddress", m_cddbAddress);
......
XMLUtils::GetInt(pElement, "commbreakautowait", m_iEdlCommBreakAutowait, 0, 10); // Between 0 and 10 seconds
XMLUtils::GetInt(pElement, "commbreakautowind", m_iEdlCommBreakAutowind, 0, 10); // Between 0 and 10 seconds
}
// picture exclude regexps
TiXmlElement* pPictureExcludes = pRootElement->FirstChildElement("pictureexcludes");
if (pPictureExcludes)
xbmc/AdvancedSettings.h (working copy)
bool m_bPythonVerbose;
bool m_bAutoFatxLimit;
int m_bgInfoLoaderMaxThreads;
bool m_ambiLight;
int m_ambiLightSpaceBetweenPixels;
int m_ambiLightFloatingAverageFrames;
int m_ambiLightMinRGB;
int m_ambiLightMaxRGB;
CStdString m_ambiLightMode;
CStdString m_ambiLightPosition;
float m_ambiLightGammaR;
float m_ambiLightGammaG;
float m_ambiLightGammaB;
float m_ambiLightIntensityR;
float m_ambiLightIntensityG;
float m_ambiLightIntensityB;
int m_ambiLightFilterThreshold;
int m_ambiLightDarknessLimit;
};
extern CAdvancedSettings g_advancedSettings;
xbmc/Application.cpp (working copy)
}
UpdateLCD();
g_iledSmartxxrgb.AmbiLightUpdateFrameNumber();
// read raw input from controller, remote control, mouse and keyboard
ReadInput();
xbmc/cores/dvdplayer/DVDPlayerVideo.cpp (working copy)
#include "DVDCodecs/Overlay/DVDOverlaySSA.h"
#include <sstream>
#include <iomanip>
#include "utils/LED.h"
using namespace std;
......
memset(&picture, 0, sizeof(DVDVideoPicture));
if (m_pVideoCodec->GetPicture(&picture))
{
// AMBI-LIGHT STUFF
if(g_advancedSettings.m_ambiLight)
{
g_iledSmartxxrgb.AmbiLightUpdate();
g_iledSmartxxrgb.AmbiLightParamsUpdate(0,picture.iWidth,2);
for(unsigned int i=0;i<picture.iHeight;i++)
{
BYTE *s0=&picture.data[0][i*picture.iWidth];
BYTE *s1=&picture.data[1][i/2*picture.iWidth/2];
BYTE *s2=&picture.data[2][i/2*picture.iWidth/2];
g_iledSmartxxrgb.AmbiLightRGBCalculate(s0,s1,s2);
}
}
// END AMBI-LIGHT STUFF
sPostProcessType.clear();
picture.iGroupId = pPacket->iGroupId;
......
m_pOverlayCodecCC = NULL;
}
//g_iledSmartxxrgb.AmbiLightStop();
CLog::Log(LOGNOTICE, "thread end: video_thread");
}
xbmc/cores/VideoRenderers/XBoxRenderer.cpp (working copy)
#include "Application.h"
#include "XBVideoConfig.h"
#include "Settings.h"
#include "utils/LED.h"
// http://www.martinreddy.net/gfx/faqs/colorconv.faq
......
m_yuvcoef = yuv_coef_bt601; break;
}
// init Params for AmbiLight
g_iledSmartxxrgb.AmbiLightParamsInit(width,height,m_yuvcoef,m_yuvrange);
// calculate the input frame aspect ratio
CalculateFrameAspectRatio(d_width, d_height);
ChooseBestResolution(m_fps);
......
unsigned int CXBoxRenderer::DrawSlice(unsigned char *src[], int stride[], int w, int h, int x, int y)
{
BYTE *s;
BYTE *d;
int i, p;
BYTE *s0,*s1,*s2;
BYTE *d0,*d1,*d2;
int w2,h2,x2,y2;
// check if we've finished the recent Frame and push it to the SmartXX...
if(g_advancedSettings.m_ambiLight)
g_iledSmartxxrgb.AmbiLightUpdate();
int index = NextYV12Texture();
if( index < 0 )
return -1;
......
CLog::Log(LOGWARNING, CStdString(__FUNCTION__) + " - Timeout waiting for texture %d", index);
YV12Image &im = m_image[index];
// copy Y
p = 0;
d = (BYTE*)im.plane[p] + im.stride[p] * y + x;
s = src[p];
for (i = 0;i < h;i++)
{
memcpy(d, s, w);
s += stride[p];
d += im.stride[p];
}
// Y
d0 = (BYTE*)im.plane[0] + im.stride[0] * y + x;
s0 = src[0];
w >>= im.cshift_x; h >>= im.cshift_y;
x >>= im.cshift_x; y >>= im.cshift_y;
w2 = w >> im.cshift_x; h2 = h >> im.cshift_y;
x2 = x >> im.cshift_x; y2 = y >> im.cshift_y;
// U
d1 = (BYTE*)im.plane[1] + im.stride[1] * y2 + x2;
s1 = src[1];
// copy U
p = 1;
d = (BYTE*)im.plane[p] + im.stride[p] * y + x;
s = src[p];
for (i = 0;i < h;i++)
// V
d2 = (BYTE*)im.plane[2] + im.stride[2] * y2 + x2;
s2 = src[2];
int widthRatio = (int)(w/w2);
int heightRatio = (int)(h/h2);
//Update AmbiLights params...
if(g_advancedSettings.m_ambiLight)
g_iledSmartxxrgb.AmbiLightParamsUpdate(x,w,widthRatio);
for (int i = 0;i < h;i++)
{
memcpy(d, s, w);
s += stride[p];
d += im.stride[p];
}
memcpy(d0, s0, w);
s0 += stride[0];
d0 += im.stride[0];
// copy V
p = 2;
d = (BYTE*)im.plane[p] + im.stride[p] * y + x;
s = src[p];
for (i = 0;i < h;i++)
{
memcpy(d, s, w);
s += stride[p];
d += im.stride[p];
if(i % heightRatio == 0)
{
memcpy(d1, s1, w2);
s1 += stride[1];
d1 += im.stride[1];
memcpy(d2, s2, w2);
s2 += stride[2];
d2 += im.stride[2];
}
// calculate RGB-values for the recent row of the frame...
if(g_advancedSettings.m_ambiLight)
g_iledSmartxxrgb.AmbiLightRGBCalculate(s0,s1,s2);
}
SetEvent(m_eventTexturesDone[index]);
......
m_hLowMemShader = 0;
}
g_iledSmartxxrgb.AmbiLightStop();
m_bConfigured = false;
}
xbmc/Settings.cpp (working copy)
*/
#include "stdafx.h"
#include "utils/SystemInfo.h"
#include "Settings.h"
#include "AdvancedSettings.h"
#include "Application.h"
......
g_stSettings.iAdditionalSubtitleDirectoryChecked = 0;
g_settings.bUseLoginScreen = false;
/*g_advancedSettings.m_ambiLight = false;
g_advancedSettings.m_ambiLightSpaceBetweenPixels = 100;
g_advancedSettings.m_ambiLightFloatingAverageFrames = 10;
g_advancedSettings.m_ambiLightMinRGB = 0;
g_advancedSettings.m_ambiLightMaxRGB = 255;
g_advancedSettings.m_ambiLightMode = "linear";
g_advancedSettings.m_ambiLightPosition = "all";
g_advancedSettings.m_ambiLightGammaR = 1.0f;
g_advancedSettings.m_ambiLightGammaG = 1.0f;
g_advancedSettings.m_ambiLightGammaB = 1.0f;
g_advancedSettings.m_ambiLightIntensityR = 1.0f;
g_advancedSettings.m_ambiLightIntensityG = 1.0f;
g_advancedSettings.m_ambiLightIntensityB = 1.0f;
g_advancedSettings.m_ambiLightFilterThreshold = 150;
g_advancedSettings.m_ambiLightDarknessLimit = 2;*/
}
CSettings::~CSettings(void)
xbmc/Settings.h (working copy)
CStdString m_cpuTempCmd;
CStdString m_gpuTempCmd;
int m_bgInfoLoaderMaxThreads;
//bool m_ambiLight;
/*int m_ambiLightSpaceBetweenPixels;
int m_ambiLightFloatingAverageFrames;
int m_ambiLightMinRGB;
int m_ambiLightMaxRGB;
CStdString m_ambiLightMode;
CStdString m_ambiLightPosition;
float m_ambiLightGammaR;
float m_ambiLightGammaG;
float m_ambiLightGammaB;
float m_ambiLightIntensityR;
float m_ambiLightIntensityG;
float m_ambiLightIntensityB;
int m_ambiLightFilterThreshold;
int m_ambiLightDarknessLimit;*/
};
struct stSettings
xbmc/Util.cpp (working copy)
strWhiteB= arSplit[3].c_str();
strTran = arSplit[4].c_str();
iTrTime = atoi(arSplit[5].c_str());
CUtil::PWMControl(strRgbA,strRgbB,strWhiteA,strWhiteB,strTran, iTrTime);
}
else if(parameter.size() > 6)
else if(parameter.size() == 7)
{
strRgbA = strRgbB = parameter;
strWhiteA = strWhiteB = "#000000";
strTran = "none";
strTran = "fade2";
tRGBColor rgb;
sscanf(parameter,"#%2X%2X%2X",&rgb.r,&rgb.g,&rgb.b);
//CUtil::PWMControl(strRgbA,strRgbB,strWhiteA,strWhiteB,strTran, iTrTime);
g_iledSmartxxrgb.SetRGBState(rgb);
}
CUtil::PWMControl(strRgbA,strRgbB,strWhiteA,strWhiteB,strTran, iTrTime);
else
CLog::Log(LOGDEBUG,"System.PWMControl(): Invalid parameters - use: System.PWMControl(#rgb1,#rgb2,#white1,#white2,mode,time)");
}
else if (execute.Equals("backupsysteminfo"))
{
xbmc/utils/LED.cpp (working copy)
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
/*
XBOX Front LED control
......
#include "xbox/XKUtils.h"
#include "LCD.h"
#include "GUISettings.h"
#include "Settings.h"
#include <conio.h>
// set accuracy of color calculation
#define h_MAX 255
#define s_MAX 255
#define v_MAX 255
#define POS_DIV(a, b) ( (a)/(b) + ( ((a)%(b) >= (b)/2 ) ? 1 : 0) )
#define WINDOW_SIZE 5
#define HUE_WINDOW 5
#define PIXEL_AMOUNT 768*576
#define MIN_PERCENTAGE 1
#define FADE2_MAX_TIME 1000
#define SLOWLIMIT 12
#define SLOWTIMES 4
ILEDSmartxxRGB g_iledSmartxxrgb;
void ILED::CLEDControl(int ixLED)
......
ILEDSmartxxRGB::ILEDSmartxxRGB()
{
strCurrentStatus = "NULL";
strLastStatus = "NULL";
strCurrentStatus = "NULL";
strLastStatus = "NULL";
s_RGBs.strTransition = "NULL";
s_CurRGB.red = 0;
s_CurRGB.green = 0;
s_CurRGB.blue = 0;
s_CurRGB.red = 0;
s_CurRGB.green = 0;
s_CurRGB.blue = 0;
s_CurRGB.white = 0;
dwLastTime = 0;
bRepeat = false;
isPaused = false;
AmbiLightParams.AmbiLightIsPlaying=false;
}
ILEDSmartxxRGB::~ILEDSmartxxRGB()
......
{
if (g_sysinfo.SmartXXModCHIP().Equals("SmartXX V3") || g_sysinfo.SmartXXModCHIP().Equals("SmartXX OPX"))
{
SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST);
CLog::Log(LOGDEBUG,"Starting SmartXX RGB LED thread");
//SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST);
SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST);
CLog::Log(LOGDEBUG,"Starting SmartXX RGB LED thread");
SetRGBStatus("general");
}
}
void ILEDSmartxxRGB::Process()
{
while(!m_bStop)
{
dwFrameTime = timeGetTime() - dwLastTime;
while(!m_bStop)
{
if(!isPaused)
{
dwFrameTime = timeGetTime() - dwLastTime;
if( (s_RGBs.strTransition.IsEmpty() || s_RGBs.strTransition.Equals("none")) && !strLastTransition.Equals("none") )
{
strLastTransition = "none";
s_CurRGB.red = s_RGBs.red1;
s_CurRGB.green = s_RGBs.green1;
s_CurRGB.blue = s_RGBs.blue1;
s_CurRGB.white = s_RGBs.white1;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue, s_CurRGB.white);
}
else if(s_RGBs.strTransition.Equals("switch") && !strLastTransition.Equals("switch"))
{
if(dwFrameTime >= s_RGBs.iTime )
{
s_CurRGB.red = s_RGBs.red2;
s_CurRGB.green = s_RGBs.green2;
s_CurRGB.blue = s_RGBs.blue2;
s_CurRGB.white = s_RGBs.white2;
strLastTransition = "switch";
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
else
{
s_CurRGB.red = s_RGBs.red1;
s_CurRGB.green = s_RGBs.green1;
if( (s_RGBs.strTransition.IsEmpty() || s_RGBs.strTransition.Equals("none")) && !strLastTransition.Equals("none") )
{
s_CurRGB.red = s_RGBs.red1;
s_CurRGB.green = s_RGBs.green1;
s_CurRGB.blue = s_RGBs.blue1;
s_CurRGB.white = s_RGBs.white1;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue, s_CurRGB.white);
}
}
else if(s_RGBs.strTransition.Equals("blink"))
else if(s_RGBs.strTransition.Equals("switch") && !strLastTransition.Equals("switch"))
{
if(dwFrameTime >= s_RGBs.iTime )
{
s_CurRGB.red = s_RGBs.red2;
s_CurRGB.green = s_RGBs.green2;
s_CurRGB.blue = s_RGBs.blue2;
s_CurRGB.white = s_RGBs.white2;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
else
{
s_CurRGB.red = s_RGBs.red1;
s_CurRGB.green = s_RGBs.green1;
s_CurRGB.blue = s_RGBs.blue1;
s_CurRGB.white = s_RGBs.white1;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
}
else if(s_RGBs.strTransition.Equals("blink"))
{
strLastTransition = "blink";
if(dwFrameTime >= s_RGBs.iTime )
{
s_CurRGB.red = (s_CurRGB.red != s_RGBs.red1) ? s_RGBs.red1 : s_RGBs.red2;
s_CurRGB.green = (s_CurRGB.green != s_RGBs.green1) ? s_RGBs.green1 : s_RGBs.green2;
s_CurRGB.blue = (s_CurRGB.blue != s_RGBs.blue1) ? s_RGBs.blue1 : s_RGBs.blue2;
s_CurRGB.white= (s_CurRGB.white != s_RGBs.white1) ? s_RGBs.white1 : s_RGBs.white2;
dwLastTime = timeGetTime();
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
}
else if(s_RGBs.strTransition.Equals("fade") || s_RGBs.strTransition.Equals("fadeloop") || s_RGBs.strTransition.Equals("faderepeat"))
{
static double distanceR,distanceG,distanceB,distanceW;
if(!strLastTransition.Equals("fade"))
{
distanceR = bRepeat ? s_RGBs.red1-s_RGBs.red2 : s_RGBs.red2-s_RGBs.red1;
distanceG = bRepeat ? s_RGBs.green1-s_RGBs.green2 : s_RGBs.green2-s_RGBs.green1;
distanceB = bRepeat ? s_RGBs.blue1-s_RGBs.blue2 : s_RGBs.blue2-s_RGBs.blue1;
distanceW = bRepeat ? s_RGBs.white1-s_RGBs.white2 : s_RGBs.white2-s_RGBs.white1;
strLastTransition = "fade";
if(s_RGBs.strTransition.Equals("faderepeat"))bRepeat=!bRepeat;
}
if(dwFrameTime <= s_RGBs.iTime )
{
double stepR=distanceR/s_RGBs.iTime*dwFrameTime;
double stepG=distanceG/s_RGBs.iTime*dwFrameTime;
double stepB=distanceB/s_RGBs.iTime*dwFrameTime;
double stepW=distanceW/s_RGBs.iTime*dwFrameTime;
s_CurRGB.red=(bRepeat ? s_RGBs.red1 : s_RGBs.red2) +(int)stepR;
s_CurRGB.green=(bRepeat ? s_RGBs.green1 : s_RGBs.green2)+(int)stepG;
s_CurRGB.blue=(bRepeat ? s_RGBs.blue1 : s_RGBs.blue2)+(int)stepB;
s_CurRGB.white=(bRepeat ? s_RGBs.white1 : s_RGBs.white2)+(int)stepW;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
else if(s_RGBs.strTransition.Equals("fadeloop") || s_RGBs.strTransition.Equals("faderepeat"))
{
strLastTransition="none";
dwLastTime = timeGetTime();
}
}
else if(s_RGBs.strTransition.Equals("fade2"))
{
static int distanceR,distanceG,distanceB,distanceW;
static int maxDiffR,maxDiffG,maxDiffB;
if(!strLastTransition.Equals("fade2"))
{
strLastTransition = "fade2";
dwFrameTime = 0;
dwLastTime = timeGetTime();
s_RGBs.red1 =s_CurRGB.red;
s_RGBs.green1 =s_CurRGB.green;
s_RGBs.blue1 =s_CurRGB.blue ;
distanceR = s_RGBs.red2-s_RGBs.red1;
distanceG = s_RGBs.green2-s_RGBs.green1;
distanceB = s_RGBs.blue2-s_RGBs.blue1;
distanceW = s_RGBs.white2-s_RGBs.white1;
/*maxDiffR=(int)((float)distanceR/FADE2_MAX_TIME*2);
maxDiffG=(int)((float)distanceG/FADE2_MAX_TIME*2);
maxDiffB=(int)((float)distanceB/FADE2_MAX_TIME*2);
if(maxDiffR==0)maxDiffR=1;
if(maxDiffG==0)maxDiffG=1;
if(maxDiffB==0)maxDiffB=1;*/
int max=abs(MAX(distanceR,distanceG,distanceB));
//max eine sekunde transition time
s_RGBs.iTime = int((max/255.0f)*FADE2_MAX_TIME);
}
if(dwFrameTime <= s_RGBs.iTime && (s_CurRGB.red!=s_RGBs.red2 || s_CurRGB.blue!=s_RGBs.blue2 || s_CurRGB.green!=s_RGBs.green2))
{
// how far do we need to be according to current time...
int stepR=(int)((double)distanceR/s_RGBs.iTime*dwFrameTime);
int stepG=(int)((double)distanceG/s_RGBs.iTime*dwFrameTime);
int stepB=(int)((double)distanceB/s_RGBs.iTime*dwFrameTime);
int stepW=(int)((double)distanceW/s_RGBs.iTime*dwFrameTime);
/*int diffR=abs(s_CurRGB.red-s_RGBs.red1+stepR);
int diffG=abs(s_CurRGB.green-s_RGBs.green1+stepG);
int diffB=abs(s_CurRGB.blue-s_RGBs.blue1+stepB);
if(diffR>maxDiffR)
stepR=s_CurRGB.red+maxDiffR-s_RGBs.red1;
if(diffG>maxDiffG)
stepG=s_CurRGB.green+maxDiffG-s_RGBs.green1;
if(diffB>maxDiffB)
stepB=s_CurRGB.blue+maxDiffB-s_RGBs.blue1;*/
s_CurRGB.red=s_RGBs.red1+stepR;
s_CurRGB.green=s_RGBs.green1+stepG;
s_CurRGB.blue=s_RGBs.blue1+stepB;
s_CurRGB.white=s_RGBs.white1+stepW;
/*if(s_CurRGB.red<=SLOWLIMIT)
{
static int counter=0;
if(counter==SLOWTIMES)
{
if(s_CurRGB.red<s_RGBs.red2) s_CurRGB.red++;
else if(s_CurRGB.red>s_RGBs.red2) s_CurRGB.red--;
counter=0;
}
counter++;
}
else
{
if(s_CurRGB.red<s_RGBs.red2) s_CurRGB.red++;
else if(s_CurRGB.red>s_RGBs.red2) s_CurRGB.red--;
}
if(s_CurRGB.blue<=SLOWLIMIT)
{
static int counter=0;
if(counter==SLOWTIMES)
{
if(s_CurRGB.blue<s_RGBs.blue2) s_CurRGB.blue++;
else if(s_CurRGB.blue>s_RGBs.blue2) s_CurRGB.blue--;
counter=0;
}
counter++;
}
else
{
if(s_CurRGB.blue<s_RGBs.blue2) s_CurRGB.blue++;
else if(s_CurRGB.blue>s_RGBs.blue2) s_CurRGB.blue--;
}
if(s_CurRGB.green<=SLOWLIMIT)
{
static int counter=0;
if(counter==SLOWTIMES)
{
if(s_CurRGB.green<s_RGBs.green2) s_CurRGB.green++;
else if(s_CurRGB.green>s_RGBs.green2) s_CurRGB.green--;
counter=0;
}
counter++;
}
else
{
if(s_CurRGB.green<s_RGBs.green2) s_CurRGB.green++;
else if(s_CurRGB.green>s_RGBs.green2) s_CurRGB.green--;
}*/
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
/*static int i=0,minR=255,minG=255,minB=255,maxR=0,maxG=0,maxB=0;
minR=s_CurRGB.red<minR?s_CurRGB.red:minR;
minG=s_CurRGB.green<minG?s_CurRGB.green:minG;
minB=s_CurRGB.blue<minB?s_CurRGB.blue:minB;
maxR=s_CurRGB.red>maxR?s_CurRGB.red:maxR;
maxG=s_CurRGB.green>maxG?s_CurRGB.green:maxG;
maxB=s_CurRGB.blue>maxB?s_CurRGB.blue:maxB;
static int dwLastTime=0;
i=(i+1) % 100;
if(i==0)
{
CLog::DebugLog("AmbiTime: %i minR%i G%i B%i maxR%i G%i B%i",timeGetTime()-dwLastTime,minR,minG,minB,maxR,maxG,maxB);
dwLastTime=timeGetTime();
minR=minG=minB=255;
maxR=maxG=maxB=0;
}*/
}
else
{
strLastTransition = "blink";
if(dwFrameTime >= s_RGBs.iTime )
{
s_CurRGB.red = (s_CurRGB.red != s_RGBs.red1) ? s_RGBs.red1 : s_RGBs.red2;
s_CurRGB.green = (s_CurRGB.green != s_RGBs.green1) ? s_RGBs.green1 : s_RGBs.green2;
s_CurRGB.blue = (s_CurRGB.blue != s_RGBs.blue1) ? s_RGBs.blue1 : s_RGBs.blue2;
s_CurRGB.white= (s_CurRGB.white != s_RGBs.white1) ? s_RGBs.white1 : s_RGBs.white2;
dwLastTime = timeGetTime();
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
strLastTransition = "reset";
}
else if(s_RGBs.strTransition.Equals("fade") || s_RGBs.strTransition.Equals("fadeloop") || s_RGBs.strTransition.Equals("faderepeat"))
{
static double distanceR,distanceG,distanceB,distanceW;
}
/*else if(s_RGBs.strTransition.Equals("firework"))
{
static double distanceR,distanceG,distanceB,distanceW;
static double logScaleR,logScaleG,logScaleB,logScaleW;
static int counter;
if(!strLastTransition.Equals("fade"))
{
distanceR = bRepeat ? s_RGBs.red1-s_RGBs.red2 : s_RGBs.red2-s_RGBs.red1;
distanceG = bRepeat ? s_RGBs.green1-s_RGBs.green2 : s_RGBs.green2-s_RGBs.green1;
distanceB = bRepeat ? s_RGBs.blue1-s_RGBs.blue2 : s_RGBs.blue2-s_RGBs.blue1;
distanceW = bRepeat ? s_RGBs.white1-s_RGBs.white2 : s_RGBs.white2-s_RGBs.white1;
if(!strLastTransition.Equals("firework"))
{
counter=0;
strLastTransition="reset";
}
strLastTransition = "fade";
if(strLastTransition.Equals("reset"))
{
distanceR = s_RGBs.red1-s_RGBs.red2;
distanceG = s_RGBs.green1-s_RGBs.green2;
distanceB = s_RGBs.blue1-s_RGBs.blue2;
distanceW = s_RGBs.white1-s_RGBs.white2;
if(s_RGBs.strTransition.Equals("faderepeat"))bRepeat=!bRepeat;
}
logScaleR = 127/log(distanceR);
logScaleG = 127/log(distanceG);
logScaleB = 127/log(distanceB);
logScaleW = 127/log(distanceW);
if(dwFrameTime <= s_RGBs.iTime )
{
double stepR=distanceR/s_RGBs.iTime*dwFrameTime;
double stepG=distanceG/s_RGBs.iTime*dwFrameTime;
double stepB=distanceB/s_RGBs.iTime*dwFrameTime;
double stepW=distanceW/s_RGBs.iTime*dwFrameTime;
counter++;
}
s_CurRGB.red=(bRepeat ? s_RGBs.red1 : s_RGBs.red2) +(int)stepR;
s_CurRGB.green=(bRepeat ? s_RGBs.green1 : s_RGBs.green2)+(int)stepG;
s_CurRGB.blue=(bRepeat ? s_RGBs.blue1 : s_RGBs.blue2)+(int)stepB;
s_CurRGB.white=(bRepeat ? s_RGBs.white1 : s_RGBs.white2)+(int)stepW;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
else if(s_RGBs.strTransition.Equals("fadeloop") || s_RGBs.strTransition.Equals("faderepeat"))
{
strLastTransition="none";
dwFrameTime = 0;
dwLastTime = timeGetTime();
}
}
Sleep(10);
}
if(counter<=3)
{
if(dwFrameTime <= s_RGBs.iTime )
{
double stepR=log(distanceR/s_RGBs.iTime*dwFrameTime)*logScaleR*-1;
double stepG=log(distanceG/s_RGBs.iTime*dwFrameTime)*logScaleG*-1;
double stepB=log(distanceB/s_RGBs.iTime*dwFrameTime)*logScaleB*-1;
double stepW=log(distanceW/s_RGBs.iTime*dwFrameTime)*logScaleW*-1;
s_CurRGB.red=s_RGBs.red1+(int)stepR;
s_CurRGB.green=s_RGBs.green1+(int)stepG;
s_CurRGB.blue=s_RGBs.blue1+(int)stepB;
s_CurRGB.white=s_RGBs.white1+(int)stepW;
SetRGBLed(s_CurRGB.red,s_CurRGB.green,s_CurRGB.blue,s_CurRGB.white);
}
else
{
SetRGBLed(0,0,0,s_CurRGB.white);
Sleep(200);
strLastTransition="reset";
dwLastTime = timeGetTime();
}
}
}*/
}
for(int i=0;i<10;i++)
Sleep(1);
}
}
void ILEDSmartxxRGB::OnExit()
{
SetRGBLed(0,0,0,0xb); //r=0,g=0,b=0 w=0xb (Status LED ON)
// this can also be called when navigationg in the XBMC while a movie runs in background.
// when in menu it can happen that parallel to AmbiLight PWMControl will be started. In that
// case we want AmbiLight to stay on and so the ambilight will stop the rgb-thread. To avoid
// flashing of LEDs in this case we don't turn them off.
if(!AmbiLightParams.AmbiLightIsPlaying)
{
SetRGBLed(0,0,0,0xb); //r=0,g=0,b=0 w=0xb (Status LED ON)
// SmartXX OPX port for RGB-Red is the same port for display brightness control
// Restoring brightness value from the settings
if ( g_sysinfo.SmartXXModCHIP().Equals("SmartXX OPX") )
g_lcd->SetBackLight(g_guiSettings.GetInt("lcd.backlight"));
// SmartXX OPX port for RGB-Red is the same port for display brightness control
// Restoring brightness value from the settings
if ( g_sysinfo.SmartXXModCHIP().Equals("SmartXX OPX") )
g_lcd->SetBackLight(g_guiSettings.GetInt("lcd.backlight"));
CLog::Log(LOGDEBUG,"Stopping SmartXX RGB LED thread");
CLog::Log(LOGDEBUG,"Stopping SmartXX RGB LED thread");
}
}
bool ILEDSmartxxRGB::Start()
{
if (g_sysinfo.SmartXXModCHIP().Equals("SmartXX V3") || g_sysinfo.SmartXXModCHIP().Equals("SmartXX OPX"))
{
if ((g_sysinfo.SmartXXModCHIP().Equals("SmartXX V3") || g_sysinfo.SmartXXModCHIP().Equals("SmartXX OPX"))) // && !AmbiLightParams.AmbiLightIsPlaying && !isPaused)
{
Create();
return true;
}
......
StopThread();
}
bool ILEDSmartxxRGB::IsRunning()
{
{
return (m_ThreadHandle != NULL);
}
void ILEDSmartxxRGB::Pause()
{
//isPaused=true;
}
void ILEDSmartxxRGB::Continue()
{
if(isPaused)
dwLastTime=timeGetTime();
isPaused=false;
}
bool ILEDSmartxxRGB::IsPaused()
{
return isPaused;
}
void ILEDSmartxxRGB::getRGBValues(const CStdString &strRGBa, const CStdString &strRGBb, const CStdString &strWhiteA, const CStdString &strWhiteB, RGBVALUES* s_rgb)
{
DWORD red=0,green=0,blue=0,white=0;
DWORD red=0,green=0,blue=0,white=0;
int ret = sscanf(strRGBa,"#%2X%2X%2X",&red,&green,&blue);
if(ret == 3)
{
s_rgb->red1 = int(red/2);
s_rgb->green1 = int(green/2);
s_rgb->blue1 = int(blue/2);
}
else
{
s_rgb->red1 = 0;
s_rgb->green1 = 0;
s_rgb->blue1 = 0;
}
if(ret == 3)
{
s_rgb->red1 = int(red/2);
s_rgb->green1 = int(green/2);
s_rgb->blue1 = int(blue/2);
}
else
{
s_rgb->red1 = 0;
s_rgb->green1 = 0;
s_rgb->blue1 = 0;
}
ret = sscanf(strRGBb,"#%2X%2X%2X",&red,&green,&blue);
if(ret == 3)
{
s_rgb->red2 = int(red/2);
s_rgb->green2 = int(green/2);
s_rgb->blue2 = int(blue/2);
}
else
{
s_rgb->red2 = 0;
s_rgb->green2 = 0;
s_rgb->blue2 = 0;
}
ret = sscanf(strRGBb,"#%2X%2X%2X",&red,&green,&blue);
if(ret == 3)
{
s_rgb->red2 = int(red/2);
s_rgb->green2 = int(green/2);
s_rgb->blue2 = int(blue/2);
}
else
{
s_rgb->red2 = 0;
s_rgb->green2 = 0;
s_rgb->blue2 = 0;
}
ret = sscanf(strWhiteA,"#%2X",&white);
if(ret == 1)
{
if(ret == 1)
{
s_rgb->white1 = int(white/2);
}
else
{
}
else
{
s_rgb->white1 = 0;
}
}
ret = sscanf(strWhiteB,"#%2X",&white);
if(ret == 1)
{
if(ret == 1)
{
s_rgb->white2 = int(white/2);
}
else
{
}
else
{
s_rgb->white2 = 0;
}
}
}
bool ILEDSmartxxRGB::SetRGBStatus(const CStdString &strStatus)
......
bool ILEDSmartxxRGB::SetRGBLed(int red, int green, int blue, int white)
{
static oldR=0,oldG=0,oldB=0;
if(abs(oldR-red)>1)
CLog::DebugLog("RSkipAmbilight");
if(abs(oldG-green)>1)
CLog::DebugLog("GSkipAmbilight");
if(abs(oldB-blue)>1)
CLog::DebugLog("BSkipAmbilight");
oldR=red;
oldG=green;
oldB=blue;
red=CLAMP(red/2,0,127);
green=CLAMP(green/2,0,127);
blue=CLAMP(blue/2,0,127);
_outp( g_sysinfo.SmartXXModCHIP().Equals("SmartXX V3") ? SMARTXX_PWD_RED:SMARTXX_OPX_PWD_RED, red);
_outp( g_sysinfo.SmartXXModCHIP().Equals("SmartXX V3") ? SMARTXX_PWD_GREEN:SMARTXX_OPX_PWD_GREEN, green);
_outp( g_sysinfo.SmartXXModCHIP().Equals("SmartXX V3") ? SMARTXX_PWD_BLUE:SMARTXX_OPX_PWD_BLUE, blue);
_outp( SMARTXX_PWM_STATUS, white);
return true;
......
return SetRGBStatus(strTransition);
}
bool ILEDSmartxxRGB::SetRGBState(tRGBColor rgb)
{
// we have a new request: start reset
strCurrentStatus = "NULL";
strLastStatus = "NULL";
strLastTransition = "NULL";
s_RGBs.strTransition = "NULL";
// is used to identify first frame in blink-mode, 0 is not usable to do this check as zero is
// a valid value for a color
s_RGBs.strTransition = "fade2";
s_RGBs.red2 =rgb.r;
s_RGBs.green2 =rgb.g;
s_RGBs.blue2 =rgb.b;
/*s_RGBs.red1 =s_CurRGB.red;
s_RGBs.green1 =s_CurRGB.green;
s_RGBs.blue1 =s_CurRGB.blue ;*/
//dwFrameTime = 0;
//dwLastTime = timeGetTime();
bRepeat = false;
// end reset
SetRGBStatus(s_RGBs.strTransition);
if(!IsRunning())
Start();
return true;
}
void ILEDSmartxxRGB::AmbiLightUpdateFrameNumber()
{
// only do this, if ambilight is enabled...
if(g_advancedSettings.m_ambiLight && AmbiLightParams.AmbiLightIsPlaying)
{
AmbiLightParams.recentFrame=(AmbiLightParams.recentFrame+1) % g_advancedSettings.m_ambiLightFloatingAverageFrames;
AmbiLightParams.frameHasChanged=true;
}
}
void ILEDSmartxxRGB::AmbiLightSetAverageColor(unsigned int H,unsigned int S,unsigned int V)
{
// this function is called after we've gotten the average color of the recent frame. It then shifts
// the array containing the values of our FloatingAverageArray (if enabled) to push out the oldest value and
// insert these new values at the beginning (FIFO).
// first copy AmbiLightParams to local var for better handling...
AMBILIGHT &params=AmbiLightParams;
// also copy our FloatingAverageFrames-var to local var...
unsigned int FloatingAverageFrames=g_advancedSettings.m_ambiLightFloatingAverageFrames;
// when mode is linear, then the oldest frame in our floating average counts once, the frame after that counts twice,
// the frame after that thrice and so on...
/*if(g_advancedSettings.m_ambiLightMode=="linear")
{
// in this case the sums have to be recalculated from zero...
params.sumR=0;
params.sumG=0;
params.sumB=0;
// recalculate RGB arrays, starting with the now oldest frame...
// if we have a framenumber of 5 at the moment and FloatingAverageFrames of 10
// then the first index is 5 which is the 6th field in the array, which takes now
// the oldest value...
for(unsigned int i=1;i<FloatingAverageFrames;i++)
{
unsigned int index=(i+params.recentFrame) % (FloatingAverageFrames);
// divide by its old weight, then multiply with its new weight which just became decreased by one...
params.arrR[index]=(params.arrR[index]/(i+1))*i;
params.arrG[index]=(params.arrG[index]/(i+1))*i;
params.arrB[index]=(params.arrB[index]/(i+1))*i;
// also update the sums...
params.sumR+=params.arrR[index];
params.sumG+=params.arrG[index];
params.sumB+=params.arrB[index];
}
// at last we update the array-field that takes the values of the recent frame times the FloatingAverageFrames
// (because the recent frame has the heighest weight which is FloatingAverageFrames)...
params.arrR[params.recentFrame]=R*(FloatingAverageFrames);
params.arrG[params.recentFrame]=G*(FloatingAverageFrames);
params.arrB[params.recentFrame]=B*(FloatingAverageFrames);
// a last update to our sums...
params.sumR+=params.arrR[params.recentFrame];
params.sumG+=params.arrG[params.recentFrame];
params.sumB+=params.arrB[params.recentFrame];
}
else*/
{
// if we donot calc linear, each frame of our floatingAverageFrames has the same weight, so calculation is easy...
// the sum gets substracted the old value and added the new value...
//params.sumH+=H-params.arrH[params.recentFrame];
//params.sumS+=S-params.arrS[params.recentFrame];
//params.sumV+=V-params.arrV[params.recentFrame];
//// the corresponding array-value gets overwritten...
//params.arrH[params.recentFrame]=H;
//params.arrS[params.recentFrame]=S;
//params.arrV[params.recentFrame]=V;
}
}
void ILEDSmartxxRGB::AmbiLightStop()
{
if(g_advancedSettings.m_ambiLight)
{
CLog::Log(LOGDEBUG,"AmbiLight is stopping...");
AmbiLightParams.AmbiLightIsPlaying=false;
OnExit();
Continue();
}
}
void ILEDSmartxxRGB::AmbiLightRGBSet()
{
AMBILIGHT &params=AmbiLightParams;
//necessary vars...
tHSVColor hsv;
tRGBColor rgb;
tHSVHistogramm hsvHisto;
// Initialize hsv-Color...
hsv.h=0;
hsv.s=0;
hsv.v=0;
// emptying the temporary histogram...
for(int i=0;i<=360;i++)
hsvHisto.h[i]=0;
for(int i=0;i<=100;i++) {
hsvHisto.s[i]=0;
hsvHisto.v[i]=0; }
//create the histogramm of the hue-channel...
for(int i=0;i<(int)params.PixelCount;i++)
hsvHisto.h[params.hsvMatrix[i].h]++;
int sumH=0,oldSumH=0;
//now find the window, with the most hue...
for(int i=0;i<HUE_WINDOW;i++)
sumH+=hsvHisto.h[i];
for(int i=0;i<=360-HUE_WINDOW;i++)
{
sumH=sumH-hsvHisto.h[i]+hsvHisto.h[i+HUE_WINDOW];
if(sumH>oldSumH)
{
oldSumH=sumH;
hsv.h=i+1;
}
}
//now find the max inside our window...
int maxH=hsv.h;
for(int i=hsv.h+1;i<hsv.h+HUE_WINDOW;i++)
maxH = hsvHisto.h[i]>hsvHisto.h[maxH]?i:maxH;
hsv.h=maxH;
//window limits for saturation histogram...
int iMin=CLAMP(hsv.h-WINDOW_SIZE,0,360);
int iMax=CLAMP(hsv.h+WINDOW_SIZE,0,360);
//now we count all pixels around the
int relevantPixelCount=0;
for(int i=iMin;i<=iMax;i++)
relevantPixelCount+=hsvHisto.h[i];
// nur wenn die Anzahl der f?r das Maximum relevanten Pixel eine Fl?che einnimmt die gr??er als die Vorgegebene
// Minimalgr??e ist wird die Saturation und der Value berechnet (ohne die bleibt die Farbe schwarz)...
if(relevantPixelCount*(g_advancedSettings.m_ambiLightSpaceBetweenPixels+1)>=PIXEL_AMOUNT*MIN_PERCENTAGE/100)
{
//Saturation Histogramm
for(int i=0;i<(int)params.PixelCount;i++)
{
if(params.hsvMatrix[i].h>=iMin && params.hsvMatrix[i].h<=iMax)
hsvHisto.s[params.hsvMatrix[i].s]++;
}
//Max Saturation
for(int i=0;i<=100;i++)
hsv.s=hsvHisto.s[i]>hsvHisto.s[hsv.s] ? i : hsv.s;
//Value Average
int sumV=0;
for(int i=0;i<(int)params.PixelCount;i++)
sumV+=params.hsvMatrix[i].v;
if(params.PixelCount>0)
hsv.v=sumV/params.PixelCount;
}
rgb=HSV2RGB(hsv);
// now we take the power of gamma for each RGB-value and use our scale-factor to form an valid RGB-value...
// this gamma factor is an simple way to control how fast a LED turns bright especially in lower values. if in dark
// passages you always have blue light try an gamme value below 1 so blue will have a lower gamma curve. On the other
// hand you could pass Red and green a gamma above 1, common value would be e.g. gammaR=2.2, gammeG=2.0, gammaB=0.8
// (as blue often seems to be the brightest LED).
rgb.r=(int)(pow((float)rgb.r,params.gammaR)*params.gammaScaleR);
rgb.g=(int)(pow((float)rgb.g,params.gammaG)*params.gammaScaleG);
rgb.b=(int)(pow((float)rgb.b,params.gammaB)*params.gammaScaleB);
rgb.r=CLAMP(rgb.r,g_advancedSettings.m_ambiLightMinRGB,g_advancedSettings.m_ambiLightMaxRGB);
rgb.g=CLAMP(rgb.g,g_advancedSettings.m_ambiLightMinRGB,g_advancedSettings.m_ambiLightMaxRGB);
rgb.b=CLAMP(rgb.b,g_advancedSettings.m_ambiLightMinRGB,g_advancedSettings.m_ambiLightMaxRGB);
// our values get passed to the SmartXX...
SetRGBState(rgb);
//SetRGBLed(rgb.r,rgb.g,rgb.b,0);
}
void ILEDSmartxxRGB::AmbiLightParamsInit(unsigned int SourceWidth,unsigned int SourceHeight,YUVCOEF yuvcoef,YUVRANGE yuvrange)
{
AMBILIGHT &params=AmbiLightParams;
if(g_advancedSettings.m_ambiLight==true)
{
CLog::Log(LOGDEBUG,"AmbiLight is initializing...");
s_CurRGB.red=2;
s_CurRGB.green=2;
s_CurRGB.blue=2;
params.AmbiLightIsPlaying=true;
// here we initialize our Params, it's always called, when a new movie starts...
params.frameHasChanged = false;
params.recentFrame = 0;
params.SourceWidth=SourceWidth;
params.SourceHeight=SourceHeight;
params.yuvcoef=yuvcoef;
params.yuvrange=yuvrange;
params.PixelCount=0;
params.RowCount=0;
params.PixelOverflow=0;
params.R=0;
params.G=0;
params.B=0;
params.hsvMatrix=new tHSVColor[92161];
//memset(&params.hsvMatrix,0,sizeof(params.hsvMatrix)*92161);
if(params.arrH==NULL)
{
params.hsvh=new tHSVHistogramm[g_advancedSettings.m_ambiLightFloatingAverageFrames];
params.arrH=new unsigned int[g_advancedSettings.m_ambiLightFloatingAverageFrames];
params.arrS=new unsigned int[g_advancedSettings.m_ambiLightFloatingAverageFrames];
params.arrV=new unsigned int[g_advancedSettings.m_ambiLightFloatingAverageFrames];
}
//initialize Array...
for(int i=0;i<g_advancedSettings.m_ambiLightFloatingAverageFrames;i++)
{
for(int j=0;j<=360;j++)
params.hsvh[i].h[j]=0;
for(int j=0;j<=100;j++)
{
params.hsvh[i].s[j]=0;
params.hsvh[i].v[j]=0;
}
params.arrH[i]=0; //g_advancedSettings.m_ambiLightMinRGB;
params.arrS[i]=0; //g_advancedSettings.m_ambiLightMinRGB;
params.arrV[i]=0; //g_advancedSettings.m_ambiLightMinRGB;
}
/*params.sumH=0;
params.sumS=0;
params.sumV=0;*/
params.gammaR=1/g_advancedSettings.m_ambiLightGammaR;
params.gammaG=1/g_advancedSettings.m_ambiLightGammaG;
params.gammaB=1/g_advancedSettings.m_ambiLightGammaB;
params.gammaScaleR=255/pow(255.0f,params.gammaR);
params.gammaScaleG=255/pow(255.0f,params.gammaG);
params.gammaScaleB=255/pow(255.0f,params.gammaB);
}
}
void ILEDSmartxxRGB::AmbiLightUpdate()
{
AMBILIGHT &params=AmbiLightParams;
// when the frame has changed...
if(params.frameHasChanged)
{
// and we have checked more than 0 pixels...
//if(params.PixelCount>0)
{
//static unsigned int oldR=0,oldG=0,oldB=0;
// then we calculate the average of the last frame...
//unsigned int R=(unsigned int)(params.R/params.PixelCount);
//unsigned int G=(unsigned int)(params.G/params.PixelCount);
//unsigned int B=(unsigned int)(params.B/params.PixelCount);
// check, whether we have a skip (e.g. a new scene or st.)
//AmbiLightCheckSkip(oldR,oldG,oldB,R,G,B);
//oldR=R;oldG=G;oldB=B;
// pass it to SetAverageColor...
//AmbiLightSetAverageColor(R,G,B);
// and push it onto the SmartXX...
AmbiLightRGBSet();
}
// then the RGB-values get zeroed for a fresh start in this new frame...
params.R=0;
params.G=0;
params.B=0;
//memset(&params.hsvMatrix,0,sizeof(params.hsvMatrix)*92161);
// the counter is reset...
params.PixelCount=0;
// a new startposition for Pixeloverflow is calculated...
//params.PixelOverflow=g_advancedSettings.m_ambiLightSpaceBetweenPixels*params.recentFrame;
// and FrameChange Property...
params.frameHasChanged = false;
// and RowCount is reset...
params.RowCount=0;
}
}
void ILEDSmartxxRGB::AmbiLightCheckSkip(unsigned int oldR,unsigned int oldG,unsigned int oldB,unsigned int newR,unsigned int newG,unsigned int newB)
{
/*AMBILIGHT &params=AmbiLightParams;
int skipR=oldR-newR;
int skipG=oldG-newG;
int skipB=oldB-newB;
if(skipR<0) skipR*=-1;
if(skipG<0) skipG*=-1;
if(skipB<0) skipB*=-1;
if((skipR+skipG+skipB)>g_advancedSettings.m_ambiLightFilterThreshold*3)
{
for(int i=0;i<g_advancedSettings.m_ambiLightFloatingAverageFrames;i++)
{
params.arrR[i]=newR;
params.arrG[i]=newG;
params.arrB[i]=newB;
}
params.sumR=newR*g_advancedSettings.m_ambiLightFloatingAverageFrames;
params.sumG=newG*g_advancedSettings.m_ambiLightFloatingAverageFrames;
params.sumB=newB*g_advancedSettings.m_ambiLightFloatingAverageFrames;
}*/
}
void ILEDSmartxxRGB::AmbiLightParamsUpdate(int x,int w,int widthRatio)
{
// set values
AmbiLightParams.x = x;
AmbiLightParams.w = w;
AmbiLightParams.WidthRatio = widthRatio;
}
void ILEDSmartxxRGB::AmbiLightRGBCalculate(BYTE *s0,BYTE *s1,BYTE *s2)
{
// copy our ambilight params for easier handling...
AMBILIGHT &params=AmbiLightParams;
CStdString position=g_advancedSettings.m_ambiLightPosition.ToLower();
// here we make sure, we're in the right row of pixels. If we only want to interpret the bottom half,
// but are in the first pixel row, do nothing...
if((position=="top" && params.RowCount<params.SourceHeight/2) || (position=="bottom" && params.RowCount>=params.SourceHeight/2) || position=="left" || position=="right" || position=="all")
{
// these vars take the x-value from where to start getting pixels and the width. e.g. if you only want to interpret
// the left area of the screen, then StartX equals zero and EndX equals StartX+resolutionwidth/2
// these are always recalulated as x and w might change during different YUV-chunks...
unsigned int StartX;
unsigned int EndX;
// here we set StartX and EndW for different modes...
if(position=="left")
{
... This diff was truncated because it exceeds the maximum size that can be displayed.
(4-4/7)