diff --git a/ChangeLog b/ChangeLog index be6f2efede..9891d8696d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +Mon Oct 5 02:42:47 PDT 1998 Manish Singh + + * app/general.c: applied gimp-bjj-980922-0, makes get_token's + EOF report "sticky" + + * app/devices.c: applied gimp-bjj-980922-1, sanity check our + saved device info for NULL pointers + + * app/file_new_dialog.c + * app/gimage_cmds.[ch] + * app/gimpimage.[ch] + * app/info_window.c + * app/internal_procs.c + * libgimp/gimp.h + * libgimp/gimpimage.c + * plug-ins/tiff/tiff.c: applied gimp-austin-980916-0, adds resolution + info to GimpImage, with accessors, and support in the tiff plug-in + Mon Oct 5 00:28:58 PDT 1998 Manish Singh * po/de.po diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpimage-guides.h b/app/core/gimpimage-guides.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpimage-guides.h +++ b/app/core/gimpimage-guides.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpimage-merge.h b/app/core/gimpimage-merge.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpimage-merge.h +++ b/app/core/gimpimage-merge.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/core/gimpimage-projection.c b/app/core/gimpimage-projection.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpimage-projection.c +++ b/app/core/gimpimage-projection.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpimage-projection.h b/app/core/gimpimage-projection.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpimage-projection.h +++ b/app/core/gimpimage-projection.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpimage-resize.h b/app/core/gimpimage-resize.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpimage-resize.h +++ b/app/core/gimpimage-resize.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpimage-scale.h b/app/core/gimpimage-scale.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpimage-scale.h +++ b/app/core/gimpimage-scale.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 6d0d426eb9..203335c4de 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/core/gimpprojection-construct.h b/app/core/gimpprojection-construct.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/core/gimpprojection-construct.h +++ b/app/core/gimpprojection-construct.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/devices.c b/app/devices.c index 3b18afbb54..bf2daef09c 100644 --- a/app/devices.c +++ b/app/devices.c @@ -597,9 +597,12 @@ devices_write_rc_device (DeviceInfo *device_info, FILE *fp) if (device_info->is_init) { - fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); - fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); - fprintf(fp, "\n (tool \"%s\")", + if (device_info->brush) + fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); + if (device_info->pattern) + fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); + if (device_info->tool) + fprintf(fp, "\n (tool \"%s\")", tool_info[device_info->tool].tool_name); fprintf(fp, "\n (foreground %d %d %d)", device_info->foreground[0], diff --git a/app/dialogs/image-new-dialog.c b/app/dialogs/image-new-dialog.c index ee217206d0..b964439ed3 100644 --- a/app/dialogs/image-new-dialog.c +++ b/app/dialogs/image-new-dialog.c @@ -113,6 +113,8 @@ file_new_ok_callback (GtkWidget *widget, gimage = gimage_new (vals->width, vals->height, vals->type); + gimp_image_set_resolution(gimage, vals->resolution); + /* Make the background (or first) layer */ layer = layer_new (gimage, gimage->width, gimage->height, type, "Background", OPAQUE_OPACITY, NORMAL); diff --git a/app/dialogs/info-window.c b/app/dialogs/info-window.c index 26bfb01f73..dba2f4aeb9 100644 --- a/app/dialogs/info-window.c +++ b/app/dialogs/info-window.c @@ -39,6 +39,7 @@ struct _InfoWinData char visual_class_str[MAX_BUF]; char visual_depth_str[MAX_BUF]; char shades_str[MAX_BUF]; + char resolution_str[MAX_BUF]; }; /* The different classes of visuals */ @@ -144,6 +145,7 @@ info_window_create (void *gdisp_ptr) iwd = (InfoWinData *) g_malloc (sizeof (InfoWinData)); info_win->user_data = iwd; iwd->dimensions_str[0] = '\0'; + iwd->resolution_str[0] = '\0'; iwd->scale_str[0] = '\0'; iwd->color_type_str[0] = '\0'; iwd->visual_class_str[0] = '\0'; @@ -152,6 +154,7 @@ info_window_create (void *gdisp_ptr) /* add the information fields */ info_dialog_add_field (info_win, "Dimensions (w x h): ", iwd->dimensions_str, NULL, NULL); + info_dialog_add_field (info_win, "Resolution: ", iwd->resolution_str, NULL, NULL); info_dialog_add_field (info_win, "Scale Ratio: ", iwd->scale_str, NULL, NULL); info_dialog_add_field (info_win, "Display Type: ", iwd->color_type_str, NULL, NULL); info_dialog_add_field (info_win, "Visual Class: ", iwd->visual_class_str, NULL, NULL); @@ -195,6 +198,9 @@ info_window_update (InfoDialog *info_win, sprintf (iwd->dimensions_str, "%d x %d", (int) gdisp->gimage->width, (int) gdisp->gimage->height); + /* image resolution */ + sprintf (iwd->resolution_str, "%g dpi", gdisp->gimage->resolution); + /* zoom ratio */ sprintf (iwd->scale_str, "%d:%d", SCALEDEST (gdisp), SCALESRC (gdisp)); diff --git a/app/file_new_dialog.c b/app/file_new_dialog.c index ee217206d0..b964439ed3 100644 --- a/app/file_new_dialog.c +++ b/app/file_new_dialog.c @@ -113,6 +113,8 @@ file_new_ok_callback (GtkWidget *widget, gimage = gimage_new (vals->width, vals->height, vals->type); + gimp_image_set_resolution(gimage, vals->resolution); + /* Make the background (or first) layer */ layer = layer_new (gimage, gimage->width, gimage->height, type, "Background", OPAQUE_OPACITY, NORMAL); diff --git a/app/general.c b/app/general.c index 10a7df320b..8986c77492 100644 --- a/app/general.c +++ b/app/general.c @@ -137,11 +137,11 @@ get_token (ParseInfo *info) info->position = -1; if ((info->position == -1) || (buffer[info->position] == '\0')) { - info->position = 0; count = fread (buffer, sizeof (char), info->buffer_size - 1, info->fp); if ((count == 0) && feof (info->fp)) return TOKEN_EOF; buffer[count] = '\0'; + info->position = 0; } info->inc_charnum = TRUE; diff --git a/app/gimage_cmds.c b/app/gimage_cmds.c index c9d8771d51..9e957eff44 100644 --- a/app/gimage_cmds.c +++ b/app/gimage_cmds.c @@ -31,6 +31,7 @@ #include "drawable_pvt.h" /* ick ick. */ static int int_value; +static float float_value; static int success; static Argument *return_args; @@ -2766,6 +2767,142 @@ ProcRecord gimage_set_filename_proc = }; + +/***************************/ +/* GIMAGE_GET_RESOLUTION */ + +static Argument * +gimage_get_resolution_invoker (Argument *args) +{ + GImage *gimage; + float resolution; + Argument *return_args; + + resolution = 0; + + success = TRUE; + if (success) + { + int_value = args[0].value.pdb_int; + if ((gimage = gimage_get_ID (int_value))) + resolution = gimage->resolution; + else + success = FALSE; + } + + return_args= procedural_db_return_args(&gimage_get_resolution_proc, success); + + if (success) + return_args[1].value.pdb_float = resolution; + + return return_args; +} + +/* The procedure definition */ +ProcArg gimage_get_resolution_args[] = +{ + { PDB_IMAGE, + "image", + "the image" + } +}; + +ProcArg gimage_get_resolution_out_args[] = +{ + { PDB_FLOAT, + "resolution", + "the image's resolution, in dots per inch" + } +}; + +ProcRecord gimage_get_resolution_proc = +{ + "gimp_image_get_resolution", + "Return the resolution of the image", + "This procedure returns the image's resolution, in dots per inch. This value is independent of any of the layers in this image. A return value of 0.0 means the image was invalid.", + "Austin Donnelly", + "Austin Donnelly", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 1, + gimage_get_resolution_args, + + /* Output arguments */ + 1, + gimage_get_resolution_out_args, + + /* Exec method */ + { { gimage_get_resolution_invoker } }, +}; + + +/***************************/ +/* GIMAGE_SET_RESOLUTION */ + +static Argument * +gimage_set_resolution_invoker (Argument *args) +{ + GImage *gimage; + Argument *return_args; + + success = TRUE; + if (success) + { + int_value = args[0].value.pdb_int; + if (!(gimage = gimage_get_ID (int_value))) + success = FALSE; + } + + if (success) + { + float_value = args[1].value.pdb_float; + gimage->resolution = float_value; + } + + return_args= procedural_db_return_args(&gimage_set_resolution_proc, success); + + return return_args; +} + +/* The procedure definition */ +ProcArg gimage_set_resolution_args[] = +{ + { PDB_IMAGE, + "image", + "the image" + }, + { PDB_FLOAT, + "resolution", + "resolution in dots per inch" + } +}; + +ProcRecord gimage_set_resolution_proc = +{ + "gimp_image_set_resolution", + "Sets the resolution of the image", + "This procedure sets the image's resolution, in dots per inch. This value is independent of any of the layers in this image. No scaling or resizing is performed.", + "Austin Donnelly", + "Austin Donnelly", + "1998", + PDB_INTERNAL, + + /* Input arguments */ + 2, + gimage_set_resolution_args, + + /* Output arguments */ + 0, + NULL, + + /* Exec method */ + { { gimage_set_resolution_invoker } }, +}; + + + /******************/ /* GIMAGE_WIDTH */ diff --git a/app/gimage_cmds.h b/app/gimage_cmds.h index 269b91e862..b478cdac0b 100644 --- a/app/gimage_cmds.h +++ b/app/gimage_cmds.h @@ -58,6 +58,8 @@ extern ProcRecord gimage_active_drawable_proc; extern ProcRecord gimage_base_type_proc; extern ProcRecord gimage_get_filename_proc; extern ProcRecord gimage_set_filename_proc; +extern ProcRecord gimage_get_resolution_proc; +extern ProcRecord gimage_set_resolution_proc; extern ProcRecord gimage_width_proc; extern ProcRecord gimage_height_proc; extern ProcRecord gimage_get_cmap_proc; diff --git a/app/gimpimage.c b/app/gimpimage.c index 6d0d426eb9..203335c4de 100644 --- a/app/gimpimage.c +++ b/app/gimpimage.c @@ -150,6 +150,7 @@ static void gimp_image_init (GimpImage *gimage) gimage->comp_preview_valid[1] = FALSE; gimage->comp_preview_valid[2] = FALSE; gimage->comp_preview = NULL; + gimage->resolution = 72.0; /* maybe should be rc-supplied default? */ } GtkType gimp_image_get_type(void){ @@ -293,6 +294,20 @@ gimp_image_set_filename (GimpImage *gimage, char *filename) } +void +gimp_image_set_resolution (GimpImage *gimage, float resolution) +{ + gimage->resolution = resolution; +} + + +float +gimp_image_get_resolution (GimpImage *gimage) +{ + return gimage->resolution; +} + + void gimp_image_resize (GimpImage *gimage, int new_width, int new_height, int offset_x, int offset_y) diff --git a/app/gimpimage.h b/app/gimpimage.h index 63ffb0fe95..c2e1f5daca 100644 --- a/app/gimpimage.h +++ b/app/gimpimage.h @@ -102,6 +102,8 @@ 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_resize (GimpImage *, int, int, int, int); void gimp_image_scale (GimpImage *, int, int); GimpImage * gimp_image_get_named (char *); diff --git a/app/gimpimageP.h b/app/gimpimageP.h index 31b4d155df..77ddeed85b 100644 --- a/app/gimpimageP.h +++ b/app/gimpimageP.h @@ -19,7 +19,8 @@ struct _GimpImage int has_filename; /* has a valid filename */ int width, height; /* width and height attributes */ - int base_type; /* base gimp_image type */ + float resolution; /* image res, in dpi */ + int base_type; /* base gimp_image type */ unsigned char * cmap; /* colormap--for indexed */ int num_cols; /* number of cols--for indexed */ diff --git a/app/gui/device-status-dialog.c b/app/gui/device-status-dialog.c index 3b18afbb54..bf2daef09c 100644 --- a/app/gui/device-status-dialog.c +++ b/app/gui/device-status-dialog.c @@ -597,9 +597,12 @@ devices_write_rc_device (DeviceInfo *device_info, FILE *fp) if (device_info->is_init) { - fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); - fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); - fprintf(fp, "\n (tool \"%s\")", + if (device_info->brush) + fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); + if (device_info->pattern) + fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); + if (device_info->tool) + fprintf(fp, "\n (tool \"%s\")", tool_info[device_info->tool].tool_name); fprintf(fp, "\n (foreground %d %d %d)", device_info->foreground[0], diff --git a/app/gui/file-new-dialog.c b/app/gui/file-new-dialog.c index ee217206d0..b964439ed3 100644 --- a/app/gui/file-new-dialog.c +++ b/app/gui/file-new-dialog.c @@ -113,6 +113,8 @@ file_new_ok_callback (GtkWidget *widget, gimage = gimage_new (vals->width, vals->height, vals->type); + gimp_image_set_resolution(gimage, vals->resolution); + /* Make the background (or first) layer */ layer = layer_new (gimage, gimage->width, gimage->height, type, "Background", OPAQUE_OPACITY, NORMAL); diff --git a/app/gui/info-window.c b/app/gui/info-window.c index 26bfb01f73..dba2f4aeb9 100644 --- a/app/gui/info-window.c +++ b/app/gui/info-window.c @@ -39,6 +39,7 @@ struct _InfoWinData char visual_class_str[MAX_BUF]; char visual_depth_str[MAX_BUF]; char shades_str[MAX_BUF]; + char resolution_str[MAX_BUF]; }; /* The different classes of visuals */ @@ -144,6 +145,7 @@ info_window_create (void *gdisp_ptr) iwd = (InfoWinData *) g_malloc (sizeof (InfoWinData)); info_win->user_data = iwd; iwd->dimensions_str[0] = '\0'; + iwd->resolution_str[0] = '\0'; iwd->scale_str[0] = '\0'; iwd->color_type_str[0] = '\0'; iwd->visual_class_str[0] = '\0'; @@ -152,6 +154,7 @@ info_window_create (void *gdisp_ptr) /* add the information fields */ info_dialog_add_field (info_win, "Dimensions (w x h): ", iwd->dimensions_str, NULL, NULL); + info_dialog_add_field (info_win, "Resolution: ", iwd->resolution_str, NULL, NULL); info_dialog_add_field (info_win, "Scale Ratio: ", iwd->scale_str, NULL, NULL); info_dialog_add_field (info_win, "Display Type: ", iwd->color_type_str, NULL, NULL); info_dialog_add_field (info_win, "Visual Class: ", iwd->visual_class_str, NULL, NULL); @@ -195,6 +198,9 @@ info_window_update (InfoDialog *info_win, sprintf (iwd->dimensions_str, "%d x %d", (int) gdisp->gimage->width, (int) gdisp->gimage->height); + /* image resolution */ + sprintf (iwd->resolution_str, "%g dpi", gdisp->gimage->resolution); + /* zoom ratio */ sprintf (iwd->scale_str, "%d:%d", SCALEDEST (gdisp), SCALESRC (gdisp)); diff --git a/app/gui/input-dialog.c b/app/gui/input-dialog.c index 3b18afbb54..bf2daef09c 100644 --- a/app/gui/input-dialog.c +++ b/app/gui/input-dialog.c @@ -597,9 +597,12 @@ devices_write_rc_device (DeviceInfo *device_info, FILE *fp) if (device_info->is_init) { - fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); - fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); - fprintf(fp, "\n (tool \"%s\")", + if (device_info->brush) + fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); + if (device_info->pattern) + fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); + if (device_info->tool) + fprintf(fp, "\n (tool \"%s\")", tool_info[device_info->tool].tool_name); fprintf(fp, "\n (foreground %d %d %d)", device_info->foreground[0], diff --git a/app/info_window.c b/app/info_window.c index 26bfb01f73..dba2f4aeb9 100644 --- a/app/info_window.c +++ b/app/info_window.c @@ -39,6 +39,7 @@ struct _InfoWinData char visual_class_str[MAX_BUF]; char visual_depth_str[MAX_BUF]; char shades_str[MAX_BUF]; + char resolution_str[MAX_BUF]; }; /* The different classes of visuals */ @@ -144,6 +145,7 @@ info_window_create (void *gdisp_ptr) iwd = (InfoWinData *) g_malloc (sizeof (InfoWinData)); info_win->user_data = iwd; iwd->dimensions_str[0] = '\0'; + iwd->resolution_str[0] = '\0'; iwd->scale_str[0] = '\0'; iwd->color_type_str[0] = '\0'; iwd->visual_class_str[0] = '\0'; @@ -152,6 +154,7 @@ info_window_create (void *gdisp_ptr) /* add the information fields */ info_dialog_add_field (info_win, "Dimensions (w x h): ", iwd->dimensions_str, NULL, NULL); + info_dialog_add_field (info_win, "Resolution: ", iwd->resolution_str, NULL, NULL); info_dialog_add_field (info_win, "Scale Ratio: ", iwd->scale_str, NULL, NULL); info_dialog_add_field (info_win, "Display Type: ", iwd->color_type_str, NULL, NULL); info_dialog_add_field (info_win, "Visual Class: ", iwd->visual_class_str, NULL, NULL); @@ -195,6 +198,9 @@ info_window_update (InfoDialog *info_win, sprintf (iwd->dimensions_str, "%d x %d", (int) gdisp->gimage->width, (int) gdisp->gimage->height); + /* image resolution */ + sprintf (iwd->resolution_str, "%g dpi", gdisp->gimage->resolution); + /* zoom ratio */ sprintf (iwd->scale_str, "%d:%d", SCALEDEST (gdisp), SCALESRC (gdisp)); diff --git a/app/internal_procs.c b/app/internal_procs.c index 6119037768..f71ee3ce5a 100644 --- a/app/internal_procs.c +++ b/app/internal_procs.c @@ -79,7 +79,7 @@ internal_procs_init () { gfloat pcount = 0; /* grep -c procedural_db_register internal_procs.c */ - gfloat total_pcount = 217; + gfloat total_pcount = 219; app_init_update_status("Internal Procedures", "Tool procedures", pcount/total_pcount); @@ -172,6 +172,8 @@ internal_procs_init () procedural_db_register (&gimage_base_type_proc); pcount++; procedural_db_register (&gimage_get_filename_proc); pcount++; procedural_db_register (&gimage_set_filename_proc); pcount++; + procedural_db_register (&gimage_get_resolution_proc); pcount++; + procedural_db_register (&gimage_set_resolution_proc); pcount++; procedural_db_register (&gimage_width_proc); pcount++; procedural_db_register (&gimage_height_proc); pcount++; procedural_db_register (&gimage_get_cmap_proc); pcount++; diff --git a/app/widgets/gimpdeviceinfo.c b/app/widgets/gimpdeviceinfo.c index 3b18afbb54..bf2daef09c 100644 --- a/app/widgets/gimpdeviceinfo.c +++ b/app/widgets/gimpdeviceinfo.c @@ -597,9 +597,12 @@ devices_write_rc_device (DeviceInfo *device_info, FILE *fp) if (device_info->is_init) { - fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); - fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); - fprintf(fp, "\n (tool \"%s\")", + if (device_info->brush) + fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); + if (device_info->pattern) + fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); + if (device_info->tool) + fprintf(fp, "\n (tool \"%s\")", tool_info[device_info->tool].tool_name); fprintf(fp, "\n (foreground %d %d %d)", device_info->foreground[0], diff --git a/app/widgets/gimpdevices.c b/app/widgets/gimpdevices.c index 3b18afbb54..bf2daef09c 100644 --- a/app/widgets/gimpdevices.c +++ b/app/widgets/gimpdevices.c @@ -597,9 +597,12 @@ devices_write_rc_device (DeviceInfo *device_info, FILE *fp) if (device_info->is_init) { - fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); - fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); - fprintf(fp, "\n (tool \"%s\")", + if (device_info->brush) + fprintf(fp, "\n (brush \"%s\")",device_info->brush->name); + if (device_info->pattern) + fprintf(fp, "\n (pattern \"%s\")",device_info->pattern->name); + if (device_info->tool) + fprintf(fp, "\n (tool \"%s\")", tool_info[device_info->tool].tool_name); fprintf(fp, "\n (foreground %d %d %d)", device_info->foreground[0], diff --git a/libgimp/gimp.h b/libgimp/gimp.h index 8143df3774..10c8d3ec51 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -425,6 +425,10 @@ void gimp_image_set_component_visible (gint32 image_ID, gint visible); void gimp_image_set_filename (gint32 image_ID, char *name); +void gimp_image_set_resolution (gint32 image_ID, + float resolution); +float gimp_image_get_resolution (gint32 image_ID); + /**************************************** diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c index 05469fa315..2253376184 100644 --- a/libgimp/gimpimage.c +++ b/libgimp/gimpimage.c @@ -909,3 +909,40 @@ gimp_image_set_filename (gint32 image_ID, gimp_destroy_params (return_vals, nreturn_vals); } + +float +gimp_image_get_resolution (gint32 image_ID) +{ + GParam *return_vals; + int nreturn_vals; + float result; + + return_vals = gimp_run_procedure ("gimp_image_get_resolution", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_END); + + result = 0.0; /* error return value */ + if (return_vals[0].data.d_status == STATUS_SUCCESS) + result = return_vals[1].data.d_float; + + gimp_destroy_params (return_vals, nreturn_vals); + + return result; +} + +void +gimp_image_set_resolution (gint32 image_ID, + float resolution) +{ + GParam *return_vals; + int nreturn_vals; + + return_vals = gimp_run_procedure ("gimp_image_set_resolution", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_FLOAT, resolution, + PARAM_END); + + gimp_destroy_params (return_vals, nreturn_vals); +} diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 05469fa315..2253376184 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -909,3 +909,40 @@ gimp_image_set_filename (gint32 image_ID, gimp_destroy_params (return_vals, nreturn_vals); } + +float +gimp_image_get_resolution (gint32 image_ID) +{ + GParam *return_vals; + int nreturn_vals; + float result; + + return_vals = gimp_run_procedure ("gimp_image_get_resolution", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_END); + + result = 0.0; /* error return value */ + if (return_vals[0].data.d_status == STATUS_SUCCESS) + result = return_vals[1].data.d_float; + + gimp_destroy_params (return_vals, nreturn_vals); + + return result; +} + +void +gimp_image_set_resolution (gint32 image_ID, + float resolution) +{ + GParam *return_vals; + int nreturn_vals; + + return_vals = gimp_run_procedure ("gimp_image_set_resolution", + &nreturn_vals, + PARAM_IMAGE, image_ID, + PARAM_FLOAT, resolution, + PARAM_END); + + gimp_destroy_params (return_vals, nreturn_vals); +} diff --git a/plug-ins/common/tiff.c b/plug-ins/common/tiff.c index e9953818ae..e55b0ba018 100644 --- a/plug-ins/common/tiff.c +++ b/plug-ins/common/tiff.c @@ -307,8 +307,12 @@ static gint32 load_image (char *filename) { } if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photomet)) { - g_message("TIFF Can't get photometric"); - gimp_quit (); + g_message("TIFF Can't get photometric\nassuming min-is-black"); + /* old AppleScan software misses out the photometric tag (and + * incidentally assumes min-is-white, but xv assumes min-is-black, + * so we follow xv's lead. It's not much hardship to invert the + * image later). */ + photomet = PHOTOMETRIC_MINISBLACK; } /* test if the extrasample represents an associated alpha channel... */ @@ -360,6 +364,73 @@ static gint32 load_image (char *filename) { } gimp_image_set_filename (image, filename); + + /* any resolution info in the file? */ + { + float xres=0, yres=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) { + case RESUNIT_NONE: + /* ImageMagick writes files with this silly resunit */ + g_message("TIFF warning: resolution units meaningless, " + "forcing 72 dpi\n"); + res = 72.0; + break; + + case RESUNIT_INCH: + break; + + case RESUNIT_CENTIMETER: + res = ((float)xres) * 2.54; + break; + + default: + g_message("TIFF file error: unknown resolution unit type %d, " + "assuming dpi\n", units); + } + } else { /* no res unit tag */ + /* old AppleScan software produces these */ + g_message("TIFF warning: resolution specified without\n" + "any units tag, assuming dpi\n"); + } + } else { /* xres but no yres */ + g_message("TIFF warning: no y resolution info, assuming same as x\n"); + } + + /* sanity check, since division by zero later could be embarrassing */ + if (res < 1e-5) { + g_message("TIFF: image resolution is zero: forcing 72 dpi\n"); + res = 72.0; + } + + /* now set the new image's resolution info */ + gimp_image_set_resolution (image, res); + } + + /* no x res tag => we assume we have no resolution info, so we + * don't care. Older versions of this plugin used to write files + * with no resolution tags at all. */ + + /* TODO: haven't caught the case where yres tag is present, but + not xres. This is left as an exercise for the reader - they + should feel free to shoot the author of the broken program + that produced the damaged TIFF file in the first place. */ + } + + + /* Install colormap for INDEXED images only */ if (image_type == INDEXED) { if (!TIFFGetField (tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) { @@ -699,6 +770,17 @@ static gint save_image (char *filename, gint32 image, gint32 layer) { /* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */ TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + /* resolution fields */ + { + float resolution = gimp_image_get_resolution(image); + if (resolution) + { + TIFFSetField (tif, TIFFTAG_XRESOLUTION, resolution); + TIFFSetField (tif, TIFFTAG_YRESOLUTION, resolution); + TIFFSetField (tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); + } + } + if (drawable_type == INDEXED_IMAGE) TIFFSetField (tif, TIFFTAG_COLORMAP, red, grn, blu); diff --git a/plug-ins/tiff/tiff.c b/plug-ins/tiff/tiff.c index e9953818ae..e55b0ba018 100644 --- a/plug-ins/tiff/tiff.c +++ b/plug-ins/tiff/tiff.c @@ -307,8 +307,12 @@ static gint32 load_image (char *filename) { } if (!TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photomet)) { - g_message("TIFF Can't get photometric"); - gimp_quit (); + g_message("TIFF Can't get photometric\nassuming min-is-black"); + /* old AppleScan software misses out the photometric tag (and + * incidentally assumes min-is-white, but xv assumes min-is-black, + * so we follow xv's lead. It's not much hardship to invert the + * image later). */ + photomet = PHOTOMETRIC_MINISBLACK; } /* test if the extrasample represents an associated alpha channel... */ @@ -360,6 +364,73 @@ static gint32 load_image (char *filename) { } gimp_image_set_filename (image, filename); + + /* any resolution info in the file? */ + { + float xres=0, yres=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) { + case RESUNIT_NONE: + /* ImageMagick writes files with this silly resunit */ + g_message("TIFF warning: resolution units meaningless, " + "forcing 72 dpi\n"); + res = 72.0; + break; + + case RESUNIT_INCH: + break; + + case RESUNIT_CENTIMETER: + res = ((float)xres) * 2.54; + break; + + default: + g_message("TIFF file error: unknown resolution unit type %d, " + "assuming dpi\n", units); + } + } else { /* no res unit tag */ + /* old AppleScan software produces these */ + g_message("TIFF warning: resolution specified without\n" + "any units tag, assuming dpi\n"); + } + } else { /* xres but no yres */ + g_message("TIFF warning: no y resolution info, assuming same as x\n"); + } + + /* sanity check, since division by zero later could be embarrassing */ + if (res < 1e-5) { + g_message("TIFF: image resolution is zero: forcing 72 dpi\n"); + res = 72.0; + } + + /* now set the new image's resolution info */ + gimp_image_set_resolution (image, res); + } + + /* no x res tag => we assume we have no resolution info, so we + * don't care. Older versions of this plugin used to write files + * with no resolution tags at all. */ + + /* TODO: haven't caught the case where yres tag is present, but + not xres. This is left as an exercise for the reader - they + should feel free to shoot the author of the broken program + that produced the damaged TIFF file in the first place. */ + } + + + /* Install colormap for INDEXED images only */ if (image_type == INDEXED) { if (!TIFFGetField (tif, TIFFTAG_COLORMAP, &redmap, &greenmap, &bluemap)) { @@ -699,6 +770,17 @@ static gint save_image (char *filename, gint32 image, gint32 layer) { /* TIFFSetField( tif, TIFFTAG_STRIPBYTECOUNTS, rows / rowsperstrip ); */ TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + /* resolution fields */ + { + float resolution = gimp_image_get_resolution(image); + if (resolution) + { + TIFFSetField (tif, TIFFTAG_XRESOLUTION, resolution); + TIFFSetField (tif, TIFFTAG_YRESOLUTION, resolution); + TIFFSetField (tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); + } + } + if (drawable_type == INDEXED_IMAGE) TIFFSetField (tif, TIFFTAG_COLORMAP, red, grn, blu);