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