Atlas - render.cpp

Home / usr / vishash / src Lines: 7 | Size: 1916 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* SPDX-License-Identifier: GPL-3.0 2 * VisHash - An easy way to visualise hashes 3 * 4 * render.cpp 5 * 6 * COPYRIGHT NOTICE 7 * Copyright (C) 2025 0x4248 and contributors 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the license is not changed. 10 * 11 * This software is free and open source. Licensed under the GNU general 12 * public license version 3.0 as published by the Free Software Foundation. 13*/ 14 15#include <vector> 16#include <openssl/sha.h> 17#include <iostream> 18#include <fstream> 19#include "image.h" 20 21/** 22 * Draw to TTY 23 */ 24void draw(const std::vector<std::vector<int>> &grid, const std::string &label) { 25 26 int maxv = 0; 27 for (auto &row : grid) 28 for (int v : row) 29 maxv = std::max(maxv, v); 30 31 32 for (int y = 0; y < H; ++y) { 33 for (int x = 0; x < W; ++x) { 34 std::cout << level_to_char(grid[y][x], maxv); 35 } 36 std::cout << "\n"; 37 } 38 39} 40 41/** 42 * Basically prints out the values for debugging 43 */ 44void print_values(const std::vector<std::vector<int>>& grid) { 45 int H = grid.size(); 46 int W = grid[0].size(); 47 for (int y = 0; y < H; y++) { 48 for (int x = 0; x < W; x++) { 49 std::cout << grid[y][x]; 50 } 51 std::cout << "\n"; 52 } 53} 54 55void savePPM(const std::vector<std::vector<int>>& grid, const std::string& filename) 56{ 57 int H = grid.size(); 58 int W = grid[0].size(); 59 60 int maxv = 0; 61 for (auto& row : grid) 62 for (int v : row) 63 maxv = std::max(maxv, v); 64 65 std::ofstream out(filename); 66 out << "P3\n" << W << " " << H << "\n255\n"; 67 68 for (int y = 0; y < H; y++) { 69 for (int x = 0; x < W; x++) { 70 float t = (float)grid[y][x] / (float)maxv; 71 72 int v = (int)(t * 255); /* Can be changed for intensity */ 73 74 out << v << " " << v << " " << v << " "; 75 } 76 out << "\n"; 77 } 78} 79
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.