structure for savign all done - now just need to fill in the save() functions

in the loaders (yes laoder are also savers - loader and saver are
interchangeable).


SVN revision: 1098
This commit is contained in:
Carsten Haitzler 1999-11-01 14:35:23 +00:00
parent 3a59c44b66
commit c944ff5199
4 changed files with 139 additions and 3 deletions

47
api.c
View File

@ -1856,3 +1856,50 @@ imlib_image_remove_and_free_attached_data_value(Imlib_Image image, char *key)
t = __imlib_RemoveTag(im, key);
__imlib_FreeTag(im, t);
}
void
imlib_save_image(Imlib_Image image, char *filename)
{
ImlibImage *im;
CAST_IMAGE(im, image);
__imlib_SaveImage(im, filename, NULL, 0, NULL);
}
void
imlib_save_image_with_progress_callback(Imlib_Image image, char *filename,
Imlib_Internal_Progress_Function progress_function,
char progress_granulatiy)
{
ImlibImage *im;
CAST_IMAGE(im, image);
__imlib_SaveImage(im, filename, progress_function,
progress_granulatiy, NULL);
}
void
imlib_save_image_with_error_return(Imlib_Image image, char *filename,
Imlib_Load_Error *error_return)
{
ImlibImage *im;
CAST_IMAGE(im, image);
__imlib_SaveImage(im, filename, NULL, 0, error_return);
}
void
imlib_save_image_with_progress_callback_and_error_return(Imlib_Image image,
char *filename,
Imlib_Internal_Progress_Function progress_function,
char progress_granulatiy,
Imlib_Load_Error *error_return)
{
ImlibImage *im;
CAST_IMAGE(im, image);
__imlib_SaveImage(im, filename,progress_function,
progress_granulatiy, error_return);
}

15
api.h
View File

@ -48,6 +48,8 @@ enum _imlib_load_error
IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS,
IMLIB_LOAD_ERROR_OUT_OF_MEMORY,
IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS,
IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE,
IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE,
IMLIB_LOAD_ERROR_UNKNOWN
};
@ -373,13 +375,20 @@ int imlib_image_get_attached_value(Imlib_Image image, char *key);
void imlib_image_remove_attached_data_value(Imlib_Image image, char *key);
void imlib_image_remove_and_free_attached_data_value(Imlib_Image image, char *key);
# if 0
/* image saving functions */
void imlib_save_image(Imlib_Image image, char *filename);
void imlib_save_image_with_progress_callback(Imlib_Image image, char *filename,
Imlib_Progress_Function progress_function,
char progress_granulatiy);
void imlib_save_image_with_error_return(Imlib_Image image, char *filename,
Imlib_Load_Error *error_return);
void imlib_save_image_with_progress_callback_and_error_return(Imlib_Image image,
char *filename,
Imlib_Progress_Function progress_function,
char progress_granulatiy,
Imlib_Load_Error *error_return);
/* FIXME: */
/* need to add arbitary rotation routines */
/* need to add polygon fill code */
#endif
#endif

72
image.c
View File

@ -1116,3 +1116,75 @@ __imlib_DirtyImage(ImlibImage *im)
__imlib_DirtyPixmapsForImage(im);
}
void
__imlib_SaveImage(ImlibImage *im, char *file,
void (*progress)(ImlibImage *im, char percent,
int update_x, int update_y,
int update_w, int update_h),
char progress_granularity,
ImlibLoadError *er)
{
ImlibLoader *l;
ImlibLoadError e;
if (!im->file)
{
if (*er)
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
return;
}
/* fidn the laoder for the format - if its null use the extension */
l = __imlib_FindBestLoaderForFileFormat(file, im->format);
/* no loader - abort */
if (!l)
{
if (er)
*er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
return;
}
/* no saver function in loader - abort */
if (!l->save)
{
if (er)
*er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
return;
}
/* if they want an error returned - assume none by default */
if (*er)
*er = LOAD_ERROR_NONE;
if (im->file)
free(im->file);
e = l->save(im, progress, progress_granularity);
if ((er) && (e == 0))
{
*er = LOAD_ERROR_UNKNOWN;
if (errno == EEXIST)
*er = LOAD_ERROR_FILE_DOES_NOT_EXIST;
else if (errno == EISDIR)
*er = LOAD_ERROR_FILE_IS_DIRECTORY;
else if (errno == EISDIR)
*er = LOAD_ERROR_FILE_IS_DIRECTORY;
else if (errno == EACCES)
*er = LOAD_ERROR_PERMISSION_DENIED_TO_WRITE;
else if (errno == ENAMETOOLONG)
*er = LOAD_ERROR_PATH_TOO_LONG;
else if (errno == ENOENT)
*er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT;
else if (errno == ENOTDIR)
*er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY;
else if (errno == EFAULT)
*er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE;
else if (errno == ELOOP)
*er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS;
else if (errno == ENOMEM)
*er = LOAD_ERROR_OUT_OF_MEMORY;
else if (errno == EMFILE)
*er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS;
else if (errno == ENOSPC)
*er = LOAD_ERROR_OUT_OF_DISK_SPACE;
else if (errno == EROFS)
*er = LOAD_ERROR_PERMISSION_DENIED_TO_WRITE;
}
}

View File

@ -23,6 +23,8 @@ enum _load_error
LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS,
LOAD_ERROR_OUT_OF_MEMORY,
LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS,
LOAD_ERROR_PERMISSION_DENIED_TO_WRITE,
LOAD_ERROR_OUT_OF_DISK_SPACE,
LOAD_ERROR_UNKNOWN
};
@ -159,6 +161,12 @@ void __imlib_FreePixmap(Display *d, Pixmap p);
void __imlib_FlushCache(void);
void __imlib_DirtyPixmapsForImage(ImlibImage *im);
void __imlib_DirtyImage(ImlibImage *im);
void __imlib_SaveImage(ImlibImage *im, char *file,
void (*progress)(ImlibImage *im, char percent,
int update_x, int update_y,
int update_w, int update_h),
char progress_granularity,
ImlibLoadError *er);
# define IMAGE_HAS_ALPHA(im) ((im)->flags & F_HAS_ALPHA)
# define IMAGE_IS_UNLOADED(im) ((im)->flags & F_UNLOADED)