Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 327179 | Differences between
and this patch

Collapse All | Expand All

(-)refocus-0.9.0/ChangeLog (+6 lines)
Lines 2-4 Link Here
2
2
3
	* This is the first public release (0.9.0) of the refocus plug-in.
3
	* This is the first public release (0.9.0) of the refocus plug-in.
4
4
5
2007-09-28  Richard Lemieux <rlemieu(at)cooptel(dot)qc(dot)ca
6
7
        * The plugin failed for some picture sizes because of buffer
8
          overflow on the last row of tiles.  I corrected the code
9
          handling the upper boundary of the picture.
10
 
(-)refocus-0.9.0/src/conv.c (-1 / +11 lines)
Lines 421-433 Link Here
421
  gint x, buf_start_y, total_tiles, tile_nr = 0;
421
  gint x, buf_start_y, total_tiles, tile_nr = 0;
422
  /* Will be false when progress_update tells us that the data is no longer needed */
422
  /* Will be false when progress_update tells us that the data is no longer needed */
423
  gboolean ok = TRUE;
423
  gboolean ok = TRUE;
424
424
  /*
425
    tile_height()                 [util.c]
426
    tile_width()                  [util.c]
427
   */
425
  initialize_buf (&buf, source, mat_size / 2, sx, sy, width, height,
428
  initialize_buf (&buf, source, mat_size / 2, sx, sy, width, height,
426
                  boundary_type);
429
                  boundary_type);
427
  total_tiles = (1 + floor ((buf.x + buf.width - 1) / tile_width ())
430
  total_tiles = (1 + floor ((buf.x + buf.width - 1) / tile_width ())
428
                 - floor ((buf.x) / tile_width ())) *
431
                 - floor ((buf.x) / tile_width ())) *
429
    (1 + floor ((buf.y_limit - 1) / tile_height ())
432
    (1 + floor ((buf.y_limit - 1) / tile_height ())
430
     - floor ((buf.y) / tile_height ()));
433
     - floor ((buf.y) / tile_height ()));
434
#ifdef RLXTEST
435
  printf("convolve_image: total_tiles %d\n",total_tiles);
436
#endif
431
437
432
  buf_start_y = buf.y;
438
  buf_start_y = buf.y;
433
  while (ok && shift_buf (&buf, source))
439
  while (ok && shift_buf (&buf, source))
