14 #include <qcombobox.h> 15 #include <qpushbutton.h> 19 #include <qsizegrip.h> 21 #include <Q3GridLayout> 25 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 26 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 32 #include "../clickableLabel.h" 33 #include "../dynamicSlider.h" 34 #include "../../config.h" 35 #include "../../backend/tools/imageTools.h" 37 #define SLIDER_RADIUS 40 57 QImage image = QImage( fileName );
58 for( y=0; y<image.height(); y++)
60 scanLine = image.scanLine(y);
61 for( x=0; x<image.width(); x++)
63 rgb = ((QRgb*)scanLine+x);
64 double r = ((double)qRed(*rgb) )/255.0;
65 double g = ((double)qGreen(*rgb) )/255.0;
66 double b = ((double)qBlue(*rgb) )/255.0;
73 meanR =
meanR / ( image.width() * image.height() );
74 meanG =
meanG / ( image.width() * image.height() );
75 meanB =
meanB / ( image.width() * image.height() );
93 "histogramInterface" );
101 histogramType =
new QComboBox( visibleFrame,
"histogramType" );
107 QToolTip::add(
histogramType, tr(
"Histogram channel displayed") );
110 QString noChange = QString( tr(
"No change") );
117 connect(
brightness, SIGNAL(valueChanged(
int)),
119 QToolTip::add(
brightness, tr(
"Drag to adjust image brightness") );
131 connect(
contrast, SIGNAL(valueChanged(
int)),
133 QToolTip::add(
contrast, tr(
"Drag to adjust image contrast") );
143 QPushButton* applyButton =
new QPushButton( tr(
"Apply"),
buttonsFrame );
144 applyButton->setDefault(
true);
145 applyButton->setFocus();
146 connect( applyButton, SIGNAL(clicked()), SLOT(
applyAction()) );
148 QPushButton* cancelButton =
new QPushButton( tr(
"Cancel"),
buttonsFrame );
149 connect( cancelButton, SIGNAL(clicked()), SLOT(reject()) );
151 QPushButton* resetButton =
new QPushButton( tr(
"Reset"),
buttonsFrame );
152 connect( resetButton, SIGNAL(clicked()), SLOT(
resetAction()) );
154 Q3GridLayout* buttonsGrid =
new Q3GridLayout(
buttonsFrame, 1, 5, 0 );
155 buttonsGrid->setColStretch( 0, 1 );
156 buttonsGrid->addWidget( applyButton, 0, 1 );
157 buttonsGrid->addWidget( cancelButton, 0, 2 );
158 buttonsGrid->addWidget( resetButton, 0, 3 );
159 buttonsGrid->setColStretch( 4, 1 );
162 Q3GridLayout* mainGrid =
new Q3GridLayout( visibleFrame, 5, 3, 0 );
165 mainGrid->addMultiCellWidget(
previewSelection, 1,1, 0,2, Qt::AlignHCenter );
169 mainGrid->addWidget(
contrast, 2, 2 );
174 mainGrid->addWidget(
histogramType, 3, 0, Qt::AlignHCenter );
180 mainGrid->setRowStretch( 0, 1 );
181 mainGrid->setColStretch( 0, 1 );
186 Q3GridLayout* invisibleGrid =
new Q3GridLayout(
this, 2, 1, 0 );
187 invisibleGrid->addWidget( visibleFrame, 0, 0 );
188 invisibleGrid->setRowStretch( 0, 1 );
193 #if defined(Q_OS_WIN) 194 QSizeGrip* sizeGrip =
new QSizeGrip(
this );
195 invisibleGrid->addWidget( sizeGrip, 1, 0, Qt::AlignRight | Qt::AlignBottom );
202 setCaption( tr(
"Histogram Editor") );
213 int lumLeft, lumRight, redLeft, redRight, greenLeft, greenRight, blueLeft, blueRight;
216 greenLeft, greenRight,
217 blueLeft, blueRight );
219 lumLeft != 0 || lumRight != 255 ||
220 redLeft !=0 || redRight != 255 ||
221 greenLeft != 0 || greenRight != 255 ||
222 blueLeft != 0 || blueRight != 255 )
237 QImage* adjustedImage =
new QImage(
fileName);
240 if( adjustedImage->depth() < 32 )
242 QImage* tmp = adjustedImage;
243 adjustedImage =
new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
244 delete tmp; tmp=NULL;
248 return adjustedImage;
268 int &redLeft,
int &redRight,
269 int &greenLeft,
int &greenRight,
270 int &blueLeft,
int &blueRight)
277 greenLeft, greenRight,
278 blueLeft, blueRight );
282 lumLeft = 0; lumRight = 255;
283 redLeft = 0; redRight = 255;
284 greenLeft = 0; greenRight = 255;
285 blueLeft = 0; blueRight = 255;
295 QImage adjustedImage = origImage.copy();
306 int lumLeft, lumRight, redLeft, redRight, greenLeft, greenRight, blueLeft, blueRight;
311 greenLeft, greenRight,
312 blueLeft, blueRight );
316 lumLeft = 0; lumRight = 255;
317 redLeft = 0; redRight = 255;
318 greenLeft = 0; greenRight = 255;
319 blueLeft = 0; blueRight = 255;
323 double displayToOneScalar = 1.0/255.0;
324 double scaledMeanR = displayToOneScalar*
scaleColor( 255.0*
meanR, redLeft, redRight );
325 double scaledMeanG = displayToOneScalar*
scaleColor( 255.0*
meanG, greenLeft, greenRight );
326 double scaledMeanB = displayToOneScalar*
scaleColor( 255.0*
meanB, blueLeft, blueRight );
328 double brightnessScalar, addedBrightnessColor;
332 addedBrightnessColor = 1.0 - brightnessScalar;
337 addedBrightnessColor = 0.0;
344 int rPrime, gPrime, bPrime;
347 for( y=0; y<image.height(); y++)
349 scanLine = image.scanLine(y);
350 for( x=0; x<image.width(); x++)
353 rgb = ((QRgb*)scanLine+x);
368 r = r*displayToOneScalar;
369 g = g*displayToOneScalar;
370 b = b*displayToOneScalar;
379 r = brightnessScalar*r + addedBrightnessColor;
380 g = brightnessScalar*g + addedBrightnessColor;
381 b = brightnessScalar*b + addedBrightnessColor;
384 rPrime = (int)
MIN(
MAX((r*255), 0), 255 );
385 gPrime = (int)
MIN(
MAX((g*255), 0), 255 );
386 bPrime = (int)
MIN(
MAX((b*255), 0), 255 );
389 *rgb = qRgb(rPrime, gPrime, bPrime);
396 return MAX(
MIN( (255.0*(color-left)) / (right-left), 255), 0 );
401 if(e->key() == Qt::Key_Control )
411 else { QDialog::keyPressEvent(e); }
416 if(e->key() == Qt::Key_Control )
421 else { QDialog::keyReleaseEvent(e); }
void setPrefixes(QString prefix1, QString prefix2)
set two prefix values, one for when the value is positive and one for when the value is negative...
void selectPreviewImageType(int selection)
updates preview image
void applyAction()
check for changes to settings, if so
QComboBox * histogramType
void resetContrast()
reset contrast
HistogramInterface * histogramInterface
Histogram view.
double meanR
Mean color values.
void setPixmap(const QPixmap &p)
QImage * getModifiedImage()
get modified image that resulted from adjustments
void resetAction()
resets all adjustments
DynamicSlider * brightness
Brightness slider.
void setDisplayChannel(DISPLAYED_CHANNEL channel)
Sets currently displayed channel.
void adjustImage(QImage &image)
double scaleColor(double color, int left, int right)
ClickableLabel * contrastIcon
ClickableLabel * brightnessIcon
void keyReleaseEvent(QKeyEvent *e)
HistogramEditor(QString filename, QWidget *parent=0, const char *name=0)
Constructs layout.
QImage & getOrigImage()
returns orig image object
DISPLAYED_CHANNEL
chanel histogram displays
void generateAdjustedPreviewImage()
updates adjusted preview image
DynamicSlider * contrast
Contrast slider.
void selectHistogramType(int selection)
updates historgram interface
A more dynamic slider that provides moving tooltips that show the slider value.
void setPreviewMode(PREVIEW_MODE mode, bool forceDrawLabel=false)
Sets preview mode.
PREVIEW_MODE
current preview mode
ScaledPreviewInterface * previewInterface
Preview image.
void setZeroString(QString val)
when set, a zero string is shown instead of the current value/prefix/suffix when the slider value is ...
void getHistBoundaries(int &lumLeft, int &lumRight, int &redLeft, int &redRight, int &greenLeft, int &greenRight, int &blueLeft, int &blueRight)
returns histogram boundaries
void resetBoundaries()
resets all boundaries
void setAdjustedImage(QImage adjustedImage)
sets adjusted image and repaints
void keyPressEvent(QKeyEvent *e)
void getHistBoundaries(int &lumLeft, int &lumRight, int &redLeft, int &redRight, int &greenLeft, int &greenRight, int &blueLeft, int &blueRight)
returns histogram boundaries
QComboBox * previewSelection
void resetBrightness()
reset brightness