5 #define LOC QString("DetectLetterbox: ")
32 unsigned char *buf =
Frame->m_buffer;
38 const int height =
Frame->m_height;
45 const int fullLimit =
static_cast<int>((height * (1 - VideoAspect * 9 / 16) / 2) *
m_detectLetterboxLimit / 100);
46 const int halfLimit =
static_cast<int>((height * (1 - VideoAspect * 9 / 14) / 2) *
m_detectLetterboxLimit / 100);
49 const std::array<int,3> xPos {
Frame->m_width / 4,
Frame->m_width / 2,
Frame->m_width * 3 / 4} ;
56 std::array<int,3> topHit = { 0, 0, 0 };
57 std::array<int,3> bottomHit = { 0, 0, 0 };
59 switch (
Frame->m_type)
73 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"'%1' frame format detected")
79 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"'%1' frame format is not supported")
85 if (
Frame->m_frameNumber < 0)
87 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Strange frame number %1").arg(
Frame->m_frameNumber));
91 if (VideoAspect > 1.5F)
95 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"The source is already in widescreen (aspect: %1)")
96 .arg(
static_cast<double>(VideoAspect)));
105 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"The source is already in widescreen (aspect: %1)")
106 .arg(
static_cast<double>(VideoAspect)));
115 averageY += buf[offsets[0] + (5 * pitches[0]) + pos];
116 averageY += buf[offsets[0] + ((height - 6) * pitches[0]) + pos];
126 int leftshift = depth > 8 ? 1 : 0;
127 int rightshift = depth > 8 ? 0 : 1;
130 for (
int y = 5; y < height / 4; y++)
134 int Y = buf[offsets[0] + (y * pitches[0]) + (xPos[detectionLine] << leftshift)];
139 U = buf[offsets[1] + ((y>>1) * pitches[1]) + (xPos[detectionLine] >> rightshift)];
140 V = buf[offsets[2] + ((y>>1) * pitches[2]) + (xPos[detectionLine] >> rightshift)];
144 int offset = offsets[1] + ((y >> 1) * pitches[1]) + (xPos[detectionLine & ~0x1] << leftshift);
146 V = buf[offset + (1 << leftshift)];
149 if ((!topHit[detectionLine]) &&
151 U < 128 - 32 || U > 128 + 32 ||
152 V < 128 - 32 || V > 128 + 32 ))
154 topHit[detectionLine] = y;
161 Y = buf[offsets[0] + ((height-y-1) * pitches[0]) + (xPos[detectionLine] << leftshift)];
164 U = buf[offsets[1] + (((height-y-1) >> 1) * pitches[1]) + (xPos[detectionLine] >> rightshift)];
165 V = buf[offsets[2] + (((height-y-1) >> 1) * pitches[2]) + (xPos[detectionLine] >> rightshift)];
169 int offset = offsets[1] + (((height - y -1) >> 1) * pitches[1]) + (xPos[detectionLine & ~0
x1] << leftshift);
171 V = buf[offset + (1 << leftshift)];
174 if ((!bottomHit[detectionLine]) &&
176 U < 128 - 32 || U > 128 + 32 ||
177 V < 128 - 32 || V > 128 + 32 ))
179 bottomHit[detectionLine] = y;
196 maxBottom = height / 4;
198 minBottom = height / 4;
211 if (minTop < halfLimit || minBottom < halfLimit)
213 if (minTop < fullLimit || minBottom < fullLimit)
230 if (maxTop < halfLimit || maxBottom < halfLimit)
235 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Non Letterbox detected on line: %1 (limit: %2)")
236 .arg(std::min(maxTop, maxBottom)).arg(halfLimit));
246 else if (horizontal && minTop > halfLimit && minBottom > halfLimit &&
247 maxTop < fullLimit && maxBottom < fullLimit)
252 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Narrow Letterbox detected on line: %1 (limit: %2) frame: %3")
270 else if (horizontal && minTop > fullLimit && minBottom > fullLimit)
276 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Detected Letterbox on line: %1 (limit: %2) frame: %3")
300 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Switched to '%1' on frame %2 (%3)")
308 else if (m_detectLetterboxSwitchFrame <= Frame->m_frameNumber)
310 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Not Switched to '%1' on frame %2 "
311 "(%3) Not enough consecutive detections (%4)")