okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e4309aaf3
main
1// src/image/vae/qi21_pixels.cpp - see include/strata/image/qi21_pixels.hpp. Contraction off for the file: v * 255 + 0.5 2// must round twice, as sd.cpp's x86 build computes it, on every compiler and CPU. 3#if defined(__clang__ ) 4#pragma clang fp contract(off) 5#elif defined(__GNUC__ ) 6#pragma GCC optimize("fp-contract=off") 7#endif 8 9#include "strata/image/qi21_pixels.hpp" 10 11#include <cstddef> 12 13namespace strata::image { 14 15uint8_t qi21_float_to_u8 (float v ) { 16if (v <=0.0f )return 0 ; 17if (v >=1.0f )return 255 ; 18volatile float m = v * 255.0f ;// its own rounding (volatile: no fused multiply-add on any compiler) 19return static_cast < uint8_t > (m + 0.5f ); 20} 21 22void qi21_picture_to_u8 (const float * planar ,int w ,int h ,int c ,uint8_t * out ) { 23const size_t px = (size_t )w * (size_t )h ; 24for (size_t i = 0 ;i < px ;++ i ) 25for (int k = 0 ;k < c ;++ k )out [i * c + k ]= qi21_float_to_u8 (planar [(size_t )k * px + i ]); 26} 27 28}// namespace strata::image