diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 9439d39..3c95424 100644
--- a/mythtv/libs/libmythtv/avformatdecoder.cpp
+++ b/mythtv/libs/libmythtv/avformatdecoder.cpp
@@ -1372,7 +1372,12 @@ void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc,
             }
 
             if (FlagIsSet(kDecodeLowRes))
-                enc->lowres = 2; // 1 = 1/2 size, 2 = 1/4 size
+            {
+                if (enc->height > 720)
+                    enc->lowres = 2; // 2 = 1/4 size
+                else
+                    enc->lowres = 1; // 1 = 1/2 size
+            }
         }
         else if (CODEC_ID_H264 == codec->id)
         {
diff --git a/mythtv/programs/mythcommflag/ClassicCommDetector.cpp b/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
index 800e83d..bb83323 100644
--- a/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
+++ b/mythtv/programs/mythcommflag/ClassicCommDetector.cpp
@@ -152,7 +152,7 @@ ClassicCommDetector::ClassicCommDetector(SkipType commDetectMethod_in,
     preRoll(0),                                postRoll(0)
 {
     commDetectBorder =
-        gCoreContext->GetNumSetting("CommDetectBorder", 20);
+        gCoreContext->GetNumSetting("CommDetectBorder", 5);
     commDetectBlankFrameMaxDiff =
         gCoreContext->GetNumSetting("CommDetectBlankFrameMaxDiff", 25);
     commDetectDarkBrightness =
@@ -206,31 +206,8 @@ void ClassicCommDetector::Init()
             .arg(width).arg(height)
             .arg(player->GetFrameRate()).arg(commDetectMethod));
 
-    if ((width * height) > 1000000)
-    {
-        horizSpacing = 10;
-        vertSpacing = 10;
-    }
-    else if ((width * height) > 800000)
-    {
-        horizSpacing = 8;
-        vertSpacing = 8;
-    }
-    else if ((width * height) > 400000)
-    {
-        horizSpacing = 6;
-        vertSpacing = 6;
-    }
-    else if ((width * height) > 300000)
-    {
-        horizSpacing = 6;
-        vertSpacing = 4;
-    }
-    else
-    {
-        horizSpacing = 4;
-        vertSpacing = 4;
-    }
+    horizSpacing = 1;
+    vertSpacing = 1;
 
     LOG(VB_COMMFLAG, LOG_INFO,
         QString("Using Sample Spacing of %1 horizontal & %2 vertical pixels.")
diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp b/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
index f961af0..6db9e12 100644
--- a/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
+++ b/mythtv/programs/mythcommflag/ClassicLogoDetector.cpp
@@ -6,22 +6,13 @@
 
 // MythTV headers
 #include "mythcorecontext.h"
-#include "mythplayer.h"
+#include "mythcommflagplayer.h"
 
 // Commercial Flagging headers
 #include "ClassicLogoDetector.h"
 #include "ClassicCommDetector.h"
-
-typedef struct edgemaskentry
-{
-    int isedge;
-    int horiz;
-    int vert;
-    int rdiag;
-    int ldiag;
-}
-EdgeMaskEntry;
-
+#include <ffmpeg-mmx.h>
+#include <lzoconf.h>
 
 ClassicLogoDetector::ClassicLogoDetector(ClassicCommDetector* commdetector,
                                          unsigned int w, unsigned int h,
@@ -29,17 +20,10 @@ ClassicLogoDetector::ClassicLogoDetector(ClassicCommDetector* commdetector,
                                          unsigned int xspacing_in,
                                          unsigned int yspacing_in)
     : LogoDetectorBase(w,h),
-      commDetector(commdetector),                       frameNumber(0),
-      previousFrameWasSceneChange(false),
-      xspacing(xspacing_in),                            yspacing(yspacing_in),
-      commDetectBorder(commdetectborder_in),            edgeMask(new EdgeMaskEntry[width * height]),
-      logoMaxValues(new unsigned char[width * height]), logoMinValues(new unsigned char[width * height]),
-      logoFrame(new unsigned char[width * height]),     logoMask(new unsigned char[width * height]),
-      logoCheckMask(new unsigned char[width * height]), tmpBuf(new unsigned char[width * height]),
-      logoEdgeDiff(0),                                  logoFrameCount(0),
-      logoMinX(0),                                      logoMaxX(0),
-      logoMinY(0),                                      logoMaxY(0),
-      logoInfoAvailable(false)
+      commDetector(commdetector), commDetectBorder(commdetectborder_in),
+      logoInfoAvailable(false),   logoEdgeDiff(0),
+      logoMinX(0),                logoWidth(0),
+      logoMinY(0),                logoHeight(0)
 {
     commDetectLogoSamplesNeeded =
         gCoreContext->GetNumSetting("CommDetectLogoSamplesNeeded", 240);
@@ -63,21 +47,7 @@ unsigned int ClassicLogoDetector::getRequiredAvailableBufferForSearch()
 void ClassicLogoDetector::deleteLater(void)
 {
     commDetector = 0;
-    if (edgeMask)
-        delete [] edgeMask;
-    if (logoFrame)
-        delete [] logoFrame;
-    if (logoMask)
-        delete [] logoMask;
-    if (logoCheckMask)
-        delete [] logoCheckMask;
-    if (logoMaxValues)
-        delete [] logoMaxValues;
-    if (logoMinValues)
-        delete [] logoMinValues;
-    if (tmpBuf)
-        delete [] tmpBuf;
-
+    
     LogoDetectorBase::deleteLater();
 }
 
@@ -88,26 +58,23 @@ bool ClassicLogoDetector::searchForLogo(MythPlayer* player)
     long long seekFrame;
     int loops;
     int maxLoops = commDetectLogoSamplesNeeded;
-    EdgeMaskEntry *edgeCounts;
-    unsigned int pos, i, x, y, dx, dy;
-    int edgeDiffs[] = {5, 7, 10, 15, 20, 30, 40, 50, 60, 0 };
-
-
+    const int edgeDiffs[] = {55, 25, 13, 6, 0};
+    
     LOG(VB_COMMFLAG, LOG_INFO, "Searching for Station Logo");
 
     logoInfoAvailable = false;
 
-    edgeCounts = new EdgeMaskEntry[width * height];
+    int *edgeCounts = new int[width * height];
 
-    for (i = 0; edgeDiffs[i] != 0 && !logoInfoAvailable; i++)
+    for (int i = 0; edgeDiffs[i] != 0 && !logoInfoAvailable; i++)
     {
         int pixelsInMask = 0;
 
         LOG(VB_COMMFLAG, LOG_INFO, QString("Trying with edgeDiff == %1")
                 .arg(edgeDiffs[i]));
 
-        memset(edgeCounts, 0, sizeof(EdgeMaskEntry) * width * height);
-        memset(edgeMask, 0, sizeof(EdgeMaskEntry) * width * height);
+        memset(edgeCounts, 0, sizeof(int) * width * height);
+        edgeMask.clear();
 
         player->DiscardVideoFrame(player->GetRawVideoFrame(0));
 
@@ -115,128 +82,37 @@ bool ClassicLogoDetector::searchForLogo(MythPlayer* player)
         seekFrame = commDetector->preRoll + seekIncrement;
         while(loops < maxLoops && !player->GetEof())
         {
-            VideoFrame* vf = player->GetRawVideoFrame(seekFrame);
-
             if ((loops % 50) == 0)
                 commDetector->logoDetectorBreathe();
 
+            if (!commDetector->fullSpeed)
+                usleep(10000);
+            
+            VideoFrame* vf = player->GetRawVideoFrame(seekFrame);
+            DetectEdges(vf, edgeCounts, edgeDiffs[i]);
+            player->DiscardVideoFrame(vf);
+            
             if (commDetector->m_bStop)
             {
-                player->DiscardVideoFrame(vf);
                 delete[] edgeCounts;
                 return false;
             }
-
-            if (!commDetector->fullSpeed)
-                usleep(10000);
-
-            DetectEdges(vf, edgeCounts, edgeDiffs[i]);
-
+            
             seekFrame += seekIncrement;
             loops++;
-
-            player->DiscardVideoFrame(vf);
-        }
-
-        LOG(VB_COMMFLAG, LOG_INFO, "Analyzing edge data");
-
-#ifdef SHOW_DEBUG_WIN
-        unsigned char *fakeFrame;
-        fakeFrame = new unsigned char[width * height * 3 / 2];
-        memset(fakeFrame, 0, width * height * 3 / 2);
-#endif
-
-        for (y = 0; y < height; y++)
-        {
-            if ((y > (height/4)) && (y < (height * 3 / 4)))
-                continue;
-
-            for (x = 0; x < width; x++)
-            {
-                if ((x > (width/4)) && (x < (width * 3 / 4)))
-                    continue;
-
-                pos = y * width + x;
-
-                if (edgeCounts[pos].isedge > (maxLoops * 0.66))
-                {
-                    edgeMask[pos].isedge = 1;
-                    pixelsInMask++;
-#ifdef SHOW_DEBUG_WIN
-                    fakeFrame[pos] = 0xff;
-#endif
-
-                }
-
-                if (edgeCounts[pos].horiz > (maxLoops * 0.66))
-                    edgeMask[pos].horiz = 1;
-
-                if (edgeCounts[pos].vert > (maxLoops * 0.66))
-                    edgeMask[pos].vert = 1;
-
-                if (edgeCounts[pos].ldiag > (maxLoops * 0.66))
-                    edgeMask[pos].ldiag = 1;
-                if (edgeCounts[pos].rdiag > (maxLoops * 0.66))
-                    edgeMask[pos].rdiag = 1;
-            }
-        }
-
-        SetLogoMaskArea();
-
-        for (y = logoMinY; y < logoMaxY; y++)
-        {
-            for (x = logoMinX; x < logoMaxX; x++)
-            {
-                int neighbors = 0;
-
-                if (!edgeMask[y * width + x].isedge)
-                    continue;
-
-                for (dy = y - 2; dy <= (y + 2); dy++ )
-                {
-                    for (dx = x - 2; dx <= (x + 2); dx++ )
-                    {
-                        if (edgeMask[dy * width + dx].isedge)
-                            neighbors++;
-                    }
-                }
-
-                if (neighbors < 5)
-                    edgeMask[y * width + x].isedge = 0;
-            }
         }
+        
+        player->DiscardVideoFrame(player->GetRawVideoFrame(0));
 
-        SetLogoMaskArea();
+        pixelsInMask = AnalyzeEdgeCounts(edgeCounts, maxLoops * 2 / 3);
+        
         LOG(VB_COMMFLAG, LOG_INFO,
-            QString("Testing Logo area: topleft (%1,%2), bottomright (%3,%4)")
+            QString("Testing Logo area: topleft (%1,%2), size (%3,%4)")
                 .arg(logoMinX).arg(logoMinY)
-                .arg(logoMaxX).arg(logoMaxY));
-
-#ifdef SHOW_DEBUG_WIN
-        for (x = logoMinX; x < logoMaxX; x++)
-        {
-            pos = logoMinY * width + x;
-            fakeFrame[pos] = 0x7f;
-            pos = logoMaxY * width + x;
-            fakeFrame[pos] = 0x7f;
-        }
-        for (y = logoMinY; y < logoMaxY; y++)
-        {
-            pos = y * width + logoMinX;
-            fakeFrame[pos] = 0x7f;
-            pos = y * width + logoMaxX;
-            fakeFrame[pos] = 0x7f;
-        }
-
-        comm_debug_show(fakeFrame);
-        delete [] fakeFrame;
+                .arg(logoWidth).arg(logoHeight));
 
-        cerr << "Hit ENTER to continue" << endl;
-        getchar();
-#endif
-        if (((logoMaxX - logoMinX) < (width / 4)) &&
-            ((logoMaxY - logoMinY) < (height / 4)) &&
-            (pixelsInMask > 50))
+        if (pixelsInMask > 100 && 
+            (logoWidth < (width / 6) || logoHeight < (height / 6)))
         {
             logoInfoAvailable = true;
             logoEdgeDiff = edgeDiffs[i];
@@ -245,7 +121,7 @@ bool ClassicLogoDetector::searchForLogo(MythPlayer* player)
                 QString("Using Logo area: topleft (%1,%2), "
                         "bottomright (%3,%4)")
                     .arg(logoMinX).arg(logoMinY)
-                    .arg(logoMaxX).arg(logoMaxY));
+                    .arg(logoWidth).arg(logoHeight));
         }
         else
         {
@@ -254,7 +130,7 @@ bool ClassicLogoDetector::searchForLogo(MythPlayer* player)
                         "bottomright (%3,%4), pixelsInMask (%5). "
                         "Not within specified limits.")
                     .arg(logoMinX).arg(logoMinY)
-                    .arg(logoMaxX).arg(logoMaxY)
+                    .arg(logoWidth).arg(logoHeight)
                     .arg(pixelsInMask));
         }
     }
