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