Makefile: Added missing png library to linker options (issue 141)

Fix the minimum screen size not enforced when resizing window (since r705)
Fix the mouse cursor position when changing pixel size (since r705)
In fileselector, the image preview now enforces "safe colors". (issue 116)


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@716 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-04-04 13:38:45 +00:00
parent bc127c5d6a
commit 5655129401
9 changed files with 94 additions and 21 deletions

View File

@ -27,6 +27,7 @@
datarootdir = $(prefix)/share
datadir = $(datarootdir)
# Compile with OPTIM=0 to disable gcc optimizations, to enable debug.
STRIP = strip
@ -40,7 +41,7 @@ ifdef COMSPEC
RMDIR = rmdir
CP = cp
BIN = grafx2.exe
COPT = -W -Wall -Wdeclaration-after-statement -O -g -ggdb `sdl-config --cflags` $(TTFCOPT) $(JOYCOPT)
COPT = -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -g -ggdb `sdl-config --cflags` $(TTFCOPT) $(JOYCOPT)
LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) -lpng
CC = gcc
OBJDIR = obj/win32
@ -177,7 +178,7 @@ else
#cross compile a Win32 executable
CC = i586-mingw32msvc-gcc
BIN = grafx2.exe
COPT = -W -Wall -Wdeclaration-after-statement -O -g -ggdb -Dmain=SDL_main `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --cflags` $(TTFCOPT)
COPT = -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -g -ggdb -Dmain=SDL_main `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --cflags` $(TTFCOPT)
LOPT = -mwindows -lmingw32 -lSDLmain -lSDL -lshlwapi `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --libs` -lSDL_image $(TTFLOPT)
OBJDIR = obj/win32
PLATFORM = win32
@ -197,7 +198,7 @@ else
# Compiles a regular linux exectutable for the native platform
BIN = grafx2
COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -c -g `sdl-config --cflags` $(TTFCOPT)
LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT)
LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) -lpng
CC = gcc
OBJDIR = obj/unix
X11LOPT = -lX11

View File

@ -1673,8 +1673,6 @@ void Button_Safety_resolution(void)
Unselect_bouton(BUTTON_MAGNIFIER);
Init_mode_video(640, 400, 0,PIXEL_SIMPLE);
Current_resolution=0;
Video_mode[0].Width = Screen_width*Pixel_width;
Video_mode[0].Height = Screen_height*Pixel_height;
Display_menu();
Display_all_screen();

View File

