(file, color_file)
return match
Check a section from the middle, top and bottom of the viewport to see if it matches
Check a section from the middle, top and bottom of the viewport to see if it matches
Check a section from the middle top and bottom of the viewport to see if it matches
def is_color_frame(file, color_file):
    """Check a section from the middle, top and bottom of the viewport to see if it matches"""
    global frame_cache
    if file in frame_cache and color_file in frame_cache[file]:
        return bool(frame_cache[file][color_file])
    match = False
    if os.path.isfile(color_file):
        try:
            from PIL import Image
            with Image.open(file) as img:
                width, height = img.size
            crops = []
            # Middle
            crops.append('{0:d}x{1:d}+{2:d}+{3:d}'.format(
                int(width / 2), int(height / 3),
                int(width / 4), int(height / 3)))
            # Top
            crops.append('{0:d}x{1:d}+{2:d}+{3:d}'.format(
                int(width / 2), int(height / 5),
                int(width / 4), 50))
            # Bottom
            crops.append('{0:d}x{1:d}+{2:d}+{3:d}'.format(
                int(width / 2), int(height / 5),
                int(width / 4), height - int(height / 5) - 50))
            for crop in crops:
                command = ('{0} "{1}" "(" "{2}" -crop {3} -resize 200x200! ")"'
                           ' miff:- | {4} -metric AE - -fuzz 15% null:'
                          ).format(image_magick['convert'], color_file, file, crop,
                                   image_magick['compare'])
                compare = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
                _, err = compare.communicate()
                if re.match('^[0-9]+$', err):
                    different_pixels = int(err)
                    if different_pixels < 100:
                        match = True
                        break
        except Exception:
            logging.exception('Error checking frame color')
    if file not in frame_cache:
        frame_cache[file] = {}
    frame_cache[file][color_file] = bool(match)
    return match
def is_color_frame ( file , color_file ) : global frame_cache if file in frame_cache and color_file in frame_cache [ file ] : return bool ( frame_cache [ file ] [ color_file ] ) match = False if os . path . isfile ( color_file ) : try : from PIL import Image with Image . open ( file ) as img : width , height = img . size crops = [ ] # Middle crops . append ( '{0:d}x{1:d}+{2:d}+{3:d}' . format ( int ( width / 2 ) , int ( height / 3 ) , int ( width / 4 ) , int ( height / 3 ) ) ) # Top crops . append ( '{0:d}x{1:d}+{2:d}+{3:d}' . format ( int ( width / 2 ) , int ( height / 5 ) , int ( width / 4 ) , 50 ) ) # Bottom crops . append ( '{0:d}x{1:d}+{2:d}+{3:d}' . format ( int ( width / 2 ) , int ( height / 5 ) , int ( width / 4 ) , height - int ( height / 5 ) - 50 ) ) for crop in crops : command = ( '{0} "{1}" "(" "{2}" -crop {3} -resize 200x200! ")"' ' miff:- | {4} -metric AE - -fuzz 15% null:' ) . format ( image_magick [ 'convert' ] , color_file , file , crop , image_magick [ 'compare' ] ) compare = subprocess . Popen ( command , stderr = subprocess . PIPE , shell = True , universal_newlines = True ) _ , err = compare . communicate ( ) if re . match ( '^[0-9]+$' , err ) : different_pixels = int ( err ) if different_pixels < 100 : match = True break except Exception : logging . exception ( 'Error checking frame color' ) if file not in frame_cache : frame_cache [ file ] = { } frame_cache [ file ] [ color_file ] = bool ( match ) return match