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