@@ -263,27 +139,56 @@ bool ClassicLogoDetector::searchForLogo(MythPlayer* player)
 
     if (!logoInfoAvailable)
         LOG(VB_COMMFLAG, LOG_NOTICE, "No suitable logo area found.");
-
-    player->DiscardVideoFrame(player->GetRawVideoFrame(0));
+    else
+        DumpLogo();
+    
     return logoInfoAvailable;
 }
 
-
-void ClassicLogoDetector::SetLogoMaskArea()
+int ClassicLogoDetector::AnalyzeEdgeCounts(int *edgeCounts, int threshold)
 {
-    LOG(VB_COMMFLAG, LOG_INFO, "SetLogoMaskArea()");
-
+    const int minNeighbors = 2;
+    int pixelsInMask = 0;
+    unsigned int logoMaxX = 0, logoMaxY = 0;
+    
     logoMinX = width - 1;
-    logoMaxX = 0;
     logoMinY = height - 1;
-    logoMaxY = 0;
-
+    
+    LOG(VB_COMMFLAG, LOG_INFO, "Analyzing edge data");
+    
+    QBitArray tmpMask(width*height);
+    
     for (unsigned int y = 0; y < height; y++)
     {
         for (unsigned int x = 0; x < width; x++)
         {
-            if (edgeMask[y * width + x].isedge)
+            unsigned int pos = y * width + x;
+            if (edgeCounts[pos] < threshold)
+                continue;
+            
+            int neighbors = 0;
+            
+            // 3x3 block
+            for (int dy = y - 1; dy <= (y + 1); dy++)
+            {
+                for (int dx = x - 1; dx <= (x + 1); dx++)
+                {
+                    unsigned int dp = dy * width + dx;
+                    if (edgeCounts[dp] >= threshold)
+                    {
+                        neighbors++;
+                        if (neighbors > minNeighbors)
+                            break;
+                    }
+                }
+            }
+            
+            if (neighbors > minNeighbors)
             {
+                tmpMask[pos] = true;
+                
+                pixelsInMask++;
+                
                 if (x < logoMinX)
                     logoMinX = x;
                 if (y < logoMinY)
@@ -293,281 +198,159 @@ void ClassicLogoDetector::SetLogoMaskArea()
                 if (y > logoMaxY)
                     logoMaxY = y;
             }
-        }
-    }
-
-    logoMinX -= 5;
-    logoMaxX += 5;
-    logoMinY -= 5;
-    logoMaxY += 5;
-
-    if (logoMinX < 4)
-        logoMinX = 4;
-    if (logoMaxX > (width-5))
-        logoMaxX = (width-5);
-    if (logoMinY < 4)
-        logoMinY = 4;
-    if (logoMaxY > (height-5))
-        logoMaxY = (height-5);
-}
-
-void ClassicLogoDetector::SetLogoMask(unsigned char *mask)
-{
-    int pixels = 0;
-
-    memcpy(logoMask, mask, width * height);
-
-    SetLogoMaskArea();
-
-    for(unsigned int y = logoMinY; y <= logoMaxY; y++)
-        for(unsigned int x = logoMinX; x <= logoMaxX; x++)
-            if (!logoMask[y * width + x] == 1)
-                pixels++;
-
-    if (pixels < 30)
-        return;
-
-    // set the pixels around our logo
-    for(unsigned int y = (logoMinY - 1); y <= (logoMaxY + 1); y++)
-    {
-        for(unsigned int x = (logoMinX - 1); x <= (logoMaxX + 1); x++)
-        {
-            if (!logoMask[y * width + x])
+            else
             {
-                for (unsigned int y2 = y - 1; y2 <= (y + 1); y2++)
-                {
-                    for (unsigned int x2 = x - 1; x2 <= (x + 1); x2++)
-                    {
-                        if ((logoMask[y2 * width + x2] == 1) &&
-                            (!logoMask[y * width + x]))
-                        {
-                            logoMask[y * width + x] = 2;
-                            x2 = x + 2;
-                            y2 = y + 2;
-
-                            logoCheckMask[y2 * width + x2] = 1;
-                            logoCheckMask[y * width + x] = 1;
-                        }
-                    }
-                }
+                tmpMask[pos] = false;
             }
-        }
-    }
-
-    for(unsigned int y = (logoMinY - 2); y <= (logoMaxY + 2); y++)
+        } // end for x
+    } // end for y
+    
+    logoMinX -= 1;
+    logoMaxX += 1;
+    logoMinY -= 1;
+    logoMaxY += 1;
+
+    if (logoMinX < commDetectBorder)
+        logoMinX = commDetectBorder;
+    if (logoMaxX > (width-commDetectBorder))
+        logoMaxX = (width-commDetectBorder);
+    if (logoMinY < commDetectBorder)
+        logoMinY = commDetectBorder;
+    if (logoMaxY > (height-commDetectBorder))
+        logoMaxY = (height-commDetectBorder);
+    
+    if (pixelsInMask > 0 && logoMaxX > logoMinX && logoMaxY > logoMinY)
     {
-        for(unsigned int x = (logoMinX - 2); x <= (logoMaxX + 2); x++)
+        logoWidth = logoMaxX - logoMinX;
+        logoHeight = logoMaxY - logoMinY;
+        
+        edgeMask.resize(logoWidth * logoHeight);
+        for (unsigned int y = 0; y < logoHeight; ++y)
         {
-            if (!logoMask[y * width + x])
+            for (unsigned int x = 0; x < logoWidth; ++x)
             {
-                for (unsigned int y2 = y - 1; y2 <= (y + 1); y2++)
-                {
-                    for (unsigned int x2 = x - 1; x2 <= (x + 1); x2++)
-                    {
-                        if ((logoMask[y2 * width + x2] == 2) &&
-                            (!logoMask[y * width + x]))
-                        {
-                            logoMask[y * width + x] = 3;
-                            x2 = x + 2;
-                            y2 = y + 2;
-
-                            logoCheckMask[y * width + x] = 1;
-                        }
-                    }
-                }
+                edgeMask[y * logoWidth + x] = tmpMask[(y + logoMinY) * width + (x + logoMinX)];
             }
         }
     }
