[Gimp-developer] Porting GIMP plugins to GEGL operations - GSOC 2011

2011-04-04 Thread shivani maheshwari
Hello sir,

I am Shivani 2nd year student at IIIT-Allahabad( Indian Institute Of
Information Technology, Allahabad ). I have a programming experience with C,
C++,QT and Java. Besides this I have also worked with OpenGl(glut/glu). I
have Graphics Visualization and Computing as one of the core subject of this
semester. Studying the plugins I find it very similar to using a combination
of QT and opengl.
I am very eagerly interested in Image Manipulations and designing and I
would like to contribute to porting the plugins to GEGL operations.Currently
I am working on designing an UCI chess engine ( coding in C++ ) and making a
virtual tour of my college campus by opengl.Both of the projects will be
complete by the end of April.

Here is the code review and algorithm for the major files specified as a
test ( please correct me if I am wrong ) -

*Cubism *-

header file - libgimp/gimp.h makes all basic plugin elements available to
us.

Structures defined-
 1. Polygon - containing detail for polygon construction

 2. CubismVals - holds details for generation of tiles such as -tile
saturation , tile size, background color and bool preview.
background color - if no bg color specified then black is used while
applying the filter.
 tile size - determines size( in pixels ) of the square to be used.
tile saturation- determines the intensity of the color of the squares
thereby defining the opacity of square.

Local Variables -
 1. cvals - storing default values for the parameters of the structure
CubismVals.

 2. GimpPlugInInfo PLUG_IN_INFO - Contains four pointers to different
functions which are called during plugin execution.
 a)init - optional(can have null value) and is called as GIMP starts up. It
can be called if we want to register some procedure conditionally on some
files prescence.
 b)quit - also optional( can have null value ) and is called when GIMP is
going to close.
c)query - called when the plugin comes into existence or every time when it
is modified.
 d)run - it is the plugin processing function which receives the plugin
name, input parameters, number of return values, pointer to output
parameters.


MAIN() - it is a macro defined for calling the initialisation and calling
appropriate functions that our plugin needs during its life time.

Functions -

1. query() - defines the input arguments
 Structure GimpParamDef contains - type, name and description.
 It registers the function in the path specified as here under
Image/Filters/Artistic


2. cubism_dialog (GimpDrawable *drawable) -
 opens a dialog box for the user for specifying the basic input parameters.
This also function holds the basic layout informaion for the dialog box. It
clearly mentions the existence of two scale bars ( tile saturation,tile size
), preview window, toggle button( use background color ) and ok button. User
can change the value of parameters and have a preview for every changed
argument.The widget does not gets destroyed until the ok button( signal -
GTK_RESPONSE_OK ) or cancel button is pressed and the final parameters are
then saved.


3. cubism (GimpDrawable *drawable,GimpPreview  *preview) -

Every variable of the GimpDrawable struct has a drawable id, width,
height,bytes per pixel,number of tile rows, number of tile columns, normal
tiles and shadow tiles. Here we check if the drawable has an alpha channel
associated with it. Alpha channel can be there with the layer types such as
RGB, GRAYSCALE and it defines the amount of opacity of the layer.

Here in this function it checks whether cubism effect has to be applied in
the preview window or on the main image and accordingly performs the task.
 For preview window -
It gets the preview window position and the preview area width, preview area
height sets the bound and allocates 'sel_height * sel_width * bytes' memory
locations of type guchar all initialised to 0 and pointed by dest.

If not preview - then directly set bounds based on drawable-id

Now we determine the background color. If it is set as default 'Black' then
we initialise the bg_col array with 0, otherwise we get the background color
and set the bg_col array with it. Then we calculate the number of rows and
columns based on tile_size.

It fills the image based on the background color.

If it is for preview then it directly assigns each destination byte with the
color in bg_color.
 Otherwise - While creating the cubistic transformation it displays the
progress bar having a label - 'Cubistic Transformation' . It now loops
through every pixel and initialises the background color to the colour of
the original image.Now based on the number of rows and columns it calculates
the number of tiles. Initialise a pixel region pointed by src_rgn ,new
region being attached to drawable region, (x1,y1) as initial coordinates,
width as (x2-x1)and height as (y2-y1).Based on tile size and random indices
it calculates the random starting points( x, y ), then random width and
height and random angle( theta ). It initialises a 

[Gimp-developer] Porting GIMP plugins to GEGL operations - GSOC 2011

2011-04-04 Thread shivani maheshwari
Here are the other 3 files . I had to post in two different mails on account
of size exceeding the limit of mail

