~ubuntu-branches/ubuntu/natty/phatch/natty

« back to all changes in this revision

Viewing changes to phatch/actions/solarize.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2009-10-12 11:53:43 UTC
  • mfrom: (1.1.7 upstream) (4.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20091012115343-viftquwjkjx19mgz
Tags: 0.2.3-2
* phatch.desktop and menu files are now shipped by phatch package
  (LP: #449210)
  - add lintian overrides for above changes (phatch depends on phatch-cli so
    everything is ok)

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
# GNU General Public License for more details.
13
 
 
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program.  If not, see http://www.gnu.org/licenses/
16
16
#
20
20
 
21
21
from core import models
22
22
from lib.reverse_translation import _t
23
 
from lib.imtools import convert_safe_mode, has_alpha, put_alpha
24
23
 
25
24
#---PIL
26
25
def init():
27
 
    global Image, ImageOps
 
26
    global Image, ImageOps, imtools
28
27
    import Image, ImageOps
29
 
    
 
28
    from lib import imtools
 
29
 
30
30
def solarize(image,treshold,amount=100):
31
31
    """Apply a filter
32
32
    - amount: 0-1"""
33
 
    image = convert_safe_mode(image)
 
33
    image = imtools.convert_safe_mode(image)
34
34
    solarized  = image.convert('RGB')
35
35
    solarized   = ImageOps.solarize(solarized, treshold)
36
 
    if has_alpha(image):
37
 
        put_alpha(solarized, image.split()[-1])
 
36
    if imtools.has_alpha(image):
 
37
        imtools.put_alpha(solarized, image.split()[-1])
38
38
    if amount < 100:
39
 
        return Image.blend(image, solarized, amount/100.0)
 
39
        return imtools.blend(image, solarized, amount/100.0)
40
40
    return solarized
41
41
 
42
42
#---Phatch
49
49
    version     = '0.1'
50
50
    tags        = [_t('filter')]
51
51
    __doc__     = _t('Invert all pixel values above threshold')
52
 
    
 
52
 
53
53
    def interface(self,fields):
54
54
        fields[_t('Treshold')]   = self.SliderField(128,0,255)
55
55
        fields[_t('Amount')] = self.SliderField(100,1,100)
56
 
    
 
56
 
57
57
    icon = \
58
58
'x\xda\x01\xd3\x0b,\xf4\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\x00\
59
59
\x00\x000\x08\x06\x00\x00\x00W\x02\xf9\x87\x00\x00\x00\x04sBIT\x08\x08\x08\