Can't find GDK::InterpType members in gtkmm

268 views Asked by At

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’
1

There are 1 answers

2
José Fonte On BEST ANSWER

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.