c mas masizat gif.cpp
This commit is contained in:
96
source/gif.h
96
source/gif.h
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h> // Para uint32_t
|
||||
#include <string.h> // Para memcpy
|
||||
#include <cstdint> // Para uint32_t
|
||||
#include <cstring> // Para memcpy
|
||||
#include <vector>
|
||||
|
||||
#define EXTENSION_INTRODUCER 0x21
|
||||
#define IMAGE_DESCRIPTOR 0x2C
|
||||
@@ -15,62 +16,71 @@
|
||||
memcpy(dst, buffer, size); \
|
||||
buffer += size
|
||||
|
||||
typedef struct
|
||||
struct ScreenDescriptor
|
||||
{
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned char fields;
|
||||
unsigned char background_color_index;
|
||||
unsigned char pixel_aspect_ratio;
|
||||
} screen_descriptor_t;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint8_t fields;
|
||||
uint8_t background_color_index;
|
||||
uint8_t pixel_aspect_ratio;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct RGB
|
||||
{
|
||||
unsigned char r, g, b;
|
||||
} rgb;
|
||||
uint8_t r, g, b;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct ImageDescriptor
|
||||
{
|
||||
unsigned short image_left_position;
|
||||
unsigned short image_top_position;
|
||||
unsigned short image_width;
|
||||
unsigned short image_height;
|
||||
unsigned char fields;
|
||||
} image_descriptor_t;
|
||||
uint16_t image_left_position;
|
||||
uint16_t image_top_position;
|
||||
uint16_t image_width;
|
||||
uint16_t image_height;
|
||||
uint8_t fields;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct DictionaryEntry
|
||||
{
|
||||
unsigned char byte;
|
||||
uint8_t byte;
|
||||
int prev;
|
||||
int len;
|
||||
} dictionary_entry_t;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct Extension
|
||||
{
|
||||
unsigned char extension_code;
|
||||
unsigned char block_size;
|
||||
} extension_t;
|
||||
uint8_t extension_code;
|
||||
uint8_t block_size;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct GraphicControlExtension
|
||||
{
|
||||
unsigned char fields;
|
||||
unsigned short delay_time;
|
||||
unsigned char transparent_color_index;
|
||||
} graphic_control_extension_t;
|
||||
uint8_t fields;
|
||||
uint16_t delay_time;
|
||||
uint8_t transparent_color_index;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct ApplicationExtension
|
||||
{
|
||||
unsigned char application_id[8];
|
||||
unsigned char version[3];
|
||||
} application_extension_t;
|
||||
uint8_t application_id[8];
|
||||
uint8_t version[3];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
struct PlaintextExtension
|
||||
{
|
||||
unsigned short left, top, width, height;
|
||||
unsigned char cell_width, cell_height;
|
||||
unsigned char foreground_color, background_color;
|
||||
} plaintext_extension_t;
|
||||
uint16_t left, top, width, height;
|
||||
uint8_t cell_width, cell_height;
|
||||
uint8_t foreground_color, background_color;
|
||||
};
|
||||
|
||||
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);
|
||||
class Gif
|
||||
{
|
||||
public:
|
||||
void uncompress(int code_length, const uint8_t *input, int input_length, uint8_t *out);
|
||||
uint32_t *LoadPalette(uint8_t *buffer);
|
||||
uint8_t *LoadGif(uint8_t *buffer, uint16_t *w, uint16_t *h);
|
||||
|
||||
private:
|
||||
int read_sub_blocks(uint8_t *buffer, uint8_t **data);
|
||||
uint8_t *process_image_descriptor(uint8_t *buffer, RGB *gct, int gct_size, int resolution_bits);
|
||||
uint8_t *process_gif_stream(uint8_t *buffer, uint16_t *w, uint16_t *h);
|
||||
};
|
||||
Reference in New Issue
Block a user