diff --git a/Makefile.dep b/Makefile.dep index f911692d..bf29f1e0 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -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 \ 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 \ - 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 \ buttons.h operatio.h shade.h errors.h sdlscreen.h windows.h brush.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)/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 \ - 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 \ 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 @@ -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 \ buttons.h pages.h help.h sdlscreen.h errors.h op_c.h windows.h input.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 \ - pxdouble.h pxwide.h -$(OBJDIR)/pxquad.o: pxquad.c global.h struct.h const.h sdlscreen.h misc.h pxquad.h + graph.h pxdouble.h pxwide.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 \ - pxsimple.h -$(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h sdlscreen.h misc.h pxtall.h \ - pxsimple.h -$(OBJDIR)/pxtall2.o: pxtall2.c global.h struct.h const.h sdlscreen.h misc.h \ + graph.h pxsimple.h +$(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ + pxtall.h pxsimple.h +$(OBJDIR)/pxtall2.o: pxtall2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ pxtall2.h $(OBJDIR)/pxtriple.o: pxtriple.c global.h struct.h const.h sdlscreen.h misc.h \ - pxtriple.h -$(OBJDIR)/pxwide.o: pxwide.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 pxtriple.h +$(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ + pxwide.h +$(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h graph.h \ pxwide2.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 \ @@ -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 \ sdlscreen.h windows.h input.h help.h misc.h readline.h buttons.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 \ - misc.h sdlscreen.h errors.h + misc.h sdlscreen.h errors.h input.h diff --git a/SDL_image.dll b/SDL_image.dll index a8fbdcfa..9b371caf 100644 Binary files a/SDL_image.dll and b/SDL_image.dll differ diff --git a/const.h b/const.h index d61583f9..4cfd3829 100644 --- a/const.h +++ b/const.h @@ -112,6 +112,7 @@ enum FILE_FORMATS FORMAT_C64, FORMAT_KCF, FORMAT_PAL, + FORMAT_MISC, ///< Must be last of enum: others formats recognized by SDL_image }; /// Default format for 'save as' diff --git a/doc/COMPILING.txt b/doc/COMPILING.txt index fb7728d2..a6ea24be 100644 --- a/doc/COMPILING.txt +++ b/doc/COMPILING.txt @@ -100,15 +100,35 @@ Libpng make install (long) 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: Requires: Libpng + Requires optionally: libtiff + Requires optionally: libjpeg 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 ./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 install + make install prefix=/usr/mingw FreeType: http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/m/mi/mingw-cross/ diff --git a/doc/README-SDL_image.txt b/doc/README-SDL_image.txt index 9a3b5a53..052582ac 100644 --- a/doc/README-SDL_image.txt +++ b/doc/README-SDL_image.txt @@ -1,11 +1,19 @@ -The following file: +The following file 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: http://www.gnu.org/copyleft/lesser.html The source is available from the libraries page at the SDL website: 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 diff --git a/init.c b/init.c index 1a372aa6..5ea4596c 100644 --- a/init.c +++ b/init.c @@ -267,12 +267,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx) return 1; } // Read the default palette - for (i=0; i<256; i++) - { - 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; - } + Get_SDL_Palette(SDLPal, gfx->Default_palette); // Carré "noir" MC_Black = Get_SDL_pixel_8(gui,cursor_x,cursor_y); diff --git a/jpeg.dll b/jpeg.dll new file mode 100644 index 00000000..12dfb0d2 Binary files /dev/null and b/jpeg.dll differ diff --git a/loadsave.c b/loadsave.c index 96aaa279..e76b9b2e 100644 --- a/loadsave.c +++ b/loadsave.c @@ -30,6 +30,7 @@ #ifndef __no_pnglib__ #include #endif +#include #include "buttons.h" #include "const.h" @@ -123,10 +124,15 @@ void Load_PNG(void); void Save_PNG(void); #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); 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_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 1, 1, "gif", "gif"}, #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_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_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. @@ -617,7 +624,8 @@ void Load_image(byte image) if (Main_format>FORMAT_ALL_FILES) { format = Get_fileformat(Main_format); - format->Test(); + if (format->Test) + format->Test(); } if (File_error) @@ -628,7 +636,7 @@ void Load_image(byte image) { format = Get_fileformat(index); // Loadable format - if (format->Load == NULL) + if (format->Test == NULL) continue; // On appelle le testeur du format: @@ -638,9 +646,27 @@ void Load_image(byte image) 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: - if (!File_error) { // On peut charger le fichier: Image_24b=0; @@ -648,102 +674,104 @@ void Load_image(byte image) // Dans certains cas il est possible que le chargement plante // après avoir modifié la palette. TODO format->Load(); + } - if (File_error>0) - { - Error(0); - } + if (File_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 - if (!File_error) + // Le chargement a réussi, on peut faire la conversion en 256 couleurs + if (Pixel_load_function==Pixel_load_in_current_screen) { - // Le chargement a réussi, on peut faire la conversion en 256 couleurs - if (Pixel_load_function==Pixel_load_in_current_screen) - { - // Cas d'un chargement dans l'image - if (Convert_24b_bitmap_to_256(Main_screen,Buffer_image_24b,Main_image_width,Main_image_height,Main_palette)) - File_error=2; - else - { - Set_palette(Main_palette); - } - } + // Cas d'un chargement dans l'image + Hide_cursor(); + Cursor_shape=CURSOR_SHAPE_HOURGLASS; + Display_cursor(); + Flush_update(); + if (Convert_24b_bitmap_to_256(Main_screen,Buffer_image_24b,Main_image_width,Main_image_height,Main_palette)) + File_error=2; else { - // Cas d'un chargement dans la brosse - if (Convert_24b_bitmap_to_256(Brush,Buffer_image_24b,Brush_width,Brush_height,Main_palette)) - File_error=2; + Set_palette(Main_palette); } - //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 { - // 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); + // Cas d'un chargement dans la brosse + Hide_cursor(); + 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) ------ void Save_image(byte image) { + T_Format *format; + // 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!) File_error=1; 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) Error(0); @@ -6847,6 +6875,79 @@ void Save_PNG(void) } #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_posw, surface->h, file_size ,FORMAT_ALL_IMAGES); + Main_image_width=surface->w; + Main_image_height=surface->h; + + for (y_pos=0; y_posformat->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. // 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, @@ -6918,4 +7019,4 @@ T_Format * Get_fileformat(byte format) // Normally impossible to reach this point, unless called with an invalid // enum.... return safe_default; -} +} \ No newline at end of file diff --git a/loadsave.h b/loadsave.h index df761483..88451dbf 100644 --- a/loadsave.h +++ b/loadsave.h @@ -67,9 +67,9 @@ T_Format * Get_fileformat(byte format); // -- File formats #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 // 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 diff --git a/op_c.c b/op_c.c index f2bdee9a..e0d28767 100644 --- a/op_c.c +++ b/op_c.c @@ -826,6 +826,7 @@ void CS_Generate(T_Cluster_set * cs, T_Occurrence_table * to) // On les remet dans le set CS_Set(cs,&Nouveau1); 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) break; } - if (table!=0) { //Convert_24b_bitmap_to_256_Floyd_Steinberg(dest,source,width,height,palette,table); diff --git a/sdlscreen.c b/sdlscreen.c index df0594a6..af0a266c 100644 --- a/sdlscreen.c +++ b/sdlscreen.c @@ -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). -// If dest is NULL, it's allocated by malloc(). Otherwise, be sure to -// pass a buffer of the right dimensions. +/// +/// 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 *src; @@ -185,13 +186,41 @@ SDL_Color Color_to_SDL_color(byte index) return color; } -// Reads a pixel in a SDL surface. -// Warning, this is only suitable for 8-bit surfaces. +/// Reads a pixel in a 8-bit SDL surface. byte Get_SDL_pixel_8(SDL_Surface *bmp, int x, int y) { 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) { int width; diff --git a/sdlscreen.h b/sdlscreen.h index de674193..455865ab 100644 --- a/sdlscreen.h +++ b/sdlscreen.h @@ -42,9 +42,20 @@ byte* Screen_pixels; void Update_rect(short x, short y, unsigned short width, unsigned short height); 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); +/// Gets the RGB 24-bit color currently associated with a palette index. 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); +/// 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.