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
1=== modified file 'phatch/actions/grid.py'
2--- phatch/actions/grid.py 2010-02-24 21:00:07 +0000
3+++ phatch/actions/grid.py 2010-02-27 17:23:15 +0000
4@@ -16,15 +16,19 @@
5
6 # Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).
7 # Based on standard Stani's actions
8-# This action is (C) 2010 by Pawel T. Jochym <jochym@gmail.com>
9+# Copyright (C) 2007-2008 www.stani.be
10+# Copyright (C) 2010 by Pawel T. Jochym <jochym@gmail.com>
11
12 # Make m x n grid with copies of imput image
13
14+# Follows PEP8
15+
16 from core import models
17 from core.translation import _t
18 from lib.imtools import has_transparency
19 from math import sqrt
20
21+
22 #---PIL
23 def init():
24 global Image
25@@ -32,20 +36,21 @@
26 global HTMLColorToRGBA
27 from lib.colors import HTMLColorToRGBA
28
29-def make_grid(image,grid,background_colour,old_size=None,scale=True):
30+
31+def make_grid(image, grid, background_colour, old_size=None, scale=True):
32 #check if there is any work to do
33 if grid[0] == 1 and grid[1] == 1:
34 return image
35 #because of layer support photo size can be different from image layer size
36 if old_size is None:
37- old_size = image.size
38- if scale :
39+ old_size = image.size
40+ if scale:
41 # Keep the same number of pixels in the result
42- s=sqrt(grid[0]*grid[1])
43- old_size = tuple(map(lambda x: int(x / s) , old_size))
44- image=image.resize( old_size, getattr(Image,'ANTIALIAS'))
45+ s = sqrt(grid[0] * grid[1])
46+ old_size = tuple(map(lambda x: int(x / s), old_size))
47+ image = image.resize(old_size, getattr(Image, 'ANTIALIAS'))
48
49- new_size=grid[0] * old_size[0], grid[1] * old_size[1]
50+ new_size = grid[0] * old_size[0], grid[1] * old_size[1]
51
52 #displacement
53 dx, dy = old_size
54@@ -55,50 +60,49 @@
55 if has_transparency(image) and image.mode != 'RGBA':
56 # Make sure 'LA' and 'P' with trasparency are handled
57 image = image.convert('RGBA')
58- else :
59+ else:
60 image = image.convert('RGB')
61
62- new_canvas = Image.new(image.mode,new_size,background_colour)
63+ new_canvas = Image.new(image.mode, new_size, background_colour)
64
65 for x in range(n):
66 for y in range(m):
67- new_canvas.paste(image,(x*dx,y*dy))
68-
69+ new_canvas.paste(image, (x * dx, y * dy))
70
71 return new_canvas
72
73
74 #---Phatch
75 class Action(models.Action):
76- label = _t('Grid')
77- all_layers = True
78- author = 'Pawel T. Jochym'
79- email = 'jochym@gmail.com'
80- init = staticmethod(init)
81- pil = staticmethod(make_grid)
82- version = '0.2'
83- tags = [_t('size'),_t('filter')]
84+ label = _t('Grid')
85+ all_layers = True
86+ author = 'Pawel T. Jochym'
87+ email = 'jochym@gmail.com'
88+ init = staticmethod(init)
89+ pil = staticmethod(make_grid)
90+ version = '0.2'
91+ tags = [_t('size'), _t('filter')]
92 update_size = True
93- __doc__ = _t('Make n x m grid of image')
94-
95- def interface(self,fields):
96- fields[_t('Width')] = self.SliderField(1,1,8)
97- fields[_t('Height')] = self.SliderField(1,1,8)
98- fields[_t('Background Color')] = self.ColorField('#FFFFFF')
99- fields[_t('Scale to keep size')] = self.BooleanField(True)
100-
101- def values(self,info):
102+ __doc__ = _t('Make n x m grid of image')
103+
104+ def interface(self, fields):
105+ fields[_t('Width')] = self.SliderField(1, 1, 8)
106+ fields[_t('Height')] = self.SliderField(1, 1, 8)
107+ fields[_t('Background Color')] = self.ColorField('#FFFFFF')
108+ fields[_t('Scale to keep size')] = self.BooleanField(True)
109+
110+ def values(self, info):
111 #size
112- x0, y0 = info['size']
113- x1 = self.get_field('Width',info)
114- y1 = self.get_field('Height',info)
115- grid = x1,y1
116+ x0, y0 = info['size']
117+ x1 = self.get_field('Width', info)
118+ y1 = self.get_field('Height', info)
119+ grid = x1, y1
120 #parameters
121 return {
122- 'old_size' : (x0,y0),
123- 'grid' : grid,
124- 'background_colour' : self.get_field('Background Color', info),
125- 'scale' : self.get_field('Scale to keep size', info),
126+ 'old_size': (x0, y0),
127+ 'grid': grid,
128+ 'background_colour': self.get_field('Background Color', info),
129+ 'scale': self.get_field('Scale to keep size', info),
130 }
131
132 icon = \
133
134=== modified file 'phatch/actions/warm_up.py'
135--- phatch/actions/warm_up.py 2010-02-24 21:00:07 +0000
136+++ phatch/actions/warm_up.py 2010-02-27 17:23:15 +0000
137@@ -10,7 +10,7 @@
138 # but WITHOUT ANY WARRANTY; without even the implied warranty of
139 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140 # GNU General Public License for more details.
141-#
142+#
143 # You should have received a copy of the GNU General Public License
144 # along with this program. If not, see http://www.gnu.org/licenses/
145 #
146@@ -18,72 +18,80 @@
147
148 # Embedded icon is designed by Igor Kekeljevic (http://www.admiror-ns.co.yu).
149 # Based on Stani's colorize
150-# This action is (C) 2010 by Pawel T. Jochym <jochym@gmail.com>
151-
152-# Make a colorized version of the image with midtone shifted to
153-# prescribed color value.
154+# Copyright (C) 2007-2008 www.stani.be
155+# Copyright (C) 2010 by Pawel T. Jochym <jochym@gmail.com>
156+
157+# Make a colorized version of the image with midtone shifted to
158+# prescribed color value.
159+
160+# Follows PEP8
161
162 from core import models
163 from core.translation import _t
164
165+
166 #---PIL
167 def init():
168 global Image, ImageMath, ImageColor, imtools
169- import Image, ImageMath, ImageColor
170- from lib import imtools
171-
172-def warmup(image,midtone,brighten,amount=100):
173+ import Image
174+ import ImageMath
175+ import ImageColor
176+ from lib import imtool
177+
178+
179+def warmup(image, midtone, brighten, amount=100):
180 """Apply a toning filter. Move the midtones to the desired
181- color while preserving blacks and whites with optional mixing
182+ color while preserving blacks and whites with optional mixing
183 with original image - amount: 0-100%"""
184-
185- mode=image.mode
186- info=image.info
187-
188+
189+ mode = image.mode
190+ info = image.info
191+
192 if image.mode != 'L':
193- im = imtools.convert(image,'L')
194+ im = imtools.convert(image, 'L')
195 else:
196 im = image
197
198 if imtools.has_transparency(image):
199- image = imtools.convert(image,'RGBA')
200-
201- luma=imtools.convert(im.split()[0],'F')
202+ image = imtools.convert(image, 'RGBA')
203+
204+ luma = imtools.convert(im.split()[0], 'F')
205 o = []
206 m = ImageColor.getrgb(midtone)
207 b = brighten / 600.0
208 # Calculate channels separately
209 for l in range(3):
210 o.append(ImageMath.eval(
211- "m*(255-i)*i+i",
212- i=luma,
213- m=4*((m[l]/255.0)-0.5+b)/255.0 ).convert('L'))
214-
215- colorized = Image.merge('RGB', tuple(o) )
216-
217+ "m*(255-i)*i+i",
218+ i=luma,
219+ m=4 * ((m[l] / 255.0) - 0.5 + b) / 255.0).convert('L'))
220+
221+ colorized = Image.merge('RGB', tuple(o))
222+
223 if imtools.has_alpha(image):
224 imtools.put_alpha(colorized, image.split()[-1])
225
226 if amount < 100:
227- colorized=imtools.blend(image, colorized, amount/100.0)
228-
229+ colorized = imtools.blend(image, colorized, amount / 100.0)
230+
231 return colorized
232
233+
234 #---Phatch
235 class Action(models.Action):
236- label = _t('Warm Up')
237- author = 'Pawel T. Jochym'
238- email = 'jochym@gmail.com'
239- init = staticmethod(init)
240- pil = staticmethod(warmup)
241- version = '0.2'
242- tags = [_t('filter'),_t('color')]
243- __doc__ = _t('Warm up or colorize midtones of an image')
244-
245- def interface(self,fields):
246- fields[_t('Midtone')] = self.ColorField('#805d40')
247- fields[_t('Brighten')] = self.SliderField(50,0,100)
248- fields[_t('Amount')] = self.SliderField(50,1,100)
249+ label = _t('Warm Up')
250+ author = 'Pawel T. Jochym'
251+ email = 'jochym@gmail.com'
252+ init = staticmethod(init)
253+ pil = staticmethod(warmup)
254+ version = '0.2'
255+ tags = [_t('filter'), _t('color')]
256+ __doc__ = _t('Warm up or colorize midtones of an image')
257+
258+ def interface(self, fields):
259+ fields[_t('Midtone')] = self.ColorField('#805d40')
260+ fields[_t('Brighten')] = self.SliderField(50, 0, 100)
261+ fields[_t('Amount')] = self.SliderField(50, 1, 100)
262
263 icon = \
264 '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: