[NEW] Now mini reads (GIFs and only GIFs)
This commit is contained in:
69
mini.cpp
69
mini.cpp
@@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lua.h"
|
||||
#include "gif.c"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
@@ -160,55 +161,15 @@ uint8_t loadsurf(const char* filename) {
|
||||
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f) {
|
||||
bmp_header_t header;
|
||||
fread(&header, 54, 1, f);
|
||||
if (header.num_colors == 0) header.num_colors = 1 << header.bpp;
|
||||
header.image_size = (header.bmp_width*header.bmp_height) * (8/header.bpp);
|
||||
fseek(f, header.num_colors*4, SEEK_CUR);
|
||||
uint8_t buffer[header.image_size];
|
||||
fread(buffer, header.image_size, 1, f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint8_t *buffer = (uint8_t*)malloc(size);
|
||||
fread(buffer, size, 1, f);
|
||||
fclose(f);
|
||||
|
||||
surfaces[i].w = header.bmp_width;
|
||||
surfaces[i].h = header.bmp_height;
|
||||
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
surfaces[i].p = (uint8_t*)malloc(surfaces[i].size);
|
||||
|
||||
for (int y=0; y<surfaces[i].h; ++y) {
|
||||
switch(header.bpp) {
|
||||
case 1:
|
||||
for (int x=0; x<(surfaces[i].w/8); ++x) {
|
||||
CURRENT(x*8 , surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w/8)] >> 7;
|
||||
CURRENT(x*8+1, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/8)] >> 6 ) & 0x1;
|
||||
CURRENT(x*8+2, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/8)] >> 5 ) & 0x1;
|
||||
CURRENT(x*8+3, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/8)] >> 4 ) & 0x1;
|
||||
CURRENT(x*8+4, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/8)] >> 3 ) & 0x1;
|
||||
CURRENT(x*8+5, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/8)] >> 2 ) & 0x1;
|
||||
CURRENT(x*8+6, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/8)] >> 1 ) & 0x1;
|
||||
CURRENT(x*8+7, surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w/8)] & 0x1;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (int x=0; x<(surfaces[i].w/4); ++x) {
|
||||
CURRENT(x*4 , surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w/4)] >> 6;
|
||||
CURRENT(x*4+1, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/4)] >> 4 ) & 0x3;
|
||||
CURRENT(x*4+2, surfaces[i].h-1-y) = ( buffer[x+y*(surfaces[i].w/4)] >> 2 ) & 0x3;
|
||||
CURRENT(x*4+3, surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w/4)] & 0x3;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
for (int x=0; x<(surfaces[i].w/2); ++x) {
|
||||
CURRENT(x*2, surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w/2)] >> 4;
|
||||
CURRENT(x*2+1, surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w/2)] & 0xf;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
for (int x=0; x<(surfaces[i].w); ++x) {
|
||||
CURRENT(x, surfaces[i].h-1-y) = buffer[x+y*(surfaces[i].w)];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -334,12 +295,16 @@ void color(uint8_t color) {
|
||||
void loadpal(const char* filename) {
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f) {
|
||||
bmp_header_t header;
|
||||
fread(&header, 54, 1, f);
|
||||
if (header.num_colors == 0) header.num_colors = 1 << header.bpp;
|
||||
header.image_size = (header.bmp_width*header.bmp_height) * (8/header.bpp);
|
||||
fread(palette, header.num_colors*4, 1, f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint8_t *buffer = (uint8_t*)malloc(size);
|
||||
fread(buffer, size, 1, f);
|
||||
fclose(f);
|
||||
uint32_t *pal = LoadPalette(buffer);
|
||||
free(buffer);
|
||||
memcpy(palette, pal, 1024);
|
||||
free(pal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user