Merge lp:~jochym/phatch/pep8 into lp:phatch

Proposed by Paweł T. Jochym
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jochym/phatch/pep8
Merge into: lp:phatch
Diff against target: 264 lines (+88/-76)
2 files modified
phatch/actions/grid.py (+41/-37)
phatch/actions/warm_up.py (+47/-39)
To merge this branch: bzr merge lp:~jochym/phatch/pep8
Reviewer Review Type Date Requested Status
Stani Needs Information
Review via email: mp+20276@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paweł T. Jochym (jochym) wrote :

PEP8 compliance for warm_up and grid actions.
Both pass pep8.py test.
Stani's copyrights added as appropriate.

Revision history for this message
Stani (stani) wrote :

The PEP8 fix is fine, but I am now doing code review.

Can you tell me in which case the background color is used in the grid action?

review: Needs Information
Revision history for this message
Paweł T. Jochym (jochym) wrote :

stani pisze:
> Review: Needs Information
> The PEP8 fix is fine, but I am now doing code review.
>
> Can you tell me in which case the background color is used in the grid action?

It is set as background in new canvas (line 66). If pictures have
transparency it shows through.

--
Paweł T. Jochym
Institute of Nuclear Physics, PAN
Cracow, Poland

Revision history for this message
Stani (stani) wrote :

