File: spirals_nested.c

package info (click to toggle)
lebiniou 3.67.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,500 kB
  • sloc: ansic: 28,670; makefile: 1,276; sh: 602; awk: 432; xml: 261; javascript: 23
file content (98 lines) | stat: -rw-r--r-- 2,281 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *  Copyright 1994-2022 Olivier Girondel
 *
 *  This file is part of lebiniou.
 *
 *  lebiniou is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  lebiniou is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
 */

#include "context.h"


uint32_t version = 0;
uint32_t options = BO_DISPLACE | BO_LENS | BO_NOT_LENS;
char desc[] = "Nested spirals filter";
char dname[] = "Spirals nested";

static uint32_t *map;

#define DST(x,y) map[(y*WIDTH)+x]
#define SRC(x,y) (reversed ? ((MAXY-y)*WIDTH+(MAXX-x)) : ((y*WIDTH)+x))


static void
init(const uint16_t startx, const uint16_t starty,
     char xinc, char yinc,
     short distx, short disty, uint8_t delta, const int reversed)
{
  uint16_t donex, doney;
  short x = startx, y = starty;

  while ((distx >= 0) || (disty >= 0)) {
    /* horizontal line: S----->E */
    for (donex = 0; donex < distx; donex++) {
      /*      if (xinc == 1) {
      uint16_t dx;
      for (dx = 0; dx < SWIDTH; dx++)
      */
      DST(x,y) = SRC(x,y);
      x += xinc;
    }
    xinc = -xinc;
    distx -= delta;

    /* vertical line: S */
    /*                | */
    /*                v */
    /*                E */
    for (doney = 0; doney < disty; doney++) {
      DST(x,y) = SRC(x,y);
      y += yinc;
    }
    yinc = -yinc;
    disty -= delta;
  }
}


int8_t
create(Context_t *ctx)
{
  map = xcalloc(BUFFSIZE, sizeof(uint32_t));

  init(0, 0, +1, +1, MAXSCREEN-2, MINSCREEN-2, 2, 0);
  init(MAXX, MAXY, -1, -1, MAXSCREEN-2, MINSCREEN-2, 2, 1);

  return 1;
}


void
destroy(Context_t *ctx)
{
  xfree(map);
}


void
run(Context_t *ctx)
{
  uint32_t k;
  const Buffer8_t *src = active_buffer(ctx);
  Buffer8_t *dst = passive_buffer(ctx);

  for (k = 0; k < BUFFSIZE; k++) {
    dst->buffer[k] = src->buffer[map[k]];
  }
}