Ticket #10793: 20141111-26-helen-mcf-bytesperline.patch

File 20141111-26-helen-mcf-bytesperline.patch, 13.2 KB (added by Mark Spieth, 4 years ago)
  • mythtv/programs/mythcommflag/ClassicCommDetector.cpp

    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, 
    139139    totalMinBrightness(0),                     detectBlankFrames(false),
    140140    detectSceneChanges(false),                 detectStationLogo(false),
    141141    logoInfoAvailable(false),                  logoDetector(0),
    142     framePtr(0),                               frameIsBlank(false),
     142    frameIsBlank(false),
    143143    sceneHasChanged(false),                    stationLogoPresent(false),
    144144    lastFrameWasBlank(false),                  lastFrameWasSceneChange(false),
    145145    decoderFoundAspectChanges(false),          sceneChangeDetector(0),
    void ClassicCommDetector::Init() 
    265265    frameIsBlank = false;
    266266    stationLogoPresent = false;
    267267
    268     framePtr = NULL;
    269 
    270268    logoInfoAvailable = false;
    271269
    272270    ClearAllMaps();
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    780778    }
    781779
    782780    curFrameNumber = frame_number;
    783     framePtr = frame->buf;
     781    unsigned char* framePtr = frame->buf;
     782    int bytesPerLine = frame->pitches[0];
    784783
    785784    fInfo.minBrightness = -1;
    786785    fInfo.maxBrightness = -1;
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    817816
    818817    if (commDetectMethod & COMM_DETECT_SCENE)
    819818    {
    820         sceneChangeDetector->processFrame(framePtr);
     819        sceneChangeDetector->processFrame(frame);
    821820    }
    822821
    823822    stationLogoPresent = false;
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    828827        for(int x = commDetectBorder; x < (width - commDetectBorder);
    829828                x += horizSpacing)
    830829        {
    831             pixel = framePtr[y * width + x];
     830            pixel = framePtr[y * bytesPerLine + x];
    832831
    833832            if (commDetectMethod & COMM_DETECT_BLANKS)
    834833            {
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    947946    if ((logoInfoAvailable) && (commDetectMethod & COMM_DETECT_LOGO))
    948947    {
    949948        stationLogoPresent =
    950             logoDetector->doesThisFrameContainTheFoundLogo(framePtr);
     949            logoDetector->doesThisFrameContainTheFoundLogo(frame);
    951950    }
    952951
    953952#if 0
  • mythtv/programs/mythcommflag/ClassicCommDetector.h

    diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.h b/mythtv/programs/mythcommflag/ClassicCommDetector.h
    index a86ab27..8c1518b 100644
    a b class ClassicCommDetector : public CommDetectorBase 
    153153        bool logoInfoAvailable;
    154154        LogoDetectorBase* logoDetector;
    155155
    156         unsigned char *framePtr;
    157 
    158156        frm_dir_map_t blankFrameMap;
    159157        frm_dir_map_t blankCommMap;
    160158        frm_dir_map_t blankCommBreakMap;
  • mythtv/programs/mythcommflag/ClassicLogoDetector.cpp

    diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp b/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
    index 5a1b832..0cdc680 100644
    a b  
    77// MythTV headers
    88#include "mythcorecontext.h"
    99#include "mythplayer.h"
     10#include "mythframe.h"
    1011
    1112// Commercial Flagging headers
    1213#include "ClassicLogoDetector.h"
    void ClassicLogoDetector::DumpLogo(bool fromCurrentFrame, 
    441442 * which are partially mods based on Myth's original commercial skip
    442443 * code written by Chris Pinkham. */
    443444bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo(
    444     unsigned char* framePtr)
     445    VideoFrame* frame)
    445446{
    446447    int radius = 2;
    447448    unsigned int x, y;
    448449    int pos1, pos2, pos3;
     450    int edgePos;
    449451    int pixel;
    450452    int goodEdges = 0;
    451453    int badEdges = 0;
    452454    int testEdges = 0;
    453455    int testNotEdges = 0;
    454456
     457    unsigned char* framePtr = frame->buf;
     458    int bytesPerLine = frame->pitches[0];
     459
    455460    for (y = logoMinY; y <= logoMaxY; y++ )
    456461    {
    457462        for (x = logoMinX; x <= logoMaxX; x++ )
    458463        {
    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;
    462468
    463469            pixel = framePtr[pos1];
    464470
    465             if (edgeMask[pos1].horiz)
     471            if (edgeMask[edgePos].horiz)
    466472            {
    467473                if ((abs(framePtr[pos1 - radius] - pixel) >= logoEdgeDiff) ||
    468474                    (abs(framePtr[pos1 + radius] - pixel) >= logoEdgeDiff))
    bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo( 
    477483                testNotEdges++;
    478484            }
    479485
    480             if (edgeMask[pos1].vert)
     486            if (edgeMask[edgePos].vert)
    481487            {
    482488                if ((abs(framePtr[pos2] - pixel) >= logoEdgeDiff) ||
    483489                    (abs(framePtr[pos3] - pixel) >= logoEdgeDiff))
    void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, 
    520526{
    521527    int r = 2;
    522528    unsigned char *buf = frame->buf;
     529    int bytesPerLine = frame->pitches[0];
    523530    unsigned char p;
    524531    unsigned int pos, x, y;
    525532
    void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, 
    536543                continue;
    537544
    538545            pos = y * width + x;
    539             p = buf[pos];
     546            p = buf[y * bytesPerLine + x];
    540547
    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))
    543550            {
    544551                edges[pos].horiz++;
    545552                edgeCount++;
    546553            }
    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))
    549556            {
    550557                edges[pos].vert++;
    551558                edgeCount++;
    552559            }
    553560
    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))
    556563            {
    557564                edges[pos].ldiag++;
    558565                edgeCount++;
    559566            }
    560567
    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))
    563570            {
    564571                edges[pos].rdiag++;
    565572                edgeCount++;
  • mythtv/programs/mythcommflag/ClassicLogoDetector.h

    diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.h b/mythtv/programs/mythcommflag/ClassicLogoDetector.h
    index d589df5..b930c98 100644
    a b class ClassicLogoDetector : public LogoDetectorBase 
    1616    virtual void deleteLater(void);
    1717
    1818    bool searchForLogo(MythPlayer* player);
    19     bool doesThisFrameContainTheFoundLogo(unsigned char* frame);
     19    bool doesThisFrameContainTheFoundLogo(VideoFrame* frame);
    2020    bool pixelInsideLogo(unsigned int x, unsigned int y);
    2121
    2222    unsigned int getRequiredAvailableBufferForSearch();
  • mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp

    diff --git a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.cpp
    index c449353..ca96f93 100644
    a b void ClassicSceneChangeDetector::deleteLater(void) 
    2525    SceneChangeDetectorBase::deleteLater();
    2626}
    2727
    28 void ClassicSceneChangeDetector::processFrame(unsigned char* frame)
     28void ClassicSceneChangeDetector::processFrame(VideoFrame* frame)
    2929{
    3030    histogram->generateFromImage(frame, width, height, commdetectborder,
    3131                                 width-commdetectborder, commdetectborder,
  • mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h

    diff --git a/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h b/mythtv/programs/mythcommflag/ClassicSceneChangeDetector.h
    index f4d2200..a8fd53b 100644
    a b class ClassicSceneChangeDetector : public SceneChangeDetectorBase 
    1313        unsigned int yspacing);
    1414    virtual void deleteLater(void);
    1515
    16     void processFrame(unsigned char* frame);
     16    void processFrame(VideoFrame* frame);
    1717
    1818  private:
    1919    ~ClassicSceneChangeDetector() {}
  • mythtv/programs/mythcommflag/Histogram.cpp

    diff --git a/mythtv/programs/mythcommflag/Histogram.cpp b/mythtv/programs/mythcommflag/Histogram.cpp
    index 12d2a9a..48d72a4 100644
    a b  
    33#include <cmath>
    44#include <cstring>
    55
     6#include "mythframe.h"
     7
    68Histogram::Histogram()
    79{
    810    memset(data,0,sizeof(data));
    Histogram::~Histogram() 
    1517{
    1618}
    1719
    18 void Histogram::generateFromImage(unsigned char* frame, unsigned int frameWidth,
     20void Histogram::generateFromImage(VideoFrame* frame, unsigned int frameWidth,
    1921         unsigned int frameHeight, unsigned int minScanX, unsigned int maxScanX,
    2022         unsigned int minScanY, unsigned int maxScanY, unsigned int XSpacing,
    2123         unsigned int YSpacing)
    void Histogram::generateFromImage(unsigned char* frame, unsigned int frameWidth, 
    2931    if (maxScanY > frameHeight-1)
    3032        maxScanY = frameHeight-1;
    3133
     34    unsigned char* framePtr = frame->buf;
     35    int bytesPerLine = frame->pitches[0];
    3236    for(unsigned int y = minScanY; y < maxScanY; y += YSpacing)
    3337        for(unsigned int x = minScanX; x < maxScanX; x += XSpacing)
    3438        {
    35             data[frame[y * frameWidth + x]]++;
     39            data[framePtr[y * bytesPerLine + x]]++;
    3640            numberOfSamples++;
    3741        }
    3842}
  • mythtv/programs/mythcommflag/Histogram.h

    diff --git a/mythtv/programs/mythcommflag/Histogram.h b/mythtv/programs/mythcommflag/Histogram.h
    index fbed991..06cd807 100644
    a b  
    11#ifndef _HISTOGRAM_H_
    22#define _HISTOGRAM_H_
    33
     4typedef struct VideoFrame_ VideoFrame;
     5
    46class Histogram
    57{
    68public:
    79    Histogram();
    810    ~Histogram();
    911
    10     void generateFromImage(unsigned char* frame, unsigned int frameWidth,
     12    void generateFromImage(VideoFrame* frame, unsigned int frameWidth,
    1113             unsigned int frameHeight, unsigned int minScanX,
    1214             unsigned int maxScanX, unsigned int minScanY,
    1315             unsigned int maxScanY, unsigned int XSpacing,
  • mythtv/programs/mythcommflag/LogoDetectorBase.h

    diff --git a/mythtv/programs/mythcommflag/LogoDetectorBase.h b/mythtv/programs/mythcommflag/LogoDetectorBase.h
    index ea3f62f..b28cbcc 100644
    a b  
    44#include <QObject>
    55
    66class MythPlayer;
     7typedef struct VideoFrame_ VideoFrame;
    78
    89class LogoDetectorBase : public QObject
    910{
    class LogoDetectorBase : public QObject 
    1415        foundLogo(false), width(w),height(h) {};
    1516
    1617    virtual bool searchForLogo(MythPlayer* player) = 0;
    17     virtual bool doesThisFrameContainTheFoundLogo(unsigned char* frame) = 0;
     18    virtual bool doesThisFrameContainTheFoundLogo(VideoFrame* frame) = 0;
    1819    virtual bool pixelInsideLogo(unsigned int x, unsigned int y) = 0;
    1920    virtual unsigned int getRequiredAvailableBufferForSearch() = 0;
    2021
  • mythtv/programs/mythcommflag/SceneChangeDetectorBase.h

    diff --git a/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h b/mythtv/programs/mythcommflag/SceneChangeDetectorBase.h
    index 67296d5..9a1b311 100644
    a b  
    33
    44#include <QObject>
    55
     6typedef struct VideoFrame_ VideoFrame;
     7
    68class SceneChangeDetectorBase : public QObject
    79{
    810    Q_OBJECT
    class SceneChangeDetectorBase : public QObject 
    1113    SceneChangeDetectorBase(unsigned int w, unsigned int h) :
    1214        width(w), height(h) {}
    1315
    14     virtual void processFrame(unsigned char *frame) = 0;
     16    virtual void processFrame(VideoFrame* frame) = 0;
    1517
    1618  signals:
    1719    void haveNewInformation(unsigned int framenum, bool scenechange,