GrafX2 2.9.3227
The ultimate 256-color painting program
loadsave.h File Reference

Saving and loading different picture formats. More...

#include <stdio.h>
#include "gfx2surface.h"
+ Include dependency graph for loadsave.h:
+ This graph shows which files directly or indirectly include this file:

Data Structures

struct  T_Color_cycle
 Data for a cycling color series. Heavily cloned from T_Gradient_array. More...
 
struct  T_IO_Context
 
struct  T_Format
 Data for an image file format. More...
 
struct  T_IMG_Header
 

Macros

#define PREVIEW_WIDTH   120
 
#define PREVIEW_HEIGHT   80
 

Typedefs

typedef void(* Func_IO_Test) (T_IO_Context *, FILE *)
 Type of a function that can be called for a T_IO_Context. Kind of a method. More...
 
typedef void(* Func_IO) (T_IO_Context *)
 

Enumerations

enum  CONTEXT_TYPE {
  CONTEXT_MAIN_IMAGE , CONTEXT_BRUSH , CONTEXT_PREVIEW , CONTEXT_PREVIEW_PALETTE ,
  CONTEXT_SURFACE , CONTEXT_PALETTE
}
 

Functions

void Init_context_preview (T_IO_Context *context, const char *file_name, const char *file_directory)
 Setup for loading a preview in fileselector. More...
 
void Init_context_layered_image (T_IO_Context *context, const char *file_name, const char *file_directory)
 Setup for loading/saving the current main image. More...
 
void Init_context_backup_image (T_IO_Context *context, const char *file_name, const char *file_directory)
 
void Init_context_flat_image (T_IO_Context *context, const char *file_name, const char *file_directory)
 
void Init_context_brush (T_IO_Context *context, const char *file_name, const char *file_directory)
 Setup for loading/saving the flattened version of current main image. More...
 
void Init_context_history_step (T_IO_Context *context, T_Page *page)
 
void Init_context_surface (T_IO_Context *context, const char *file_name, const char *file_directory)
 
void Destroy_context (T_IO_Context *context)
 Cleans up resources. More...
 
void Load_image (T_IO_Context *context)
 High-level picture loading function. More...
 
void Save_image (T_IO_Context *context)
 High-level picture saving function. More...
 
int Check_recovery (void)
 Checks if there are any pending safety backups, and then opens them. More...
 
void Rotate_safety_backups (void)
 Makes a safety backup periodically. More...
 
void Delete_safety_backups (void)
 Remove safety backups. Need to call on normal program exit. More...
 
void Image_emergency_backup (void)
 Function which attempts to save backups of the images (main and spare), called in case of SIGSEGV. More...
 
T_GFX2_SurfaceLoad_surface (const char *filename, const char *directory, T_Gradient_array *gradients)
 Load an arbitrary Surface. More...
 
const T_FormatGet_fileformat (byte format)
 
unsigned int Nb_known_formats (void)
 Total number of known file formats. More...
 
void Pre_load (T_IO_Context *context, short width, short height, long file_size, int format, enum PIXEL_RATIO ratio, byte bpp)
 Generic allocation and similar stuff, done at beginning of image load, as soon as size is known. More...
 
void Fill_canvas (T_IO_Context *context, byte color)
 Fill the entire current layer/frame of an image being loaded with a color. More...
 
byte Get_pixel (T_IO_Context *context, short x, short y)
 Query the color of a pixel (to save) More...
 
void Set_pixel (T_IO_Context *context, short x, short y, byte c)
 Set the color of a pixel (on load) More...
 
void Set_pixel_24b (T_IO_Context *context, short x, short y, byte r, byte g, byte b)
 Set the color of a 24bit pixel (on load) More...
 
void Set_loading_layer (T_IO_Context *context, int layer)
 Function to call when need to switch layers. More...
 
void Set_saving_layer (T_IO_Context *context, int layer)
 Function to call when need to switch layers. More...
 
void Set_frame_duration (T_IO_Context *context, int duration)
 Function to call when loading an image's duration. More...
 
int Get_frame_duration (T_IO_Context *context)
 Function to call to get an image's duration for saving. More...
 
