Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created August 10, 2012 11:30
Show Gist options
  • Select an option

  • Save zeffii/3313628 to your computer and use it in GitHub Desktop.

Select an option

Save zeffii/3313628 to your computer and use it in GitHub Desktop.
analyzing known fireflies
def is_firefly(rgba):
if (any(rgba) == 1.0) and (sum(rgba) > 3.8):
return True
""" found coordinates to look at """
pixels_of_interest = [[28,764]]
#[ [424,706], [178,864], [67,68], [58,110],
# [16,123], [21,169], [81,218], [49,422],
# [56,603], [29,637], [60,643], [31,686],
# [6, 720], [28,764]]
def rounded_rgba(rgba):
return ["{0:.4f}".format(component) for component in rgba]
print('-----------------')
for r,c in pixels_of_interest:
idx = co_to_idx(r, c, w)
rgba = rgba_from_index(idx, pxs)
rgba_str = rounded_rgba(rgba)
# print(r,c, '-->', rgba_str,'-->', is_firefly(rgba))
print('r={0:s}\ng={1:s}\nb={2:s}\na={3:s}\n'.format(*rgba_str))
# y,x = r,c # you might be familiar with the other way around x,y = c,r
import bpy
D = bpy.data
img = D.images['Chester mG_fireflies.tga']
pxs_slow = pixels = img.pixels
#recast, faster
pxs = list(pxs_slow)
w = width = img.size[0]
h = height = img.size[1]
num_pixels = len(pxs)
#equivalent statements
#gl = grouped_list = [pxs[i:i+4] for i in range(0, num_pixels, 4)]
gl = grouped_list = [pxs[i:i+4] for i in range(num_pixels)[::4]]
def idx_to_co(idx, width):
r = int(idx / width)
c = idx % width
return r, c
def co_to_idx(r, c, width):
return r * width + c
def rgba_from_index(idx, pxs):
start_raw_index = idx * 4
return pxs[start_raw_index:start_raw_index+4]
def is_firefly(rgba):
if (any(rgba) == 1.0) and (sum(rgba) > 3.8):
return True
""" found coordinates to look at """
pixels_of_interest = [
[424,706], [178,864], [67,68], [58,110],
[16,123], [21,169], [81,218], [49,422],
[56,603], [29,637], [60,643], [31,686],
[6, 720], [28,764]]
print('-----------------')
for r,c in pixels_of_interest:
idx = co_to_idx(r, c, w)
rgba = rgba_from_index(idx, pxs)
print(r,c, '-->', rgba,'-->', is_firefly(rgba))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment