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