MythTV  master
lines.cpp
Go to the documentation of this file.
1 /*
2  * lines.c
3  */
4 
5 #include <algorithm>
6 #include <cmath>
7 #include <cstdio>
8 #include <cstdlib>
9 
10 #include "lines.h"
11 #include "drawmethods.h"
12 #include "goom_core.h"
13 #include "goom_tools.h"
14 
15 extern unsigned int resolx, c_resoly;
16 
17 static inline unsigned char
18 lighten (unsigned char value, float power)
19 {
20  int val = value;
21  float t = (float) val * log10f(power) / 2.0F;
22 
23  if (t > 0) {
24  val = (int) t; // (32.0F * log (t));
25  return std::min(val, 255);
26  }
27  return 0;
28 }
29 
30 static void
31 lightencolor (int *col, float power)
32 {
33  auto *color = (unsigned char *) col;
34  *color = lighten (*color, power);
35  color++;
36  *color = lighten (*color, power);
37  color++;
38  *color = lighten (*color, power);
39  color++;
40  *color = lighten (*color, power);
41 }
42 
43 static void
44 genline (int id, float param, GMUnitPointer * l, int rx, int ry)
45 {
46  switch (id) {
47  case GML_HLINE:
48  for (int i = 0; i < 512; i++) {
49  l[i].x = ((float) i * rx) / 512.0F;
50  l[i].y = param;
51  l[i].angle = M_PI_F / 2.0F;
52  }
53  return;
54  case GML_VLINE:
55  for (int i = 0; i < 512; i++) {
56  l[i].y = ((float) i * ry) / 512.0F;
57  l[i].x = param;
58  l[i].angle = 0.0F;
59  }
60  return;
61  case GML_CIRCLE:
62  for (int i = 0; i < 512; i++) {
63  l[i].angle = 2.0F * M_PI_F * (float) i / 512.0F;
64  float cosa = param * cosf (l[i].angle);
65  float sina = param * sinf (l[i].angle);
66  l[i].x = ((float) rx / 2.0F) + cosa;
67  l[i].y = (float) ry / 2.0F + sina;
68  }
69  return;
70  }
71 }
72 
73 static guint32 getcouleur (int mode)
74 {
75  switch (mode) {
76  case GML_RED:
77  return (230 << (ROUGE * 8)) | (120 << (VERT * 8)) | (10 << (BLEU * 8));
78  case GML_ORANGE_J:
79  return (120 << (VERT * 8)) | (252 << (ROUGE * 8)) | (10 << (BLEU * 8));
80  case GML_ORANGE_V:
81  return (160 << (VERT * 8)) | (236 << (ROUGE * 8)) | (40 << (BLEU * 8));
82  case GML_BLEUBLANC:
83  return (40 << (BLEU * 8)) | (220 << (ROUGE * 8)) | (140 << (VERT * 8));
84  case GML_VERT:
85  return (200 << (VERT * 8)) | (80 << (ROUGE * 8)) | (10 << (BLEU * 8));
86  case GML_BLEU:
87  return (250 << (BLEU * 8)) | (30 << (VERT * 8)) | (80 << (ROUGE * 8));
88  case GML_BLACK:
89  return 0x5 << (BLEU * 8);
90  }
91  return 0;
92 }
93 
94 void
95 goom_lines_set_res (GMLine * gml, int rx, int ry)
96 {
97  if (gml != nullptr) {
98  //int i;
99 
100  gml->screenX = rx;
101  gml->screenY = ry;
102 
103  genline (gml->IDdest, gml->param, gml->points2, rx, ry);
104  }
105 }
106 
107 
108 static void
110 {
111  for (int i = 0; i < 512; i++) {
112  l->points[i].x = (l->points2[i].x + 39.0F * l->points[i].x) / 40.0F;
113  l->points[i].y = (l->points2[i].y + 39.0F * l->points[i].y) / 40.0F;
114  l->points[i].angle =
115  (l->points2[i].angle + 39.0F * l->points[i].angle) / 40.0F;
116  }
117 
118  auto *c1 = (unsigned char *) &l->color;
119  auto *c2 = (unsigned char *) &l->color2;
120  for (int i = 0; i < 4; i++) {
121  int cc1 = *c1;
122  int cc2 = *c2;
123  *c1 = (unsigned char) ((cc1 * 63 + cc2) >> 6);
124  ++c1;
125  ++c2;
126  }
127 
128  l->power += l->powinc;
129  if (l->power < 1.1F) {
130  l->power = 1.1F;
131  l->powinc = (float) (iRAND (20) + 10) / 300.0F;
132  }
133  if (l->power > 17.5F) {
134  l->power = 17.5F;
135  l->powinc = -(float) (iRAND (20) + 10) / 300.0F;
136  }
137 
138  l->amplitude = (99.0F * l->amplitude + l->amplitudeF) / 100.0F;
139 }
140 
141 void
142 goom_lines_switch_to (GMLine * gml, int IDdest,
143  float param, float amplitude, int col)
144 {
145  genline (IDdest, param, gml->points2, gml->screenX, gml->screenY);
146  gml->IDdest = IDdest;
147  gml->param = param;
148  gml->amplitudeF = amplitude;
149  gml->color2 = getcouleur (col);
150 // printf ("couleur %d : %x\n",col,gml->color2);
151 }
152 
153 GMLine *
154 goom_lines_init (int rx, int ry,
155  int IDsrc, float paramS, int coulS,
156  int IDdest, float paramD, int coulD)
157 {
158  //int i;
159  //unsigned char *color;
160  //unsigned char power = 4;
161 
162  auto *l = (GMLine *) malloc (sizeof (GMLine));
163 
164  l->points = (GMUnitPointer *) malloc (512 * sizeof (GMUnitPointer));
165  l->points2 = (GMUnitPointer *) malloc (512 * sizeof (GMUnitPointer));
166  l->nbPoints = 512;
167 
168  l->IDdest = IDdest;
169  l->param = paramD;
170 
171  l->amplitude = l->amplitudeF = 1.0F;
172 
173  genline (IDsrc, paramS, l->points, rx, ry);
174  genline (IDdest, paramD, l->points2, rx, ry);
175 
176  l->color = getcouleur (coulS);
177  l->color2 = getcouleur (coulD);
178 
179  l->screenX = rx;
180  l->screenY = ry;
181 
182  l->power = 0.0F;
183  l->powinc = 0.01F;
184 
185  goom_lines_switch_to (l, IDdest, paramD, 1.0F, coulD);
186 
187  return l;
188 }
189 
190 void
192 {
193  free ((*l)->points);
194  free ((*l)->points2);
195  free (*l);
196  *l = nullptr;
197 }
198 
199 void
200 goom_lines_draw (GMLine * line, const GoomSingleData& data, unsigned int *p)
201 {
202  if (line != nullptr) {
203  guint32 color = line->color;
204  GMUnitPointer *pt = &(line->points[0]);
205 
206  float cosa = cosf (pt->angle) / 1000.0F;
207  float sina = sinf (pt->angle) / 1000.0F;
208 
209  lightencolor ((int *)&color, line->power);
210 
211  int x1 = (int) (pt->x + (cosa * line->amplitude * data[0]));
212  int y1 = (int) (pt->y + (sina * line->amplitude * data[0]));
213 
214  for (int i = 1; i < 512; i++) {
215  pt = &(line->points[i]);
216 
217  cosa = cosf (pt->angle) / 1000.0F;
218  sina = sinf (pt->angle) / 1000.0F;
219 
220  int x2 = (int) (pt->x + (cosa * line->amplitude * data[i]));
221  int y2 = (int) (pt->y + (sina * line->amplitude * data[i]));
222 
223  draw_line ((int *)p, x1, y1, x2, y2, color, line->screenX, line->screenY);
224  DRAWMETHOD_DONE ();
225 
226  x1 = x2;
227  y1 = y2;
228  }
229  goom_lines_move (line);
230  }
231 }
GoomSingleData
std::array< int16_t, 512 > GoomSingleData
Definition: goom_core.h:12
lines.h
goom_lines_init
GMLine * goom_lines_init(int rx, int ry, int IDsrc, float paramS, int coulS, int IDdest, float paramD, int coulD)
Definition: lines.cpp:154
draw_line
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:46
resolx
unsigned int resolx
Definition: goom_core.cpp:56
GMLine::points
GMUnitPointer * points
Definition: lines.h:23
goom_lines_switch_to
void goom_lines_switch_to(GMLine *gml, int IDdest, float param, float amplitude, int col)
Definition: lines.cpp:142
x2
static int x2
Definition: mythsocket.cpp:51
GML_CIRCLE
#define GML_CIRCLE
Definition: lines.h:42
GMLine::IDdest
int IDdest
Definition: lines.h:25
GML_BLACK
#define GML_BLACK
Definition: lines.h:59
GMUnitPointer::angle
float angle
Definition: lines.h:17
GMLine::param
float param
Definition: lines.h:26
GML_ORANGE_J
#define GML_ORANGE_J
Definition: lines.h:56
GMLine::power
float power
Definition: lines.h:37
goom_lines_free
void goom_lines_free(GMLine **l)
Definition: lines.cpp:191
GML_HLINE
#define GML_HLINE
Definition: lines.h:45
c_resoly
unsigned int c_resoly
Definition: lines.cpp:15
GML_RED
#define GML_RED
Definition: lines.h:54
GMUnitPointer::x
float x
Definition: lines.h:15
goom_lines_set_res
void goom_lines_set_res(GMLine *gml, int rx, int ry)
Definition: lines.cpp:95
DRAWMETHOD_DONE
#define DRAWMETHOD_DONE()
Definition: drawmethods.h:38
goom_lines_draw
void goom_lines_draw(GMLine *line, const GoomSingleData &data, unsigned int *p)
Definition: lines.cpp:200
hardwareprofile.config.p
p
Definition: config.py:33
hardwareprofile.i18n.t
t
Definition: i18n.py:36
GML_VLINE
#define GML_VLINE
Definition: lines.h:48
goom_core.h
x1
static int x1
Definition: mythsocket.cpp:50
drawmethods.h
GML_VERT
#define GML_VERT
Definition: lines.h:57
GMLine::screenX
int screenX
Definition: lines.h:34
GMLine::amplitude
float amplitude
Definition: lines.h:28
GMLine
Definition: lines.h:21
GMLine::amplitudeF
float amplitudeF
Definition: lines.h:27
goom_lines_move
static void goom_lines_move(GMLine *l)
Definition: lines.cpp:109
iRAND
static unsigned int iRAND(int i)
Definition: goom_tools.h:42
genline
static void genline(int id, float param, GMUnitPointer *l, int rx, int ry)
Definition: lines.cpp:44
GMUnitPointer
Definition: lines.h:13
GMLine::screenY
int screenY
Definition: lines.h:35
GML_BLEU
#define GML_BLEU
Definition: lines.h:58
BLEU
#define BLEU
Definition: goomconfig.h:11
GML_ORANGE_V
#define GML_ORANGE_V
Definition: lines.h:55
goom_tools.h
ROUGE
#define ROUGE
position des composantes
Definition: goomconfig.h:10
GMLine::color
guint32 color
Definition: lines.h:31
GML_BLEUBLANC
#define GML_BLEUBLANC
Definition: lines.h:53
GMUnitPointer::y
float y
Definition: lines.h:16
VERT
#define VERT
Definition: goomconfig.h:12
guint32
#define guint32
Definition: goomconfig.h:35
GMLine::powinc
float powinc
Definition: lines.h:38
lightencolor
static void lightencolor(int *col, float power)
Definition: lines.cpp:31
lighten
static unsigned char lighten(unsigned char value, float power)
Definition: lines.cpp:18
GMLine::points2
GMUnitPointer * points2
Definition: lines.h:24
M_PI_F
#define M_PI_F
Definition: bumpscope.cpp:163
GMLine::color2
guint32 color2
Definition: lines.h:32
getcouleur
static guint32 getcouleur(int mode)
Definition: lines.cpp:73