-
-#ifdef SHOW_DEBUG_WIN
-    DumpLogo(true,framePtr);
-#endif
-
-    logoFrameCount = 0;
-    logoInfoAvailable = true;
+    
+    return pixelsInMask;
 }
 
-
-void ClassicLogoDetector::DumpLogo(bool fromCurrentFrame,
-    unsigned char* framePtr)
+void ClassicLogoDetector::DumpLogo()
 {
-    char scrPixels[] = " .oxX";
-
-    if (!logoInfoAvailable)
-        return;
-
-    cerr << "\nLogo Data ";
-    if (fromCurrentFrame)
-        cerr << "from current frame\n";
-
-    cerr << "\n     ";
-
-    for(unsigned int x = logoMinX - 2; x <= (logoMaxX + 2); x++)
-        cerr << (x % 10);
-    cerr << "\n";
-
-    for(unsigned int y = logoMinY - 2; y <= (logoMaxY + 2); y++)
+    cerr << "Logo data (" << logoMinX << "," << logoMinY << ") x (" 
+                          << logoWidth << "," << logoHeight << ") @ "
+                          << logoEdgeDiff << ":\n";
+    
+    for (unsigned int y = 0; y < logoHeight; y++)
     {
-        QString tmp = QString("%1: ").arg(y, 3);
-        QString ba = tmp.toAscii();
-        cerr << ba.constData();
-        for(unsigned int x = logoMinX - 2; x <= (logoMaxX + 2); x++)
+        for (unsigned int x = 0; x < logoWidth; x++)
         {
-            if (fromCurrentFrame)
-            {
-                cerr << scrPixels[framePtr[y * width + x] / 50];
-            }
+            unsigned int pos = y * logoWidth + x;
+            if (edgeMask[pos])
+                cerr << "#";
             else
-            {
-                switch (logoMask[y * width + x])
-                {
-                        case 0:
-                        case 2: cerr << " ";
-                        break;
-                        case 1: cerr << "*";
-                        break;
-                        case 3: cerr << ".";
-                        break;
-                }
-            }
+                cerr << " ";
         }
         cerr << "\n";
     }
-    cerr.flush();
+    
+    cerr << "\n\n\n";
 }
 
