Compare commits

...

2 Commits

4 changed files with 27 additions and 21 deletions

3
gif.c
View File

@@ -434,6 +434,9 @@ static unsigned char* process_gif_stream(unsigned char *buffer, unsigned short*
// sizeof( screen_descriptor_t ) = 8!
READ(&screen_descriptor, 7);
if (w) *w = screen_descriptor.width;
if (h) *h = screen_descriptor.height;
color_resolution_bits = ( ( screen_descriptor.fields & 0x70 ) >> 4 ) + 1;
if ( screen_descriptor.fields & 0x80 )

View File

@@ -27,15 +27,15 @@ SDL_Renderer* sdlRenderer = NULL;
SDL_Texture* sdlTexture = NULL;
void JD8_Init(const char *title) {
screen = (JD8_Surface)calloc( 1, 64000 );
main_palette = (JD8_Palette)calloc( 1, 768 );
screen = (JD8_Surface)calloc( 1, 320 * 200 );
main_palette = (JD8_Palette)calloc( 1, 256 * sizeof(uint32_t) );
pixel_data = (Uint32*)calloc(1, 320 * 200 * 4); // 1048576 );
sdlWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
}
void JD8_Quit() {
@@ -50,9 +50,9 @@ void JD8_ClearScreen(Uint8 color) {
memset( screen, color, 64000 );
}
JD8_Surface JD8_NewSurface() {
JD8_Surface surface = (JD8_Surface)malloc( 64000 );
memset( surface, 0, 64000 );
JD8_Surface JD8_NewSurface(const int w, const int h) {
JD8_Surface surface = (JD8_Surface)malloc( w * h );
memset( surface, 0, w*h );
return surface;
}
@@ -70,8 +70,8 @@ JD8_Surface JD8_LoadSurface(const char *file) {
exit(1);
}
JD8_Surface image = JD8_NewSurface();
memcpy(image, pixels, 64000);
JD8_Surface image = JD8_NewSurface(w, h);
memcpy(image, pixels, w * h);
free(pixels);
return image;
@@ -82,8 +82,15 @@ JD8_Palette JD8_LoadPalette(const char *file) {
char *buffer = NULL;
buffer = JF_GetBufferFromResource(file, filesize);
JD8_Palette palette = (JD8_Palette)LoadPalette((unsigned char*)buffer);
uint8_t *pal = LoadPalette((unsigned char*)buffer);
JD8_Palette palette = (JD8_Palette)malloc(256 * sizeof(uint32_t));
for (int i=0; i<256; ++i) {
palette[i].r = pal[i*3];
palette[i].g = pal[1 + i*3];
palette[i].b = pal[2 + i*3];
//palette[i].hex = 0xff0000;
}
return palette;
}
@@ -173,12 +180,7 @@ void JD8_BlitCKToSurface(int x, int y, JD8_Surface surface, int sx, int sy, int
SDL_Rect rect{0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
void JD8_Flip() {
for( int x = 0; x < 320; x++ ) {
for( int y = 0; y < 200; y++ ) {
Uint32 color = 0xFF000000 + main_palette[screen[x + ( y * 320 )]].r + ( main_palette[screen[x + ( y * 320 )]].g << 8 ) + ( main_palette[screen[x + ( y * 320 )]].b << 16 );
pixel_data[x + ( y * 320 )] = color;
}
}
for (int i=0; i<64000; ++i) pixel_data[i] = main_palette[screen[i]].hex;
SDL_UpdateTexture(sdlTexture, NULL, pixel_data, 320 * sizeof(Uint32));
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, &rect);
SDL_RenderPresent(sdlRenderer);

View File

@@ -1,10 +1,11 @@
#pragma once
#include <SDL2/SDL.h>
struct Color {
Uint8 r;
Uint8 g;
Uint8 b;
union Color {
struct {
uint8_t b, g, r, a;
};
uint32_t hex;
};
typedef Uint8* JD8_Surface;
@@ -16,7 +17,7 @@ void JD8_Quit();
void JD8_ClearScreen(Uint8 color);
JD8_Surface JD8_NewSurface();
JD8_Surface JD8_NewSurface(const int w, const int h);
JD8_Surface JD8_LoadSurface(const char *file);

View File

@@ -57,7 +57,7 @@ namespace module
{
bool eixir = false;
fondo_temp = JD8_NewSurface();
fondo_temp = JD8_NewSurface(320, 200);
JD8_BlitToSurface(0, 0, fondo, 0, 0, 320, 200, fondo_temp);
JD8_Blit(fondo_temp);