[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gimp-developer
Subject:    Re: [Gimp-developer] GsoC - 2011 - Porting GIMP plugins to GEGL
From:       Robert Sasu <sasu.robert () gmail ! com>
Date:       2011-03-31 18:45:51
Message-ID: AANLkTimbPHaqj4BKB-6g9xdAJR06CDuf4m0joeyTJg4A () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I wrote the code review for 2 more plug-ins: Cartoon and Photocopy

Gimp dialog function do all almost the same thing: Let the user choose the
parameters for each plugin by opening a box with a preview box. While
changing the parameters it changes the preview image until the user press
the ok or the cancel button.
We can say the same thing for run function (almost the same). It gets the
drawable in the drawable structure the sets the tile cache size, gets data
from the keyboard and run the dialog, if there is no dialog it initiates its
own values for the plug-in. Checks if everything is all right, run the
plugin and stores the data.

1. Cartoon (in gegl the base class would be AREA FILTER):
    Algorithm:
    For each pixel it calculates the pixel intensity by comparing the pixels
relative intesity to its neighborhood pixels and to the relative intensity
difference to total black .
Let say mask radius is equal with radius of pixel neighborhood for intensity
comparison, threshold is the relative intensity difference which will result
in darkening, ramp is the amount of relative intensity difference before
total black and blur radius is mask radius per 3.
Then the new intensity of the pixel will be:
 relative difference = pixel intensity / average (mask radius)
 If relative difference < Threshold
 intensity multiply = (Ramp - MIN (Ramp, (Threshold - relative difference)))
/ Ramp
 pixel intensity =old intensity * intensity mult

    static void cartoon:
    Checks for the preview, then sets the width and height of the drawable
image, gets the image type (bytes) and the aplha value (has_alpha). It
initialize the 5 vectors and 2 destination image structures (dest1 for blur
radius and dest2 for mask radius). Calculates the standard deviations from
blur and mask radius. Then derives the constant values for calculating the
gaussian's from the deviations (via the 4th order approximation of the
gaussian operator).
Like in the case of gaussian blur the calculation of the new values of the
image is linear so the calculation can be devided for 2 directions. First
calculates the values for every column then for every row.
Calculating for every column: firstly initializes and calculates the first
and the last pixel of the column. Then with the help of the gaussian
constants it calculates every pixel of the column the transfers the pixels
to the destination image.
It will do the same calculations in case of the horizontal direction.
After calculating the blakc percentage value (ramp). Then calculates the new
intensity for each pixel:
relative difference = pixel intensity / average (mask radius)
 intensity multiply=1
 If relative difference < Threshold
 intensity multiply = (Ramp - MIN (Ramp, (Threshold - relative
difference))) / Ramp
 pixel intensity =old intensity * intensity multiply
 Before upgrading the drawable image transfers the calculated destination
image structure from RGB format to HLS, sets the lightness and converts
back.

    computer ramp:
    Calculates the ramp value (intensity difference from total black) by
calculating the difference between the destination images (one calculated
with blur radius the other with mask radius), and hysterizes the difference.
Then compares the hysterized values to the percentage of the black color and
calculates the relative intensity via average.


    2. Photocopy (in gegl the base class would be AREA FILTER):
    Propagates dark value in an image based on each pixel's relative
darkness to a neighboring average. Sets the remaining pixels to white.
    The plug-in differs a little from the cartoon plug-in.
    Algorithm:
    Using the same notations as in the cartoon plug-in the new intensity of
every pixel will be:
elative diff = pixel intensity / avg (mask radius)
 If relative diff < Threshold
    intensity mult = (Ramp - MIN (Ramp, (Threshold - relative diff))) / Ramp
    pixel intensity *= intensity mult
 Else pixel intensity = white

    static void photocopy: It is almost the same as in the cartoon plug-in.
    Desaturates the image, checks for the preview, then sets the width and
