Ticket #12308: mcf-bytesPerLine.patch

File mcf-bytesPerLine.patch, 12.5 KB (added by faginbagin <mythtv@…>, 5 years ago)
  • mythtv/programs/mythcommflag/ClassicCommDetector.cpp

    diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.cpp b/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
    index 0a7c688..a66ff3e 100644
    a b ClassicCommDetector::ClassicCommDetector(SkipType commDetectMethod_in, 
    140140    totalMinBrightness(0),                     detectBlankFrames(false),
    141141    detectSceneChanges(false),                 detectStationLogo(false),
    142142    logoInfoAvailable(false),                  logoDetector(0),
    143     framePtr(0),                               frameIsBlank(false),
     143    frameIsBlank(false),
    144144    sceneHasChanged(false),                    stationLogoPresent(false),
    145145    lastFrameWasBlank(false),                  lastFrameWasSceneChange(false),
    146146    decoderFoundAspectChanges(false),          sceneChangeDetector(0),
    void ClassicCommDetector::Init() 
    266266    frameIsBlank = false;
    267267    stationLogoPresent = false;
    268268
    269     framePtr = NULL;
    270 
    271269    logoInfoAvailable = false;
    272270
    273271    ClearAllMaps();
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    781779    }
    782780
    783781    curFrameNumber = frame_number;
    784     framePtr = frame->buf;
     782    unsigned char* framePtr = frame->buf;
     783    int bytesPerLine = frame->pitches[0];
    785784
    786785    fInfo.minBrightness = -1;
    787786    fInfo.maxBrightness = -1;
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    818817
    819818    if (commDetectMethod & COMM_DETECT_SCENE)
    820819    {
    821         sceneChangeDetector->processFrame(framePtr);
     820        sceneChangeDetector->processFrame(frame);
    822821    }
    823822
    824823    stationLogoPresent = false;
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    829828        for(int x = commDetectBorder; x < (width - commDetectBorder);
    830829                x += horizSpacing)
    831830        {
    832             pixel = framePtr[y * width + x];
     831            pixel = framePtr[y * bytesPerLine + x];
    833832
    834833            if (commDetectMethod & COMM_DETECT_BLANKS)
    835834            {
    void ClassicCommDetector::ProcessFrame(VideoFrame *frame, 
    948947    if ((logoInfoAvailable) && (commDetectMethod & COMM_DETECT_LOGO))
    949948    {
    950949        stationLogoPresent =
    951             logoDetector->doesThisFrameContainTheFoundLogo(framePtr);
     950            logoDetector->doesThisFrameContainTheFoundLogo(frame);
    952951    }
    953952
    954953#if 0
  • mythtv/programs/mythcommflag/ClassicCommDetector.h

    diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.h b/mythtv/programs/mythcommflag/ClassicCommDetector.h
    index f9e5c4c..6c25f5d 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 d909950..3a2326a 100644
    a b  
    77// MythTV headers
    88#include "mythcorecontext.h"
    99#include "mythplayer.h"
     10#include "frame.h"
    1011
    1112// Commercial Flagging headers
    1213#include "ClassicLogoDetector.h"
    void ClassicLogoDetector::DumpLogo(bool fromCurrentFrame, 
    443444 * which are partially mods based on Myth's original commercial skip
    444445 * code written by Chris Pinkham. */
    445446bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo(
    446     unsigned char* framePtr)
     447    VideoFrame* frame)
    447448{
    448449    int radius = 2;
    449450    unsigned int x, y;
    450451    int pos1, pos2, pos3;
     452    int edgePos;
    451453    int pixel;
    452454    int goodEdges = 0;
    453455    int badEdges = 0;
    454456    int testEdges = 0;
    455457    int testNotEdges = 0;
    456458
     459    unsigned char* framePtr = frame->buf;
     460    int bytesPerLine = frame->pitches[0];
     461
    457462    for (y = logoMinY; y <= logoMaxY; y++ )
    458463    {
    459464        for (x = logoMinX; x <= logoMaxX; x++ )
    460465        {
    461             pos1 = y * width + x;
    462             pos2 = (y - radius) * width + x;
    463             pos3 = (y + radius) * width + x;
     466            pos1 = y * bytesPerLine + x;
     467            edgePos = y * width + x;
     468            pos2 = (y - radius) * bytesPerLine + x;
     469            pos3 = (y + radius) * bytesPerLine + x;
    464470
    465471            pixel = framePtr[pos1];
    466472
    467             if (edgeMask[pos1].horiz)
     473            if (edgeMask[edgePos].horiz)
    468474            {
    469475                if ((abs(framePtr[pos1 - radius] - pixel) >= logoEdgeDiff) ||
    470476                    (abs(framePtr[pos1 + radius] - pixel) >= logoEdgeDiff))
    bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo( 
    479485                testNotEdges++;
    480486            }
    481487
    482             if (edgeMask[pos1].vert)
     488            if (edgeMask[edgePos].vert)
    483489            {
    484490                if ((abs(framePtr[pos2] - pixel) >= logoEdgeDiff) ||
    485491                    (abs(framePtr[pos3] - pixel) >= logoEdgeDiff))
    void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, 
    522528{
    523529    int r = 2;
    524530    unsigned char *buf = frame->buf;
     531    int bytesPerLine = frame->pitches[0];
    525532    unsigned char p;
    526533    unsigned int pos, x, y;
    527534
    void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, 
    538545                continue;
    539546
    540547            pos = y * width + x;
    541             p = buf[pos];
     548            p = buf[y * bytesPerLine + x];
    542549
    543             if (( abs(buf[y * width + (x - r)] - p) >= edgeDiff) ||
    544                 ( abs(buf[y * width + (x + r)] - p) >= edgeDiff))
     550            if (( abs(buf[y * bytesPerLine + (x - r)] - p) >= edgeDiff) ||
     551                ( abs(buf[y * bytesPerLine + (x + r)] - p) >= edgeDiff))
    545552            {
    546553                edges[pos].horiz++;
    547554                edgeCount++;
    548555            }
    549             if (( abs(buf[(y - r) * width + x] - p) >= edgeDiff) ||
    550                 ( abs(buf[(y + r) * width + x] - p) >= edgeDiff))
     556            if (( abs(buf[(y - r) * bytesPerLine + x] - p) >= edgeDiff) ||
     557                ( abs(buf[(y + r) * bytesPerLine + x] - p) >= edgeDiff))
    551558            {
    552559                edges[pos].vert++;
    553560                edgeCount++;
    554561            }
    555562
    556             if (( abs(buf[(y - r) * width + (x - r)] - p) >= edgeDiff) ||
    557                 ( abs(buf[(y + r) * width + (x + r)] - p) >= edgeDiff))
     563            if (( abs(buf[(y - r) * bytesPerLine + (x - r)] - p) >= edgeDiff) ||
     564                ( abs(buf[(y + r) * bytesPerLine + (x + r)] - p) >= edgeDiff))
    558565            {
    559566                edges[pos].ldiag++;
    560567                edgeCount++;
    561568            }
    562569
    563             if (( abs(buf[(y - r) * width + (x + r)] - p) >= edgeDiff) ||
    564                 ( abs(buf[(y + r) * width + (x - r)] - p) >= edgeDiff))
     570            if (( abs(buf[(y - r) * bytesPerLine + (x + r)] - p) >= edgeDiff) ||
     571                ( abs(buf[(y + r) * bytesPerLine + (x - r)] - p) >= edgeDiff))
    565572            {
    566573                edges[pos].rdiag++;
    567574                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..90c040d 100644
    a b  
    33#include <cmath>
    44#include <cstring>
    55
     6#include "frame.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,