#include "base_image.h"
#include "config.h"
+#include "fs.h"
+#include "fs_png.h"
+
/*---------------------------------------------------------------------------*/
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;
/* 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;
{
/* 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,
/* Release all resources. */
png_destroy_write_struct(&writep, &infop);
- fclose(filep);
+ fs_close(filep);
}
/*---------------------------------------------------------------------------*/
/* 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);
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. */
int h;
int b;
+ SDL_Surface *srf = NULL;
+
Uint32 rmask;
Uint32 gmask;
Uint32 bmask;
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;
}
/*---------------------------------------------------------------------------*/