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 polygon, translates it to
starting point( x,y ) and rotates it. Now by making use of CLAMP macro it
checks whether the starting point x and y lie within the specified range (
x1, x2-1 ) and ( y1, y2-1) respectively then it fills the buffer pointed by
col with the value of pixel (ix,iy) in the region src_rgn.col. It fills the
respective polygon and updates the image.


4. fill_poly_color (Polygon *poly,GimpDrawable *drawable, GimpPreview
 *preview,guchar *col,guchar *dest) -

It uses polygon fill algorithm(scanline) to fill the polygon. Find the
distance between the two points, if the dist > 0 then initialise the vector
vec by the unit vectors else by 0.Now we initialise the pixel region pointed
by src_rgn, but the point to be noticed here is that we keep the last 2
parameters as TRUE, TRUE which define that the src_rgn will be used to write
the shadow tiles. We first write the shadow tiles and then merge changes
from the shadow tile to the current selected image.

polygon_extends function is used to calculate the minimum and maximum of x
and y values and from it we initialise the size_y, size_x . Besides it
min_scanlines, max_scanlines, min_scanlines_iter, max_scanlines_iter are
also allocated memory and initialised. Now apply convert_segment for every
two points of a segment to find min and max values.

After all prior calculations now we fill the polygon. A memory location vals
of size = size_x is initialised.Now we use the vector 'vec' which we
initialised in the begining of this function to calc_alpha_blend which
returns the alpha value between 0.2 to 1.0 and the buf buffer is actually
used to hold the color(+opacity) for each pixel


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

Enumerator holding the types for the region outside the mandelbrot fractal -
OUTSIDE_TYPE_WRAP,  OUTSIDE_TYPE_TRANSPARENT,  OUTSIDE_TYPE_BLACK,
 OUTSIDE_TYPE_WHITE

Structures defined-
 1. parameter_t - it holds the input values for the mandelbrot fractal.
x1 - minimum x value
x2 - maximum x value
 y1 - minimum y value
y2 - maximim y value
depth - number of iterations
 outside_type - type of layer outside the fractal. can have any value as
defined in the enum above.

 2. selection_t - parameters for the selected region - x1, y1, x2, y2,
width, height, center_x, center_y

 3. image_t - holds info about the image including its width, height, alpha
value,bytes per pixel

 4. pixel_t - holds the coloring info for each pixel including the RGB value
along with alpha it any.

 5. preview - holds the preview info including the preview obj, pixels,
scale, width, height, bpp.
Local Variables -

 1. 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/Map"

2. pixels_init (GimpDrawable *drawable) -

initialises the pixel region pointed by *sPr ,  starting point (0,0) width
and height being - image->width, image->height and the region will be used
to read the actual drawable datas.

initialises the pixel region pointed by *dPr ,  starting point (0,0) width
and height being - image->width, image->height and the region will be used
to the region will be used to write to the shadow tiles.

initialise 2 references to 2 memory locations - spixel for source and dpixel
for destination. Each of them hold the pixel values for each column
 In the next for loop we get all pixel of a row in spixel[y] and we iterate
over from col 0 - height so as to cover whole image row wise.

3. pixels_free( ) -
 to free the source and destination pixel arrays.

4. pixels_get() -
In this function each pixel is initialised the appropriate color + alpha
value depending upon the bpp( bytes per pixel ) from the spixel .

5. pixels_get_biliner (gdouble  x, gdouble  y, pixel_t *pixel) -
for a particular pixel it calculates x1 = floor(x) and x2 = x1+1 and then it
gets the pixel color info for following pixels-
 (x1,y1),(x1,y2),(x2,y1)(x2,y2).After this it gets the aggregate alpha value
and if this aggregate alpha value for the pixel(x,y) is not zero then it
redefines the RGB values for that pixel

6. pixels_set (gint x, gint y, pixel_t *pixel ) -
sets value for the destination pixel based upon the bpp for the current
image.

7. pixels_store() -
sets the pixels pointed by dPr by values of buffer dpixel. It draws pixels
from values (0,y) to (0+width-1,y).