height of the drawable image, gets the image type (bytes) and the aplha
value (has_alpha). It initialize the 5 vectors and 2 destination image
structures (dest1 for blur radius and dest2 for mask radius). Calculates the
standard deviations from blur and mask radius. Then derives the constant
values for calculating the gaussian's from the deviations (via the 4th order
approximation of the gaussian operator).
Like in the case of gaussian blur the calculation of the new values of the
image is linear so the calculation can be devided for 2 directions. First
calculates the values for every column then for every row.
Calculating for every column: firstly initializes and calculates the first
and the last pixel of the column. Then with the help of the gaussian
constants it calculates every pixel of the column the transfers the pixels
to the destination image.
It will do the same calculations in case of the horizontal direction.
After calculating the black and white percentage values (ramp down and ramp
up). Relative difference is equal with the average pixel intensity of the
blur radius image per the average pixel intersity of the maske radius image.
While calculating the intensity of each pixel it also calculates the
lightness of the drawable image between 0 and 255.
   intensity multiply = 1
   if relative diff < Threshold
    if ramp_down == 0 intensity multiply = 0
        else intensity mult = (ramp_down - MIN (ramp_down, (Threshold -
relative
difference))) / ramp_down
   else if ramp_down !=0 mult = MIN (ramp_up,(relative difference -
Threshold)) / ramp_up;
    Knowing the lightness calculates the value of each pixel and draws the
image.

    compute ramp and find constants functions are the same as in the cartoon
plug-in.



    Compute ramp and find constants could be directly written in gegl api as
not to write the same thing twice. For recalculating the pixels by adding
lightness we could use a lightness plug-in for it.

    I have an exam saturday, so I will finish and send the plug-in ported to
gegl on sunday.
    If there is anything else I should do please write it. If there is
something wrong with the code reviews tell it and I will rewrite it.

    Thanks,
    Robert Sasu

