helen mcf bytes per line
From: Mark Spieth <mspieth@digivation.com.au>
---
.../programs/mythcommflag/ClassicCommDetector.cpp | 13 +++----
mythtv/programs/mythcommflag/ClassicCommDetector.h | 2 -
.../programs/mythcommflag/ClassicLogoDetector.cpp | 37 ++++++++++++--------
mythtv/programs/mythcommflag/ClassicLogoDetector.h | 2 +
.../mythcommflag/ClassicSceneChangeDetector.cpp | 2 +
.../mythcommflag/ClassicSceneChangeDetector.h | 2 +
mythtv/programs/mythcommflag/Histogram.cpp | 8 +++-
mythtv/programs/mythcommflag/Histogram.h | 4 ++
mythtv/programs/mythcommflag/LogoDetectorBase.h | 3 +-
.../mythcommflag/SceneChangeDetectorBase.h | 4 ++
10 files changed, 45 insertions(+), 32 deletions(-)
diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.cpp b/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
index 8db7f3d..d3f67c8 100644
a
|
b
|
ClassicCommDetector::ClassicCommDetector(SkipType commDetectMethod_in, |
139 | 139 | totalMinBrightness(0), detectBlankFrames(false), |
140 | 140 | detectSceneChanges(false), detectStationLogo(false), |
141 | 141 | logoInfoAvailable(false), logoDetector(0), |
142 | | framePtr(0), frameIsBlank(false), |
| 142 | frameIsBlank(false), |
143 | 143 | sceneHasChanged(false), stationLogoPresent(false), |
144 | 144 | lastFrameWasBlank(false), lastFrameWasSceneChange(false), |
145 | 145 | decoderFoundAspectChanges(false), sceneChangeDetector(0), |
… |
… |
void ClassicCommDetector::Init() |
265 | 265 | frameIsBlank = false; |
266 | 266 | stationLogoPresent = false; |
267 | 267 | |
268 | | framePtr = NULL; |
269 | | |
270 | 268 | logoInfoAvailable = false; |
271 | 269 | |
272 | 270 | ClearAllMaps(); |
… |
… |
void ClassicCommDetector::ProcessFrame(VideoFrame *frame, |
780 | 778 | } |
781 | 779 | |
782 | 780 | curFrameNumber = frame_number; |
783 | | framePtr = frame->buf; |
| 781 | unsigned char* framePtr = frame->buf; |
| 782 | int bytesPerLine = frame->pitches[0]; |
784 | 783 | |
785 | 784 | fInfo.minBrightness = -1; |
786 | 785 | fInfo.maxBrightness = -1; |
… |
… |
void ClassicCommDetector::ProcessFrame(VideoFrame *frame, |
817 | 816 | |
818 | 817 | if (commDetectMethod & COMM_DETECT_SCENE) |
819 | 818 | { |
820 | | sceneChangeDetector->processFrame(framePtr); |
| 819 | sceneChangeDetector->processFrame(frame); |
821 | 820 | } |
822 | 821 | |
823 | 822 | stationLogoPresent = false; |
… |
… |
void ClassicCommDetector::ProcessFrame(VideoFrame *frame, |
828 | 827 | for(int x = commDetectBorder; x < (width - commDetectBorder); |
829 | 828 | x += horizSpacing) |
830 | 829 | { |
831 | | pixel = framePtr[y * width + x]; |
| 830 | pixel = framePtr[y * bytesPerLine + x]; |
832 | 831 | |
833 | 832 | if (commDetectMethod & COMM_DETECT_BLANKS) |
834 | 833 | { |
… |
… |
void ClassicCommDetector::ProcessFrame(VideoFrame *frame, |
947 | 946 | if ((logoInfoAvailable) && (commDetectMethod & COMM_DETECT_LOGO)) |
948 | 947 | { |
949 | 948 | stationLogoPresent = |
950 | | logoDetector->doesThisFrameContainTheFoundLogo(framePtr); |
| 949 | logoDetector->doesThisFrameContainTheFoundLogo(frame); |
951 | 950 | } |
952 | 951 | |
953 | 952 | #if 0 |
diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.h b/mythtv/programs/mythcommflag/ClassicCommDetector.h
index a86ab27..8c1518b 100644
a
|
b
|
class ClassicCommDetector : public CommDetectorBase |
153 | 153 | bool logoInfoAvailable; |
154 | 154 | LogoDetectorBase* logoDetector; |
155 | 155 | |
156 | | unsigned char *framePtr; |
157 | | |
158 | 156 | frm_dir_map_t blankFrameMap; |
159 | 157 | frm_dir_map_t blankCommMap; |
160 | 158 | frm_dir_map_t blankCommBreakMap; |
diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp b/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
index 5a1b832..0cdc680 100644
a
|
b
|
|
7 | 7 | // MythTV headers |
8 | 8 | #include "mythcorecontext.h" |
9 | 9 | #include "mythplayer.h" |
| 10 | #include "mythframe.h" |
10 | 11 | |
11 | 12 | // Commercial Flagging headers |
12 | 13 | #include "ClassicLogoDetector.h" |
… |
… |
void ClassicLogoDetector::DumpLogo(bool fromCurrentFrame, |
441 | 442 | * which are partially mods based on Myth's original commercial skip |
442 | 443 | * code written by Chris Pinkham. */ |
443 | 444 | bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo( |
444 | | unsigned char* framePtr) |
| 445 | VideoFrame* frame) |
445 | 446 | { |
446 | 447 | int radius = 2; |
447 | 448 | unsigned int x, y; |
448 | 449 | int pos1, pos2, pos3; |
| 450 | int edgePos; |
449 | 451 | int pixel; |
450 | 452 | int goodEdges = 0; |
451 | 453 | int badEdges = 0; |
452 | 454 | int testEdges = 0; |
453 | 455 | int testNotEdges = 0; |
454 | 456 | |
| 457 | unsigned char* framePtr = frame->buf; |
| 458 | int bytesPerLine = frame->pitches[0]; |
| 459 | |
455 | 460 | for (y = logoMinY; y <= logoMaxY; y++ ) |
456 | 461 | { |
457 | 462 | for (x = logoMinX; x <= logoMaxX; x++ ) |
458 | 463 | { |
459 | | pos1 = y * width + x; |
460 | | pos2 = (y - radius) * width + x; |
461 | | pos3 = (y + radius) * width + x; |
| 464 | pos1 = y * bytesPerLine + x; |
| 465 | edgePos = y * width + x; |
| 466 | pos2 = (y - radius) * bytesPerLine + x; |
| 467 | pos3 = (y + radius) * bytesPerLine + x; |
462 | 468 | |
463 | 469 | pixel = framePtr[pos1]; |
464 | 470 | |
465 | | if (edgeMask[pos1].horiz) |
| 471 | if (edgeMask[edgePos].horiz) |
466 | 472 | { |
467 | 473 | if ((abs(framePtr[pos1 - radius] - pixel) >= logoEdgeDiff) || |
468 | 474 | (abs(framePtr[pos1 + radius] - pixel) >= logoEdgeDiff)) |
… |
… |
bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo( |
477 | 483 | testNotEdges++; |
478 | 484 | } |
479 | 485 | |
480 | | if (edgeMask[pos1].vert) |
| 486 | if (edgeMask[edgePos].vert) |
481 | 487 | { |
482 | 488 | if ((abs(framePtr[pos2] - pixel) >= logoEdgeDiff) || |
483 | 489 | (abs(framePtr[pos3] - pixel) >= logoEdgeDiff)) |
… |
… |
void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, |
520 | 526 | { |
521 | 527 | int r = 2; |
522 | 528 | unsigned char *buf = frame->buf; |
| 529 | int bytesPerLine = frame->pitches[0]; |
523 | 530 | unsigned char p; |
524 | 531 | unsigned int pos, x, y; |
525 | 532 | |
… |
… |
void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, |
536 | 543 | continue; |
537 | 544 | |
538 | 545 | pos = y * width + x; |
539 | | p = buf[pos]; |
| 546 | p = buf[y * bytesPerLine + x]; |
540 | 547 | |
541 | | if (( abs(buf[y * width + (x - r)] - p) >= edgeDiff) || |
542 | | ( abs(buf[y * width + (x + r)] - p) >= edgeDiff)) |
| 548 | if (( abs(buf[y * bytesPerLine + (x - r)] - p) >= edgeDiff) || |
| 549 | ( abs(buf[y * bytesPerLine + (x + r)] - p) >= edgeDiff)) |
543 | 550 | { |
544 | 551 | edges[pos].horiz++; |
545 | 552 | edgeCount++; |
546 | 553 | } |
547 | | if (( abs(buf[(y - r) * width + x] - p) >= edgeDiff) || |
548 | | ( abs(buf[(y + r) * width + x] - p) >= edgeDiff)) |
| 554 | if (( abs(buf[(y - r) * bytesPerLine + x] - p) >= edgeDiff) || |
| 555 | ( abs(buf[(y + r) * bytesPerLine + x] - p) >= edgeDiff)) |
549 | 556 | { |
550 | 557 | edges[pos].vert++; |
551 | 558 | edgeCount++; |
552 | 559 | } |
553 | 560 | |
554 | | if (( abs(buf[(y - r) * width + (x - r)] - p) >= edgeDiff) || |
555 | | ( abs(buf[(y + r) * width + (x + r)] - p) >= edgeDiff)) |
| 561 | if (( abs(buf[(y - r) * bytesPerLine + (x - r)] - p) >= edgeDiff) || |
| 562 | ( abs(buf[(y + r) * bytesPerLine + (x + r)] - p) >= edgeDiff)) |
556 | 563 | { |
557 | 564 | edges[pos].ldiag++; |
558 | 565 | edgeCount++; |
559 | 566 | } |
560 | 567 | |
561 | | if (( abs(buf[(y - r) * width + (x + r)] - p) >= edgeDiff) || |
562 | | ( abs(buf[(y + r) * width + (x - r)] - p) >= edgeDiff)) |
| 568 | if (( abs(buf[(y - r) * bytesPerLine + (x + r)] - p) >= edgeDiff) || |
| 569 | ( abs(buf[(y + r) * bytesPerLine + (x - r)] - p) >= edgeDiff)) |
563 | 570 | { |
564 | 571 | edges[pos].rdiag++; |
565 | 572 | edgeCount++; |
diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.h b/mythtv/programs/mythcommflag/ClassicLogoDetector.h
index d589df5..b930c98 100644
a
|
b
|
class ClassicLogoDetector : public LogoDetectorBase |
16 | 16 | virtual void deleteLater(void); |
17 | 17 | |
18 | 18 | bool searchForLogo(MythPlayer* player); |
19 | | bool doesThisFrameContainTheFoundLogo(unsigned char* frame); |
| 19 | bool doesThisFrameContainTheFoundLogo(VideoFrame* frame); |
20 | 20 | bool pixelInsideLogo(unsigned int x, unsigned int y); |
21 | 21 | |
22 | 22 | unsigned int getRequiredAvailableBufferForSearch(); |
diff --git a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp
index c449353..ca96f93 100644
a
|
b
|
void ClassicSceneChangeDetector::deleteLater(void) |
25 | 25 | SceneChangeDetectorBase::deleteLater(); |
26 | 26 | } |
27 | 27 | |
28 | | void ClassicSceneChangeDetector::processFrame(unsigned char* frame) |
| 28 | void ClassicSceneChangeDetector::processFrame(VideoFrame* frame) |
29 | 29 | { |
30 | 30 | histogram->generateFromImage(frame, width, height, commdetectborder, |
31 | 31 | width-commdetectborder, commdetectborder, |
diff --git a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h
index f4d2200..a8fd53b 100644
a
|
b
|
class ClassicSceneChangeDetector : public SceneChangeDetectorBase |
13 | 13 | unsigned int yspacing); |
14 | 14 | virtual void deleteLater(void); |
15 | 15 | |
16 | | void processFrame(unsigned char* frame); |
| 16 | void processFrame(VideoFrame* frame); |
17 | 17 | |
18 | 18 | private: |
19 | 19 | ~ClassicSceneChangeDetector() {} |
diff --git a/mythtv/programs/mythcommflag/Histogram.cpp b/mythtv/programs/mythcommflag/Histogram.cpp
index 12d2a9a..48d72a4 100644
a
|
b
|
|
3 | 3 | #include <cmath> |
4 | 4 | #include <cstring> |
5 | 5 | |
| 6 | #include "mythframe.h" |
| 7 | |
6 | 8 | Histogram::Histogram() |
7 | 9 | { |
8 | 10 | memset(data,0,sizeof(data)); |
… |
… |
Histogram::~Histogram() |
15 | 17 | { |
16 | 18 | } |
17 | 19 | |
18 | | void Histogram::generateFromImage(unsigned char* frame, unsigned int frameWidth, |
| 20 | void Histogram::generateFromImage(VideoFrame* frame, unsigned int frameWidth, |
19 | 21 | unsigned int frameHeight, unsigned int minScanX, unsigned int maxScanX, |
20 | 22 | unsigned int minScanY, unsigned int maxScanY, unsigned int XSpacing, |
21 | 23 | unsigned int YSpacing) |
… |
… |
void Histogram::generateFromImage(unsigned char* frame, unsigned int frameWidth, |
29 | 31 | if (maxScanY > frameHeight-1) |
30 | 32 | maxScanY = frameHeight-1; |
31 | 33 | |
| 34 | unsigned char* framePtr = frame->buf; |
| 35 | int bytesPerLine = frame->pitches[0]; |
32 | 36 | for(unsigned int y = minScanY; y < maxScanY; y += YSpacing) |
33 | 37 | for(unsigned int x = minScanX; x < maxScanX; x += XSpacing) |
34 | 38 | { |
35 | | data[frame[y * frameWidth + x]]++; |
| 39 | data[framePtr[y * bytesPerLine + x]]++; |
36 | 40 | numberOfSamples++; |
37 | 41 | } |
38 | 42 | } |
diff --git a/mythtv/programs/mythcommflag/Histogram.h b/mythtv/programs/mythcommflag/Histogram.h
index fbed991..06cd807 100644
a
|
b
|
|
1 | 1 | #ifndef _HISTOGRAM_H_ |
2 | 2 | #define _HISTOGRAM_H_ |
3 | 3 | |
| 4 | typedef struct VideoFrame_ VideoFrame; |
| 5 | |
4 | 6 | class Histogram |
5 | 7 | { |
6 | 8 | public: |
7 | 9 | Histogram(); |
8 | 10 | ~Histogram(); |
9 | 11 | |
10 | | void generateFromImage(unsigned char* frame, unsigned int frameWidth, |
| 12 | void generateFromImage(VideoFrame* frame, unsigned int frameWidth, |
11 | 13 | unsigned int frameHeight, unsigned int minScanX, |
12 | 14 | unsigned int maxScanX, unsigned int minScanY, |
13 | 15 | unsigned int maxScanY, unsigned int XSpacing, |
diff --git a/mythtv/programs/mythcommflag/LogoDetectorBase.h b/mythtv/programs/mythcommflag/LogoDetectorBase.h
index ea3f62f..b28cbcc 100644
a
|
b
|
|
4 | 4 | #include <QObject> |
5 | 5 | |
6 | 6 | class MythPlayer; |
| 7 | typedef struct VideoFrame_ VideoFrame; |
7 | 8 | |
8 | 9 | class LogoDetectorBase : public QObject |
9 | 10 | { |
… |
… |
class LogoDetectorBase : public QObject |
14 | 15 | foundLogo(false), width(w),height(h) {}; |
15 | 16 | |
16 | 17 | virtual bool searchForLogo(MythPlayer* player) = 0; |
17 | | virtual bool doesThisFrameContainTheFoundLogo(unsigned char* frame) = 0; |
| 18 | virtual bool doesThisFrameContainTheFoundLogo(VideoFrame* frame) = 0; |
18 | 19 | virtual bool pixelInsideLogo(unsigned int x, unsigned int y) = 0; |
19 | 20 | virtual unsigned int getRequiredAvailableBufferForSearch() = 0; |
20 | 21 | |
diff --git a/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h b/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h
index 67296d5..9a1b311 100644
a
|
b
|
|
3 | 3 | |
4 | 4 | #include <QObject> |
5 | 5 | |
| 6 | typedef struct VideoFrame_ VideoFrame; |
| 7 | |
6 | 8 | class SceneChangeDetectorBase : public QObject |
7 | 9 | { |
8 | 10 | Q_OBJECT |
… |
… |
class SceneChangeDetectorBase : public QObject |
11 | 13 | SceneChangeDetectorBase(unsigned int w, unsigned int h) : |
12 | 14 | width(w), height(h) {} |
13 | 15 | |
14 | | virtual void processFrame(unsigned char *frame) = 0; |
| 16 | virtual void processFrame(VideoFrame* frame) = 0; |
15 | 17 | |
16 | 18 | signals: |
17 | 19 | void haveNewInformation(unsigned int framenum, bool scenechange, |