pusho per testare nel threadripper

This commit is contained in:
2025-02-08 19:15:34 +01:00
parent 8f360421f2
commit 7c242fabfa
12 changed files with 617 additions and 52 deletions

75
visualizzatore.h Normal file
View File

@@ -0,0 +1,75 @@
#include <allegro.h>
#include "percettroni.h"
#define IMAGE_WIDTH 32
#define IMAGE_HEIGHT 32
#define SCALE_FACTOR 2
BITMAP *buffer;
BITMAP *image;
void init_allegro() {
allegro_init();
install_keyboard();
install_mouse();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
buffer = create_bitmap(800,600);
image = create_bitmap(IMAGE_WIDTH, IMAGE_HEIGHT);
show_mouse(screen);
}
void load_current_image(Dataset *set) {
int indice = rand()%set->size;
for (int y = 0; y < IMAGE_HEIGHT; y++) {
for (int x = 0; x < IMAGE_WIDTH; x++) {
int r = set->istanze[indice].immagine[y * IMAGE_WIDTH + x];
int g = set->istanze[indice].immagine[1024 + y * IMAGE_WIDTH + x];
int b = set->istanze[indice].immagine[2048 + y * IMAGE_WIDTH + x];
putpixel(image, x, y, makecol(r, g, b));
}
}
}
void draw_interface() {
clear_to_color(buffer, makecol(255, 255, 255));
// Calcola la posizione per centrare l'immagine ingrandita
int scaled_width = IMAGE_WIDTH * SCALE_FACTOR;
int scaled_height = IMAGE_HEIGHT * SCALE_FACTOR;
int image_x = (800 - scaled_width) / 2;
int image_y = (600 - scaled_height) / 2 - 20; // Sposta leggermente sopra per fare spazio al pulsante
// Disegna l'immagine ingrandita
stretch_blit(image, buffer, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, image_x, image_y, scaled_width, scaled_height);
// Disegna il pulsante "prossima"
int button_width = 150;
int button_height = 40;
int button_x = (800 - button_width) / 2;
int button_y = 600 - 60; // Posizione in basso
rectfill(buffer, button_x, button_y, button_x + button_width, button_y + button_height, makecol(200, 200, 200));
textout_centre_ex(buffer, font, "prossima", button_x + button_width / 2, button_y + 10, makecol(0, 0, 0), -1);
// Copia il buffer sullo schermo
blit(buffer, screen, 0, 0, 0, 0, 800, 600);
}
void handle_input(Dataset *set) {
if (mouse_b & 1) {
int mx = mouse_x;
int my = mouse_y;
// Coordinate del pulsante
int button_width = 150;
int button_height = 40;
int button_x = (800 - button_width) / 2;
int button_y = 600 - 60;
// Controlla se il clic è avvenuto sul pulsante
if (mx >= button_x && mx <= button_x + button_width && my >= button_y && my <= button_y + button_height) {
load_current_image(set);
rest(200); // Debounce
}
}
}