Index: FL/Fl_Device.H
===================================================================
--- FL/Fl_Device.H	(revision 10483)
+++ FL/Fl_Device.H	(working copy)
@@ -397,6 +397,10 @@
   inline Fl_Font_Descriptor *font_descriptor() { return font_descriptor_;}
   /** Sets the current Fl_Font_Descriptor for the graphics driver */
   inline void font_descriptor(Fl_Font_Descriptor *d) { font_descriptor_ = d;}
+#if FLTK_ABI_VERSION >= 10304
+  virtual
+#endif
+  int draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H);
   /** \brief The destructor */
   virtual ~Fl_Graphics_Driver() { if (p) free(p); }
 };
@@ -423,6 +427,7 @@
   void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
   void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
   void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
+  int draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP);
   void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
   void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
   void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
@@ -483,6 +488,7 @@
   const char *class_name() {return class_id;};
   void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
   void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy);
+  int draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H);
 };
 #endif
 #if !(defined(__APPLE__) || defined(WIN32))
Index: FL/Fl_Image.H
===================================================================
--- FL/Fl_Image.H	(revision 10483)
+++ FL/Fl_Image.H	(working copy)
@@ -183,6 +183,7 @@
 class FL_EXPORT Fl_RGB_Image : public Fl_Image {
   friend class Fl_Quartz_Graphics_Driver;
   friend class Fl_GDI_Graphics_Driver;
+  friend class Fl_GDI_Printer_Graphics_Driver;
   friend class Fl_Xlib_Graphics_Driver;
   static size_t max_size_;
 public:
Index: FL/Fl_PostScript.H
===================================================================
--- FL/Fl_PostScript.H	(revision 10549)
+++ FL/Fl_PostScript.H	(working copy)
@@ -205,6 +205,7 @@
   void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
   void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
   void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
+  int draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP);
   int clocale_printf(const char *format, ...);
   ~Fl_PostScript_Graphics_Driver();
 };
Index: FL/Fl_Shared_Image.H
===================================================================
--- FL/Fl_Shared_Image.H	(revision 10483)
+++ FL/Fl_Shared_Image.H	(working copy)
@@ -3,7 +3,7 @@
 //
 // Shared image header file for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2015 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -41,7 +41,12 @@
   
   friend class Fl_JPEG_Image;
   friend class Fl_PNG_Image;
-
+  
+private:
+  static Fl_RGB_Scaling scaling_algorithm_; // method used to rescale RGB source images
+#if FLTK_ABI_VERSION >= 10304
+  Fl_Image *scaled_image_;
+#endif
 protected:
 
   static Fl_Shared_Image **images_;	// Shared images
@@ -66,7 +71,7 @@
   void add();
   void update();
 
-  public:
+public:
   /** Returns the filename of the shared image */
   const char	*name() { return name_; }
   /** Returns the number of references of this shared image. When reference is below 1, the image is deleted. */
@@ -80,14 +85,25 @@
   virtual void desaturate();
   virtual void draw(int X, int Y, int W, int H, int cx, int cy);
   void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); }
+  void scale(int width, int height, int proportional = 1, int can_expand = 0);
   virtual void uncache();
 
   static Fl_Shared_Image *find(const char *n, int W = 0, int H = 0);
   static Fl_Shared_Image *get(const char *n, int W = 0, int H = 0);
+  static Fl_Shared_Image *get(Fl_RGB_Image *rgb, int ownit);
   static Fl_Shared_Image **images();
   static int		num_images();
   static void		add_handler(Fl_Shared_Handler f);
   static void		remove_handler(Fl_Shared_Handler f);
+  /** Sets what algorithm is used when resizing a source image.
+   The default algorithm is FL_RGB_SCALING_BILINEAR.
+   Drawing an Fl_Shared_Image is sometimes performed by first resizing the source image
+   and then drawing the resized copy. This occurs, e.g., when drawing to screen under Linux or MSWindows
+   after having called Fl_Shared_Image::scale().
+   This function controls what method is used when the image to be resized is an Fl_RGB_Image.
+   \version 1.3.4 and requires compiling with FLTK_ABI_VERSION = 10304
+   */
+  static void scaling_algorithm(Fl_RGB_Scaling algorithm) {scaling_algorithm_ = algorithm; }
 };
 
 //
