From 2bfbc03cb812f7505635a4484a2f73f7a65ae91a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 5 Feb 2018 01:30:57 +0100 Subject: [PATCH] Display the bpp of the picture in the Load/Save Dialog --- src/fileformats.c | 51 ++++++++++++++++++++++++++++--------------- src/filesel.c | 3 +-- src/loadsave.c | 27 +++++++++++++---------- src/loadsave.h | 2 +- src/miscfileformats.c | 15 +++---------- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/fileformats.c b/src/fileformats.c index 6e0becb0..037db713 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -614,7 +614,7 @@ void Load_IFF(T_IO_Context * context) byte * buffer; T_Components * SHAM_palettes = NULL; unsigned SHAM_palette_count = 0; - byte truecolor = 0; + byte bpp = 0; byte Image_HAM = 0; T_IFF_PCHG_Palette * PCHG_palettes = NULL; @@ -698,8 +698,7 @@ void Load_IFF(T_IO_Context * context) else ratio = PIXEL_WIDE; // 1.5 <= ratio } - if (header.BitPlanes > 8) - truecolor = 1; + bpp = header.BitPlanes; while (File_error == 0 && Read_bytes(IFF_file,section,4) @@ -712,7 +711,7 @@ void Load_IFF(T_IO_Context * context) if ((header.BitPlanes==6 && nb_colors==16) || (header.BitPlanes==8 && nb_colors==64)) { Image_HAM=header.BitPlanes; - truecolor = 1; + bpp = 3 * (header.BitPlanes - 2); // HAM6 = 12bpp, HAM8 = 18bpp } if (Config.Clear_palette) @@ -802,7 +801,7 @@ void Load_IFF(T_IO_Context * context) word version; Image_HAM = header.BitPlanes; - truecolor = 1; + bpp = 3 * (header.BitPlanes - 2); Read_word_be(IFF_file, &version); // always 0 section_size -= 2; SHAM_palette_count = section_size >> 5; // 32 bytes per palette (16 colors * 2 bytes) @@ -982,7 +981,7 @@ void Load_IFF(T_IO_Context * context) } fseek(IFF_file, (section_size+1)&~1, SEEK_CUR); if (PCHG_palettes != NULL) - truecolor = 1; + bpp = 12; } else if (memcmp(section, "TINY", 4) == 0) { @@ -995,7 +994,7 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s // Load thumbnail if in preview mode if ((context->Type == CONTEXT_PREVIEW || context->Type == CONTEXT_PREVIEW_PALETTE) && iff_format == FORMAT_PBM) { - Pre_load(context, tiny_width, tiny_height,file_size,iff_format,ratio,truecolor); + Pre_load(context, tiny_width, tiny_height,file_size,iff_format,ratio,bpp); PBM_Decode(context, IFF_file, header.Compression, tiny_width, tiny_height); fclose(IFF_file); IFF_file = NULL; @@ -1021,7 +1020,7 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s // ACBM format : ABIT = Amiga BITplanes // The ABIT chunk contains contiguous bitplane data. // The chunk contains sequential data for bitplane 0 through bitplane n. - Pre_load(context, header.Width, header.Height, file_size, iff_format, ratio, truecolor); + Pre_load(context, header.Width, header.Height, file_size, iff_format, ratio, bpp); // compute row size real_line_size = (context->Width+15) & ~15; plane_line_size = real_line_size >> 3; // 8bits per byte @@ -1066,7 +1065,7 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s Original_screen_X = header.X_screen; Original_screen_Y = header.Y_screen; - Pre_load(context, header.Width, header.Height, file_size, iff_format, ratio, truecolor); + Pre_load(context, header.Width, header.Height, file_size, iff_format, ratio, bpp); context->Background_transparent = header.Mask == 2; context->Transparent_color = context->Background_transparent ? header.Transp_col : 0; @@ -2083,7 +2082,7 @@ void Load_BMP(T_IO_Context * context) } if (File_error == 0) { - Pre_load(context, header.Width,header.Height,file_size,FORMAT_BMP,PIXEL_SIMPLE,true_color); + Pre_load(context, header.Width,header.Height,file_size,FORMAT_BMP,PIXEL_SIMPLE,header.Nb_bits); if (File_error==0) { if (true_color) @@ -2434,7 +2433,7 @@ void Load_ICO(T_IO_Context * context) mask[1] = 0x0000FF00; mask[2] = 0x000000FF; } - Pre_load(context, bmpheader.Width,real_height,File_length_file(file),FORMAT_ICO,PIXEL_SIMPLE,(bmpheader.Nb_bits > 8) || (nb_colors > 256)); + Pre_load(context, bmpheader.Width,real_height,File_length_file(file),FORMAT_ICO,PIXEL_SIMPLE,bmpheader.Nb_bits); if (bmpheader.Nb_bits <= 8) Load_BMP_Palette(context, file, nb_colors, 0); else @@ -2843,7 +2842,7 @@ void Load_GIF(T_IO_Context * context) else ratio=PIXEL_SIMPLE; - Pre_load(context, LSDB.Width,LSDB.Height,file_size,FORMAT_GIF,ratio,0); + Pre_load(context, LSDB.Width,LSDB.Height,file_size,FORMAT_GIF,ratio,(LSDB.Resol&7)+1); context->Width=LSDB.Width; context->Height=LSDB.Height; @@ -3988,9 +3987,10 @@ void Load_PCX(T_IO_Context * context) Original_screen_X=PCX_header.Screen_X; Original_screen_Y=PCX_header.Screen_Y; + Pre_load(context, context->Width, context->Height, file_size, FORMAT_PCX, PIXEL_SIMPLE, PCX_header.Plane * PCX_header.Depth); + if (!(PCX_header.Plane==3 && PCX_header.Depth==8)) { - Pre_load(context, context->Width,context->Height,file_size,FORMAT_PCX,PIXEL_SIMPLE,0); if (File_error==0) { // On prépare la palette à accueillir les valeurs du fichier PCX @@ -4198,9 +4198,6 @@ void Load_PCX(T_IO_Context * context) else { // Image 24 bits!!! - - Pre_load(context,context->Width,context->Height,file_size,FORMAT_PCX,PIXEL_SIMPLE,1); - if (File_error==0) { line_size=PCX_header.Bytes_per_plane_line*3; @@ -4761,6 +4758,7 @@ static void Load_PNG_Sub(T_IO_Context * context, FILE * file) png_byte color_type; png_byte bit_depth; png_voidp user_chunk_ptr; + byte bpp; // Setup a return point. If a pnglib loading error occurs // in this if(), the else will be executed. @@ -4782,6 +4780,23 @@ static void Load_PNG_Sub(T_IO_Context * context, FILE * file) color_type = png_get_color_type(png_ptr,info_ptr); bit_depth = png_get_bit_depth(png_ptr,info_ptr); + switch (color_type) + { + case PNG_COLOR_TYPE_GRAY_ALPHA: + bpp = bit_depth * 2; + break; + case PNG_COLOR_TYPE_RGB: + bpp = bit_depth * 3; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + bpp = bit_depth * 4; + break; + case PNG_COLOR_TYPE_PALETTE: + case PNG_COLOR_TYPE_GRAY: + default: + bpp = bit_depth; + } + // If it's any supported file // (Note: As of writing this, this test covers every possible // image format of libpng) @@ -4833,9 +4848,9 @@ static void Load_PNG_Sub(T_IO_Context * context, FILE * file) } } if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) - Pre_load(context,png_get_image_width(png_ptr,info_ptr),png_get_image_height(png_ptr,info_ptr),File_length_file(file),FORMAT_PNG,PIXEL_SIMPLE,1); + Pre_load(context,png_get_image_width(png_ptr,info_ptr),png_get_image_height(png_ptr,info_ptr),File_length_file(file),FORMAT_PNG,PIXEL_SIMPLE,bpp); else - Pre_load(context,png_get_image_width(png_ptr,info_ptr),png_get_image_height(png_ptr,info_ptr),File_length_file(file),FORMAT_PNG,context->Ratio,0); + Pre_load(context,png_get_image_width(png_ptr,info_ptr),png_get_image_height(png_ptr,info_ptr),File_length_file(file),FORMAT_PNG,context->Ratio,bpp); if (File_error==0) { diff --git a/src/filesel.c b/src/filesel.c index 12bd6e03..ef9aa288 100644 --- a/src/filesel.c +++ b/src/filesel.c @@ -1517,7 +1517,6 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context Print_in_window(9,47,"Filename",MC_Dark,MC_Light); Print_in_window(9,59,"Image:",MC_Dark,MC_Light); - Print_in_window(101,59,"Size:",MC_Dark,MC_Light); Print_in_window(228,59,"(",MC_Dark,MC_Light); Print_in_window(292,59,")",MC_Dark,MC_Light); @@ -2144,7 +2143,7 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context // On nettoie la zone où va s'afficher la preview: Window_rectangle(183,95,PREVIEW_WIDTH,PREVIEW_HEIGHT,MC_Light); // On efface les dimensions de l'image - Window_rectangle(143,59,72,8,MC_Light); + Window_rectangle(101,59,120,8,MC_Light); // On efface la taille du fichier Window_rectangle(236,59,56,8,MC_Light); // On efface le format du fichier diff --git a/src/loadsave.c b/src/loadsave.c index 7d68cd15..4165b359 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -382,10 +382,14 @@ int Get_frame_duration(T_IO_Context *context) /// /// 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) +void Pre_load(T_IO_Context *context, short width, short height, long file_size, int format, enum PIXEL_RATIO ratio, byte bpp) { char str[10]; + byte truecolor; + if (bpp == 0) + bpp = 8; // default to 8bits + truecolor = (bpp > 8) ? 1 : 0; context->Pitch = width; // default context->Width = width; context->Height = height; @@ -410,32 +414,33 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size, Num2str(width,str,4); Num2str(height,str+5,4); str[4]='x'; - Print_in_window(143,59,str,MC_Black,MC_Light); } else { - Print_in_window(143,59,"VERY BIG!",MC_Black,MC_Light); + memcpy(str, "VERY BIG!", 10); } + Print_in_window(101,59,str,MC_Black,MC_Light); + snprintf(str, sizeof(str), "%2dbpp", bpp); + Print_in_window(181,59,str,MC_Black,MC_Light); // Affichage de la taille du fichier if (file_size<1048576) { // Le fichier fait moins d'un Mega, on affiche sa taille direct Num2str(file_size,str,7); - Print_in_window(236,59,str,MC_Black,MC_Light); } - else if ((file_size/1024)<100000) + else if (((file_size+512)/1024)<100000) { // Le fichier fait plus d'un Mega, on peut afficher sa taille en Ko - Num2str(file_size/1024,str,5); - strcpy(str+5,"Kb"); - Print_in_window(236,59,str,MC_Black,MC_Light); + Num2str((file_size+512)/1024,str,5); + strcpy(str+5,"KB"); } else { // Le fichier fait plus de 100 Mega octets (cas très rare :)) - Print_in_window(236,59,"LARGE!!",MC_Black,MC_Light); + memcpy(str,"LARGE!!",8); } + Print_in_window(236,59,str,MC_Black,MC_Light); // Affichage du vrai format if (format!=Selector->Format_filter) @@ -1123,7 +1128,7 @@ void Load_SDL_Image(T_IO_Context *context) { // 8bpp image - Pre_load(context, surface->w, surface->h, file_size ,FORMAT_MISC, PIXEL_SIMPLE, 0); + Pre_load(context, surface->w, surface->h, file_size ,FORMAT_MISC, PIXEL_SIMPLE, 8); // Read palette if (surface->format->palette) @@ -1144,7 +1149,7 @@ void Load_SDL_Image(T_IO_Context *context) { { // Hi/Trucolor - Pre_load(context, surface->w, surface->h, file_size ,FORMAT_ALL_IMAGES, PIXEL_SIMPLE, 1); + Pre_load(context, surface->w, surface->h, file_size ,FORMAT_ALL_IMAGES, PIXEL_SIMPLE, 8 * surface->format->BytesPerPixel); } for (y_pos=0; y_posHeight; y_pos++) diff --git a/src/loadsave.h b/src/loadsave.h index b262e4d9..637dd5ac 100644 --- a/src/loadsave.h +++ b/src/loadsave.h @@ -204,7 +204,7 @@ unsigned int Nb_known_formats(void); // Internal use /// 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); +void Pre_load(T_IO_Context *context, short width, short height, long file_size, int format, enum PIXEL_RATIO ratio, byte bpp); /// Fill the entire current layer/frame of an image being loaded with a color. void Fill_canvas(T_IO_Context *context, byte color); diff --git a/src/miscfileformats.c b/src/miscfileformats.c index 2ddf774e..aa048863 100644 --- a/src/miscfileformats.c +++ b/src/miscfileformats.c @@ -1711,7 +1711,7 @@ void Load_PI1(T_IO_Context * context) if (Read_bytes(file,buffer,32034)) { // Initialisation de la preview - Pre_load(context, 320,200,File_length_file(file),FORMAT_PI1,PIXEL_SIMPLE,0); + Pre_load(context, 320,200,File_length_file(file),FORMAT_PI1,PIXEL_SIMPLE,4); if (File_error==0) { // Initialisation de la palette @@ -1719,9 +1719,6 @@ void Load_PI1(T_IO_Context * context) memset(context->Palette,0,sizeof(T_Palette)); PI1_decode_palette(buffer+2,(byte *)context->Palette); - context->Width=320; - context->Height=200; - // Chargement/décompression de l'image ptr=buffer+34; for (y_pos=0;y_pos<200;y_pos++) @@ -2043,7 +2040,7 @@ void Load_PC1(T_IO_Context * context) if (Read_bytes(file,buffercomp,size)) { // Initialisation de la preview - Pre_load(context, 320,200,File_length_file(file),FORMAT_PC1,PIXEL_SIMPLE,0); + Pre_load(context, 320,200,File_length_file(file),FORMAT_PC1,PIXEL_SIMPLE,4); if (File_error==0) { // Initialisation de la palette @@ -2051,9 +2048,6 @@ void Load_PC1(T_IO_Context * context) memset(context->Palette,0,sizeof(T_Palette)); PI1_decode_palette(buffercomp+2,(byte *)context->Palette); - context->Width=320; - context->Height=200; - // Décompression du buffer PC1_uncompress_packbits(buffercomp+34,bufferdecomp); @@ -2232,7 +2226,7 @@ void Load_NEO(T_IO_Context * context) if (Read_bytes(file,buffer,32128)) { // Initialisation de la preview - Pre_load(context, 320,200,File_length_file(file),FORMAT_NEO,PIXEL_SIMPLE,0); + Pre_load(context, 320,200,File_length_file(file),FORMAT_NEO,PIXEL_SIMPLE,4); if (File_error==0) { // Initialisation de la palette @@ -2241,9 +2235,6 @@ void Load_NEO(T_IO_Context * context) // on saute la résolution et le flag, chacun 2 bits PI1_decode_palette(buffer+4,(byte *)context->Palette); - context->Width=320; - context->Height=200; - // Chargement/décompression de l'image ptr=buffer+128; for (y_pos=0;y_pos<200;y_pos++)