summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/oimagescrollview.cpp107
-rw-r--r--libopie2/opiemm/oimagescrollview.h16
2 files changed, 123 insertions, 0 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp
index 37a1ad5..58a9748 100644
--- a/libopie2/opiemm/oimagescrollview.cpp
+++ b/libopie2/opiemm/oimagescrollview.cpp
@@ -27,70 +27,75 @@ OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f
{
_zoomer = 0;
m_states[AUTO_SCALE]=true;
m_states[AUTO_ROTATE]=true;
m_states[FIRST_RESIZE_DONE]=false;
m_states[IMAGE_IS_JPEG]=false;
m_states[IMAGE_SCALED_LOADED]=false;
m_states[SHOW_ZOOMER]=true;
+ _newImage = true;
init();
}
OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
:QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),
m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
{
_zoomer = 0;
m_states[AUTO_SCALE]=always_scale;
m_states[AUTO_ROTATE]=rfit;
m_states[FIRST_RESIZE_DONE]=false;
m_states[IMAGE_IS_JPEG]=false;
m_states[IMAGE_SCALED_LOADED]=false;
m_states[SHOW_ZOOMER]=true;
_original_data.convertDepth(QPixmap::defaultDepth());
_original_data.setAlphaBuffer(false);
+ _newImage = true;
init();
}
OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
:QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
{
_zoomer = 0;
m_states.resize(SCROLLVIEW_BITSET_SIZE);
m_states[AUTO_SCALE]=always_scale;
m_states[AUTO_ROTATE]=rfit;
m_states[FIRST_RESIZE_DONE]=false;
m_states[IMAGE_IS_JPEG]=false;
m_states[IMAGE_SCALED_LOADED]=false;
m_states[SHOW_ZOOMER]=true;
+ _newImage = true;
init();
setImage(img);
}
void OImageScrollView::setImage(const QImage&img)
{
_image_data = QImage();
_original_data=img;
_original_data.convertDepth(QPixmap::defaultDepth());
_original_data.setAlphaBuffer(false);
m_lastName = "";
setImageIsJpeg(false);
setImageScaledLoaded(false);
+ _newImage = true;
if (FirstResizeDone()) {
generateImage();
}
}
void OImageScrollView::loadJpeg(bool interncall)
{
if (m_lastName.isEmpty()) return;
QImageIO iio( m_lastName, 0l );
QString param;
bool real_load = false;
+ _newImage = true;
if (AutoScale()) {
if (!interncall) {
ExifData xf;
bool scanned = xf.scan(m_lastName);
int wid, hei;
wid = QApplication::desktop()->width();
hei = QApplication::desktop()->height();
if (hei>wid) {
@@ -118,16 +123,17 @@ void OImageScrollView::loadJpeg(bool interncall)
_original_data = iio.read() ? iio.image() : QImage();
}
}
void OImageScrollView::setImage( const QString& path ) {
odebug << "load new image " << oendl;
if (m_lastName == path) return;
m_lastName = path;
+ _newImage = true;
_original_data = QImage();
QString itype = QImage::imageFormat(m_lastName);
odebug << "Image type = " << itype << oendl;
if (itype == "JPEG") {
setImageIsJpeg(true);
loadJpeg();
} else {
setImageIsJpeg(false);
@@ -169,16 +175,17 @@ void OImageScrollView::init()
setImageIsJpeg(false);
if (FirstResizeDone()) {
m_last_rot = Rotate0;
generateImage();
} else if (_original_data.size().isValid()) {
if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
resizeContents(_original_data.width(),_original_data.height());
}
+ _intensity = 0;
}
void OImageScrollView::setAutoRotate(bool how)
{
/* to avoid double repaints */
if (AutoRotate() != how) {
m_states.setBit(AUTO_ROTATE,how);
_image_data = QImage();
@@ -335,19 +342,112 @@ void OImageScrollView::rotate_into_data(Rotation r)
}
break;
default:
dest = _original_data;
break;
}
}
+ _newImage = true;
_image_data = dest;
}
+void OImageScrollView::apply_gamma(int aValue)
+{
+ if (!_image_data.size().isValid()) return;
+ float percent = ((float)aValue/100);
+ odebug << "Apply gamma " << percent << oendl;
+ int pixels = _image_data.depth()>8?_image_data.width()*_image_data.height() : _image_data.numColors();
+ int segColors = _image_data.depth() > 8 ? 256 : _image_data.numColors();
+ unsigned char *segTbl = new unsigned char[segColors];
+ bool brighten = (percent >= 0);
+ if ( percent < 0 )
+ percent = -percent;
+
+ unsigned int *data = _image_data.depth() > 8 ? (unsigned int *)_image_data.bits() :
+ (unsigned int *)_image_data.colorTable();
+
+
+ if (brighten) {
+ for ( int i=0; i < segColors; ++i )
+ {
+ int tmp = (int)(i*percent);
+ if ( tmp > 255 )
+ tmp = 255;
+ segTbl[i] = tmp;
+ }
+ } else {
+ for ( int i=0; i < segColors; ++i )
+ {
+ int tmp = (int)(i*percent);
+ if ( tmp < 0 )
+ tmp = 0;
+ segTbl[i] = tmp;
+ }
+ }
+ if (brighten) {
+ for ( int i=0; i < pixels; ++i )
+ {
+ int r = qRed(data[i]);
+ int g = qGreen(data[i]);
+ int b = qBlue(data[i]);
+ int a = qAlpha(data[i]);
+ r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
+ g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
+ b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
+ data[i] = qRgba(r, g, b,a);
+ }
+ } else {
+ for ( int i=0; i < pixels; ++i )
+ {
+ int r = qRed(data[i]);
+ int g = qGreen(data[i]);
+ int b = qBlue(data[i]);
+ int a = qAlpha(data[i]);
+ r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
+ g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
+ b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
+ data[i] = qRgba(r, g, b, a);
+ }
+ }
+ delete [] segTbl;
+}
+
+const int OImageScrollView::Intensity()const
+{
+ return _intensity;
+}
+
+int OImageScrollView::setIntensity(int value,bool reload)
+{
+ int oldi = _intensity;
+ _intensity = value;
+ if (!_pdata.size().isValid()) {
+ return _intensity;
+ }
+
+ if (!reload) {
+ _image_data = _pdata.convertToImage();
+ apply_gamma(_intensity-oldi);
+ _pdata.convertFromImage(_image_data);
+ /*
+ * invalidate
+ */
+ _image_data=QImage();
+ if (isVisible()) {
+ updateContents(contentsX(),contentsY(),width(),height());
+ }
+ } else {
+ _newImage = true;
+ generateImage();
+ }
+ return _intensity;
+}
+
void OImageScrollView::generateImage()
{
Rotation r = Rotate0;
_pdata = QPixmap();
if (_original_data.isNull()) {
emit imageSizeChanged( _image_data.size() );
if (_zoomer) _zoomer->setImage( _image_data );
return;
@@ -362,26 +462,33 @@ void OImageScrollView::generateImage()
if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) {
if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
odebug << "Rescaling data" << oendl;
if (r==Rotate0) {
_image_data = _original_data;
} else {
rotate_into_data(r);
}
+ _newImage = true;
}
rescaleImage(width(),height());
} else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
if (r==Rotate0) {
_image_data = _original_data;
} else {
rotate_into_data(r);
}
m_last_rot = r;
}
+
+ if (_newImage) {
+ apply_gamma(_intensity);
+ _newImage = false;
+ }
+
_pdata.convertFromImage(_image_data);
twidth = _image_data.width();
theight = _image_data.height();
/*
* update the zoomer
*/
check_zoomer();
diff --git a/libopie2/opiemm/oimagescrollview.h b/libopie2/opiemm/oimagescrollview.h
index 01a2d56..11964fd 100644
--- a/libopie2/opiemm/oimagescrollview.h
+++ b/libopie2/opiemm/oimagescrollview.h
@@ -116,16 +116,29 @@ public:
* return the current value of the autoscale flag.
*/
virtual bool AutoScale()const;
/**
* return the current value of the show zoomer flag.
*/
virtual bool ShowZoomer()const;
+ /**
+ * set a display intensity
+ * @param value the intensity value, will calcuated to a percent value (value/100)
+ * @param reload should the real image recalculated complete or just work on current display.
+ * @return the new intensity
+ */
+ virtual int setIntensity(int value,bool reload=false);
+ /**
+ * return the current display intensity
+ */
+ virtual const int Intensity()const;
+
+
public slots:
/**
* Displays a new image, calculations will made immediately.
*
* @param aImage the image to display
*/
virtual void setImage(const QImage&aImage);
/**
@@ -152,16 +165,18 @@ signals:
protected:
virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
void init();
Opie::MM::OImageZoomer *_zoomer;
QImage _image_data;
QImage _original_data;
QPixmap _pdata;
+ int _intensity;
+ bool _newImage;
int _mouseStartPosX,_mouseStartPosY;
QBitArray m_states;
Rotation m_last_rot;
QString m_lastName;
virtual void rescaleImage(int w, int h);
@@ -174,16 +189,17 @@ protected:
/* internal bitset manipulation */
virtual bool ImageIsJpeg()const;
virtual void setImageIsJpeg(bool how);
virtual bool ImageScaledLoaded()const;
virtual void setImageScaledLoaded(bool how);
virtual bool FirstResizeDone()const;
virtual void setFirstResizeDone(bool how);
+ virtual void apply_gamma(int aValue);
protected slots:
virtual void viewportMouseMoveEvent(QMouseEvent* e);
virtual void contentsMousePressEvent ( QMouseEvent * e);
virtual void resizeEvent(QResizeEvent * e);
virtual void keyPressEvent(QKeyEvent * e);
};