diff --git a/src/Makefile b/src/Makefile
index dfabf6b6..20984b10 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -577,7 +577,7 @@ OBJS = main.o init.o graph.o $(APIOBJ) misc.o special.o \
transform.o pversion.o factory.o $(PLATFORMOBJ) \
fileformats.o miscfileformats.o libraw2crtc.o \
brush_ops.o buttons_effects.o layers.o \
- oldies.o tiles.o colorred.o unicode.o
+ oldies.o tiles.o colorred.o unicode.o gfx2surface.o
ifndef NORECOIL
OBJS += loadrecoil.o recoil.o
endif
diff --git a/src/Makefile.dep b/src/Makefile.dep
index ae99e7ed..9b49d69a 100644
--- a/src/Makefile.dep
+++ b/src/Makefile.dep
@@ -2,78 +2,80 @@ $(OBJDIR)/SFont.o: SFont.c SFont.h
$(OBJDIR)/brush.o: brush.c global.h struct.h const.h graph.h misc.h errors.h \
windows.h sdlscreen.h brush.h tiles.h
$(OBJDIR)/brush_ops.o: brush_ops.c brush.h struct.h const.h buttons.h loadsave.h \
- engine.h global.h graph.h misc.h operatio.h pages.h sdlscreen.h \
- windows.h
+ gfx2surface.h engine.h global.h graph.h misc.h operatio.h pages.h \
+ sdlscreen.h windows.h
$(OBJDIR)/buttons.o: buttons.c const.h struct.h global.h misc.h graph.h engine.h \
- readline.h filesel.h loadsave.h init.h buttons.h operatio.h pages.h \
- palette.h errors.h readini.h saveini.h shade.h io.h help.h text.h \
- sdlscreen.h windows.h brush.h input.h special.h tiles.h setup.h \
- unicode.h
+ readline.h filesel.h loadsave.h gfx2surface.h init.h buttons.h \
+ operatio.h pages.h palette.h errors.h readini.h saveini.h shade.h io.h \
+ help.h text.h sdlscreen.h windows.h brush.h input.h special.h tiles.h \
+ setup.h unicode.h
$(OBJDIR)/buttons_effects.o: buttons_effects.c brush.h struct.h const.h buttons.h \
- loadsave.h engine.h global.h graph.h help.h input.h misc.h pages.h \
- readline.h sdlscreen.h windows.h tiles.h
+ loadsave.h gfx2surface.h engine.h global.h graph.h help.h input.h misc.h \
+ pages.h readline.h sdlscreen.h windows.h tiles.h
$(OBJDIR)/colorred.o: colorred.c colorred.h struct.h const.h
$(OBJDIR)/engine.o: engine.c const.h struct.h global.h graph.h misc.h special.h \
- buttons.h loadsave.h operatio.h shade.h errors.h sdlscreen.h windows.h \
- brush.h input.h engine.h pages.h layers.h factory.h io.h pxsimple.h \
- oldies.h
+ buttons.h loadsave.h gfx2surface.h operatio.h shade.h errors.h \
+ sdlscreen.h windows.h brush.h input.h engine.h pages.h layers.h \
+ factory.h io.h pxsimple.h oldies.h
$(OBJDIR)/factory.o: factory.c brush.h struct.h const.h buttons.h loadsave.h \
- engine.h errors.h filesel.h global.h graph.h io.h misc.h pages.h \
- readline.h sdlscreen.h windows.h palette.h input.h help.h realpath.h \
- setup.h tiles.h
+ gfx2surface.h engine.h errors.h filesel.h global.h graph.h io.h misc.h \
+ pages.h readline.h sdlscreen.h windows.h palette.h input.h help.h \
+ realpath.h setup.h tiles.h
$(OBJDIR)/fileformats.o: fileformats.c errors.h global.h struct.h const.h \
- loadsave.h misc.h io.h pages.h windows.h fileformats.h
+ loadsave.h gfx2surface.h misc.h io.h pages.h windows.h fileformats.h
$(OBJDIR)/filesel.o: filesel.c const.h struct.h global.h misc.h errors.h io.h \
- windows.h sdlscreen.h loadsave.h mountlist.h engine.h readline.h input.h \
- help.h unicode.h filesel.h
+ windows.h sdlscreen.h loadsave.h gfx2surface.h mountlist.h engine.h \
+ readline.h input.h help.h unicode.h filesel.h
+$(OBJDIR)/gfx2surface.o: gfx2surface.c gfx2surface.h struct.h const.h errors.h
$(OBJDIR)/graph.o: graph.c global.h struct.h const.h engine.h buttons.h loadsave.h \
- pages.h errors.h sdlscreen.h graph.h misc.h pxsimple.h pxtall.h pxwide.h \
- pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxtall3.h pxquad.h windows.h \
- input.h brush.h tiles.h
+ gfx2surface.h pages.h errors.h sdlscreen.h graph.h misc.h pxsimple.h \
+ pxtall.h pxwide.h pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxtall3.h \
+ pxquad.h windows.h input.h brush.h tiles.h
$(OBJDIR)/help.o: help.c const.h struct.h global.h misc.h engine.h helpfile.h \
help.h sdlscreen.h text.h keyboard.h windows.h input.h hotkeys.h \
errors.h pages.h factory.h
$(OBJDIR)/hotkeys.o: hotkeys.c struct.h const.h global.h hotkeys.h
-$(OBJDIR)/init.o: init.c buttons.h struct.h const.h loadsave.h errors.h global.h \
- graph.h init.h io.h factory.h help.h hotkeys.h keyboard.h misc.h \
- mountlist.h operatio.h palette.h sdlscreen.h setup.h transform.h \
+$(OBJDIR)/init.o: init.c buttons.h struct.h const.h loadsave.h gfx2surface.h \
+ errors.h global.h graph.h init.h io.h factory.h help.h hotkeys.h \
+ keyboard.h misc.h mountlist.h operatio.h palette.h setup.h transform.h \
windows.h layers.h special.h
$(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h sdlscreen.h \
- windows.h errors.h misc.h buttons.h loadsave.h input.h
+ windows.h errors.h misc.h buttons.h loadsave.h gfx2surface.h input.h
$(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.h unicode.h global.h
$(OBJDIR)/keyboard.o: keyboard.c global.h struct.h const.h keyboard.h
$(OBJDIR)/layers.o: layers.c const.h struct.h global.h windows.h engine.h pages.h \
sdlscreen.h input.h help.h misc.h readline.h graph.h
-$(OBJDIR)/libraw2crtc.o: libraw2crtc.c const.h global.h struct.h loadsave.h
-$(OBJDIR)/loadrecoil.o: loadrecoil.c struct.h const.h global.h loadsave.h io.h \
- errors.h recoil.h
-$(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h loadsave.h errors.h \
- global.h io.h misc.h graph.h op_c.h colorred.h pages.h palette.h \
- sdlscreen.h windows.h engine.h brush.h setup.h filesel.h unicode.h \
+$(OBJDIR)/libraw2crtc.o: libraw2crtc.c const.h global.h struct.h loadsave.h \
+ gfx2surface.h
+$(OBJDIR)/loadrecoil.o: loadrecoil.c struct.h const.h global.h loadsave.h \
+ gfx2surface.h io.h errors.h recoil.h
+$(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h loadsave.h \
+ gfx2surface.h errors.h global.h io.h misc.h graph.h op_c.h colorred.h \
+ pages.h palette.h windows.h engine.h brush.h setup.h filesel.h unicode.h \
fileformats.h
$(OBJDIR)/main.o: main.c const.h struct.h global.h graph.h misc.h init.h buttons.h \
- loadsave.h engine.h pages.h sdlscreen.h errors.h readini.h saveini.h \
- io.h text.h setup.h windows.h brush.h palette.h realpath.h input.h \
- help.h filesel.h
+ loadsave.h gfx2surface.h engine.h pages.h sdlscreen.h errors.h readini.h \
+ saveini.h io.h text.h setup.h windows.h brush.h palette.h realpath.h \
+ input.h help.h filesel.h
$(OBJDIR)/misc.o: misc.c struct.h const.h sdlscreen.h global.h errors.h buttons.h \
- loadsave.h engine.h misc.h keyboard.h windows.h palette.h input.h \
- graph.h pages.h
+ loadsave.h gfx2surface.h engine.h misc.h keyboard.h windows.h palette.h \
+ input.h graph.h pages.h
$(OBJDIR)/miscfileformats.o: miscfileformats.c engine.h struct.h const.h errors.h \
- global.h io.h libraw2crtc.h loadsave.h misc.h sdlscreen.h windows.h \
- oldies.h fileformats.h
+ global.h io.h libraw2crtc.h loadsave.h gfx2surface.h misc.h sdlscreen.h \
+ windows.h oldies.h pages.h fileformats.h
$(OBJDIR)/mountlist.o: mountlist.c mountlist.h
$(OBJDIR)/oldies.o: oldies.c struct.h const.h global.h errors.h misc.h palette.h \
pages.h windows.h layers.h
$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h colorred.h errors.h global.h \
engine.h windows.h
$(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h misc.h engine.h graph.h \
- operatio.h buttons.h loadsave.h pages.h errors.h sdlscreen.h brush.h \
- windows.h input.h special.h tiles.h
+ operatio.h buttons.h loadsave.h gfx2surface.h pages.h errors.h \
+ sdlscreen.h brush.h windows.h input.h special.h tiles.h
$(OBJDIR)/pages.o: pages.c global.h struct.h const.h pages.h errors.h loadsave.h \
- misc.h windows.h tiles.h graph.h
+ gfx2surface.h misc.h windows.h tiles.h graph.h
$(OBJDIR)/palette.o: palette.c const.h struct.h global.h misc.h engine.h readline.h \
- buttons.h loadsave.h pages.h help.h sdlscreen.h errors.h op_c.h \
- colorred.h windows.h input.h palette.h shade.h
+ buttons.h loadsave.h gfx2surface.h pages.h help.h sdlscreen.h errors.h \
+ op_c.h colorred.h windows.h input.h palette.h shade.h
$(OBJDIR)/pversion.o: pversion.c
$(OBJDIR)/pxdouble.o: pxdouble.c global.h struct.h const.h sdlscreen.h misc.h \
graph.h pxdouble.h pxwide.h
@@ -107,14 +109,14 @@ $(OBJDIR)/setup.o: setup.c struct.h const.h io.h setup.h
$(OBJDIR)/shade.o: shade.c global.h struct.h const.h graph.h engine.h errors.h \
misc.h readline.h help.h sdlscreen.h windows.h input.h shade.h
$(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h \
- special.h pages.h misc.h buttons.h loadsave.h
+ special.h pages.h misc.h buttons.h loadsave.h gfx2surface.h
$(OBJDIR)/text.o: text.c SFont.h struct.h const.h global.h sdlscreen.h io.h \
errors.h windows.h misc.h setup.h
$(OBJDIR)/tiles.o: tiles.c struct.h const.h global.h graph.h sdlscreen.h engine.h \
windows.h input.h misc.h tiles.h
$(OBJDIR)/transform.o: transform.c global.h struct.h const.h transform.h engine.h \
sdlscreen.h windows.h input.h help.h misc.h readline.h buttons.h \
- loadsave.h pages.h tiles.h
+ loadsave.h gfx2surface.h pages.h tiles.h
$(OBJDIR)/unicode.o: unicode.c unicode.h struct.h const.h
$(OBJDIR)/version.o: version.c
$(OBJDIR)/windows.o: windows.c windows.h struct.h const.h engine.h errors.h \
diff --git a/src/gfx2surface.c b/src/gfx2surface.c
new file mode 100644
index 00000000..46f325fc
--- /dev/null
+++ b/src/gfx2surface.c
@@ -0,0 +1,80 @@
+/* vim:expandtab:ts=2 sw=2:
+*/
+/* Grafx2 - The Ultimate 256-color bitmap paint program
+
+ Copyright 2018 Thomas Bernard
+ Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
+
+ Grafx2 is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; version 2
+ of the License.
+
+ Grafx2 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grafx2; if not, see
+*/
+#include
+#include
+#include "gfx2surface.h"
+#include "errors.h"
+
+T_GFX2_Surface * New_GFX2_Surface(word width, word height)
+{
+ T_GFX2_Surface * surface;
+ size_t size;
+
+ surface = malloc(sizeof(T_GFX2_Surface));
+ if (surface == NULL)
+ return NULL;
+ size = width * height;
+ if (size > 0)
+ {
+ surface->pixels = malloc(size);
+ if(surface->pixels == NULL)
+ {
+ free(surface);
+ return NULL;
+ }
+ }
+ else
+ {
+ surface->pixels = NULL;
+ }
+ memset(surface->palette, 0, sizeof(surface->palette));
+ surface->w = width;
+ surface->h = height;
+ return surface;
+}
+
+void Free_GFX2_Surface(T_GFX2_Surface * surface)
+{
+ free(surface->pixels);
+ free(surface);
+}
+
+byte Get_GFX2_Surface_pixel(const T_GFX2_Surface * surface, int x, int y)
+{
+ if (surface == NULL) return 0;
+ if (x<0 || x>=surface->w || y<0 || y>=surface->h)
+ {
+ Warning("Get_GFX2_Surface_pixel() out of bound access");
+ return 0;
+ }
+ return surface->pixels[x + surface->w * y];
+}
+
+void Set_GFX2_Surface_pixel(T_GFX2_Surface * surface, int x, int y, byte value)
+{
+ if (surface == NULL) return;
+ if (x<0 || x>=surface->w || y<0 || y>=surface->h)
+ {
+ Warning("Set_GFX2_Surface_pixel() out of bound access");
+ return;
+ }
+ surface->pixels[x + surface->w * y] = value;
+}
diff --git a/src/gfx2surface.h b/src/gfx2surface.h
new file mode 100644
index 00000000..72801d19
--- /dev/null
+++ b/src/gfx2surface.h
@@ -0,0 +1,46 @@
+/* vim:expandtab:ts=2 sw=2:
+*/
+/* Grafx2 - The Ultimate 256-color bitmap paint program
+
+ Copyright 2018 Thomas Bernard
+ Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
+
+ Grafx2 is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; version 2
+ of the License.
+
+ Grafx2 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grafx2; if not, see
+*/
+//////////////////////////////////////////////////////////////////////////////
+///@file gfx2surface.h
+/// Memory representation of a 8bits picture
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef GFX2SURFACE_H__
+#define GFX2SURFACE_H__
+
+#include "struct.h"
+
+/// to load 256 color pictures into memory
+typedef struct
+{
+ byte * pixels;
+ T_Palette palette;
+ word w; ///< Width
+ word h; ///< Height
+} T_GFX2_Surface;
+
+T_GFX2_Surface * New_GFX2_Surface(word width, word height);
+void Free_GFX2_Surface(T_GFX2_Surface * surface);
+
+byte Get_GFX2_Surface_pixel(const T_GFX2_Surface * surface, int x, int y);
+void Set_GFX2_Surface_pixel(T_GFX2_Surface * surface, int x, int y, byte value);
+
+#endif
diff --git a/src/init.c b/src/init.c
index c592a7ad..de14d2a5 100644
--- a/src/init.c
+++ b/src/init.c
@@ -43,8 +43,10 @@
#include
#include
+#if defined(USE_SDL) || defined(USE_SDL2)
#include
#include
+#endif
#if defined(__WIN32__)
#include // GetLogicalDrives(), GetDriveType(), DRIVE_*
#endif
@@ -81,13 +83,16 @@
#include "mountlist.h" // read_file_system_list
#include "operatio.h"
#include "palette.h"
+#if defined(USE_SDL) || defined(USE_SDL2)
#include "sdlscreen.h"
+#endif
#include "setup.h"
#include "struct.h"
#include "transform.h"
#include "windows.h"
#include "layers.h"
#include "special.h"
+#include "gfx2surface.h"
char Gui_loading_error_message[512];
@@ -98,7 +103,7 @@ void bstrtostr( BSTR in, STRPTR out, TEXT max );
#endif
// Fonctions de lecture dans la skin de l'interface graphique
-byte GUI_seek_down(SDL_Surface *gui, int *start_x, int *start_y, byte neutral_color,char * section)
+static byte GUI_seek_down(T_GFX2_Surface *gui, int *start_x, int *start_y, byte neutral_color,char * section)
{
byte color;
int y;
@@ -106,7 +111,7 @@ byte GUI_seek_down(SDL_Surface *gui, int *start_x, int *start_y, byte neutral_co
*start_x=0;
do
{
- color=Get_SDL_pixel_8(gui,*start_x,y);
+ color=Get_GFX2_Surface_pixel(gui,*start_x,y);
if (color!=neutral_color)
{
*start_y=y;
@@ -120,7 +125,7 @@ byte GUI_seek_down(SDL_Surface *gui, int *start_x, int *start_y, byte neutral_co
return 1;
}
-byte GUI_seek_right(SDL_Surface *gui, int *start_x, int start_y, byte neutral_color, char * section)
+static byte GUI_seek_right(T_GFX2_Surface *gui, int *start_x, int start_y, byte neutral_color, char * section)
{
byte color;
int x;
@@ -128,7 +133,7 @@ byte GUI_seek_right(SDL_Surface *gui, int *start_x, int start_y, byte neutral_co
do
{
- color=Get_SDL_pixel_8(gui,x,start_y);
+ color=Get_GFX2_Surface_pixel(gui,x,start_y);
if (color!=neutral_color)
{
*start_x=x;
@@ -142,7 +147,7 @@ byte GUI_seek_right(SDL_Surface *gui, int *start_x, int start_y, byte neutral_co
return 1;
}
-byte Read_GUI_block(T_Gui_skin *gfx, SDL_Surface *gui, int start_x, int start_y, void *dest, int width, int height, char * section, int type)
+static byte Read_GUI_block(T_Gui_skin *gfx, T_GFX2_Surface *gui, int start_x, int start_y, void *dest, int width, int height, char * section, int type)
{
// type: 0 = normal GUI element, only 4 colors allowed
// type: 1 = mouse cursor, 4 colors allowed + transparent
@@ -165,7 +170,7 @@ byte Read_GUI_block(T_Gui_skin *gfx, SDL_Surface *gui, int start_x, int start_y,
{
for (x=start_x; xColor[0] && color != gfx->Color[1] && color != gfx->Color[2] && color != gfx->Color[3]))
{
sprintf(Gui_loading_error_message, "Error in skin file: Was looking at %d,%d for a %d*%d object (%s) but at %d,%d a pixel was found with color %d which isn't one of the GUI colors (which were detected as %d,%d,%d,%d.\n",
@@ -196,7 +201,7 @@ byte Read_GUI_block(T_Gui_skin *gfx, SDL_Surface *gui, int start_x, int start_y,
return 0;
}
-byte Read_GUI_pattern(T_Gui_skin *gfx, SDL_Surface *gui, int start_x, int start_y, word *dest, char * section)
+static byte Read_GUI_pattern(T_Gui_skin *gfx, T_GFX2_Surface *gui, int start_x, int start_y, word *dest, char * section)
{
byte buffer[256];
int x,y;
@@ -260,7 +265,7 @@ void Center_GUI_cursor(T_Gui_skin *gfx, byte *cursor_buffer, int cursor_number)
gfx->Cursor_sprite[cursor_number][y][x]=cursor_buffer[(start_y+y)*29+start_x+x];
}
-byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
+static byte Parse_skin(T_GFX2_Surface * gui, T_Gui_skin *gfx)
{
int i,j;
int cursor_x=0,cursor_y=0;
@@ -271,26 +276,12 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
int char_3=0; // l'une des fontes dans l'ordre : 1 2
int char_4=0; // 3 4
byte mouse_cursor_area[31][29];
- SDL_Palette * SDLPal;
// Default palette
- if (!gui->format || gui->format->BitsPerPixel != 8)
- {
- sprintf(Gui_loading_error_message, "Not a 8-bit image");
- return 1;
- }
- SDLPal=gui->format->palette;
- if (!SDLPal || SDLPal->ncolors!=256)
- {
- sprintf(Gui_loading_error_message, "Not a 256-color palette");
- return 1;
- }
-
- // Read the default palette
- Get_SDL_Palette(SDLPal, gfx->Default_palette);
+ memcpy(gfx->Default_palette, gui->palette, sizeof(T_Palette));
// Carré "noir"
- gfx->Color[0] = Get_SDL_pixel_8(gui,cursor_x,cursor_y);
+ gfx->Color[0] = Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y);
do
{
if (++cursor_x>=gui->w)
@@ -298,7 +289,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
sprintf(Gui_loading_error_message, "Error in GUI skin file: should start with 5 consecutive squares for black, dark, light, white, transparent, then a neutral color\n");
return 1;
}
- color=Get_SDL_pixel_8(gui,cursor_x,cursor_y);
+ color=Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y);
} while(color==gfx->Color[0]);
// Carré "foncé"
gfx->Color[1] = color;
@@ -309,7 +300,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
sprintf(Gui_loading_error_message, "Error in GUI skin file: should start with 5 consecutive squares for black, dark, light, white, transparent, then a neutral color\n");
return 1;
}
- color=Get_SDL_pixel_8(gui,cursor_x,cursor_y);
+ color=Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y);
} while(color==gfx->Color[1]);
// Carré "clair"
gfx->Color[2] = color;
@@ -320,7 +311,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
sprintf(Gui_loading_error_message, "Error in GUI skin file: should start with 5 consecutive squares for black, dark, light, white, transparent, then a neutral color\n");
return 1;
}
- color=Get_SDL_pixel_8(gui,cursor_x,cursor_y);
+ color=Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y);
} while(color==gfx->Color[2]);
// Carré "blanc"
gfx->Color[3] = color;
@@ -331,7 +322,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
sprintf(Gui_loading_error_message, "Error in GUI skin file: should start with 5 consecutive squares for black, dark, light, white, transparent, then a neutral color\n");
return 1;
}
- color=Get_SDL_pixel_8(gui,cursor_x,cursor_y);
+ color=Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y);
} while(color==gfx->Color[3]);
// Carré "transparent"
gfx->Color_trans=color;
@@ -342,7 +333,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
sprintf(Gui_loading_error_message, "Error in GUI skin file: should start with 5 consecutive squares for black, dark, light, white, transparent, then a neutral color\n");
return 1;
}
- color=Get_SDL_pixel_8(gui,cursor_x,cursor_y);
+ color=Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y);
} while(color==gfx->Color_trans);
// Reste : couleur neutre
neutral_color=color;
@@ -350,7 +341,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
cursor_x=0;
cursor_y=1;
- while ((color=Get_SDL_pixel_8(gui,cursor_x,cursor_y))==gfx->Color[0])
+ while ((color=Get_GFX2_Surface_pixel(gui,cursor_x,cursor_y))==gfx->Color[0])
{
cursor_y++;
if (cursor_y>=gui->h)
@@ -666,7 +657,7 @@ T_Gui_skin * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
{
T_Gui_skin * gfx;
char filename[MAX_PATH_CHARACTERS];
- SDL_Surface * gui;
+ T_GFX2_Surface * gui;
if (skin_file[0] == '\0')
{
@@ -692,20 +683,18 @@ T_Gui_skin * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
gfx = NULL;
return NULL;
}
- if (Parse_skin(gui, gfx))
+ if (Parse_skin(gui, gfx) != 0)
{
- SDL_FreeSurface(gui);
free(gfx);
gfx = NULL;
- return NULL;
}
- SDL_FreeSurface(gui);
+ Free_GFX2_Surface(gui);
return gfx;
}
// ---- font loading -----
-static byte * Parse_font(SDL_Surface * image, int is_main)
+static byte * Parse_font(T_GFX2_Surface * image, int is_main)
{
byte * font;
int character;
@@ -741,7 +730,7 @@ static byte * Parse_font(SDL_Surface * image, int is_main)
for (x=0;x<8; x++)
{
// Pick pixel
- color = Get_SDL_pixel_8(image, (character % chars_per_line)*8+x, (character / chars_per_line)*8+y);
+ color = Get_GFX2_Surface_pixel(image, (character % chars_per_line)*8+x, (character / chars_per_line)*8+y);
if (color > 1)
{
sprintf(Gui_loading_error_message, "Error in font file: Only colors 0 and 1 can be used for the font.\n");
@@ -760,7 +749,7 @@ byte * Load_font(const char * font_name, int is_main)
{
byte * font = NULL;
char filename[MAX_PATH_CHARACTERS];
- SDL_Surface * image;
+ T_GFX2_Surface * image;
if (font_name[0] == '\0')
{
@@ -778,7 +767,7 @@ byte * Load_font(const char * font_name, int is_main)
return NULL;
}
font = Parse_font(image, is_main);
- SDL_FreeSurface(image);
+ Free_GFX2_Surface(image);
return font;
}
@@ -3193,6 +3182,7 @@ void Define_icon(void)
#endif
// General version: Load icon from the file gfx2.gif
+#if defined(USE_SDL) || defined(USE_SDL2)
{
char icon_path[MAX_PATH_CHARACTERS];
SDL_Surface * icon;
@@ -3230,4 +3220,5 @@ void Define_icon(void)
SDL_FreeSurface(icon);
}
}
+#endif
}
diff --git a/src/loadsave.c b/src/loadsave.c
index 5b543e45..b951eb1b 100644
--- a/src/loadsave.c
+++ b/src/loadsave.c
@@ -41,8 +41,11 @@
#endif
#endif
#include
+#if defined(USE_SDL) || defined(USE_SDL2)
+#include
#include
#include
+#endif
#include "buttons.h"
#include "const.h"
@@ -55,7 +58,9 @@
#include "op_c.h"
#include "pages.h"
#include "palette.h"
+#if defined(USE_SDL) || defined(USE_SDL2)
#include "sdlscreen.h"
+#endif
#include "struct.h"
#include "windows.h"
#include "engine.h"
@@ -65,9 +70,11 @@
#include "unicode.h"
#include "fileformats.h"
+#if defined(USE_SDL) || defined(USE_SDL2)
// -- SDL_Image -------------------------------------------------------------
// (TGA, BMP, PNM, XPM, XCF, PCX, GIF, JPG, TIF, IFF, PNG, ICO)
void Load_SDL_Image(T_IO_Context *);
+#endif
// -- Recoil ----------------------------------------------------------------
// 8bits and 16bits computer graphics
@@ -170,10 +177,10 @@ void Set_pixel(T_IO_Context *context, short x_pos, short y_pos, byte color)
break;
- // Load pixels in a SDL_Surface
+ // Load pixels into a Surface
case CONTEXT_SURFACE:
if (x_pos>=0 && y_pos>=0 && x_posSurface->w && y_posSurface->h)
- *(((byte *)(context->Surface->pixels)) + context->Surface->pitch * y_pos + x_pos) = color;
+ Set_GFX2_Surface_pixel(context->Surface, x_pos, y_pos, color);
break;
case CONTEXT_PALETTE:
@@ -447,7 +454,7 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
break;
case CONTEXT_SURFACE:
- context->Surface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCCOLORKEY, width, height, 8, 0, 0, 0, 0);
+ context->Surface = New_GFX2_Surface(width, height);
if (! context->Surface)
{
File_error=1;
@@ -586,12 +593,14 @@ void Load_image(T_IO_Context *context)
Load_Recoil_Image(context);
if (File_error)
#endif
+#if defined(USE_SDL) || defined(USE_SDL2)
{
// Last try: with SDL_image
Load_SDL_Image(context);
}
if (File_error)
+#endif
{
// Sinon, l'appelant sera au courant de l'échec grace à File_error;
// et si on s'apprêtait à faire un chargement définitif de l'image (pas
@@ -846,16 +855,7 @@ void Load_image(T_IO_Context *context)
if (File_error == 0)
{
// Copy the palette
- SDL_Color colors[256];
- int i;
-
- for (i=0; i<256; i++)
- {
- colors[i].r=context->Palette[i].R;
- colors[i].g=context->Palette[i].G;
- colors[i].b=context->Palette[i].B;
- }
- SDL_SetColors(context->Surface, colors, 0, 256);
+ memcpy(context->Surface->palette, context->Palette, sizeof(T_Palette));
}
}
else if (context->Type == CONTEXT_PREVIEW || context->Type == CONTEXT_PREVIEW_PALETTE
@@ -1049,6 +1049,7 @@ void Save_image(T_IO_Context *context)
}
+#if defined(USE_SDL) || defined(USE_SDL2)
void Load_SDL_Image(T_IO_Context *context)
{
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
@@ -1120,12 +1121,12 @@ void Load_SDL_Image(T_IO_Context *context)
}
///
-/// Load an arbitrary SDL_Surface.
+/// Load an arbitrary Surface.
/// @param full_name Full (absolute) path of the file to load.
/// @param gradients Pass the address of a target T_Gradient_array if you want the gradients, NULL otherwise
-SDL_Surface * Load_surface(char *full_name, T_Gradient_array *gradients)
+T_GFX2_Surface * Load_surface(char *full_name, T_Gradient_array *gradients)
{
- SDL_Surface * bmp=NULL;
+ T_GFX2_Surface * bmp=NULL;
T_IO_Context context;
Init_context_surface(&context, full_name, "");
@@ -1153,6 +1154,7 @@ SDL_Surface * Load_surface(char *full_name, T_Gradient_array *gradients)
return bmp;
}
+#endif
/// Saves an image.
@@ -1335,7 +1337,7 @@ void Init_context_brush(T_IO_Context * context, char *file_name, char *file_dire
}
-// Setup for loading an image into a new SDL surface.
+// Setup for loading an image into a new GFX2 surface.
void Init_context_surface(T_IO_Context * context, char *file_name, char *file_directory)
{
memset(context, 0, sizeof(T_IO_Context));
diff --git a/src/loadsave.h b/src/loadsave.h
index 4261a346..7efc0873 100644
--- a/src/loadsave.h
+++ b/src/loadsave.h
@@ -28,7 +28,10 @@
#define __LOADSAVE_H__
#include
+#if defined(USE_SDL) || defined(USE_SDL2)
#include
+#endif
+#include "gfx2surface.h"
enum CONTEXT_TYPE {
CONTEXT_MAIN_IMAGE,
@@ -107,8 +110,8 @@ typedef struct
byte *Preview_bitmap;
byte Preview_usage[256];
- // Internal: returned surface for SDL_Surface case
- SDL_Surface * Surface;
+ // Internal: returned surface for Surface case
+ T_GFX2_Surface * Surface;
} T_IO_Context;
@@ -137,7 +140,7 @@ void Init_context_flat_image(T_IO_Context * context, char *file_name, char *file
void Init_context_brush(T_IO_Context * context, char *file_name, char *file_directory);
// Setup for saving an arbitrary undo/redo step, from either the main or spare page.
void Init_context_history_step(T_IO_Context * context, T_Page *page);
-// Setup for loading an image into a new SDL surface.
+// Setup for loading an image into a new GFX2 surface.
void Init_context_surface(T_IO_Context * context, char *file_name, char *file_directory);
// Cleans up resources (currently: the 24bit buffer)
@@ -189,9 +192,9 @@ extern const T_Format File_formats[];
void Image_emergency_backup(void);
///
-/// Load an arbitrary SDL_Surface.
+/// Load an arbitrary GFX2_Surface.
/// @param gradients Pass the address of a target T_Gradient_array if you want the gradients, NULL otherwise
-SDL_Surface * Load_surface(char *full_name, T_Gradient_array *gradients);
+T_GFX2_Surface * Load_surface(char *full_name, T_Gradient_array *gradients);
/*
diff --git a/src/sdlscreen.c b/src/sdlscreen.c
index cba94834..d2b2d7b8 100644
--- a/src/sdlscreen.c
+++ b/src/sdlscreen.c
@@ -309,7 +309,7 @@ SDL_Color Color_to_SDL_color(byte index)
}
/// Reads a pixel in a 8-bit SDL surface.
-byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y)
+byte Get_SDL_pixel_8(const SDL_Surface *bmp, int x, int y)
{
return ((byte *)(bmp->pixels))[(y*bmp->pitch+x)];
}
@@ -322,7 +322,7 @@ void Set_SDL_pixel_8(SDL_Surface *bmp, int x, int y, byte color)
/// Reads a pixel in a multi-byte SDL surface.
-dword Get_SDL_pixel_hicolor(SDL_Surface *bmp, int x, int y)
+dword Get_SDL_pixel_hicolor(const SDL_Surface *bmp, int x, int y)
{
byte * ptr;
diff --git a/src/sdlscreen.h b/src/sdlscreen.h
index 81647a36..80183ade 100644
--- a/src/sdlscreen.h
+++ b/src/sdlscreen.h
@@ -58,9 +58,9 @@ byte * Surface_to_bytefield(SDL_Surface *source, byte * dest);
/// Gets the RGB 24-bit color currently associated with a palette index.
SDL_Color Color_to_SDL_color(byte);
/// Reads a pixel in a 8-bit SDL surface.
-byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y);
+byte Get_SDL_pixel_8(const SDL_Surface *bmp, int x, int y);
/// Reads a pixel in a multi-byte SDL surface.
-dword Get_SDL_pixel_hicolor(SDL_Surface *bmp, int x, int y);
+dword Get_SDL_pixel_hicolor(const SDL_Surface *bmp, int x, int y);
/// Writes a pixel in a 8-bit SDL surface.
void Set_SDL_pixel_8(SDL_Surface *bmp, int x, int y, byte color);
/// Convert a SDL Palette to a grafx2 palette