[Attachment #5 (text/html)]

I wrote the code review for 2 more plug-ins: Cartoon and Photocopy<br><br>Gimp dialog \
function do all almost the same thing: Let the user choose the parameters for each \
plugin by opening a box with a preview box. While changing the parameters it changes \
the preview image until the user press the ok or the cancel button. <br> We can say \
the same thing for run function (almost the same). It gets the drawable in the \
drawable structure the sets the tile cache size, gets data from the keyboard and run \
the dialog, if there is no dialog it initiates its own values for the plug-in. Checks \
if everything is all right, run the plugin and stores the data.<br> <br>1. Cartoon \
(in gegl the base class would be AREA FILTER):<br>    Algorithm: <br>    For each \
pixel it calculates the pixel intensity by comparing the pixels relative intesity to \
its neighborhood pixels and to the relative intensity difference to total black .<br> \
Let say mask radius is equal with radius of pixel neighborhood for intensity \
comparison, threshold is the relative intensity difference which will result in \
darkening, ramp is the amount of relative intensity difference before total black and \
blur radius is mask radius per 3. <br> Then the new intensity of the pixel will be: \
<br> relative difference = pixel intensity / average (mask radius)<br> If relative \
difference &lt; Threshold<br> intensity multiply = (Ramp - MIN (Ramp, (Threshold - \
relative difference))) / Ramp<br>  pixel intensity =old intensity * intensity \
mult<br>    <br>    static void cartoon:<br>    Checks for the preview, then sets the \
width and height of the drawable image, gets the image type (bytes) and the aplha \
value (has_alpha). It initialize the 5 vectors and 2 destination image structures \
(dest1 for blur radius and dest2 for mask radius). Calculates the standard deviations \
from blur and mask radius. Then derives the constant values for calculating the \
gaussian&#39;s from the deviations (via the 4th order approximation of the gaussian \
operator). <br> Like in the case of gaussian blur the calculation of the new values \
of the image is linear so the calculation can be devided for 2 directions. First \
calculates the values for every column then for every row. <br>Calculating for every \
column: firstly initializes and calculates the first and the last pixel of the \
column. Then with the help of the gaussian constants it calculates every pixel of the \
column the transfers the pixels to the destination image. <br> It will do the same \
calculations in case of the horizontal direction. <br>After calculating the blakc \
percentage value (ramp). Then calculates the new intensity for each \
pixel:<br>relative difference = pixel intensity / average (mask radius)<br>  \
intensity multiply=1<br> If relative difference &lt; Threshold<br> intensity multiply \
= (Ramp - MIN (Ramp, (Threshold - relative   difference))) / Ramp<br> pixel intensity \
=old intensity * intensity multiply<br> Before upgrading the drawable image transfers \
the calculated destination image structure from RGB format to HLS, sets the lightness \
and converts back. <br> <br>    computer ramp:<br>    Calculates the ramp value \
(intensity difference from total black) by calculating the difference between the \
destination images (one calculated with blur radius the other with mask radius), and \
hysterizes the difference. Then compares the hysterized values to the percentage of \
the black color and calculates the relative intensity via average. <br> <br>    <br>  \
2. Photocopy (in gegl the base class would be AREA FILTER):<br>    Propagates dark \
value in an image based on each pixel&#39;s relative darkness to a neighboring \
average. Sets the remaining pixels to white.<br>  The plug-in differs a little from \
the cartoon plug-in. <br>    Algorithm: <br>    Using the same notations as in the \
cartoon plug-in the new intensity of every pixel will be: <br>elative diff = pixel \
intensity / avg (mask radius)<br>  If relative diff &lt; Threshold<br>    intensity \
mult = (Ramp - MIN (Ramp, (Threshold - relative diff))) / Ramp<br>    pixel intensity \
*= intensity mult<br> Else pixel intensity = white<br><br>    static void photocopy: \
It is almost the same as in the cartoon plug-in.<br>  Desaturates the image, checks \
for the preview, then sets the width and height of the drawable image, gets the image \
type (bytes) and the aplha value (has_alpha). It initialize the 5 vectors and 2 \
destination image structures (dest1 for blur radius and dest2 for mask radius). \
Calculates the standard deviations from blur and mask radius. Then derives the \
constant values for calculating the gaussian&#39;s from the deviations (via the 4th \
order approximation of the gaussian operator). <br> Like in the case of gaussian blur \
the calculation of the new values of the image is linear so the calculation can be \
devided for 2 directions. First calculates the values for every column then for every \
row. <br>Calculating for every column: firstly initializes and calculates the first \
and the last pixel of the column. Then with the help of the gaussian constants it \
calculates every pixel of the column the transfers the pixels to the destination \
image. <br> It will do the same calculations in case of the horizontal direction. \
<br>After calculating the black and white percentage values (ramp down and ramp up). \
Relative difference is equal with the average pixel intensity of the blur radius \
image per the average pixel intersity of the maske radius image. While calculating \
the intensity of each pixel it also calculates the lightness of the drawable image \
between 0 and 255.<br>  intensity multiply = 1<br>   if relative diff &lt; \
Threshold<br>    if ramp_down == 0 intensity multiply = 0<br>        else intensity \
mult = (ramp_down - MIN (ramp_down, (Threshold - relative<br>difference))) / \
ramp_down<br>  else if ramp_down !=0 mult = MIN (ramp_up,(relative difference - \
Threshold)) / ramp_up;<br>    Knowing the lightness calculates the value of each \
pixel and draws the image.<br><br>    compute ramp and find constants functions are \
the same as in the cartoon plug-in.<br> <br>    <br><br>    Compute ramp and find \
constants could be directly written in gegl api as not to write the same thing twice. \
For recalculating the pixels by adding lightness we could use a lightness plug-in for \
it. <br> <br>    I have an exam saturday, so I will finish and send the plug-in \
ported to gegl on sunday.<br>    If there is anything else I should do please write \
it. If there is something wrong with the code reviews tell it and I will rewrite \
it.<br> <br>    Thanks,<br>    Robert Sasu<br>



_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic