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