mirror of
https://github.com/arsenetar/dupeguru.git
synced 2024-11-17 20:49:02 +00:00
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
|
#!/usr/bin/env python
|
||
|
# Unit Name: block
|
||
|
# Created By: Virgil Dupras
|
||
|
# Created On: 2009-05-10
|
||
|
# $Id$
|
||
|
# Copyright 2009 Hardcoded Software (http://www.hardcoded.net)
|
||
|
|
||
|
from _block import getblocks
|
||
|
|
||
|
# Converted to Cython
|
||
|
# def getblock(image):
|
||
|
# width = image.width()
|
||
|
# height = image.height()
|
||
|
# if width:
|
||
|
# pixel_count = width * height
|
||
|
# red = green = blue = 0
|
||
|
# s = image.bits().asstring(image.numBytes())
|
||
|
# for i in xrange(pixel_count):
|
||
|
# offset = i * 3
|
||
|
# red += ord(s[offset])
|
||
|
# green += ord(s[offset + 1])
|
||
|
# blue += ord(s[offset + 2])
|
||
|
# return (red // pixel_count, green // pixel_count, blue // pixel_count)
|
||
|
# else:
|
||
|
# return (0, 0, 0)
|
||
|
#
|
||
|
# def getblocks(image, block_count_per_side):
|
||
|
# width = image.width()
|
||
|
# height = image.height()
|
||
|
# if not width:
|
||
|
# return []
|
||
|
# block_width = max(width // block_count_per_side, 1)
|
||
|
# block_height = max(height // block_count_per_side, 1)
|
||
|
# result = []
|
||
|
# for ih in xrange(block_count_per_side):
|
||
|
# top = min(ih * block_height, height - block_height)
|
||
|
# for iw in range(block_count_per_side):
|
||
|
# left = min(iw * block_width, width - block_width)
|
||
|
# crop = image.copy(left, top, block_width, block_height)
|
||
|
# result.append(getblock(crop))
|
||
|
# return result
|