@@ -25,6 +25,7 @@ def main(arguments):
25
25
parser .add_argument ("-n" , "--num-samples" , type = int , default = 256 , help = "The number of samples to generate." )
26
26
parser .add_argument ("-a" , "--include-alpha" , action = "store_true" , help = "Include the alpha channel in the output." )
27
27
parser .add_argument ("-l" , "--linearize" , action = "store_true" , help = "Output linear (instead of sRGB encoded) values." )
28
+ parser .add_argument ("-b" , "--bit-depth" , type = int , choices = [8 , 16 , 32 ], default = 32 , help = "Bit depth of the output values." )
28
29
29
30
args = parser .parse_args (arguments )
30
31
@@ -40,9 +41,17 @@ def main(arguments):
40
41
if args .include_alpha :
41
42
values = np .column_stack ((values , alpha ))
42
43
43
- values = ",\n " .join (["{" + ", " .join ([str (y ) + "f" for y in x ]) + "}" for x in values ]) + ","
44
- print (f"static const std::vector<float4> data = {{\n { values } \n }};" )
45
-
44
+ if args .bit_depth == 8 :
45
+ values = (values * 255 ).astype (int )
46
+ values = ",\n " .join (["IM_COL32(" + ", " .join ([str (y ) for y in x ]) + ")" for x in values ]) + ","
47
+ print (f"static const std::vector<ImU32> data = {{\n { values } \n }};" )
48
+ elif args .bit_depth == 16 :
49
+ values = (values * 65535 ).astype (int )
50
+ values = ",\n " .join (["{" + ", " .join ([str (y ) for y in x ]) + "}" for x in values ]) + ","
51
+ print (f"static const std::vector<ushort4> data = {{\n { values } \n }};" )
52
+ else :
53
+ values = ",\n " .join (["{" + ", " .join ([f"{ y :.6f} f" for y in x ]) + "}" for x in values ]) + ","
54
+ print (f"static const std::vector<float4> data = {{\n { values } \n }};" )
46
55
47
56
if __name__ == "__main__" :
48
57
sys .exit (main (sys .argv [1 :]))
0 commit comments