diff --git a/src/filters/wrap.c b/src/filters/wrap.c index e1bd9b186..b7bdc039f 100644 --- a/src/filters/wrap.c +++ b/src/filters/wrap.c @@ -28,13 +28,88 @@ typedef struct { bool current_only; } filter_wrap_t; +static void volume_wrap(volume_t *volume, int axis, int sign, + const int aabb[2][3]) +{ + int pos[3]; + int buffer_pos[3]; + int volume_pos[3]; + int size[3]; + uint8_t *buffer; + int i; + size_t buffer_offset; + + if (aabb[1][axis] - aabb[0][axis] == 1) { + return; + } + + size[0] = aabb[1][0] - aabb[0][0]; + size[1] = aabb[1][1] - aabb[0][1]; + size[2] = aabb[1][2] - aabb[0][2]; + + buffer = malloc(4 * size[0] * size[1] * size[2]); + + for (pos[0] = 0; pos[0] < size[0]; pos[0]++) { + for (pos[1] = 0; pos[1] < size[1]; pos[1]++) { + for (pos[2] = 0; pos[2] < size[2]; pos[2]++) { + memcpy(buffer_pos, pos, sizeof(pos)); + memcpy(volume_pos, pos, sizeof(pos)); + + for (i = 0; i < 3; i++) { + volume_pos[i] += aabb[0][i]; + } + + buffer_pos[axis] += sign; + + if (buffer_pos[axis] < 0) { + buffer_pos[axis] += size[axis]; + } + + buffer_pos[axis] %= size[axis]; + + buffer_offset = 4 * ( + buffer_pos[2] * size[0] * size[1] + + buffer_pos[1] * size[0] + buffer_pos[0] + ); + + volume_get_at(volume, NULL, volume_pos, &buffer[buffer_offset]); + } + } + } + + for (pos[0] = 0; pos[0] < size[0]; pos[0]++) { + for (pos[1] = 0; pos[1] < size[1]; pos[1]++) { + for (pos[2] = 0; pos[2] < size[2]; pos[2]++) { + memcpy(volume_pos, pos, sizeof(pos)); + + for (i = 0; i < 3; i++) { + volume_pos[i] += aabb[0][i]; + } + + buffer_offset = 4 * ( + pos[2] * size[0] * size[1] + + pos[1] * size[0] + pos[0] + ); + + volume_set_at(volume, NULL, volume_pos, &buffer[buffer_offset]); + } + } + } + + free(buffer); +} + static bool wrap_box(int *out_axis, int *sign) { char buf[8]; bool ret = false; - static const char* AXIS_NAMES[] = {"X", "Y", "Z"}; + int axis; + const char *AXIS_NAMES[] = {"X", "Y", "Z"}; + + *out_axis = 0; + *sign = 1; - for (int axis = 0; axis < 3; axis++) { + for (axis = 0; axis < 3; axis++) { gui_row_begin(2); snprintf(buf, sizeof(buf), "-%s", AXIS_NAMES[axis]); diff --git a/src/volume.c b/src/volume.c index 90e4648f3..faf5d6464 100644 --- a/src/volume.c +++ b/src/volume.c @@ -825,71 +825,3 @@ void volume_get_global_stats(volume_global_stats_t *stats) { *stats = g_global_stats; } - -void volume_wrap(volume_t *volume, int axis, int sign, int aabb[2][3]) -{ - int pos[3]; - int buffer_pos[3]; - int volume_pos[3]; - - if (aabb[1][axis] - aabb[0][axis] == 1) { - return; - } - - int size[3] = { - aabb[1][0] - aabb[0][0], - aabb[1][1] - aabb[0][1], - aabb[1][2] - aabb[0][2], - }; - - uint8_t *buffer = malloc(4 * size[0] * size[1] * size[2]); - - for (pos[0] = 0; pos[0] < size[0]; pos[0]++) { - for (pos[1] = 0; pos[1] < size[1]; pos[1]++) { - for (pos[2] = 0; pos[2] < size[2]; pos[2]++) { - memcpy(buffer_pos, pos, sizeof(pos)); - memcpy(volume_pos, pos, sizeof(pos)); - - for (int i = 0; i < 3; i++) { - volume_pos[i] += aabb[0][i]; - } - - buffer_pos[axis] += sign; - - if (buffer_pos[axis] < 0) { - buffer_pos[axis] += size[axis]; - } - - buffer_pos[axis] %= size[axis]; - - size_t buffer_offset = 4 * ( - buffer_pos[2] * size[0] * size[1] + - buffer_pos[1] * size[0] + buffer_pos[0] - ); - - volume_get_at(volume, NULL, volume_pos, &buffer[buffer_offset]); - } - } - } - - for (pos[0] = 0; pos[0] < size[0]; pos[0]++) { - for (pos[1] = 0; pos[1] < size[1]; pos[1]++) { - for (pos[2] = 0; pos[2] < size[2]; pos[2]++) { - memcpy(volume_pos, pos, sizeof(pos)); - - for (int i = 0; i < 3; i++) { - volume_pos[i] += aabb[0][i]; - } - - size_t buffer_offset = 4 * ( - pos[2] * size[0] * size[1] + - pos[1] * size[0] + pos[0] - ); - - volume_set_at(volume, NULL, volume_pos, &buffer[buffer_offset]); - } - } - } - - free(buffer); -} \ No newline at end of file diff --git a/src/volume.h b/src/volume.h index 4a12db7fd..d028bd835 100644 --- a/src/volume.h +++ b/src/volume.h @@ -237,6 +237,5 @@ typedef struct { } volume_global_stats_t; void volume_get_global_stats(volume_global_stats_t *stats); -void volume_wrap(volume_t *volume, int axis, int sign, int aabb[2][3]); #endif // VOLUME_H