Selection offset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I currently have a problem with my plugin. On some pictures, it works on a part of the image right-shifted from the selection, instead of working on the selection itself. I commented out the algorithm part of the plugin, and it keeps having this effect.

Does anybody have an idea?

Here is the code and test procedure.

First I select a part of the image away for the border (it must always be the case, because of other reasons).

I initialize two regions : one for reading, and one for writing.


Here is the initialisation part.

gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
width = x2-x1; height = y2-y1;
iWidth = gimp_drawable_width(drawable->drawable_id);
iHeight = gimp_drawable_height(drawable->drawable_id);
gimp_pixel_rgn_init (&rgn_mask, mask_drawable, 0, 0, iWidth, iHeight,
                      FALSE, FALSE);
gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, width, height,
                        TRUE, TRUE);


Then, if I just read the whole first region with this loop

   for(j=0; j<iHeight; j++) {
           gimp_pixel_rgn_get_row(&rgn_in, rvbrow, 0, j, iWidth);
           for(i=0; i<iWidth; i++) {
                   gdouble r, v, b;
                   r=(gdouble)rvbrow[3*i]; v=(gdouble)rvbrow[3*i+1]; b=(gdouble)rvbrow[3*i+2];
                   rhoIn[j*iWidth+i] = sqrt(r*r+b*b+v*v);
                   if( sqrt(r*r+b*b) != 0.0 )
                           sinPhiIn[j*iWidth+i] = r / sqrt(r*r+b*b);
                   else
                           sinPhiIn[j*iWidth+i] = 0.0;
                   if( rhoIn[j*iWidth+i] != 0.0 )
                           sinPsiIn[j*iWidth+i] = v / rhoIn[j*iWidth+i];
                   else
                           sinPsiIn[j*iWidth+i] = 0.0;
                   rhoIn[j*iWidth+i] /= sqrt(3.0*255.0*255.0);
           }
           gimp_progress_update((gdouble)j/(gdouble)iHeight);
   }


and write it again with this one :

   for(j=y1; j<y2; j++) {
           for(i=x1; i<x2; i++) {
                   gdouble r, v, b;
                   rhoIn[j*iWidth+i] *= sqrt(3.0*255.0*255.0);
                   v = round( rhoIn[j*iWidth+i] * sinPsiIn[j*iWidth+i] );
                   r = round(sqrt( rhoIn[j*iWidth+i]*rhoIn[j*iWidth+i]
                                   * (1 - sinPsiIn[j*iWidth+i]*sinPsiIn[j*iWidth+i])
                                   * sinPhiIn[j*iWidth+i]*sinPhiIn[j*iWidth+i] ));
                   b = round( sqrt(rhoIn[j*iWidth+i]*rhoIn[j*iWidth+i]-r*r-v*v) );
                   r=CLAMP(r,0.0,255.0); v=CLAMP(v,0.0,255.0); b=CLAMP(b,0.0,255.0);
                   rvbout[3*(i-x1)] = (guchar)r; rvbout[3*(i-x1)+1] = (guchar)v; rvbout[3*(i-x1)+2] = (guchar)b;

           }
           gimp_pixel_rgn_set_row(&rgn_out, rvbout, x1, j, width);
           gimp_progress_update((gdouble)(j-y1)/(gdouble)height);
   }

I have this problem with some pictures, but not with others, which adds to the mystery.
_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux