From 9dd1c38b7ff8389632c31f5d57a366b5f39edba3 Mon Sep 17 00:00:00 2001 From: GMT 1998 Austin Donnelly Date: Sat, 14 Nov 1998 23:28:47 +0000 Subject: [PATCH] app/gimpimage.h app/gimpimageP.h app/gimpimage.c app/gimage_cmds.c Sat Nov 14 23:16:55 GMT 1998 Austin Donnelly * app/gimpimage.h * app/gimpimageP.h * app/gimpimage.c * app/gimage_cmds.c * app/file_new_dialog.c * app/info_window.c * libgimp/gimp.h * libgimp/gimpimage.c * plug-ins/newsprint/newsprint.c * plug-ins/tiff/tiff.c: gimp_image_{get,set}_resolution() calls now get and set both X and Y resolutions. Gimp image struct now has two resolution fields, one for each direction. I've updated the two plugins which used the info (TIFF and newsprint). --- ChangeLog | 16 +++++++++++ app/core/gimpimage-guides.c | 20 ++++++++++---- app/core/gimpimage-guides.h | 6 ++-- app/core/gimpimage-merge.c | 20 ++++++++++---- app/core/gimpimage-merge.h | 6 ++-- app/core/gimpimage-projection.c | 20 ++++++++++---- app/core/gimpimage-projection.h | 6 ++-- app/core/gimpimage-resize.c | 20 ++++++++++---- app/core/gimpimage-resize.h | 6 ++-- app/core/gimpimage-scale.c | 20 ++++++++++---- app/core/gimpimage-scale.h | 6 ++-- app/core/gimpimage.c | 20 ++++++++++---- app/core/gimpimage.h | 6 ++-- app/core/gimpprojection-construct.c | 20 ++++++++++---- app/core/gimpprojection-construct.h | 6 ++-- app/dialogs/image-new-dialog.c | 7 +++-- app/dialogs/info-window.c | 4 ++- app/file_new_dialog.c | 7 +++-- app/gimage_cmds.c | 43 ++++++++++++++++++++--------- app/gimpimage.c | 20 ++++++++++---- app/gimpimage.h | 6 ++-- app/gimpimageP.h | 3 +- app/gui/file-new-dialog.c | 7 +++-- app/gui/info-window.c | 4 ++- app/info_window.c | 4 ++- libgimp/gimp.h | 7 +++-- libgimp/gimpimage.c | 30 ++++++++++++++------ libgimp/gimpimage_pdb.c | 30 ++++++++++++++------ plug-ins/common/newsprint.c | 11 ++++++-- plug-ins/common/tiff.c | 35 +++++++++++------------ plug-ins/newsprint/newsprint.c | 11 ++++++-- plug-ins/tiff/tiff.c | 35 +++++++++++------------ 32 files changed, 319 insertions(+), 143 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7761eadf7..450ae4af79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Sat Nov 14 23:16:55 GMT 1998 Austin Donnelly + + * app/gimpimage.h + * app/gimpimageP.h + * app/gimpimage.c + * app/gimage_cmds.c + * app/file_new_dialog.c + * app/info_window.c + * libgimp/gimp.h + * libgimp/gimpimage.c + * plug-ins/newsprint/newsprint.c + * plug-ins/tiff/tiff.c: gimp_image_{get,set}_resolution() calls + now get and set both X and Y resolutions. Gimp image struct now + has two resolution fields, one for each direction. I've updated + the two plugins which used the info (TIFF and newsprint). + Sat Nov 14 20:15:46 CET 1998 Marc Lehmann * plug-ins/script-fu/scripts/*: removed the image diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpimage-guides.h b/app/core/gimpimage-guides.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpimage-guides.h +++ b/app/core/gimpimage-guides.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpimage-merge.h b/app/core/gimpimage-merge.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpimage-merge.h +++ b/app/core/gimpimage-merge.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/core/gimpimage-projection.c b/app/core/gimpimage-projection.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpimage-projection.c +++ b/app/core/gimpimage-projection.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpimage-projection.h b/app/core/gimpimage-projection.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpimage-projection.h +++ b/app/core/gimpimage-projection.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpimage-resize.h b/app/core/gimpimage-resize.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpimage-resize.h +++ b/app/core/gimpimage-resize.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpimage-scale.h b/app/core/gimpimage-scale.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpimage-scale.h +++ b/app/core/gimpimage-scale.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/core/gimpprojection-construct.h b/app/core/gimpprojection-construct.h index 0ebb8ba10f..5725689845 100644 --- a/app/core/gimpprojection-construct.h +++ b/app/core/gimpprojection-construct.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/dialogs/image-new-dialog.c b/app/dialogs/image-new-dialog.c index 6135f80eef..29478cc587 100644 --- a/app/dialogs/image-new-dialog.c +++ b/app/dialogs/image-new-dialog.c @@ -118,7 +118,10 @@ file_new_ok_callback (GtkWidget *widget, gimage = gimage_new (vals->width, vals->height, vals->type); - gimp_image_set_resolution(gimage, vals->resolution); + /* XXX for the moment, we set both x and y resolution to the same, + * since we don't have the UI to get both values from the user, and + * besides, that's what PhotoShop seems to do. */ + gimp_image_set_resolution(gimage, vals->resolution, vals->resolution); /* Make the background (or first) layer */ layer = layer_new (gimage, gimage->width, gimage->height, @@ -448,7 +451,7 @@ file_new_cmd_callback (GtkWidget *widget, vals->width = gdisp->gimage->width; vals->height = gdisp->gimage->height; vals->type = gimage_base_type (gdisp->gimage); - vals->resolution = gdisp->gimage->resolution; + vals->resolution = gdisp->gimage->xresolution; vals->unit = last_unit; vals->res_unit = 1.0; } diff --git a/app/dialogs/info-window.c b/app/dialogs/info-window.c index dba2f4aeb9..873832016e 100644 --- a/app/dialogs/info-window.c +++ b/app/dialogs/info-window.c @@ -199,7 +199,9 @@ info_window_update (InfoDialog *info_win, (int) gdisp->gimage->width, (int) gdisp->gimage->height); /* image resolution */ - sprintf (iwd->resolution_str, "%g dpi", gdisp->gimage->resolution); + sprintf (iwd->resolution_str, "%g x %g dpi", + gdisp->gimage->xresolution, + gdisp->gimage->yresolution); /* zoom ratio */ sprintf (iwd->scale_str, "%d:%d", diff --git a/app/file_new_dialog.c b/app/file_new_dialog.c index 6135f80eef..29478cc587 100644 --- a/app/file_new_dialog.c +++ b/app/file_new_dialog.c @@ -118,7 +118,10 @@ file_new_ok_callback (GtkWidget *widget, gimage = gimage_new (vals->width, vals->height, vals->type); - gimp_image_set_resolution(gimage, vals->resolution); + /* XXX for the moment, we set both x and y resolution to the same, + * since we don't have the UI to get both values from the user, and + * besides, that's what PhotoShop seems to do. */ + gimp_image_set_resolution(gimage, vals->resolution, vals->resolution); /* Make the background (or first) layer */ layer = layer_new (gimage, gimage->width, gimage->height, @@ -448,7 +451,7 @@ file_new_cmd_callback (GtkWidget *widget, vals->width = gdisp->gimage->width; vals->height = gdisp->gimage->height; vals->type = gimage_base_type (gdisp->gimage); - vals->resolution = gdisp->gimage->resolution; + vals->resolution = gdisp->gimage->xresolution; vals->unit = last_unit; vals->res_unit = 1.0; } diff --git a/app/gimage_cmds.c b/app/gimage_cmds.c index d239cecdc7..9fe72080b5 100644 --- a/app/gimage_cmds.c +++ b/app/gimage_cmds.c @@ -2783,25 +2783,32 @@ static Argument * gimage_get_resolution_invoker (Argument *args) { GImage *gimage; - float resolution; + float xresolution; + float yresolution; Argument *return_args; - resolution = 0; + xresolution = 0.0; + yresolution = 0.0; success = TRUE; if (success) { int_value = args[0].value.pdb_int; - if ((gimage = gimage_get_ID (int_value))) - resolution = gimage->resolution; - else + if ((gimage = gimage_get_ID (int_value))) { + xresolution = gimage->xresolution; + yresolution = gimage->yresolution; + } else { success = FALSE; + } } return_args= procedural_db_return_args(&gimage_get_resolution_proc, success); if (success) - return_args[1].value.pdb_float = resolution; + { + return_args[1].value.pdb_float = xresolution; + return_args[2].value.pdb_float = yresolution; + } return return_args; } @@ -2818,8 +2825,12 @@ ProcArg gimage_get_resolution_args[] = ProcArg gimage_get_resolution_out_args[] = { { PDB_FLOAT, - "resolution", - "the image's resolution, in dots per inch" + "xresolution", + "the image's resolution in the x-axis, in dots per inch" + }, + { PDB_FLOAT, + "yresolution", + "the image's resolution in the y-axis, in dots per inch" } }; @@ -2838,7 +2849,7 @@ ProcRecord gimage_get_resolution_proc = gimage_get_resolution_args, /* Output arguments */ - 1, + 2, gimage_get_resolution_out_args, /* Exec method */ @@ -2866,7 +2877,9 @@ gimage_set_resolution_invoker (Argument *args) if (success) { float_value = args[1].value.pdb_float; - gimage->resolution = float_value; + gimage->xresolution = float_value; + float_value = args[2].value.pdb_float; + gimage->yresolution = float_value; } return_args= procedural_db_return_args(&gimage_set_resolution_proc, success); @@ -2882,8 +2895,12 @@ ProcArg gimage_set_resolution_args[] = "the image" }, { PDB_FLOAT, - "resolution", - "resolution in dots per inch" + "xresolution", + "resolution in x-axis, in dots per inch" + }, + { PDB_FLOAT, + "yresolution", + "resolution in y-axis, in dots per inch" } }; @@ -2898,7 +2915,7 @@ ProcRecord gimage_set_resolution_proc = PDB_INTERNAL, /* Input arguments */ - 2, + 3, gimage_set_resolution_args, /* Output arguments */ diff --git a/app/gimpimage.c b/app/gimpimage.c index 0bbe75c103..fbdcd66fae 100644 --- a/app/gimpimage.c +++ b/app/gimpimage.c @@ -155,7 +155,8 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview = NULL; gimage->parasites = parasite_list_new(); gimp_matrix_identity(gimage->transform); - gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->xresolution = 72.0; /* maybe should be rc-supplied default? */ + gimage->yresolution = 72.0; gimage->save_proc= NULL; } @@ -301,15 +302,22 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) void -gimp_image_set_resolution (GimpImage *gimage, float resolution) +gimp_image_set_resolution (GimpImage *gimage, + float xresolution, + float yresolution) { - gimage->resolution = resolution; + gimage->xresolution = xresolution; + gimage->yresolution = yresolution; } -float -gimp_image_get_resolution (GimpImage *gimage) +void +gimp_image_get_resolution (GimpImage *gimage, + float *xresolution, + float *yresolution) { - return gimage->resolution; + g_return_if_fail(xresolution && yresolution); + *xresolution = gimage->xresolution; + *yresolution = gimage->yresolution; } void diff --git a/app/gimpimage.h b/app/gimpimage.h index 0ebb8ba10f..5725689845 100644 --- a/app/gimpimage.h +++ b/app/gimpimage.h @@ -104,8 +104,10 @@ GtkType gimp_image_get_type(void); GimpImage * gimp_image_new (int, int, int); void gimp_image_set_filename (GimpImage *, char *); -void gimp_image_set_resolution (GimpImage *, float); -float gimp_image_get_resolution (GimpImage *); +void gimp_image_set_resolution (GimpImage *, float, float); +void gimp_image_get_resolution (GimpImage *, + float *, + float *); void gimp_image_set_save_proc (GimpImage *, PlugInProcDef *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *); void gimp_image_resize (GimpImage *, int, int, int, int); diff --git a/app/gimpimageP.h b/app/gimpimageP.h index 0257457734..78e6a6d4ec 100644 --- a/app/gimpimageP.h +++ b/app/gimpimageP.h @@ -22,7 +22,8 @@ struct _GimpImage PlugInProcDef *save_proc; /* last PDB save proc used */ int width, height; /* width and height attributes */ - float resolution; /* image res, in dpi */ + float xresolution; /* image x-res, in dpi */ + float yresolution; /* image y-res, in dpi */ int base_type; /* base gimp_image type */ unsigned char * cmap; /* colormap--for indexed */ diff --git a/app/gui/file-new-dialog.c b/app/gui/file-new-dialog.c index 6135f80eef..29478cc587 100644 --- a/app/gui/file-new-dialog.c +++ b/app/gui/file-new-dialog.c @@ -118,7 +118,10 @@ file_new_ok_callback (GtkWidget *widget, gimage = gimage_new (vals->width, vals->height, vals->type); - gimp_image_set_resolution(gimage, vals->resolution); + /* XXX for the moment, we set both x and y resolution to the same, + * since we don't have the UI to get both values from the user, and + * besides, that's what PhotoShop seems to do. */ + gimp_image_set_resolution(gimage, vals->resolution, vals->resolution); /* Make the background (or first) layer */ layer = layer_new (gimage, gimage->width, gimage->height, @@ -448,7 +451,7 @@ file_new_cmd_callback (GtkWidget *widget, vals->width = gdisp->gimage->width; vals->height = gdisp->gimage->height; vals->type = gimage_base_type (gdisp->gimage); - vals->resolution = gdisp->gimage->resolution; + vals->resolution = gdisp->gimage->xresolution; vals->unit = last_unit; vals->res_unit = 1.0; } diff --git a/app/gui/info-window.c b/app/gui/info-window.c index dba2f4aeb9..873832016e 100644 --- a/app/gui/info-window.c +++ b/app/gui/info-window.c @@ -199,7 +199,9 @@ info_window_update (InfoDialog *info_win, (int) gdisp->gimage->width, (int) gdisp->gimage->height); /* image resolution */ - sprintf (iwd->resolution_str, "%g dpi", gdisp->gimage->resolution); + sprintf (iwd->resolution_str, "%g x %g dpi", + gdisp->gimage->xresolution, + gdisp->gimage->yresolution); /* zoom ratio */ sprintf (iwd->scale_str, "%d:%d", diff --git a/app/info_window.c b/app/info_window.c index dba2f4aeb9..873832016e 100644 --- a/app/info_window.c +++ b/app/info_window.c @@ -199,7 +199,9 @@ info_window_update (InfoDialog *info_win, (int) gdisp->gimage->width, (int) gdisp->gimage->height); /* image resolution */ - sprintf (iwd->resolution_str, "%g dpi", gdisp->gimage->resolution); + sprintf (iwd->resolution_str, "%g x %g dpi", + gdisp->gimage->xresolution, + gdisp->gimage->yresolution); /* zoom ratio */ sprintf (iwd->scale_str, "%d:%d", diff --git a/libgimp/gimp.h b/libgimp/gimp.h index f033d7fb36..d55b7755a1 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -445,8 +445,11 @@ void gimp_image_attach_new_parasite (gint32 image_ID, void gimp_image_detach_parasite (gint32 image_ID, const char *name); void gimp_image_set_resolution (gint32 image_ID, - float resolution); -float gimp_image_get_resolution (gint32 image_ID); + float xresolution, + float yresolution); +void gimp_image_get_resolution (gint32 image_ID, + float *xresolution, + float *yresolution); gint32 gimp_image_get_layer_by_tattoo (gint32 image_ID, gint32 tattoo); gint32 gimp_image_get_channel_by_tattoo (gint32 image_ID, diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c index fcbab4d613..c5fd4c45be 100644 --- a/libgimp/gimpimage.c +++ b/libgimp/gimpimage.c @@ -982,30 +982,43 @@ gimp_image_detach_parasite (gint32 image_ID, const char *name) gimp_destroy_params (return_vals, nreturn_vals); } -float -gimp_image_get_resolution (gint32 image_ID) +void +gimp_image_get_resolution (gint32 image_ID, + float *xresolution, + float *yresolution) { GParam *return_vals; int nreturn_vals; - float result; + float xres; + float yres; + + g_return_if_fail(xresolution && yresolution); return_vals = gimp_run_procedure ("gimp_image_get_resolution", &nreturn_vals, PARAM_IMAGE, image_ID, PARAM_END); - result = 0.0; /* error return value */ + /* error return values */ + xres = 0.0; + yres = 0.0; + if (return_vals[0].data.d_status == STATUS_SUCCESS) - result = return_vals[1].data.d_float; + { + xres = return_vals[1].data.d_float; + yres = return_vals[2].data.d_float; + } gimp_destroy_params (return_vals, nreturn_vals); - return result; + *xresolution = xres; + *yresolution = yres; } void gimp_image_set_resolution (gint32 image_ID, - float resolution) + float xresolution, + float yresolution) { GParam *return_vals; int nreturn_vals; @@ -1013,7 +1026,8 @@ gimp_image_set_resolution (gint32 image_ID, return_vals = gimp_run_procedure ("gimp_image_set_resolution", &nreturn_vals, PARAM_IMAGE, image_ID, - PARAM_FLOAT, resolution, + PARAM_FLOAT, xresolution, + PARAM_FLOAT, yresolution, PARAM_END); gimp_destroy_params (return_vals, nreturn_vals); diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index fcbab4d613..c5fd4c45be 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -982,30 +982,43 @@ gimp_image_detach_parasite (gint32 image_ID, const char *name) gimp_destroy_params (return_vals, nreturn_vals); } -float -gimp_image_get_resolution (gint32 image_ID) +void +gimp_image_get_resolution (gint32 image_ID, + float *xresolution, + float *yresolution) { GParam *return_vals; int nreturn_vals; - float result; + float xres; + float yres; + + g_return_if_fail(xresolution && yresolution); return_vals = gimp_run_procedure ("gimp_image_get_resolution", &nreturn_vals, PARAM_IMAGE, image_ID, PARAM_END); - result = 0.0; /* error return value */ + /* error return values */ + xres = 0.0; + yres = 0.0; + if (return_vals[0].data.d_status == STATUS_SUCCESS) - result = return_vals[1].data.d_float; + { + xres = return_vals[1].data.d_float; + yres = return_vals[2].data.d_float; + } gimp_destroy_params (return_vals, nreturn_vals); - return result; + *xresolution = xres; + *yresolution = yres; } void gimp_image_set_resolution (gint32 image_ID, - float resolution) + float xresolution, + float yresolution) { GParam *return_vals; int nreturn_vals; @@ -1013,7 +1026,8 @@ gimp_image_set_resolution (gint32 image_ID, return_vals = gimp_run_procedure ("gimp_image_set_resolution", &nreturn_vals, PARAM_IMAGE, image_ID, - PARAM_FLOAT, resolution, + PARAM_FLOAT, xresolution, + PARAM_FLOAT, yresolution, PARAM_END); gimp_destroy_params (return_vals, nreturn_vals); diff --git a/plug-ins/common/newsprint.c b/plug-ins/common/newsprint.c index 9107bec486..9e191c6ce9 100644 --- a/plug-ins/common/newsprint.c +++ b/plug-ins/common/newsprint.c @@ -1265,8 +1265,15 @@ newsprint_dialog (GDrawable *drawable) gtk_container_add (GTK_CONTAINER (frame), table); #ifdef GIMP_HAVE_RESOLUTION_INFO - pvals_ui.input_spi = - gimp_image_get_resolution(gimp_drawable_image_id(drawable->id)); + { + float xres, yres; + gimp_image_get_resolution(gimp_drawable_image_id(drawable->id), + &xres, &yres); + /* XXX hack: should really note both resolutions, and use + * rectangular cells, not square cells. But I'm being lazy, + * and the majority of the world works with xres == yres */ + pvals_ui.input_spi = xres; + } #endif st.input_spi = NULL; diff --git a/plug-ins/common/tiff.c b/plug-ins/common/tiff.c index 5014f278f0..5744543111 100644 --- a/plug-ins/common/tiff.c +++ b/plug-ins/common/tiff.c @@ -466,18 +466,11 @@ static gint32 load_image (char *filename) { /* any resolution info in the file? */ #ifdef GIMP_HAVE_RESOLUTION_INFO { - float xres=0, yres=0; + float xres=0.0, yres=0.0; unsigned short units; - float res=0.0; if (TIFFGetField (tif, TIFFTAG_XRESOLUTION, &xres)) { if (TIFFGetField (tif, TIFFTAG_YRESOLUTION, &yres)) { - if (abs(xres - yres) > 1e-5) - g_message("TIFF warning: x resolution differs " - "from y resolution (%g != %g)\n" - "Using x resolution\n", xres, yres); - - res = xres; if (TIFFGetField (tif, TIFFTAG_RESOLUTIONUNIT, &units)) { switch(units) { @@ -485,14 +478,16 @@ static gint32 load_image (char *filename) { /* ImageMagick writes files with this silly resunit */ g_message("TIFF warning: resolution units meaningless, " "forcing 72 dpi\n"); - res = 72.0; + xres = 72.0; + yres = 72.0; break; case RESUNIT_INCH: break; case RESUNIT_CENTIMETER: - res = ((float)xres) * 2.54; + xres *= 2.54; + yres *= 2.54; break; default: @@ -506,16 +501,18 @@ static gint32 load_image (char *filename) { } } else { /* xres but no yres */ g_message("TIFF warning: no y resolution info, assuming same as x\n"); + yres = xres; } /* sanity check, since division by zero later could be embarrassing */ - if (res < 1e-5) { + if (xres < 1e-5 || yres < 1e-5) { g_message("TIFF: image resolution is zero: forcing 72 dpi\n"); - res = 72.0; + xres = 72.0; + yres = 72.0; } /* now set the new image's resolution info */ - gimp_image_set_resolution (image, res); + gimp_image_set_resolution (image, xres, yres); } /* no x res tag => we assume we have no resolution info, so we @@ -1133,11 +1130,15 @@ static gint save_image (char *filename, gint32 image, gint32 layer) { #ifdef GIMP_HAVE_RESOLUTION_INFO /* resolution fields */ { - float resolution = gimp_image_get_resolution(image); - if (resolution) + float xresolution; + float yresolution; + + gimp_image_get_resolution (image, &xresolution, &yresolution); + + if (xresolution > 1e-5 && yresolution > 1e-5) { - TIFFSetField (tif, TIFFTAG_XRESOLUTION, resolution); - TIFFSetField (tif, TIFFTAG_YRESOLUTION, resolution); + TIFFSetField (tif, TIFFTAG_XRESOLUTION, xresolution); + TIFFSetField (tif, TIFFTAG_YRESOLUTION, yresolution); TIFFSetField (tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); } } diff --git a/plug-ins/newsprint/newsprint.c b/plug-ins/newsprint/newsprint.c index 9107bec486..9e191c6ce9 100644 --- a/plug-ins/newsprint/newsprint.c +++ b/plug-ins/newsprint/newsprint.c @@ -1265,8 +1265,15 @@ newsprint_dialog (GDrawable *drawable) gtk_container_add (GTK_CONTAINER (frame), table); #ifdef GIMP_HAVE_RESOLUTION_INFO - pvals_ui.input_spi = - gimp_image_get_resolution(gimp_drawable_image_id(drawable->id)); + { + float xres, yres; + gimp_image_get_resolution(gimp_drawable_image_id(drawable->id), + &xres, &yres); + /* XXX hack: should really note both resolutions, and use + * rectangular cells, not square cells. But I'm being lazy, + * and the majority of the world works with xres == yres */ + pvals_ui.input_spi = xres; + } #endif st.input_spi = NULL; diff --git a/plug-ins/tiff/tiff.c b/plug-ins/tiff/tiff.c index 5014f278f0..5744543111 100644 --- a/plug-ins/tiff/tiff.c +++ b/plug-ins/tiff/tiff.c @@ -466,18 +466,11 @@ static gint32 load_image (char *filename) { /* any resolution info in the file? */ #ifdef GIMP_HAVE_RESOLUTION_INFO { - float xres=0, yres=0; + float xres=0.0, yres=0.0; unsigned short units; - float res=0.0; if (TIFFGetField (tif, TIFFTAG_XRESOLUTION, &xres)) { if (TIFFGetField (tif, TIFFTAG_YRESOLUTION, &yres)) { - if (abs(xres - yres) > 1e-5) - g_message("TIFF warning: x resolution differs " - "from y resolution (%g != %g)\n" - "Using x resolution\n", xres, yres); - - res = xres; if (TIFFGetField (tif, TIFFTAG_RESOLUTIONUNIT, &units)) { switch(units) { @@ -485,14 +478,16 @@ static gint32 load_image (char *filename) { /* ImageMagick writes files with this silly resunit */ g_message("TIFF warning: resolution units meaningless, " "forcing 72 dpi\n"); - res = 72.0; + xres = 72.0; + yres = 72.0; break; case RESUNIT_INCH: break; case RESUNIT_CENTIMETER: - res = ((float)xres) * 2.54; + xres *= 2.54; + yres *= 2.54; break; default: @@ -506,16 +501,18 @@ static gint32 load_image (char *filename) { } } else { /* xres but no yres */ g_message("TIFF warning: no y resolution info, assuming same as x\n"); + yres = xres; } /* sanity check, since division by zero later could be embarrassing */ - if (res < 1e-5) { + if (xres < 1e-5 || yres < 1e-5) { g_message("TIFF: image resolution is zero: forcing 72 dpi\n"); - res = 72.0; + xres = 72.0; + yres = 72.0; } /* now set the new image's resolution info */ - gimp_image_set_resolution (image, res); + gimp_image_set_resolution (image, xres, yres); } /* no x res tag => we assume we have no resolution info, so we @@ -1133,11 +1130,15 @@ static gint save_image (char *filename, gint32 image, gint32 layer) { #ifdef GIMP_HAVE_RESOLUTION_INFO /* resolution fields */ { - float resolution = gimp_image_get_resolution(image); - if (resolution) + float xresolution; + float yresolution; + + gimp_image_get_resolution (image, &xresolution, &yresolution); + + if (xresolution > 1e-5 && yresolution > 1e-5) { - TIFFSetField (tif, TIFFTAG_XRESOLUTION, resolution); - TIFFSetField (tif, TIFFTAG_YRESOLUTION, resolution); + TIFFSetField (tif, TIFFTAG_XRESOLUTION, xresolution); + TIFFSetField (tif, TIFFTAG_YRESOLUTION, yresolution); TIFFSetField (tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); } }