How to get familiar with GIMP codebase?

Hi folks,

I was wondering… is there a good overview/tutorial for beginners to learn and get familiar with GIMP/GEGL codebase?

Using Elle Stone’s script, I find most source code is inside /home/pinto/code/gimpdefault/build folder. Is there any source code outside this folder?

I am especially interested in GIMP filters and corresponding performance.

I’m not sure what you mean by source code outside the folder. But when compiling GIMP from git, from source, using the folder structure suggested in my article, all the source code for babl/GEGL/GIMP is in the build folder.

In case it helps, here are some general starting points for anyone wanting to work with GIMP code:

GIMP depends heavily on babl and GEGL:

  • Babl handles (among other things) bit depth and color space transforms, including conversions between linear sRGB and regular sRGB (that is, encoded using the “almost perceptually uniform” sRGB companding curve), and conversions to and from XYZ/LAB/LCH.

  • GEGL handles image buffers and many (but not all) image-altering operations, including scaling and other transforms, and most of the filters and color operations in the GIMP menu.

  • GIMP handles layer blend and composite modes, color management, the user-interface, some filters, plug-in code, display modules, import/export, various operations available in the GIMP menu that aren’t handled by GEGL, and etc.

In a sense babl/GEGL/GIMP become one great big program via these two “include” lines, which are liberally sprinkled throughout GIMP code:

#include <babl/babl.h>
#include <gegl.h>

The relevant babl functions that GIMP and GEGL use are fairly well documented by comments in babl/babl.h, in the babl build folder.

babl/GEGL/GIMP are mostly written in c, with a little c++. Information/buffers/etc are passed back and forth between babl/GEGL/GIMP using structures. The code makes heavy use of pointers.

In GIMP:

  • “main ()” in “app/main.c” is the first code that’s run when you start GIMP.
  • main () calls on the function “app_run ()” in app.c.
  • “app_run ()” calls on “gimp_gegl_init (gimp)”, which I’m guessing is where all the communication between gimp and gegl starts.

After that, tracking what happens when and where can be done using GDB, if you have a lot of time and patiences, and by using temporary write statements if you have an idea where to start. Probably there are other ways that an actually skilled and knowledgeable programmer would use (I can program, but I’m neither skilled nor knowledgeable).

I don’t have any clue about checking performance, but the topic comes up on the GIMP dev mailing list from time to time.

Here are some useful links:

GIMP - IRC Channels Related to GIMP - the best place to interact with the babl/GEGL/GIMP devs

GIMP - Mailing Lists - also a place to interact with the devs

babl/GEGL documentation:
http://www.gegl.org/
http://gegl.org/babl/

GIMP 2.0 API:
https://developer.gimp.org/api/2.0/index.html

GIMP Developer wiki:
https://wiki.gimp.org/wiki/Main_Page

4 Likes

This is important, as the most knowledgeable folks are here and usually able to answer questions in real-time. @Elle isn’t always there, but she’s usually around (as you’ve seen), and quite dense with information to assist (so take the time to read carefully).

Thanks very much Elle for your detailed answer and info!

I will definitely have a go at it!

“Performance” is determined by a lot of factors: in the code, in the way the code is compiled, in the parameters used to start babl/GEGL/GIMP, in options set in GIMP Preferences. Plus of course the user’s operating system and hardware also makes a difference. Here’s a post I started several years ago, that specifically asks about what the user can do to make GIMP run faster (fortunately the old machine I was trying to run GIMP on finally stopped working): http://gimp.1065349.n5.nabble.com/Ways-to-improve-Gimp-2-9-performance-td37814.html

You mention filters, but different filters benefit from different types of code modifications. For example if you are interested in “Filters/Noise/CIE lch noise”, then the speed at which LCH transforms are done becomes relevant. Here’s a recent bug report about making these transforms faster: Bug 791837 – CIE: Use a faster cbrtf implementation - I don’t know how the “time” measurements were made, but if you ask on IRC, someone will surely have the answer.

I can’t find the link, but there was a discussion on the developer’s list about the slowness at which the canvas is redrawn. Some filters actually work a whole lot faster than you might think, but they seem slow because of the speed at which the image is redrawn on the screen.

The goal of course is to increase performance without reducing accuracy. I’ve been told that GIMP’s image display is superior to PhotoShop’s. But PhotoShop’s display is faster. I remember using CS2 many years ago, and the display of linear images was severely posterized until the image was zoomed in to 67%.

If you search through posts to the GIMP user and developer’s list, questions about making GIMP faster/improving performance/etc come up a lot.

3 Likes

Thanks Elle!

I was interested in finding out why when I use some of the slow filters (Artistic → Waterpixels for example) on a 16M photo, It does not show the progress circle and takes way too long to do the calculations. Again, the waterpixels output is amazing, but it is slow and the user as no clue as when it will be ready, since the progress bar does not update. in fact the whole UI freezes when you use the waterpixels filter on a large enough photo.

So… I searched for the waterpixels source code in the GEGL directory. And found a file called waterpixels.c in the /gegl/operations/common directory. I then played a bit with the code. Is it enough to compile and run the new zombie gegl library I have created to go on gimpdefault/build/gegl directory and type make (and then start ./gimp-2.9)?

Hi @SheetM - I’m not sure what a zombie GEGL libary is, but if you modify some part of the GEGL code, usually it’s enough to just do “make && make install” for GEGL, without having to also recompile GIMP, assuming of course babl/GEGL/GIMP were already compiled and installed.

