summaryrefslogtreecommitdiff
path: root/libopie2/opiemm
authoralwin <alwin>2005-03-22 22:15:50 (UTC)
committer alwin <alwin>2005-03-22 22:15:50 (UTC)
commit31035d399edaaaff64976705fd44468b6357c863 (patch) (side-by-side diff)
treecd32f1d5c23de21a924b5bd8bb7d43fadf160e3e /libopie2/opiemm
parent0b1f73644d33291b3a03d347dc5be3167126b652 (diff)
downloadopie-31035d399edaaaff64976705fd44468b6357c863.zip
opie-31035d399edaaaff64976705fd44468b6357c863.tar.gz
opie-31035d399edaaaff64976705fd44468b6357c863.tar.bz2
added missing interface methods for a generic imagedisplay (display
brightness) apps using that OImageScrollview must rebuild! this will be the last change of interface for a long time
Diffstat (limited to 'libopie2/opiemm') (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
@@ -34,2 +34,3 @@ OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f
m_states[SHOW_ZOOMER]=true;
+ _newImage = true;
init();
@@ -50,2 +51,3 @@ OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const ch
_original_data.setAlphaBuffer(false);
+ _newImage = true;
init();
@@ -64,2 +66,3 @@ OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const c
m_states[SHOW_ZOOMER]=true;
+ _newImage = true;
init();
@@ -77,2 +80,3 @@ void OImageScrollView::setImage(const QImage&img)
setImageScaledLoaded(false);
+ _newImage = true;
if (FirstResizeDone()) {
@@ -88,2 +92,3 @@ void OImageScrollView::loadJpeg(bool interncall)
bool real_load = false;
+ _newImage = true;
if (AutoScale()) {
@@ -125,2 +130,3 @@ void OImageScrollView::setImage( const QString& path ) {
m_lastName = path;
+ _newImage = true;
_original_data = QImage();
@@ -176,2 +182,3 @@ void OImageScrollView::init()
}
+ _intensity = 0;
}
@@ -342,2 +349,3 @@ void OImageScrollView::rotate_into_data(Rotation r)
}
+ _newImage = true;
_image_data = dest;
@@ -345,2 +353,94 @@ void OImageScrollView::rotate_into_data(Rotation r)
+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()
@@ -369,2 +469,3 @@ void OImageScrollView::generateImage()
}
+ _newImage = true;
}
@@ -379,2 +480,8 @@ void OImageScrollView::generateImage()
}
+
+ if (_newImage) {
+ apply_gamma(_intensity);
+ _newImage = false;
+ }
+
_pdata.convertFromImage(_image_data);
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
@@ -123,2 +123,15 @@ public:
+ /**
+ * 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:
@@ -159,2 +172,4 @@ protected:
QPixmap _pdata;
+ int _intensity;
+ bool _newImage;
@@ -181,2 +196,3 @@ protected:
virtual void setFirstResizeDone(bool how);
+ virtual void apply_gamma(int aValue);