garrigue / lablgtk

LablGTK 2 and 3: an interface to the GIMP Tool Kit
https://garrigue.github.io/lablgtk
Other
89 stars 40 forks source link

question on pixbufloader #150

Open dadkins789 opened 2 years ago

dadkins789 commented 2 years ago

pixbufloader only shows in stubs_GdkPixbuf.ml are there plans to fully support it?

garrigue commented 2 years ago

LablGTK is mostly in maintenance mode, so additions are only on request. If you have a use case, with the functions you would need, or even better a pull request with an actual implementation, then it could be added.

dadkins789 commented 2 years ago

I’m just learning ocaml and translating some c++ code. Here is the use case in c++.

/////////////////////////////////////////////////////////////////////////////////// Gtk::Image * createImagefromPixbufWithText(Glib::RefPtr pix, int count) { auto height = pix->get_height(); auto width = pix->get_width();

//Glib::RefPtr<Gdk::Pixbuf>
auto rotpix = pix->rotate_simple (Gdk::PIXBUF_ROTATE_UPSIDEDOWN);

auto surf = Gdk::Cairo::create_surface_from_pixbuf (rotpix, 0);
auto ctx  = Cairo::Context::create (surf)

Gdk::Cairo::set_source_pixbuf (ctx, rotpix);

ctx->paint();
ctx->move_to (40.0, height - 40.0);
ctx->set_source_rgb (1.0, 0.0, 1.0);
ctx->select_font_face ("courier", Cairo::FontSlant::FONT_SLANT_NORMAL, Cairo::FontWeight::FONT_WEIGHT_BOLD);
ctx->set_font_size (32.0);
auto s = fmt::format ("{:08d}", count);
ctx->show_text (s);

//surf->write_to_png ("foo.png");

return new Gtk::Image (surf);

}

boost::optional < Glib::RefPtr > convertPayloadToPixbuf(const unsigned char *payload, int size) { try { Glib::RefPtr pix; Glib::RefPtr loader = Gdk::PixbufLoader::create ("jpeg"); loader->write (payload, (gsize) size); loader->close(); pix = loader->get_pixbuf(); loader->close(); return pix; } catch (...) { BOOST_LOG_SEV (lg, error) << "Error converting payload to pixbuf"; return boost::none; } }

//////////////////////////////////////////////////////////////////////////////////

As I look at it there might be some Cairo functions missing too. I haven’t looked. Is there an existing module/class that I could use as an example to start writing the interface to pixbufloader? This is code is using gtkmm and caromm.

Thanks

Dave

On Feb 5, 2022, at 9:54 PM, Jacques Garrigue @.***> wrote:

LablGTK is mostly in maintenance mode, so additions are only on request. If you have a use case, with the functions you would need, or even better a pull request with an actual implementation, then it could be added.

— Reply to this email directly, view it on GitHub https://github.com/garrigue/lablgtk/issues/150#issuecomment-1030746244, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMWVQZZATELJUYU2ZB35SLUZXWGDANCNFSM5NUALDRQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.

garrigue commented 2 years ago

The code for pixbufs is in gdkPixbuf.ml and ml_gdkpixbuf.c. The macros such as ML_1 are in wrappers.h. If you can follow what it does, give it a try. Note that we only interface to vanilla C, not C++