trunk: Implemented file loading of JPEG, TGA, TIFF and a few others, by using SDL_Image builtin loader. Added visible 'hourglass' cursor during 24bit color reduction.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1085 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-10-21 22:12:56 +00:00
parent 9ef0e6b74c
commit db130fc60d
12 changed files with 278 additions and 108 deletions

View File

@ -4,7 +4,7 @@ $(OBJDIR)/brush.o: brush.c global.h struct.h const.h graph.h misc.h errors.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 init.h buttons.h operatio.h pages.h \
palette.h errors.h readini.h saveini.h shade.h io.h help.h text.h \ palette.h errors.h readini.h saveini.h shade.h io.h help.h text.h \
sdlscreen.h windows.h brush.h input.h sdlscreen.h windows.h brush.h input.h special.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 operatio.h shade.h errors.h sdlscreen.h windows.h brush.h \ buttons.h operatio.h shade.h errors.h sdlscreen.h windows.h brush.h \
input.h engine.h input.h engine.h
@ -26,7 +26,8 @@ $(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h sdlscreen.h \
$(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.h $(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.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)/loadsave.o: loadsave.c buttons.h struct.h const.h errors.h global.h io.h \ $(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h errors.h global.h io.h \
loadsave.h misc.h op_c.h pages.h palette.h sdlscreen.h windows.h loadsave.h misc.h op_c.h pages.h palette.h sdlscreen.h windows.h \
engine.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 \
engine.h pages.h loadsave.h sdlscreen.h errors.h readini.h saveini.h \ engine.h pages.h loadsave.h sdlscreen.h errors.h readini.h saveini.h \
io.h text.h setup.h windows.h brush.h palette.h realpath.h io.h text.h setup.h windows.h brush.h palette.h realpath.h
@ -41,19 +42,22 @@ $(OBJDIR)/pages.o: pages.c global.h struct.h const.h pages.h errors.h misc.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 pages.h help.h sdlscreen.h errors.h op_c.h windows.h input.h \ buttons.h pages.h help.h sdlscreen.h errors.h op_c.h windows.h input.h \
palette.h shade.h palette.h shade.h
$(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 \
pxdouble.h pxwide.h graph.h pxdouble.h pxwide.h
$(OBJDIR)/pxquad.o: pxquad.c global.h struct.h const.h sdlscreen.h misc.h pxquad.h $(OBJDIR)/pxquad.o: pxquad.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxquad.h
$(OBJDIR)/pxsimple.o: pxsimple.c global.h struct.h const.h sdlscreen.h misc.h \ $(OBJDIR)/pxsimple.o: pxsimple.c global.h struct.h const.h sdlscreen.h misc.h \
pxsimple.h graph.h pxsimple.h
$(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h sdlscreen.h misc.h pxtall.h \ $(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxsimple.h pxtall.h pxsimple.h
$(OBJDIR)/pxtall2.o: pxtall2.c global.h struct.h const.h sdlscreen.h misc.h \ $(OBJDIR)/pxtall2.o: pxtall2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxtall2.h pxtall2.h
$(OBJDIR)/pxtriple.o: pxtriple.c global.h struct.h const.h sdlscreen.h misc.h \ $(OBJDIR)/pxtriple.o: pxtriple.c global.h struct.h const.h sdlscreen.h misc.h \
pxtriple.h graph.h pxtriple.h
$(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h sdlscreen.h misc.h pxwide.h $(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
$(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h \ pxwide.h
$(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \
pxwide2.h pxwide2.h
$(OBJDIR)/readini.o: readini.c const.h global.h struct.h misc.h readini.h $(OBJDIR)/readini.o: readini.c const.h global.h struct.h misc.h readini.h
$(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \ $(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \
@ -73,5 +77,6 @@ $(OBJDIR)/text.o: text.c SFont.h struct.h const.h global.h sdlscreen.h io.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 \
pages.h pages.h
$(OBJDIR)/version.o: version.c
$(OBJDIR)/windows.o: windows.c windows.h struct.h const.h global.h graph.h engine.h \ $(OBJDIR)/windows.o: windows.c windows.h struct.h const.h global.h graph.h engine.h \
misc.h sdlscreen.h errors.h misc.h sdlscreen.h errors.h input.h

Binary file not shown.

View File

@ -112,6 +112,7 @@ enum FILE_FORMATS
FORMAT_C64, FORMAT_C64,
FORMAT_KCF, FORMAT_KCF,
FORMAT_PAL, FORMAT_PAL,
FORMAT_MISC, ///< Must be last of enum: others formats recognized by SDL_image
}; };
/// Default format for 'save as' /// Default format for 'save as'

View File

@ -100,15 +100,35 @@ Libpng
make install (long) make install (long)
Files created in /usr/local/include and /usr/local/lib .... Files created in /usr/local/include and /usr/local/lib ....
libjpeg (optional - improves SDL_image with JPEG reading)
http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/project/li/libjpeg/libjpeg/
jpegsr6.zip
Uncompress in temporary directory
./configure --enable-shared
make
(make install doesn't work. Copy jpeglib.h, jmorecfg.h, jconfig.h in include, and libjpeg.a in lib)
libtiff (optional - improves SDL_image with TIFF reading)
ftp://ftp.sgi.com/graphics/tiff/
tiff-v3.4-tar.gz
Uncompress in temporary directory
./configure i686-pc-mingw32
make
Don't use 'make install', copy tiff.h libtiff.a manually instead.
SDL_image: SDL_image:
Requires: Libpng Requires: Libpng
Requires optionally: libtiff
Requires optionally: libjpeg
http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libsdl/ http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libsdl/
SDL_image-1.2.6.zip SDL_image-1.2.8.zip
Uncompress in temporary directory Uncompress in temporary directory
./configure ./configure
Check that png worked Check in the messages that png worked
Optionally check if jpeg worked too
Optionally check if tiff worked too
make make
make install make install prefix=/usr/mingw
FreeType: FreeType:
http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/m/mi/mingw-cross/ http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/m/mi/mingw-cross/

View File

@ -1,11 +1,19 @@
The following file: The following file
SDL_image.dll SDL_image.dll
is the runtime environment for the library SDL_image 1.2.70 by Sam Lantiga and Mattias Engdegård. is the runtime environment for the library SDL_image 1.2.8 by Sam Lantiga and Mattias Engdegård.
This library is distributed under the terms of the GNU LGPL license: This library is distributed under the terms of the GNU LGPL license:
http://www.gnu.org/copyleft/lesser.html http://www.gnu.org/copyleft/lesser.html
The source is available from the libraries page at the SDL website: The source is available from the libraries page at the SDL website:
http://www.libsdl.org/ http://www.libsdl.org/
=========================
Compiled by yrizoud on 21/10/2009 with static builds of :
libjpeg (JPEG library http://www.ijg.org/ release 6b of 27-Mar-1998 : jpegsr6.zip)
libtiff (TIFF library ftp://ftp.sgi.com/graphics/tiff/ : tiff-v3.4-tar.gz)
And dynamic version of :
libpng (http://www.libpng.org/pub/png/libpng.html) --> libpng13.dll requirement

7
init.c
View File

@ -267,12 +267,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
return 1; return 1;
} }
// Read the default palette // Read the default palette
for (i=0; i<256; i++) Get_SDL_Palette(SDLPal, gfx->Default_palette);
{
gfx->Default_palette[i].R=SDLPal->colors[i].r;
gfx->Default_palette[i].G=SDLPal->colors[i].g;
gfx->Default_palette[i].B=SDLPal->colors[i].b;
}
// Carré "noir" // Carré "noir"
MC_Black = Get_SDL_pixel_8(gui,cursor_x,cursor_y); MC_Black = Get_SDL_pixel_8(gui,cursor_x,cursor_y);

BIN
jpeg.dll Normal file

Binary file not shown.

View File

@ -30,6 +30,7 @@
#ifndef __no_pnglib__ #ifndef __no_pnglib__
#include <png.h> #include <png.h>
#endif #endif
#include <SDL_image.h>
#include "buttons.h" #include "buttons.h"
#include "const.h" #include "const.h"
@ -123,10 +124,15 @@ void Load_PNG(void);
void Save_PNG(void); void Save_PNG(void);
#endif #endif
// -- SDL_Image -------------------------------------------------------------
// (TGA, BMP, PNM, XPM, XCF, PCX, GIF, JPG, TIF, LBM, PNG)
void Load_SDL_Image(void);
void Init_preview(short width,short height,long size,int format,enum PIXEL_RATIO ratio); void Init_preview(short width,short height,long size,int format,enum PIXEL_RATIO ratio);
T_Format File_formats[NB_KNOWN_FORMATS] = { T_Format File_formats[NB_KNOWN_FORMATS] = {
{FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;iff;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;kcf;pal;c64;koa"}, {FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;iff;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;kcf;pal;c64;koa;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff"},
{FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, "", "*"}, {FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, "", "*"},
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 1, 1, "gif", "gif"}, {FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 1, 1, "gif", "gif"},
#ifndef __no_pnglib__ #ifndef __no_pnglib__
@ -145,6 +151,7 @@ T_Format File_formats[NB_KNOWN_FORMATS] = {
{FORMAT_KCF, " kcf", Test_KCF, Load_KCF, Save_KCF, 0, 0, "kcf", "kcf"}, {FORMAT_KCF, " kcf", Test_KCF, Load_KCF, Save_KCF, 0, 0, "kcf", "kcf"},
{FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 0, 0, "pal", "pal"}, {FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 0, 0, "pal", "pal"},
{FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 1, 1, "c64", "c64;koa"}, {FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 1, 1, "c64", "c64;koa"},
{FORMAT_MISC,"misc.", NULL, NULL, NULL, 1, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff"},
}; };
// Cette variable est alimentée après chargement réussi d'une image. // Cette variable est alimentée après chargement réussi d'une image.
@ -617,7 +624,8 @@ void Load_image(byte image)
if (Main_format>FORMAT_ALL_FILES) if (Main_format>FORMAT_ALL_FILES)
{ {
format = Get_fileformat(Main_format); format = Get_fileformat(Main_format);
format->Test(); if (format->Test)
format->Test();
} }
if (File_error) if (File_error)
@ -628,7 +636,7 @@ void Load_image(byte image)
{ {
format = Get_fileformat(index); format = Get_fileformat(index);
// Loadable format // Loadable format
if (format->Load == NULL) if (format->Test == NULL)
continue; continue;
// On appelle le testeur du format: // On appelle le testeur du format:
@ -638,9 +646,27 @@ void Load_image(byte image)
break; break;
} }
} }
if (File_error)
{
// Last try: with SDL_image
Image_24b=0;
Ratio_of_loaded_image=PIXEL_SIMPLE;
Load_SDL_Image();
if (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
// une preview), alors on flash l'utilisateur.
if (Pixel_load_function!=Pixel_load_in_preview)
Error(0);
return;
}
}
else
// Si on a su déterminer avec succès le format du fichier: // Si on a su déterminer avec succès le format du fichier:
if (!File_error)
{ {
// On peut charger le fichier: // On peut charger le fichier:
Image_24b=0; Image_24b=0;
@ -648,102 +674,104 @@ void Load_image(byte image)
// Dans certains cas il est possible que le chargement plante // Dans certains cas il est possible que le chargement plante
// après avoir modifié la palette. TODO // après avoir modifié la palette. TODO
format->Load(); format->Load();
}
if (File_error>0) if (File_error>0)
{ {
Error(0); Error(0);
} }
if (Image_24b) if (Image_24b)
{
// On vient de charger une image 24b
if (!File_error)
{ {
// On vient de charger une image 24b // Le chargement a réussi, on peut faire la conversion en 256 couleurs
if (!File_error) if (Pixel_load_function==Pixel_load_in_current_screen)
{ {
// Le chargement a réussi, on peut faire la conversion en 256 couleurs // Cas d'un chargement dans l'image
if (Pixel_load_function==Pixel_load_in_current_screen) Hide_cursor();
{ Cursor_shape=CURSOR_SHAPE_HOURGLASS;
// Cas d'un chargement dans l'image Display_cursor();
if (Convert_24b_bitmap_to_256(Main_screen,Buffer_image_24b,Main_image_width,Main_image_height,Main_palette)) Flush_update();
File_error=2; if (Convert_24b_bitmap_to_256(Main_screen,Buffer_image_24b,Main_image_width,Main_image_height,Main_palette))
else File_error=2;
{
Set_palette(Main_palette);
}
}
else else
{ {
// Cas d'un chargement dans la brosse Set_palette(Main_palette);
if (Convert_24b_bitmap_to_256(Brush,Buffer_image_24b,Brush_width,Brush_height,Main_palette))
File_error=2;
} }
//if (!File_error)
// Palette_256_to_64(Main_palette);
// Normalement plus besoin car 256 color natif, et c'etait probablement
// un bug - yr
}
free(Buffer_image_24b);
}
if (image)
{
if ( (File_error!=1) && (format->Backup_done) )
{
if (Pixel_load_function==Pixel_load_in_preview)
{
dword color_usage[256];
Count_used_colors_screen_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:
Main_fileformat=format->Identifier;
// Correction des dimensions
if (Main_image_width<1)
Main_image_width=1;
if (Main_image_height<1)
Main_image_height=1;
}
else if (File_error!=1)
{
// On considère que l'image chargée est encore modifiée
Main_image_is_modified=1;
// Et on documente la variable Main_fileformat avec la valeur:
Main_fileformat=format->Identifier;
} }
else else
{ {
// Dans ce cas, on sait que l'image n'a pas changé, mais ses // Cas d'un chargement dans la brosse
// paramètres (dimension, palette, ...) si. Donc on les restaures. Hide_cursor();
Download_infos_page_main(Main_backups->Pages); Cursor_shape=CURSOR_SHAPE_HOURGLASS;
Display_cursor();
Flush_update();
if (Convert_24b_bitmap_to_256(Brush,Buffer_image_24b,Brush_width,Brush_height,Main_palette))
File_error=2;
} }
} }
free(Buffer_image_24b);
}
if (image)
{
if ( (File_error!=1) && (format->Backup_done) )
{
if (Pixel_load_function==Pixel_load_in_preview)
{
dword color_usage[256];
Count_used_colors_screen_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:
Main_fileformat=format->Identifier;
// Correction des dimensions
if (Main_image_width<1)
Main_image_width=1;
if (Main_image_height<1)
Main_image_height=1;
}
else if (File_error!=1)
{
// On considère que l'image chargée est encore modifiée
Main_image_is_modified=1;
// Et on documente la variable Main_fileformat avec la valeur:
Main_fileformat=format->Identifier;
}
else
{
// Dans ce cas, on sait que l'image n'a pas changé, mais ses
// paramètres (dimension, palette, ...) si. Donc on les restaures.
Download_infos_page_main(Main_backups->Pages);
}
} }
else
// 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
// une preview), alors on flash l'utilisateur.
if (Pixel_load_function!=Pixel_load_in_preview)
Error(0);
} }
// -- Sauver n'importe quel type connu de fichier d'image (ou palette) ------ // -- Sauver n'importe quel type connu de fichier d'image (ou palette) ------
void Save_image(byte image) void Save_image(byte image)
{ {
T_Format *format;
// On place par défaut File_error à vrai au cas où on ne sache pas // On place par défaut File_error à vrai au cas où on ne sache pas
// sauver le format du fichier: (Est-ce vraiment utile??? Je ne crois pas!) // sauver le format du fichier: (Est-ce vraiment utile??? Je ne crois pas!)
File_error=1; File_error=1;
Read_pixel_function=(image)?Read_pixel_from_current_screen:Read_pixel_from_brush; Read_pixel_function=(image)?Read_pixel_from_current_screen:Read_pixel_from_brush;
Get_fileformat(Main_fileformat)->Save(); format = Get_fileformat(Main_fileformat);
if (format->Save)
format->Save();
if (File_error) if (File_error)
Error(0); Error(0);
@ -6847,6 +6875,79 @@ void Save_PNG(void)
} }
#endif // __no_pnglib__ #endif // __no_pnglib__
void Load_SDL_Image(void)
{
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
word x_pos,y_pos;
// long file_size;
dword pixel;
long file_size;
SDL_Surface * surface;
Get_full_filename(filename,0);
File_error=0;
surface = IMG_Load(filename);
if (!surface)
{
File_error=1;
return;
}
file_size=File_length(filename);
if (surface->format->BytesPerPixel == 1)
{
// 8bpp image
Init_preview(surface->w, surface->h, file_size ,FORMAT_MISC, PIXEL_SIMPLE);
// Read palette
if (surface->format->palette)
{
Get_SDL_Palette(surface->format->palette, Main_palette);
Set_palette(Main_palette);
Remap_fileselector();
}
Main_image_width=surface->w;
Main_image_height=surface->h;
for (y_pos=0; y_pos<Main_image_height; y_pos++)
{
for (x_pos=0; x_pos<Main_image_width; x_pos++)
{
Pixel_load_function(x_pos,y_pos,Get_SDL_pixel_8(surface, x_pos, y_pos));
}
}
}
else
{
// Hi/Trucolor
Init_preview_24b(surface->w, surface->h, file_size ,FORMAT_ALL_IMAGES);
Main_image_width=surface->w;
Main_image_height=surface->h;
for (y_pos=0; y_pos<Main_image_height; y_pos++)
{
for (x_pos=0; x_pos<Main_image_width; x_pos++)
{
pixel = Get_SDL_pixel_hicolor(surface, x_pos, y_pos);
Pixel_load_24b(
x_pos,
y_pos,
((pixel & surface->format->Rmask) >> surface->format->Rshift) << surface->format->Rloss,
((pixel & surface->format->Gmask) >> surface->format->Gshift) << surface->format->Gloss,
((pixel & surface->format->Bmask) >> surface->format->Bshift) << surface->format->Bloss);
}
}
}
SDL_FreeSurface(surface);
}
// Saves an image. // Saves an image.
// This routine will only be called when all hope is lost, memory thrashed, etc // 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 careful, // It's the last chance to save anything, but the code has to be extremely careful,
@ -6918,4 +7019,4 @@ T_Format * Get_fileformat(byte format)
// Normally impossible to reach this point, unless called with an invalid // Normally impossible to reach this point, unless called with an invalid
// enum.... // enum....
return safe_default; return safe_default;
} }

View File

@ -67,9 +67,9 @@ T_Format * Get_fileformat(byte format);
// -- File formats // -- File formats
#ifndef __no_pnglib__ #ifndef __no_pnglib__
#define NB_KNOWN_FORMATS 17 ///< Total number of known file formats. #define NB_KNOWN_FORMATS 18 ///< Total number of known file formats.
#else #else
// Without pnglib // Without pnglib
#define NB_KNOWN_FORMATS 16 ///< Total number of known file formats. #define NB_KNOWN_FORMATS 17 ///< Total number of known file formats.
#endif #endif

2
op_c.c
View File

@ -826,6 +826,7 @@ void CS_Generate(T_Cluster_set * cs, T_Occurrence_table * to)
// On les remet dans le set // On les remet dans le set
CS_Set(cs,&Nouveau1); CS_Set(cs,&Nouveau1);
CS_Set(cs,&Nouveau2); CS_Set(cs,&Nouveau2);
} }
} }
@ -1275,7 +1276,6 @@ int Convert_24b_bitmap_to_256(T_Bitmap256 dest,T_Bitmap24B source,int width,int
if (table!=0) if (table!=0)
break; break;
} }
if (table!=0) if (table!=0)
{ {
//Convert_24b_bitmap_to_256_Floyd_Steinberg(dest,source,width,height,palette,table); //Convert_24b_bitmap_to_256_Floyd_Steinberg(dest,source,width,height,palette,table);

View File

@ -139,10 +139,11 @@ void Update_rect(short x, short y, unsigned short width, unsigned short height)
} }
// Converts a SDL_Surface (indexed colors or RGB) into an array of bytes ///
// (indexed colors). /// Converts a SDL_Surface (indexed colors or RGB) into an array of bytes
// If dest is NULL, it's allocated by malloc(). Otherwise, be sure to /// (indexed colors).
// pass a buffer of the right dimensions. /// If dest is NULL, it's allocated by malloc(). Otherwise, be sure to
/// pass a buffer of the right dimensions.
byte * Surface_to_bytefield(SDL_Surface *source, byte * dest) byte * Surface_to_bytefield(SDL_Surface *source, byte * dest)
{ {
byte *src; byte *src;
@ -185,13 +186,41 @@ SDL_Color Color_to_SDL_color(byte index)
return color; return color;
} }
// Reads a pixel in a SDL surface. /// Reads a pixel in a 8-bit SDL surface.
// Warning, this is only suitable for 8-bit surfaces.
byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y) byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y)
{ {
return ((byte *)(bmp->pixels))[(y*bmp->pitch+x)]; return ((byte *)(bmp->pixels))[(y*bmp->pitch+x)];
} }
/// Reads a pixel in a multi-byte SDL surface.
dword Get_SDL_pixel_hicolor(SDL_Surface *bmp, int x, int y)
{
switch(bmp->format->BytesPerPixel)
{
case 4:
default:
return *((dword *)((byte *)bmp->pixels+(y*bmp->pitch+x*4)));
case 3:
return *(((dword *)((byte *)bmp->pixels+(y*bmp->pitch+x*3)))) & 0xFFFFFF;
case 2:
return *((word *)((byte *)bmp->pixels+(y*bmp->pitch+x*2)));
}
}
/// Convert a SDL Palette to a grafx2 palette
void Get_SDL_Palette(const SDL_Palette * sdl_palette, T_Palette palette)
{
int i;
for (i=0; i<256; i++)
{
palette[i].R=sdl_palette->colors[i].r;
palette[i].G=sdl_palette->colors[i].g;
palette[i].B=sdl_palette->colors[i].b;
}
}
void Clear_border(byte color) void Clear_border(byte color)
{ {
int width; int width;

View File

@ -42,9 +42,20 @@ byte* Screen_pixels;
void Update_rect(short x, short y, unsigned short width, unsigned short height); void Update_rect(short x, short y, unsigned short width, unsigned short height);
void Flush_update(void); void Flush_update(void);
///
/// Converts a SDL_Surface (indexed colors or RGB) into an array of bytes
/// (indexed colors).
/// If dest is NULL, it's allocated by malloc(). Otherwise, be sure to
/// pass a buffer of the right dimensions.
byte * Surface_to_bytefield(SDL_Surface *source, byte * dest); byte * Surface_to_bytefield(SDL_Surface *source, byte * dest);
/// 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.
byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y); byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y);
/// Reads a pixel in a multi-byte SDL surface.
dword Get_SDL_pixel_hicolor(SDL_Surface *bmp, int x, int y);
/// Convert a SDL Palette to a grafx2 palette
void Get_SDL_Palette(const SDL_Palette * sdl_palette, T_Palette palette);
/// ///
/// Clears the parts of screen that are outside of the editing area. /// Clears the parts of screen that are outside of the editing area.