MythTV  master
lines.c
Go to the documentation of this file.
1 /*
2  * lines.c
3  */
4 
5 #include "lines.h"
6 #include <math.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "goom_tools.h"
10 #include "drawmethods.h"
11 
12 extern unsigned int resolx, c_resoly;
13 
14 static inline unsigned char
15 lighten (unsigned char value, float power)
16 {
17  int val = value;
18  float t = (float) val * log10f(power) / 2.0F;
19 
20  if (t > 0) {
21  val = (int) t; // (32.0F * log (t));
22  if (val > 255)
23  val = 255;
24  if (val < 0)
25  val = 0;
26  return val;
27  }
28  return 0;
29 }
30 
31 static void
32 lightencolor (int *col, float power)
33 {
34  unsigned char *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 != NULL) {
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  unsigned char *c1 = (unsigned char *) &l->color;
120  unsigned char *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  GMLine *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 = NULL;
198 }
199 
200 void
201 goom_lines_draw (GMLine * line, const gint16 data[512], unsigned int *p)
202 {
203  if (line != NULL) {
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 }
static unsigned char lighten(unsigned char value, float power)
Definition: lines.c:15
void goom_lines_set_res(GMLine *gml, int rx, int ry)
Definition: lines.c:96
float amplitude
Definition: lines.h:27
int IDdest
Definition: lines.h:24
#define NULL
Definition: H264Parser.h:62
GMUnitPointer * points2
Definition: lines.h:23
int screenY
Definition: lines.h:34
#define ROUGE
position des composantes
Definition: goomconfig.h:10
float powinc
Definition: lines.h:37
GMLine * goom_lines_init(int rx, int ry, int IDsrc, float paramS, int coulS, int IDdest, float paramD, int coulD)
Definition: lines.c:155
#define GML_HLINE
Definition: lines.h:44
#define GML_VLINE
Definition: lines.h:47
#define GML_BLACK
Definition: lines.h:58
static guint32 getcouleur(int mode)
Definition: lines.c:74
#define DRAWMETHOD_DONE()
Definition: drawmethods.h:38
static void goom_lines_move(GMLine *l)
Definition: lines.c:110
#define guint32
Definition: goomconfig.h:35
float angle
Definition: lines.h:16
guint32 color2
Definition: lines.h:31
#define GML_BLEU
Definition: lines.h:57
Definition: lines.h:20
static int x2
Definition: mythsocket.cpp:61
GMUnitPointer * points
Definition: lines.h:22
int nbPoints
Definition: lines.h:29
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:46
static void lightencolor(int *col, float power)
Definition: lines.c:32
#define M_PI_F
Definition: goom_tools.h:7
guint32 color
Definition: lines.h:30
float amplitudeF
Definition: lines.h:26
int screenX
Definition: lines.h:33
float x
Definition: lines.h:14
#define GML_RED
Definition: lines.h:53
void goom_lines_switch_to(GMLine *gml, int IDdest, float param, float amplitude, int col)
Definition: lines.c:143
void goom_lines_free(GMLine **l)
Definition: lines.c:192
float param
Definition: lines.h:25
#define BLEU
Definition: goomconfig.h:11
static void genline(int id, float param, GMUnitPointer *l, int rx, int ry)
Definition: lines.c:45
#define GML_ORANGE_V
Definition: lines.h:54
#define GML_VERT
Definition: lines.h:56
#define GML_BLEUBLANC
Definition: lines.h:52
float power
Definition: lines.h:36
unsigned int resolx
Definition: goom_core.c:65
float y
Definition: lines.h:15
#define iRAND(i)
Definition: goom_tools.h:33
#define VERT
Definition: goomconfig.h:12
void goom_lines_draw(GMLine *line, const gint16 data[512], unsigned int *p)
Definition: lines.c:201
unsigned int c_resoly
Definition: goom_core.c:65
#define gint16
Definition: goomconfig.h:37
#define GML_CIRCLE
Definition: lines.h:41
static int x1
Definition: mythsocket.cpp:60
#define GML_ORANGE_J
Definition: lines.h:55