+bool ClassicLogoDetector::pixelInsideLogo(unsigned int x, unsigned int y)
+{
+    if (!logoInfoAvailable)
+        return false;
+    
+    int xd = x - logoMinX;
+    int yd = y - logoMinY;
+    
+    return xd >= 0 && xd < (int)logoWidth &&
+           yd >= 0 && yd < (int)logoHeight;
+}
 
-/* ideas for this method ported back from comskip.c mods by Jere Jones
- * which are partially mods based on Myth's original commercial skip
- * code written by Chris Pinkham. */
-bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo(
-    unsigned char* framePtr)
+bool ClassicLogoDetector::isSobelEdgeAt(unsigned char *buf,
+                                        unsigned int x,
+                                        unsigned int y,
+                                        unsigned int width,
+                                        unsigned char edgeDiff)
 {
-    int radius = 2;
-    unsigned int x, y;
-    int pos1, pos2, pos3;
-    int pixel;
-    int goodEdges = 0;
-    int badEdges = 0;
-    int testEdges = 0;
-    int testNotEdges = 0;
+    int center = y * width + x;
+    int above = center - width;
+    int below = center + width;
+    
+    int gx = 0;
+    gx -= buf[above - 1];
+    gx -= (buf[center - 1]*2);
+    gx -= buf[below - 1];
+    
+    gx += buf[above + 1];
+    gx += (buf[center + 1]*2);
+    gx += buf[below + 1];
+    
+    int gy = 0;
+    gy -= buf[above - 1];
+    gy -= (buf[above]*2);
+    gy -= buf[above + 1];
+    
+    gy += buf[below - 1];
+    gy += (buf[below]*2);
+    gy += buf[below + 1];
+    
+    return abs(gx) + abs(gy) > 3*edgeDiff;
+}
 
