okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-5b adfcf9028 into f-own-int (round 16: the strata-image test program and its parts, DiT runner, sampler, noise, PNG writer; hooked into no build)e4309aaf3

main
1.3 KiB36 linesraw
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) {
15    int bad = 0;
16    for (int i = 1; i < argc; ++i) {
17        std::ifstream f(argv[i], std::ios::binary);
18        int32_t n = 0;
19        f.read((char*) &n, 4);
20        std::vector<float> v(n > 0 ? n : 0);
21        std::vector<uint8_t> want(v.size());
22        f.read((char*) v.data(), 4 * (std::streamsize) v.size());
23        f.read((char*) want.data(), (std::streamsize) want.size());
24        if (!f || n <= 0) {
25            std::printf("%s: cannot read\n", argv[i]);
26            ++bad;
27            continue;
28        }
29        size_t differ = 0;
30        for (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);
32        bad += differ != 0;
33    }
34    std::printf("PIXELS-CHECK %s\n", bad || argc < 2 ? "FAIL" : "PASS");
35    return bad || argc < 2 ? 1 : 0;
36}