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