Changeset 7
- Timestamp:
- 09/23/07 11:59:05 (1 year ago)
- Files:
-
- config.py (modified) (1 diff)
- mactorii.py (modified) (5 diffs)
- osx_pyx_setup.sh (added)
- pyx.pyx (added)
- pyx_setup.py (added)
- wavelet.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
config.py
r6 r7 11 11 import os 12 12 13 taps = 1613 taps = 64 14 14 weights = (1,0.5, 0.75) 15 15 img_size = (256, 256) 16 16 crop_size= 100 17 17 tmp_file=".89885e5234e2f0ae1e2015642425d1eb.jpg" 18 font_size=12 19 font_name="Monaco" 18 20 def main(): 19 21 pass mactorii.py
r6 r7 10 10 import sys 11 11 import os 12 import math 13 import Image 12 14 13 15 import wavelet … … 18 20 from pyglet import image as pyglet_image 19 21 from pyglet import clock 22 from pyglet.window import key 23 from pyglet.window import mouse 24 from pyglet import font 25 26 files = None 27 win = None 20 28 21 29 yoffset = 0 22 30 xoffset = 0 23 rows = 0 31 rows = 1 32 xmotion = 0 33 34 clickx = 0 35 clicky = 0 36 37 hoverx = 0 38 hovery = 0 39 40 selected = None 41 42 def on_mouse_motion(x,y,dx,dy): 43 global hoverx 44 global hovery 45 46 hoverx = x 47 hovery = y 48 49 def on_mouse_press(x, y, button, modifiers): 50 global clickx 51 global clicky 52 53 if button == mouse.LEFT: 54 clickx = x 55 clicky = y 56 57 def on_mouse_release(x,y,button, modifiers): 58 global clickx 59 global clicky 60 61 return 62 if button == mouse.LEFT: 63 clickx = -1 64 clicky = -1 65 66 def on_key_release(symbol, modifier): 67 global xoffset 68 global xmotion 69 70 if symbol == key.LEFT: 71 xmotion = 0 72 73 if symbol == key.RIGHT: 74 xmotion = 0 75 76 def on_key_press(symbol, modifier): 77 global xoffset 78 global xmotion 79 80 if symbol == key.LEFT: 81 xmotion = 10 82 83 if symbol == key.RIGHT: 84 xmotion -= 10 85 86 def strip_width(): 87 """returns the width of the strip in pixels""" 88 global rows 89 return math.ceil(1.0 * len(files)/rows) * config.crop_size 24 90 25 91 def on_resize(width, height): … … 29 95 global rows 30 96 31 rows = int(height/config.crop_size) 97 p = xoffset/strip_width() 98 99 rows = int(height/config.crop_size) 32 100 33 101 yoffset = (height - rows * config.crop_size)/2 34 102 yoffset = height-yoffset-config.crop_size 35 103 36 def main(): 37 global xoffset 38 global yoffset 39 global rows 40 41 files = sys.argv[1:] 104 # compute the new xoffset 105 xoffset = p * strip_width() 106 107 def sort_func(item): 108 assert selected != None 109 110 selected_sig = selected[2] 111 item_sig = item[1][2] 112 113 score = [] 114 for b in xrange(3): 115 score.append(config.weights[b]*len(selected_sig[b].intersection(item_sig[b]))) 116 return -sum(score) 117 118 def load_files(files): 119 """loads the files given in the command line""" 42 120 images = dict() 121 43 122 for file in files: 44 123 print "processing file: %s"%(file) 45 124 wi = wavelet.open(file) 46 125 sig = wi.signature() 47 wi.cleanup() 48 img = pyglet_image.load(file) 49 region = img.get_region(x=img.width/2-config.crop_size/2, \ 50 y=img.height/2-config.crop_size/2, \ 51 width=config.crop_size, height=config.crop_size) 52 images[file] = (region, img, 0) 53 54 126 wi.im.thumbnail((config.crop_size, config.crop_size)) 127 wi.im.save(config.tmp_file) 128 129 thumbnail = pyglet_image.load(config.tmp_file) 130 131 images[file] = (thumbnail, None, sig, wi.size) 132 133 return images 134 135 def window_setup(): 136 """sets up our window""" 55 137 win = window.Window(resizable=True, visible=False) 138 56 139 win.push_handlers(on_resize) 140 win.push_handlers(on_key_press) 141 win.push_handlers(on_key_release) 142 win.push_handlers(on_mouse_press) 143 win.push_handlers(on_mouse_release) 144 win.push_handlers(on_mouse_motion) 145 146 win.set_visible() 147 148 return win 149 150 def font_setup(): 151 """sets up fonts""" 152 return font.load(config.font_name, config.font_size) 153 154 def is_over_image(x, y, mousex, mousey): 155 if mousex < 0 or mousey < 0: 156 return False 157 158 if mousex < x or mousex > x + config.crop_size: 159 return False 160 161 if mousey < y or mousey > y + config.crop_size: 162 return False 163 164 return True 165 166 def main(): 167 global xoffset 168 global xmotion 169 global yoffset 170 global rows 171 global files 172 global win 173 global clickx 174 global clicky 175 global hoverx 176 global hovery 177 global selected 178 179 files = sys.argv[1:] 180 images = load_files(files) 181 182 win = window_setup() 183 ft = font_setup() 184 185 assert win != None 186 assert ft != None 57 187 58 188 clock.set_fps_limit(30) 59 win.set_visible() 189 190 renderables = images.items() 191 60 192 while not win.has_exit: 61 193 clock.tick() … … 63 195 glClear(GL_COLOR_BUFFER_BIT) 64 196 65 x = xoffset 197 if xmotion < 0: 198 if strip_width() + xoffset > win.width: 199 xoffset+=xmotion 200 201 if xmotion > 0: 202 if xoffset < 0: 203 xoffset+=xmotion 204 205 x = xoffset 66 206 y = yoffset 207 pix_name = None 208 pix_size = None 209 67 210 drawn = 0 68 for image in images.values():211 for filename, image in renderables: 69 212 img = image[0] 70 213 img.blit(x,y) 71 214 215 if is_over_image(x,y,clickx, clicky): 216 print "%s selected"%(filename) 217 selected = image 218 renderables.sort(key=sort_func) 219 220 clickx = -1 221 clicky = -1 222 223 xoffset = 0 224 break 225 226 if is_over_image(x,y,hoverx, hovery): 227 pix_name = font.Text(ft, filename, hoverx, hovery+config.font_size+5) 228 pix_size = font.Text(ft, "%dx%d"%(image[3][0], image[3][0]), hoverx, hovery+5) 72 229 drawn+=1 73 230 y-=config.crop_size … … 76 233 x+=config.crop_size 77 234 y = yoffset 235 if pix_name: 236 pix_name.draw() 237 if pix_size: 238 pix_size.draw() 78 239 79 240 win.flip() wavelet.py
r6 r7 11 11 import os 12 12 import Image 13 13 14 import config 15 import pyx 14 16 15 17 def open(path): … … 32 34 33 35 im = Image.open(path) 34 im = im.resize(config.img_size) 36 self.size = im.size 37 38 im.thumbnail(config.img_size) 35 39 im = im.convert("RGB") 36 im = im.convert("RGB", rgb2yiq)37 40 38 self.data = im. getdata()39 self.im = Image.open(path)41 self.data = im.convert("RGB", rgb2yiq).getdata() 42 self.im = im 40 43 self.wavelets = None 41 44 self.sig = None … … 133 136 input = list(self.data) 134 137 135 self.wavelets = self.transform_array(input) 138 #self.wavelets = self.transform_array(input) 139 self.wavelets = pyx.pyx_transform_array(input) 136 140 return 137 141