Index: src/Fl_Image.cxx
===================================================================
--- src/Fl_Image.cxx	(revision 10571)
+++ src/Fl_Image.cxx	(working copy)
@@ -3,7 +3,7 @@
 //
 // Image drawing code for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2014 by Bill Spitzak and others.
+// Copyright 1998-2015 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -548,6 +548,14 @@
   return 0;
 }
 
+/** Draws an Fl_RGB_Image scaled to width \p W & height \p H with top-left corner at \em X,Y
+ \return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it.
+ */
+int Fl_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H) {
+  return 0;
+}
+
+
 #ifdef __APPLE__
 static void imgProviderReleaseData (void *info, const void *data, size_t size)
 {
@@ -612,7 +620,41 @@
   }
 }
 
+int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP) {
+  int X, Y, W, H;
+  fl_clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
+  if (W == 0 || H == 0) return 1;
+  fl_push_no_clip(); // remove the FLTK clip that can't be rescaled
+  CGContextSaveGState(fl_gc);
+  CGContextClipToRect(fl_gc, CGRectMake(X, Y, W, H)); // this clip path will be rescaled & translated
+  CGContextTranslateCTM(fl_gc, XP, YP);
+  CGContextScaleCTM(fl_gc, float(WP)/img->w(), float(HP)/img->h());
+  draw(img, 0, 0, img->w(), img->h(), 0, 0);
+  CGContextRestoreGState(fl_gc);
+  fl_pop_clip(); // restore FLTK's clip
+  return 1;
+}
+
+
 #elif defined(WIN32)
+static Fl_Offscreen build_id(Fl_RGB_Image *img, void **pmask)
+{
+  Fl_Offscreen offs = fl_create_offscreen(img->w(), img->h());
+  if ((img->d() == 2 || img->d() == 4) && fl_can_do_alpha_blending()) {
+    fl_begin_offscreen(offs);
+    fl_draw_image(img->array, 0, 0, img->w(), img->h(), img->d()|FL_IMAGE_WITH_ALPHA, img->ld());
+    fl_end_offscreen();
+  } else {
+    fl_begin_offscreen(offs);
+    fl_draw_image(img->array, 0, 0, img->w(), img->h(), img->d(), img->ld());
+    fl_end_offscreen();
+    if (img->d() == 2 || img->d() == 4) {
+      *pmask = fl_create_alphamask(img->w(), img->h(), img->d(), img->ld(), img->array);
+    }
+  }
+  return offs;
+}
+
 void Fl_GDI_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy) {
   int X, Y, W, H;
   // Don't draw an empty image...
@@ -623,21 +665,7 @@
   if (start(img, XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
     return;
   }
-  if (!img->id_) {
-    img->id_ = fl_create_offscreen(img->w(), img->h());
-    if ((img->d() == 2 || img->d() == 4) && fl_can_do_alpha_blending()) {
-      fl_begin_offscreen((Fl_Offscreen)img->id_);
-      fl_draw_image(img->array, 0, 0, img->w(), img->h(), img->d()|FL_IMAGE_WITH_ALPHA, img->ld());
-      fl_end_offscreen();
-    } else {
-      fl_begin_offscreen((Fl_Offscreen)img->id_);
-      fl_draw_image(img->array, 0, 0, img->w(), img->h(), img->d(), img->ld());
-      fl_end_offscreen();
-      if (img->d() == 2 || img->d() == 4) {
-        img->mask_ = fl_create_alphamask(img->w(), img->h(), img->d(), img->ld(), img->array);
-      }
-    }
-  }
+  if (!img->id_) img->id_ = build_id(img, &(img->mask_));
   if (img->mask_) {
     HDC new_gc = CreateCompatibleDC(fl_gc);
     int save = SaveDC(new_gc);
@@ -654,6 +682,25 @@
   }
 }
 
+int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP) {
+  // Don't draw an empty image...
+  if (!img->d() || !img->array) {
+    push_clip(XP, YP, WP, HP);
+    img->draw_empty(XP, YP);
+    pop_clip();
+    return 1;
+  }
+  if (!img->id_) img->id_ = build_id(img, &(img->mask_));
+  HDC new_gc = CreateCompatibleDC(fl_gc);
+  int save = SaveDC(new_gc);
+  SelectObject(new_gc, img->id_);
+  StretchBlt(fl_gc, XP, YP, WP, HP, new_gc, 0, 0, img->w(), img->h(), SRCCOPY);
+  RestoreDC(new_gc, save);
+  DeleteDC(new_gc);
+  return 1;
+}
+
+
 #else
 void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy) {
   int X, Y, W, H;
Index: src/Fl_Shared_Image.cxx
===================================================================
--- src/Fl_Shared_Image.cxx	(revision 10483)
+++ src/Fl_Shared_Image.cxx	(working copy)
@@ -3,7 +3,7 @@
 //
 // Shared image code for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2015 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -25,8 +25,9 @@
 #include <FL/Fl_Shared_Image.H>
 #include <FL/Fl_XBM_Image.H>
 #include <FL/Fl_XPM_Image.H>
+#include <FL/Fl_Preferences.H>
+#include <FL/fl_draw.H>
 
-
 //
 // Global class vars...
 //
@@ -89,6 +90,9 @@
   original_    = 0;
   image_       = 0;
   alloc_image_ = 0;
+#if FLTK_ABI_VERSION >= 10304
+  scaled_image_= 0;
+#endif
 }
 
 
