okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e4309aaf3
main
1// src/image/vae/qi21_pixels_check_main.cpp - test program strata-pixels-check (not shipped): qi21_float_to_u8 on a 2// fixture of float values and the bytes stable-diffusion.cpp made of them. 3// 4// strata-pixels-check FILE... FILE: int32 n, then n float32 values, then n expected bytes 5#include "strata/image/qi21_pixels.hpp" 6 7#include <cstdint> 8#include <cstdio> 9#include <fstream> 10#include <vector> 11 12using namespace strata::image ; 13 14int main (int argc ,char ** argv ) { 15int bad = 0 ; 16for (int i = 1 ;i < argc ;++ i ) { 17 std::ifstream f (argv [i ], std::ios::binary ); 18int32_t n = 0 ; 19f .read ((char * )& n ,4 ); 20 std::vector < float > v (n > 0 ?n :0 ); 21 std::vector < uint8_t > want (v .size ()); 22f .read ((char * )v .data (),4 * (std::streamsize )v .size ()); 23f .read ((char * )want .data (), (std::streamsize )want .size ()); 24if (!f || n <=0 ) { 25 std::printf ("%s: cannot read\n" ,argv [i ]); 26++ bad ; 27continue ; 28 } 29size_t differ = 0 ; 30for (size_t k = 0 ;k < v .size ();++ k )differ += qi21_float_to_u8 (v [k ])!= want [k ]; 31 std::printf ("%s: %d values, %zu differ\n" ,argv [i ],n ,differ ); 32bad += differ != 0 ; 33 } 34 std::printf ("PIXELS-CHECK %s\n" ,bad || argc < 2 ?"FAIL" :"PASS" ); 35return bad || argc < 2 ?1 :0 ; 36}