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/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
+++ b/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
@@ -139,7 +139,7 @@ ClassicCommDetector::ClassicCommDetector(SkipType commDetectMethod_in,
     totalMinBrightness(0),                     detectBlankFrames(false),
     detectSceneChanges(false),                 detectStationLogo(false),
     logoInfoAvailable(false),                  logoDetector(0),
-    framePtr(0),                               frameIsBlank(false),
+    frameIsBlank(false),
     sceneHasChanged(false),                    stationLogoPresent(false),
     lastFrameWasBlank(false),                  lastFrameWasSceneChange(false),
     decoderFoundAspectChanges(false),          sceneChangeDetector(0),
@@ -265,8 +265,6 @@ void ClassicCommDetector::Init()
     frameIsBlank = false;
     stationLogoPresent = false;
 
-    framePtr = NULL;
-
     logoInfoAvailable = false;
 
     ClearAllMaps();
@@ -780,7 +778,8 @@ void ClassicCommDetector::ProcessFrame(VideoFrame *frame,
     }
 
     curFrameNumber = frame_number;
-    framePtr = frame->buf;
+    unsigned char* framePtr = frame->buf;
+    int bytesPerLine = frame->pitches[0];
 
     fInfo.minBrightness = -1;
     fInfo.maxBrightness = -1;
@@ -817,7 +816,7 @@ void ClassicCommDetector::ProcessFrame(VideoFrame *frame,
 
     if (commDetectMethod & COMM_DETECT_SCENE)
     {
-        sceneChangeDetector->processFrame(framePtr);
+        sceneChangeDetector->processFrame(frame);
     }
 
     stationLogoPresent = false;
@@ -828,7 +827,7 @@ void ClassicCommDetector::ProcessFrame(VideoFrame *frame,
         for(int x = commDetectBorder; x < (width - commDetectBorder);
                 x += horizSpacing)
         {
-            pixel = framePtr[y * width + x];
+            pixel = framePtr[y * bytesPerLine + x];
 
             if (commDetectMethod & COMM_DETECT_BLANKS)
             {
@@ -947,7 +946,7 @@ void ClassicCommDetector::ProcessFrame(VideoFrame *frame,
     if ((logoInfoAvailable) && (commDetectMethod & COMM_DETECT_LOGO))
     {
         stationLogoPresent =
-            logoDetector->doesThisFrameContainTheFoundLogo(framePtr);
+            logoDetector->doesThisFrameContainTheFoundLogo(frame);
     }
 
 #if 0
diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.h b/mythtv/programs/mythcommflag/ClassicCommDetector.h
index a86ab27..8c1518b 100644
--- a/mythtv/programs/mythcommflag/ClassicCommDetector.h
+++ b/mythtv/programs/mythcommflag/ClassicCommDetector.h
@@ -153,8 +153,6 @@ class ClassicCommDetector : public CommDetectorBase
         bool logoInfoAvailable;
         LogoDetectorBase* logoDetector;
 
-        unsigned char *framePtr;
-
         frm_dir_map_t blankFrameMap;
         frm_dir_map_t blankCommMap;
         frm_dir_map_t blankCommBreakMap;
diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp b/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
index 5a1b832..0cdc680 100644
--- a/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
+++ b/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
@@ -7,6 +7,7 @@
 // MythTV headers
 #include "mythcorecontext.h"
 #include "mythplayer.h"
+#include "mythframe.h"
 
 // Commercial Flagging headers
 #include "ClassicLogoDetector.h"
@@ -441,28 +442,33 @@ void ClassicLogoDetector::DumpLogo(bool fromCurrentFrame,
  * which are partially mods based on Myth's original commercial skip
  * code written by Chris Pinkham. */
 bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo(
-    unsigned char* framePtr)
+    VideoFrame* frame)
 {
     int radius = 2;
     unsigned int x, y;
     int pos1, pos2, pos3;
+    int edgePos;
     int pixel;
     int goodEdges = 0;
     int badEdges = 0;
     int testEdges = 0;
     int testNotEdges = 0;
 
+    unsigned char* framePtr = frame->buf;
+    int bytesPerLine = frame->pitches[0];
+
     for (y = logoMinY; y <= logoMaxY; y++ )
     {
         for (x = logoMinX; x <= logoMaxX; x++ )
         {
-            pos1 = y * width + x;
-            pos2 = (y - radius) * width + x;
-            pos3 = (y + radius) * width + x;
+            pos1 = y * bytesPerLine + x;
+            edgePos = y * width + x;
+            pos2 = (y - radius) * bytesPerLine + x;
+            pos3 = (y + radius) * bytesPerLine + x;
 
             pixel = framePtr[pos1];
 
-            if (edgeMask[pos1].horiz)
+            if (edgeMask[edgePos].horiz)
             {
                 if ((abs(framePtr[pos1 - radius] - pixel) >= logoEdgeDiff) ||
                     (abs(framePtr[pos1 + radius] - pixel) >= logoEdgeDiff))
@@ -477,7 +483,7 @@ bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo(
                 testNotEdges++;
             }
 
-            if (edgeMask[pos1].vert)
+            if (edgeMask[edgePos].vert)
             {
                 if ((abs(framePtr[pos2] - pixel) >= logoEdgeDiff) ||
                     (abs(framePtr[pos3] - pixel) >= logoEdgeDiff))
@@ -520,6 +526,7 @@ void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges,
 {
     int r = 2;
     unsigned char *buf = frame->buf;
+    int bytesPerLine = frame->pitches[0];
     unsigned char p;
     unsigned int pos, x, y;
 
@@ -536,30 +543,30 @@ void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges,
                 continue;
 
             pos = y * width + x;
-            p = buf[pos];
+            p = buf[y * bytesPerLine + x];
 
-            if (( abs(buf[y * width + (x - r)] - p) >= edgeDiff) ||
-                ( abs(buf[y * width + (x + r)] - p) >= edgeDiff))
+            if (( abs(buf[y * bytesPerLine + (x - r)] - p) >= edgeDiff) ||
+                ( abs(buf[y * bytesPerLine + (x + r)] - p) >= edgeDiff))
             {
                 edges[pos].horiz++;
                 edgeCount++;
             }
-            if (( abs(buf[(y - r) * width + x] - p) >= edgeDiff) ||
-                ( abs(buf[(y + r) * width + x] - p) >= edgeDiff))
+            if (( abs(buf[(y - r) * bytesPerLine + x] - p) >= edgeDiff) ||
+                ( abs(buf[(y + r) * bytesPerLine + x] - p) >= edgeDiff))
             {
                 edges[pos].vert++;
                 edgeCount++;
             }
 
-            if (( abs(buf[(y - r) * width + (x - r)] - p) >= edgeDiff) ||
-                ( abs(buf[(y + r) * width + (x + r)] - p) >= edgeDiff))
+            if (( abs(buf[(y - r) * bytesPerLine + (x - r)] - p) >= edgeDiff) ||
+                ( abs(buf[(y + r) * bytesPerLine + (x + r)] - p) >= edgeDiff))
             {
                 edges[pos].ldiag++;
                 edgeCount++;
             }
 
-            if (( abs(buf[(y - r) * width + (x + r)] - p) >= edgeDiff) ||
-                ( abs(buf[(y + r) * width + (x - r)] - p) >= edgeDiff))
+            if (( abs(buf[(y - r) * bytesPerLine + (x + r)] - p) >= edgeDiff) ||
+                ( abs(buf[(y + r) * bytesPerLine + (x - r)] - p) >= edgeDiff))
             {
                 edges[pos].rdiag++;
                 edgeCount++;
diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.h b/mythtv/programs/mythcommflag/ClassicLogoDetector.h
index d589df5..b930c98 100644
--- a/mythtv/programs/mythcommflag/ClassicLogoDetector.h
+++ b/mythtv/programs/mythcommflag/ClassicLogoDetector.h
@@ -16,7 +16,7 @@ class ClassicLogoDetector : public LogoDetectorBase
     virtual void deleteLater(void);
 
     bool searchForLogo(MythPlayer* player);
-    bool doesThisFrameContainTheFoundLogo(unsigned char* frame);
+    bool doesThisFrameContainTheFoundLogo(VideoFrame* frame);
     bool pixelInsideLogo(unsigned int x, unsigned int y);
 
     unsigned int getRequiredAvailableBufferForSearch();
diff --git a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp
index c449353..ca96f93 100644
--- a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp
+++ b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp
@@ -25,7 +25,7 @@ void ClassicSceneChangeDetector::deleteLater(void)
     SceneChangeDetectorBase::deleteLater();
 }
 
-void ClassicSceneChangeDetector::processFrame(unsigned char* frame)
+void ClassicSceneChangeDetector::processFrame(VideoFrame* frame)
 {
     histogram->generateFromImage(frame, width, height, commdetectborder,
                                  width-commdetectborder, commdetectborder,
diff --git a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h
index f4d2200..a8fd53b 100644
--- a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h
+++ b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h
@@ -13,7 +13,7 @@ class ClassicSceneChangeDetector : public SceneChangeDetectorBase
         unsigned int yspacing);
     virtual void deleteLater(void);
 
-    void processFrame(unsigned char* frame);
+    void processFrame(VideoFrame* frame);
 
   private:
     ~ClassicSceneChangeDetector() {}
diff --git a/mythtv/programs/mythcommflag/Histogram.cpp b/mythtv/programs/mythcommflag/Histogram.cpp
index 12d2a9a..48d72a4 100644
--- a/mythtv/programs/mythcommflag/Histogram.cpp
+++ b/mythtv/programs/mythcommflag/Histogram.cpp
@@ -3,6 +3,8 @@
 #include <cmath>
 #include <cstring>
 
+#include "mythframe.h"
+
 Histogram::Histogram()
 {
     memset(data,0,sizeof(data));
@@ -15,7 +17,7 @@ Histogram::~Histogram()
 {
 }
 
-void Histogram::generateFromImage(unsigned char* frame, unsigned int frameWidth,
+void Histogram::generateFromImage(VideoFrame* frame, unsigned int frameWidth,
          unsigned int frameHeight, unsigned int minScanX, unsigned int maxScanX,
          unsigned int minScanY, unsigned int maxScanY, unsigned int XSpacing,
          unsigned int YSpacing)
@@ -29,10 +31,12 @@ void Histogram::generateFromImage(unsigned char* frame, unsigned int frameWidth,
     if (maxScanY > frameHeight-1)
         maxScanY = frameHeight-1;
 
+    unsigned char* framePtr = frame->buf;
+    int bytesPerLine = frame->pitches[0];
     for(unsigned int y = minScanY; y < maxScanY; y += YSpacing)
         for(unsigned int x = minScanX; x < maxScanX; x += XSpacing)
         {
-            data[frame[y * frameWidth + x]]++;
+            data[framePtr[y * bytesPerLine + x]]++;
             numberOfSamples++;
         }
 }
diff --git a/mythtv/programs/mythcommflag/Histogram.h b/mythtv/programs/mythcommflag/Histogram.h
index fbed991..06cd807 100644
--- a/mythtv/programs/mythcommflag/Histogram.h
+++ b/mythtv/programs/mythcommflag/Histogram.h
@@ -1,13 +1,15 @@
 #ifndef _HISTOGRAM_H_
 #define _HISTOGRAM_H_
 
+typedef struct VideoFrame_ VideoFrame;
+
 class Histogram
 {
 public:
     Histogram();
     ~Histogram();
 
-    void generateFromImage(unsigned char* frame, unsigned int frameWidth,
+    void generateFromImage(VideoFrame* frame, unsigned int frameWidth,
              unsigned int frameHeight, unsigned int minScanX,
              unsigned int maxScanX, unsigned int minScanY,
              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/mythtv/programs/mythcommflag/LogoDetectorBase.h
+++ b/mythtv/programs/mythcommflag/LogoDetectorBase.h
@@ -4,6 +4,7 @@
 #include <QObject>
 
 class MythPlayer;
+typedef struct VideoFrame_ VideoFrame;
 
 class LogoDetectorBase : public QObject
 {
@@ -14,7 +15,7 @@ class LogoDetectorBase : public QObject
         foundLogo(false), width(w),height(h) {};
 
     virtual bool searchForLogo(MythPlayer* player) = 0;
-    virtual bool doesThisFrameContainTheFoundLogo(unsigned char* frame) = 0;
+    virtual bool doesThisFrameContainTheFoundLogo(VideoFrame* frame) = 0;
     virtual bool pixelInsideLogo(unsigned int x, unsigned int y) = 0;
     virtual unsigned int getRequiredAvailableBufferForSearch() = 0;
 
diff --git a/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h b/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h
index 67296d5..9a1b311 100644
--- a/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h
+++ b/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h
@@ -3,6 +3,8 @@
 
 #include <QObject>
 
+typedef struct VideoFrame_ VideoFrame;
+
 class SceneChangeDetectorBase : public QObject
 {
     Q_OBJECT
@@ -11,7 +13,7 @@ class SceneChangeDetectorBase : public QObject
     SceneChangeDetectorBase(unsigned int w, unsigned int h) :
         width(w), height(h) {}
 
-    virtual void processFrame(unsigned char *frame) = 0;
+    virtual void processFrame(VideoFrame* frame) = 0;
 
   signals:
     void haveNewInformation(unsigned int framenum, bool scenechange,
