Compare commits
No commits in common. "cd33490c6609cea7d10096fb999fb0a13d7960ab" and "9aa99e23c40d2cc0b31aecac1ecff93bc5c42e50" have entirely different histories.
cd33490c66
...
9aa99e23c4
11
3rdparty/Makefile
vendored
11
3rdparty/Makefile
vendored
@ -51,7 +51,7 @@ SDLTTFARCH=$(SDLTTF).tar.gz
|
|||||||
SDLTTFURL=https://www.libsdl.org/projects/SDL_ttf/release/$(SDLTTFARCH)
|
SDLTTFURL=https://www.libsdl.org/projects/SDL_ttf/release/$(SDLTTFARCH)
|
||||||
SDLTTFSHA256 = 724cd895ecf4da319a3ef164892b72078bd92632a5d812111261cde248ebcdb7
|
SDLTTFSHA256 = 724cd895ecf4da319a3ef164892b72078bd92632a5d812111261cde248ebcdb7
|
||||||
# we cannot take the latest version automatically because SDL2DEVEL is not signed :(
|
# we cannot take the latest version automatically because SDL2DEVEL is not signed :(
|
||||||
SDL2VER = 2.26.4
|
SDL2VER = 2.26.3
|
||||||
LATESTSDL2VER = $(shell curl -s -S http://www.libsdl.org/ | grep current | grep stable | sed 's/.*version \([0-9.]*\).*/\1/' )
|
LATESTSDL2VER = $(shell curl -s -S http://www.libsdl.org/ | grep current | grep stable | sed 's/.*version \([0-9.]*\).*/\1/' )
|
||||||
SDL2 = SDL2-$(SDL2VER)
|
SDL2 = SDL2-$(SDL2VER)
|
||||||
SDL2ARCH = $(SDL2).tar.gz
|
SDL2ARCH = $(SDL2).tar.gz
|
||||||
@ -65,7 +65,7 @@ endif
|
|||||||
SDL2DEVEL = SDL2-devel-$(SDL2VER)-mingw.tar.gz
|
SDL2DEVEL = SDL2-devel-$(SDL2VER)-mingw.tar.gz
|
||||||
SDL2DEVELURL = https://www.libsdl.org/release/$(SDL2DEVEL)
|
SDL2DEVELURL = https://www.libsdl.org/release/$(SDL2DEVEL)
|
||||||
SDL2DEVELPATCH = SDL2-devel.patch
|
SDL2DEVELPATCH = SDL2-devel.patch
|
||||||
SDL2DEVELSHA256 = fe899c8642caac2f180b1ee6f786857ddcaa0adc1fa82474312b09dd47d74712
|
SDL2DEVELSHA256 = dca2d0c1a9e99e72f13f185a0e410007872a2cd5b5d5ed2913abcf2f8f93552e
|
||||||
SDL2IMAGEVER = $(LATESTSDL2IMAGEVER)
|
SDL2IMAGEVER = $(LATESTSDL2IMAGEVER)
|
||||||
SDL2IMAGE = SDL2_image-$(SDL2IMAGEVER)
|
SDL2IMAGE = SDL2_image-$(SDL2IMAGEVER)
|
||||||
SDL2IMAGEARCH = $(SDL2IMAGE).tar.gz
|
SDL2IMAGEARCH = $(SDL2IMAGE).tar.gz
|
||||||
@ -206,14 +206,12 @@ ifdef WIN32CROSS
|
|||||||
WIN32 = 1
|
WIN32 = 1
|
||||||
PLATFORMDIR = -win32
|
PLATFORMDIR = -win32
|
||||||
CROSS_CC ?= $(shell which i686-w64-mingw32-gcc || which mingw32-gcc)
|
CROSS_CC ?= $(shell which i686-w64-mingw32-gcc || which mingw32-gcc)
|
||||||
CROSS_CXX ?= $(shell which i686-w64-mingw32-g++ || which mingw32-g++)
|
|
||||||
CROSS_AR ?= $(shell which i686-w64-mingw32-ar || which mingw32-ar)
|
CROSS_AR ?= $(shell which i686-w64-mingw32-ar || which mingw32-ar)
|
||||||
CROSS_RANLIB ?= $(shell which i686-w64-mingw32-ranlib || which mingw32-ranlib)
|
CROSS_RANLIB ?= $(shell which i686-w64-mingw32-ranlib || which mingw32-ranlib)
|
||||||
CROSS_STRIP ?= $(shell which i686-w64-mingw32-strip || which mingw32-strip)
|
CROSS_STRIP ?= $(shell which i686-w64-mingw32-strip || which mingw32-strip)
|
||||||
CROSS_OBJDUMP ?= $(shell which i686-w64-mingw32-objdump || which mingw32-objdump)
|
CROSS_OBJDUMP ?= $(shell which i686-w64-mingw32-objdump || which mingw32-objdump)
|
||||||
CROSS_LDFLAGS += -static-libgcc
|
CROSS_LDFLAGS += -static-libgcc
|
||||||
CC = $(CROSS_CC)
|
CC = $(CROSS_CC)
|
||||||
CXX = $(CROSS_CXX)
|
|
||||||
AR = $(CROSS_AR)
|
AR = $(CROSS_AR)
|
||||||
RANLIB = $(CROSS_RANLIB)
|
RANLIB = $(CROSS_RANLIB)
|
||||||
STRIP = $(CROSS_STRIP)
|
STRIP = $(CROSS_STRIP)
|
||||||
@ -339,7 +337,6 @@ $(PREFIX)/lib/libSDL2main.a: archives/$(SDL2DEVEL)
|
|||||||
$(MKDIR) $(PREFIX)
|
$(MKDIR) $(PREFIX)
|
||||||
cd $(SDL2) && $(MAKE) install-package arch=i686-w64-mingw32 prefix=$(PREFIX)
|
cd $(SDL2) && $(MAKE) install-package arch=i686-w64-mingw32 prefix=$(PREFIX)
|
||||||
$(MKDIR) ../bin && $(CP) $(PREFIX)/bin/SDL2.dll ../bin && $(STRIP) ../bin/SDL2.dll
|
$(MKDIR) ../bin && $(CP) $(PREFIX)/bin/SDL2.dll ../bin && $(STRIP) ../bin/SDL2.dll
|
||||||
$(OBJDUMP) -p $(PREFIX)/bin/SDL2.dll | grep 'DLL Name'
|
|
||||||
echo "The following file:" > ../doc/README-SDL2.txt
|
echo "The following file:" > ../doc/README-SDL2.txt
|
||||||
echo "" >> ../doc/README-SDL2.txt
|
echo "" >> ../doc/README-SDL2.txt
|
||||||
echo " SDL2.dll" >> ../doc/README-SDL2.txt
|
echo " SDL2.dll" >> ../doc/README-SDL2.txt
|
||||||
@ -375,7 +372,6 @@ $(PREFIX)/lib/libSDL2_image.a: $(SDL2IMAGE)/.ok
|
|||||||
cd $(SDL2IMAGE)/build$(PLATFORMDIR) && $(MAKE) && $(MAKE) install
|
cd $(SDL2IMAGE)/build$(PLATFORMDIR) && $(MAKE) && $(MAKE) install
|
||||||
ifdef WIN32
|
ifdef WIN32
|
||||||
$(MKDIR) ../bin && $(CP) $(PREFIX)/bin/SDL2_image.dll ../bin && $(STRIP) ../bin/SDL2_image.dll
|
$(MKDIR) ../bin && $(CP) $(PREFIX)/bin/SDL2_image.dll ../bin && $(STRIP) ../bin/SDL2_image.dll
|
||||||
$(OBJDUMP) -p $(PREFIX)/bin/SDL2_image.dll | grep 'DLL Name'
|
|
||||||
endif
|
endif
|
||||||
echo "$(SDL2IMAGE)" > ../doc/README-SDL2_image.txt
|
echo "$(SDL2IMAGE)" > ../doc/README-SDL2_image.txt
|
||||||
echo "" >> ../doc/README-SDL2_image.txt
|
echo "" >> ../doc/README-SDL2_image.txt
|
||||||
@ -393,8 +389,7 @@ $(PREFIX)/lib/libSDL2_ttf.a: $(PREFIX)/lib/libSDL2main.a
|
|||||||
$(PREFIX)/lib/libSDL2_ttf.a: $(SDL2TTF)/.ok
|
$(PREFIX)/lib/libSDL2_ttf.a: $(SDL2TTF)/.ok
|
||||||
$(MKDIR) $(SDL2TTF)/build$(PLATFORMDIR)
|
$(MKDIR) $(SDL2TTF)/build$(PLATFORMDIR)
|
||||||
cd $(SDL2TTF)/build$(PLATFORMDIR) && PKG_CONFIG_LIBDIR=$(PREFIX)/lib/pkgconfig \
|
cd $(SDL2TTF)/build$(PLATFORMDIR) && PKG_CONFIG_LIBDIR=$(PREFIX)/lib/pkgconfig \
|
||||||
CC="$(CC) $(LDFLAGS)" CXX="$(CXX) $(LDFLAGS)" \
|
CC="$(CC) $(LDFLAGS)" CPPFLAGS=-I$(PREFIX)/include LDFLAGS="-L$(PREFIX)/lib $(LDFLAGS)" \
|
||||||
CPPFLAGS=-I$(PREFIX)/include LDFLAGS="-L$(PREFIX)/lib $(LDFLAGS)" \
|
|
||||||
../configure --prefix=$(PREFIX) --with-sdl-prefix=$(PREFIX) \
|
../configure --prefix=$(PREFIX) --with-sdl-prefix=$(PREFIX) \
|
||||||
--with-freetype-prefix=$(PREFIX) --with-ft-prefix=$(PREFIX) --host=$(HOST)
|
--with-freetype-prefix=$(PREFIX) --with-ft-prefix=$(PREFIX) --host=$(HOST)
|
||||||
cd $(SDL2TTF)/build$(PLATFORMDIR) && $(MAKE)
|
cd $(SDL2TTF)/build$(PLATFORMDIR) && $(MAKE)
|
||||||
|
|||||||
253
src/2gsformats.c
253
src/2gsformats.c
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
///@file 2gsformats.c
|
///@file 2gsformats.c
|
||||||
/// Formats for the Apple II GS
|
/// Formats for the Apple II GS
|
||||||
/// Support APF = Apple Preferred Format
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -31,7 +30,6 @@
|
|||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "gfx2mem.h"
|
#include "gfx2mem.h"
|
||||||
#include "gfx2log.h"
|
#include "gfx2log.h"
|
||||||
#include "packbytes.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for an Apple 2 GS picture file
|
* Test for an Apple 2 GS picture file
|
||||||
@ -146,29 +144,21 @@ void Load_2GS(T_IO_Context * context)
|
|||||||
|
|
||||||
if (Config.Clear_palette)
|
if (Config.Clear_palette)
|
||||||
memset(context->Palette, 0, sizeof(T_Palette));
|
memset(context->Palette, 0, sizeof(T_Palette));
|
||||||
for (palindex = 0; palindex < palcount && palindex < 16; palindex++)
|
for (palindex = 0; palindex < palcount; palindex++)
|
||||||
{
|
{
|
||||||
if (!Load_2GS_Palette(context->Palette + (palindex * 16), file))
|
if (!Load_2GS_Palette(context->Palette + (palindex * 16), file))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (palindex < palcount)
|
|
||||||
{
|
|
||||||
GFX2_Log(GFX2_WARNING, "2GS %u palettes, skipping %u of them !\n",
|
|
||||||
(unsigned)palcount, (unsigned)(palcount - palindex));
|
|
||||||
fseek(file, 16*2*(palcount - palindex), SEEK_CUR);
|
|
||||||
}
|
|
||||||
if (!Read_word_le(file, &height))
|
if (!Read_word_le(file, &height))
|
||||||
goto error;
|
goto error;
|
||||||
lineoffset = ftell(file);
|
lineoffset = ftell(file);
|
||||||
dataoffset = lineoffset + 4 * (long)height;
|
dataoffset = lineoffset + 4 * (long)height;
|
||||||
GFX2_Log(GFX2_DEBUG, "2GS mode %02x %ux%u %u palette(s)\n", mode, (unsigned)width, (unsigned)height, (unsigned)palcount);
|
GFX2_Log(GFX2_DEBUG, " mode %02x %ux%u %u palettes\n", mode, (unsigned)width, (unsigned)height, (unsigned)palcount);
|
||||||
if (palcount > 16)
|
|
||||||
palcount = 16;
|
|
||||||
|
|
||||||
// read other chunks before decoding the picture
|
// read other chunks before decoding the picture
|
||||||
GFX2_Log(GFX2_DEBUG, "2GS file_size : %06lx, chunksize : %06lx, current offset : %06lx\n", file_size, chunksize, dataoffset);
|
GFX2_Log(GFX2_DEBUG, "file_size : %06lx, chunksize : %06lx, current offset : %06lx\n", file_size, chunksize, dataoffset);
|
||||||
offset = chunksize;
|
offset = chunksize;
|
||||||
while (chunksize > 0 && offset < (long)file_size)
|
while (offset < (long)file_size)
|
||||||
{
|
{
|
||||||
char * p;
|
char * p;
|
||||||
byte c;
|
byte c;
|
||||||
@ -192,9 +182,7 @@ void Load_2GS(T_IO_Context * context)
|
|||||||
{
|
{
|
||||||
fread(p, 1, len, file);
|
fread(p, 1, len, file);
|
||||||
p[len] = '\0';
|
p[len] = '\0';
|
||||||
GFX2_Log(GFX2_DEBUG, " \"%s\"\n", p);
|
GFX2_Log(GFX2_DEBUG, "%s\n", p);
|
||||||
strncpy(context->Comment, p, COMMENT_SIZE);
|
|
||||||
context->Comment[COMMENT_SIZE] = '\0';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,8 +203,6 @@ void Load_2GS(T_IO_Context * context)
|
|||||||
{
|
{
|
||||||
// all palettes are there...
|
// all palettes are there...
|
||||||
multipaloffset = ftell(file);
|
multipaloffset = ftell(file);
|
||||||
GFX2_Log(GFX2_DEBUG, "2GS MULTIPAL count %u offset %06lx\n",
|
|
||||||
(unsigned)multipalcount, multipaloffset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(p);
|
free(p);
|
||||||
@ -321,232 +307,3 @@ error:
|
|||||||
File_error = 1;
|
File_error = 1;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Save a 16 entry Apple II GS palette to file
|
|
||||||
*/
|
|
||||||
static int Save_2GS_Palette_Entry(FILE * file, const T_Components * palette)
|
|
||||||
{
|
|
||||||
word palentry = ((palette->R << 4) & 0xf00) | (palette->G & 0xf0) | (palette->B >> 4);
|
|
||||||
return Write_word_le(file, palentry);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct line_data {
|
|
||||||
byte used_colors[256 / 8]; // bit map of used colors
|
|
||||||
word color_count;
|
|
||||||
word palette_index;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Save_2GS(T_IO_Context * context)
|
|
||||||
{
|
|
||||||
FILE *file;
|
|
||||||
word x, y, n;
|
|
||||||
byte * palette_mapping;
|
|
||||||
byte * palette_used_colors;
|
|
||||||
struct line_data * lines;
|
|
||||||
word palette_count = 0;
|
|
||||||
long linelist_offset;
|
|
||||||
|
|
||||||
File_error = 1;
|
|
||||||
palette_mapping = GFX2_malloc(16 * context->Height);
|
|
||||||
memset(palette_mapping, 0, 16 * context->Height);
|
|
||||||
lines = GFX2_malloc(sizeof(struct line_data) * context->Height);
|
|
||||||
palette_used_colors = GFX2_malloc((256 / 8) * context->Height);
|
|
||||||
// Parcours de chaque ligne pour construire la / les palette(s)
|
|
||||||
for (y = 0; y < context->Height; y++)
|
|
||||||
{
|
|
||||||
memset(lines + y, 0, sizeof(struct line_data));
|
|
||||||
for (x = 0; x < context->Width; x++)
|
|
||||||
{
|
|
||||||
byte c = Get_pixel(context, x, y);
|
|
||||||
if (!(lines[y].used_colors[c >> 3] & (1 << (c & 7))))
|
|
||||||
{
|
|
||||||
lines[y].used_colors[c >> 3] |= (1 << (c & 7));
|
|
||||||
lines[y].color_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lines[y].color_count > 16)
|
|
||||||
{
|
|
||||||
GFX2_Log(GFX2_DEBUG, "%u colors used on line %u !\n", lines[y].color_count, (unsigned)y);
|
|
||||||
free(palette_used_colors);
|
|
||||||
free(palette_mapping);
|
|
||||||
free(lines);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lines[y].palette_index = 0xffff; // pas de palette attribuée
|
|
||||||
}
|
|
||||||
// attribue les palettes en commençant par celles qui ont le plus de couleurs
|
|
||||||
for (n = 16; n > 0; n--)
|
|
||||||
{
|
|
||||||
for (y = 0 ; y < context->Height; y++)
|
|
||||||
{
|
|
||||||
if (lines[y].color_count == n)
|
|
||||||
{
|
|
||||||
word i;
|
|
||||||
for (i = 0; i < palette_count; i++)
|
|
||||||
{
|
|
||||||
for (x = 0; x < 32; x++)
|
|
||||||
{
|
|
||||||
if (lines[y].used_colors[x] & ~palette_used_colors[i * (256 / 8) + x])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (x == 32)
|
|
||||||
{
|
|
||||||
lines[y].palette_index = i;
|
|
||||||
GFX2_Log(GFX2_DEBUG, " line#%u => pal#%u\n", y, lines[y].palette_index);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// évolution : chercher parmi les palettes avec moins de 16 couleurs s'il y en a une qui convient
|
|
||||||
if (lines[y].palette_index == 0xffff)
|
|
||||||
{
|
|
||||||
for (i = 0; i < palette_count; i++)
|
|
||||||
{
|
|
||||||
word freeslots = 0;
|
|
||||||
while (freeslots <= 15 && palette_mapping[i * 16 + 15 - freeslots] == 0)
|
|
||||||
freeslots++;
|
|
||||||
if (freeslots > 0)
|
|
||||||
{
|
|
||||||
word to_add_count = 0;
|
|
||||||
byte to_add[16];
|
|
||||||
for (x = 0; x < 256; x++)
|
|
||||||
if ((lines[y].used_colors[x >> 3] & ~palette_used_colors[i * (256 / 8) + (x >> 3)]) & (1 << (x & 7)))
|
|
||||||
{
|
|
||||||
// color used on the line but not in the palette
|
|
||||||
to_add[to_add_count++] = (byte)x;
|
|
||||||
}
|
|
||||||
if (to_add_count <= freeslots)
|
|
||||||
{
|
|
||||||
GFX2_Log(GFX2_DEBUG, " add %u colors from line#%u to pal#%u\n",
|
|
||||||
(unsigned)to_add_count, (unsigned)y, (unsigned)i);
|
|
||||||
lines[y].palette_index = i;
|
|
||||||
for (x = 0; x < to_add_count; x++)
|
|
||||||
{
|
|
||||||
// add the color to the palette
|
|
||||||
palette_used_colors[i * (256 / 8) + (to_add[x] >> 3)] |= (1 << (to_add[x] & 7));
|
|
||||||
palette_mapping[i * 16 + 16 - freeslots + x] = to_add[x];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lines[y].palette_index == 0xffff)
|
|
||||||
{
|
|
||||||
word index;
|
|
||||||
lines[y].palette_index = palette_count;
|
|
||||||
for (x = 0, index = 0; x < 256; x++)
|
|
||||||
if (lines[y].used_colors[x >> 3] & (1 << (x & 7)))
|
|
||||||
palette_mapping[palette_count * 16 + index++] = x;
|
|
||||||
memcpy(palette_used_colors + palette_count * (256 / 8), lines[y].used_colors, 256 / 8);
|
|
||||||
GFX2_Log(GFX2_DEBUG, " line#%u => pal#%u (new, %ucolors)\n",
|
|
||||||
(unsigned)y, (unsigned)palette_count, (unsigned)index);
|
|
||||||
palette_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GFX2_Log(GFX2_DEBUG, "%u palette(s) (16 colors each).\n", (unsigned)palette_count);
|
|
||||||
// packing
|
|
||||||
file = Open_file_write(context);
|
|
||||||
if (file != NULL)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
byte pal_mapping[256] = { 0 };
|
|
||||||
// Write Header
|
|
||||||
if(!Write_dword_le(file, 0)) // chunksize, to be written afterward
|
|
||||||
goto error;
|
|
||||||
if(!Write_byte(file, 4) || !Write_bytes(file, "MAIN", 4))
|
|
||||||
goto error;
|
|
||||||
if (!Write_word_le(file, 0/*mode*/) || !Write_word_le(file, context->Width))
|
|
||||||
goto error;
|
|
||||||
// Write Palettes
|
|
||||||
if (palette_count <= 16)
|
|
||||||
{
|
|
||||||
if (!Write_word_le(file, palette_count))
|
|
||||||
goto error;
|
|
||||||
for (i = 0; i < palette_count * 16; i++)
|
|
||||||
{
|
|
||||||
if (!Save_2GS_Palette_Entry(file, context->Palette + palette_mapping[i]))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!Write_word_le(file, 1))
|
|
||||||
goto error;
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
if (!Save_2GS_Palette_Entry(file, context->Palette + palette_mapping[i]))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GFX2_Log(GFX2_DEBUG, "%d 0x%x\n", (int)ftell(file), (int)ftell(file));
|
|
||||||
// Write lines
|
|
||||||
if (!Write_word_le(file, context->Height))
|
|
||||||
goto error;
|
|
||||||
linelist_offset = ftell(file);
|
|
||||||
for (y = 0; y < context->Height; y++)
|
|
||||||
{
|
|
||||||
if (!Write_word_le(file, 0/*linebytes*/) || !Write_word_le(file, palette_count <= 16 ? lines[y].palette_index : 0))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
GFX2_Log(GFX2_DEBUG, " %d 0x%x\n", (int)ftell(file), (int)ftell(file));
|
|
||||||
// Write Pixels
|
|
||||||
for (y = 0; y < context->Height; y++)
|
|
||||||
{
|
|
||||||
byte b;
|
|
||||||
T_PackBytes_data data;
|
|
||||||
unsigned packed_len;
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
pal_mapping[palette_mapping[16 * lines[y].palette_index + i]] = i;
|
|
||||||
}
|
|
||||||
PackBytes_pack_init(&data, file);
|
|
||||||
for (x = 0; x < context->Width; x += 2)
|
|
||||||
{
|
|
||||||
b = pal_mapping[Get_pixel(context, x, y)] << 4;
|
|
||||||
b |= pal_mapping[Get_pixel(context, x + 1, y)];
|
|
||||||
if (PackBytes_pack_add(&data, b) < 0)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
packed_len = PackBytes_pack_flush(&data);
|
|
||||||
//fseek(file, 15 + 32 * palette_count + 2 + y * 4, SEEK_SET);
|
|
||||||
fseek(file, linelist_offset + y * 4, SEEK_SET);
|
|
||||||
if (!Write_word_le(file, packed_len))
|
|
||||||
goto error;
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
long chunk_size = ftell(file);
|
|
||||||
fseek(file, 0, SEEK_SET);
|
|
||||||
if (!Write_dword_le(file, (dword)chunk_size))
|
|
||||||
goto error;
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
}
|
|
||||||
// Comment => NOTE
|
|
||||||
if (palette_count > 16)
|
|
||||||
{
|
|
||||||
if (!Write_dword_le(file, context->Height * 32 + 9 + 2 + 4))
|
|
||||||
goto error;
|
|
||||||
if (!Write_bytes(file, "\x08MULTIPAL", 9))
|
|
||||||
goto error;
|
|
||||||
if (!Write_word_le(file, context->Height))
|
|
||||||
goto error;
|
|
||||||
for (y = 0; y < (unsigned)context->Height; y++)
|
|
||||||
{
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
if (!Save_2GS_Palette_Entry(file, context->Palette + palette_mapping[lines[y].palette_index * 16 + i]))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File_error = 0;
|
|
||||||
error:
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
free(palette_used_colors);
|
|
||||||
free(lines);
|
|
||||||
free(palette_mapping);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -820,7 +820,7 @@ OBJS = main.o init.o graph.o $(APIOBJ) misc.o osdep.o special.o \
|
|||||||
loadsave.o loadsavefuncs.o \
|
loadsave.o loadsavefuncs.o \
|
||||||
pngformat.o motoformats.o stformats.o c64formats.o cpcformats.o \
|
pngformat.o motoformats.o stformats.o c64formats.o cpcformats.o \
|
||||||
ifformat.o msxformats.o packbits.o giformat.o \
|
ifformat.o msxformats.o packbits.o giformat.o \
|
||||||
2gsformats.o packbytes.o \
|
2gsformats.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 gfx2surface.o \
|
oldies.o tiles.o colorred.o unicode.o gfx2surface.o \
|
||||||
|
|||||||
@ -157,7 +157,7 @@ const T_Format File_formats[] = {
|
|||||||
{FORMAT_MOTO," moto",Test_MOTO,Load_MOTO,Save_MOTO,0, 1, 0, "bin", "bin;map"},
|
{FORMAT_MOTO," moto",Test_MOTO,Load_MOTO,Save_MOTO,0, 1, 0, "bin", "bin;map"},
|
||||||
{FORMAT_MSX, " msx", Test_MSX, Load_MSX, Save_MSX, 0, 0, 0, "sc2", "sc2"},
|
{FORMAT_MSX, " msx", Test_MSX, Load_MSX, Save_MSX, 0, 0, 0, "sc2", "sc2"},
|
||||||
{FORMAT_HGR, " hgr", Test_HGR, Load_HGR, Save_HGR, 0, 0, 1, "hgr", "hgr;dhgr;bin"},
|
{FORMAT_HGR, " hgr", Test_HGR, Load_HGR, Save_HGR, 0, 0, 1, "hgr", "hgr;dhgr;bin"},
|
||||||
{FORMAT_2GS, " 2gs", Test_2GS, Load_2GS, Save_2GS, 0, 0, 0, "shr", "shr;gs;iigs;32k"},
|
{FORMAT_2GS, " 2gs", Test_2GS, Load_2GS, NULL, 0, 0, 0, "shr", "shr;gs;iigs;32k"},
|
||||||
#ifndef __no_tifflib__
|
#ifndef __no_tifflib__
|
||||||
{FORMAT_TIFF," tiff",Test_TIFF,Load_TIFF,Save_TIFF,0, 1, 1, "tif", "tif;tiff"},
|
{FORMAT_TIFF," tiff",Test_TIFF,Load_TIFF,Save_TIFF,0, 1, 1, "tif", "tif;tiff"},
|
||||||
#endif
|
#endif
|
||||||
@ -2232,8 +2232,8 @@ void Rotate_safety_backups(void)
|
|||||||
Init_context_backup_image(&context, file_name, Config_directory);
|
Init_context_backup_image(&context, file_name, Config_directory);
|
||||||
context.Format=FORMAT_GIF;
|
context.Format=FORMAT_GIF;
|
||||||
// Provide original file data, to store as a GIF Application Extension
|
// Provide original file data, to store as a GIF Application Extension
|
||||||
context.Original_file_name = Main.backups->Pages->Filename != NULL ? strdup(Main.backups->Pages->Filename) : NULL;
|
context.Original_file_name = strdup(Main.backups->Pages->Filename);
|
||||||
context.Original_file_directory = Main.backups->Pages->File_directory != NULL ? strdup(Main.backups->Pages->File_directory) : NULL;
|
context.Original_file_directory = strdup(Main.backups->Pages->File_directory);
|
||||||
|
|
||||||
Save_image(&context);
|
Save_image(&context);
|
||||||
Destroy_context(&context);
|
Destroy_context(&context);
|
||||||
|
|||||||
154
src/packbytes.c
154
src/packbytes.c
@ -1,154 +0,0 @@
|
|||||||
/* vim:expandtab:ts=2 sw=2:
|
|
||||||
*/
|
|
||||||
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
|
||||||
|
|
||||||
Copyright owned by various GrafX2 authors, see COPYRIGHT.txt for details.
|
|
||||||
|
|
||||||
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 packbytes.c
|
|
||||||
/// Packbytes compression as used in Apple Preferred Format
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "struct.h"
|
|
||||||
#include "io.h"
|
|
||||||
#include "gfx2log.h"
|
|
||||||
#include "packbytes.h"
|
|
||||||
|
|
||||||
void PackBytes_pack_init(T_PackBytes_data * data, FILE * f)
|
|
||||||
{
|
|
||||||
memset(data, 0, sizeof(T_PackBytes_data));
|
|
||||||
data->f = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PackBytes_pack_add(T_PackBytes_data * data, byte b)
|
|
||||||
{
|
|
||||||
switch (data->list_size)
|
|
||||||
{
|
|
||||||
case 0 : // First color
|
|
||||||
data->list[0] = b;
|
|
||||||
data->list_size = 1;
|
|
||||||
break;
|
|
||||||
case 1 : // second color
|
|
||||||
data->repetition_mode = (data->list[0] == b);
|
|
||||||
data->list[1] = b;
|
|
||||||
data->list_size = 2;
|
|
||||||
break;
|
|
||||||
default: // next colors
|
|
||||||
if (data->list[data->list_size - 1] == b) // repeat detected
|
|
||||||
{
|
|
||||||
if ( !data->repetition_mode && data->list_size >= 63)
|
|
||||||
{
|
|
||||||
// diff mode with 126 bytes then 2 identical bytes
|
|
||||||
data->list_size--;
|
|
||||||
if (PackBytes_pack_flush(data) < 0)
|
|
||||||
return -1;
|
|
||||||
data->list[0] = b;
|
|
||||||
data->list[1] = b;
|
|
||||||
data->list_size = 2;
|
|
||||||
data->repetition_mode = 1;
|
|
||||||
}
|
|
||||||
else if ((data->repetition_mode) || (data->list[data->list_size - 2] != b))
|
|
||||||
{
|
|
||||||
// same mode is kept
|
|
||||||
if (data->list_size == 64)
|
|
||||||
{
|
|
||||||
if (PackBytes_pack_flush(data) < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
data->list[data->list_size++] = b;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// diff mode and 3 identical bytes
|
|
||||||
data->list_size -= 2;
|
|
||||||
if (PackBytes_pack_flush(data) < 0)
|
|
||||||
return -1;
|
|
||||||
data->list[0] = b;
|
|
||||||
data->list[1] = b;
|
|
||||||
data->list[2] = b;
|
|
||||||
data->list_size = 3;
|
|
||||||
data->repetition_mode = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // the color is different from the previous one
|
|
||||||
{
|
|
||||||
if (!data->repetition_mode) // keep mode
|
|
||||||
{
|
|
||||||
if (data->list_size == 64)
|
|
||||||
{
|
|
||||||
if (PackBytes_pack_flush(data) < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
data->list[data->list_size++] = b;
|
|
||||||
}
|
|
||||||
else // change mode
|
|
||||||
{
|
|
||||||
if (PackBytes_pack_flush(data) < 0)
|
|
||||||
return -1;
|
|
||||||
data->list[data->list_size++] = b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0; // OK
|
|
||||||
}
|
|
||||||
|
|
||||||
int PackBytes_pack_flush(T_PackBytes_data * data)
|
|
||||||
{
|
|
||||||
if (data->list_size > 0)
|
|
||||||
{
|
|
||||||
if (data->list_size > 64)
|
|
||||||
{
|
|
||||||
GFX2_Log(GFX2_ERROR, "PackBytes_pack_flush() list_size=%d !\n", data->list_size);
|
|
||||||
}
|
|
||||||
if (data->repetition_mode)
|
|
||||||
{
|
|
||||||
if (data->f != NULL)
|
|
||||||
{
|
|
||||||
if (!Write_byte(data->f, 0x40 + data->list_size - 1) ||
|
|
||||||
!Write_byte(data->f, data->list[0]))
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
data->output_count += 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (data->f != NULL)
|
|
||||||
{
|
|
||||||
if (!Write_byte(data->f, data->list_size - 1) ||
|
|
||||||
!Write_bytes(data->f, data->list, data->list_size))
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
data->output_count += 1 + data->list_size;
|
|
||||||
}
|
|
||||||
data->list_size = 0;
|
|
||||||
data->repetition_mode = 0;
|
|
||||||
}
|
|
||||||
return data->output_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PackBytes_pack_buffer(FILE * f, const byte * buffer, size_t size)
|
|
||||||
{
|
|
||||||
T_PackBytes_data pb_data;
|
|
||||||
|
|
||||||
PackBytes_pack_init(&pb_data, f);
|
|
||||||
while (size-- > 0)
|
|
||||||
{
|
|
||||||
if (PackBytes_pack_add(&pb_data, *buffer++))
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return PackBytes_pack_flush(&pb_data);
|
|
||||||
}
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
/* vim:expandtab:ts=2 sw=2:
|
|
||||||
*/
|
|
||||||
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
|
||||||
|
|
||||||
Copyright owned by various GrafX2 authors, see COPYRIGHT.txt for details.
|
|
||||||
|
|
||||||
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 packbytes.h
|
|
||||||
/// Packbytes is used in Apple Preferred Format
|
|
||||||
|
|
||||||
#ifndef PACKBYTES_H_INCLUDED
|
|
||||||
#define PACKBYTES_H_INCLUDED
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data used by the PackBytes packer
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
FILE * f;
|
|
||||||
int output_count;
|
|
||||||
byte list_size;
|
|
||||||
byte repetition_mode;
|
|
||||||
byte list[65];
|
|
||||||
} T_PackBytes_data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* init before packing
|
|
||||||
*
|
|
||||||
* @param data storage for packbits data
|
|
||||||
* @param f FILE output or NULL (for no output)
|
|
||||||
*/
|
|
||||||
void PackBytes_pack_init(T_PackBytes_data * data, FILE * f);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a byte to the packbits stream
|
|
||||||
* @return -1 for error, 0 if OK
|
|
||||||
*/
|
|
||||||
int PackBytes_pack_add(T_PackBytes_data * data, byte b);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flush the packed data to the file
|
|
||||||
*
|
|
||||||
* @return -1 for error, or the size of the packed stream so far
|
|
||||||
*/
|
|
||||||
int PackBytes_pack_flush(T_PackBytes_data * data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pack a full buffer to FILE
|
|
||||||
* @param f FILE output or NULL (for no output)
|
|
||||||
* @param buffer input buffer
|
|
||||||
* @param size byte size of input buffer
|
|
||||||
* @return -1 for error, or the size of the packed stream so far
|
|
||||||
*/
|
|
||||||
int PackBytes_pack_buffer(FILE * f, const byte * buffer, size_t size);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1100,8 +1100,6 @@ void Print_filename(void)
|
|||||||
// Partial copy of the name
|
// Partial copy of the name
|
||||||
if (Main.backups->Pages->Filename_unicode != NULL)
|
if (Main.backups->Pages->Filename_unicode != NULL)
|
||||||
Unicode_strlcpy(display_string, Main.backups->Pages->Filename_unicode, 256);
|
Unicode_strlcpy(display_string, Main.backups->Pages->Filename_unicode, 256);
|
||||||
else if (Main.backups->Pages->Filename == NULL)
|
|
||||||
display_string[0] = 0;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_FILENAMES_ICONV
|
#ifdef ENABLE_FILENAMES_ICONV
|
||||||
|
|||||||
@ -327,7 +327,11 @@ void Allow_drag_and_drop(int flag)
|
|||||||
|
|
||||||
void Define_icon(void)
|
void Define_icon(void)
|
||||||
{
|
{
|
||||||
icon = Load_surface("gfx2.png", Data_directory, NULL); // 48x48
|
char * icon_path;
|
||||||
|
|
||||||
|
icon_path = Filepath_append_to_dir(Data_directory, "gfx2.png"); // 48x48
|
||||||
|
icon = Load_surface(icon_path, NULL);
|
||||||
|
free(icon_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set_mouse_position(void)
|
void Set_mouse_position(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user