1 /*
2  *  lines.c
3  *  iTunesXPlugIn
4  *
5  *  Created by guillaum on Tue Aug 14 2001.
6  *  Copyright (c) 2001 __CompanyName__. All rights reserved.
7  *
8  */
9 
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 
14 #include "lines.h"
15 #include <math.h>
16 
17 static inline unsigned char
lighten(unsigned char value,unsigned char power)18 lighten (unsigned char value, unsigned char power)
19 {
20   unsigned char i;
21 
22   for (i = 0; i < power; i++)
23     value += (255 - value) / 5;
24   return value;
25 }
26 
27 void
goom_lines(GoomData * goomdata,gint16 data[2][512],unsigned int ID,unsigned int * p,guint32 power)28 goom_lines (GoomData * goomdata, gint16 data[2][512], unsigned int ID,
29     unsigned int *p, guint32 power)
30 {
31   guint32 color1;
32   guint32 color2;
33   guint32 resolx = goomdata->resolx;
34   guint32 resoly = goomdata->resoly;
35   unsigned char *color = 1 + (unsigned char *) &color1;
36 
37   switch (ID) {
38     case 0:                    /* Horizontal stereo lines */
39     {
40       color1 = 0x0000AA00;
41       color2 = 0x00AA0000;
42       break;
43     }
44 
45     case 1:                    /* Stereo circles */
46     {
47       color1 = 0x00AA33DD;
48       color2 = 0x00AA33DD;
49       break;
50     }
51     default:{
52       color1 = color2 = 0;
53       g_assert_not_reached ();
54       break;
55     }
56   }
57   *color = lighten (*color, power);
58   color++;
59   *color = lighten (*color, power);
60   color++;
61   *color = lighten (*color, power);
62   color = 1 + (unsigned char *) &color2;
63   *color = lighten (*color, power);
64   color++;
65   *color = lighten (*color, power);
66   color++;
67   *color = lighten (*color, power);
68 
69   switch (ID) {
70     case 0:                    /* Horizontal stereo lines */
71     {
72       unsigned int i;
73 
74       for (i = 0; i < 512; i++) {
75         guint32 plot;
76 
77         plot = i * resolx / 512 + (resoly / 4 + data[0][i] / 1600) * resolx;
78         p[plot] = color1;
79         p[plot + 1] = color1;
80         plot = i * resolx / 512 + (resoly * 3 / 4 - data[1][i] / 1600) * resolx;
81         p[plot] = color2;
82         p[plot + 1] = color2;
83       }
84       break;
85     }
86 
87     case 1:                    /* Stereo circles */
88     {
89       float z;
90       unsigned int monX = resolx / 2;
91       float monY = (float) resoly / 4;
92       float monY2 = (float) resoly / 2;
93 
94       for (z = 0; z < 6.2832f; z += 1.0f / monY) {
95         /* float offset1 = 128+data[1][(unsigned int)(z*81.33f)])/200000; */
96         p[monX + (unsigned int) ((monY + ((float) resoly) * (128 +
97                         data[1][(unsigned int) (z * 81.33f)]) / 200000) *
98                 cos (z) + resolx * (unsigned int) (monY2 + (monY +
99                         ((float) resoly) * (128 +
100                             data[1][(unsigned int) (z * 81.33f)]) / 400000) *
101                     sin (z)))] = color1;
102         p[monX + (unsigned int) ((monY - ((float) resoly) * (128 +
103                         data[0][(unsigned int) (z * 81.33f)]) / 200000) *
104                 cos (z) + resolx * (unsigned int) (monY2 + (monY -
105                         ((float) resoly) * (128 +
106                             data[0][(unsigned int) (z * 81.33f)]) / 400000) *
107                     sin (z)))] = color2;
108       }
109       break;
110     }
111   }
112 }
113