This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
QImage * | improveColorBalance (QString filename, StatusWidget *status) |
|
Definition at line 21 of file color.cpp. References b, editedImage, StatusWidget::incrementProgress(), newProgress, StatusWidget::setStatus(), StatusWidget::showProgressBar(), status, and updateIncrement. Referenced by EditingInterface::colorBalance(). 00022 { 00023 //load original image 00024 QImage* editedImage = new QImage( filename ); 00025 00026 //setup progress bar 00027 QString statusMessage = qApp->translate( "improveColorBalance", "Enhancing Color Balance:" ); 00028 status->showProgressBar( statusMessage, 100 ); 00029 qApp->processEvents(); 00030 00031 //update progress bar for every 1% of completion 00032 const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() ); 00033 int newProgress = 0; 00034 00035 //construct intensity histographs for each color channel 00036 int redVals[256]; 00037 int greenVals[256]; 00038 int blueVals[256]; 00039 int i=0; 00040 for(i=0; i<256; i++) 00041 { 00042 redVals[i] = 0; 00043 greenVals[i] = 0; 00044 blueVals[i] = 0; 00045 } 00046 00047 //populate histogram by iterating over all image pixels 00048 int numPixels = editedImage->width()*editedImage->height(); 00049 QRgb* rgb; 00050 uchar* scanLine; 00051 int x, y; 00052 for( y=0; y<editedImage->height(); y++) 00053 { 00054 //iterate over each selected pixel in scanline 00055 scanLine = editedImage->scanLine(y); 00056 for( x=0; x<editedImage->width(); x++) 00057 { 00058 rgb = ((QRgb*)scanLine+x); 00059 redVals[qRed(*rgb)]++; 00060 greenVals[qGreen(*rgb)]++; 00061 blueVals[qBlue(*rgb)]++; 00062 } //for x 00063 } //for y 00064 00065 //find 1% and 99% precenticles 00066 //we'll stretch these values so we avoid outliers from affecting the stretch 00067 int sumR=0; 00068 int sumG=0; 00069 int sumB=0; 00070 int indexLowR, indexHighR; 00071 int indexLowG, indexHighG; 00072 int indexLowB, indexHighB; 00073 indexLowR = -1; indexHighR = -1; 00074 indexLowG = -1; indexHighG = -1; 00075 indexLowB = -1; indexHighB = -1; 00076 for(i=0; i<256; i++) 00077 { 00078 sumR+=redVals[i]; 00079 sumG+=greenVals[i]; 00080 sumB+=blueVals[i]; 00081 00082 //if 1% not found yet and criteria met set index 00083 if(indexLowR < 0 && sumR >= 0.01*numPixels) 00084 { indexLowR = i; } 00085 if(indexLowG < 0 && sumG >= 0.01*numPixels) 00086 { indexLowG = i; } 00087 if(indexLowB < 0 && sumB >= 0.01*numPixels) 00088 { indexLowB = i; } 00089 00090 //if 99% not found yet and criteria met set index 00091 if(indexHighR < 0 && sumR >= 0.99*numPixels) 00092 { indexHighR = i; } 00093 if(indexHighG < 0 && sumG >= 0.99*numPixels) 00094 { indexHighG = i; } 00095 if(indexHighB < 0 && sumB >= 0.99*numPixels) 00096 { indexHighB = i; } 00097 } 00098 00099 //run through all image pixels a second time, this time scaling coordinates as necessary 00100 for( y=0; y<editedImage->height(); y++) 00101 { 00102 //iterate over each selected pixel in scanline 00103 scanLine = editedImage->scanLine(y); 00104 for( x=0; x<editedImage->width(); x++) 00105 { 00106 //get color coordinates and convert to 0-1 scale 00107 rgb = ((QRgb*)scanLine+x); 00108 double r = ((double)qRed(*rgb) ); 00109 double g = ((double)qGreen(*rgb) ); 00110 double b = ((double)qBlue(*rgb) ); 00111 00112 if(indexHighR != indexLowR) { r = (255*(r-indexLowR))/(indexHighR-indexLowR); } 00113 if(indexHighG != indexLowG) { g = (255*(g-indexLowG))/(indexHighG-indexLowG); } 00114 if(indexHighB != indexLowB) { b = (255*(b-indexLowB))/(indexHighB-indexLowB); } 00115 00116 int rp = (int) QMIN( QMAX(r, 0), 255 ); 00117 int gp = (int) QMIN( QMAX(g, 0), 255 ); 00118 int bp = (int) QMIN( QMAX(b, 0), 255 ); 00119 00120 //set adjusted color value 00121 *rgb = qRgb(rp,gp,bp); 00122 00123 //update status bar if significant progress has been made since last update 00124 newProgress++; 00125 if(newProgress >= updateIncrement) 00126 { 00127 newProgress = 0; 00128 status->incrementProgress(); 00129 qApp->processEvents(); 00130 } 00131 00132 } //for x 00133 } //for y 00134 00135 //remove status bar 00136 status->setStatus( "" ); 00137 qApp->processEvents(); 00138 00139 //return pointer to edited image 00140 return editedImage; 00141 }
|