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, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "vcolourtuner.h"
31 #include "mediaoptions.h"
33 #define PICTUREFILE "/colourtest.jpg"
35 int VColourTuner::rfactor=100;
36 int VColourTuner::gfactor=100;
37 int VColourTuner::bfactor=100;
39 VColourTuner::VColourTuner()
41 int sw= Video::getInstance()->getScreenWidth();
42 int sh= Video::getInstance()->getScreenHeight();
44 setPosition((sw-area.w)/2, (sh-area.h)/2);
47 picture.setPosition(160,60);
54 Log::getInstance()->log("VColourTuner",Log::DEBUG,"created %p",this);
57 VColourTuner::~VColourTuner()
59 Log::getInstance()->log("VColourTuner",Log::DEBUG,"deleted %p",this);
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);
70 void VColourTuner::draw()
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);
80 int picx=picture.getX();
81 Colour bc=Colour(140,140,140);
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);
105 picture.init(PICTUREFILE);
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);
114 int VColourTuner::handleCommand(int command)
172 ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);
180 MediaOptions::getInstance()->setIntOption("FactorRed",rfactor);
181 MediaOptions::getInstance()->setIntOption("FactorGreen",gfactor);
182 MediaOptions::getInstance()->setIntOption("FactorBlue",bfactor);
188 ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);
190 bool updateAll=drawPicture;
193 BoxStack::getInstance()->update(this);
198 r.w=picture.getX()-1;
201 BoxStack::getInstance()->update(this,&r);
205 r.w=area.w-picture.getX();
206 BoxStack::getInstance()->update(this,&r);
214 void VColourTuner::processMessage(Message* m)
216 if (m->message == Message::MOUSE_MOVE)
220 else if (m->message == Message::MOUSE_LBDOWN)
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())
227 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
229 else if (y>=(int)area.h-24 && y<=(int)area.h-6)
236 void VColourTuner::updateFactor(int color, int amount) {
240 if (vrfactor < 20 ) vrfactor=20;
241 if (vrfactor > 200) vrfactor=200;
245 if (vgfactor < 20 ) vgfactor=20;
246 if (vgfactor > 200) vgfactor=200;
250 if (vbfactor < 20 ) vbfactor=20;
251 if (vbfactor > 200) vbfactor=200;
254 updateFactor(1,amount);
255 updateFactor(2,amount);
256 updateFactor(3,amount);
259 while ((vrfactor+vbfactor+vgfactor) > 300) updateFactor(4,-1);
260 while ((vrfactor+vbfactor+vgfactor) < 300) updateFactor(4,1);
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)
273 Log::getInstance()->log("VColourTuner",Log::DEBUG,"setting initial factors r=%d,g=%d,b=%d",rf,gf,bf);
275 Surface_TYPE::initConversionTables(rfactor,gfactor,bfactor);