@ -524,8 +524,6 @@ void Main_handler(void)
{
Hide_cursor();
Init_mode_video(Resize_width, Resize_height, 0, Pixel_ratio);
Video_mode[0].Width = Screen_width*Pixel_width;
Video_mode[0].Height = Screen_height*Pixel_height;
// Remise à zero des variables indiquant le Redimensionnement demandé
Display_menu();
Display_all_screen();

27
graph.c
View File

@ -190,6 +190,9 @@ int Init_mode_video(int width, int height, int fullscreen, int pix_ratio)
int pix_height;
byte screen_changed;
byte pixels_changed;
int absolute_mouse_x=Mouse_X*Pixel_width;
int absolute_mouse_y=Mouse_Y*Pixel_height;
switch (pix_ratio)
{
@ -212,13 +215,26 @@ int Init_mode_video(int width, int height, int fullscreen, int pix_ratio)
break;
}
screen_changed = (Screen_width*Pixel_width!=width ||
Screen_height*Pixel_height!=height ||
Video_mode[Current_resolution].Fullscreen != fullscreen);
// Valeurs raisonnables: minimum 320x200
if (!fullscreen)
{
if (width < 320*pix_width)
{
width = 320*pix_width;
screen_changed=1;
}
if (height < 200*pix_height)
{
height = 200*pix_height;
screen_changed=1;
}
Video_mode[0].Width = width;
Video_mode[0].Height = height;
}
else
{
@ -233,9 +249,6 @@ int Init_mode_video(int width, int height, int fullscreen, int pix_ratio)
width = (width + 3 ) & 0xFFFFFFFC;
#endif
screen_changed = (Screen_width*Pixel_width!=width ||
Screen_height*Pixel_height!=height ||
Video_mode[Current_resolution].Fullscreen != fullscreen);
pixels_changed = (Pixel_ratio!=pix_ratio);
if (!screen_changed && !pixels_changed)
@ -405,6 +418,14 @@ int Init_mode_video(int width, int height, int fullscreen, int pix_ratio)
y_sensitivity>>=Mouse_fix_factor_Y;
Mouse_sensitivity(x_sensitivity?x_sensitivity:1,y_sensitivity?y_sensitivity:1);
Mouse_X=absolute_mouse_x/Pixel_width;
if (Mouse_X>=Screen_width)
Mouse_X=Screen_width-1;
Mouse_Y=absolute_mouse_y/Pixel_height;
if (Mouse_Y>=Screen_height)
Mouse_Y=Screen_height-1;
Set_mouse_position();
Spare_offset_X=0; // | Il faut penser à éviter les incohérences
Spare_offset_Y=0; // |- de décalage du brouillon par rapport à
Spare_magnifier_mode=0; // | la résolution.

View File

@ -514,7 +514,8 @@ void filename_complet(char * filename, byte is_colorix_format)
void Read_one_byte(FILE * file, byte *b)
{
// FIXME : Replace les appelants par Read_bytes(), et gérer les retours d'erreur.
Read_byte(file, b);
if (!Read_byte(file, b))
File_error=2;
}
// --------------------------------------------------------------------------
@ -645,6 +646,16 @@ void Load_image(byte image)
{
if ( (File_error!=1) && (File_formats[format].Backup_done) )
{
if (Pixel_load_function==Pixel_load_in_preview)
{
dword color_usage[256];
Count_used_colors_area(color_usage,Preview_pos_X,Preview_pos_Y,Main_image_width/Preview_factor_X,Main_image_height/Preview_factor_Y);
//Count_used_colors(color_usage);
Display_cursor();
Set_nice_menu_colors(color_usage,1);
Hide_cursor();
}
// On considère que l'image chargée n'est plus modifiée
Main_image_is_modified=0;
// Et on documente la variable Main_fileformat avec la valeur:

36
misc.c
View File

@ -40,7 +40,7 @@
word Count_used_colors(dword* usage)
{
int nb_pixels=0;
Uint8* Pixel_Courant=Main_screen;
Uint8* current_pixel=Main_screen;
Uint8 color;
word nb_colors=0;
int i;
@ -53,12 +53,12 @@ word Count_used_colors(dword* usage)
// On parcourt l'écran courant pour compter les utilisations des couleurs
for(i=0;i<nb_pixels;i++)
{
color=*Pixel_Courant; //on lit la couleur dans l'écran
color=*current_pixel; //on lit la couleur dans l'écran
usage[color]++; //Un point de plus pour cette couleur
// On passe au pixel suivant
Pixel_Courant++;
current_pixel++;
}
//On va maintenant compter dans la table les couleurs utilisées:
@ -71,6 +71,36 @@ word Count_used_colors(dword* usage)
return nb_colors;
}
/// Same as ::Count_used_colors, but for a given rectangle.
word Count_used_colors_area(dword* usage, word start_x, word start_y, word width, word height)
{
Uint8 color;
word x,y;
word nb_colors=0;
int i;
// Init usage table
for (i=0;i<256;i++) usage[i]=0;
// On parcourt l'écran courant pour compter les utilisations des couleurs
for(y=0;y<height;y++)
{
for(x=0;x<width;x++)
{
color=*(Screen_pixels+((start_x+x)+(start_y+y)*Screen_width*Pixel_height)*Pixel_width); //on lit la couleur dans l'écran
usage[color]++; //Un point de plus pour cette couleur
}
}
//On va maintenant compter dans la table les couleurs utilisées:
for(i=0;i<256;i++)
{
if (usage[i]!=0)
nb_colors++;
}
return nb_colors;
}
void Set_palette(T_Palette palette)
{
register int i;

2
misc.h
View File

@ -38,7 +38,7 @@ void Wait_VBL(void);
void Slider_timer(byte speed);
dword Round_div(dword numerator,dword divisor);
word Count_used_colors(dword * usage);
word Count_used_colors_area(dword* usage, word start_x, word start_y, word width, word height);
void Pixel_in_current_screen (word x,word y,byte color);
void Pixel_in_brush (word x,word y,byte color);
byte Read_pixel_from_current_screen (word x,word y);

View File

@ -385,7 +385,7 @@ void Swap(int with_remap,short block_1_start,short block_2_start,short block_siz
void Set_nice_menu_colors(dword * color_usage)
void Set_nice_menu_colors(dword * color_usage,int not_picture)
{
short index,index2;
byte color;
@ -445,8 +445,16 @@ void Set_nice_menu_colors(dword * color_usage)
replace_table[new_colors[index]]=Best_color_nonexcluded
(rgb[index].R,rgb[index].G,rgb[index].B);
// On fait un changement des couleurs visibles à l'écran et dans l'image
Remap_image_highlevel(replace_table);
if (not_picture)
{
// Remap caused by preview. Only remap screen
Remap_zone_highlevel(0,0,Screen_width,Screen_height,replace_table);
}
else
{
// On fait un changement des couleurs visibles à l'écran et dans l'image
Remap_image_highlevel(replace_table);
}
Display_cursor();
}
@ -1398,7 +1406,7 @@ void Button_Palette(void)
{
memcpy(temp_palette,Main_palette,sizeof(T_Palette));
memcpy(Main_palette,working_palette,sizeof(T_Palette));
Set_nice_menu_colors(color_usage);
Set_nice_menu_colors(color_usage,0);
memcpy(working_palette,Main_palette,sizeof(T_Palette));
memcpy(Main_palette,temp_palette,sizeof(T_Palette));
}
@ -1444,7 +1452,7 @@ void Button_Palette(void)
{
memcpy(temp_palette,Main_palette,sizeof(T_Palette));
memcpy(Main_palette,working_palette,sizeof(T_Palette));
Set_nice_menu_colors(color_usage);
Set_nice_menu_colors(color_usage,0);
memcpy(working_palette,Main_palette,sizeof(T_Palette));
memcpy(Main_palette,temp_palette,sizeof(T_Palette));
}
@ -1946,7 +1954,7 @@ void Button_Palette(void)
memcpy(backup_palette,working_palette,sizeof(T_Palette));
memcpy(temp_palette,Main_palette,sizeof(T_Palette));
memcpy(Main_palette,working_palette,sizeof(T_Palette));
Set_nice_menu_colors(color_usage);
Set_nice_menu_colors(color_usage,0);
memcpy(working_palette,Main_palette,sizeof(T_Palette));
memcpy(Main_palette,temp_palette,sizeof(T_Palette));
Set_palette(working_palette);

View File

@ -28,3 +28,9 @@ void Set_palette_RGB_scale(int);
// The resulting range is [0-255]
byte Round_palette_component(byte comp);
/*!
Adds 4 menu colors in the current palette.
@param color_usage An up-to-date color usage table (byte[256]) (read only)
@param not_picture 0 if the caller is the palette screen, 1 if it's a preview in the file selector.
*/
void Set_nice_menu_colors(dword * color_usage,int not_picture);