2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-25
|
2011-04-12 08:04:01 +00:00
|
|
|
# Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
import os.path as op
|
2009-12-15 16:54:47 +00:00
|
|
|
import logging
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-05-31 14:05:12 +00:00
|
|
|
from PyQt4.QtGui import QImage, QImageReader, QTransform
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-01-21 12:57:54 +00:00
|
|
|
from core_pe import data as data_pe, __appname__
|
2011-05-29 14:18:03 +00:00
|
|
|
from core_pe.photo import Photo as PhotoBase
|
2009-12-30 10:37:57 +00:00
|
|
|
from core_pe.scanner import ScannerPE
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
from ..base.app import DupeGuru as DupeGuruBase
|
|
|
|
from .block import getblocks
|
|
|
|
from .details_dialog import DetailsDialog
|
2011-01-15 15:29:35 +00:00
|
|
|
from .result_window import ResultWindow
|
2010-10-04 13:29:00 +00:00
|
|
|
from .preferences import Preferences
|
|
|
|
from .preferences_dialog import PreferencesDialog
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-05-29 14:18:03 +00:00
|
|
|
class File(PhotoBase):
|
2011-05-31 14:05:12 +00:00
|
|
|
def _plat_get_dimensions(self):
|
|
|
|
try:
|
|
|
|
ir = QImageReader(str(self.path))
|
|
|
|
size = ir.size()
|
|
|
|
if size.isValid():
|
|
|
|
return (size.width(), size.height())
|
|
|
|
else:
|
|
|
|
return (0, 0)
|
|
|
|
except EnvironmentError:
|
|
|
|
logging.warning("Could not read image '%s'", str(self.path))
|
|
|
|
return (0, 0)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-05-31 14:05:12 +00:00
|
|
|
def _plat_get_blocks(self, block_count_per_side, orientation):
|
2010-08-11 14:39:06 +00:00
|
|
|
image = QImage(str(self.path))
|
2009-06-01 09:55:11 +00:00
|
|
|
image = image.convertToFormat(QImage.Format_RGB888)
|
2011-05-31 14:05:12 +00:00
|
|
|
# MYSTERY TO SOLVE: For reasons I cannot explain, orientations 5 and 7 don't work for
|
|
|
|
# duplicate scanning. The transforms seems to work fine (if I try to save the image after
|
|
|
|
# the transform, we see that the image has been correctly flipped and rotated), but the
|
|
|
|
# analysis part yields wrong blocks. I spent enought time with this feature, so I'll leave
|
|
|
|
# like that for now. (by the way, orientations 5 and 7 work fine under Cocoa)
|
|
|
|
if 2 <= orientation <= 8:
|
|
|
|
t = QTransform()
|
|
|
|
if orientation == 2:
|
|
|
|
t.scale(-1, 1)
|
|
|
|
elif orientation == 3:
|
|
|
|
t.rotate(180)
|
|
|
|
elif orientation == 4:
|
|
|
|
t.scale(1, -1)
|
|
|
|
elif orientation == 5:
|
|
|
|
t.scale(-1, 1)
|
|
|
|
t.rotate(90)
|
|
|
|
elif orientation == 6:
|
|
|
|
t.rotate(90)
|
|
|
|
elif orientation == 7:
|
|
|
|
t.scale(-1, 1)
|
|
|
|
t.rotate(270)
|
|
|
|
elif orientation == 8:
|
|
|
|
t.rotate(270)
|
|
|
|
image = image.transformed(t)
|
2009-06-01 09:55:11 +00:00
|
|
|
return getblocks(image, block_count_per_side)
|
|
|
|
|
|
|
|
|
|
|
|
class DupeGuru(DupeGuruBase):
|
2010-04-07 16:04:58 +00:00
|
|
|
EDITION = 'pe'
|
2009-06-01 09:55:11 +00:00
|
|
|
LOGO_NAME = 'logo_pe'
|
2011-01-21 12:57:54 +00:00
|
|
|
NAME = __appname__
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2010-09-29 14:49:50 +00:00
|
|
|
DupeGuruBase.__init__(self, data_pe)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def _setup(self):
|
2009-10-18 09:26:04 +00:00
|
|
|
self.scanner = ScannerPE()
|
2009-10-23 15:04:37 +00:00
|
|
|
self.directories.fileclasses = [File]
|
2010-01-14 15:14:26 +00:00
|
|
|
self.scanner.cache_path = op.join(self.appdata, 'cached_pictures.db')
|
2009-06-01 09:55:11 +00:00
|
|
|
DupeGuruBase._setup(self)
|
|
|
|
|
|
|
|
def _update_options(self):
|
|
|
|
DupeGuruBase._update_options(self)
|
2011-04-21 15:17:19 +00:00
|
|
|
self.scanner.scan_type = self.prefs.scan_type
|
2009-10-18 09:26:04 +00:00
|
|
|
self.scanner.match_scaled = self.prefs.match_scaled
|
|
|
|
self.scanner.threshold = self.prefs.filter_hardness
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def _create_details_dialog(self, parent):
|
|
|
|
return DetailsDialog(parent, self)
|
|
|
|
|
2011-01-15 15:29:35 +00:00
|
|
|
def _create_result_window(self):
|
|
|
|
return ResultWindow(app=self)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def _create_preferences(self):
|
|
|
|
return Preferences()
|
|
|
|
|
|
|
|
def _create_preferences_dialog(self, parent):
|
|
|
|
return PreferencesDialog(parent, self)
|
|
|
|
|