Issue 285: For skins and fonts, replaced calls to SDL_image with our own image-loading functions. Also fixed the generic loader that was updating the screen palette even when not useful.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1247 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
3226961fb5
commit
84ac0df49c
@ -106,8 +106,7 @@ void Load_IMG(T_IO_Context * context)
|
||||
if (File_error==0)
|
||||
{
|
||||
memcpy(context->Palette,IMG_header.Palette,sizeof(T_Palette));
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
context->Width=IMG_header.Width;
|
||||
context->Height=IMG_header.Height;
|
||||
@ -595,8 +594,7 @@ void Load_LBM(T_IO_Context * context)
|
||||
if (Image_HAM)
|
||||
Adapt_palette_HAM(context);
|
||||
Palette_64_to_256(context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
// On lit l'octet de padding du CMAP si la taille est impaire
|
||||
if (nb_colors&1)
|
||||
@ -1160,8 +1158,7 @@ void Load_BMP(T_IO_Context * context)
|
||||
context->Palette[index].G=local_palette[index][1];
|
||||
context->Palette[index].B=local_palette[index][0];
|
||||
}
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
context->Width=header.Width;
|
||||
context->Height=header.Height;
|
||||
@ -1811,7 +1808,6 @@ void Load_GIF(T_IO_Context * context)
|
||||
for (color_index=0;color_index<nb_colors;color_index++)
|
||||
Read_byte(GIF_file,&(context->Palette[color_index].B));
|
||||
}
|
||||
Set_palette(context->Palette);
|
||||
}
|
||||
|
||||
// On lit un indicateur de block
|
||||
@ -1924,10 +1920,9 @@ void Load_GIF(T_IO_Context * context)
|
||||
for (color_index=0;color_index<nb_colors;color_index++)
|
||||
Read_byte(GIF_file,&(context->Palette[color_index].B));
|
||||
}
|
||||
Set_palette(context->Palette);
|
||||
}
|
||||
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
value_clr =nb_colors+0;
|
||||
value_eof =nb_colors+1;
|
||||
@ -2648,8 +2643,7 @@ void Load_PCX(T_IO_Context * context)
|
||||
}
|
||||
}
|
||||
}
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
// Maintenant qu'on a lu la palette que ces crétins sont allés foutre
|
||||
// à la fin, on retourne juste après le header pour lire l'image.
|
||||
@ -3057,8 +3051,7 @@ void Load_SCx(T_IO_Context * context)
|
||||
|
||||
Palette_64_to_256(SCx_Palette);
|
||||
memcpy(context->Palette,SCx_Palette,size);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
context->Width=SCx_header.Width;
|
||||
context->Height=SCx_header.Height;
|
||||
@ -3384,10 +3377,10 @@ void Load_PNG(T_IO_Context * context)
|
||||
}
|
||||
free(palette);
|
||||
}
|
||||
|
||||
if (color_type != PNG_COLOR_TYPE_RGB && color_type != PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
}
|
||||
|
||||
context->Width=info_ptr->width;
|
||||
@ -3441,6 +3434,7 @@ void Load_PNG(T_IO_Context * context)
|
||||
break;
|
||||
case CONTEXT_MAIN_IMAGE:
|
||||
case CONTEXT_BRUSH:
|
||||
case CONTEXT_SURFACE:
|
||||
// It's loading an actual image
|
||||
// We'll save memory and time by writing directly into
|
||||
// our pre-allocated 24bit buffer
|
||||
|
||||
BIN
gfx2.gif
BIN
gfx2.gif
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -74,7 +74,7 @@
|
||||
; bar according to the resolution| d'outils suivant la résolution
|
||||
; 2: Slightly adapt the ratio of | 2: Adapter légèrement les proportions
|
||||
; the menus and tool-bar | des menus et de la barre d'outils
|
||||
Menu_ratio = 1 ; (default 1)
|
||||
Menu_ratio = 254 ; (default -2)
|
||||
|
||||
[FILE_SELECTOR] # [SELECTEUR_DE_FICHIERS]
|
||||
|
||||
|
||||
4
init.c
4
init.c
@ -819,7 +819,7 @@ T_Gui_skin * Load_graphics(const char * skin_file)
|
||||
strcat(filename,"skins" PATH_SEPARATOR);
|
||||
strcat(filename,skin_file);
|
||||
|
||||
gui=IMG_Load(filename);
|
||||
gui=Load_surface(filename);
|
||||
if (!gui)
|
||||
{
|
||||
sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?)\n");
|
||||
@ -895,7 +895,7 @@ byte * Load_font(const char * font_name)
|
||||
// Read the file containing the image
|
||||
sprintf(filename,"%sskins%s%s", Data_directory, PATH_SEPARATOR, font_name);
|
||||
|
||||
image=IMG_Load(filename);
|
||||
image=Load_surface(filename);
|
||||
if (!image)
|
||||
{
|
||||
sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?)\n");
|
||||
|
||||
15
io.c
15
io.c
@ -274,12 +274,13 @@ void For_each_file(const char * directory_name, void Callback(const char *))
|
||||
void Get_full_filename(char * output_name, char * file_name, char * directory_name)
|
||||
{
|
||||
strcpy(output_name,directory_name);
|
||||
|
||||
// Append a separator at the end of path, if there isn't one already.
|
||||
// This handles the case of directory variables which contain one,
|
||||
// as well as directories like "/" on Unix.
|
||||
if (output_name[strlen(output_name)-1]!=PATH_SEPARATOR[0])
|
||||
strcat(output_name,PATH_SEPARATOR);
|
||||
|
||||
if (output_name[0] != '\0')
|
||||
{
|
||||
// Append a separator at the end of path, if there isn't one already.
|
||||
// This handles the case of directory variables which contain one,
|
||||
// as well as directories like "/" on Unix.
|
||||
if (output_name[strlen(output_name)-1]!=PATH_SEPARATOR[0])
|
||||
strcat(output_name,PATH_SEPARATOR);
|
||||
}
|
||||
strcat(output_name,file_name);
|
||||
}
|
||||
|
||||
105
loadsave.c
105
loadsave.c
@ -210,14 +210,32 @@ void Set_pixel(T_IO_Context *context, short x_pos, short y_pos, byte color)
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Load pixels in a SDL_Surface
|
||||
case CONTEXT_SURFACE:
|
||||
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;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Remap_fileselector(T_IO_Context *context)
|
||||
void Palette_loaded(T_IO_Context *context)
|
||||
{
|
||||
// Update the current screen to the loaded palette
|
||||
switch (context->Type)
|
||||
{
|
||||
case CONTEXT_MAIN_IMAGE:
|
||||
case CONTEXT_PREVIEW:
|
||||
Set_palette(context->Palette);
|
||||
break;
|
||||
case CONTEXT_BRUSH:
|
||||
case CONTEXT_SURFACE:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (context->Type)
|
||||
{
|
||||
case CONTEXT_PREVIEW:
|
||||
@ -268,10 +286,11 @@ void Remap_fileselector(T_IO_Context *context)
|
||||
*/
|
||||
Remap_screen_after_menu_colors_change();
|
||||
break;
|
||||
|
||||
case CONTEXT_MAIN_IMAGE:
|
||||
case CONTEXT_BRUSH:
|
||||
case CONTEXT_SURFACE:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,6 +307,7 @@ void Set_pixel_24b(T_IO_Context *context, short x_pos, short y_pos, byte r, byte
|
||||
{
|
||||
case CONTEXT_MAIN_IMAGE:
|
||||
case CONTEXT_BRUSH:
|
||||
case CONTEXT_SURFACE:
|
||||
{
|
||||
int index;
|
||||
|
||||
@ -465,6 +485,17 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
|
||||
context->Target_address=context->Buffer_image;
|
||||
|
||||
break;
|
||||
|
||||
case CONTEXT_SURFACE:
|
||||
context->Surface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCCOLORKEY, width, height, 8, 0, 0, 0, 0);
|
||||
if (! context->Surface)
|
||||
{
|
||||
File_error=1;
|
||||
return;
|
||||
}
|
||||
//context->Pitch = context->Surface->pitch;
|
||||
//context->Target_address = context->Surface->pixels;
|
||||
break;
|
||||
}
|
||||
|
||||
if (File_error)
|
||||
@ -479,6 +510,7 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
|
||||
{
|
||||
case CONTEXT_MAIN_IMAGE:
|
||||
case CONTEXT_BRUSH:
|
||||
case CONTEXT_SURFACE:
|
||||
// Allocate 24bit buffer
|
||||
context->Buffer_image_24b=
|
||||
(T_Components *)malloc(width*height*sizeof(T_Components));
|
||||
@ -495,8 +527,7 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
|
||||
case CONTEXT_PREVIEW:
|
||||
// Load palette
|
||||
Set_palette_fake_24b(context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -635,7 +666,7 @@ void Load_image(T_IO_Context *context)
|
||||
File_error=2;
|
||||
else
|
||||
{
|
||||
Set_palette(context->Palette);
|
||||
Palette_loaded(context);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -652,6 +683,11 @@ void Load_image(T_IO_Context *context)
|
||||
case CONTEXT_PREVIEW:
|
||||
// nothing to do
|
||||
break;
|
||||
|
||||
case CONTEXT_SURFACE:
|
||||
if (Convert_24b_bitmap_to_256(context->Surface->pixels,context->Buffer_image_24b,context->Width,context->Height,context->Palette))
|
||||
File_error=1;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
@ -727,6 +763,23 @@ void Load_image(T_IO_Context *context)
|
||||
if (!Smear_brush)
|
||||
File_error=3;
|
||||
}
|
||||
else if (context->Type == CONTEXT_SURFACE)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -758,6 +811,9 @@ void Save_image(T_IO_Context *context)
|
||||
|
||||
case CONTEXT_PREVIEW:
|
||||
break;
|
||||
|
||||
case CONTEXT_SURFACE:
|
||||
break;
|
||||
}
|
||||
|
||||
format = Get_fileformat(context->Format);
|
||||
@ -807,8 +863,6 @@ void Load_SDL_Image(T_IO_Context *context)
|
||||
if (surface->format->palette)
|
||||
{
|
||||
Get_SDL_Palette(surface->format->palette, context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
}
|
||||
|
||||
for (y_pos=0; y_pos<context->Height; y_pos++)
|
||||
@ -844,6 +898,24 @@ void Load_SDL_Image(T_IO_Context *context)
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
/// Load an arbitrary SDL_Surface.
|
||||
SDL_Surface * Load_surface(char *full_name)
|
||||
{
|
||||
SDL_Surface * bmp=NULL;
|
||||
T_IO_Context context;
|
||||
|
||||
Init_context_surface(&context, full_name, "");
|
||||
Load_image(&context);
|
||||
|
||||
if (context.Surface)
|
||||
bmp=context.Surface;
|
||||
|
||||
Destroy_context(&context);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
||||
/// Saves an image.
|
||||
/// This routine will only be called when all hope is lost, memory thrashed, etc
|
||||
/// It's the last chance to save anything, but the code has to be extremely
|
||||
@ -1007,6 +1079,25 @@ void Init_context_brush(T_IO_Context * context, char *file_name, char *file_dire
|
||||
|
||||
}
|
||||
|
||||
// Setup for loading an image into a new SDL surface.
|
||||
void Init_context_surface(T_IO_Context * context, char *file_name, char *file_directory)
|
||||
{
|
||||
memset(context, 0, sizeof(T_IO_Context));
|
||||
|
||||
context->Type = CONTEXT_SURFACE;
|
||||
context->File_name = file_name;
|
||||
context->File_directory = file_directory;
|
||||
context->Format = DEFAULT_FILEFORMAT;
|
||||
// context->Palette
|
||||
// context->Width
|
||||
// context->Height
|
||||
context->Nb_layers = 1;
|
||||
context->Transparent_color=-1;
|
||||
context->Ratio=PIXEL_SIMPLE;
|
||||
//context->Target_address
|
||||
//context->Pitch
|
||||
|
||||
}
|
||||
/// Function to call when need to switch layers.
|
||||
void Set_layer(T_IO_Context *context, byte layer)
|
||||
{
|
||||
|
||||
12
loadsave.h
12
loadsave.h
@ -33,6 +33,7 @@ enum CONTEXT_TYPE {
|
||||
CONTEXT_MAIN_IMAGE,
|
||||
CONTEXT_BRUSH,
|
||||
CONTEXT_PREVIEW,
|
||||
CONTEXT_SURFACE,
|
||||
};
|
||||
|
||||
|
||||
@ -76,6 +77,9 @@ typedef struct
|
||||
short Preview_factor_Y;
|
||||
short Preview_pos_X;
|
||||
short Preview_pos_Y;
|
||||
|
||||
// Internal: returned surface for SDL_Surface case
|
||||
SDL_Surface * Surface;
|
||||
|
||||
} T_IO_Context;
|
||||
|
||||
@ -98,6 +102,8 @@ 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.
|
||||
void Init_context_surface(T_IO_Context * context, char *file_name, char *file_directory);
|
||||
|
||||
// Cleans up resources (currently: the 24bit buffer)
|
||||
void Destroy_context(T_IO_Context *context);
|
||||
@ -141,6 +147,10 @@ extern T_Format File_formats[];
|
||||
/// called in case of SIGSEGV.
|
||||
void Image_emergency_backup(void);
|
||||
|
||||
/// Load an arbitrary SDL_Surface.
|
||||
SDL_Surface * Load_surface(char *full_name);
|
||||
|
||||
|
||||
/*
|
||||
/// Pixel ratio of last loaded image: one of :PIXEL_SIMPLE, :PIXEL_WIDE or :PIXEL_TALL
|
||||
extern enum PIXEL_RATIO Ratio_of_loaded_image;
|
||||
@ -162,7 +172,7 @@ T_Format * Get_fileformat(byte format);
|
||||
/// Generic allocation and similar stuff, done at beginning of image load, as soon as size is known.
|
||||
void Pre_load(T_IO_Context *context, short width, short height, long file_size, int format, enum PIXEL_RATIO ratio, byte truecolor);
|
||||
/// Remaps the window. To call after palette (last) changes.
|
||||
void Remap_fileselector(T_IO_Context *context);
|
||||
void Palette_loaded(T_IO_Context *context);
|
||||
/// Generic cleanup done on end of loading (ex: color-conversion from the temporary 24b buffer)
|
||||
//void Post_load(T_IO_Context *context);
|
||||
|
||||
|
||||
7
main.c
7
main.c
@ -509,16 +509,19 @@ int Init_program(int argc,char * argv[])
|
||||
char icon_path[MAX_PATH_CHARACTERS];
|
||||
SDL_Surface * icon;
|
||||
sprintf(icon_path, "%s%s", Data_directory, "gfx2.gif");
|
||||
icon = IMG_Load(icon_path);
|
||||
icon = Load_surface(icon_path);
|
||||
if (icon)
|
||||
{
|
||||
byte *icon_mask;
|
||||
int x,y;
|
||||
Uint32 pink;
|
||||
|
||||
pink = SDL_MapRGB(icon->format, 255, 0, 255);
|
||||
icon_mask=malloc(128);
|
||||
memset(icon_mask,0,128);
|
||||
for (y=0;y<32;y++)
|
||||
for (x=0;x<32;x++)
|
||||
if (((byte *)(icon->pixels))[(y*32+x)] != 255)
|
||||
if (((byte *)(icon->pixels))[(y*32+x)] != pink)
|
||||
icon_mask[(y*32+x)/8] |=0x80>>(x&7);
|
||||
SDL_WM_SetIcon(icon,icon_mask);
|
||||
free(icon_mask);
|
||||
|
||||
@ -110,8 +110,7 @@ void Load_PAL(T_IO_Context * context)
|
||||
{
|
||||
Palette_64_to_256(palette_64);
|
||||
memcpy(context->Palette, palette_64, sizeof(T_Palette));
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
// On dessine une preview de la palette (si chargement = preview)
|
||||
Draw_palette_preview(context);
|
||||
@ -139,8 +138,7 @@ void Load_PAL(T_IO_Context * context)
|
||||
context->Palette[i].G = g;
|
||||
context->Palette[i].B = b;
|
||||
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
// On dessine une preview de la palette (si chargement = preview)
|
||||
Draw_palette_preview(context);
|
||||
@ -378,8 +376,7 @@ void Load_PKM(T_IO_Context * context)
|
||||
// Palette lue en 64
|
||||
memcpy(context->Palette,header.Palette,sizeof(T_Palette));
|
||||
Palette_64_to_256(context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
Compteur_de_donnees_packees=0;
|
||||
Compteur_de_pixels=0;
|
||||
@ -1106,8 +1103,7 @@ void Load_KCF(T_IO_Context * context)
|
||||
context->Palette[index].B=context->Palette[index+16].B;
|
||||
}
|
||||
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
}
|
||||
else
|
||||
File_error=1;
|
||||
@ -1166,8 +1162,7 @@ void Load_KCF(T_IO_Context * context)
|
||||
context->Palette[index].B=context->Palette[index+16].B;
|
||||
}
|
||||
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
}
|
||||
else
|
||||
File_error=1;
|
||||
@ -1445,8 +1440,7 @@ void Load_PI1(T_IO_Context * context)
|
||||
if (Config.Clear_palette)
|
||||
memset(context->Palette,0,sizeof(T_Palette));
|
||||
PI1_decode_palette(buffer+2,(byte *)context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
context->Width=320;
|
||||
context->Height=200;
|
||||
@ -1771,8 +1765,7 @@ void Load_PC1(T_IO_Context * context)
|
||||
if (Config.Clear_palette)
|
||||
memset(context->Palette,0,sizeof(T_Palette));
|
||||
PI1_decode_palette(buffercomp+2,(byte *)context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
context->Width=320;
|
||||
context->Height=200;
|
||||
@ -1954,8 +1947,7 @@ void Load_NEO(T_IO_Context * context)
|
||||
memset(context->Palette,0,sizeof(T_Palette));
|
||||
// on saute la résolution et le flag, chacun 2 bits
|
||||
PI1_decode_palette(buffer+4,(byte *)context->Palette);
|
||||
Set_palette(context->Palette);
|
||||
Remap_fileselector(context);
|
||||
Palette_loaded(context);
|
||||
|
||||
context->Width=320;
|
||||
context->Height=200;
|
||||
@ -2224,8 +2216,7 @@ void Load_C64(T_IO_Context * context)
|
||||
}
|
||||
|
||||
memcpy(context->Palette,pal,48); // this set the software palette for grafx2
|
||||
Set_palette(context->Palette); // this set the hardware palette for SDL
|
||||
Remap_fileselector(context); // Always call it if you change the palette
|
||||
Palette_loaded(context); // Always call it if you change the palette
|
||||
|
||||
if (file_size>9002)
|
||||
width=160;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user