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