Forked from zeffii/useful string formatting for debug.py
Created
February 11, 2020 08:07
-
-
Save niittymaa/af729e09bdbccbe0c6b147c541e34cf4 to your computer and use it in GitHub Desktop.
analyzing known fireflies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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