<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>AlbumShaper: histogramEditor.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>histogramEditor.cpp</h1><a href="histogramEditor_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//==============================================</span> <a name="l00002"></a>00002 <span class="comment">// copyright : (C) 2003-2005 by Will Stokes</span> <a name="l00003"></a>00003 <span class="comment">//==============================================</span> <a name="l00004"></a>00004 <span class="comment">// This program is free software; you can redistribute it</span> <a name="l00005"></a>00005 <span class="comment">// and/or modify it under the terms of the GNU General</span> <a name="l00006"></a>00006 <span class="comment">// Public License as published by the Free Software</span> <a name="l00007"></a>00007 <span class="comment">// Foundation; either version 2 of the License, or</span> <a name="l00008"></a>00008 <span class="comment">// (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment">//==============================================</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="comment">//Systemwide includes</span> <a name="l00012"></a>00012 <span class="preprocessor">#include <qlayout.h></span> <a name="l00013"></a>00013 <span class="preprocessor">#include <qlabel.h></span> <a name="l00014"></a>00014 <span class="preprocessor">#include <qcombobox.h></span> <a name="l00015"></a>00015 <span class="preprocessor">#include <qpushbutton.h></span> <a name="l00016"></a>00016 <span class="preprocessor">#include <qframe.h></span> <a name="l00017"></a>00017 <span class="preprocessor">#include <qslider.h></span> <a name="l00018"></a>00018 <span class="preprocessor">#include <qtooltip.h></span> <a name="l00019"></a>00019 <span class="preprocessor">#include <qsizegrip.h></span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="comment">//Projectwide includes</span> <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="histogramEditor_8h.html">histogramEditor.h</a>"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="scaledPreviewInterface_8h.html">scaledPreviewInterface.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="histogramInterface_8h.html">histogramInterface.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "../clickableLabel.h"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "../dynamicSlider.h"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "../../config.h"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "../../backend/tools/imageTools.h"</span> <a name="l00029"></a>00029 <a name="l00030"></a><a class="code" href="histogramEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">00030</a> <span class="preprocessor">#define SLIDER_RADIUS 40</span> <a name="l00031"></a>00031 <span class="preprocessor"></span> <a name="l00032"></a>00032 <span class="comment">//==============================================</span> <a name="l00033"></a><a class="code" href="classHistogramEditor.html#a0af1416cad26f3aaefb779eeca50433e">00033</a> <a class="code" href="classHistogramEditor.html#a0af1416cad26f3aaefb779eeca50433e" title="Constructs layout.">HistogramEditor::HistogramEditor</a>( QString fileName, <a class="code" href="classQWidget.html">QWidget</a> *parent, <span class="keyword">const</span> <span class="keywordtype">char</span>* name ) : <a class="code" href="classQDialog.html">QDialog</a>(parent,name,true) <a name="l00034"></a>00034 { <a name="l00035"></a>00035 <span class="comment">//set pointer to null to make sure no </span> <a name="l00036"></a>00036 <span class="comment">//random data is ever accessed by the preview interface</span> <a name="l00037"></a>00037 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a> = NULL; <a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="comment">//record filename</span> <a name="l00040"></a>00040 this->fileName = fileName; <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="comment">//-----</span> <a name="l00043"></a>00043 <span class="comment">//find mean color values</span> <a name="l00044"></a>00044 <a class="code" href="classHistogramEditor.html#a7465081e30a87e34552434d4863a15ab" title="Mean color values.">meanR</a> = 0; <a name="l00045"></a>00045 <a class="code" href="classHistogramEditor.html#a32535a647e5ff5e67b229df42b475a78">meanG</a> = 0; <a name="l00046"></a>00046 <a class="code" href="classHistogramEditor.html#a38831069b820cd8156f0df1510fba666">meanB</a> = 0; <a name="l00047"></a>00047 <span class="keywordtype">int</span> x, y; <a name="l00048"></a>00048 QRgb* rgb; <a name="l00049"></a>00049 uchar* scanLine; <a name="l00050"></a>00050 QImage image = QImage( fileName ); <a name="l00051"></a>00051 <span class="keywordflow">for</span>( y=0; y<image.height(); y++) <a name="l00052"></a>00052 { <a name="l00053"></a>00053 scanLine = image.scanLine(y); <a name="l00054"></a>00054 <span class="keywordflow">for</span>( x=0; x<image.width(); x++) <a name="l00055"></a>00055 { <a name="l00056"></a>00056 rgb = ((QRgb*)scanLine+x); <a name="l00057"></a>00057 <span class="keywordtype">double</span> r = ((double)qRed(*rgb) )/255.0; <a name="l00058"></a>00058 <span class="keywordtype">double</span> g = ((double)qGreen(*rgb) )/255.0; <a name="l00059"></a>00059 <span class="keywordtype">double</span> <a class="code" href="jpegInternal_8h.html#af320905358fa78701e4cc60b6135601f">b</a> = ((double)qBlue(*rgb) )/255.0; <a name="l00060"></a>00060 <a name="l00061"></a>00061 <a class="code" href="classHistogramEditor.html#a7465081e30a87e34552434d4863a15ab" title="Mean color values.">meanR</a>+=r; <a name="l00062"></a>00062 <a class="code" href="classHistogramEditor.html#a32535a647e5ff5e67b229df42b475a78">meanG</a>+=g; <a name="l00063"></a>00063 <a class="code" href="classHistogramEditor.html#a38831069b820cd8156f0df1510fba666">meanB</a>+=b; <a name="l00064"></a>00064 } <span class="comment">//x</span> <a name="l00065"></a>00065 } <span class="comment">//y</span> <a name="l00066"></a>00066 <a class="code" href="classHistogramEditor.html#a7465081e30a87e34552434d4863a15ab" title="Mean color values.">meanR</a> = <a class="code" href="classHistogramEditor.html#a7465081e30a87e34552434d4863a15ab" title="Mean color values.">meanR</a> / ( image.width() * image.height() ); <a name="l00067"></a>00067 <a class="code" href="classHistogramEditor.html#a32535a647e5ff5e67b229df42b475a78">meanG</a> = <a class="code" href="classHistogramEditor.html#a32535a647e5ff5e67b229df42b475a78">meanG</a> / ( image.width() * image.height() ); <a name="l00068"></a>00068 <a class="code" href="classHistogramEditor.html#a38831069b820cd8156f0df1510fba666">meanB</a> = <a class="code" href="classHistogramEditor.html#a38831069b820cd8156f0df1510fba666">meanB</a> / ( image.width() * image.height() ); <a name="l00069"></a>00069 <a name="l00070"></a>00070 <a class="code" href="classQFrame.html">QFrame</a>* visibleFrame = <span class="keyword">new</span> <a class="code" href="classQFrame.html">QFrame</a>( <span class="keyword">this</span>, <span class="stringliteral">"visible widgets"</span> ); <a name="l00071"></a>00071 <span class="comment">//-------------- </span> <a name="l00072"></a>00072 <span class="comment">//Preview frame: </span> <a name="l00073"></a>00073 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a> = <span class="keyword">new</span> <a class="code" href="classScaledPreviewInterface.html">ScaledPreviewInterface</a>( fileName, visibleFrame, <a name="l00074"></a>00074 <span class="stringliteral">"previewInterface"</span> ); <a name="l00075"></a>00075 connect( <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>, SIGNAL(resized()), <a name="l00076"></a>00076 <span class="keyword">this</span>, SLOT(<a class="code" href="classHistogramEditor.html#abafd2847c061763cd7c16bc500fe1bdd" title="updates adjusted preview image">generateAdjustedPreviewImage</a>()) ); <a name="l00077"></a>00077 <a name="l00078"></a>00078 <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a> = <span class="keyword">new</span> QComboBox( visibleFrame, <span class="stringliteral">"previewSelction"</span> ); <a name="l00079"></a>00079 <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>->insertItem( tr(<span class="stringliteral">"Split View"</span>) ); <a name="l00080"></a>00080 <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>->insertItem( tr(<span class="stringliteral">"Original Image"</span>) ); <a name="l00081"></a>00081 <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>->insertItem( tr(<span class="stringliteral">"Adjusted Image"</span>) ); <a name="l00082"></a>00082 connect( <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>, SIGNAL(activated(<span class="keywordtype">int</span>)), <span class="keyword">this</span>, SLOT(<a class="code" href="classHistogramEditor.html#a561456c67ccb364303bd70ac27e06b2a" title="updates preview image">selectPreviewImageType</a>(<span class="keywordtype">int</span>)) ); <a name="l00083"></a>00083 <span class="comment">//--------------</span> <a name="l00084"></a>00084 <span class="comment">//Adjust frame: </span> <a name="l00085"></a>00085 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a> = <span class="keyword">new</span> <a class="code" href="classHistogramInterface.html">HistogramInterface</a>( fileName, visibleFrame, <a name="l00086"></a>00086 <span class="stringliteral">"histogramInterface"</span> ); <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="comment">//connect adjustments in histogram to generateAdjustedPreviewImage</span> <a name="l00089"></a>00089 connect( <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>, SIGNAL( selectedRangeChanged() ), <a name="l00090"></a>00090 SLOT( <a class="code" href="classHistogramEditor.html#abafd2847c061763cd7c16bc500fe1bdd" title="updates adjusted preview image">generateAdjustedPreviewImage</a>() ) ); <a name="l00091"></a>00091 <a name="l00092"></a>00092 QToolTip::add( <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>, tr(<span class="stringliteral">"Click and drag to select tonal range"</span>) ); <a name="l00093"></a>00093 <a name="l00094"></a>00094 <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a> = <span class="keyword">new</span> QComboBox( visibleFrame, <span class="stringliteral">"histogramType"</span> ); <a name="l00095"></a>00095 <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>->insertItem( tr(<span class="stringliteral">"Luminosity"</span>) ); <a name="l00096"></a>00096 <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>->insertItem( tr(<span class="stringliteral">"Red"</span>) ); <a name="l00097"></a>00097 <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>->insertItem( tr(<span class="stringliteral">"Green"</span>) ); <a name="l00098"></a>00098 <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>->insertItem( tr(<span class="stringliteral">"Blue"</span>) ); <a name="l00099"></a>00099 connect( <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>, SIGNAL(activated(<span class="keywordtype">int</span>)), <span class="keyword">this</span>, SLOT(<a class="code" href="classHistogramEditor.html#a23e6a70b3f7df16aa87df3e718e99527" title="updates historgram interface">selectHistogramType</a>(<span class="keywordtype">int</span>)) ); <a name="l00100"></a>00100 QToolTip::add( <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>, tr(<span class="stringliteral">"Histogram channel displayed"</span>) ); <a name="l00101"></a>00101 <span class="comment">//--------------</span> <a name="l00102"></a>00102 <span class="comment">//Slider frame:</span> <a name="l00103"></a>00103 QString noChange = QString( tr(<span class="stringliteral">"No change"</span>) ); <a name="l00104"></a>00104 <a name="l00105"></a>00105 <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a> = <span class="keyword">new</span> <a class="code" href="classDynamicSlider.html" title="A more dynamic slider that provides moving tooltips that show the slider value.">DynamicSlider</a>( Qt::Vertical, visibleFrame ); <a name="l00106"></a>00106 <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>-><a class="code" href="classDynamicSlider.html#a750e540c9e41e4ffcc04634d3c126ebe" title="when set, a zero string is shown instead of the current value/prefix/suffix when...">setZeroString</a>( noChange ); <a name="l00107"></a>00107 <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>-><a class="code" href="classDynamicSlider.html#a3468a9997b768c4464eede49b4c2b563" title="set two prefix values, one for when the value is positive and one for when the value...">setPrefixes</a>(<span class="stringliteral">""</span>, <span class="stringliteral">"+"</span>); <a name="l00108"></a>00108 <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->setMinValue( -<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> ); <a name="l00109"></a>00109 <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->setMaxValue( <a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> ); <a name="l00110"></a>00110 connect( <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>, SIGNAL(valueChanged(<span class="keywordtype">int</span>)), <a name="l00111"></a>00111 <span class="keyword">this</span>, SLOT(<a class="code" href="classHistogramEditor.html#abafd2847c061763cd7c16bc500fe1bdd" title="updates adjusted preview image">generateAdjustedPreviewImage</a>()) );; <a name="l00112"></a>00112 QToolTip::add( <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>, tr(<span class="stringliteral">"Drag to adjust image brightness"</span>) ); <a name="l00113"></a>00113 <a name="l00114"></a>00114 <a class="code" href="classHistogramEditor.html#a2a0e73c776b754fa5471b68f7b5c9d80">brightnessIcon</a> = <span class="keyword">new</span> <a class="code" href="classClickableLabel.html" title="A clickable label.">ClickableLabel</a>( visibleFrame, <span class="stringliteral">"brightnessIcon"</span> ); <a name="l00115"></a>00115 <a class="code" href="classHistogramEditor.html#a2a0e73c776b754fa5471b68f7b5c9d80">brightnessIcon</a>-><a class="code" href="classClickableLabel.html#af6ee3b690cac8ad35b1979b4fce21460">setPixmap</a>( QPixmap(QString(<a class="code" href="config_8cpp.html#a59e02362a9a29a755712dc830a3eb513">IMAGE_PATH</a>)+<span class="stringliteral">"miscImages/brightness.png"</span>) ); <a name="l00116"></a>00116 connect( <a class="code" href="classHistogramEditor.html#a2a0e73c776b754fa5471b68f7b5c9d80">brightnessIcon</a>, SIGNAL(clicked()), SLOT(<a class="code" href="classHistogramEditor.html#af29047ba2eb64cbc3df15f585c1acb16" title="reset brightness">resetBrightness</a>()) ); <a name="l00117"></a>00117 QToolTip::add( <a class="code" href="classHistogramEditor.html#a2a0e73c776b754fa5471b68f7b5c9d80">brightnessIcon</a>, tr(<span class="stringliteral">"Reset brightness"</span>) ); <a name="l00118"></a>00118 <a name="l00119"></a>00119 <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a> = <span class="keyword">new</span> <a class="code" href="classDynamicSlider.html" title="A more dynamic slider that provides moving tooltips that show the slider value.">DynamicSlider</a>( Qt::Vertical, visibleFrame ); <a name="l00120"></a>00120 <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>-><a class="code" href="classDynamicSlider.html#a750e540c9e41e4ffcc04634d3c126ebe" title="when set, a zero string is shown instead of the current value/prefix/suffix when...">setZeroString</a>( noChange ); <a name="l00121"></a>00121 <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>-><a class="code" href="classDynamicSlider.html#a3468a9997b768c4464eede49b4c2b563" title="set two prefix values, one for when the value is positive and one for when the value...">setPrefixes</a>(<span class="stringliteral">""</span>, <span class="stringliteral">"+"</span>); <a name="l00122"></a>00122 <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->setMinValue( -<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> ); <a name="l00123"></a>00123 <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->setMaxValue( <a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> ); <a name="l00124"></a>00124 connect( <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>, SIGNAL(valueChanged(<span class="keywordtype">int</span>)), <a name="l00125"></a>00125 <span class="keyword">this</span>, SLOT(<a class="code" href="classHistogramEditor.html#abafd2847c061763cd7c16bc500fe1bdd" title="updates adjusted preview image">generateAdjustedPreviewImage</a>()) ); <a name="l00126"></a>00126 QToolTip::add( <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>, tr(<span class="stringliteral">"Drag to adjust image contrast"</span>) ); <a name="l00127"></a>00127 <a name="l00128"></a>00128 <a class="code" href="classHistogramEditor.html#aa74cba2fe4d4d1698529c032b4af4233">contrastIcon</a> = <span class="keyword">new</span> <a class="code" href="classClickableLabel.html" title="A clickable label.">ClickableLabel</a>( visibleFrame, <span class="stringliteral">"contrastIcon"</span> ); <a name="l00129"></a>00129 <a class="code" href="classHistogramEditor.html#aa74cba2fe4d4d1698529c032b4af4233">contrastIcon</a>-><a class="code" href="classClickableLabel.html#af6ee3b690cac8ad35b1979b4fce21460">setPixmap</a>( QPixmap(QString(<a class="code" href="config_8cpp.html#a59e02362a9a29a755712dc830a3eb513">IMAGE_PATH</a>)+<span class="stringliteral">"miscImages/contrast.png"</span>) ); <a name="l00130"></a>00130 connect( <a class="code" href="classHistogramEditor.html#aa74cba2fe4d4d1698529c032b4af4233">contrastIcon</a>, SIGNAL(clicked()), SLOT(<a class="code" href="classHistogramEditor.html#a04de16886597eb3907140c7c7db7ddeb" title="reset contrast">resetContrast</a>()) ); <a name="l00131"></a>00131 QToolTip::add( <a class="code" href="classHistogramEditor.html#aa74cba2fe4d4d1698529c032b4af4233">contrastIcon</a>, tr(<span class="stringliteral">"Reset contrast"</span>) ); <a name="l00132"></a>00132 <span class="comment">//--------------</span> <a name="l00133"></a>00133 <span class="comment">//Dialog buttons: </span> <a name="l00134"></a>00134 <a class="code" href="classHistogramEditor.html#ac10565d1a164dd060d0e0b04cf9fc378">buttonsFrame</a> = <span class="keyword">new</span> <a class="code" href="classQFrame.html">QFrame</a>( visibleFrame, <span class="stringliteral">"dialogButtons"</span> ); <a name="l00135"></a>00135 <a name="l00136"></a>00136 QPushButton* applyButton = <span class="keyword">new</span> QPushButton( tr(<span class="stringliteral">"Apply"</span>), <a class="code" href="classHistogramEditor.html#ac10565d1a164dd060d0e0b04cf9fc378">buttonsFrame</a> ); <a name="l00137"></a>00137 applyButton->setDefault(<span class="keyword">true</span>); <a name="l00138"></a>00138 applyButton->setFocus(); <a name="l00139"></a>00139 connect( applyButton, SIGNAL(clicked()), SLOT(<a class="code" href="classHistogramEditor.html#a14ff05c81910e9f41a43c45abb07606a" title="check for changes to settings, if so">applyAction</a>()) ); <a name="l00140"></a>00140 <a name="l00141"></a>00141 QPushButton* cancelButton = <span class="keyword">new</span> QPushButton( tr(<span class="stringliteral">"Cancel"</span>), <a class="code" href="classHistogramEditor.html#ac10565d1a164dd060d0e0b04cf9fc378">buttonsFrame</a> ); <a name="l00142"></a>00142 connect( cancelButton, SIGNAL(clicked()), SLOT(reject()) ); <a name="l00143"></a>00143 <a name="l00144"></a>00144 QPushButton* resetButton = <span class="keyword">new</span> QPushButton( tr(<span class="stringliteral">"Reset"</span>), <a class="code" href="classHistogramEditor.html#ac10565d1a164dd060d0e0b04cf9fc378">buttonsFrame</a> ); <a name="l00145"></a>00145 connect( resetButton, SIGNAL(clicked()), SLOT(<a class="code" href="classHistogramEditor.html#a1ae27f41de269b4b51104a31295c2d1e" title="resets all adjustments">resetAction</a>()) ); <a name="l00146"></a>00146 <a name="l00147"></a>00147 QGridLayout* buttonsGrid = <span class="keyword">new</span> QGridLayout( <a class="code" href="classHistogramEditor.html#ac10565d1a164dd060d0e0b04cf9fc378">buttonsFrame</a>, 1, 5, 0 ); <a name="l00148"></a>00148 buttonsGrid->setColStretch( 0, 1 ); <a name="l00149"></a>00149 buttonsGrid->addWidget( applyButton, 0, 1 ); <a name="l00150"></a>00150 buttonsGrid->addWidget( cancelButton, 0, 2 ); <a name="l00151"></a>00151 buttonsGrid->addWidget( resetButton, 0, 3 ); <a name="l00152"></a>00152 buttonsGrid->setColStretch( 4, 1 ); <a name="l00153"></a>00153 buttonsGrid->setSpacing( <a class="code" href="config_8h.html#a07d364596a27705c900f07340515d5db">WIDGET_SPACING</a> ); <a name="l00154"></a>00154 <span class="comment">//--------------</span> <a name="l00155"></a>00155 QGridLayout* mainGrid = <span class="keyword">new</span> QGridLayout( visibleFrame, 5, 3, 0 ); <a name="l00156"></a>00156 <a name="l00157"></a>00157 mainGrid->addMultiCellWidget( <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>, 0,0, 0,2 ); <a name="l00158"></a>00158 mainGrid->addMultiCellWidget( <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>, 1,1, 0,2, Qt::AlignHCenter ); <a name="l00159"></a>00159 <a name="l00160"></a>00160 mainGrid->addWidget( <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>, 2, 0 ); <a name="l00161"></a>00161 mainGrid->addWidget( <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>, 2, 1 ); <a name="l00162"></a>00162 mainGrid->addWidget( <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>, 2, 2 ); <a name="l00163"></a>00163 <a name="l00164"></a>00164 <span class="comment">//make sure sliders have enough space so all slider units are settable</span> <a name="l00165"></a>00165 mainGrid->setRowSpacing( 2, 2*<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> + 5) ; <a name="l00166"></a>00166 <a name="l00167"></a>00167 mainGrid->addWidget( <a class="code" href="classHistogramEditor.html#ab476a3eea3a146149ec7bba4a4878399">histogramType</a>, 3, 0, Qt::AlignHCenter ); <a name="l00168"></a>00168 mainGrid->addWidget( <a class="code" href="classHistogramEditor.html#a2a0e73c776b754fa5471b68f7b5c9d80">brightnessIcon</a>, 3, 1 ); <a name="l00169"></a>00169 mainGrid->addWidget( <a class="code" href="classHistogramEditor.html#aa74cba2fe4d4d1698529c032b4af4233">contrastIcon</a>, 3, 2 ); <a name="l00170"></a>00170 <a name="l00171"></a>00171 mainGrid->addMultiCellWidget( <a class="code" href="classHistogramEditor.html#ac10565d1a164dd060d0e0b04cf9fc378">buttonsFrame</a>, 4,4, 0,2 ); <a name="l00172"></a>00172 <a name="l00173"></a>00173 mainGrid->setRowStretch( 0, 1 ); <a name="l00174"></a>00174 mainGrid->setColStretch( 0, 1 ); <a name="l00175"></a>00175 <a name="l00176"></a>00176 mainGrid->setSpacing( <a class="code" href="config_8h.html#a07d364596a27705c900f07340515d5db">WIDGET_SPACING</a> ); <a name="l00177"></a>00177 mainGrid->setMargin( <a class="code" href="config_8h.html#a07d364596a27705c900f07340515d5db">WIDGET_SPACING</a> ); <a name="l00178"></a>00178 <a name="l00179"></a>00179 QGridLayout* invisibleGrid = <span class="keyword">new</span> QGridLayout( <span class="keyword">this</span>, 2, 1, 0 ); <a name="l00180"></a>00180 invisibleGrid->addWidget( visibleFrame, 0, 0 ); <a name="l00181"></a>00181 invisibleGrid->setRowStretch( 0, 1 ); <a name="l00182"></a>00182 <a name="l00183"></a>00183 <span class="comment">//PLATFORM_SPECIFIC_CODE</span> <a name="l00184"></a>00184 <span class="comment">//windows users expect a grip, but qt doesn't put one in by default. we'll add</span> <a name="l00185"></a>00185 <span class="comment">//it for them too. :-)</span> <a name="l00186"></a>00186 <span class="preprocessor">#if defined(Q_OS_WIN)</span> <a name="l00187"></a>00187 <span class="preprocessor"></span> QSizeGrip* sizeGrip = <span class="keyword">new</span> QSizeGrip( <span class="keyword">this</span> ); <a name="l00188"></a>00188 invisibleGrid->addWidget( sizeGrip, 1, 0, Qt::AlignRight | Qt::AlignBottom ); <a name="l00189"></a>00189 <span class="preprocessor">#endif</span> <a name="l00190"></a>00190 <span class="preprocessor"></span> <a name="l00191"></a>00191 <a name="l00192"></a>00192 <a name="l00193"></a>00193 <a name="l00194"></a>00194 <span class="comment">//Window caption</span> <a name="l00195"></a>00195 setCaption( tr(<span class="stringliteral">"Histogram Editor"</span>) ); <a name="l00196"></a>00196 <span class="comment">//-------------------------------</span> <a name="l00197"></a>00197 } <a name="l00198"></a>00198 <span class="comment">//==============================================</span> <a name="l00199"></a><a class="code" href="classHistogramEditor.html#a2135b9e57008236be5d278674f9c8bbe">00199</a> <a class="code" href="classHistogramEditor.html#a2135b9e57008236be5d278674f9c8bbe">HistogramEditor::~HistogramEditor</a>() { } <a name="l00200"></a>00200 <span class="comment">//==============================================</span> <a name="l00201"></a><a class="code" href="classHistogramEditor.html#a14ff05c81910e9f41a43c45abb07606a">00201</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a14ff05c81910e9f41a43c45abb07606a" title="check for changes to settings, if so">HistogramEditor::applyAction</a>() <a name="l00202"></a>00202 { <a name="l00203"></a>00203 <span class="comment">//check if user has adjusted brightness, contrast, or histogram ranges.</span> <a name="l00204"></a>00204 <span class="comment">//if any changes have taken place call "accept", else "reject" so image is not</span> <a name="l00205"></a>00205 <span class="comment">//updated and appear modified</span> <a name="l00206"></a>00206 <span class="keywordtype">int</span> lumLeft, lumRight, redLeft, redRight, greenLeft, greenRight, blueLeft, blueRight; <a name="l00207"></a>00207 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>-><a class="code" href="classHistogramInterface.html#ace352a748cf063b12cd22d54f1460680" title="returns histogram boundaries">getHistBoundaries</a>( lumLeft, lumRight, <a name="l00208"></a>00208 redLeft, redRight, <a name="l00209"></a>00209 greenLeft, greenRight, <a name="l00210"></a>00210 blueLeft, blueRight ); <a name="l00211"></a>00211 <span class="keywordflow">if</span>( <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->value() != 0 || <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->value() != 0 || <a name="l00212"></a>00212 lumLeft != 0 || lumRight != 255 || <a name="l00213"></a>00213 redLeft !=0 || redRight != 255 || <a name="l00214"></a>00214 greenLeft != 0 || greenRight != 255 || <a name="l00215"></a>00215 blueLeft != 0 || blueRight != 255 ) <a name="l00216"></a>00216 { accept(); } <a name="l00217"></a>00217 <span class="keywordflow">else</span> <a name="l00218"></a>00218 { reject(); } <a name="l00219"></a>00219 } <a name="l00220"></a>00220 <span class="comment">//==============================================</span> <a name="l00221"></a><a class="code" href="classHistogramEditor.html#a1ae27f41de269b4b51104a31295c2d1e">00221</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a1ae27f41de269b4b51104a31295c2d1e" title="resets all adjustments">HistogramEditor::resetAction</a>() <a name="l00222"></a>00222 { <a name="l00223"></a>00223 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>-><a class="code" href="classHistogramInterface.html#aa50e91749fffe828524ae0248f66b4d5" title="resets all boundaries">resetBoundaries</a>(); <a name="l00224"></a>00224 <a class="code" href="classHistogramEditor.html#af29047ba2eb64cbc3df15f585c1acb16" title="reset brightness">resetBrightness</a>(); <a name="l00225"></a>00225 <a class="code" href="classHistogramEditor.html#a04de16886597eb3907140c7c7db7ddeb" title="reset contrast">resetContrast</a>(); <a name="l00226"></a>00226 } <a name="l00227"></a>00227 <span class="comment">//==============================================</span> <a name="l00228"></a><a class="code" href="classHistogramEditor.html#a620d6a6f5d7165dffced1f695dead40f">00228</a> QImage* <a class="code" href="classHistogramEditor.html#a620d6a6f5d7165dffced1f695dead40f" title="get modified image that resulted from adjustments">HistogramEditor::getModifiedImage</a>() <a name="l00229"></a>00229 { <a name="l00230"></a>00230 QImage* adjustedImage = <span class="keyword">new</span> QImage(<a class="code" href="classHistogramEditor.html#a9ceb548284f1b20acfa1bff16865f5a8">fileName</a>); <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">//convert to 32-bit depth if necessary</span> <a name="l00233"></a>00233 <span class="keywordflow">if</span>( adjustedImage->depth() < 32 ) <a name="l00234"></a>00234 { <a name="l00235"></a>00235 QImage* tmp = adjustedImage; <a name="l00236"></a>00236 adjustedImage = <span class="keyword">new</span> QImage( tmp->convertDepth( 32, Qt::AutoColor ) ); <a name="l00237"></a>00237 <span class="keyword">delete</span> tmp; tmp=NULL; <a name="l00238"></a>00238 } <a name="l00239"></a>00239 <a name="l00240"></a>00240 <a class="code" href="classHistogramEditor.html#a84e9f69ff2889a4baaf2d8e620a36554">adjustImage</a>( *adjustedImage ); <a name="l00241"></a>00241 <span class="keywordflow">return</span> adjustedImage; <a name="l00242"></a>00242 } <a name="l00243"></a>00243 <span class="comment">//==============================================</span> <a name="l00244"></a><a class="code" href="classHistogramEditor.html#a561456c67ccb364303bd70ac27e06b2a">00244</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a561456c67ccb364303bd70ac27e06b2a" title="updates preview image">HistogramEditor::selectPreviewImageType</a>( <span class="keywordtype">int</span> selection ) <a name="l00245"></a>00245 { <a name="l00246"></a>00246 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#ae6cd0c9f1fb64b0313063f59aa748943" title="Sets preview mode.">setPreviewMode</a>( (<a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80" title="current preview mode">PREVIEW_MODE</a>)selection ); <a name="l00247"></a>00247 } <a name="l00248"></a>00248 <span class="comment">//==============================================</span> <a name="l00249"></a><a class="code" href="classHistogramEditor.html#a23e6a70b3f7df16aa87df3e718e99527">00249</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a23e6a70b3f7df16aa87df3e718e99527" title="updates historgram interface">HistogramEditor::selectHistogramType</a>( <span class="keywordtype">int</span> selection ) <a name="l00250"></a>00250 { <a name="l00251"></a>00251 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>-><a class="code" href="classHistogramInterface.html#a84ee87d1cc494c965375266d24adfd85" title="Sets currently displayed channel.">setDisplayChannel</a>( (<a class="code" href="histogramInterface_8h.html#a435afa8a7ae5dd59e451491c9e221c8c" title="chanel histogram displays">DISPLAYED_CHANNEL</a>) selection ); <a name="l00252"></a>00252 } <a name="l00253"></a>00253 <span class="comment">//==============================================</span> <a name="l00254"></a><a class="code" href="classHistogramEditor.html#af29047ba2eb64cbc3df15f585c1acb16">00254</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#af29047ba2eb64cbc3df15f585c1acb16" title="reset brightness">HistogramEditor::resetBrightness</a>() <a name="l00255"></a>00255 { <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->setValue( 0 ); } <a name="l00256"></a>00256 <span class="comment">//==============================================</span> <a name="l00257"></a><a class="code" href="classHistogramEditor.html#a04de16886597eb3907140c7c7db7ddeb">00257</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a04de16886597eb3907140c7c7db7ddeb" title="reset contrast">HistogramEditor::resetContrast</a>() <a name="l00258"></a>00258 { <a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->setValue( 0 ); } <a name="l00259"></a>00259 <span class="comment">//==============================================</span> <a name="l00260"></a><a class="code" href="classHistogramEditor.html#a7e426c0dc30a2823b42fa8546063af46">00260</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a7e426c0dc30a2823b42fa8546063af46" title="returns histogram boundaries">HistogramEditor::getHistBoundaries</a>(<span class="keywordtype">int</span> &lumLeft, <span class="keywordtype">int</span> &lumRight, <a name="l00261"></a>00261 <span class="keywordtype">int</span> &redLeft, <span class="keywordtype">int</span> &redRight, <a name="l00262"></a>00262 <span class="keywordtype">int</span> &greenLeft, <span class="keywordtype">int</span> &greenRight, <a name="l00263"></a>00263 <span class="keywordtype">int</span> &blueLeft, <span class="keywordtype">int</span> &blueRight) <a name="l00264"></a>00264 { <a name="l00265"></a>00265 <span class="comment">//sanity check</span> <a name="l00266"></a>00266 <span class="keywordflow">if</span>( <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a> ) <a name="l00267"></a>00267 { <a name="l00268"></a>00268 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>-><a class="code" href="classHistogramInterface.html#ace352a748cf063b12cd22d54f1460680" title="returns histogram boundaries">getHistBoundaries</a>( lumLeft, lumRight, <a name="l00269"></a>00269 redLeft, redRight, <a name="l00270"></a>00270 greenLeft, greenRight, <a name="l00271"></a>00271 blueLeft, blueRight ); <a name="l00272"></a>00272 } <a name="l00273"></a>00273 <span class="keywordflow">else</span> <a name="l00274"></a>00274 { <a name="l00275"></a>00275 lumLeft = 0; lumRight = 255; <a name="l00276"></a>00276 redLeft = 0; redRight = 255; <a name="l00277"></a>00277 greenLeft = 0; greenRight = 255; <a name="l00278"></a>00278 blueLeft = 0; blueRight = 255; <a name="l00279"></a>00279 } <a name="l00280"></a>00280 } <a name="l00281"></a>00281 <span class="comment">//==============================================</span> <a name="l00282"></a><a class="code" href="classHistogramEditor.html#abafd2847c061763cd7c16bc500fe1bdd">00282</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#abafd2847c061763cd7c16bc500fe1bdd" title="updates adjusted preview image">HistogramEditor::generateAdjustedPreviewImage</a>() <a name="l00283"></a>00283 { <a name="l00284"></a>00284 <span class="comment">//get original image</span> <a name="l00285"></a>00285 QImage origImage = <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#a7139f30dcf4faa4afa1fa837334a088d" title="returns orig image object">getOrigImage</a>(); <a name="l00286"></a>00286 <a name="l00287"></a>00287 <span class="comment">//construct adjusted image</span> <a name="l00288"></a>00288 QImage adjustedImage = origImage.copy(); <a name="l00289"></a>00289 <a class="code" href="classHistogramEditor.html#a84e9f69ff2889a4baaf2d8e620a36554">adjustImage</a>( adjustedImage ); <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="comment">//set adjusted image</span> <a name="l00292"></a>00292 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#ad7328bc93d69a28310a23d9294ec29d7" title="sets adjusted image and repaints">setAdjustedImage</a>( adjustedImage ); <a name="l00293"></a>00293 } <a name="l00294"></a>00294 <span class="comment">//==============================================</span> <a name="l00295"></a><a class="code" href="classHistogramEditor.html#a84e9f69ff2889a4baaf2d8e620a36554">00295</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a84e9f69ff2889a4baaf2d8e620a36554">HistogramEditor::adjustImage</a>( QImage &image ) <a name="l00296"></a>00296 { <a name="l00297"></a>00297 <span class="comment">//obtain histogram left and right boundaries</span> <a name="l00298"></a>00298 <span class="comment">//sanity check</span> <a name="l00299"></a>00299 <span class="keywordtype">int</span> lumLeft, lumRight, redLeft, redRight, greenLeft, greenRight, blueLeft, blueRight; <a name="l00300"></a>00300 <span class="keywordflow">if</span>( <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a> ) <a name="l00301"></a>00301 { <a name="l00302"></a>00302 <a class="code" href="classHistogramEditor.html#a6caaa3aada0953fec4c1329d94737cef" title="Histogram view.">histogramInterface</a>-><a class="code" href="classHistogramInterface.html#ace352a748cf063b12cd22d54f1460680" title="returns histogram boundaries">getHistBoundaries</a>( lumLeft, lumRight, <a name="l00303"></a>00303 redLeft, redRight, <a name="l00304"></a>00304 greenLeft, greenRight, <a name="l00305"></a>00305 blueLeft, blueRight ); <a name="l00306"></a>00306 } <a name="l00307"></a>00307 <span class="keywordflow">else</span> <a name="l00308"></a>00308 { <a name="l00309"></a>00309 lumLeft = 0; lumRight = 255; <a name="l00310"></a>00310 redLeft = 0; redRight = 255; <a name="l00311"></a>00311 greenLeft = 0; greenRight = 255; <a name="l00312"></a>00312 blueLeft = 0; blueRight = 255; <a name="l00313"></a>00313 } <a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="comment">//modify image</span> <a name="l00316"></a>00316 <span class="keywordtype">double</span> displayToOneScalar = 1.0/255.0; <a name="l00317"></a>00317 <span class="keywordtype">double</span> scaledMeanR = displayToOneScalar*<a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( 255.0*<a class="code" href="classHistogramEditor.html#a7465081e30a87e34552434d4863a15ab" title="Mean color values.">meanR</a>, redLeft, redRight ); <a name="l00318"></a>00318 <span class="keywordtype">double</span> scaledMeanG = displayToOneScalar*<a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( 255.0*<a class="code" href="classHistogramEditor.html#a32535a647e5ff5e67b229df42b475a78">meanG</a>, greenLeft, greenRight ); <a name="l00319"></a>00319 <span class="keywordtype">double</span> scaledMeanB = displayToOneScalar*<a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( 255.0*<a class="code" href="classHistogramEditor.html#a38831069b820cd8156f0df1510fba666">meanB</a>, blueLeft, blueRight ); <a name="l00320"></a>00320 <a name="l00321"></a>00321 <span class="keywordtype">double</span> brightnessScalar, addedBrightnessColor; <a name="l00322"></a>00322 <span class="keywordflow">if</span>(<a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->value() < 0) <a name="l00323"></a>00323 { <a name="l00324"></a>00324 brightnessScalar = ((double)(<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> + <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->value()))/<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a>; <a name="l00325"></a>00325 addedBrightnessColor = 1.0 - brightnessScalar; <a name="l00326"></a>00326 } <a name="l00327"></a>00327 <span class="keywordflow">else</span> <a name="l00328"></a>00328 { <a name="l00329"></a>00329 brightnessScalar = ((double)(<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> - <a class="code" href="classHistogramEditor.html#a9f4cfe8de5107624f038d82c5b35b637" title="Brightness slider.">brightness</a>->value()))/<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a>; <a name="l00330"></a>00330 addedBrightnessColor = 0.0; <a name="l00331"></a>00331 } <a name="l00332"></a>00332 <a name="l00333"></a>00333 <span class="keywordtype">int</span> x, y; <a name="l00334"></a>00334 QRgb* rgb; <a name="l00335"></a>00335 <span class="keywordtype">double</span> r,g,<a class="code" href="jpegInternal_8h.html#af320905358fa78701e4cc60b6135601f">b</a>; <a name="l00336"></a>00336 <span class="keywordtype">double</span> h,s,v; <a name="l00337"></a>00337 <span class="keywordtype">int</span> rPrime, gPrime, bPrime; <a name="l00338"></a>00338 uchar* scanLine; <a name="l00339"></a>00339 <a name="l00340"></a>00340 <span class="keywordflow">for</span>( y=0; y<image.height(); y++) <a name="l00341"></a>00341 { <a name="l00342"></a>00342 scanLine = image.scanLine(y); <a name="l00343"></a>00343 <span class="keywordflow">for</span>( x=0; x<image.width(); x++) <a name="l00344"></a>00344 { <a name="l00345"></a>00345 <span class="comment">//get rgb value</span> <a name="l00346"></a>00346 rgb = ((QRgb*)scanLine+x); <a name="l00347"></a>00347 r = qRed(*rgb); <a name="l00348"></a>00348 g = qGreen(*rgb); <a name="l00349"></a>00349 b = qBlue(*rgb); <a name="l00350"></a>00350 <a name="l00351"></a>00351 <span class="comment">//apply histogram boundaries</span> <a name="l00352"></a>00352 <a class="code" href="imageTools_8cpp.html#a7769c25727d6caedf20321d238b3828d" title="Convert a RGB color triplet to HSV.">RGBtoHSV</a>(r,g,b,&h,&s,&v); <a name="l00353"></a>00353 v = <a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( v, lumLeft, lumRight ); <a name="l00354"></a>00354 <a class="code" href="imageTools_8cpp.html#aa4ea508b635b1a7648bb5834132d4681" title="Convert a HSV color triplet to RGB.">HSVtoRGB</a>( &r,&g,&b, h,s,v); <a name="l00355"></a>00355 <a name="l00356"></a>00356 r = <a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( r, redLeft, redRight ); <a name="l00357"></a>00357 g = <a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( g, greenLeft, greenRight ); <a name="l00358"></a>00358 b = <a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">scaleColor</a>( b, blueLeft, blueRight ); <a name="l00359"></a>00359 <a name="l00360"></a>00360 <span class="comment">//convert to 0-1 scale</span> <a name="l00361"></a>00361 r = r*displayToOneScalar; <a name="l00362"></a>00362 g = g*displayToOneScalar; <a name="l00363"></a>00363 b = b*displayToOneScalar; <a name="l00364"></a>00364 <a name="l00365"></a>00365 <span class="comment">//adjust contrast</span> <a name="l00366"></a>00366 r = ( (r-scaledMeanR) * (<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a>-<a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->value()) )/<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> + scaledMeanR; <a name="l00367"></a>00367 g = ( (g-scaledMeanG) * (<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a>-<a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->value()) )/<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> + scaledMeanG; <a name="l00368"></a>00368 b = ( (b-scaledMeanB) * (<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a>-<a class="code" href="classHistogramEditor.html#a2628052b95734019ed8bd3d5cf084b22" title="Contrast slider.">contrast</a>->value()) )/<a class="code" href="grainEditor_8cpp.html#a4ded029c11c97d844b3bab790eeae2af">SLIDER_RADIUS</a> + scaledMeanB; <a name="l00369"></a>00369 <a name="l00370"></a>00370 <span class="comment">//apply brightness adjustment</span> <a name="l00371"></a>00371 <span class="comment">//http://www.sgi.com/misc/grafica/interp/</span> <a name="l00372"></a>00372 r = brightnessScalar*r + addedBrightnessColor; <a name="l00373"></a>00373 g = brightnessScalar*g + addedBrightnessColor; <a name="l00374"></a>00374 b = brightnessScalar*b + addedBrightnessColor; <a name="l00375"></a>00375 <a name="l00376"></a>00376 <span class="comment">//scale and clamp to 0-255 range</span> <a name="l00377"></a>00377 rPrime = (int) QMIN( QMAX((r*255), 0), 255 ); <a name="l00378"></a>00378 gPrime = (int) QMIN( QMAX((g*255), 0), 255 ); <a name="l00379"></a>00379 bPrime = (int) QMIN( QMAX((b*255), 0), 255 ); <a name="l00380"></a>00380 <a name="l00381"></a>00381 <span class="comment">//set adjusted color value</span> <a name="l00382"></a>00382 *rgb = qRgb(rPrime, gPrime, bPrime); <a name="l00383"></a>00383 } <span class="comment">//x</span> <a name="l00384"></a>00384 } <span class="comment">//y </span> <a name="l00385"></a>00385 } <a name="l00386"></a>00386 <span class="comment">//==============================================</span> <a name="l00387"></a><a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">00387</a> <span class="keywordtype">double</span> <a class="code" href="classHistogramEditor.html#aef547637cba09d72bbb8769a5012992f">HistogramEditor::scaleColor</a>( <span class="keywordtype">double</span> color, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> right ) <a name="l00388"></a>00388 { <a name="l00389"></a>00389 <span class="keywordflow">return</span> QMAX( QMIN( (255.0*(color-left)) / (right-left), 255), 0 ); <a name="l00390"></a>00390 } <a name="l00391"></a>00391 <span class="comment">//==============================================</span> <a name="l00392"></a><a class="code" href="classHistogramEditor.html#a1762e200233db3b9d0e110b67c6fd542">00392</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a1762e200233db3b9d0e110b67c6fd542">HistogramEditor::keyPressEvent</a>(QKeyEvent *e) <a name="l00393"></a>00393 { <a name="l00394"></a>00394 <span class="keywordflow">if</span>(e->key() == Qt::Key_Control ) <a name="l00395"></a>00395 { <a name="l00396"></a>00396 <a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80" title="current preview mode">PREVIEW_MODE</a> curMode = (<a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80" title="current preview mode">PREVIEW_MODE</a>) <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>->currentItem(); <a name="l00397"></a>00397 <span class="keywordflow">if</span>(curMode == <a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80a4b0845a3961eed793f478ae334aad65d">ORIGINAL_IMAGE</a>) <a name="l00398"></a>00398 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#ae6cd0c9f1fb64b0313063f59aa748943" title="Sets preview mode.">setPreviewMode</a>( <a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80ae5a5e7966f92d18ce66136439e1303bd">ADJUSTED_IMAGE</a>, <span class="keyword">true</span> ); <a name="l00399"></a>00399 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(curMode == <a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80ae5a5e7966f92d18ce66136439e1303bd">ADJUSTED_IMAGE</a>) <a name="l00400"></a>00400 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#ae6cd0c9f1fb64b0313063f59aa748943" title="Sets preview mode.">setPreviewMode</a>( <a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80a4b0845a3961eed793f478ae334aad65d">ORIGINAL_IMAGE</a>, <span class="keyword">true</span> ); <a name="l00401"></a>00401 <span class="keywordflow">else</span> <a name="l00402"></a>00402 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#ae6cd0c9f1fb64b0313063f59aa748943" title="Sets preview mode.">setPreviewMode</a>( <a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80af94a0ed6eca377f0937a43f5b9f29c9d">INV_SPLIT_VIEW</a> ); <a name="l00403"></a>00403 } <a name="l00404"></a>00404 <span class="keywordflow">else</span> { <a class="code" href="classHistogramEditor.html#a1762e200233db3b9d0e110b67c6fd542">QDialog::keyPressEvent</a>(e); } <a name="l00405"></a>00405 } <a name="l00406"></a>00406 <span class="comment">//==============================================</span> <a name="l00407"></a><a class="code" href="classHistogramEditor.html#a66c1f2cf3030b472f58dc3ce26946a50">00407</a> <span class="keywordtype">void</span> <a class="code" href="classHistogramEditor.html#a66c1f2cf3030b472f58dc3ce26946a50">HistogramEditor::keyReleaseEvent</a>(QKeyEvent *e) <a name="l00408"></a>00408 { <a name="l00409"></a>00409 <span class="keywordflow">if</span>(e->key() == Qt::Key_Control ) <a name="l00410"></a>00410 { <a name="l00411"></a>00411 <a class="code" href="classHistogramEditor.html#ac3cefbf518300bd46401606802584b57" title="Preview image.">previewInterface</a>-><a class="code" href="classSplitViewInterface.html#ae6cd0c9f1fb64b0313063f59aa748943" title="Sets preview mode.">setPreviewMode</a>( (<a class="code" href="splitViewInterface_8h.html#aa4478246983e5a13f84754204fb5ab80" title="current preview mode">PREVIEW_MODE</a>) <a class="code" href="classHistogramEditor.html#a16747259c09a2c24d59b396ac63dc588">previewSelection</a>->currentItem(), <a name="l00412"></a>00412 false ); <a name="l00413"></a>00413 } <a name="l00414"></a>00414 <span class="keywordflow">else</span> { <a class="code" href="classHistogramEditor.html#a66c1f2cf3030b472f58dc3ce26946a50">QDialog::keyReleaseEvent</a>(e); } <a name="l00415"></a>00415 } <a name="l00416"></a>00416 <span class="comment">//==============================================</span> <a name="l00417"></a>00417 <a name="l00418"></a>00418 </pre></div></div> <hr size="1"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address> </body> </html>