1

I'm trying to make a Gtk::Image widget display a picture from a file, but prevent the widget from expanding in size, so I'm loading it from a Gdk::Pixbuf and then scaling the picture. I'm using Gdk::Pixbuf instead of GdkPixBuf because the latter one works on regular pointers, but Gtk::Image requires a Glib::RefPtr<Gdk::Pixbuf>. (Just mentioning all this in case there's a better way to achieve what I'm doing that I'm unaware of.)

auto pixbuf = Gdk::Pixbuf::create_from_file("/home/raitis/Music/WRLD/Awake EP/cover.jpg");
auto scaled = pixbuf->scale_simple(48, 48, Gdk::InterpType::NEAREST);
image->set(scaled);

Anyway, problem is that although I'm following the documentation for Gdk::Pixbuf, line 2 in my code generate the error:

error: ‘NEAREST’ is not a member of ‘Gdk::InterpType’
auto scaled = pixbuf->scale_simple(48, 48, Gdk::InterpType::NEAREST);
                                                            ^~~~~~~

Trying GDK_INTERP_NEAREST instead also leads to an error. :(

no known conversion for argument 3 from ‘GdkInterpType’ to ‘Gdk::InterpType’
rusins
  • 309
  • 4
  • 8
  • If anyone knows how I could query the g++ compiler to tell me what ARE members of Gdk::InterpType, please let me know! – rusins Dec 16 '17 at 23:34
  • GDK_INTERP_TYPE is an enum, for test purposes only, try with an equivalent `int`, let's say 0. Does it compile? – José Fonte Dec 17 '17 at 16:12
  • @JoséFonte nope, still getting a type error `invalid conversion from ‘int’ to ‘Gdk::InterpType’` – rusins Dec 18 '17 at 12:36
  • 1
    Try with `Gdk::INTERP_NEAREST` – José Fonte Dec 18 '17 at 13:18
  • @JoséFonte Holy moly! I thought I had tried every possible name I could think of, but no – your suggestion worked! :D Feel free to leave it as an answer and I'll accept it! Huge thank you! :) – rusins Dec 18 '17 at 14:14

1 Answers1

1

From the stable gtkmm gdkmm documentation, Gdk::InterpType members are:

INTERP_NEAREST

Nearest neighbor sampling; this is the fastest and lowest quality mode. Quality is normally unacceptable when scaling down, but may be OK when scaling up.

INTERP_TILES

This is an accurate simulation of the PostScript image operator without any interpolation enabled.

Each pixel is rendered as a tiny parallelogram of solid color, the edges of which are implemented with antialiasing. It resembles nearest neighbor for enlargement, and bilinear for reduction.

INTERP_BILINEAR

Best quality/speed balance; use this mode by default.

Bilinear interpolation. For enlargement, it is equivalent to point-sampling the ideal bilinear-interpolated image. For reduction, it is equivalent to laying down small tiles and integrating over the coverage area.

INTERP_HYPER

This is the slowest and highest quality reconstruction function.

It is derived from the hyperbolic filters in Wolberg's "Digital Image Warping", and is formally defined as the hyperbolic-filter sampling the ideal hyperbolic-filter interpolated image (the filter is designed to be idempotent for 1:1 pixel mapping).

And from the documentation of the Gdk::Pixbuf, in the scale_simple method you'll find a reference to the interpolation type:

Leaves src unaffected. interp_type should be Gdk::INTERP_NEAREST if you want maximum speed (but when scaling down Gdk::INTERP_NEAREST is usually unusably ugly). The default interp_type should be Gdk::INTERP_BILINEAR which offers reasonable quality and speed.

José Fonte
  • 4,016
  • 2
  • 16
  • 28
  • 1
    Yeah, my problem was that I was reading the unstable documentation for gtkmm instead of the stable one (which I didn't realize, since I thought I was just using the latest version, which I wasn't). Thanks! – rusins Dec 18 '17 at 14:45
  • @rusins Glad to help :) Good luck with your project! – José Fonte Dec 18 '17 at 14:48