-    for (y = logoMinY; y <= logoMaxY; y++ )
+bool ClassicLogoDetector::doesThisFrameContainTheFoundLogo(unsigned char *framePtr)
+{
+    if (!logoInfoAvailable)
+        return false;
+    
+    unsigned int x, y;
+    unsigned int correct = 0, total = 0;
+    
+    for (y = 0; y < logoHeight; y++ )
     {
-        for (x = logoMinX; x <= logoMaxX; x++ )
+        for (x = 0; x < logoWidth; x++ )
         {
-            pos1 = y * width + x;
-            pos2 = (y - radius) * width + x;
-            pos3 = (y + radius) * width + x;
-
-            pixel = framePtr[pos1];
-
-            if (edgeMask[pos1].horiz)
-            {
-                if ((abs(framePtr[pos1 - radius] - pixel) >= logoEdgeDiff) ||
-                    (abs(framePtr[pos1 + radius] - pixel) >= logoEdgeDiff))
-                    goodEdges++;
-                testEdges++;
-            }
-            else
-            {
-                if ((abs(framePtr[pos1 - radius] - pixel) >= logoEdgeDiff) ||
-                    (abs(framePtr[pos1 + radius] - pixel) >= logoEdgeDiff))
-                    badEdges++;
-                testNotEdges++;
-            }
-
-            if (edgeMask[pos1].vert)
-            {
-                if ((abs(framePtr[pos2] - pixel) >= logoEdgeDiff) ||
-                    (abs(framePtr[pos3] - pixel) >= logoEdgeDiff))
-                    goodEdges++;
-                testEdges++;
-            }
-            else
+            if (edgeMask[y * logoWidth + x])
             {
-                if ((abs(framePtr[pos2] - pixel) >= logoEdgeDiff) ||
-                    (abs(framePtr[pos3] - pixel) >= logoEdgeDiff))
-                    badEdges++;
-                testNotEdges++;
+                if (isSobelEdgeAt(framePtr, x + logoMinX, y + logoMinY, width, logoEdgeDiff))
+                    correct++;
+                total ++;
             }
         }
     }
-
-    frameNumber++;
-    double goodEdgeRatio = (double)goodEdges / (double)testEdges;
-    double badEdgeRatio = (double)badEdges / (double)testNotEdges;
-    if ((goodEdgeRatio > commDetectLogoGoodEdgeThreshold) &&
-        (badEdgeRatio < commDetectLogoBadEdgeThreshold))
-        return true;
-    else
-        return false;
-}
-
-bool ClassicLogoDetector::pixelInsideLogo(unsigned int x, unsigned int y)
-{
-    if (!logoInfoAvailable)
-        return false;
-
-    return ((x > logoMinX) && (x < logoMaxX) &&
-            (y > logoMinY) && (y < logoMaxY));
+    
+    double d = (double)correct / (double)total;
+    return d >= commDetectLogoGoodEdgeThreshold;
 }
 
