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) (unidiff)
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
34 m_states[SHOW_ZOOMER]=true; 34 m_states[SHOW_ZOOMER]=true;
35 _newImage = true;
35 init(); 36 init();
@@ -50,2 +51,3 @@ OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const ch
50 _original_data.setAlphaBuffer(false); 51 _original_data.setAlphaBuffer(false);
52 _newImage = true;
51 init(); 53 init();
@@ -64,2 +66,3 @@ OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const c
64 m_states[SHOW_ZOOMER]=true; 66 m_states[SHOW_ZOOMER]=true;
67 _newImage = true;
65 init(); 68 init();
@@ -77,2 +80,3 @@ void OImageScrollView::setImage(const QImage&img)
77 setImageScaledLoaded(false); 80 setImageScaledLoaded(false);
81 _newImage = true;
78 if (FirstResizeDone()) { 82 if (FirstResizeDone()) {
@@ -88,2 +92,3 @@ void OImageScrollView::loadJpeg(bool interncall)
88 bool real_load = false; 92 bool real_load = false;
93 _newImage = true;
89 if (AutoScale()) { 94 if (AutoScale()) {
@@ -125,2 +130,3 @@ void OImageScrollView::setImage( const QString& path ) {
125 m_lastName = path; 130 m_lastName = path;
131 _newImage = true;
126 _original_data = QImage(); 132 _original_data = QImage();
@@ -176,2 +182,3 @@ void OImageScrollView::init()
176 } 182 }
183 _intensity = 0;
177} 184}
@@ -342,2 +349,3 @@ void OImageScrollView::rotate_into_data(Rotation r)
342 } 349 }
350 _newImage = true;
343 _image_data = dest; 351 _image_data = dest;
@@ -345,2 +353,94 @@ void OImageScrollView::rotate_into_data(Rotation r)
345 353
354void OImageScrollView::apply_gamma(int aValue)
355{
356 if (!_image_data.size().isValid()) return;
357 float percent = ((float)aValue/100);
358 odebug << "Apply gamma " << percent << oendl;
359 int pixels = _image_data.depth()>8?_image_data.width()*_image_data.height() : _image_data.numColors();
360 int segColors = _image_data.depth() > 8 ? 256 : _image_data.numColors();
361 unsigned char *segTbl = new unsigned char[segColors];
362 bool brighten = (percent >= 0);
363 if ( percent < 0 )
364 percent = -percent;
365
366 unsigned int *data = _image_data.depth() > 8 ? (unsigned int *)_image_data.bits() :
367 (unsigned int *)_image_data.colorTable();
368
369
370 if (brighten) {
371 for ( int i=0; i < segColors; ++i )
372 {
373 int tmp = (int)(i*percent);
374 if ( tmp > 255 )
375 tmp = 255;
376 segTbl[i] = tmp;
377 }
378 } else {
379 for ( int i=0; i < segColors; ++i )
380 {
381 int tmp = (int)(i*percent);
382 if ( tmp < 0 )
383 tmp = 0;
384 segTbl[i] = tmp;
385 }
386 }
387 if (brighten) {
388 for ( int i=0; i < pixels; ++i )
389 {
390 int r = qRed(data[i]);
391 int g = qGreen(data[i]);
392 int b = qBlue(data[i]);
393 int a = qAlpha(data[i]);
394 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
395 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
396 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
397 data[i] = qRgba(r, g, b,a);
398 }
399 } else {
400 for ( int i=0; i < pixels; ++i )
401 {
402 int r = qRed(data[i]);
403 int g = qGreen(data[i]);
404 int b = qBlue(data[i]);
405 int a = qAlpha(data[i]);
406 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
407 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
408 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
409 data[i] = qRgba(r, g, b, a);
410 }
411 }
412 delete [] segTbl;
413}
414
415const int OImageScrollView::Intensity()const
416{
417 return _intensity;
418}
419
420int OImageScrollView::setIntensity(int value,bool reload)
421{
422 int oldi = _intensity;
423 _intensity = value;
424 if (!_pdata.size().isValid()) {
425 return _intensity;
426 }
427
428 if (!reload) {
429 _image_data = _pdata.convertToImage();
430 apply_gamma(_intensity-oldi);
431 _pdata.convertFromImage(_image_data);
432 /*
433 * invalidate
434 */
435 _image_data=QImage();
436 if (isVisible()) {
437 updateContents(contentsX(),contentsY(),width(),height());
438 }
439 } else {
440 _newImage = true;
441 generateImage();
442 }
443 return _intensity;
444}
445
346void OImageScrollView::generateImage() 446void OImageScrollView::generateImage()
@@ -369,2 +469,3 @@ void OImageScrollView::generateImage()
369 } 469 }
470 _newImage = true;
370 } 471 }
@@ -379,2 +480,8 @@ void OImageScrollView::generateImage()
379 } 480 }
481
482 if (_newImage) {
483 apply_gamma(_intensity);
484 _newImage = false;
485 }
486
380 _pdata.convertFromImage(_image_data); 487 _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:
123 123
124 /**
125 * set a display intensity
126 * @param value the intensity value, will calcuated to a percent value (value/100)
127 * @param reload should the real image recalculated complete or just work on current display.
128 * @return the new intensity
129 */
130 virtual int setIntensity(int value,bool reload=false);
131 /**
132 * return the current display intensity
133 */
134 virtual const int Intensity()const;
135
136
124public slots: 137public slots:
@@ -159,2 +172,4 @@ protected:
159 QPixmap _pdata; 172 QPixmap _pdata;
173 int _intensity;
174 bool _newImage;
160 175
@@ -181,2 +196,3 @@ protected:
181 virtual void setFirstResizeDone(bool how); 196 virtual void setFirstResizeDone(bool how);
197 virtual void apply_gamma(int aValue);
182 198