close

Вход

Забыли?

вход по аккаунту

?

HACK THE GIMP How to help Your mission

код для вставки
HACK THE GIMP
Hackthe Gimp
From documentation to coding, there are plenty of ways to get involved with any free software project.
Why not start with Gimp? Michael J Hammel steps you through a bugfix that he prepared earlier…
в– Gimp 2.2.11
and 2.3.8
в– GEGL CVS
snapshot
T
he GNU Image
Manipulation Program –
better known as Gimp –
is the grandfather
desktop application of
the open source world.
It began life as a Motif-based
application in 1995, and has led to the
creation of the Gimp Toolkit (aka GTK)
and the Gnome desktop.
While other desktop applications
have been around for longer than
Gimp, none has brought so many new
users to the open source world or had
the impact on the evolution of the
Current stable (left) and developer versions (right)
of Gimp. Both are on your coverdisc to delve into.
56
LXF82.gimp 56
LXF82 AUGUST 2006
desktop that Gimp has. But even this
grandaddy of projects needs continual
support from the open source
community: from developers, writers,
artists, publicists and users.
How to help
Gimp’s development – like that of
many other open source projects – is
driven directly by input from users.
Wish lists and feature requests are
submitted via Bugzilla – a web-based
system used to track the status of
bugs – and reviewed by the Gimp
development team. If accepted, those
requests, along with sets of required
bugfixes, are loosely scheduled for an
upcoming release. Developers then
attack the new features, bugs and
documentation changes while users
test the development releases.
Eventually a new stable release is
made publicly available in source form.
Linux distributors such as Red Hat,
Mandriva and Ubuntu then package
the new release for inclusion in their
respective distributions.
Development is handled by two
very small teams: the core team and a
set of frequent contributors. In fact,
the core team are just two people:
Sven Neumann and Mitch Natterer.
Neumann is the de facto project leader,
though the project is loosely
structured so that important decisions
are often made only with serious input
from the rest of the team.
The frequent contributors are a
group of around 30 people who work
on various other parts of the project,
including source code, documentation
and management of resources such as
the CVS repository. Other contributors
from the past (including this writer!)
are listed in the About dialog.
You don’t have to know how to
code in order to get involved, but you
will need to be very familiar with the
Gimp application from the point of
view of an end user.
Your mission
In this article, we’ll be demonstrating
two of the best ways to contribute:
bug hunting and bugfixing.
Working as a bug hunter can be
casual or focused. Focused testing is
done to isolate problems in greater
detail than casual reporting, especially
with respect to hard-to-reproduce
www.linuxformat.co.uk
7/6/06 11:54:55
HACK THE GIMP
CONTRIBUTOR RESOURCES
в– http://developer.gimp.org
Gimp developer information
в– www.gimp.org/bugs/howtos/
bugzilla.html Reporting bugs
в– www.gimp.org/bugs/howtos/
submit-patch.html About patches
в– www.le-hacker.org/papers/gobject
The GLib object system
в– http://developer.gimp.org/api/2.0/
index.html Gimp API docs
в– For coding styles, try the HACKING
file in the source code.
These are all required reading. But if
The elite Gimp team, including lead developers Mitch Natterer (third from
left, bottom row) and Sven Neumann (fourth from left, middle row).
issues. Bug hunters should be very
familiar with the stable version of
Gimp, and focused bug hunters should
be able to compile new versions of
the software. You will also become
acquainted with Bugzilla – we’ll
introduce you on page 58.
As for bugfixing, the Gimp core is
written in C, but many of the plugins
are written in various scripting
languages: Perl, Python and Script-Fu
(a variation of Scheme) are the most
common. You’ll need to be familiar
with creating patches: instructions for
doing this are on the www.gimp.org
website, but we’ll cover the process in
more depth on page 60.
experienced Bugzilla users will find
more detailed information useful for
finding existing Bugzilla reports.
C, Autoconf and other tools
If you’re going to be digging into the
source code, there are a few tools you
should know about:
The Gimp core code uses the Autoconf
tool set (Autoconf, Automake and
Libtool) to manage the build
environment. Knowledge of Autoconf is
helpful but not required. However, it is
important that you can code in C – it’s
required to work on the Gimp core
code and many of the plugins. Perl,
Python and Script-Fu are necessary
for some plugins, but you won’t need
them for working on the core code. If
you know your way around a text
editor and tools like Cscope, Strace
and GDB it would be useful. You
should also become familiar with the
Gimp coding styles (again, see
Contributor Resources box).
CVS
Not a coder?
Every Gimp contributor will get to
know CVS, the software that manages
the Gimp source code. Users check
out source from CVS, make changes,
create a patch and submit it to the
core team or frequent contributors.
Before we start bug hunting, here’s a
brief look at the other ways you can
get involved in Gimp.
First is user support. The
development team spend much of
their free time working on code, so
they have only limited time to answer
questions from new users. Once you’re
comfortable with the program you can
provide end-user support on mailing
lists, websites and in chat rooms.
This kind of support is vital: your
support is the public face of the
project. Because of this, it’s important
that you fully understand how to use
the program and that you react
politely to even the harshest critic.
Just as valuable are translations
and docs. Translations are needed for
documentation or in the program itself.
This is a nice area to cut your teeth on:
Before we start…
Bugzilla
Bugzilla is a web-based application
used to track changes to the Gimp
project. This can include reported bugs,
new feature requests and
documentation changes. Bugzilla can
seem a bit daunting to use the first
time, but the Gimp team have worked
hard to ease your transition into their
world. On the Gimp website you’ll find
information on how to use Bugzilla to
report and search for bugs; and on the
Gimp developer website (see
Contributor Resources box, above),
most of the documentation requires
only familiarity with at least one text
editor; working on the website calls
for some knowledge of XML and
the DocBook format.
At the other end of the scale,
experienced programmers could
consider working on core feature
enhancement. The best-known
example of this is support of 16-bit
colour channels. This new feature has
been requested for many years now,
but turned out to be a much bigger
job than anyone realised. In order to
implement 16-bit colour, a major
overhaul of the Gimp core code is
planned to make use of a secondary
project called GEGL (see box below).
However you decide to take part,
the Gimp is a great project to start out
with, and we’re sure you’ll find it a
rewarding and addictive experience.
Before you dive into the source, have
a look at the Contributor Resources
box, above. If we’ve tempted you into
hunting and fixing a bug, we’re ready
to start – just turn the page!
Gimp has a number of projects
under CVS source code control.
>>
GEGL: THE FUTURE OF GIMP
GEGL is the Generic Graphical Library,
and the de facto future of the Gimp
project. It’s a work in progress without
an official release date, but when
completed it will become a back-end
processing library for Gimp. Beyond
support for 16-bit colour channels (one
of its initial goals), GEGL will provide a
wealth of image editing functionality
including colour management, CMYK
(illustrated above right) and L*a*b native
colourspace editing, flexible tile-based
systems and multi-threaded image
processing. It will also provide a
directed graph mechanism to store
processes in image manipulation.
Most of these features are of real
importance to high-end users – video
editors, for one. But the average user
will also find them useful. The directed
www.linuxformat.co.uk
LXF82.gimp 57
you want real interaction with other
contributors you’ll need to turn to the
mailing lists and IRC channels:
в– www.gimp.org/mail_lists.html
в– Channel #gimp on irc.gimp.org
There are many mailing lists for the
project. The primary lists are Gimp user
(for general use issues) and Gimp
developer (for general development
issues). The IRC channel is where live,
interactive discussions occur. For more
information, see the wiki page at
http://wiki.gimp.org/gimp/irc.
graph mechanism, for instance, will
make it possible to store a complex set
of steps, from adding text to applying
multiple filters, to produce an image,
and even edit those steps later. This
would make it possible to use Gimp to
create a logo for the web and save the
steps used to create the logo to a file.
Later, you can load the file and edit
those steps so the logo is generated for
a large printed banner by, for example,
simply specifying a higher resolution or
canvas size.
There is no timeframe for when GEGL
will be integrated into Gimp, but the
hope is for the next major version after
the upcoming Gimp 2.4 release. Until
then, the project needs developers and
testers – you know what to do!
www.gegl.org
LXF82 AUGUST 2006
57
7/6/06 11:55:02
HACK THE GIMP
>>
Part 1 Go bug hunting
Before you fix bugs, you have to find them – so get looking in Bugzilla!
The best way to find out what it’s
like to work on a project is to fix a bug.
For the purposes of contributing to
the Gimp project, a bug is anything
that already exists in the Gimp source
code and doesn’t do what it was
intended to do. This contrasts with a
feature request for which no code
exists yet or which exists and works as
designed but the design is different
from what is desired.
If a bug is found, the most
important thing you can do is
reproduce it: simply play with the
program repeatedly until you’ve
reduced the problem to its fewest
components, then document those
components, usually as a set of steps
that someone else can read in a
Bugzilla report.
The Bugzilla database
(http://bugzilla.gnome.org) is
actually a database for many projects
related to the Gnome desktop
environment. Before you can get active
in your bug search you’ll need to
register to get a login ID.
HOW TO FIND A BUG IN BUGZILLA
1
2
Log in to the Bugzilla database and click on the Search
link at the top of the page, then go to the Complicated
Bug Search Form. We’ll use the special �gnome-love’
keyword to find bugs marked by the Gimp development
team. These bugs are considered easy to fix, and are
tagged this way to make them easy to find.
There are only two places you’ll need to be concerned
with in your bug search. The first is the product list. Scroll
through this list until you find the entry �Gimp’ and click
on it. Other lists will be updated when you do this, but we
can ignore all of these for now.
4
3
Now scroll down to the area titled Advanced Searching
Using Boolean Charts. There are two drop-down lists. In
the first, select the entry for Keywords. In the next, select
the entry for Contains The String. In the field next to this,
type the phrase �gnome-love’. You’re now ready to run
your search.
Click on the Search button (right above the fields you’ve
just modified). Scan the Summary column for a title of a
bug that looks interesting, then click on the associated ID
column entry to read more about the bug (see table,
below). We’ve chosen bug #331839 to work on.
This tells us about our chosen Gimp
bug. The Severity (2nd column)
shows �enh’, which is short for
331839
enh
Nor
All
Gimp
NEW
Clear
keyboard
enhancement. Technically that
shortcuts
makes this a feature request rather
than a bug. This, and other fields, are usually agreed on by developers after a bug report is filed in Bugzilla. It turns out
that this is a request to change the Preferences dialog to include an option to clear all keyboard accelerators without
resetting them to their original state. We think we can handle this, so we’ll give it a try.
5
58
LXF82.gimp 58
LXF82 AUGUST 2006
ID
Sev
Pri
OS
Product
Status
Resolution
Summary
www.linuxformat.co.uk
7/6/06 11:55:05
HACK THE GIMP
Once you’ve chosen your bug,
you’ll need the latest copy of Gimp
from CVS. To get it working, you’ll need
these dependencies:
в– autoconf 2.54 or later.
в– automake1.7 or later.
в– libtool1.4 or later.
в– gettext 0.13 or later.
в– GTK 2.8.10 or later.
While the first four are probably on
your system already, we bet the last
isn’t. The GTK software has its own
dependencies. These are easy to build
with a little trick so they won’t break
anything already on your system.
OK. Grab and unpack the GTK
software. With any modern distro the
packages you’re most likely to need
are the latest GTK, GLib, ATK, Pango
and Cairo. The first four are available
from the GTK website (www.gtk.org/
download). The Cairo software is also
archived on the GTK website, but on a
different page (ftp://ftp.gtk.org/pub/
gtk/v2.8/dependencies). It’s
important to build the packages in this
order: Cairo, GLib, Pango, ATK, GTK.
Before building, we need to tell
each package where to look for
libraries and configuration information:
export PKG_CONFIG_PATH=/usr/
local/gtk+-2.8/lib/pkgconfig:$PKG_
CONFIG_PATH
export LD_LIBRARY_PATH=/usr/
local/gtk+-2.8/lib:$LD_LIBRARY_
PATH
Set both of these environment
variables or the build will pick up older
versions of the same software already
installed on your system. Change into
each package directory, one at a time,
and run these commands:
./configure --prefix=/usr/local/gtk+2.8
make
sudo make install
The trick is to tell all of these
packages to install themselves under
/usr/local/gtk+-2.8. This prevents
new versions of the software from
interfering with older, previously
installed versions.
Design and build
After all of the GTK dependencies are
installed, you’re ready to build the
Gimp software. We need to log in to
CVS and check out the source. Point
your machine at the Gimp CVS server:
export CVSROOT=’:pserver:
anonymous@anoncvs.gimp.org:/cvs/
gnome’
and log in with
cvs login
You’ll get back something like this:
�Logging in to :pserver:
anonymous@anoncvs.gimp.
org:2401/cvs/gnome
CVS password:’
We’re logging in as an anonymous
user, so we’ll have read-only access to
the CVS server. Just hit Enter (you
don’t need a password).
Now you can check out the Gimp
source code:
cvs -z3 checkout gimp
The -z3 uses compression for
downloading to speed the transfers.
All finished? You should have a
directory called gimp in your current
directory. To build the source, run
cd gimp
./autogen.sh --prefix=/usr/local/
gimp-2.3
make
sudo make install
Now, the autogen.sh script is like the
configure script you ran for the GTK
applications, but we pass that --prefix
option to autogen.sh instead of
configure (notice that we’re installing
Gimp into a different directory from
GTK). The PKG_CONFIG_PATH and
LD_LIBRARY_PATH variables we set
before building GTK are enough to tell
Gimp’s build system for where to find
the new GTK software. We want Gimp
in its own directory so we can remove
it later and build another version
without harming the GTK software.
Plan of attack
Now we can look at the latest
Preferences dialog to make a plan of
what needs to be done to get that
pesky bug fixed. The area of concern is
outlined and coloured blue in the
image (top right) – these are the
Keyboard Shortcuts options. The bug
report requests a new option to clear
keyboard shortcuts, and that the
existing buttons be changed to an
options menu, similar to the Navigation
Preview Size menu.
Very well… We need to find the
code that creates this part of the
Preferences dialog. Under the Gimp
source directory we find a number of
directories, including:
в– app The core Gimp code.
в– data Brushes, gradients and
other data.
в– plugins Filters and other plugin
source code.
в– po Translations for user interface
components such as menus.
Here’s what we’re going to fix:
the buttons shaded blue need to be
changed to a list of options. Think
you fix it? Of course you can!
We need to look in the app directory
for the dialogs directory, and under
here we find preferences-dialog.c.
Search the file for the string found in
the Reset button, which will take us to
where this button is created:
button2 = prefs_button_add (
GIMP_STOCK_RESET,
_(“_Reset Saved Keyboard Shortcuts
to “
“Default Values”),
GTK_BOX (vbox2));
g_signal_connect (
button2, “clicked”,
G_CALLBACK (prefs_menus_clear_
callback),
gimp);
g_object_set_data (
G_OBJECT (button),
“clear-button”, button2);
A ha! The calls to prefs_button_
add() need to be replaced with a
single call to gimp_int_combo_box_
new(), which is a Gimp-specific widget
creation function for an option menu
that can be found in the Gimp API
documentation (http://developer.
gimp.org/api/2.0/libgimpwidgets/
GimpIntComboBox.html).
Additionally, the callbacks for both
buttons need to be merged into a
single callback.
That’s our to-do list: let’s get to it!
Anyone can submit a bug report – just make it as detailed as possible.
www.linuxformat.co.uk
LXF82.gimp 59
>>
LXF82 AUGUST 2006
59
7/6/06 11:55:11
HACK THE GIMP
>>
Part 2 Bugfixing and patches
We have our task – so let’s execute it and submit it to the team for review…
After all the work of finding the
bug, the actual fix turns out to be the
easiest part. We’ll outlined it here, and
though you won’t be fixing exactly the
same code, the steps we take will be
helpful in your own coding.
It’s a fix
We’ll add the new combo box directly
below the existing buttons in app/
dialogs/preferences-dialog.c. The
combo box needs a label to its left,
which requires a GTK �hbox’ widgetx:
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX
(vbox2), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new (_(“Keyboard
Shortcut Status:”));
TAKE ON A GIMP PLUGIN…
C, Python and Script-Fu plugins:
preview windows are only
available to plugins written in C.
Plugins are small programs written in a
variety of programming languages,
which extend Gimp’s features. Plugins
are often referred to as filters, simply
because you’ll find most plugins in the
Filters menu. However, a plugin can
install itself under any menu and can do
things other than filter image data, such
as generate logos and patterns, provide
file I/O functions, and even act as
servers for external programs to run
images through Gimp.
A plugin can be written in C and
compiled against the libgimp API library,
or it can be written in one of the
supported scripting languages: Script-Fu
(a subset of the Scheme language) and
Python. Perl is also supported, but only
as an add-on package. Each of the
scripting languages is a binding for the
libgimp API library.
60
LXF82.gimp 60
LXF82 AUGUST 2006
To write a plugin you must become
familiar with the PDB, the Procedural
Database, which is the set of all the
functions callable from you plugin. You
can view the PDB by opening the
Procedure Browser (Xtns > Procedure
Browser) from the Toolbox menus. Each
function is searchable by its name, and
function parameters are provided with
short descriptions. The method of
calling these functions depends on the
language used for the plugin. In C, you
might do the following:
image_id = gimp_image_
new(width, height, type);
while in objectified Perl it might be
like this:
image_id = $image->new(width,
height, type);
and in Python like this:
image_id = gimp.image(width,
height, type)
There are a number of good
references for writing plugins. For
plugins written in C, see the three-part
series on the Gimp developer website at
http://developer.gimp.org/plug-ins.
html. A very well-written Python
tutorial is also available online at www.
gimp.org/docs/python/index.html.
Perl plugin documentation comes
with the Gimp-Perl package, which you
can read by running perldoc Gimp or
by visiting www.gimp.org/tutorials/
Basic_Perl. Good luck!
gtk_box_pack_start (GTK_BOX
(hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
Then we add the combo box with
four entries. The first entry is a dummy
entry, which allows the menu to be
reset after each action so that the user
can rerun the same action at any time.
combo = gimp_int_combo_box_new
(
_(“Choose an Action”),
KBS_IGNORE,
_(“Save Now”),
KBS_SAVE,
_(“Reset to Default Values”),
KBS_RESET,
_(“Remove All Keyboard Shortcuts”),
KBS_CLEAR,
NULL);
gimp_int_combo_box_set_active
(GIMP_INT_COMBO_BOX (combo),
KBS_SAVE);
gtk_box_pack_start (GTK_BOX
(hbox), combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
g_signal_connect (combo,
“changed”,
G_CALLBACK (prefs_menus_
keyboard_shortcuts),
gimp);
The g_signal_connect() line tells
the program that when the user makes
a change to our new combo box, the
function prefs_menus_keyboard_
shortcuts() needs to be called. That
function gets the widget ID of the
combo box (which we’ll use to find out
which menu item has just been
selected) and a structure called gimp
passed to it.
Each menu label in the call to
gimp_int_combo_box_new() is listed
next to a defined value (KBS_SAVE
and so on). Those values need an
enum added to the start of the file:
enum {
KBS_IGNORE,
KBS_SAVE,
KBS_RESET,
KBS_CLEAR
};
We should replace the callback
functions for the existing buttons with
a single callback function. Any change
to the combo box causes a call to the
callback function. Simple. The new
function will test the combo box to see
which menu item has been selected,
and use a switch statement to choose
the appropriate action. In two cases
(KBS_SAVE and KBS_CLEAR), we do
what the original buttons used to do.
The first menu option is a dummy
item, and we just ignore it when the
menu changes to that item. The last
option will remove all keyboard
accelerators by running through the list
of accelerators and resetting them.
After they’ve all been reset, the new
list is saved so it will be available the
next time the user runs the program.
static void
prefs_menus_keyboard_
shortcuts(GtkWidget *combo,
Gimp
*gimp)
{
gint value;
gint fd;
GError *error = NULL;
gchar *filename;
gimp_int_combo_box_get_active
(GIMP_INT_COMBO_BOX (combo),
www.linuxformat.co.uk
7/6/06 11:55:13
HACK THE GIMP
we can see that the shortcuts are still
not listed. If we then choose the Reset
option in the menu, quit and restart
Gimp we find that the default shortcut
settings have returned.
Creating a patch
Our updated Keyboard Shortcuts pane in the Preferences dialog, with the
new menu displayed in the lower-right portion of the dialog box.
&value);
switch(value)
{
case KBS_IGNORE:
break;
case KBS_SAVE:
menus_save (gimp, TRUE);
g_message (_(“Your keyboard
shortcuts have been saved.”));
break;
case KBS_RESET:
menus_clear (gimp, &error);
g_message (_(“Your keyboard
shortcuts will be reset to default “
“values the next time you start
GIMP.”));
break;
case KBS_CLEAR:
menus_remove (gimp);
menus_save (gimp, TRUE);
g_message (_(“Your keyboard
shortcuts will be cleared “
“the next time you start GIMP.”));
break;
}
gimp_int_combo_box_set_active
(GIMP_INT_COMBO_BOX (combo),
KBS_IGNORE);
}
We add two new entries in the
app/menus/menus.c file, and add a
function called menus_remove() that
can be called by our prefs_menus_
keyboard_shortcuts() case
statement. This will iterate over the
existing accelerators to reset them.
void
menus_remove (Gimp *gimp)
{
gtk_accel_map_foreach(0,menus_
remove_actions);
}
static void
menus_remove_actions (gpointer
data,
const gchar *accel_path,
guint
accel_key,
GdkModifierType accel_mods,
gboolean
changed)
{
gtk_accel_map_change_entry
(accel_path, 0, 0, TRUE);
}
The menus_remove() function also
needs a prototype in the app/menus/
menus.h header file so that it can be
called from preferences-dialog.c.
Put to the test
All the hard work is over. We can
recompile and reinstall, then we’re
ready to start the application again to
test the changes.
make
sudo make install
/usr/local/gimp-2.3/bin/gimp-2.3
To verify that the changes have
worked, the easiest thing to do is look
at the File menu in the Toolbox. Before
we run the new Remove All Keyboard
Shortcuts option, we open this menu
and see the keyboard shortcuts listed
next to the New and Save menu
options. When we run the new menu
option these disappear immediately.
Quitting the program and restarting it,
The changes work. Now it’s time to
create a patch and submit it for review
by the venerable Gimp developers – a
process you can follow for your own
bugfix. From the top of the Gimp
source tree, let’s run
cvs diff -up > ../patchfile.patch
This creates a patch file in the
directory directly above where you’ve
been working on the Gimp source
code. The diff can take a while to
complete. Check the file contains only
those changes you made: it’s possible
that additional changes unrelated to
yours crept in with the command.
At the bottom of the Bugzilla bug
report is a field to say what was done.
Fill in the comment section, then
attach the patch file using the link
below. Task completed: now we can sit
back and pat ourselves on the back.
One last thing: the developers
replied that our implementation would
work better with a third button instead
of a menu. So we went back and
rewrote the code to put in a third
button, aligned in a single row with the
existing buttons. After making those
changes the patch was accepted by
Mitch Natterer.
You’ve seen how straightforward
the process is – so dive in, get involved
and make a difference! LXF
This article was based on the slides
presented by Karine Delvare at the
Libre Graphics conference earlier this
year. Additional assistance was
provided by Carol Spears, Mitch
Natterer and William Skaggs. Special
thanks to Karine Delvare (and her
husband) and Carol Spears for
providing photos of the developers at
the Libre Graphics meeting.
WHAT HAPPENED TO THE LXF BUGFIX?
Our submitted fix had put the buttons
next to each other. In the end, due to
constraints on text widths, the
developers decided to add another
button directly below the original
buttons. The average user may never
use these buttons, but experienced
users who reconfigure their keyboard
shortcuts will find them useful.
In the future, additional settings for
loading keyboard shortcut presets may
also be added, so users can select
between the default configuration or a
Photoshop or Mac OS workalike.
Before (left) and after (right): the Preferences dialog gets a new
feature. Among advanced users, this fix will be much appreciated.
www.linuxformat.co.uk
LXF82.gimp 61
WITH THANKS
LXF82 AUGUST 2006
61
7/6/06 11:55:15
Документ
Категория
Без категории
Просмотров
22
Размер файла
343 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа