X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=share%2Fimage.c;h=4623547d8321798408f48661e3eb85f9f5383ab8;hb=d9f6f8642b9a4f326c0854efe969195a8d0d2e2a;hp=84343aa5e2ac83839e6b27e35bd386864b30ad13;hpb=e6ffcac002911b6d88128dd400529117dd5784b6;p=neverball diff --git a/share/image.c b/share/image.c index 84343aa..4623547 100644 --- a/share/image.c +++ b/share/image.c @@ -24,11 +24,14 @@ #include "base_image.h" #include "config.h" +#include "fs.h" +#include "fs_png.h" + /*---------------------------------------------------------------------------*/ -void image_snap(char *filename) +void image_snap(const char *filename) { - FILE *filep = NULL; + fs_file filep = NULL; png_structp writep = NULL; png_infop infop = NULL; png_bytep *bytep = NULL; @@ -41,7 +44,7 @@ void image_snap(char *filename) /* Initialize all PNG export data structures. */ - if (!(filep = fopen(filename, FMODE_WB))) + if (!(filep = fs_open(filename, "w"))) return; if (!(writep = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) return; @@ -54,7 +57,7 @@ void image_snap(char *filename) { /* Initialize the PNG header. */ - png_init_io (writep, filep); + png_set_write_fn(writep, filep, fs_png_write, fs_png_flush); png_set_IHDR(writep, infop, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, @@ -69,7 +72,7 @@ void image_snap(char *filename) /* Allocate and initialize the row pointers. */ - if ((bytep = png_malloc(writep, h * sizeof (png_bytep)))) + if ((bytep = (png_bytep *) png_malloc(writep, h * sizeof (png_bytep)))) { for (i = 0; i < h; ++i) bytep[h - i - 1] = (png_bytep) (p + i * w * 3); @@ -90,7 +93,7 @@ void image_snap(char *filename) /* Release all resources. */ png_destroy_write_struct(&writep, &infop); - fclose(filep); + fs_close(filep); } /*---------------------------------------------------------------------------*/ @@ -114,13 +117,14 @@ static GLuint make_texture(const void *p, int w, int h, int b) int k = config_get_d(CONFIG_TEXTURES); int W = w; int H = h; - int max; + + GLint max; void *q = NULL; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); - while (w / k > max || h / k > max) + while (w / k > (int) max || h / k > (int) max) k *= 2; if (k > 1) @@ -174,7 +178,7 @@ GLuint make_image_from_file(const char *filename) /* Load the image. */ - if ((p = image_load(config_data(filename), &w, &h, &b))) + if ((p = image_load(filename, &w, &h, &b))) { o = make_texture(p, w, h, b); free(p); @@ -201,14 +205,36 @@ GLuint make_image_from_font(int *W, int *H, if (text && strlen(text) > 0) { SDL_Color col = { 0xFF, 0xFF, 0xFF, 0xFF }; - SDL_Surface *src; + SDL_Surface *orig; - if ((src = TTF_RenderUTF8_Blended(font, text, col))) + if ((orig = TTF_RenderUTF8_Blended(font, text, col))) { void *p; int w2; int h2; - int b = src->format->BitsPerPixel / 8; + int b = orig->format->BitsPerPixel / 8; + + SDL_Surface *src; + SDL_PixelFormat fmt; + + fmt = *orig->format; + + fmt.Rmask = RMASK; + fmt.Gmask = GMASK; + fmt.Bmask = BMASK; + fmt.Amask = AMASK; + + if ((src = SDL_ConvertSurface(orig, &fmt, orig->flags)) == NULL) + { + fprintf(stderr, _("Failed to convert SDL_ttf surface: %s\n"), + SDL_GetError()); + + /* Pretend everything's just fine. */ + + src = orig; + } + else + SDL_FreeSurface(orig); /* Pad the text to power-of-two. */ @@ -256,6 +282,8 @@ SDL_Surface *load_surface(const char *filename) int h; int b; + SDL_Surface *srf = NULL; + Uint32 rmask; Uint32 gmask; Uint32 bmask; @@ -273,11 +301,16 @@ SDL_Surface *load_surface(const char *filename) amask = 0xFF000000; #endif - if ((p = image_load(config_data(filename), &w, &h, &b))) - return SDL_CreateRGBSurfaceFrom(p, w, h, b * 8, w * b, - rmask, gmask, bmask, amask); - else - return NULL; + if ((p = image_load(filename, &w, &h, &b))) + { + void *q; + + if ((q = image_flip(p, w, h, b, 0, 1))) + srf = SDL_CreateRGBSurfaceFrom(q, w, h, b * 8, w * b, + rmask, gmask, bmask, amask); + free(p); + } + return srf; } /*---------------------------------------------------------------------------*/