Lines 437-442 Link Here
437
        {
443
        {
438
          const gint ncolors = source->bpp - source->has_alpha;
444
          const gint ncolors = source->bpp - source->has_alpha;
439
          GimpTile *tile = tile_sink_get_tile (sink, x, buf.y);
445
          GimpTile *tile = tile_sink_get_tile (sink, x, buf.y);
446
#ifdef RLXTEST
447
          printf("convolve_image: x %d, y %d, tile->eheight %d\n",
448
                 x, buf.y, tile->eheight);
449
#endif
440
          convolve_tile (tile, pixpos_in_buf (&buf, x, buf.y), buf.row_stride,
450
          convolve_tile (tile, pixpos_in_buf (&buf, x, buf.y), buf.row_stride,
441
                         ncolors, sink->bpp, mat->data, mat_size);
451
                         ncolors, sink->bpp, mat->data, mat_size);
442
          tile_sink_tile_unref (sink, tile);
452
          tile_sink_tile_unref (sink, tile);
(-)refocus-0.9.0/src/tilebuf.c (-7 / +74 lines)
Lines 18-23 Link Here
18
 * Version $Id: tilebuf.c,v 1.1.1.1 2003/01/30 21:30:19 ernstl Exp $
18
 * Version $Id: tilebuf.c,v 1.1.1.1 2003/01/30 21:30:19 ernstl Exp $
19
 */
19
 */
20
20
21
#include <stdio.h>
21
#include "tilebuf.h"
22
#include "tilebuf.h"
22
#include "util.h"
23
#include "util.h"
23
#include <string.h>
24
#include <string.h>
Lines 39-44 Link Here
39
guchar *
40
guchar *
40
pixpos_in_buf (TileStripBuffer * buf, const gint x, const gint y)
41
pixpos_in_buf (TileStripBuffer * buf, const gint x, const gint y)
41
{
42
{
43
  /*
44
    & data = array(? lines x row_stride columns)
45
    & pixpos_in_buf = &data[(x - real_x)*bytes_per_pixel, y - real_y]
46
    & (real_x, real_y) = origin of tile.
47
   */
42
  return (&buf->data[buf->row_stride * (y - buf->real_y) +
48
  return (&buf->data[buf->row_stride * (y - buf->real_y) +
43
                     buf->bpp * (x - buf->real_x)]);
49
                     buf->bpp * (x - buf->real_x)]);
44
}
50
}
Lines 220-226 Link Here
220
static void
226
static void
221
fix_bottom_boundary (TileStripBuffer * buf, const gint y_hi)
227
fix_bottom_boundary (TileStripBuffer * buf, const gint y_hi)
222
{
228
{
223
  if (y_hi >= buf->real_y + buf->real_height)
229
  if (y_hi >= buf->real_y + buf->real_height)       /* (1) */
224
    {
230
    {
225
      return;
231
      return;
226
    };
232
    };
Lines 234-246 Link Here
234
      break;
240
      break;
235
    case TB_BOUNDARY_MIRROR:
241
    case TB_BOUNDARY_MIRROR:
236
      {
242
      {
237
        register gint y;
243
        register gint y2;
238
244
239
        for (y = y_hi; y < buf->real_y + buf->real_height; y++)
245
        /*if (y_hi < buf->y_limit)*/
246
        for (y2 = y_hi; y2 < buf->real_y + buf->real_height; y2++) /*(2)*/
240
          {
247
          {
241
            gint sy = 2 * (y_hi - 1) - y;
248
            /*
242
            copy_row (buf, buf->real_x, sy>=buf->real_y?sy:buf->real_y,
249
              &1 y < y_hi              [domain of y, definition of y_hi, (1)]
243
                      buf->real_width, y);
250
              &2 y_hi <= y2 < buf->real_y + buf->real_height  [(1),(2)]
251
              &3 i = 0, 1, ...
252
              &4 y=y_hi-i-1 -> y2=y_hi+i               [definition of mirror]
253
              &5 y = y2 - 2*i - 1                      [4]
254
              &6 y = 2*y2 - 2*i - y2 - 1               [5,algebra]
255
              &7 y = 2*y_hi - y2 - 1                   [4,6]
256
            */
257
            gint y =  2*y_hi - y2 - 1;
258
            if (y < buf->real_y) break;
259
#ifdef RLXTEST
260
           printf("fix_bottom_boundary: Copying row %d to %d, width %d, buf_loc %d %d, real_y %d\n",
261
                  2*y_hi - y2 - 1, y2, buf->real_width,
262
                  buf->row_stride * (2*y_hi - y2 - 1 - buf->real_y) +
263
                   buf->bpp * (buf->real_x - buf->real_x),
264
                  buf->row_stride * (y2 - buf->real_y) +
265
                   buf->bpp * (buf->real_x - buf->real_x),
266
                   buf->real_y);
267
#endif
268
            copy_row (buf, buf->real_x, y, buf->real_width,y2);
244
          };
269
          };
245
      }
270
      }
246
      break;
271
      break;
Lines 262-268 Link Here
262
  const gint y_lo = MAX (buf->real_y, source->y);
287
  const gint y_lo = MAX (buf->real_y, source->y);
263
  const gint y_hi = MIN (buf->real_y + buf->real_height,
288
  const gint y_hi = MIN (buf->real_y + buf->real_height,
264
                         source->y + source->height);
289
                         source->y + source->height);
265
290
  /*
291
    y:  domain of y.
292
    & 0 <= y.  y is a 0-index.
293
    & | & y in the source image
294
        & 0 <=  source->y <= y < source->y + source->height
295
      | & y in the buffer
296
        & 0 <= buf->real_y <= y < buf->real_y + buf->real_height
297
    x:  domain of x = domain of y with mapping y -> x, height -> width.
298
   */
299
300
#ifdef RLXTEST
301
  printf("buf->real_y %d, buf->real_height %d, source->y %d, source->heigh %d, y_hi %d\n",
302
         buf->real_y,  buf->real_height,
303
       source->y, source->height, y_hi);
304
#endif
266
  fix_left_boundary (buf, x_lo, first_time ? buf->y : buf->y + tile_height (),
305
  fix_left_boundary (buf, x_lo, first_time ? buf->y : buf->y + tile_height (),
267
                     y_hi);
306
                     y_hi);
268
  fix_right_boundary (buf, x_hi,
307
  fix_right_boundary (buf, x_hi,
Lines 271-277 Link Here
271
    {
310
    {
272
      fix_top_boundary (buf, y_lo);
311
      fix_top_boundary (buf, y_lo);
273
    };
312
    };
313
#ifdef RLXTEST
314
  printf("fix_boundaries: Now goto fix_bottom_boundary: y_hi %d, real_y + real_height %d, data[%d]\n",
315
         y_hi, buf->real_y + buf->real_height,
316
         buf->real_height * buf->row_stride);
317
#endif
274
  fix_bottom_boundary (buf, y_hi);
318
  fix_bottom_boundary (buf, y_hi);
319
#ifdef RLXTEST
320
  printf("bottom boundary fixed\n");
321
#endif
275
}
322
}
276
323
277
void
324
void
Lines 318-323 Link Here
318
  gint x;
365
  gint x;
319
  gboolean not_finished = TRUE;
366
  gboolean not_finished = TRUE;
320
367
368
  /*
369
    & y_limit = height of picture, if full picture.
370
   */
371
#ifdef RLXTEST
372
  printf("buf->y %d + tile_height%d () >= buf->y_limit %d\n",
373
         buf->y,tile_height(),buf->y_limit);
374
#endif
375
321
  if (buf->first_time)
376
  if (buf->first_time)
322
    {
377
    {
323
      /* Buf must already have been initialized so there is nothing to do */
378
      /* Buf must already have been initialized so there is nothing to do */
Lines 330-348 Link Here
330
    }
385
    }
331
  else
386
  else
332
    {
387
    {
388
#ifdef RLXTEST
389
      printf("shift_buf: tile_height %d\n", tile_height());
390
#endif
333
      memmove (pixpos_in_buf (buf, buf->real_x,
391
      memmove (pixpos_in_buf (buf, buf->real_x,
334
                              buf->real_y),
392
                              buf->real_y),
335
               pixpos_in_buf (buf, buf->real_x,
393
               pixpos_in_buf (buf, buf->real_x,
336
                              buf->real_y + tile_height ()),
394
                              buf->real_y + tile_height ()),
337
               buf->row_stride * (tile_height () + buf->border_width));
395
               buf->row_stride * (tile_height () + buf->border_width));
338
      buf->y += tile_height ();
396
      buf->y += tile_height ();
397
#ifdef RLXTEST
398
      printf("shift_buf: y %d, y_limit %d\n", buf->y,  buf->y_limit);
399
#endif
339
      buf->real_y = buf->y - buf->border_width;
400
      buf->real_y = buf->y - buf->border_width;
340
      for (x = buf->x - tile_width ();
401
      for (x = buf->x - tile_width ();
341
           x <= buf->x + buf->width; x += tile_width ())
402
           x <= buf->x + buf->width; x += tile_width ())
342
        {
403
        {
343
          copy_tile_to_buf (buf, source, x, buf->y + tile_height ());
404
          copy_tile_to_buf (buf, source, x, buf->y + tile_height ());
405
#ifdef RLXTEST
406
          printf("shift_buf: x %d\n", x);
407
#endif
344
        };
408
        };
345
      fix_boundaries (buf, source, FALSE);
409
      fix_boundaries (buf, source, FALSE);
346
    };
410
    };
411
#ifdef RLXTEST
412
  printf("shift_buf: done\n");
413
#endif
347
  return (not_finished);
414
  return (not_finished);
348
}
415
}
(-)refocus-0.9.0/src/util.c (+25 lines)
Lines 18-23 Link Here
18
 * Version $Id: util.c,v 1.1.1.1 2003/01/30 21:30:19 ernstl Exp $
18
 * Version $Id: util.c,v 1.1.1.1 2003/01/30 21:30:19 ernstl Exp $
19
 */
19
 */
20
20
21
#include <stdio.h>
21
#include "util.h"
22
#include "util.h"
22
#include <string.h>
23
#include <string.h>
23
#include <math.h>
24
#include <math.h>
Lines 30-43 Link Here
30
gint
31
gint
31
floorm (gint a, gint b)
32
floorm (gint a, gint b)
32
 /* return largest multiple of b that is <= a */
33
 /* return largest multiple of b that is <= a */
34
 /*
35
  & & m = floorm(a,b)
36
    & a = b*m + r
37
    &  0 <= r < b
38
  */
33
{
39
{
40
#ifdef RLXTEST
41
  printf("floorm: a/b %d, fl %g\n", a/b, floor ((gdouble) a / b));
42
#endif
34
  return (b * floor ((gdouble) a / b));
43
  return (b * floor ((gdouble) a / b));
35
}
44
}
36
45
37
gint
46
gint
38
ceilm (gint a, gint b)
47
ceilm (gint a, gint b)
39
 /* return least multiple of b that is >= a */
48
 /* return least multiple of b that is >= a */
49
 /*
50
    & m = ceilm(a,b)
51
    & a = b*m - r;
52
    & m = a/b
53
    % r = a%b
54
    & -a = -b*m + r
55
56
    & ceilm = (r == 0 ? b*m : (b+1)*m)
57
  */
40
{
58
{
59
#ifdef RLXTEST
60
  printf("ceil: a %d, b %d, -(-a/b) %d,a/b+(a%b != 0 ? 1:0) %d,  fl %g\n",
61
         a,b,
62
         -((-a)/b),
63
          a/b+(a%b != 0 ? 1:0),
64
         ceil ((gdouble) a / b) );
65
#endif
41
  return (b * ceil ((gdouble) a / b));
66
  return (b * ceil ((gdouble) a / b));
42
}
67
}
43
68

Return to bug 327179