Friday, February 10, 2012

Post-GSoC work, End(?) of University

I have done the seamless cloning project for GIMP and finished it in August. So, you may ask, why on earth is it not integrated yet? The answer is short and simple - last university semester combined with real life. But, I'm not here to bring excuses, I'm here to bring results:
  • On Thursday I had my last university exam (Computational Complexity). Unless I fail, and I hope I don't, I finished university!
  • In the last two weeks of university, I had more and more free time so I began working again on my GSoC project. The current things that are waiting to happen are:
    • Fix the triangulation refinement implementation. For those who are not familiar with the algorithm behind the scene, the algorithm itself is based on interpolation of image differences in a triangular mesh. Therfor, it is a critical part.
      The algorithm currently would get stuck in an infinite loop of refining the triangulation, even though it was gauranteed to stop (meaning an implementation bug). I think I just fixed it now (now as in 5 minutes ago), more on this below.
    • Make the algorithm iterate over tiles inside of allocating a big chunk of memory, and thus limiting the maximal image size for the algorithm.
    • Fix memory leaks (there are several known leaks, and hopefully none unknown).
    • Improve a small glitch on the borders of the image.
    • Optimize the speed!
    • Get it reviewed, and merge back to master.
  • Being free of university, and free from other work (I have a day work on which I don't work "after-hours"), I'm now free from chores on evenings (if I get home at sane hours) and weekends. For the first time in the last 3.5 years, I really have free time with nothing on my mind. So don't worry, I'll get into GIMP :D
Now, before I get into details on my GSoC bug, a short "what's going on?".
  • Last time I left the geometry library, I was completly stuck with no idea what was the bug.
  • When I got to it again, I decided to re-write it in a language which is more type-safe (no pointer bugs), with less memory issues (garbage collection), and much easier to debug (no offense, but gdb isn't always ideal). Eventually I chose C# (and not Java, my favorite language) in order to learn a bit.
  • I have been spending my free time between the exams, in the last two weekends, to re-write the library. The re-write was something like "look at the code and write it in a different language". Almost no structural changes or anything, so that I'll keep synced with the source.
  • And then I found the bug...
Now for the bug, which made me like C much less than I did before:

// Relevant type declarations:
typedef enum
{
  INCIRCLE_ON,
  INCIRCLE_INSIDE,
  INCIRCLE_OUTSIDE
} P2tRInCircle;

// Types from GLib
typedef int  gint;
typedef gint gboolean;

// The function I called
P2tRInCircle p2tr_math_incircle (P2tRPoint* a,
                                 P2tRPoint* b,
                                 P2tRPoint* c,
                                 P2tRPoint* d);

// Somewhere in the code, in the function that I knew that
// was deeply related to the problem:
gboolean inside = p2tr_math_incircle (p, a, q, b);

if (inside)
  {
    ...
  }

I don't even feel like explaining this. It is so trivial (and if not, go learn C!) Other than feeling stupid silly for falling on such a bug for days of debugging, I don't have anything else I can say... So, with all the dislike of some people to high level languages, I like type safety. It saved my here simply since this code, when converted directly to C#, didn't compile and produce an error instead!

So, Hurray for C#, Hurray for end of University (hopefully) at least untill second degree, and just some other random hapiness. And don't worry, I'm not gone yet :)

Edit: More silly bugs found. I'm starting to like re-writing stuff - way better than debugging...
Edit 2 (February 11th, 2012): The geometry library works, at least in C#. Now it's time to re-implement in C.

7 comments:

  1. Beautiful news!
    Return soon to the Gimp!

    If possible to help in the bug list Gimp 2.8 :-)
    There is a great team effort (true warriors), but there are still 18 errors for the birth of Gimp 2.8.

    I can not wait to participate in the birth of this child named Gimp 2.8;-)

    Sorry for the mistakes in the text, I used the google translator.

    ReplyDelete
  2. Maybe you can even make use of the dubious conversion of integer to boolean and define:

    typedef enum
    {
    INCIRCLE_ON = 1,
    INCIRCLE_INSIDE = 2,
    INCIRCLE_OUTSIDE = 0
    } P2tRInCircle;

    Then it's "true" for INCIRCLE_ON and INCIRCLE_INSIDE and "false" (0) for INCIRCLE_OUTSIDE

    ReplyDelete
  3. Shouldn't compiler warnings be able to pick up these types of bugs? Turning on all of the compiler warnings always helps me out a great deal :).

    ReplyDelete
  4. Yup, obviously should have been: gboolean inside = (p2tr_math_incircle (p, a, q, b) == INCIRCLE_INSIDE);

    Instead, I'm guessing inside was only false when INCIRCLE_ON was returned -- first one defaults to 0 correct?

    ReplyDelete
  5. Nice work! Like so many others, I'm very grateful that you have devoted time to this project.

    ReplyDelete
  6. Thanks very much for the tool, you are a real asset to the libre design world.

    ReplyDelete