8. mandelbrot (gdouble  x, gdouble  y, gdouble *u, gdouble *v) -
 This function calculates the x, y values till the iterator < depth. It
initialises xx = x, yy = y.And then on every iteration yy = 2*xx*yy + y and
xx = x^2 - y^2 + x and updated x^2 = xx and y^2 = yy  after every
iteration.

9. filter( GimpDrawable *drawable ) -
calculate the scale_x and scale_y parameters. Iterate row wise from bottom
to up  and calculate px, py from mandelbrot. If the returned values lie
between the image bounds i.e 0 <= px <= width and 0 <= py <= height then
apply pixel_biliner to calculate corresponding color+alpha value.
Else if the pixel does not lie within the bounds then it makes use of the
enum defined variables to color the image.
In case of OUTSIDE_TYPE_WRAP - if( px < 0 ) set px = px + image.width and
similarly for height and then use pixel_biliner() to get pixel color.
 In case of OUTSIDE_TYPE_TRANSPARENT - r = g = b = a = 0;
In case of OUTSIDE_BLACK - r = g = b = 0, a = 255
 In case of OUTSIDE_TYPE_WHITE - r = g = b = a = 255

gimp_progress_update() updates the progress bar labelled by "Fractal Trace"
as the image is being mapped to destination .Finally the shadow tiles are
merged and the drawable image is updated.

10. dialog_show() -
Sets up the dialog box to set parameters for the mandelbrot fractal.There
are groupped radio buttons including - Wrap, Transparent,Black, White for
the outside type. 5 state bars exist each for x1,x2,y1,y2 and depth value
and an ok button clicking on which leads to release of signal
(GTK_RESPONSE_OK ) thereby saving the parameters and destroying the widget.
We can change the parameters indefinitely and have a look in a preview
window.

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

Structures defined-
 1. PlasmaValues - it holds parameters - seed, turbulence,random_seed
turbulence - controls complexity of plasma. High values give hard feeling to
the cloud( like an abstract oil painting or mineral grains), low values
produce a softer cloud (like steam, mist or smoke). The range is 0.1 to 7.0.
 random_seed - controls randomisation element.

Local Variables -

 1. 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.
 2. pvals - default plasma values.

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/Map"

2. plasma_dialog(GimpDrawable *drawable)-
 creates a dialog box for selecting the parameters for plasma view. It
contains a preview window,preview toggle button, random seed, scale bar for
turbulence.New seed button clicking on which sets new seed. Randomise
check-button will set the seed using the hardware clock of the computer. Can
change the parameters any number of time, have preview in preview window. On
clicking the OK button GTK_RESPONSE_OK signal is released and final image is
generated.

3. plasma( GimpDrawable *drawable, gboolean preview_mode ) -
intialise a pixel by pixel_init(). It then checks in the selected figure a
rectangle exists or a point. If it is not a point it will try to reduce it
to a point by placing the seed pixel in all of the corners and then at the
center as well.Now we recurse deep into the image by do_plasma until we
reach the desired depth.

5. add_random( GRand  *gr, guchar *pixel, gint amount ) -
generates a random int between -amount to +amount for every alpha value and
adds it to the pixel.

4. do_plasma()-
  calculates the center of the rectangle( xm, ym ). For depth = -1 it
calculates the random values of color for the center of rectangle, corners
of rectangle and center of each edge and then returns FALSE.
  For depth = 0 - it gets pixels for all the corner points.ran = (gint)
((256.0 / (2.0 * scale_depth)) * pvals.turbulence) is used to add_random
values to the result.Now we do divide the region into four parts and based
on that we do the analysis. For the left region - average the values,
add_random values and put_pixel in the position. For the right region , top
region , bottom region also do the same task.For the middle pixel it does
the same work but first calculates the average from t1, br buffer and then
average from b1, tr buffer and then the average of the two results obtained,
followed by add_random and put_pixel in destination.
 If pixel depth is not zero then it calls this function recursively for the
four different regions of the rectangle until the recurssion unwinds.

-- 
Shivani Maheshwari
Under Graduation( BTech.)
Indian Institute of Information Technology,
Allahabad (Amethi Campus)
India
_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

Reply via email to