Passat gif.c a gif.cpp

Afegit reloadTextures a Resources
This commit is contained in:
2025-03-10 22:38:23 +01:00
parent 9c1b3c45b0
commit 9d98d3ea6a
7 changed files with 82 additions and 93 deletions

View File

@@ -1,93 +1,6 @@
#include <stdio.h> #include "gif.h"
#include <stdlib.h> #include <stdio.h> // for NULL, fprintf, stderr
#include <string.h> #include <stdlib.h> // for malloc, realloc, exit, calloc, free
#include <fcntl.h>
#define EXTENSION_INTRODUCER 0x21
#define IMAGE_DESCRIPTOR 0x2C
#define TRAILER 0x3B
#define GRAPHIC_CONTROL 0xF9
#define APPLICATION_EXTENSION 0xFF
#define COMMENT_EXTENSION 0xFE
#define PLAINTEXT_EXTENSION 0x01
#define READ(dst, size) memcpy(dst, buffer, size); buffer += size
typedef struct
{
unsigned short width;
unsigned short height;
unsigned char fields;
unsigned char background_color_index;
unsigned char pixel_aspect_ratio;
}
screen_descriptor_t;
typedef struct
{
unsigned char r;
unsigned char g;
unsigned char b;
}
rgb;
typedef struct
{
unsigned short image_left_position;
unsigned short image_top_position;
unsigned short image_width;
unsigned short image_height;
unsigned char fields;
}
image_descriptor_t;
typedef struct
{
unsigned char byte;
int prev;
int len;
}
dictionary_entry_t;
typedef struct
{
unsigned char extension_code;
unsigned char block_size;
}
extension_t;
typedef struct
{
unsigned char fields;
unsigned short delay_time;
unsigned char transparent_color_index;
}
graphic_control_extension_t;
typedef struct
{
unsigned char application_id[ 8 ];
unsigned char version[ 3 ];
}
application_extension_t;
typedef struct
{
unsigned short left;
unsigned short top;
unsigned short width;
unsigned short height;
unsigned char cell_width;
unsigned char cell_height;
unsigned char foreground_color;
unsigned char background_color;
}
plaintext_extension_t;
//static unsigned short width = 0;
//static unsigned short height = 0;
//static unsigned char* uncompressed_data = NULL;
void uncompress( int code_length, void uncompress( int code_length,
const unsigned char *input, const unsigned char *input,
@@ -104,7 +17,6 @@ void uncompress( int code_length,
int clear_code; // This varies depending on code_length int clear_code; // This varies depending on code_length
int stop_code; // one more than clear code int stop_code; // one more than clear code
int match_len; int match_len;
clear_code = 1 << ( code_length ); clear_code = 1 << ( code_length );
stop_code = clear_code + 1; stop_code = clear_code + 1;
@@ -142,7 +54,7 @@ void uncompress( int code_length,
{ {
code = 0x0; code = 0x0;
// Always read one more bit than the code length // Always read one more bit than the code length
for ( i = 0; i < ( code_length + 1 ); ++i ) for ( i = 0; i < ( code_length + 1 ); i++ )
{ {
// This is different than in the file read example; that // This is different than in the file read example; that
// was a call to "next_bit" // was a call to "next_bit"

66
source/gif.h Normal file
View File

@@ -0,0 +1,66 @@
#pragma once
#include <stdint.h> // for uint32_t
#include <string.h> // for memcpy
#define EXTENSION_INTRODUCER 0x21
#define IMAGE_DESCRIPTOR 0x2C
#define TRAILER 0x3B
#define GRAPHIC_CONTROL 0xF9
#define APPLICATION_EXTENSION 0xFF
#define COMMENT_EXTENSION 0xFE
#define PLAINTEXT_EXTENSION 0x01
#define READ(dst, size) memcpy(dst, buffer, size); buffer += size
typedef struct {
unsigned short width;
unsigned short height;
unsigned char fields;
unsigned char background_color_index;
unsigned char pixel_aspect_ratio;
} screen_descriptor_t;
typedef struct {
unsigned char r, g, b;
} rgb;
typedef struct {
unsigned short image_left_position;
unsigned short image_top_position;
unsigned short image_width;
unsigned short image_height;
unsigned char fields;
} image_descriptor_t;
typedef struct {
unsigned char byte;
int prev;
int len;
} dictionary_entry_t;
typedef struct {
unsigned char extension_code;
unsigned char block_size;
} extension_t;
typedef struct {
unsigned char fields;
unsigned short delay_time;
unsigned char transparent_color_index;
} graphic_control_extension_t;
typedef struct {
unsigned char application_id[8];
unsigned char version[3];
} application_extension_t;
typedef struct {
unsigned short left, top, width, height;
unsigned char cell_width, cell_height;
unsigned char foreground_color, background_color;
} plaintext_extension_t;
void uncompress(int code_length, const unsigned char *input, int input_length, unsigned char *out);
uint32_t* LoadPalette(unsigned char *buffer);
unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h);

0
source/global_events.cpp Normal file
View File

0
source/global_events.h Normal file
View File

View File

@@ -73,6 +73,14 @@ void Resource::reload()
load(); load();
} }
// Recarga las texturas
void Resource::reloadTextures()
{
loadTextures();
addPalettes();
createTextures();
}
// Obtiene el sonido a partir de un nombre // Obtiene el sonido a partir de un nombre
JA_Sound_t *Resource::getSound(const std::string &name) JA_Sound_t *Resource::getSound(const std::string &name)
{ {

View File

@@ -170,4 +170,7 @@ public:
// Recarga todos los recursos // Recarga todos los recursos
void reload(); void reload();
// Recarga las texturas
void reloadTextures();
}; };

View File

@@ -7,7 +7,7 @@
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include <string> // Para char_traits, operator<<, operator+ #include <string> // Para char_traits, operator<<, operator+
#include <vector> // Para vector #include <vector> // Para vector
#include "gif.c" // Para LoadGif, LoadPalette #include "gif.h" // Para LoadGif, LoadPalette
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a... #include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
#include "utils.h" // Para getFileName, printWithDots #include "utils.h" // Para getFileName, printWithDots