void Set_image_mode (T_IO_Context *context, enum IMAGE_MODES mode)
 Function to set a specific image mode. More...
 
enum IMAGE_MODES Get_image_mode (T_IO_Context *context)
 get the current image mode More...
 

Variables

const T_Format File_formats []
 Array of the known file formats. More...
 

Detailed Description

Saving and loading different picture formats.

Also handles showing the preview in fileselectors.

Macro Definition Documentation

◆ PREVIEW_WIDTH

#define PREVIEW_WIDTH   120

◆ PREVIEW_HEIGHT

#define PREVIEW_HEIGHT   80

Typedef Documentation

◆ Func_IO_Test

typedef void(* Func_IO_Test) (T_IO_Context *, FILE *)

Type of a function that can be called for a T_IO_Context. Kind of a method.

◆ Func_IO

typedef void(* Func_IO) (T_IO_Context *)

Enumeration Type Documentation

◆ CONTEXT_TYPE

Enumerator
CONTEXT_MAIN_IMAGE 
CONTEXT_BRUSH 
CONTEXT_PREVIEW 
CONTEXT_PREVIEW_PALETTE 
CONTEXT_SURFACE 
CONTEXT_PALETTE 

Function Documentation

◆ Init_context_preview()

void Init_context_preview ( T_IO_Context context,
const char *  file_name,
const char *  file_directory 
)

Setup for loading a preview in fileselector.

References CONTEXT_PREVIEW, T_IO_Context::File_directory, T_IO_Context::File_name, NULL, and T_IO_Context::Type.

Referenced by Button_Load_or_Save().

◆ Init_context_layered_image()

◆ Init_context_backup_image()

void Init_context_backup_image ( T_IO_Context context,
const char *  file_name,
const char *  file_directory 
)

◆ Init_context_flat_image()

void Init_context_flat_image ( T_IO_Context context,
const char *  file_name,
const char *  file_directory 
)

◆ Init_context_brush()

◆ Init_context_history_step()

void Init_context_history_step ( T_IO_Context context,
T_Page page 
)

◆ Init_context_surface()

◆ Destroy_context()

◆ Load_image()

void Load_image ( T_IO_Context context)

High-level picture loading function.

References T_Components::B, Back_color, T_IO_Context::Background_transparent, T_Page::Background_transparent, Backup_layers(), T_Document::backups, T_IO_Context::bpp, Brush_original_palette, T_IO_Context::Buffer_image, T_IO_Context::Buffer_image_24b, T_IO_Context::Color_cycles, T_IO_Context::Comment, T_Page::Comment, Compute_optimal_menu_colors(), Config, CONTEXT_BRUSH, CONTEXT_MAIN_IMAGE, CONTEXT_PALETTE, CONTEXT_PREVIEW, CONTEXT_PREVIEW_PALETTE, CONTEXT_SURFACE, Convert_24b_bitmap_to_256(), Count_used_colors(), T_Document::current_layer, Cursor_shape, CURSOR_SHAPE_HOURGLASS, T_IO_Context::Cycle_range, DEFAULT_FILEFORMAT, Display_cursor(), Download_infos_page_main(), T_Color_cycle::End, T_Gradient_range::End, Error, Favorite_GUI_color(), T_IO_Context::File_directory, T_Page::File_directory, File_error, File_formats, T_IO_Context::File_name, T_IO_Context::File_name_unicode, T_Document::fileformat, T_Page::Filename, T_Page::Filename_unicode, Flush_update(), T_IO_Context::Format, format, FORMAT_ALL_FILES, FORMAT_CLIPBOARD, T_Components::G, Get_fileformat(), GFX2_ERROR, GFX2_Log(), GFX2_WARNING, T_Page::Gradients, T_IO_Context::Height, Hide_cursor, T_Page::Image, T_Document::image_height, T_Document::image_is_modified, T_Page::Image_mode, IMAGE_MODE_ANIMATION, T_Document::image_width, T_Color_cycle::Inverse, T_Gradient_range::Inverse, LAYER_NONE, T_Document::layers_visible, Load_ClipBoard_Image(), Load_Recoil_Image(), Main, MC_Black, MC_Light, MC_Window, Menu_factor_X, Nb_known_formats(), T_IO_Context::Nb_layers, NULL, Open_file_read(), T_IO_Context::Original_file_directory, T_IO_Context::Original_file_name, T_List_of_pages::Pages, T_GFX2_Surface::palette, T_IO_Context::Palette, T_Page::Palette, T_Document::palette, T_Format::Palette_only, Pixel, Pixel_ratio, PIXEL_TALL, PIXEL_TALL2, PIXEL_TALL3, PIXEL_WIDE, PIXEL_WIDE2, T_GFX2_Surface::pixels, T_Image::Pixels, T_IO_Context::Preview_bitmap, T_IO_Context::Preview_factor_X, T_IO_Context::Preview_factor_Y, PREVIEW_HEIGHT, T_IO_Context::Preview_pos_X, T_IO_Context::Preview_pos_Y, T_IO_Context::Preview_usage, PREVIEW_WIDTH, Print_in_window(), T_Components::R, T_Gradient_array::Range, T_IO_Context::Ratio, Realloc_brush(), Remap_brush(), Remap_screen_after_menu_colors_change(), T_Config::Safety_colors, Set_palette(), Set_palette_fake_24b(), T_Color_cycle::Speed, T_Gradient_range::Speed, T_Color_cycle::Start, T_Gradient_range::Start, T_IO_Context::Surface, T_IO_Context::Transparent_color, T_Page::Transparent_color, T_IO_Context::Type, Unicode_strdup(), Update_window_area, T_IO_Context::Width, and Window_rectangle().