Hmmm... I think the background color should never show through the
pictures. If I want to make a grid with transparent pictures, I like
them to remain transparent as they are without adding any color. It
should only be used for the border color (color in between images), eg
when you scale to the original image and you select 4x2 grid. So the
background color should be shown conditionally if n!=m.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'phatch/actions/grid.py'
--- phatch/actions/grid.py 2010-02-24 21:00:07 +0000
+++ phatch/actions/grid.py 2010-02-27 17:23:15 +0000
@@ -16,15 +16,19 @@
1616
17# Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).17# Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).
18# Based on standard Stani's actions18# Based on standard Stani's actions
19# This action is (C) 2010 by Pawel T. Jochym <jochym@gmail.com>19# Copyright (C) 2007-2008 www.stani.be
20# Copyright (C) 2010 by Pawel T. Jochym <jochym@gmail.com>
2021
21# Make m x n grid with copies of imput image22# Make m x n grid with copies of imput image
2223
24# Follows PEP8
25
23from core import models26from core import models
24from core.translation import _t27from core.translation import _t
25from lib.imtools import has_transparency28from lib.imtools import has_transparency
26from math import sqrt29from math import sqrt
2730
31
28#---PIL32#---PIL
29def init():33def init():
30 global Image34 global Image
@@ -32,20 +36,21 @@
32 global HTMLColorToRGBA36 global HTMLColorToRGBA
33 from lib.colors import HTMLColorToRGBA37 from lib.colors import HTMLColorToRGBA
3438
35def make_grid(image,grid,background_colour,old_size=None,scale=True):39
40def make_grid(image, grid, background_colour, old_size=None, scale=True):
36 #check if there is any work to do41 #check if there is any work to do
37 if grid[0] == 1 and grid[1] == 1:42 if grid[0] == 1 and grid[1] == 1:
38 return image43 return image
39 #because of layer support photo size can be different from image layer size44 #because of layer support photo size can be different from image layer size
40 if old_size is None:45 if old_size is None:
41 old_size = image.size46 old_size = image.size
42 if scale :47 if scale:
43 # Keep the same number of pixels in the result48 # Keep the same number of pixels in the result
44 s=sqrt(grid[0]*grid[1])49 s = sqrt(grid[0] * grid[1])
45 old_size = tuple(map(lambda x: int(x / s) , old_size))50 old_size = tuple(map(lambda x: int(x / s), old_size))
46 image=image.resize( old_size, getattr(Image,'ANTIALIAS'))51 image = image.resize(old_size, getattr(Image, 'ANTIALIAS'))
4752
48 new_size=grid[0] * old_size[0], grid[1] * old_size[1]53 new_size = grid[0] * old_size[0], grid[1] * old_size[1]
4954
50 #displacement55 #displacement
51 dx, dy = old_size56 dx, dy = old_size
@@ -55,50 +60,49 @@
55 if has_transparency(image) and image.mode != 'RGBA':60 if has_transparency(image) and image.mode != 'RGBA':
56 # Make sure 'LA' and 'P' with trasparency are handled61 # Make sure 'LA' and 'P' with trasparency are handled
57 image = image.convert('RGBA')62 image = image.convert('RGBA')
58 else :63 else:
59 image = image.convert('RGB')64 image = image.convert('RGB')
6065
61 new_canvas = Image.new(image.mode,new_size,background_colour)66 new_canvas = Image.new(image.mode, new_size, background_colour)
6267
63 for x in range(n):68 for x in range(n):
64 for y in range(m):69 for y in range(m):
65 new_canvas.paste(image,(x*dx,y*dy))70 new_canvas.paste(image, (x * dx, y * dy))
66
6771
68 return new_canvas72 return new_canvas
6973
7074
71#---Phatch75#---Phatch
72class Action(models.Action):76class Action(models.Action):
73 label = _t('Grid')77 label = _t('Grid')
74 all_layers = True78 all_layers = True
75 author = 'Pawel T. Jochym'79 author = 'Pawel T. Jochym'
76 email = 'jochym@gmail.com'80 email = 'jochym@gmail.com'
77 init = staticmethod(init)81 init = staticmethod(init)
78 pil = staticmethod(make_grid)82 pil = staticmethod(make_grid)
79 version = '0.2'83 version = '0.2'
80 tags = [_t('size'),_t('filter')]84 tags = [_t('size'), _t('filter')]
81 update_size = True85 update_size = True
82 __doc__ = _t('Make n x m grid of image')86 __doc__ = _t('Make n x m grid of image')
8387
84 def interface(self,fields):88 def interface(self, fields):
85 fields[_t('Width')] = self.SliderField(1,1,8)89 fields[_t('Width')] = self.SliderField(1, 1, 8)
86 fields[_t('Height')] = self.SliderField(1,1,8)90 fields[_t('Height')] = self.SliderField(1, 1, 8)
87 fields[_t('Background Color')] = self.ColorField('#FFFFFF')91 fields[_t('Background Color')] = self.ColorField('#FFFFFF')
88 fields[_t('Scale to keep size')] = self.BooleanField(True)92 fields[_t('Scale to keep size')] = self.BooleanField(True)
8993
90 def values(self,info):94 def values(self, info):
91 #size95 #size
92 x0, y0 = info['size']96 x0, y0 = info['size']
93 x1 = self.get_field('Width',info)97 x1 = self.get_field('Width', info)
94 y1 = self.get_field('Height',info)98 y1 = self.get_field('Height', info)
95 grid = x1,y199 grid = x1, y1
96 #parameters100 #parameters
97 return {101 return {
98 'old_size' : (x0,y0),102 'old_size': (x0, y0),
99 'grid' : grid,103 'grid': grid,
100 'background_colour' : self.get_field('Background Color', info),104 'background_colour': self.get_field('Background Color', info),
101 'scale' : self.get_field('Scale to keep size', info),105 'scale': self.get_field('Scale to keep size', info),
102 }106 }
103107
104 icon = \108 icon = \
105109
=== modified file 'phatch/actions/warm_up.py'
--- phatch/actions/warm_up.py 2010-02-24 21:00:07 +0000
+++ phatch/actions/warm_up.py 2010-02-27 17:23:15 +0000
@@ -10,7 +10,7 @@
10# but WITHOUT ANY WARRANTY; without even the implied warranty of10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see http://www.gnu.org/licenses/15# along with this program. If not, see http://www.gnu.org/licenses/
16#16#
@@ -18,72 +18,80 @@
1818
19# Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).19# Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).
20# Based on Stani's colorize20# Based on Stani's colorize
21# This action is (C) 2010 by Pawel T. Jochym <jochym@gmail.com>21# Copyright (C) 2007-2008 www.stani.be
2222# Copyright (C) 2010 by Pawel T. Jochym <jochym@gmail.com>
23# Make a colorized version of the image with midtone shifted to 23
24# prescribed color value. 24# Make a colorized version of the image with midtone shifted to
25# prescribed color value.
26
27# Follows PEP8
2528
26from core import models29from core import models
27from core.translation import _t30from core.translation import _t
2831
32
29#---PIL33#---PIL
30def init():34def init():
31 global Image, ImageMath, ImageColor, imtools35 global Image, ImageMath, ImageColor, imtools
32 import Image, ImageMath, ImageColor36 import Image
33 from lib import imtools37 import ImageMath
34 38 import ImageColor
35def warmup(image,midtone,brighten,amount=100):39 from lib import imtool
40
41
42def warmup(image, midtone, brighten, amount=100):
36 """Apply a toning filter. Move the midtones to the desired43 """Apply a toning filter. Move the midtones to the desired
37 color while preserving blacks and whites with optional mixing 44 color while preserving blacks and whites with optional mixing
38 with original image - amount: 0-100%"""45 with original image - amount: 0-100%"""
39 46
40 mode=image.mode47 mode = image.mode
41 info=image.info48 info = image.info
42 49
43 if image.mode != 'L':50 if image.mode != 'L':
44 im = imtools.convert(image,'L')51 im = imtools.convert(image, 'L')
45 else:52 else:
46 im = image53 im = image
4754
48 if imtools.has_transparency(image):55 if imtools.has_transparency(image):
49 image = imtools.convert(image,'RGBA')56 image = imtools.convert(image, 'RGBA')
50 57
51 luma=imtools.convert(im.split()[0],'F')58 luma = imtools.convert(im.split()[0], 'F')
52 o = []59 o = []
53 m = ImageColor.getrgb(midtone)60 m = ImageColor.getrgb(midtone)
54 b = brighten / 600.061 b = brighten / 600.0
55 # Calculate channels separately62 # Calculate channels separately
56 for l in range(3):63 for l in range(3):
57 o.append(ImageMath.eval(64 o.append(ImageMath.eval(
58 "m*(255-i)*i+i", 65 "m*(255-i)*i+i",
59 i=luma, 66 i=luma,
60 m=4*((m[l]/255.0)-0.5+b)/255.0 ).convert('L'))67 m=4 * ((m[l] / 255.0) - 0.5 + b) / 255.0).convert('L'))
61 68
62 colorized = Image.merge('RGB', tuple(o) )69 colorized = Image.merge('RGB', tuple(o))
63 70
64 if imtools.has_alpha(image):71 if imtools.has_alpha(image):
65 imtools.put_alpha(colorized, image.split()[-1])72 imtools.put_alpha(colorized, image.split()[-1])
6673
67 if amount < 100:74 if amount < 100:
68 colorized=imtools.blend(image, colorized, amount/100.0)75 colorized = imtools.blend(image, colorized, amount / 100.0)
69 76
70 return colorized77 return colorized
7178
79
72#---Phatch80#---Phatch
73class Action(models.Action):81class Action(models.Action):
74 label = _t('Warm Up')82 label = _t('Warm Up')
75 author = 'Pawel T. Jochym'83 author = 'Pawel T. Jochym'
76 email = 'jochym@gmail.com'84 email = 'jochym@gmail.com'
77 init = staticmethod(init)85 init = staticmethod(init)
78 pil = staticmethod(warmup)86 pil = staticmethod(warmup)
79 version = '0.2'87 version = '0.2'
80 tags = [_t('filter'),_t('color')]88 tags = [_t('filter'), _t('color')]
81 __doc__ = _t('Warm up or colorize midtones of an image')89 __doc__ = _t('Warm up or colorize midtones of an image')
82 90
83 def interface(self,fields):91 def interface(self, fields):
84 fields[_t('Midtone')] = self.ColorField('#805d40')92 fields[_t('Midtone')] = self.ColorField('#805d40')
85 fields[_t('Brighten')] = self.SliderField(50,0,100)93 fields[_t('Brighten')] = self.SliderField(50, 0, 100)
86 fields[_t('Amount')] = self.SliderField(50,1,100)94 fields[_t('Amount')] = self.SliderField(50, 1, 100)
8795
88 icon = \96 icon = \
89'x\xda\x01<\n\xc3\xf5\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\x00\97'x\xda\x01<\n\xc3\xf5\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\x00\

Subscribers

People subscribed via source and target branches

to status/vote changes: