Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvdplayer: drop autocrop #6154

Merged
merged 1 commit into from Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions xbmc/cores/VideoRenderers/BaseRenderer.cpp
Expand Up @@ -301,8 +301,8 @@ RESOLUTION CBaseRenderer::GetResolution() const

float CBaseRenderer::GetAspectRatio() const
{
float width = (float)m_sourceWidth - CMediaSettings::Get().GetCurrentVideoSettings().m_CropLeft - CMediaSettings::Get().GetCurrentVideoSettings().m_CropRight;
float height = (float)m_sourceHeight - CMediaSettings::Get().GetCurrentVideoSettings().m_CropTop - CMediaSettings::Get().GetCurrentVideoSettings().m_CropBottom;
float width = (float)m_sourceWidth;
float height = (float)m_sourceHeight;
return m_sourceFrameRatio * width / height * m_sourceHeight / m_sourceWidth;
}

Expand Down Expand Up @@ -614,11 +614,6 @@ void CBaseRenderer::ManageDisplay()
break;
}

m_sourceRect.x1 += (float)CMediaSettings::Get().GetCurrentVideoSettings().m_CropLeft;
m_sourceRect.y1 += (float)CMediaSettings::Get().GetCurrentVideoSettings().m_CropTop;
m_sourceRect.x2 -= (float)CMediaSettings::Get().GetCurrentVideoSettings().m_CropRight;
m_sourceRect.y2 -= (float)CMediaSettings::Get().GetCurrentVideoSettings().m_CropBottom;

CalcNormalDisplayRect(view.x1, view.y1, view.Width(), view.Height(), GetAspectRatio() * CDisplaySettings::Get().GetPixelRatio(), CDisplaySettings::Get().GetZoomAmount(), CDisplaySettings::Get().GetVerticalShift());
}

Expand Down Expand Up @@ -719,7 +714,7 @@ void CBaseRenderer::SetViewMode(int viewMode)
newHeight = screenHeight;
}
// now work out the zoom amount so that no zoom is done
CDisplaySettings::Get().SetZoomAmount((m_sourceHeight - CMediaSettings::Get().GetCurrentVideoSettings().m_CropTop - CMediaSettings::Get().GetCurrentVideoSettings().m_CropBottom) / newHeight);
CDisplaySettings::Get().SetZoomAmount(m_sourceHeight / newHeight);
}
else if (CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode == ViewModeCustom)
{
Expand Down
1 change: 0 additions & 1 deletion xbmc/cores/VideoRenderers/LinuxRendererGL.cpp
Expand Up @@ -3287,7 +3287,6 @@ bool CLinuxRendererGL::Supports(ERENDERFEATURE feature)
}

if (feature == RENDERFEATURE_STRETCH ||
feature == RENDERFEATURE_CROP ||
feature == RENDERFEATURE_ZOOM ||
feature == RENDERFEATURE_VERTICAL_SHIFT ||
feature == RENDERFEATURE_PIXEL_RATIO ||
Expand Down
1 change: 0 additions & 1 deletion xbmc/cores/VideoRenderers/LinuxRendererGLES.cpp
Expand Up @@ -2817,7 +2817,6 @@ bool CLinuxRendererGLES::Supports(ERENDERFEATURE feature)
return false;

if (feature == RENDERFEATURE_STRETCH ||
feature == RENDERFEATURE_CROP ||
feature == RENDERFEATURE_ZOOM ||
feature == RENDERFEATURE_VERTICAL_SHIFT ||
feature == RENDERFEATURE_PIXEL_RATIO ||
Expand Down
1 change: 0 additions & 1 deletion xbmc/cores/VideoRenderers/RenderFeatures.h
Expand Up @@ -31,7 +31,6 @@ enum ERENDERFEATURE
RENDERFEATURE_NONLINSTRETCH,
RENDERFEATURE_ROTATION,
RENDERFEATURE_STRETCH,
RENDERFEATURE_CROP,
RENDERFEATURE_ZOOM,
RENDERFEATURE_VERTICAL_SHIFT,
RENDERFEATURE_PIXEL_RATIO,
Expand Down
1 change: 0 additions & 1 deletion xbmc/cores/VideoRenderers/WinRenderer.cpp
Expand Up @@ -1265,7 +1265,6 @@ bool CWinRenderer::Supports(ERENDERFEATURE feature)

if (feature == RENDERFEATURE_STRETCH ||
feature == RENDERFEATURE_NONLINSTRETCH ||
feature == RENDERFEATURE_CROP ||
feature == RENDERFEATURE_ZOOM ||
feature == RENDERFEATURE_VERTICAL_SHIFT ||
feature == RENDERFEATURE_PIXEL_RATIO ||
Expand Down
178 changes: 0 additions & 178 deletions xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
Expand Up @@ -1159,8 +1159,6 @@ int CDVDPlayerVideo::OutputPicture(const DVDVideoPicture* src, double pts)
mDisplayField = FS_BOT;
}

AutoCrop(pPicture);

int buffer = g_renderManager.WaitForBuffer(m_bStop, std::max(DVD_TIME_TO_MSEC(iSleepTime) + 500, 1));
if (buffer < 0)
return EOS_DROPPED;
Expand Down Expand Up @@ -1189,182 +1187,6 @@ int CDVDPlayerVideo::OutputPicture(const DVDVideoPicture* src, double pts)
#endif
}

void CDVDPlayerVideo::AutoCrop(DVDVideoPicture *pPicture)
{
if ((pPicture->format == RENDER_FMT_YUV420P) ||
(pPicture->format == RENDER_FMT_NV12) ||
(pPicture->format == RENDER_FMT_YUYV422) ||
(pPicture->format == RENDER_FMT_UYVY422))
{
RECT crop;

if (CMediaSettings::Get().GetCurrentVideoSettings().m_Crop)
AutoCrop(pPicture, crop);
else
{ // reset to defaults
crop.left = 0;
crop.right = 0;
crop.top = 0;
crop.bottom = 0;
}

m_crop.x1 += ((float)crop.left - m_crop.x1) * 0.1;
m_crop.x2 += ((float)crop.right - m_crop.x2) * 0.1;
m_crop.y1 += ((float)crop.top - m_crop.y1) * 0.1;
m_crop.y2 += ((float)crop.bottom - m_crop.y2) * 0.1;

crop.left = MathUtils::round_int(m_crop.x1);
crop.right = MathUtils::round_int(m_crop.x2);
crop.top = MathUtils::round_int(m_crop.y1);
crop.bottom = MathUtils::round_int(m_crop.y2);

//compare with hysteresis
# define HYST(n, o) ((n) > (o) || (n) + 1 < (o))
if(HYST(CMediaSettings::Get().GetCurrentVideoSettings().m_CropLeft , crop.left)
|| HYST(CMediaSettings::Get().GetCurrentVideoSettings().m_CropRight , crop.right)
|| HYST(CMediaSettings::Get().GetCurrentVideoSettings().m_CropTop , crop.top)
|| HYST(CMediaSettings::Get().GetCurrentVideoSettings().m_CropBottom, crop.bottom))
{
CMediaSettings::Get().GetCurrentVideoSettings().m_CropLeft = crop.left;
CMediaSettings::Get().GetCurrentVideoSettings().m_CropRight = crop.right;
CMediaSettings::Get().GetCurrentVideoSettings().m_CropTop = crop.top;
CMediaSettings::Get().GetCurrentVideoSettings().m_CropBottom = crop.bottom;
g_renderManager.SetViewMode(CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode);
}
# undef HYST
}
}

void CDVDPlayerVideo::AutoCrop(DVDVideoPicture *pPicture, RECT &crop)
{
crop.left = CMediaSettings::Get().GetCurrentVideoSettings().m_CropLeft;
crop.right = CMediaSettings::Get().GetCurrentVideoSettings().m_CropRight;
crop.top = CMediaSettings::Get().GetCurrentVideoSettings().m_CropTop;
crop.bottom = CMediaSettings::Get().GetCurrentVideoSettings().m_CropBottom;

int black = 16; // what is black in the image
int level = 8; // how high above this should we detect
int multi = 4; // what multiple of last line should failing line be to accept
uint8_t *s;
int last, detect, black2;

// top and bottom levels
black2 = black * pPicture->iWidth;
detect = level * pPicture->iWidth + black2;

//YV12 and NV12 have planar Y plane
//YUY2 and UYVY have Y packed with U and V
int xspacing = 1;
int xstart = 0;
if (pPicture->format == RENDER_FMT_YUYV422)
xspacing = 2;
else if (pPicture->format == RENDER_FMT_UYVY422)
{
xspacing = 2;
xstart = 1;
}

// Crop top
s = pPicture->data[0];
last = black2;
for (unsigned int y = 0; y < pPicture->iHeight/2; y++)
{
int total = 0;
for (unsigned int x = xstart; x < pPicture->iWidth * xspacing; x += xspacing)
total += s[x];
s += pPicture->iLineSize[0];

if (total > detect)
{
if (total - black2 > (last - black2) * multi)
crop.top = y;
break;
}
last = total;
}

// Crop bottom
s = pPicture->data[0] + (pPicture->iHeight-1) * pPicture->iLineSize[0];
last = black2;
for (unsigned int y = (int)pPicture->iHeight; y > pPicture->iHeight/2; y--)
{
int total = 0;
for (unsigned int x = xstart; x < pPicture->iWidth * xspacing; x += xspacing)
total += s[x];
s -= pPicture->iLineSize[0];

if (total > detect)
{
if (total - black2 > (last - black2) * multi)
crop.bottom = pPicture->iHeight - y;
break;
}
last = total;
}

// left and right levels
black2 = black * pPicture->iHeight;
detect = level * pPicture->iHeight + black2;


// Crop left
s = pPicture->data[0];
last = black2;
for (unsigned int x = xstart; x < pPicture->iWidth/2*xspacing; x += xspacing)
{
int total = 0;
for (unsigned int y = 0; y < pPicture->iHeight; y++)
total += s[y * pPicture->iLineSize[0]];
s++;
if (total > detect)
{
if (total - black2 > (last - black2) * multi)
crop.left = x / xspacing;
break;
}
last = total;
}

// Crop right
s = pPicture->data[0] + (pPicture->iWidth-1);
last = black2;
for (unsigned int x = (int)pPicture->iWidth*xspacing-1; x > pPicture->iWidth/2*xspacing; x -= xspacing)
{
int total = 0;
for (unsigned int y = 0; y < pPicture->iHeight; y++)
total += s[y * pPicture->iLineSize[0]];
s--;

if (total > detect)
{
if (total - black2 > (last - black2) * multi)
crop.right = pPicture->iWidth - (x / xspacing);
break;
}
last = total;
}

// We always crop equally on each side to get zoom
// effect intead of moving the image. Aslong as the
// max crop isn't much larger than the min crop
// use that.
int min, max;

min = std::min(crop.left, crop.right);
max = std::max(crop.left, crop.right);
if(10 * (max - min) / pPicture->iWidth < 1)
crop.left = crop.right = max;
else
crop.left = crop.right = min;

min = std::min(crop.top, crop.bottom);
max = std::max(crop.top, crop.bottom);
if(10 * (max - min) / pPicture->iHeight < 1)
crop.top = crop.bottom = max;
else
crop.top = crop.bottom = min;
}

std::string CDVDPlayerVideo::GetPlayerInfo()
{
std::ostringstream s;
Expand Down
2 changes: 0 additions & 2 deletions xbmc/settings/MediaSettings.cpp
Expand Up @@ -128,7 +128,6 @@ bool CMediaSettings::Load(const TiXmlNode *settings)
m_defaultVideoSettings.m_AudioDelay = 0.0f;
if (!XMLUtils::GetFloat(pElement, "subtitledelay", m_defaultVideoSettings.m_SubtitleDelay, -10.0f, 10.0f))
m_defaultVideoSettings.m_SubtitleDelay = 0.0f;
XMLUtils::GetBoolean(pElement, "autocrop", m_defaultVideoSettings.m_Crop);
XMLUtils::GetBoolean(pElement, "nonlinstretch", m_defaultVideoSettings.m_CustomNonLinStretch);
if (!XMLUtils::GetInt(pElement, "stereomode", m_defaultVideoSettings.m_StereoMode))
m_defaultVideoSettings.m_StereoMode = 0;
Expand Down Expand Up @@ -213,7 +212,6 @@ bool CMediaSettings::Save(TiXmlNode *settings) const
XMLUtils::SetFloat(pNode, "gamma", m_defaultVideoSettings.m_Gamma);
XMLUtils::SetFloat(pNode, "audiodelay", m_defaultVideoSettings.m_AudioDelay);
XMLUtils::SetFloat(pNode, "subtitledelay", m_defaultVideoSettings.m_SubtitleDelay);
XMLUtils::SetBoolean(pNode, "autocrop", m_defaultVideoSettings.m_Crop);
XMLUtils::SetBoolean(pNode, "nonlinstretch", m_defaultVideoSettings.m_CustomNonLinStretch);
XMLUtils::SetInt(pNode, "stereomode", m_defaultVideoSettings.m_StereoMode);

Expand Down
10 changes: 0 additions & 10 deletions xbmc/settings/VideoSettings.cpp
Expand Up @@ -52,11 +52,6 @@ CVideoSettings::CVideoSettings()
m_AudioDelay = 0.0f;
m_OutputToAllSpeakers = false;
m_ResumeTime = 0;
m_Crop = false;
m_CropTop = 0;
m_CropBottom = 0;
m_CropLeft = 0;
m_CropRight = 0;
}

bool CVideoSettings::operator!=(const CVideoSettings &right) const
Expand Down Expand Up @@ -84,11 +79,6 @@ bool CVideoSettings::operator!=(const CVideoSettings &right) const
if (m_AudioDelay != right.m_AudioDelay) return true;
if (m_OutputToAllSpeakers != right.m_OutputToAllSpeakers) return true;
if (m_ResumeTime != right.m_ResumeTime) return true;
if (m_Crop != right.m_Crop) return true;
if (m_CropTop != right.m_CropTop) return true;
if (m_CropBottom != right.m_CropBottom) return true;
if (m_CropLeft != right.m_CropLeft) return true;
if (m_CropRight != right.m_CropRight) return true;
if (m_StereoMode != right.m_StereoMode) return true;
if (m_StereoInvert != right.m_StereoInvert) return true;
return false;
Expand Down
5 changes: 0 additions & 5 deletions xbmc/settings/VideoSettings.h
Expand Up @@ -148,11 +148,6 @@ class CVideoSettings
float m_Sharpness;
float m_AudioDelay;
int m_ResumeTime;
bool m_Crop;
int m_CropTop;
int m_CropBottom;
int m_CropLeft;
int m_CropRight;
int m_StereoMode;
bool m_StereoInvert;

Expand Down
15 changes: 5 additions & 10 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -95,8 +95,8 @@ void CVideoDatabase::CreateTables()
m_pDS->exec("CREATE TABLE settings ( idFile integer, Deinterlace bool,"
"ViewMode integer,ZoomAmount float, PixelRatio float, VerticalShift float, AudioStream integer, SubtitleStream integer,"
"SubtitleDelay float, SubtitlesOn bool, Brightness float, Contrast float, Gamma float,"
"VolumeAmplification float, AudioDelay float, OutputToAllSpeakers bool, ResumeTime integer, Crop bool, CropLeft integer,"
"CropRight integer, CropTop integer, CropBottom integer, Sharpness float, NoiseReduction float, NonLinStretch bool, PostProcess bool,"
"VolumeAmplification float, AudioDelay float, OutputToAllSpeakers bool, ResumeTime integer,"
"Sharpness float, NoiseReduction float, NonLinStretch bool, PostProcess bool,"
"ScalingMethod integer, DeinterlaceMode integer, StereoMode integer, StereoInvert bool)\n");

CLog::Log(LOGINFO, "create stacktimes table");
Expand Down Expand Up @@ -3713,11 +3713,6 @@ bool CVideoDatabase::GetVideoSettings(const std::string &strFilenameAndPath, CVi
settings.m_SubtitleStream = m_pDS->fv("SubtitleStream").get_asInt();
settings.m_ViewMode = m_pDS->fv("ViewMode").get_asInt();
settings.m_ResumeTime = m_pDS->fv("ResumeTime").get_asInt();
settings.m_Crop = m_pDS->fv("Crop").get_asBool();
settings.m_CropLeft = m_pDS->fv("CropLeft").get_asInt();
settings.m_CropRight = m_pDS->fv("CropRight").get_asInt();
settings.m_CropTop = m_pDS->fv("CropTop").get_asInt();
settings.m_CropBottom = m_pDS->fv("CropBottom").get_asInt();
settings.m_DeinterlaceMode = (EDEINTERLACEMODE)m_pDS->fv("DeinterlaceMode").get_asInt();
settings.m_InterlaceMethod = (EINTERLACEMETHOD)m_pDS->fv("Deinterlace").get_asInt();
settings.m_VolumeAmplification = m_pDS->fv("VolumeAmplification").get_asFloat();
Expand Down Expand Up @@ -3764,7 +3759,7 @@ void CVideoDatabase::SetVideoSettings(const std::string& strFilenameAndPath, con
setting.m_OutputToAllSpeakers,setting.m_Sharpness,setting.m_NoiseReduction,setting.m_CustomNonLinStretch,setting.m_PostProcess,setting.m_ScalingMethod,
setting.m_DeinterlaceMode);
std::string strSQL2;
strSQL2=PrepareSQL("ResumeTime=%i,Crop=%i,CropLeft=%i,CropRight=%i,CropTop=%i,CropBottom=%i,StereoMode=%i,StereoInvert=%i where idFile=%i\n", setting.m_ResumeTime, setting.m_Crop, setting.m_CropLeft, setting.m_CropRight, setting.m_CropTop, setting.m_CropBottom, setting.m_StereoMode, setting.m_StereoInvert, idFile);
strSQL2=PrepareSQL("ResumeTime=%i,StereoMode=%i,StereoInvert=%i where idFile=%i\n", setting.m_ResumeTime, setting.m_StereoMode, setting.m_StereoInvert, idFile);
strSQL += strSQL2;
m_pDS->exec(strSQL.c_str());
return ;
Expand All @@ -3775,14 +3770,14 @@ void CVideoDatabase::SetVideoSettings(const std::string& strFilenameAndPath, con
strSQL= "INSERT INTO settings (idFile,Deinterlace,ViewMode,ZoomAmount,PixelRatio, VerticalShift, "
"AudioStream,SubtitleStream,SubtitleDelay,SubtitlesOn,Brightness,"
"Contrast,Gamma,VolumeAmplification,AudioDelay,OutputToAllSpeakers,"
"ResumeTime,Crop,CropLeft,CropRight,CropTop,CropBottom,"
"ResumeTime,"
"Sharpness,NoiseReduction,NonLinStretch,PostProcess,ScalingMethod,DeinterlaceMode,StereoMode,StereoInvert) "
"VALUES ";
strSQL += PrepareSQL("(%i,%i,%i,%f,%f,%f,%i,%i,%f,%i,%f,%f,%f,%f,%f,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i)",
idFile, setting.m_InterlaceMethod, setting.m_ViewMode, setting.m_CustomZoomAmount, setting.m_CustomPixelRatio, setting.m_CustomVerticalShift,
setting.m_AudioStream, setting.m_SubtitleStream, setting.m_SubtitleDelay, setting.m_SubtitleOn, setting.m_Brightness,
setting.m_Contrast, setting.m_Gamma, setting.m_VolumeAmplification, setting.m_AudioDelay, setting.m_OutputToAllSpeakers,
setting.m_ResumeTime, setting.m_Crop, setting.m_CropLeft, setting.m_CropRight, setting.m_CropTop, setting.m_CropBottom,
setting.m_ResumeTime,
setting.m_Sharpness, setting.m_NoiseReduction, setting.m_CustomNonLinStretch, setting.m_PostProcess, setting.m_ScalingMethod,
setting.m_DeinterlaceMode, setting.m_StereoMode, setting.m_StereoInvert);
m_pDS->exec(strSQL.c_str());
Expand Down
6 changes: 0 additions & 6 deletions xbmc/video/dialogs/GUIDialogVideoSettings.cpp
Expand Up @@ -36,7 +36,6 @@
#include "utils/log.h"
#include "video/VideoDatabase.h"

#define SETTING_VIDEO_CROP "video.crop"
#define SETTING_VIDEO_VIEW_MODE "video.viewmode"
#define SETTING_VIDEO_ZOOM "video.zoom"
#define SETTING_VIDEO_PIXEL_RATIO "video.pixelratio"
Expand Down Expand Up @@ -87,8 +86,6 @@ void CGUIDialogVideoSettings::OnSettingChanged(const CSetting *setting)
else if (settingId == SETTING_VIDEO_SCALINGMETHOD)
videoSettings.m_ScalingMethod = static_cast<ESCALINGMETHOD>(static_cast<const CSettingInt*>(setting)->GetValue());
#ifdef HAS_VIDEO_PLAYBACK
else if (settingId == SETTING_VIDEO_CROP)
videoSettings.m_Crop = static_cast<const CSettingBool*>(setting)->GetValue();
else if (settingId == SETTING_VIDEO_VIEW_MODE)
{
videoSettings.m_ViewMode = static_cast<const CSettingInt*>(setting)->GetValue();
Expand Down Expand Up @@ -318,9 +315,6 @@ void CGUIDialogVideoSettings::InitializeSettings()
AddSpinner(groupVideo, SETTING_VIDEO_SCALINGMETHOD, 16300, 0, static_cast<int>(videoSettings.m_ScalingMethod), entries);

#ifdef HAS_VIDEO_PLAYBACK
if (g_renderManager.Supports(RENDERFEATURE_CROP))
AddToggle(groupVideo, SETTING_VIDEO_CROP, 644, 0, videoSettings.m_Crop);

if (g_renderManager.Supports(RENDERFEATURE_STRETCH) || g_renderManager.Supports(RENDERFEATURE_PIXEL_RATIO))
{
entries.clear();
Expand Down