-void ClassicLogoDetector::DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges,
-                                      int edgeDiff)
+void ClassicLogoDetector::DetectEdges(VideoFrame *frame, int *edgeCounts, int edgeDiff)
 {
-    int r = 2;
-    unsigned char *buf = frame->buf;
-    unsigned char p;
-    unsigned int pos, x, y;
-
-    for (y = commDetectBorder + r; y < (height - commDetectBorder - r); y++)
+    unsigned int x, y;
+    
+    unsigned int hOneThird = height / 3;
+    unsigned int hTwoThirds = hOneThird*2;
+    unsigned int wOneThird = width / 3;
+    unsigned int wTwoThirds = wOneThird*2;
+    
+    for (y = commDetectBorder; y < height - commDetectBorder; ++y)
     {
-        if ((y > (height/4)) && (y < (height * 3 / 4)))
-            continue;
-
-        for (x = commDetectBorder + r; x < (width - commDetectBorder - r); x++)
+        for (x = commDetectBorder; x < width - commDetectBorder; ++x)
         {
-            int edgeCount = 0;
-
-            if ((x > (width/4)) && (x < (width * 3 / 4)))
-                continue;
-
-            pos = y * width + x;
-            p = buf[pos];
-
-            if (( abs(buf[y * width + (x - r)] - p) >= edgeDiff) ||
-                ( abs(buf[y * width + (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))
-            {
-                edges[pos].vert++;
-                edgeCount++;
-            }
-
-            if (( abs(buf[(y - r) * width + (x - r)] - p) >= edgeDiff) ||
-                ( abs(buf[(y + r) * width + (x + r)] - p) >= edgeDiff))
+            if (y > hOneThird && y < hTwoThirds && 
+                x > wOneThird && x < wTwoThirds)
             {
-                edges[pos].ldiag++;
-                edgeCount++;
+                x = wTwoThirds - 1;
             }
-
-            if (( abs(buf[(y - r) * width + (x + r)] - p) >= edgeDiff) ||
-                ( abs(buf[(y + r) * width + (x - r)] - p) >= edgeDiff))
+            else if (isSobelEdgeAt(frame->buf, x, y, width, edgeDiff))
             {
-                edges[pos].rdiag++;
-                edgeCount++;
+                edgeCounts[y * width + x]++;
             }
-
-            if (edgeCount >= 3)
-                edges[pos].isedge++;
         }
     }
 }
 
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
-
diff --git a/mythtv/programs/mythcommflag/ClassicLogoDetector.h b/mythtv/programs/mythcommflag/ClassicLogoDetector.h
index d589df5..a78ce4c 100644
--- a/mythtv/programs/mythcommflag/ClassicLogoDetector.h
+++ b/mythtv/programs/mythcommflag/ClassicLogoDetector.h
@@ -2,8 +2,8 @@
 #define _CLASSICLOGOGEDETECTOR_H_
 
 #include "LogoDetectorBase.h"
+#include <qbitarray.h>
 
-typedef struct edgemaskentry EdgeMaskEntry;
 typedef struct VideoFrame_ VideoFrame;
 class ClassicCommDetector;
 
@@ -16,49 +16,38 @@ class ClassicLogoDetector : public LogoDetectorBase
     virtual void deleteLater(void);
 
     bool searchForLogo(MythPlayer* player);
-    bool doesThisFrameContainTheFoundLogo(unsigned char* frame);
+    bool doesThisFrameContainTheFoundLogo(unsigned char *framePtr);
     bool pixelInsideLogo(unsigned int x, unsigned int y);
 
     unsigned int getRequiredAvailableBufferForSearch();
 
+    void DumpLogo();
+    static bool isSobelEdgeAt(unsigned char *buf, unsigned int x, unsigned int y, unsigned int width, unsigned char edgeDiff);
+    
   protected:
     virtual ~ClassicLogoDetector() {}
 
   private:
-    void SetLogoMaskArea();
-    void SetLogoMask(unsigned char *mask);
-    void DumpLogo(bool fromCurrentFrame,unsigned char* framePtr);
-    void DetectEdges(VideoFrame *frame, EdgeMaskEntry *edges, int edgeDiff);
-
+    int AnalyzeEdgeCounts(int *edgeCounts, int threshold);
+    void DetectEdges(VideoFrame *frame, int *edgeCounts, int edgeDiff);
+    
     ClassicCommDetector* commDetector;
-    unsigned int frameNumber;
-    bool previousFrameWasSceneChange;
-    unsigned int xspacing, yspacing;
     unsigned int commDetectBorder;
-
+    
     int commDetectLogoSamplesNeeded;
     int commDetectLogoSampleSpacing;
     int commDetectLogoSecondsNeeded;
     double commDetectLogoGoodEdgeThreshold;
     double commDetectLogoBadEdgeThreshold;
+    
+    QBitArray edgeMask;
 
-    EdgeMaskEntry *edgeMask;
-
-    unsigned char *logoMaxValues;
-    unsigned char *logoMinValues;
-    unsigned char *logoFrame;
-    unsigned char *logoMask;
-    unsigned char *logoCheckMask;
-    unsigned char *tmpBuf;
-
+    bool logoInfoAvailable;    
     int logoEdgeDiff;
-    unsigned int logoFrameCount;
     unsigned int logoMinX;
-    unsigned int logoMaxX;
+    unsigned int logoWidth;
     unsigned int logoMinY;
-    unsigned int logoMaxY;
-
-    bool logoInfoAvailable;
+    unsigned int logoHeight;
 };
 
 #endif
