[GRASS-SVN] r71936 - grass-addons/grass7/imagery/i.superpixels.slic
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 14 06:25:58 PST 2017
Author: mmetz
Date: 2017-12-14 06:25:58 -0800 (Thu, 14 Dec 2017)
New Revision: 71936
Modified:
grass-addons/grass7/imagery/i.superpixels.slic/cache.c
grass-addons/grass7/imagery/i.superpixels.slic/cache.h
Log:
i.superpixels.slic: improve cache
Modified: grass-addons/grass7/imagery/i.superpixels.slic/cache.c
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/cache.c 2017-12-13 08:39:11 UTC (rev 71935)
+++ grass-addons/grass7/imagery/i.superpixels.slic/cache.c 2017-12-14 14:25:58 UTC (rev 71936)
@@ -6,12 +6,12 @@
static void *cache_get_r(struct cache *c, void *p, int row, int col)
{
- return memcpy(p, c->r[row][col], c->n);
+ return memcpy(p, c->r + ((size_t)row * c->cols + col) * c->n, c->n);
}
static void *cache_put_r(struct cache *c, void *p, int row, int col)
{
- return memcpy(c->r[row][col], p, c->n);
+ return memcpy(c->r + ((size_t)row * c->cols + col) * c->n, p, c->n);
}
static void *cache_get_s(struct cache *c, void *p, int row, int col)
@@ -46,23 +46,7 @@
c->put = cache_put_s;
}
else {
- int row, col;
-
- c->r = G_malloc(sizeof(char **) * c->rows);
- row = 0;
- c->r[row] = G_malloc(sizeof(char *) * c->rows * c->cols);
- c->r[row][0] = G_malloc(sizeof(char) * c->rows * c->cols * c->n);
- for (col = 1; col < c->cols; col++) {
- c->r[row][col] = c->r[row][col - 1] + c->n;
- }
- for (row = 1; row < c->rows; row++) {
- c->r[row] = c->r[row - 1] + c->cols;
- c->r[row][0] = c->r[row - 1][0] + c->cols * c->n;
- for (col = 1; col < c->cols; col++) {
- c->r[row][col] = c->r[row][col - 1] + c->n;
- }
- }
-
+ c->r = G_malloc(sizeof(char) * c->rows * c->cols * c->n);
c->get = cache_get_r;
c->put = cache_put_r;
}
@@ -76,8 +60,6 @@
Segment_close(&c->s);
}
else {
- G_free(c->r[0][0]);
- G_free(c->r[0]);
G_free(c->r);
}
Modified: grass-addons/grass7/imagery/i.superpixels.slic/cache.h
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/cache.h 2017-12-13 08:39:11 UTC (rev 71935)
+++ grass-addons/grass7/imagery/i.superpixels.slic/cache.h 2017-12-14 14:25:58 UTC (rev 71936)
@@ -3,7 +3,7 @@
struct cache
{
SEGMENT s;
- char ***r;
+ char *r;
int n; /* data size per cell in bytes */
int rows, cols;
void *(* get)(struct cache *c, void *p, int row, int col);
More information about the grass-commit
mailing list