@@ -109,6 +113,9 @@
   image_       = img;
   alloc_image_ = !img;
   original_    = 1;
+#if FLTK_ABI_VERSION >= 10304
+  scaled_image_= 0;
+#endif
 
   if (!img) reload();
   else update();
@@ -170,6 +177,9 @@
 Fl_Shared_Image::~Fl_Shared_Image() {
   if (name_) delete[] (char *)name_;
   if (alloc_image_) delete image_;
+#if FLTK_ABI_VERSION >= 10304
+  delete scaled_image_;
+#endif
 }
 
 
@@ -317,14 +327,92 @@
 //
 // 'Fl_Shared_Image::draw()' - Draw a shared image...
 //
-
-void
-Fl_Shared_Image::draw(int X, int Y, int W, int H, int cx, int cy) {
+void Fl_Shared_Image::draw(int X, int Y, int W, int H, int cx, int cy) {
+#if FLTK_ABI_VERSION >= 10304
+  if (!image_) {
+    Fl_Image::draw(X, Y, W, H, cx, cy);
+    return;
+  }
+  if (w() == image_->w() && h() == image_->h()) {
+    image_->draw(X, Y, W, H, cx, cy);
+    return;
+  }
+  fl_push_clip(X, Y, W, H);
+  int use_scaled_image = 0;
+  if (image_->d() == 0 || image_->count() >= 2) { // handles Fl_Bitmap or Fl_Pixmap
+    use_scaled_image = 1;
+  }
+  else { // handles Fl_RGB_Image
+    int done = fl_graphics_driver->draw_scaled((Fl_RGB_Image*)image_, X-cx, Y-cy, w(), h());
+    if (done == 0) use_scaled_image = 1;
+  }
+  if (use_scaled_image) {
+    if (scaled_image_ && (scaled_image_->w() != w() || scaled_image_->h() != h())) {
+      delete scaled_image_;
+      scaled_image_ = NULL;
+    }
+    if (!scaled_image_) {
+      Fl_RGB_Scaling previous = RGB_scaling();
+      RGB_scaling(scaling_algorithm_); // useless but no harm if image_ is not an Fl_RGB_Image
+      scaled_image_ = image_->copy(w(), h());
+      RGB_scaling(previous);
+    }
+    scaled_image_->draw(X-cx, Y-cy, scaled_image_->w(), scaled_image_->h(), 0, 0);
+  }
+  fl_pop_clip();
+#else
   if (image_) image_->draw(X, Y, W, H, cx, cy);
   else Fl_Image::draw(X, Y, W, H, cx, cy);
+#endif // FLTK_ABI_VERSION
 }
 
+/** Sets the drawing size of the shared image.
+ This function gives the shared image its own size, independently from the size of the original image
+ that is typically larger than the shared image.
+ This can be useful to draw a shared image on a drawing surface whose resolution is higher
+ than the drawing unit for this surface. Examples of such drawing surfaces: laser printers,
+ PostScript files, PDF printers, retina displays on Apple hardware.
 
+ \param width,height   maximum width and height (in drawing units) to use when drawing the shared image
+ \param proportional   if not null, keep the width and height of the shared image proportional to those of its original image
+ \param can_expand  if null, the width and height of the shared image will not exceed those of the original image
+ 
+ \version 1.3.4 and requires compiling with FLTK_ABI_VERSION = 10304
+ 
+ Example code: scale an image to fit in a box
+ \code
+ Fl_Box *b = ...  // a box
+ Fl_Shared_Image *shared = Fl_Shared_Image::get("/path/to/picture.jpeg"); // read a picture file
+ b->image(shared); // use the shared image as the box image
+ b->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER | FL_ALIGN_CLIP); // the image is to be drawn centered in the box
+ shared->scale(b->w(), b->h(), 1); // set the drawing size of the shared image to the size of the box
+ \endcode
+ */
+void Fl_Shared_Image::scale(int width, int height, int proportional, int can_expand)
+{
+#if FLTK_ABI_VERSION >= 10304
+  w(width);
+  h(height);
+  if (!image_) return;
+  float fw = image_->w() / float(width);
+  float fh = image_->h() / float(height);
+  if (proportional) {
+    if (fh > fw) fw = fh;
+    else fh = fw;
+  }
+  if (!can_expand) {
+    if (fw < 1) fw = 1;
+    if (fh < 1) fh = 1;
+  }
+  w(image_->w() / fw);
+  h(image_->h() / fh);
+#endif
+}
+
+
+Fl_RGB_Scaling Fl_Shared_Image::scaling_algorithm_ = FL_RGB_SCALING_BILINEAR;
+
+
 //
 // 'Fl_Shared_Image::uncache()' - Uncache the shared image...
 //
@@ -408,6 +496,27 @@
   return temp;
 }
 
