don't use SDL in Load_surface() anymore

So the init phase does not depend on SDL anymore.

Signed-off-by: Thomas Bernard <miniupnp@free.fr>
This commit is contained in:
Thomas Bernard 2018-05-28 11:54:59 +02:00
parent 72fea0290f
commit a6c948b27e
9 changed files with 234 additions and 110 deletions

View File

@ -577,7 +577,7 @@ OBJS = main.o init.o graph.o $(APIOBJ) misc.o special.o \
transform.o pversion.o factory.o $(PLATFORMOBJ) \ transform.o pversion.o factory.o $(PLATFORMOBJ) \
fileformats.o miscfileformats.o libraw2crtc.o \ fileformats.o miscfileformats.o libraw2crtc.o \
brush_ops.o buttons_effects.o layers.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 ifndef NORECOIL
OBJS += loadrecoil.o recoil.o OBJS += loadrecoil.o recoil.o
endif endif

View File

@ -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 \ $(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 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 \ $(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 \ gfx2surface.h engine.h global.h graph.h misc.h operatio.h pages.h \
windows.h sdlscreen.h windows.h
$(OBJDIR)/buttons.o: buttons.c const.h struct.h global.h misc.h graph.h engine.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 \ readline.h filesel.h loadsave.h gfx2surface.h init.h buttons.h \
palette.h errors.h readini.h saveini.h shade.h io.h help.h text.h \ operatio.h pages.h palette.h errors.h readini.h saveini.h shade.h io.h \
sdlscreen.h windows.h brush.h input.h special.h tiles.h setup.h \ help.h text.h sdlscreen.h windows.h brush.h input.h special.h tiles.h \
unicode.h setup.h unicode.h
$(OBJDIR)/buttons_effects.o: buttons_effects.c brush.h struct.h const.h buttons.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 \ loadsave.h gfx2surface.h engine.h global.h graph.h help.h input.h misc.h \
readline.h sdlscreen.h windows.h tiles.h pages.h readline.h sdlscreen.h windows.h tiles.h
$(OBJDIR)/colorred.o: colorred.c colorred.h struct.h const.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 \ $(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 \ buttons.h loadsave.h gfx2surface.h operatio.h shade.h errors.h \
brush.h input.h engine.h pages.h layers.h factory.h io.h pxsimple.h \ sdlscreen.h windows.h brush.h input.h engine.h pages.h layers.h \
oldies.h factory.h io.h pxsimple.h oldies.h
$(OBJDIR)/factory.o: factory.c brush.h struct.h const.h buttons.h loadsave.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 \ gfx2surface.h engine.h errors.h filesel.h global.h graph.h io.h misc.h \
readline.h sdlscreen.h windows.h palette.h input.h help.h realpath.h \ pages.h readline.h sdlscreen.h windows.h palette.h input.h help.h \
setup.h tiles.h realpath.h setup.h tiles.h
$(OBJDIR)/fileformats.o: fileformats.c errors.h global.h struct.h const.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 \ $(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 \ windows.h sdlscreen.h loadsave.h gfx2surface.h mountlist.h engine.h \
help.h unicode.h filesel.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 \ $(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 \ gfx2surface.h pages.h errors.h sdlscreen.h graph.h misc.h pxsimple.h \
pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxtall3.h pxquad.h windows.h \ pxtall.h pxwide.h pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxtall3.h \
input.h brush.h tiles.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 \ $(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 \ help.h sdlscreen.h text.h keyboard.h windows.h input.h hotkeys.h \
errors.h pages.h factory.h errors.h pages.h factory.h
$(OBJDIR)/hotkeys.o: hotkeys.c struct.h const.h global.h hotkeys.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 \ $(OBJDIR)/init.o: init.c buttons.h struct.h const.h loadsave.h gfx2surface.h \
graph.h init.h io.h factory.h help.h hotkeys.h keyboard.h misc.h \ errors.h global.h graph.h init.h io.h factory.h help.h hotkeys.h \
mountlist.h operatio.h palette.h sdlscreen.h setup.h transform.h \ keyboard.h misc.h mountlist.h operatio.h palette.h setup.h transform.h \
windows.h layers.h special.h windows.h layers.h special.h
$(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h sdlscreen.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)/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)/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 \ $(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 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)/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 \ gfx2surface.h
errors.h recoil.h $(OBJDIR)/loadrecoil.o: loadrecoil.c struct.h const.h global.h loadsave.h \
$(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h loadsave.h errors.h \ gfx2surface.h io.h errors.h recoil.h
global.h io.h misc.h graph.h op_c.h colorred.h pages.h palette.h \ $(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h loadsave.h \
sdlscreen.h windows.h engine.h brush.h setup.h filesel.h unicode.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 fileformats.h
$(OBJDIR)/main.o: main.c const.h struct.h global.h graph.h misc.h init.h buttons.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 \ loadsave.h gfx2surface.h engine.h pages.h sdlscreen.h errors.h readini.h \
io.h text.h setup.h windows.h brush.h palette.h realpath.h input.h \ saveini.h io.h text.h setup.h windows.h brush.h palette.h realpath.h \
help.h filesel.h input.h help.h filesel.h
$(OBJDIR)/misc.o: misc.c struct.h const.h sdlscreen.h global.h errors.h buttons.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 \ loadsave.h gfx2surface.h engine.h misc.h keyboard.h windows.h palette.h \
graph.h pages.h input.h graph.h pages.h
$(OBJDIR)/miscfileformats.o: miscfileformats.c engine.h struct.h const.h errors.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 \ global.h io.h libraw2crtc.h loadsave.h gfx2surface.h misc.h sdlscreen.h \
oldies.h fileformats.h windows.h oldies.h pages.h fileformats.h
$(OBJDIR)/mountlist.o: mountlist.c mountlist.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 \ $(OBJDIR)/oldies.o: oldies.c struct.h const.h global.h errors.h misc.h palette.h \
pages.h windows.h layers.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 \ $(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h colorred.h errors.h global.h \
engine.h windows.h engine.h windows.h
$(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h misc.h engine.h graph.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 \ operatio.h buttons.h loadsave.h gfx2surface.h pages.h errors.h \
windows.h input.h special.h tiles.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 \ $(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 \ $(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 \ buttons.h loadsave.h gfx2surface.h pages.h help.h sdlscreen.h errors.h \
colorred.h windows.h input.h palette.h shade.h op_c.h colorred.h windows.h input.h palette.h shade.h
$(OBJDIR)/pversion.o: pversion.c $(OBJDIR)/pversion.o: pversion.c
$(OBJDIR)/pxdouble.o: pxdouble.c global.h struct.h const.h sdlscreen.h misc.h \ $(OBJDIR)/pxdouble.o: pxdouble.c global.h struct.h const.h sdlscreen.h misc.h \
graph.h pxdouble.h pxwide.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 \ $(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 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 \ $(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 \ $(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 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 \ $(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 windows.h input.h misc.h tiles.h
$(OBJDIR)/transform.o: transform.c global.h struct.h const.h transform.h engine.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 \ 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)/unicode.o: unicode.c unicode.h struct.h const.h
$(OBJDIR)/version.o: version.c $(OBJDIR)/version.o: version.c
$(OBJDIR)/windows.o: windows.c windows.h struct.h const.h engine.h errors.h \ $(OBJDIR)/windows.o: windows.c windows.h struct.h const.h engine.h errors.h \

80
src/gfx2surface.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>
*/
#include <stdlib.h>
#include <string.h>
#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;
}

46
src/gfx2surface.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>
*/
//////////////////////////////////////////////////////////////////////////////
///@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

View File

@ -43,8 +43,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#if defined(USE_SDL) || defined(USE_SDL2)
#include <SDL_byteorder.h> #include <SDL_byteorder.h>
#include <SDL_image.h> #include <SDL_image.h>
#endif
#if defined(__WIN32__) #if defined(__WIN32__)
#include <windows.h> // GetLogicalDrives(), GetDriveType(), DRIVE_* #include <windows.h> // GetLogicalDrives(), GetDriveType(), DRIVE_*
#endif #endif
@ -81,13 +83,16 @@
#include "mountlist.h" // read_file_system_list #include "mountlist.h" // read_file_system_list
#include "operatio.h" #include "operatio.h"
#include "palette.h" #include "palette.h"
#if defined(USE_SDL) || defined(USE_SDL2)
#include "sdlscreen.h" #include "sdlscreen.h"
#endif
#include "setup.h" #include "setup.h"
#include "struct.h" #include "struct.h"
#include "transform.h" #include "transform.h"
#include "windows.h" #include "windows.h"
#include "layers.h" #include "layers.h"
#include "special.h" #include "special.h"
#include "gfx2surface.h"
char Gui_loading_error_message[512]; char Gui_loading_error_message[512];
@ -98,7 +103,7 @@ void bstrtostr( BSTR in, STRPTR out, TEXT max );
#endif #endif
// Fonctions de lecture dans la skin de l'interface graphique // 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; byte color;
int y; 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; *start_x=0;
do do
{ {
color=Get_SDL_pixel_8(gui,*start_x,y); color=Get_GFX2_Surface_pixel(gui,*start_x,y);
if (color!=neutral_color) if (color!=neutral_color)
{ {
*start_y=y; *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; 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; byte color;
int x; int x;
@ -128,7 +133,7 @@ byte GUI_seek_right(SDL_Surface *gui, int *start_x, int start_y, byte neutral_co
do do
{ {
color=Get_SDL_pixel_8(gui,x,start_y); color=Get_GFX2_Surface_pixel(gui,x,start_y);
if (color!=neutral_color) if (color!=neutral_color)
{ {
*start_x=x; *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; 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: 0 = normal GUI element, only 4 colors allowed
// type: 1 = mouse cursor, 4 colors allowed + transparent // 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; x<start_x+width; x++) for (x=start_x; x<start_x+width; x++)
{ {
color=Get_SDL_pixel_8(gui,x,y); color=Get_GFX2_Surface_pixel(gui,x,y);
if (type==0 && (color != gfx->Color[0] && color != gfx->Color[1] && color != gfx->Color[2] && color != gfx->Color[3])) if (type==0 && (color != gfx->Color[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", 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; 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]; byte buffer[256];
int x,y; 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]; 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 i,j;
int cursor_x=0,cursor_y=0; 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_3=0; // l'une des fontes dans l'ordre : 1 2
int char_4=0; // 3 4 int char_4=0; // 3 4
byte mouse_cursor_area[31][29]; byte mouse_cursor_area[31][29];
SDL_Palette * SDLPal;
// Default palette // Default palette
if (!gui->format || gui->format->BitsPerPixel != 8) memcpy(gfx->Default_palette, gui->palette, sizeof(T_Palette));
{
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);
// Carré "noir" // 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 do
{ {
if (++cursor_x>=gui->w) 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"); 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; 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]); } while(color==gfx->Color[0]);
// Carré "foncé" // Carré "foncé"
gfx->Color[1] = color; 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"); 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; 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]); } while(color==gfx->Color[1]);
// Carré "clair" // Carré "clair"
gfx->Color[2] = color; 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"); 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; 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]); } while(color==gfx->Color[2]);
// Carré "blanc" // Carré "blanc"
gfx->Color[3] = color; 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"); 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; 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]); } while(color==gfx->Color[3]);
// Carré "transparent" // Carré "transparent"
gfx->Color_trans=color; 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"); 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; 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); } while(color==gfx->Color_trans);
// Reste : couleur neutre // Reste : couleur neutre
neutral_color=color; neutral_color=color;
@ -350,7 +341,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
cursor_x=0; cursor_x=0;
cursor_y=1; 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++; cursor_y++;
if (cursor_y>=gui->h) 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; T_Gui_skin * gfx;
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
SDL_Surface * gui; T_GFX2_Surface * gui;
if (skin_file[0] == '\0') if (skin_file[0] == '\0')
{ {
@ -692,20 +683,18 @@ T_Gui_skin * Load_graphics(const char * skin_file, T_Gradient_array *gradients)
gfx = NULL; gfx = NULL;
return NULL; return NULL;
} }
if (Parse_skin(gui, gfx)) if (Parse_skin(gui, gfx) != 0)
{ {
SDL_FreeSurface(gui);
free(gfx); free(gfx);
gfx = NULL; gfx = NULL;
return NULL;
} }
SDL_FreeSurface(gui); Free_GFX2_Surface(gui);
return gfx; return gfx;
} }
// ---- font loading ----- // ---- 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; byte * font;
int character; int character;
@ -741,7 +730,7 @@ static byte * Parse_font(SDL_Surface * image, int is_main)
for (x=0;x<8; x++) for (x=0;x<8; x++)
{ {
// Pick pixel // 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) if (color > 1)
{ {
sprintf(Gui_loading_error_message, "Error in font file: Only colors 0 and 1 can be used for the font.\n"); 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; byte * font = NULL;
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
SDL_Surface * image; T_GFX2_Surface * image;
if (font_name[0] == '\0') if (font_name[0] == '\0')
{ {
@ -778,7 +767,7 @@ byte * Load_font(const char * font_name, int is_main)
return NULL; return NULL;
} }
font = Parse_font(image, is_main); font = Parse_font(image, is_main);
SDL_FreeSurface(image); Free_GFX2_Surface(image);
return font; return font;
} }
@ -3193,6 +3182,7 @@ void Define_icon(void)
#endif #endif
// General version: Load icon from the file gfx2.gif // General version: Load icon from the file gfx2.gif
#if defined(USE_SDL) || defined(USE_SDL2)
{ {
char icon_path[MAX_PATH_CHARACTERS]; char icon_path[MAX_PATH_CHARACTERS];
SDL_Surface * icon; SDL_Surface * icon;
@ -3230,4 +3220,5 @@ void Define_icon(void)
SDL_FreeSurface(icon); SDL_FreeSurface(icon);
} }
} }
#endif
} }

View File

@ -41,8 +41,11 @@
#endif #endif
#endif #endif
#include <limits.h> #include <limits.h>
#if defined(USE_SDL) || defined(USE_SDL2)
#include <SDL.h>
#include <SDL_image.h> #include <SDL_image.h>
#include <SDL_endian.h> #include <SDL_endian.h>
#endif
#include "buttons.h" #include "buttons.h"
#include "const.h" #include "const.h"
@ -55,7 +58,9 @@
#include "op_c.h" #include "op_c.h"
#include "pages.h" #include "pages.h"
#include "palette.h" #include "palette.h"
#if defined(USE_SDL) || defined(USE_SDL2)
#include "sdlscreen.h" #include "sdlscreen.h"
#endif
#include "struct.h" #include "struct.h"
#include "windows.h" #include "windows.h"
#include "engine.h" #include "engine.h"
@ -65,9 +70,11 @@
#include "unicode.h" #include "unicode.h"
#include "fileformats.h" #include "fileformats.h"
#if defined(USE_SDL) || defined(USE_SDL2)
// -- SDL_Image ------------------------------------------------------------- // -- SDL_Image -------------------------------------------------------------
// (TGA, BMP, PNM, XPM, XCF, PCX, GIF, JPG, TIF, IFF, PNG, ICO) // (TGA, BMP, PNM, XPM, XCF, PCX, GIF, JPG, TIF, IFF, PNG, ICO)
void Load_SDL_Image(T_IO_Context *); void Load_SDL_Image(T_IO_Context *);
#endif
// -- Recoil ---------------------------------------------------------------- // -- Recoil ----------------------------------------------------------------
// 8bits and 16bits computer graphics // 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; break;
// Load pixels in a SDL_Surface // Load pixels into a Surface
case CONTEXT_SURFACE: case CONTEXT_SURFACE:
if (x_pos>=0 && y_pos>=0 && x_pos<context->Surface->w && y_pos<context->Surface->h) if (x_pos>=0 && y_pos>=0 && x_pos<context->Surface->w && y_pos<context->Surface->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; break;
case CONTEXT_PALETTE: case CONTEXT_PALETTE:
@ -447,7 +454,7 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
break; break;
case CONTEXT_SURFACE: 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) if (! context->Surface)
{ {
File_error=1; File_error=1;
@ -586,12 +593,14 @@ void Load_image(T_IO_Context *context)
Load_Recoil_Image(context); Load_Recoil_Image(context);
if (File_error) if (File_error)
#endif #endif
#if defined(USE_SDL) || defined(USE_SDL2)
{ {
// Last try: with SDL_image // Last try: with SDL_image
Load_SDL_Image(context); Load_SDL_Image(context);
} }
if (File_error) if (File_error)
#endif
{ {
// Sinon, l'appelant sera au courant de l'échec grace à File_error; // 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 // 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) if (File_error == 0)
{ {
// Copy the palette // Copy the palette
SDL_Color colors[256]; memcpy(context->Surface->palette, context->Palette, sizeof(T_Palette));
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);
} }
} }
else if (context->Type == CONTEXT_PREVIEW || context->Type == CONTEXT_PREVIEW_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) void Load_SDL_Image(T_IO_Context *context)
{ {
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier 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 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 /// @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; T_IO_Context context;
Init_context_surface(&context, full_name, ""); Init_context_surface(&context, full_name, "");
@ -1153,6 +1154,7 @@ SDL_Surface * Load_surface(char *full_name, T_Gradient_array *gradients)
return bmp; return bmp;
} }
#endif
/// Saves an image. /// 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) void Init_context_surface(T_IO_Context * context, char *file_name, char *file_directory)
{ {
memset(context, 0, sizeof(T_IO_Context)); memset(context, 0, sizeof(T_IO_Context));

View File

@ -28,7 +28,10 @@
#define __LOADSAVE_H__ #define __LOADSAVE_H__
#include <stdio.h> #include <stdio.h>
#if defined(USE_SDL) || defined(USE_SDL2)
#include <SDL_image.h> #include <SDL_image.h>
#endif
#include "gfx2surface.h"
enum CONTEXT_TYPE { enum CONTEXT_TYPE {
CONTEXT_MAIN_IMAGE, CONTEXT_MAIN_IMAGE,
@ -107,8 +110,8 @@ typedef struct
byte *Preview_bitmap; byte *Preview_bitmap;
byte Preview_usage[256]; byte Preview_usage[256];
// Internal: returned surface for SDL_Surface case // Internal: returned surface for Surface case
SDL_Surface * Surface; T_GFX2_Surface * Surface;
} T_IO_Context; } 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); 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. // 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); 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); void Init_context_surface(T_IO_Context * context, char *file_name, char *file_directory);
// Cleans up resources (currently: the 24bit buffer) // Cleans up resources (currently: the 24bit buffer)
@ -189,9 +192,9 @@ extern const T_Format File_formats[];
void Image_emergency_backup(void); 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 /// @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);
/* /*

View File

@ -309,7 +309,7 @@ SDL_Color Color_to_SDL_color(byte index)
} }
/// Reads a pixel in a 8-bit SDL surface. /// 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)]; 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. /// 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; byte * ptr;

View File

@ -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. /// Gets the RGB 24-bit color currently associated with a palette index.
SDL_Color Color_to_SDL_color(byte); SDL_Color Color_to_SDL_color(byte);
/// Reads a pixel in a 8-bit SDL surface. /// 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. /// 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. /// Writes a pixel in a 8-bit SDL surface.
void Set_SDL_pixel_8(SDL_Surface *bmp, int x, int y, byte color); void Set_SDL_pixel_8(SDL_Surface *bmp, int x, int y, byte color);
/// Convert a SDL Palette to a grafx2 palette /// Convert a SDL Palette to a grafx2 palette