1-
21// https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/latent_formats.py#L152-L169
32const float flux_latent_rgb_proj [16 ][3 ] = {
43 {-0.0346f , 0.0244f , 0.0681f },
@@ -17,6 +16,7 @@ const float flux_latent_rgb_proj[16][3] = {
1716 {-0.1264f , -0.0522f , -0.1103f },
1817 {-0.0280f , -0.0881f , -0.0499f },
1918 {-0.1262f , -0.0982f , -0.0778f }};
19+ float flux_latent_rgb_bias [3 ] = {-0.0329 , -0.0718 , -0.0851 };
2020
2121// https://github.com/Stability-AI/sd3.5/blob/main/sd3_impls.py#L228-L246
2222const float sd3_latent_rgb_proj [16 ][3 ] = {
@@ -37,22 +37,25 @@ const float sd3_latent_rgb_proj[16][3] = {
3737 {-0.0749f , -0.0634f , -0.0456f },
3838 {-0.1418f , -0.1457f , -0.1259f },
3939};
40+ float sd3_latent_rgb_bias [3 ] = {0 , 0 , 0 };
4041
4142// https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/latent_formats.py#L32-L38
4243const float sdxl_latent_rgb_proj [4 ][3 ] = {
4344 {0.3651f , 0.4232f , 0.4341f },
4445 {-0.2533f , -0.0042f , 0.1068f },
4546 {0.1076f , 0.1111f , -0.0362f },
4647 {-0.3165f , -0.2492f , -0.2188f }};
48+ float sdxl_latent_rgb_bias [3 ] = {0.1084 , -0.0175 , -0.0011 };
4749
4850// https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/latent_formats.py#L32-L38
4951const float sd_latent_rgb_proj [4 ][3 ]{
5052 {0.3512f , 0.2297f , 0.3227f },
5153 {0.3250f , 0.4974f , 0.2350f },
5254 {-0.2829f , 0.1762f , 0.2721f },
5355 {-0.2120f , -0.2616f , -0.7177f }};
56+ float sd_latent_rgb_bias [3 ] = {0 ,0 ,0 };
5457
55- void preview_latent_image (uint8_t * buffer , struct ggml_tensor * latents , const float (* latent_rgb_proj )[3 ], int width , int height , int dim ) {
58+ void preview_latent_image (uint8_t * buffer , struct ggml_tensor * latents , const float (* latent_rgb_proj )[3 ], const float latent_rgb_bias [ 3 ], int width , int height , int dim ) {
5659 size_t buffer_head = 0 ;
5760 for (int j = 0 ; j < height ; j ++ ) {
5861 for (int i = 0 ; i < width ; i ++ ) {
@@ -64,6 +67,10 @@ void preview_latent_image(uint8_t* buffer, struct ggml_tensor* latents, const fl
6467 g += value * latent_rgb_proj [d ][1 ];
6568 b += value * latent_rgb_proj [d ][2 ];
6669 }
70+ // bias
71+ r += latent_rgb_bias [0 ];
72+ g += latent_rgb_bias [1 ];
73+ b += latent_rgb_bias [2 ];
6774
6875 // change range
6976 r = r * .5f + .5f ;
0 commit comments