]> git.vomp.tv Git - vompclient.git/blob - wwss.cc
*** empty log message ***
[vompclient.git] / wwss.cc
1 /*\r
2     Copyright 2006 Chris Tallon\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 */\r
20 \r
21 #include "wwss.h"\r
22 \r
23 Wwss::Wwss()\r
24 {\r
25 }\r
26 \r
27 Wwss::~Wwss()\r
28 {\r
29 }\r
30 \r
31 UINT Wwss::gcd(UINT a, UINT b)\r
32 {\r
33   UINT t;\r
34   while (b != 0)\r
35   {\r
36     t = b;\r
37     b = a % b;\r
38     a = t;\r
39   }\r
40   return a;\r
41 }\r
42 \r
43 UINT Wwss::lcm(UINT a, UINT b)\r
44 {\r
45   return (a / gcd(a, b)) * b;\r
46 }\r
47 \r
48 void Wwss::setWide(bool twide)\r
49 {\r
50   wide = twide;\r
51 }\r
52 \r
53 void Wwss::draw()\r
54 {\r
55   // The aspect43 and aspect169 codes are not what they should be according to the docs, but these are what work...\r
56   // (1 = 111000, = 0 000111)\r
57   static UCHAR runIn[]     = {1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1};                       // 29 pos 0\r
58   static UCHAR startCode[] = {0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1};                                 // 24 pos 29\r
59   static UCHAR aspect43[]  = {0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0}; // = 0001   4:3 full frame      // 24 pos 53\r
60   static UCHAR aspect169[] = {1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1}; // = 1110   16:9 anamorphic     // 24 pos 53\r
61   static UCHAR theRest[]   = {0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,                                  // 60 pos 77\r
62                               0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,\r
63                               0,0,0,1,1,1,0,0,0,1,1,1};\r
64   /*\r
65   Real PAL pixel frequency: 13.5 MHz\r
66   WSS element frequency: 5 MHz\r
67   = 2.7 pal pixels per wss element\r
68   * 137 wss elements = 369.9 pal pixels (total code width) (round to 370..)\r
69 \r
70   There is also a 11us gap at the start of the pal raster, but since I don't really have any\r
71   idea where our 720 pixels start in the raster I can't calculate an offset.\r
72 \r
73   PAL line 23 seems to be MVP line 6.\r
74   */\r
75 \r
76   const UINT   Ns = 137;           // Num pix src\r
77   const UINT   Nd = 370;           // Num pix dst         359->395 does something. not the right thing, but something.\r
78   UINT         Nl = lcm(Ns, Nd);   // Num pix in lcm\r
79   UINT         Ss = Nl / Ns;       // Source split (how many lcm px = 1 src px)\r
80   UINT         Sd = Nl / Nd;       // Dst split\r
81   UCHAR src[Ns];\r
82 \r
83   memcpy(&src[0], runIn, 29);\r
84   memcpy(&src[29], startCode, 24);\r
85   if (wide) memcpy(&src[53], aspect169, 24);\r
86   else      memcpy(&src[53], aspect43, 24);\r
87   memcpy(&src[77], theRest, 60);\r
88 \r
89   float dst[Nd];\r
90   UINT lcmpxbase = 0;\r
91 \r
92   for(UINT t = 0; t < Nd; t++) // for every destination pixel\r
93   {\r
94     dst[t] = 0;\r
95     for(UINT lcmpx = lcmpxbase; lcmpx < (lcmpxbase + Sd); lcmpx++)\r
96     {\r
97       if (src[lcmpx / Ss]) dst[t] += (float)1/Sd;\r
98     }\r
99     lcmpxbase += Sd;\r
100   }\r
101 \r
102   Colour c;\r
103   UINT value;\r
104   for(UINT q = 0; q < Nd; q++)\r
105   {\r
106     value = (UINT)(dst[q] * 182); // Apparently this is a better number than 255 for the colour value\r
107     c.set(value, value, value);\r
108     drawPixel(q, 6, c);\r
109   }\r
110 }\r