*Gaussian blur-*
*
*
Functions -

1.iir_young_find_constants (gfloat sigma, gdouble *B, gdouble *b) -
 Based on sigma( standard deviation of Gaussian distribution ) we calculate
the constants. If sigma == 0 then to prevent ringing at the tile boundaries
we define *B = 1 and b[0]=1,b[1]=b[2]=b[3]=0 else the value of the constants
depend upon the parameter 'q'.

2. iir_young_blur_1D (gfloat * buf,gint offset, gint delta_offset, gdouble
B, gdouble * b, gfloat *w, gint w_len)-
in the forward filter we increase the offset every time we iterate by an
amount = delta_offset till we reach the end.
 In backward filter we begin from the other extreme and every time we
iterate to the left we decrease the offset by an amount = delta_offset
 3. iir_young_hor_blur (GeglBuffer *src, const GeglRectangle
*src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect, gdouble B,  gdouble
 *b) -
This is for INFINITE IMPULSE RESPONSE.Produces the horizontal blurring in
the image.It expects the source and destination to be of same height and 0 y
offset.

4. iir_young_ver_blur (GeglBuffer *src, const GeglRectangle
*src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect, gdouble B,  gdouble
 *b) -
This is for INFINITE IMPULSE RESPONSE.Produces the vertical blurring in the
image.It expects the source and destination to be of same width and 0 x
offset.

5. fir_calc_convolve_matrix_length (gdouble sigma) -
calculates the length of convolution matrix depending upon the standard
deviation.

6. fir_gen_convolve_matrix (gdouble sigma, gdouble **cmatrix_p) -
produces the convolution matrix cmatrix_p which is applied to the original
image to produce gaussian blur.Each pixel's new value is set to a weighted
average of that pixel's neighborhood. The original pixel's value receives
the heaviest weight (having the highest Gaussian value) and neighboring
pixels receive smaller weights as their distance to the original pixel
increases.

7. fir_young_hor_blur (GeglBuffer *src, const GeglRectangle
*src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect, gdouble B,  gdouble
 *b) -
Calculates horizontal blur for FINITE IMPULSE RESPONSE.It expects the source
and destination to be of same height and 0 y offset.

8. fir_young_ver_blur (GeglBuffer *src, const GeglRectangle
*src_rect,GeglBuffer *dst,const GeglRectangle *dst_rect, gdouble B,  gdouble
 *b) -
Calculates vertical blur for FINITE IMPULSE RESPONSE.It expects the source
and destination to be of same width and 0 x offset.

9.process (GeglOperation *operation, GeglBuffer *input,GeglBuffer *output,
const GeglRectangle *result)-

GeglOperationAreaFilter base class allows defining operations where output
data depends upon a neighbourhood with an input window that extends beyond
the output window, the information about needed extra pixels in different
directions should be set up in the prepare callback for the operation.Based
on 'iir' or 'fir' it blurifies the image first horizontally and then
 vertically with different sets of functions used for both cases.

*Extras -*
*
*
*Cartoon - *
*
*
header file - libgimp/gimp.h makes all basic plugin elements available to
us.

Structures defined-
 1. CartoonVals - holds parameters - mask_radius,threshold,pct_black
mask_radius - size of area the filter works upon
 threshold - relative intensity difference which will result in darkening
pct_black - decides the amount of black color added to the image

Local Variables -
 1. cvals - storing default values for the parameters of the structure
CartoonVals.

 2. GimpPlugInInfo PLUG_IN_INFO - Contains four pointers to different
functions which are called during plugin execution.
 a)init - optional(can have null value) and is called as GIMP starts up. It
can be called if we want to register some procedure conditionally on some
files prescence.
 b)quit - also optional( can have null value ) and is called when GIMP is
going to close.
c)query - called when the plugin comes into existence or every time when it
is modified.
 d)run - it is the plugin processing function which receives the plugin
name, input parameters, number of return values, pointer to output
parameters.


MAIN() - it is a macro defined for calling the initialisation and calling
appropriate functions that our plugin needs during its life time.

Functions -

1. query() - defines the input arguments
 Structure GimpParamDef contains - type, name and description.
 It registers the function in the path specified as here under
Image/Filters/Artistic


2. cartoon_dialog (GimpDrawable *drawable) -
 opens a dialog box for the user for specifying the basic input parameters.
This also function holds the basic layout informaion for the dialog box. It
clearly mentions the existence of two scale bars ( mask radius, percent
black ), preview window and ok button. User can change the value of
parameters and have a preview for every changed argument.The widget does