Index: gdk-pixbuf-io.c =================================================================== RCS file: /cvs/gnome/gtk+/gdk-pixbuf/gdk-pixbuf-io.c,v retrieving revision 1.105.2.3 diff -u -p -r1.105.2.3 gdk-pixbuf-io.c --- gdk-pixbuf-io.c 30 Mar 2005 19:42:30 -0000 1.105.2.3 +++ gdk-pixbuf-io.c 1 Jul 2005 16:57:45 -0000 @@ -939,18 +939,35 @@ size_prepared_cb (GdkPixbufLoader *loade g_return_if_fail (width > 0 && height > 0); - if(info->preserve_aspect_ratio) { - if ((double)height * (double)info->width > - (double)width * (double)info->height) { - width = 0.5 + (double)width * (double)info->height / (double)height; - height = info->height; - } else { - height = 0.5 + (double)height * (double)info->width / (double)width; - width = info->width; - } + if (info->preserve_aspect_ratio) { + if (info->width != -1 && info->height != -1) { + double width_ratio; + double height_ratio; + + width_ratio = (double)info->width / (double)width; + height_ratio = (double)info->height / (double)height; + + if (width_ratio > height_ratio) { + width = 0.5 + (double)width * height_ratio; + height = info->height; + } else { + height = 0.5 + (double)height * width_ratio; + width = info->width; + } + } else if (info->width != -1 || info->height != -1) { + double ratio; + + if (info->width == -1) + ratio = (double)info->height / (double)height; + else + ratio = (double)info->width / (double)width; + + width = 0.5 + (double)width * ratio; + height = 0.5 + (double)height * ratio; + } } else { - width = info->width; - height = info->height; + width = info->width != -1 ? info->width : width; + height = info->height != -1 ? info->height : height; } gdk_pixbuf_loader_set_size (loader, width, height); @@ -959,8 +976,8 @@ size_prepared_cb (GdkPixbufLoader *loade /** * gdk_pixbuf_new_from_file_at_size: * @filename: Name of file to load, in the GLib file name encoding - * @width: The width the image should have - * @height: The height the image should have + * @width: The width the image should have or -1 to preserve the width + * @height: The height the image should have or -1 to preserve the height * @error: Return location for an error * * Creates a new pixbuf by loading an image from a file. The file format is @@ -1018,8 +1035,8 @@ gdk_pixbuf_new_from_file_at_size (const /** * gdk_pixbuf_new_from_file_at_scale: * @filename: Name of file to load, in the GLib file name encoding - * @width: The width the image should have - * @height: The height the image should have + * @width: The width the image should have or -1 to preserve the width + * @height: The height the image should have or -1 to preserve the height * @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio * @error: Return location for an error * @@ -1057,7 +1074,8 @@ gdk_pixbuf_new_from_file_at_scale (const } info; g_return_val_if_fail (filename != NULL, NULL); - g_return_val_if_fail (width > 0 && height > 0, NULL); + g_return_val_if_fail (width > 0 || width == -1, NULL); + g_return_val_if_fail (height > 0 || height == -1, NULL); f = g_fopen (filename, "rb"); if (!f) {