Skip to content

Commit

Permalink
fixed exception, won't break on misformatted files in collection, add…
Browse files Browse the repository at this point in the history
…ed support for blacknwhite source images
  • Loading branch information
Abhishek Mishra committed Dec 13, 2009
1 parent 97357f5 commit b30d442
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pymos/core.py
Expand Up @@ -35,8 +35,12 @@ def build_colormap(files):
temp = Image.open(eachfile) temp = Image.open(eachfile)


red = green = blue = 0 red = green = blue = 0
imdata = list(temp.getdata()) try:
imdata_size = len(imdata) imdata = list(temp.getdata())
imdata_size = len(imdata)
except:
log.debug ("Error processing " + eachfile)
continue


try: try:
for i in imdata: for i in imdata:
Expand Down Expand Up @@ -83,12 +87,13 @@ def build_mosaic(input_path, output_path, collection_path,
if os.path.exists(colormap_file) and not new_colormap: if os.path.exists(colormap_file) and not new_colormap:
colormap = pickle.load(open(colormap_file)) colormap = pickle.load(open(colormap_file))
else: else:
try: #try:
colormap = build_colormap(files) colormap = build_colormap(files)
pickle.dump(colormap, open(colormap_file, 'w')) pickle.dump(colormap, open(colormap_file, 'w'))
except IOError: #except IOError:
log.info( "Error: Collection not found.") # log.info( "Error: Collection not found.")
sys.exit(1) # sys.exit(1)
# this exception might cause it to break even at x% of colormap build


log.info("Color Index built") log.info("Color Index built")


Expand All @@ -111,8 +116,11 @@ def build_mosaic(input_path, output_path, collection_path,
if (fuzz!=0): if (fuzz!=0):
source_color = tuple(s_x + random.randint(-fuzz, fuzz) source_color = tuple(s_x + random.randint(-fuzz, fuzz)
for s_x in source_color) for s_x in source_color)


r_1, g_1, b_1 = source_color if cmp(type(source_color).__name__, 'int') == 0:
r_1 = g_1 = b_1 = source_color
else:
r_1, g_1, b_1 = source_color


# euclidean distance, color, index in colormap # euclidean distance, color, index in colormap
match = (196608, (555, 555, 555), 0)# initially something out of range match = (196608, (555, 555, 555), 0)# initially something out of range
Expand Down

0 comments on commit b30d442

Please sign in to comment.