Skip to content

Commit

Permalink
added simplistic gui (so far windows only)
Browse files Browse the repository at this point in the history
  • Loading branch information
stg committed May 30, 2012
1 parent dc43a5b commit ec226e5
Show file tree
Hide file tree
Showing 13 changed files with 1,938 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
private/
bin-win/sdl.dll
bin-win/gui_sdl12.exe
thumbs.db
thumbs.db
/ui.bmp
Binary file added bin-win/FreeImage.dll
Binary file not shown.
Binary file added bin-win/SDL2.dll
Binary file not shown.
Binary file added bin-win/gui.exe
Binary file not shown.
Binary file added bin-win/ui.bmp
Binary file not shown.
57 changes: 57 additions & 0 deletions gui/loader.c
@@ -0,0 +1,57 @@
#ifdef SDL2
#include <stdint.h>
#include <stdbool.h>
#include <FreeImage/FreeImage.h>
#include "loader.h"

static FIBITMAP *dib=NULL;
static uint16_t w,h;

bool image_loadpicture(const char* filename) {
FREE_IMAGE_FORMAT fif=FIF_UNKNOWN;
int flag=0;
fif=FreeImage_GetFileType(filename,0);
if(fif==FIF_UNKNOWN) {
fif=FreeImage_GetFIFFromFilename(filename);
}
if((fif!=FIF_UNKNOWN)&&FreeImage_FIFSupportsReading(fif)) {
dib=FreeImage_Load(fif,filename,flag);
if(dib) {
w=FreeImage_GetWidth(dib);
h=FreeImage_GetHeight(dib);
if(w>4000||h>4000) {
FreeImage_Unload(dib);
dib=NULL;
} else {
return true;
}
}
}
return false;
}

uint16_t image_width() {
return w;
}

uint16_t image_height() {
return h;
}

void image_convert(uint8_t *p_data) {
uint16_t x,y;
RGBQUAD quad;
for(y=0;y<h;y++) {
for(x=0;x<w;x++) {
FreeImage_GetPixelColor(dib,x,y,&quad);
p_data[y*w+x]=(quad.rgbRed+quad.rgbGreen+quad.rgbBlue)/3;
}
}
}

void image_free() {
if(dib) FreeImage_Unload(dib);
dib=NULL;
}

#endif
9 changes: 9 additions & 0 deletions gui/loader.h
@@ -0,0 +1,9 @@
#ifdef SDL2
#include <stdint.h>
#include <stdbool.h>
bool image_load(const char* filename,int flag);
uint16_t image_width();
uint16_t image_height();
void image_convert(uint8_t *p_data);
void image_free();
#endif

0 comments on commit ec226e5

Please sign in to comment.