• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

conbridlg.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           conbridlg.h  -  Contrast/Brightness Dialog
00003                              -------------------
00004     begin                : Fri Feb 6th 2004
00005     copyright            : (C) 2004 by Jasem Mutlaq
00006     email                : mutlaqja@ikarustech.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *                                         *
00017  ***************************************************************************/
00018  
00019  #include <klocale.h>
00020  #include <kimageeffect.h> 
00021  #include <kdebug.h>
00022  
00023  #include <qslider.h>
00024  #include <qimage.h>
00025  #include <qdatetime.h>
00026  #include <knuminput.h>
00027  
00028  #include <stdlib.h>
00029  
00030  #include "contrastbrightnessgui.h"
00031  #include "conbridlg.h"
00032  #include "fitsviewer.h"
00033  #include "fitsimage.h"
00034  
00035  #define REFRESH 500
00036  
00037 //TODO find a better and faster way to implement this, this operation can be memory and CPU intensive.
00038 
00039 ContrastBrightnessDlg::ContrastBrightnessDlg(QWidget *parent) :
00040     KDialogBase(KDialogBase::Plain, i18n( "Brightness/Contrast" ), Ok|Cancel, Ok, parent )
00041 {
00042     
00043   float pixdiff, datadiff;
00044   contrast = brightness = 0;
00045   viewer = (FITSViewer *) parent;
00046   displayImage = viewer->image->displayImage;
00047   tempImage    = new QImage(displayImage->copy());
00048   width  = displayImage->width();
00049   height = displayImage->height();
00050   
00051   datadiff = 255;
00052   pixdiff  = viewer->stats.max - viewer->stats.min;
00053   offs = - (viewer->stats.min * datadiff / pixdiff);
00054   scale = datadiff / pixdiff;
00055   
00056   ConBriDlg = new ConBriForm(this);
00057   if (!ConBriDlg) return;
00058   
00059   localImgBuffer = (float *) malloc (width * height * sizeof(float));
00060   if (!localImgBuffer)
00061   {
00062     kdDebug() << "Not enough memory for local image buffer" << endl;
00063     return;
00064   }
00065   
00066   memcpy(localImgBuffer, viewer->imgBuffer, width * height * sizeof(float));
00067   
00068   setMainWidget(ConBriDlg);
00069   show();
00070   
00071   connect(ConBriDlg->conSlider, SIGNAL( valueChanged(int)), this, SLOT (setContrast(int )));
00072   connect(ConBriDlg->briSlider, SIGNAL( valueChanged(int)), this, SLOT (setBrightness(int)));
00073   
00074 }
00075 
00076 ContrastBrightnessDlg::~ContrastBrightnessDlg()
00077 {
00078   delete (tempImage);
00079 }
00080 
00081 void ContrastBrightnessDlg::range(int min, int max, int & num)
00082 {
00083    if (num < min) num = min;
00084    else if (num > max) num = max;
00085 }
00086 
00087 void ContrastBrightnessDlg::range(float min, float max, float & num)
00088 {
00089    if (num < min) num = min;
00090    else if (num > max) num = max;
00091 }
00092 
00093 
00094 #include <math.h>
00095 
00096 void ContrastBrightnessDlg::setContrast(int contrastValue)
00097 {
00098   int val = 0, index=0, totalPix = width * height;
00099   int min = (int) viewer->imgBuffer[0], max = 0;
00100   if (!viewer) return;
00101   QColor myCol;
00102   contrast = contrastValue;
00103 
00104  
00105   // Apply Contrast and brightness
00106   for (int i=0 ; i < height ; i++)
00107            for (int j=0; j < width; j++)
00108        {
00109         val  = (int) *(viewer->image->templateImage->scanLine(i) + j);
00110         
00111         if (contrast)
00112         {
00113             if (val < 128)
00114             {
00115                 val -= contrast;
00116                 range(0, 127, val);
00117                 }
00118                 else
00119                {
00120                         val += contrast;
00121                         range(128, 255, val);
00122                }
00123          }
00124         if (brightness)
00125         {
00126             myCol.setRgb(val,val,val);
00127                     if ( brightness < 0 )
00128                         val += brightness;
00129                     else
00130             {      
00131                     myCol = myCol.light(100+(brightness));
00132                 val   = myCol.red();
00133             }
00134             
00135             range(0, 255, val);
00136         }
00137          
00138         localImgBuffer[(height - i - 1) * width + j] = (val - offs) / scale;
00139        }
00140        
00141        
00142   
00143   for (int i=0; i < totalPix; i++)
00144   {
00145     if (localImgBuffer[i] < min) min = (int) localImgBuffer[i];
00146     else if (localImgBuffer[i] > max) max = (int) localImgBuffer[i];
00147   }
00148   
00149   float pixdiff_b  = max - min;
00150   float offs_b     = - (min * 255 / pixdiff_b);
00151   float scale_b    = 255 / pixdiff_b;
00152   
00153   for (int i=0; i < height; i++)
00154     for (int j=0; j < width; j++)
00155     {
00156             index = i * width + j;
00157         val = (int) (localImgBuffer[index] * scale_b + offs_b);
00158         range(0, 255, val);
00159         displayImage->setPixel(j, height - i - 1, val);
00160     }
00161   
00162   viewer->image->zoomToCurrent();             
00163 }
00164 
00165 void ContrastBrightnessDlg::setBrightness(int brightnessValue)
00166 {
00167   int val = 0, index=0, totalPix = width * height;
00168   int min = (int) viewer->imgBuffer[0], max = 0;
00169   if (!viewer) return;
00170   QColor myCol;
00171   brightness = brightnessValue;
00172 
00173   // Apply Contrast and brightness
00174   for (int i=0 ; i < height ; i++)
00175            for (int j=0; j < width; j++)
00176        {
00177         val  = (int) *(viewer->image->templateImage->scanLine(i) + j);
00178         
00179         if (contrast)
00180         {
00181             if (val < 128)
00182             {
00183                 val -= contrast;
00184                 range(0, 127, val);
00185                 }
00186                 else
00187                {
00188                         val += contrast;
00189                         range(128, 255, val);
00190                }
00191          }
00192         if (brightness)
00193         {
00194             myCol.setRgb(val,val,val);
00195                     if ( brightness < 0 )
00196                         val += brightness;
00197                     else
00198             {      
00199                     myCol = myCol.light(100+(brightness));
00200                 val   = myCol.red();
00201             }
00202             
00203             range(0, 255, val);
00204         }
00205          
00206         localImgBuffer[(height - i - 1) * width + j] = (val - offs) / scale;
00207         
00208         
00209        }
00210   
00211   for (int i=0; i < totalPix; i++)
00212   {
00213     if (localImgBuffer[i] < min) min = (int) localImgBuffer[i];
00214     else if (localImgBuffer[i] > max) max = (int) localImgBuffer[i];
00215   }
00216   
00217   float pixdiff_b  = max - min;
00218   float offs_b     = - (min * 255 / pixdiff_b);
00219   float scale_b    = 255 / pixdiff_b;
00220   
00221   for (int i=0; i < height; i++)
00222     for (int j=0; j < width; j++)
00223     {
00224             index = i * width + j;
00225         val = (int) (localImgBuffer[index] * scale_b + offs_b);
00226         range(0, 255, val);
00227         displayImage->setPixel(j, height - i - 1, val);
00228     }
00229    
00230   viewer->image->zoomToCurrent();
00231  
00232 }
00233 
00234 QSize ContrastBrightnessDlg::sizeHint() const
00235 {
00236   return QSize(400,130);
00237 }
00238 
00239 #include "conbridlg.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal