eliminat molt de ruido de la consola de log

This commit is contained in:
2026-04-14 13:04:24 +02:00
parent f5da35bfb2
commit cf7ea6cc9c
27 changed files with 144 additions and 383 deletions

View File

@@ -2,6 +2,7 @@
#include <SDL3/SDL.h> // Para SDL_LogError, SDL_LogCategory, SDL_LogInfo
#include <cstring> // Para memcpy, size_t
#include <iostream> // Para std::cout
#include <stdexcept> // Para runtime_error
#include <string> // Para char_traits, operator==, basic_string, string
@@ -13,7 +14,7 @@ inline void readBytes(const uint8_t *&buffer, void *dst, size_t size) {
void Gif::decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out) {
if (code_length < 2 || code_length > 12) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid LZW code length: %d", code_length);
std::cout << "Invalid LZW code length: " << code_length << '\n';
throw std::runtime_error("Invalid LZW code length");
}
@@ -39,7 +40,7 @@ void Gif::decompress(int code_length, const uint8_t *input, int input_length, ui
int code = 0;
for (i = 0; i < (code_length + 1); i++) {
if (input_length <= 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unexpected end of input in decompress");
std::cout << "Unexpected end of input in decompress" << '\n';
throw std::runtime_error("Unexpected end of input in decompress");
}
bit = ((*input & mask) != 0) ? 1 : 0;
@@ -69,7 +70,7 @@ void Gif::decompress(int code_length, const uint8_t *input, int input_length, ui
if (prev > -1 && code_length < 12) {
if (code > dictionary_ind) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "LZW error: code (%d) exceeds dictionary_ind (%d)", code, dictionary_ind);
std::cout << "LZW error: code (" << code << ") exceeds dictionary_ind (" << dictionary_ind << ")" << '\n';
throw std::runtime_error("LZW error: code exceeds dictionary_ind.");
}
@@ -98,7 +99,7 @@ void Gif::decompress(int code_length, const uint8_t *input, int input_length, ui
prev = code;
if (code < 0 || static_cast<size_t>(code) >= dictionary.size()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid LZW code %d, dictionary size %lu", code, static_cast<unsigned long>(dictionary.size()));
std::cout << "Invalid LZW code " << code << ", dictionary size " << static_cast<unsigned long>(dictionary.size()) << '\n';
throw std::runtime_error("LZW error: invalid code encountered");
}
@@ -107,7 +108,7 @@ void Gif::decompress(int code_length, const uint8_t *input, int input_length, ui
while (curCode != -1) {
out[dictionary[curCode].len - 1] = dictionary[curCode].byte;
if (dictionary[curCode].prev == curCode) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Internal error; self-reference detected.");
std::cout << "Internal error; self-reference detected." << '\n';
throw std::runtime_error("Internal error in decompress: self-reference");
}
curCode = dictionary[curCode].prev;
@@ -175,20 +176,16 @@ std::vector<uint8_t> Gif::processGifStream(const uint8_t *buffer, uint16_t &w, u
std::string headerStr(reinterpret_cast<char *>(header), 6);
if (headerStr != "GIF87a" && headerStr != "GIF89a") {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Formato de archivo GIF inválido: %s", headerStr.c_str());
std::cout << "Formato de archivo GIF inválido: " << headerStr << '\n';
throw std::runtime_error("Formato de archivo GIF inválido.");
}
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "Procesando GIF con cabecera: %s", headerStr.c_str());
ScreenDescriptor screen_descriptor;
readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor));
w = screen_descriptor.width;
h = screen_descriptor.height;
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "Resolución del GIF: %dx%d", w, h);
int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
std::vector<RGB> global_color_table;
if (screen_descriptor.fields & 0x80) {
@@ -239,13 +236,12 @@ std::vector<uint8_t> Gif::processGifStream(const uint8_t *buffer, uint16_t &w, u
} else if (block_type == IMAGE_DESCRIPTOR) {
return processImageDescriptor(buffer, global_color_table, color_resolution_bits);
} else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized block type: 0x%X", block_type);
std::cout << "Unrecognized block type: 0x" << std::hex << static_cast<int>(block_type) << std::dec << '\n';
return std::vector<uint8_t>{};
}
block_type = *buffer++;
}
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "GIF procesado correctamente.");
return std::vector<uint8_t>{};
}