+/** Builds a shared image from a pre-existing Fl_RGB_Image
+ \param rgb  an Fl_RGB_Image used to build a new shared image.
+ \param ownit 1 if the shared image should delete \p rgb when it is itself deleted, 0 otherwise
+ \version 1.3.4
+ */
+Fl_Shared_Image *Fl_Shared_Image::get(Fl_RGB_Image *rgb, int ownit)
+{
+  Fl_Shared_Image *temp = new Fl_Shared_Image();
+  const char *uuid = Fl_Preferences::newUUID();
+  temp->name_ = new char[strlen(uuid) + 1];
+  strcpy((char *)temp->name_, uuid);
+  
+  temp->refcount_    = 1;
+  temp->image_       = rgb;
+  temp->alloc_image_ = ownit;
+  temp->original_    = 1;
+  
+  temp->update();
+  temp->add();
+  return temp;
+}
 
 
 /** Adds a shared image handler, which is basically a test function for adding new formats */
Index: src/ps_image.cxx
===================================================================
--- src/ps_image.cxx	(revision 10483)
+++ src/ps_image.cxx	(working copy)
@@ -456,6 +456,19 @@
   mask=0;
 }
 
+int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_RGB_Image *rgb, int XP, int YP, int WP, int HP){
+  int X, Y, W, H;
+  clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
+  if (W == 0 || H == 0) return 1;
+  push_no_clip(); // remove the FLTK clip that can't be rescaled
+  clocale_printf("%d %d %i %i CL\n", X, Y, W, H);
+  clocale_printf("GS %d %d TR  %f %f SC GS\n", XP, YP, float(WP)/rgb->w(), float(HP)/rgb->h());
+  draw(rgb, 0, 0, rgb->w(), rgb->h(), 0, 0);
+  clocale_printf("GR GR\n");
+  pop_clip(); // restore FLTK's clip
+  return 1;
+}
+
 void Fl_PostScript_Graphics_Driver::draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy){
   const uchar  * di = bitmap->array;
   int w,h;
Index: test/pixmap_browser.cxx
===================================================================
--- test/pixmap_browser.cxx	(revision 10483)
+++ test/pixmap_browser.cxx	(working copy)
@@ -3,7 +3,7 @@
 //
 // A shared image test program for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2015 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -21,6 +21,7 @@
 #include <FL/Fl_Double_Window.H>
 #include <FL/Fl_Button.H>
 #include <FL/Fl_Shared_Image.H>
+#include <FL/Fl_Printer.H>
 #include <string.h>
 #include <errno.h>
 #include <FL/Fl_File_Chooser.H>
@@ -35,7 +36,7 @@
 
 void load_file(const char *n) {
   if (img) {
-    img->release();
+    ((Fl_Shared_Image*)b->image())->release();
     img = 0L;
   }
   if (fl_filename_isdir(n)) {
@@ -46,8 +47,9 @@
     b->redraw();
     return;
   }
-  img = Fl_Shared_Image::get(n);
-  if (!img) {
+  Fl_Shared_Image *img2 = Fl_Shared_Image::get(n);
+ 
+  if (!img2) {
     b->label("@filenew"); // show an empty document
     b->labelsize(64);
     b->labelcolor(FL_LIGHT2);
@@ -55,18 +57,23 @@
     b->redraw();
     return;
   }
-  if (img->w() > b->w() || img->h() > b->h()) {
-    Fl_Image *temp;
-    if (img->w() > img->h()) temp = img->copy(b->w(), b->h() * img->h() / img->w());
-    else temp = img->copy(b->w() * img->w() / img->h(), b->h());
-
-    img->release();
-    img = (Fl_Shared_Image *)temp;
-  }
-  b->label(name);
+  img = img2;
   b->labelsize(14);
   b->labelcolor(FL_FOREGROUND_COLOR);
+#if FLTK_ABI_VERSION >= 10304
   b->image(img);
+  img->scale(b->w(), b->h());
+#else
+  if (img->w() <= b->w() && img->h() <= b->h()) b->image(img);
+  else {
+    float fw = img->w() / float(b->w());
+    float fh = img->h() / float(b->h());
+    float f = fw > fh ? fw : fh;
+    b->image(img->copy(img->w()/f, img->h()/f));
+    img->release();
+  }
+#endif
+  b->label(NULL);
   b->redraw();
 }
 
@@ -83,6 +90,20 @@
   puts(fname ? fname : "(null)"); fflush(stdout);
   fl_file_chooser_callback(0);
 }
+void print_cb(Fl_Widget *widget, void *) {
+  Fl_Printer printer;
+  int width, height;
+  printer.start_job(1);
+  printer.start_page();
+  printer.printable_rect(&width, &height);
+  float fw = widget->window()->decorated_w() / float(width);
+  float fh = widget->window()->decorated_h() / float(height);
+  if (fh > fw) fw = fh;
+  printer.scale(1/fw);
+  printer.print_window(widget->window());
+  printer.end_page();
+  printer.end_job();
+}
 
 int dvisual = 0;
 int arg(int, char **argv, int &i) {
@@ -97,15 +118,18 @@
 
   Fl::args(argc,argv,i,arg);
 
-  Fl_Double_Window window(400,435); ::w = &window;
+  Fl_Double_Window window(400,450); ::w = &window;
   Fl_Box b(10,45,380,380); ::b = &b;
   b.box(FL_THIN_DOWN_BOX);
-  b.align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
+  b.align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER|FL_ALIGN_CLIP);
   Fl_Button button(150,5,100,30,"load");
   button.callback(button_cb);
   if (!dvisual) Fl::visual(FL_RGB);
   if (argv[1]) load_file(argv[1]);
-  window.resizable(window);
+  window.resizable(b);
+  Fl_Button print(300,425,50,25,"Print");
+  print.callback(print_cb);
+
   window.show(argc,argv);
   return Fl::run();
 }
