mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
[#67 state:fixed] Fixed block.pyx so it takes Qt pixel alignment into account.
--HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40172
This commit is contained in:
parent
df6c9b3740
commit
90e2e43f3e
@ -6,7 +6,7 @@
|
|||||||
# http://www.hardcoded.net/licenses/hs_license
|
# http://www.hardcoded.net/licenses/hs_license
|
||||||
|
|
||||||
cdef object getblock(object image):
|
cdef object getblock(object image):
|
||||||
cdef int width, height, pixel_count, red, green, blue, i, offset
|
cdef int width, height, pixel_count, red, green, blue, i, offset, bytes_per_line
|
||||||
cdef char *s
|
cdef char *s
|
||||||
cdef unsigned char r, g, b
|
cdef unsigned char r, g, b
|
||||||
width = image.width()
|
width = image.width()
|
||||||
@ -14,10 +14,15 @@ cdef object getblock(object image):
|
|||||||
if width:
|
if width:
|
||||||
pixel_count = width * height
|
pixel_count = width * height
|
||||||
red = green = blue = 0
|
red = green = blue = 0
|
||||||
|
bytes_per_line = image.bytesPerLine()
|
||||||
tmp = image.bits().asstring(image.numBytes())
|
tmp = image.bits().asstring(image.numBytes())
|
||||||
s = tmp
|
s = tmp
|
||||||
for i in range(pixel_count):
|
# Qt aligns all its lines on 32bit, which means that if the number of bytes per
|
||||||
offset = i * 3
|
# line for image is not divisible by 4, there's going to be crap inserted in "s"
|
||||||
|
# We have to take this into account when calculating offsets
|
||||||
|
for i in range(height):
|
||||||
|
for j in range(width):
|
||||||
|
offset = i * bytes_per_line + j * 3
|
||||||
r = s[offset]
|
r = s[offset]
|
||||||
g = s[offset + 1]
|
g = s[offset + 1]
|
||||||
b = s[offset + 2]
|
b = s[offset + 2]
|
||||||
@ -38,9 +43,9 @@ def getblocks(image, int block_count_per_side):
|
|||||||
block_height = max(height // block_count_per_side, 1)
|
block_height = max(height // block_count_per_side, 1)
|
||||||
result = []
|
result = []
|
||||||
for ih in range(block_count_per_side):
|
for ih in range(block_count_per_side):
|
||||||
top = min(ih * block_height, height - block_height)
|
top = min(ih*block_height, height-block_height-1)
|
||||||
for iw in range(block_count_per_side):
|
for iw in range(block_count_per_side):
|
||||||
left = min(iw * block_width, width - block_width)
|
left = min(iw*block_width, width-block_width-1)
|
||||||
crop = image.copy(left, top, block_width, block_height)
|
crop = image.copy(left, top, block_width, block_height)
|
||||||
result.append(getblock(crop))
|
result.append(getblock(crop))
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user