Referenced by Button_Load_or_Save(), Button_Reload(), Init_program(), Load_picture(), Load_surface(), Main_handler(), and Process_backups().

◆ Save_image()

◆ Check_recovery()

int Check_recovery ( void  )

Checks if there are any pending safety backups, and then opens them.

Returns 0 if there were none Returns non-zero if some backups were loaded.

Returns
0 if no problem, -1 if the backup system cannot be activated, >=1 if some backups are restored

References Add_backup_file(), Backups_main, Backups_spare, Button_Page(), BUTTON_PAGE, Compute_limits(), Compute_paintbrush_coordinates(), Config_directory, Create_lock_file(), For_each_file(), Main, NULL, T_Document::offset_X, T_Document::offset_Y, Process_backups(), and Safety_backup_active.

Referenced by Init_program().

◆ Rotate_safety_backups()

◆ Delete_safety_backups()

void Delete_safety_backups ( void  )

◆ Image_emergency_backup()

void Image_emergency_backup ( void  )

Function which attempts to save backups of the images (main and spare), called in case of SIGSEGV.

It will save an image only if it has just one layer... otherwise, the risk of flattening a layered image (or saving just one detail layer) is too high.

References BACKUP_FILE_EXTENSION, T_Document::backups, Emergency_backup(), T_Bitmap::Image, T_Document::image_height, T_Document::image_width, Main, Main_screen, T_Page::Nb_layers, T_List_of_pages::Pages, T_Document::palette, SAFETYBACKUP_PREFIX_A, SAFETYBACKUP_PREFIX_B, Spare, and T_Document::visible_image.

◆ Load_surface()

T_GFX2_Surface * Load_surface ( const char *  filename,
const char *  directory,
T_Gradient_array gradients 
)

Load an arbitrary Surface.

Parameters
filenamefile to load.
directorypath of the file to load. if NULL, filename have to be a full path name
gradientsPass the address of a target T_Gradient_array if you want the gradients, NULL otherwise

References T_IO_Context::Color_cycles, T_IO_Context::Cycle_range, Destroy_context(), T_Color_cycle::End, T_Gradient_range::End, Init_context_surface(), T_Color_cycle::Inverse, T_Gradient_range::Inverse, Load_image(), NULL, T_Gradient_array::Range, T_Color_cycle::Speed, T_Gradient_range::Speed, T_Color_cycle::Start, T_Gradient_range::Start, and T_IO_Context::Surface.

Referenced by Define_icon(), Load_font(), Load_graphics(), and Render_text_SFont().

◆ Get_fileformat()

◆ Nb_known_formats()

