Atlas - image.cpp
Home / usr / vishash / src Lines: 1 | Size: 2411 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 * image.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 <cstring> 18#include <cmath> 19 20#include "const.h" 21 22std::vector<std::vector<int>> heatmap(const std::vector<uint8_t> &digest) { 23 std::vector<std::vector<int>> grid(H, std::vector<int>(W, 0)); 24 25 uint8_t buf[SHA256_DIGEST_LENGTH]; 26 memcpy(buf, digest.data(), digest.size()); 27 28 int samples = H * W * 3; 29 for (int i = 0; i < samples; i++) { 30 uint8_t tmp[SHA256_DIGEST_LENGTH]; 31 SHA256(buf, SHA256_DIGEST_LENGTH, tmp); 32 memcpy(buf, tmp, SHA256_DIGEST_LENGTH); 33 34 35 int y = buf[0] % H; 36 int x = buf[1] % W; 37 38 grid[y][x]++; 39 } 40 41 return grid; 42} 43 44std::vector<std::vector<int>> blur(const std::vector<std::vector<int>>& grid) { 45 std::vector<std::vector<int>> out = grid; 46 47 static int kernel[3][3] = { 48 {1, 2, 1}, 49 {2, 4, 2}, 50 {1, 2, 1} 51 }; 52 53 int H = grid.size(); 54 int W = grid[0].size(); 55 56 for (int y = 0; y < H; y++) { 57 for (int x = 0; x < W; x++) { 58 59 int sum = 0, weight = 0; 60 for (int dy = -1; dy <= 1; dy++) { 61 for (int dx = -1; dx <= 1; dx++) { 62 int ny = y + dy; 63 int nx = x + dx; 64 if (ny >= 0 && ny < H && nx >= 0 && nx < W) { 65 int w = kernel[dy+1][dx+1]; 66 sum += grid[ny][nx] * w; 67 weight += w; 68 } 69 } 70 } 71 72 out[y][x] = sum / weight; 73 } 74 } 75 76 return out; 77} 78 79int apply_contrast(int v, int maxv, double gamma = 1.8) { 80 if (maxv == 0) return 0; 81 double norm = (double)v / maxv; 82 norm = pow(norm, gamma); 83 return (int)(norm * maxv); 84} 85 86char level_to_char(int level, int maxLevel) 87{ 88 if (maxLevel == 0) return ' '; 89 90 int adjusted = apply_contrast(level, maxLevel, 1.8); 91 92 int idx = (adjusted * (RAMP.size() - 1)) / maxLevel; 93 return RAMP[idx]; 94} 95[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.