]> git.vomp.tv Git - vompclient.git/blob - vcolourtuner.cc
Preparations for dynamic mode switching
[vompclient.git] / vcolourtuner.cc
1 /*\r
2     Copyright 2004-2005 Chris Tallon, Andreas Vogel\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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 #include "vcolourtuner.h"\r
22 \r
23 #include "wsymbol.h"\r
24 #include "remote.h"\r
25 #include "colour.h"\r
26 #include "video.h"\r
27 #include "vinfo.h"\r
28 #include "boxstack.h"\r
29 #include "i18n.h"\r
30 #include "log.h"\r
31 #include "mediaoptions.h"\r
32
33 #ifdef VOMP_PLATTFORM_MVP
34 #include "surfacemvp.h"
35 #endif
36
37 \r
38 #define PICTUREFILE "/colourtest.jpg"\r
39 \r
40 int VColourTuner::rfactor=100;\r
41 int VColourTuner::gfactor=100;\r
42 int VColourTuner::bfactor=100;\r
43 \r
44 VColourTuner::VColourTuner()\r
45 {\r
46   int sw= Video::getInstance()->getScreenWidth();\r
47   int sh= Video::getInstance()->getScreenHeight();\r
48   setSize(sw-80,sh-40);\r
49   setPosition((sw-area.w)/2, (sh-area.h)/2);\r
50   createBuffer();\r
51   setTitleBarOn(0);\r
52   picture.setPosition(160,60);\r
53   add(&picture);\r
54   drawPicture=true;\r
55   vrfactor=rfactor;\r
56   vbfactor=bfactor;\r
57   vgfactor=gfactor;\r
58   hasChanged=false;\r
59   Log::getInstance()->log("VColourTuner",Log::DEBUG,"created %p",this);\r
60 }\r
61 \r
62 VColourTuner::~VColourTuner()\r
63 {\r
64   Log::getInstance()->log("VColourTuner",Log::DEBUG,"deleted %p",this);\r
65 }\r
66 \r
67 void VColourTuner::drawBox(int x, int y, int w, int h, DrawStyle &c) {\r
68   for (int row=y;row<y+h;row++)\r
69     for (int col=x;col<x+w;col++) {\r
70       surface->drawPixel(col,row,c);\r
71     }\r
72 }\r
73 \r
74 \r
75 void VColourTuner::draw()\r
76 {\r
77     //do not call base classes draw to avoid drawing the picture...\r
78     Log::getInstance()->log("VColourTuner::draw",Log::DEBUG,"dp %s, rf=%d, gf=%d, bf=%d",\r
79         (drawPicture?"true":"false"),vrfactor,vgfactor,vbfactor);\r
80     char valbuf[20];\r
81     int x=20;\r
82     int y=20;\r
83     int bw=50;\r
84     int bh=50;\r
85     int picx=picture.getX();\r
86     DrawStyle bc=DrawStyle(140,140,140);\r
87     fillColour(bc);\r
88     bc=DrawStyle(255,255,255);\r
89     drawText(tr("Colour Tuning"), x+20, y+5, DrawStyle::LIGHTTEXT);\r
90     drawBox(x, y+50, bw, bh, DrawStyle::RED);\r
91     drawBox(x, y+130, bw, bh, DrawStyle::GREEN);\r
92     drawBox(x, y+190, bw, bh, DrawStyle::BLUE);\r
93     drawBox(x, y+270, bw, bh, bc);\r
94     sprintf(valbuf,"%03d%%",vrfactor);\r
95     drawText(valbuf,x+bw+x,y+50, DrawStyle::LIGHTTEXT);\r
96     drawText("<1 2>",x+bw+x,y+74, DrawStyle::LIGHTTEXT);\r
97     sprintf(valbuf,"%03d%%",vgfactor);\r
98     drawText(valbuf,x+bw+x,y+120, DrawStyle::LIGHTTEXT);\r
99     drawText("<4 5>",x+bw+x,y+144, DrawStyle::LIGHTTEXT);\r
100     sprintf(valbuf,"%03d%%",vbfactor);\r
101     drawText(valbuf,x+bw+x,y+190, DrawStyle::LIGHTTEXT);\r
102     drawText("<7 8>",x+bw+x,y+214, DrawStyle::LIGHTTEXT);\r
103     sprintf(valbuf,"%03d%%",(vbfactor+vgfactor+vrfactor)/3);\r
104     drawText(valbuf,x+bw+x,y+270, DrawStyle::LIGHTTEXT);\r
105     drawText("<3 6>",x+bw+x,y+294, DrawStyle::LIGHTTEXT);\r
106     drawText("9 norm",x+bw+x,y+318, DrawStyle::LIGHTTEXT);\r
107     drawText(tr("OK to save, BACK to cancel"), x+20, area.h - 50, DrawStyle::LIGHTTEXT);\r
108     if (drawPicture) {\r
109       hasChanged=false;\r
110       picture.init(PICTUREFILE);\r
111       picture.draw();\r
112       drawPicture=false;\r
113     }\r
114     int picy=picture.getY();\r
115     int pich=picture.getHeight();\r
116     if (hasChanged) drawText(tr("0 to draw picture"), picx+30, picy+pich+10, DrawStyle::LIGHTTEXT);\r
117 }\r
118 \r
119 int VColourTuner::handleCommand(int command)\r
120 {\r
121   int rt=0;\r
122   switch(command) {\r
123       case Remote::ONE:\r
124       updateFactor(1,-1);\r
125       rt=2;\r
126       hasChanged=true;\r
127       break;\r
128     case Remote::TWO:\r
129       updateFactor(1,1);\r
130       rt=2;\r
131       hasChanged=true;\r
132       break;\r
133     case Remote::FOUR:\r
134       updateFactor(2,-1);\r
135       rt=2;\r
136       hasChanged=true;\r
137       break;\r
138     case Remote::FIVE:\r
139       updateFactor(2,1);\r
140       rt=2;\r
141       hasChanged=true;\r
142       break;\r
143     case Remote::SEVEN:\r
144       updateFactor(3,-1);\r
145       rt=2;\r
146       hasChanged=true;\r
147       break;\r
148     case Remote::EIGHT:\r
149       updateFactor(3,1);\r
150       hasChanged=true;\r
151       rt=2;\r
152       break;\r
153     case Remote::THREE:\r
154       updateFactor(4,-1);\r
155       hasChanged=true;\r
156       rt=2;\r
157       break;\r
158     case Remote::SIX:\r
159       updateFactor(4,1);\r
160       hasChanged=true;\r
161       rt=2;\r
162       break;\r
163     case Remote::NINE:\r
164       updateFactor(5,0);\r
165       hasChanged=true;\r
166       rt=2;\r
167       break;\r
168     case Remote::ZERO:\r
169       drawPicture=true;\r
170       rt=2;\r
171       break;\r
172     case Remote::BACK:\r
173       vrfactor=rfactor;\r
174       vgfactor=gfactor;\r
175       vbfactor=bfactor;\r
176 #ifndef WIN32\r
177 #ifndef _MIPS_ARCH\r
178 #ifndef __ANDROID__\r
179     ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);\r
180 #endif\r
181 #endif\r
182 #endif\r
183       rt=4;\r
184       break;\r
185     case Remote::OK:\r
186       rfactor=vrfactor;\r
187       gfactor=vgfactor;\r
188       bfactor=vbfactor;\r
189       MediaOptions::getInstance()->setIntOption("FactorRed",rfactor);\r
190       MediaOptions::getInstance()->setIntOption("FactorGreen",gfactor);\r
191       MediaOptions::getInstance()->setIntOption("FactorBlue",bfactor);\r
192       rt=4;\r
193       break;\r
194   }\r
195   if (rt == 2) {\r
196 #ifndef WIN32\r
197 #ifndef _MIPS_ARCH\r
198 #ifndef __ANDROID__\r
199     ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);\r
200 #endif\r
201 #endif\r
202 #endif\r
203     bool updateAll=drawPicture;\r
204     draw();\r
205     if (updateAll) {\r
206       BoxStack::getInstance()->update(this);\r
207     }\r
208     else {\r
209       Region r;\r
210       r.x=0;\r
211       r.w=picture.getX()-1;\r
212       r.y=0;\r
213       r.h=area.h;\r
214       BoxStack::getInstance()->update(this,&r);\r
215       r.x=picture.getX();\r
216       r.y=picture.getY();\r
217       r.h=area.h-r.y;\r
218       r.w=area.w-picture.getX();\r
219       BoxStack::getInstance()->update(this,&r);\r
220     }\r
221   }\r
222   return rt;\r
223 }\r
224 \r
225 \r
226 \r
227 void VColourTuner::processMessage(Message* m)\r
228 {\r
229   if (m->message == Message::MOUSE_MOVE)\r
230   {\r
231     \r
232   }\r
233   else if (m->message == Message::MOUSE_LBDOWN)\r
234   {\r
235     //check if press is outside this view! then simulate cancel\r
236     int x=(m->parameter>>16)-getScreenX();\r
237     int y=(m->parameter&0xFFFF)-getScreenY();\r
238     if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())\r
239     {\r
240       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press\r
241     }\r
242     else if (y>=(int)area.h-24 && y<=(int)area.h-6)\r
243     {\r
244       ;\r
245     }\r
246   }\r
247 }\r
248 \r
249 void VColourTuner::updateFactor(int color, int amount) {\r
250   switch (color) {\r
251     case 1:\r
252       vrfactor+=amount;\r
253       if (vrfactor < 20 ) vrfactor=20;\r
254       if (vrfactor > 200) vrfactor=200;\r
255       break;\r
256     case 2:\r
257       vgfactor+=amount;\r
258       if (vgfactor < 20 ) vgfactor=20;\r
259       if (vgfactor > 200) vgfactor=200;\r
260       break;\r
261     case 3:\r
262       vbfactor+=amount;\r
263       if (vbfactor < 20 ) vbfactor=20;\r
264       if (vbfactor > 200) vbfactor=200;\r
265       break;\r
266     case 4:\r
267       updateFactor(1,amount);\r
268       updateFactor(2,amount);\r
269       updateFactor(3,amount);\r
270       break;\r
271     case 5:\r
272       while ((vrfactor+vbfactor+vgfactor) > 300) updateFactor(4,-1);\r
273       while ((vrfactor+vbfactor+vgfactor) < 300) updateFactor(4,1);\r
274   }\r
275 }\r
276 \r
277 void VColourTuner::initFactors(){\r
278   MediaOptions * options=MediaOptions::getInstance();\r
279   int rf=options->getIntOption("FactorRed");\r
280   int gf=options->getIntOption("FactorGreen");\r
281   int bf=options->getIntOption("FactorBlue");\r
282   if (rf >= 20 && bf >= 20 && gf >= 20)\r
283   rfactor=rf;\r
284   gfactor=gf;\r
285   bfactor=bf;\r
286   Log::getInstance()->log("VColourTuner",Log::DEBUG,"setting initial factors r=%d,g=%d,b=%d",rf,gf,bf);\r
287 #ifndef __ANDROID__\r
288 #ifndef WIN32\r
289 #ifndef _MIPS_ARCH\r
290   Surface_TYPE::initConversionTables(rfactor,gfactor,bfactor);\r
291 #endif\r
292 #endif\r
293 #endif\r
294 }\r