unsigned int Nb_known_formats ( void  )

Total number of known file formats.

References File_formats.

Referenced by Button_Load_or_Save(), Get_fileformat(), and Load_image().

◆ Pre_load()

void Pre_load ( T_IO_Context context,
short  width,
short  height,
long  file_size,
int  format,
enum PIXEL_RATIO  ratio,
byte  bpp 
)

Generic allocation and similar stuff, done at beginning of image load, as soon as size is known.

References T_IO_Context::Background_transparent, Backup_new_image(), T_IO_Context::bpp, T_IO_Context::Buffer_image, T_IO_Context::Buffer_image_24b, T_IO_Context::Comment, Compute_optimal_menu_colors(), Config, CONTEXT_BRUSH, CONTEXT_MAIN_IMAGE, CONTEXT_PALETTE, CONTEXT_PREVIEW, CONTEXT_PREVIEW_PALETTE, CONTEXT_SURFACE, T_Document::current_layer, File_error, T_IO_Context::Format, format, Free_GFX2_Surface(), Get_fileformat(), GFX2_malloc, T_IO_Context::Height, T_Document::layers_visible, Main, T_Config::Maximize_preview, MC_Black, MC_Light, Menu_factor_X, Menu_factor_Y, Message_out_of_memory(), T_IO_Context::Nb_layers, New_GFX2_Surface(), NULL, Num2str, T_IO_Context::Original_height, T_IO_Context::Original_width, T_IO_Context::Palette, T_Format::Palette_only, T_IO_Context::Pitch, Pixel_ratio, PIXEL_TALL, PIXEL_TALL2, PIXEL_TALL3, PIXEL_WIDE, PIXEL_WIDE2, T_GFX2_Surface::pixels, T_IO_Context::Preview_bitmap, T_IO_Context::Preview_factor_X, T_IO_Context::Preview_factor_Y, PREVIEW_HEIGHT, T_IO_Context::Preview_pos_X, T_IO_Context::Preview_pos_Y, PREVIEW_WIDTH, Print_in_window(), T_IO_Context::Ratio, Round_div_max(), Set_loading_layer(), T_IO_Context::Surface, T_IO_Context::Target_address, T_IO_Context::Transparent_color, T_IO_Context::Type, Update_window_area, T_GFX2_Surface::w, T_IO_Context::Width, Window_pos_X, Window_pos_Y, and Window_rectangle().

Referenced by Load_2GS(), Load_BMP(), Load_C64(), Load_CA1(), Load_CEL(), Load_ClipBoard_Image(), Load_CM5(), Load_FLI(), Load_GIF(), Load_GOS(), Load_GPX(), Load_GRB(), Load_HGR(), Load_ICO(), Load_IFF(), Load_IMG(), Load_INFO(), Load_MOTO(), Load_MSX(), Load_NEO(), Load_PC1(), Load_PCX(), Load_PI1(), Load_PKM(), Load_PNG_Sub(), Load_PPH(), Load_PRG(), Load_Recoil_Image(), Load_SCR(), Load_SCx(), Load_SGX(), Load_TIFF_Sub(), and Load_TNY().

◆ Fill_canvas()

◆ Get_pixel()

◆ Set_pixel()

◆ Set_pixel_24b()

◆ Set_loading_layer()

◆ Set_saving_layer()

◆ Set_frame_duration()

void Set_frame_duration ( T_IO_Context context,
int  duration 
)

◆ Get_frame_duration()

int Get_frame_duration ( T_IO_Context context)

Function to call to get an image's duration for saving.

References T_Document::backups, CONTEXT_MAIN_IMAGE, T_IO_Context::Current_layer, T_Image::Duration, T_Page::Image, Main, T_List_of_pages::Pages, and T_IO_Context::Type.

Referenced by Save_GIF().

◆ Set_image_mode()

◆ Get_image_mode()

enum IMAGE_MODES Get_image_mode ( T_IO_Context context)

Variable Documentation

◆ File_formats

const T_Format File_formats[]
extern

Array of the known file formats.

Referenced by Button_Load_or_Save(), Get_fileformat(), Load_image(), and Nb_known_formats().