Try to load images with RECOIL (REtro COmputer IMage Library)
This commit is contained in:
parent
f53925f4f5
commit
44b1d5a466
19
3rdparty/Makefile
vendored
19
3rdparty/Makefile
vendored
@ -28,6 +28,11 @@ LUA=lua-5.3.4
|
|||||||
LUAARCH=$(LUA).tar.gz
|
LUAARCH=$(LUA).tar.gz
|
||||||
LUAURL=https://www.lua.org/ftp/$(LUAARCH)
|
LUAURL=https://www.lua.org/ftp/$(LUAARCH)
|
||||||
# https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.6.1.tar.gz
|
# https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.6.1.tar.gz
|
||||||
|
RECOILVER=4.2.0
|
||||||
|
RECOIL=recoil-$(RECOILVER)
|
||||||
|
RECOILARCH=$(RECOIL).tar.gz
|
||||||
|
#RECOILURL=https://downloads.sourceforge.net/project/recoil/recoil/$(RECOILVER)/$(RECOILARCH)
|
||||||
|
RECOILURL=https://excellmedia.dl.sourceforge.net/project/recoil/recoil/$(RECOILVER)/$(RECOILARCH)
|
||||||
|
|
||||||
PREFIX = $(PWD)/usr
|
PREFIX = $(PWD)/usr
|
||||||
|
|
||||||
@ -53,7 +58,7 @@ endif
|
|||||||
HOST = $(shell $(CC) -dumpmachine)
|
HOST = $(shell $(CC) -dumpmachine)
|
||||||
#HOST = i686-pc-mingw32
|
#HOST = i686-pc-mingw32
|
||||||
|
|
||||||
.PHONY: all clean clean_archives clean_all libs libpng libsdl libsdl_image libsdl_ttf libjpeg libtiff zlib freetype lua
|
.PHONY: all clean clean_archives clean_all libs libpng libsdl libsdl_image libsdl_ttf libjpeg libtiff zlib freetype lua recoil
|
||||||
|
|
||||||
all: libs
|
all: libs
|
||||||
|
|
||||||
@ -61,7 +66,7 @@ clean_all: clean clean_archives
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -r usr/ $(LIBPNG) $(ZLIB) $(SDLIMAGE) $(JPEGDIR) $(LIBTIFF)
|
$(RM) -r usr/ $(LIBPNG) $(ZLIB) $(SDLIMAGE) $(JPEGDIR) $(LIBTIFF)
|
||||||
$(RM) -r $(SDLTTF) $(FREETYPE) SDL-1.2.15 $(LUA)
|
$(RM) -r $(SDLTTF) $(FREETYPE) SDL-1.2.15 $(LUA) $(RECOIL)
|
||||||
|
|
||||||
clean_archives:
|
clean_archives:
|
||||||
$(RM) -r archives
|
$(RM) -r archives
|
||||||
@ -193,6 +198,12 @@ $(ZLIB)/.ok: archives/$(ZLIBARCH)
|
|||||||
$(TAR) xzf $<
|
$(TAR) xzf $<
|
||||||
touch $@
|
touch $@
|
||||||
|
|
||||||
|
recoil: $(RECOIL)/.ok
|
||||||
|
|
||||||
|
$(RECOIL)/.ok: archives/$(RECOILARCH)
|
||||||
|
$(TAR) xzf $<
|
||||||
|
touch $@
|
||||||
|
|
||||||
archives/$(SDLDEVEL):
|
archives/$(SDLDEVEL):
|
||||||
@$(MKDIR) $(@D)
|
@$(MKDIR) $(@D)
|
||||||
cd $(@D) && $(GETURL) $(SDLDEVELURL)
|
cd $(@D) && $(GETURL) $(SDLDEVELURL)
|
||||||
@ -228,3 +239,7 @@ archives/$(FREETYPEARCH):
|
|||||||
archives/$(LUAARCH):
|
archives/$(LUAARCH):
|
||||||
@$(MKDIR) $(@D)
|
@$(MKDIR) $(@D)
|
||||||
cd $(@D) && $(GETURL) $(LUAURL)
|
cd $(@D) && $(GETURL) $(LUAURL)
|
||||||
|
|
||||||
|
archives/$(RECOILARCH):
|
||||||
|
@$(MKDIR) $(@D)
|
||||||
|
cd $(@D) && $(GETURL) $(RECOILURL)
|
||||||
|
|||||||
2
src/.gitignore
vendored
Normal file
2
src/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
recoil.c
|
||||||
|
recoil.h
|
||||||
10
src/Makefile
10
src/Makefile
@ -50,6 +50,8 @@ endif
|
|||||||
|
|
||||||
CFLAGS_CACHE = .cflags.cache
|
CFLAGS_CACHE = .cflags.cache
|
||||||
|
|
||||||
|
RECOILVER = 4.2.0
|
||||||
|
|
||||||
### PLATFORM DETECTION AND CONFIGURATION ###
|
### PLATFORM DETECTION AND CONFIGURATION ###
|
||||||
|
|
||||||
PLATFORMOBJ =
|
PLATFORMOBJ =
|
||||||
@ -545,6 +547,7 @@ OBJS = main.o init.o graph.o sdlscreen.o misc.o special.o \
|
|||||||
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
|
||||||
|
OBJS += loadrecoil.o recoil.o
|
||||||
OBJ = $(addprefix $(OBJDIR)/,$(OBJS))
|
OBJ = $(addprefix $(OBJDIR)/,$(OBJS))
|
||||||
|
|
||||||
SKINS = skin_classic.png skin_modern.png skin_DPaint.png \
|
SKINS = skin_classic.png skin_modern.png skin_DPaint.png \
|
||||||
@ -713,6 +716,13 @@ $(OBJDIR)/versiontag: pversion.c $(REVISION_CACHE)
|
|||||||
|
|
||||||
RES := $(shell if [ ! -f $(CFLAGS_CACHE) ] || [ "`cat $(CFLAGS_CACHE)`" != "$(COPT) $(CFLAGS)" ] ; then echo "$(COPT) $(CFLAGS)" > $(CFLAGS_CACHE) ; fi )
|
RES := $(shell if [ ! -f $(CFLAGS_CACHE) ] || [ "`cat $(CFLAGS_CACHE)`" != "$(COPT) $(CFLAGS)" ] ; then echo "$(COPT) $(CFLAGS)" > $(CFLAGS_CACHE) ; fi )
|
||||||
|
|
||||||
|
recoil.c: ../3rdparty/recoil-$(RECOILVER)/recoil.c
|
||||||
|
$(CP) $< $@
|
||||||
|
$(CP) $(subst .c,.h,$< $@)
|
||||||
|
|
||||||
|
../3rdparty/recoil-$(RECOILVER)/recoil.c:
|
||||||
|
$(MAKE) -C ../3rdparty recoil
|
||||||
|
|
||||||
$(OBJ): $(CFLAGS_CACHE)
|
$(OBJ): $(CFLAGS_CACHE)
|
||||||
|
|
||||||
$(OBJDIR)/%.o : %.c
|
$(OBJDIR)/%.o : %.c
|
||||||
|
|||||||
142
src/loadrecoil.c
Normal file
142
src/loadrecoil.c
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/* vim:expandtab:ts=2 sw=2:
|
||||||
|
*/
|
||||||
|
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
||||||
|
|
||||||
|
Copyright 2018 Thomas Bernard
|
||||||
|
|
||||||
|
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 "struct.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "loadsave.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "errors.h"
|
||||||
|
|
||||||
|
#include "recoil.h"
|
||||||
|
|
||||||
|
void Load_Recoil_Image(T_IO_Context *context)
|
||||||
|
{
|
||||||
|
RECOIL *recoil;
|
||||||
|
byte * file_content;
|
||||||
|
unsigned long file_length;
|
||||||
|
FILE * f;
|
||||||
|
|
||||||
|
f = Open_file_read(context);
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
File_error = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
file_length = File_length_file(f);
|
||||||
|
if (file_length == 0)
|
||||||
|
{
|
||||||
|
fclose(f);
|
||||||
|
File_error = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
file_content = malloc(file_length);
|
||||||
|
if (file_content == NULL)
|
||||||
|
{
|
||||||
|
Warning("Memory allocation error");
|
||||||
|
fclose(f);
|
||||||
|
File_error = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Read_bytes(f, file_content, file_length))
|
||||||
|
{
|
||||||
|
Warning("Read error");
|
||||||
|
fclose(f);
|
||||||
|
free(file_content);
|
||||||
|
File_error = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
recoil = RECOIL_New();
|
||||||
|
if (recoil)
|
||||||
|
{
|
||||||
|
if (RECOIL_Decode(recoil, context->File_name, file_content, file_length))
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
int x, y;
|
||||||
|
byte * pixels;
|
||||||
|
const int *palette;
|
||||||
|
enum PIXEL_RATIO ratio = PIXEL_SIMPLE;
|
||||||
|
|
||||||
|
width = RECOIL_GetWidth(recoil);
|
||||||
|
height = RECOIL_GetHeight(recoil);
|
||||||
|
pixels = malloc(width * height);
|
||||||
|
if (pixels == NULL)
|
||||||
|
{
|
||||||
|
Warning("Memory allocation error");
|
||||||
|
File_error = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// try to convert to 8bpp image
|
||||||
|
File_error = 0;
|
||||||
|
palette = RECOIL_ToPalette(recoil, pixels);
|
||||||
|
if (palette == NULL)
|
||||||
|
{
|
||||||
|
// 24bits
|
||||||
|
const int * tc_pixels;
|
||||||
|
|
||||||
|
Pre_load(context, width, height, file_length, FORMAT_MISC, ratio, 24);
|
||||||
|
tc_pixels = RECOIL_GetPixels(recoil);
|
||||||
|
for (y = 0; y < height; y++)
|
||||||
|
for (x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
Set_pixel_24b(context, x, y, *tc_pixels >> 16, *tc_pixels >> 8, *tc_pixels);
|
||||||
|
tc_pixels++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 8bits
|
||||||
|
int i;
|
||||||
|
int bpp;
|
||||||
|
int ncolors = RECOIL_GetColors(recoil);
|
||||||
|
const byte * p = pixels;
|
||||||
|
|
||||||
|
bpp = 8;
|
||||||
|
while (ncolors <= (1 << (bpp - 1)))
|
||||||
|
bpp--;
|
||||||
|
if (Config.Clear_palette)
|
||||||
|
memset(context->Palette,0,sizeof(T_Palette));
|
||||||
|
for (i = 0; i < ncolors; i++)
|
||||||
|
{
|
||||||
|
context->Palette[i].R = (byte)(palette[i] >> 16);
|
||||||
|
context->Palette[i].G = (byte)(palette[i] >> 8);
|
||||||
|
context->Palette[i].B = (byte)(palette[i]);
|
||||||
|
}
|
||||||
|
Pre_load(context, width, height, file_length, FORMAT_MISC, ratio, bpp);
|
||||||
|
for (y = 0; y < height; y++)
|
||||||
|
for (x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
Set_pixel(context, x, y, *p++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(pixels);
|
||||||
|
if (!File_error)
|
||||||
|
{
|
||||||
|
snprintf(context->Comment, COMMENT_SIZE + 1, "RECOIL: %s", RECOIL_GetPlatform(recoil));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RECOIL_Delete(recoil);
|
||||||
|
}
|
||||||
|
free(file_content);
|
||||||
|
}
|
||||||
@ -174,6 +174,10 @@ void Save_PNG(T_IO_Context *);
|
|||||||
// (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 *);
|
||||||
|
|
||||||
|
// -- Recoil ----------------------------------------------------------------
|
||||||
|
// 8bits and 16bits computer graphics
|
||||||
|
void Load_Recoil_Image(T_IO_Context *);
|
||||||
|
|
||||||
// ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts
|
// ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts
|
||||||
const T_Format File_formats[] = {
|
const T_Format File_formats[] = {
|
||||||
{FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;2bp;pcx;pkm;iff;lbm;ilbm;sham;ham;ham6;ham8;acbm;pic;anim;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;c64;koa;koala;fli;bml;cdu;prg;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico;ic2;cur;cm5;pph"},
|
{FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;2bp;pcx;pkm;iff;lbm;ilbm;sham;ham;ham6;ham8;acbm;pic;anim;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;c64;koa;koala;fli;bml;cdu;prg;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico;ic2;cur;cm5;pph"},
|
||||||
@ -661,8 +665,13 @@ void Load_image(T_IO_Context *context)
|
|||||||
if (File_error)
|
if (File_error)
|
||||||
{
|
{
|
||||||
context->Format = DEFAULT_FILEFORMAT;
|
context->Format = DEFAULT_FILEFORMAT;
|
||||||
// Last try: with SDL_image
|
// try with recoil
|
||||||
Load_SDL_Image(context);
|
Load_Recoil_Image(context);
|
||||||
|
if (File_error)
|
||||||
|
{
|
||||||
|
// Last try: with SDL_image
|
||||||
|
Load_SDL_Image(context);
|
||||||
|
}
|
||||||
|
|
||||||
if (File_error)
|
if (File_error)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user