Sometimes changes in GEGL do require recompiling GEGL and also GIMP, sometimes even starting over with ./autogen.sh for both GEGL and GIMP - the “symptom” being that GIMP complains about two plug-ins for the same thing, or other such complaint, in which case sometimes you might also need to delete files from the install folder, just to make sure all the old stuff is really gone.

But for smaller changes in GEGL, just “make and make install”, with no need to also reinstall GIMP, is sufficient.

If there is a GEGL filter that’s really slow and doesn’t have a progress bar that updates, and sometimes freezes GIMP, this is a good thing to ask about on IRC, and/or file a bug report.

2 Likes

Many thanks Elle!

1 Like

Thanks. I have a problem though: when I try irc://irc.gimp.org/#gimp, HexChat says:

 Python interface loaded
 Sysinfo plugin loaded
 Perl interface loaded
 FiSHLiM plugin loaded
 Lua version 1.3/5.3 loaded.
 Checksum plugin loaded
* Looking up newserver
* Unknown host. Maybe you misspelt it?
 Cycling to next server in irc://irc.gimp.org/#gimp...

I can only connect to irc://irc.freenode.net/#gimp.

Do you know what could I be doing wrong?

Try irc.gnome.org.

Edit: In Hexchat you also don’t need the irc:// part. Maybe that’s the problem?

Hmm, too many irc’s that end in “gimp”:

This is the correct one for GIMP development:

There is an irc named “gimp” at “irc.gnome.org”, but it’s the wrong chatroom (is “chatroom” the right terminology?) - edit added: This isn’t true! as @houz notes below, one is just an alias for the other.

I don’t know how to use HexChat. But an easy way to access irc.gimp.org/#gimp is to install Chatzilla in Firefox and just click on the irc link from GIMP - IRC Channels Related to GIMP

@patdavid - Maybe it would be a good idea to add a note to the gimp.org irc page, somehow letting people know that “#gimp” isn’t enough, the rest of the address also matters?

Not too long ago I was having an email exchange with a person who was a bit upset that no one on IRC was responding to the person’s questions, and it turned out that person was in the wrong “#gimp” chatroom.

Also I seem to recall one or two other people saying they were being ignored on irc, which seems completely at odds with my own observations about gimp irc, which is that questions are usually answered fairly quickly. So in retrospect it seems possible these other people also might have been in the wrong irc chatroom.

The server is irc.gimp.org and the channel is #gimp, so to connect using a proper IRC client:

/server irc.gimp.org
/join #gimp
1 Like

Again, I get

Cycling to next server in irc.gimp.org...
* Disconnected ()
* Looking up newserver
* Unknown host. Maybe you misspelt it?

When I use Hexchat. I must be doing something wrong as I can only connect to |irc://irc.freenode.net/#gimp !

I can’t speak about Gimp internals, but my own (unpublished) editor which is built using ImageMagick for the backend and Microsoft Windows for the frontend has exactly that issue. For most effects on 35M pixel images, the effect itself is fast, but the speed for transforming that result to the approx 2M pixel screen is comparatively slow. The “proper” resizing method is too slow for real-time updates when sliders are shifted, so I use the less accurate sampling method that simply samples every 4 pixels or whatever. Other more complex techniques might apply the effect initially to just the screen buffer with background updates to the rest of the image, but that would massively increase complexity.

You could try dig irc.gimp.org if that gives you something like

; <<>> DiG 9.10.3-P4-Ubuntu <<>> irc.gimp.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54144
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;irc.gimp.org.			IN	A

;; ANSWER SECTION:
irc.gimp.org.		299	IN	A	158.69.32.35
irc.gimp.org.		299	IN	A	51.15.53.172
irc.gimp.org.		299	IN	A	130.239.18.215
irc.gimp.org.		299	IN	A	83.98.201.47

;; Query time: 213 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sun Jan 14 01:48:26 CET 2018
;; MSG SIZE  rcvd: 105

If that works, DNS is likely not the problem and you can try to connect to it via the telnet client:

Trying 83.98.201.47...
Connected to irc.gimp.org.
Escape character is '^]'.
:irc.poop.nl NOTICE AUTH :*** Looking up your hostname...
:irc.poop.nl NOTICE AUTH :*** Found your hostname

To get out you can send QUIT.

If that works something is fishy with your client. If it doesn’t then the connection might be blocked by a firewall rule. IRC used to be a popular way to control botnets (might still be…) so it is often blocked for “security” purposes.

In any case the easiest solution is likely to use a web based client like mibbit.

1 Like

It’s tough to troubleshoot irc client use. :slight_smile:

@Jonas_Wagner is on the right track with a web client, here’s a link that’ll connect you directly to irc.gimp.org #gimp:

https://kiwiirc.com/nextclient/irc.gimp.org/#gimp

irc.gnome.org is an alias for irc.gimp.org, both will bring you to the same #gimp channel.

As the round robin name doesn’t work I’d like to see the output of nslookup irc.gimp.org from @SheetM

Edit: Jonas was faster.
Edit2: @SheetM: Please show a screenshot of how you configure the channel in Hexchat. Maybe you are doing something wrong there?

Hi @houz - Hmm, you are absolutely right.

I had been in a long email conversation with a person trying to get onto gimp irc, and whatever gimp channel/chatroom they found, wasn’t the right one - we confirmed this because I opened the gimp channel using chatzilla, and we weren’t seeing the same list of people on the channel, not at all.

I thought that person had typed in “irc.gnome.org”, but checking the email exchange, I’m not sure why I thought that’s what they had typed. Anyway, that person finally got on the right channel by using chatzilla.

My apologies for adding confusion to this thread!