2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
20 #include "vcolourtuner.h"
30 #include "mediaoptions.h"
32 #define PICTUREFILE "/colourtest.jpg"
34 int VColourTuner::rfactor=100;
35 int VColourTuner::gfactor=100;
36 int VColourTuner::bfactor=100;
38 VColourTuner::VColourTuner()
40 int sw= Video::getInstance()->getScreenWidth();
41 int sh= Video::getInstance()->getScreenHeight();
43 setPosition((sw-area.w)/2, (sh-area.h)/2);
46 picture.setPosition(160,60);
53 Log::getInstance()->log("VColourTuner",Log::DEBUG,"created %p",this);
56 VColourTuner::~VColourTuner()
58 Log::getInstance()->log("VColourTuner",Log::DEBUG,"deleted %p",this);
61 void VColourTuner::drawBox(int x, int y, int w, int h, const DrawStyle& c) {
62 for (int row=y;row<y+h;row++)
63 for (int col=x;col<x+w;col++) {
64 surface->drawPixel(col,row,c);
69 void VColourTuner::draw()
71 //do not call base classes draw to avoid drawing the picture...
72 Log::getInstance()->log("VColourTuner::draw",Log::DEBUG,"dp %s, rf=%d, gf=%d, bf=%d",
73 (drawPicture?"true":"false"),vrfactor,vgfactor,vbfactor);
79 int picx=picture.getX();
80 DrawStyle bc=DrawStyle(140,140,140);
83 drawText(tr("Colour Tuning"), x+20, y+5, DrawStyle::LIGHTTEXT);
84 drawBox(x, y+50, bw, bh, DrawStyle::RED);
85 drawBox(x, y+130, bw, bh, DrawStyle::GREEN);
86 drawBox(x, y+190, bw, bh, DrawStyle::BLUE);
87 drawBox(x, y+270, bw, bh, bc);
88 sprintf(valbuf,"%03d%%",vrfactor);
89 drawText(valbuf,x+bw+x,y+50, DrawStyle::LIGHTTEXT);
90 drawText("<1 2>",x+bw+x,y+74, DrawStyle::LIGHTTEXT);
91 sprintf(valbuf,"%03d%%",vgfactor);
92 drawText(valbuf,x+bw+x,y+120, DrawStyle::LIGHTTEXT);
93 drawText("<4 5>",x+bw+x,y+144, DrawStyle::LIGHTTEXT);
94 sprintf(valbuf,"%03d%%",vbfactor);
95 drawText(valbuf,x+bw+x,y+190, DrawStyle::LIGHTTEXT);
96 drawText("<7 8>",x+bw+x,y+214, DrawStyle::LIGHTTEXT);
97 sprintf(valbuf,"%03d%%",(vbfactor+vgfactor+vrfactor)/3);
98 drawText(valbuf,x+bw+x,y+270, DrawStyle::LIGHTTEXT);
99 drawText("<3 6>",x+bw+x,y+294, DrawStyle::LIGHTTEXT);
100 drawText("9 norm",x+bw+x,y+318, DrawStyle::LIGHTTEXT);
101 drawText(tr("OK to save, BACK to cancel"), x+20, area.h - 50, DrawStyle::LIGHTTEXT);
104 picture.init(PICTUREFILE);
108 int picy=picture.getY();
109 int pich=picture.getHeight();
110 if (hasChanged) drawText(tr("0 to draw picture"), picx+30, picy+pich+10, DrawStyle::LIGHTTEXT);
113 int VColourTuner::handleCommand(int command)
173 ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);
183 MediaOptions::getInstance()->setIntOption("FactorRed",rfactor);
184 MediaOptions::getInstance()->setIntOption("FactorGreen",gfactor);
185 MediaOptions::getInstance()->setIntOption("FactorBlue",bfactor);
193 ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);
197 bool updateAll=drawPicture;
200 BoxStack::getInstance()->update(this);
205 r.w=picture.getX()-1;
208 BoxStack::getInstance()->update(this,&r);
212 r.w=area.w-picture.getX();
213 BoxStack::getInstance()->update(this,&r);
221 void VColourTuner::processMessage(Message* m)
223 if (m->message == Message::MOUSE_MOVE)
227 else if (m->message == Message::MOUSE_LBDOWN)
229 if (coordsOutsideBox(m))
231 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press
233 else if (y>=(int)area.h-24 && y<=(int)area.h-6)
240 void VColourTuner::updateFactor(int color, int amount) {
244 if (vrfactor < 20 ) vrfactor=20;
245 if (vrfactor > 200) vrfactor=200;
249 if (vgfactor < 20 ) vgfactor=20;
250 if (vgfactor > 200) vgfactor=200;
254 if (vbfactor < 20 ) vbfactor=20;
255 if (vbfactor > 200) vbfactor=200;
258 updateFactor(1,amount);
259 updateFactor(2,amount);
260 updateFactor(3,amount);
263 while ((vrfactor+vbfactor+vgfactor) > 300) updateFactor(4,-1);
264 while ((vrfactor+vbfactor+vgfactor) < 300) updateFactor(4,1);
268 void VColourTuner::initFactors(){
269 MediaOptions * options=MediaOptions::getInstance();
270 int rf=options->getIntOption("FactorRed");
271 int gf=options->getIntOption("FactorGreen");
272 int bf=options->getIntOption("FactorBlue");
273 if (rf >= 20 && bf >= 20 && gf >= 20)
277 Log::getInstance()->log("VColourTuner",Log::DEBUG,"setting initial factors r=%d,g=%d,b=%d",rf,gf,bf);
281 Surface_TYPE::initConversionTables(rfactor,gfactor,bfactor);