summaryrefslogtreecommitdiff
Unidiff
Diffstat (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
27{ 27{
28 _zoomer = 0; 28 _zoomer = 0;
29 m_states[AUTO_SCALE]=true; 29 m_states[AUTO_SCALE]=true;
30 m_states[AUTO_ROTATE]=true; 30 m_states[AUTO_ROTATE]=true;
31 m_states[FIRST_RESIZE_DONE]=false; 31 m_states[FIRST_RESIZE_DONE]=false;
32 m_states[IMAGE_IS_JPEG]=false; 32 m_states[IMAGE_IS_JPEG]=false;
33 m_states[IMAGE_SCALED_LOADED]=false; 33 m_states[IMAGE_SCALED_LOADED]=false;
34 m_states[SHOW_ZOOMER]=true; 34 m_states[SHOW_ZOOMER]=true;
35 _newImage = true;
35 init(); 36 init();
36} 37}
37 38
38OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 39OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
39 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img), 40 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),
40 m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") 41 m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
41{ 42{
42 _zoomer = 0; 43 _zoomer = 0;
43 m_states[AUTO_SCALE]=always_scale; 44 m_states[AUTO_SCALE]=always_scale;
44 m_states[AUTO_ROTATE]=rfit; 45 m_states[AUTO_ROTATE]=rfit;
45 m_states[FIRST_RESIZE_DONE]=false; 46 m_states[FIRST_RESIZE_DONE]=false;
46 m_states[IMAGE_IS_JPEG]=false; 47 m_states[IMAGE_IS_JPEG]=false;
47 m_states[IMAGE_SCALED_LOADED]=false; 48 m_states[IMAGE_SCALED_LOADED]=false;
48 m_states[SHOW_ZOOMER]=true; 49 m_states[SHOW_ZOOMER]=true;
49 _original_data.convertDepth(QPixmap::defaultDepth()); 50 _original_data.convertDepth(QPixmap::defaultDepth());
50 _original_data.setAlphaBuffer(false); 51 _original_data.setAlphaBuffer(false);
52 _newImage = true;
51 init(); 53 init();
52} 54}
53 55
54OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 56OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
55 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") 57 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
56{ 58{
57 _zoomer = 0; 59 _zoomer = 0;
58 m_states.resize(SCROLLVIEW_BITSET_SIZE); 60 m_states.resize(SCROLLVIEW_BITSET_SIZE);
59 m_states[AUTO_SCALE]=always_scale; 61 m_states[AUTO_SCALE]=always_scale;
60 m_states[AUTO_ROTATE]=rfit; 62 m_states[AUTO_ROTATE]=rfit;
61 m_states[FIRST_RESIZE_DONE]=false; 63 m_states[FIRST_RESIZE_DONE]=false;
62 m_states[IMAGE_IS_JPEG]=false; 64 m_states[IMAGE_IS_JPEG]=false;
63 m_states[IMAGE_SCALED_LOADED]=false; 65 m_states[IMAGE_SCALED_LOADED]=false;
64 m_states[SHOW_ZOOMER]=true; 66 m_states[SHOW_ZOOMER]=true;
67 _newImage = true;
65 init(); 68 init();
66 setImage(img); 69 setImage(img);
67} 70}
68 71
69void OImageScrollView::setImage(const QImage&img) 72void OImageScrollView::setImage(const QImage&img)
70{ 73{
71 _image_data = QImage(); 74 _image_data = QImage();
72 _original_data=img; 75 _original_data=img;
73 _original_data.convertDepth(QPixmap::defaultDepth()); 76 _original_data.convertDepth(QPixmap::defaultDepth());
74 _original_data.setAlphaBuffer(false); 77 _original_data.setAlphaBuffer(false);
75 m_lastName = ""; 78 m_lastName = "";
76 setImageIsJpeg(false); 79 setImageIsJpeg(false);
77 setImageScaledLoaded(false); 80 setImageScaledLoaded(false);
81 _newImage = true;
78 if (FirstResizeDone()) { 82 if (FirstResizeDone()) {
79 generateImage(); 83 generateImage();
80 } 84 }
81} 85}
82 86
83void OImageScrollView::loadJpeg(bool interncall) 87void OImageScrollView::loadJpeg(bool interncall)
84{ 88{
85 if (m_lastName.isEmpty()) return; 89 if (m_lastName.isEmpty()) return;
86 QImageIO iio( m_lastName, 0l ); 90 QImageIO iio( m_lastName, 0l );
87 QString param; 91 QString param;
88 bool real_load = false; 92 bool real_load = false;
93 _newImage = true;
89 if (AutoScale()) { 94 if (AutoScale()) {
90 if (!interncall) { 95 if (!interncall) {
91 ExifData xf; 96 ExifData xf;
92 bool scanned = xf.scan(m_lastName); 97 bool scanned = xf.scan(m_lastName);
93 int wid, hei; 98 int wid, hei;
94 wid = QApplication::desktop()->width(); 99 wid = QApplication::desktop()->width();
95 hei = QApplication::desktop()->height(); 100 hei = QApplication::desktop()->height();
96 if (hei>wid) { 101 if (hei>wid) {
@@ -118,16 +123,17 @@ void OImageScrollView::loadJpeg(bool interncall)
118 _original_data = iio.read() ? iio.image() : QImage(); 123 _original_data = iio.read() ? iio.image() : QImage();
119 } 124 }
120} 125}
121 126
122void OImageScrollView::setImage( const QString& path ) { 127void OImageScrollView::setImage( const QString& path ) {
123 odebug << "load new image " << oendl; 128 odebug << "load new image " << oendl;
124 if (m_lastName == path) return; 129 if (m_lastName == path) return;
125 m_lastName = path; 130 m_lastName = path;
131 _newImage = true;
126 _original_data = QImage(); 132 _original_data = QImage();
127 QString itype = QImage::imageFormat(m_lastName); 133 QString itype = QImage::imageFormat(m_lastName);
128 odebug << "Image type = " << itype << oendl; 134 odebug << "Image type = " << itype << oendl;
129 if (itype == "JPEG") { 135 if (itype == "JPEG") {
130 setImageIsJpeg(true); 136 setImageIsJpeg(true);
131 loadJpeg(); 137 loadJpeg();
132 } else { 138 } else {
133 setImageIsJpeg(false); 139 setImageIsJpeg(false);
@@ -169,16 +175,17 @@ void OImageScrollView::init()
169 setImageIsJpeg(false); 175 setImageIsJpeg(false);
170 if (FirstResizeDone()) { 176 if (FirstResizeDone()) {
171 m_last_rot = Rotate0; 177 m_last_rot = Rotate0;
172 generateImage(); 178 generateImage();
173 } else if (_original_data.size().isValid()) { 179 } else if (_original_data.size().isValid()) {
174 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); 180 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
175 resizeContents(_original_data.width(),_original_data.height()); 181 resizeContents(_original_data.width(),_original_data.height());
176 } 182 }
183 _intensity = 0;
177} 184}
178 185
179void OImageScrollView::setAutoRotate(bool how) 186void OImageScrollView::setAutoRotate(bool how)
180{ 187{
181 /* to avoid double repaints */ 188 /* to avoid double repaints */
182 if (AutoRotate() != how) { 189 if (AutoRotate() != how) {
183 m_states.setBit(AUTO_ROTATE,how); 190 m_states.setBit(AUTO_ROTATE,how);
184 _image_data = QImage(); 191 _image_data = QImage();
@@ -335,19 +342,112 @@ void OImageScrollView::rotate_into_data(Rotation r)
335 } 342 }
336 break; 343 break;
337 default: 344 default:
338 dest = _original_data; 345 dest = _original_data;
339 break; 346 break;
340 } 347 }
341 348
342 } 349 }
350 _newImage = true;
343 _image_data = dest; 351 _image_data = dest;
344} 352}
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()
347{ 447{
348 Rotation r = Rotate0; 448 Rotation r = Rotate0;
349 _pdata = QPixmap(); 449 _pdata = QPixmap();
350 if (_original_data.isNull()) { 450 if (_original_data.isNull()) {
351 emit imageSizeChanged( _image_data.size() ); 451 emit imageSizeChanged( _image_data.size() );
352 if (_zoomer) _zoomer->setImage( _image_data ); 452 if (_zoomer) _zoomer->setImage( _image_data );
353 return; 453 return;
@@ -362,26 +462,33 @@ void OImageScrollView::generateImage()
362 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { 462 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) {
363 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 463 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
364 odebug << "Rescaling data" << oendl; 464 odebug << "Rescaling data" << oendl;
365 if (r==Rotate0) { 465 if (r==Rotate0) {
366 _image_data = _original_data; 466 _image_data = _original_data;
367 } else { 467 } else {
368 rotate_into_data(r); 468 rotate_into_data(r);
369 } 469 }
470 _newImage = true;
370 } 471 }
371 rescaleImage(width(),height()); 472 rescaleImage(width(),height());
372 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { 473 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
373 if (r==Rotate0) { 474 if (r==Rotate0) {
374 _image_data = _original_data; 475 _image_data = _original_data;
375 } else { 476 } else {
376 rotate_into_data(r); 477 rotate_into_data(r);
377 } 478 }
378 m_last_rot = r; 479 m_last_rot = r;
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);
381 twidth = _image_data.width(); 488 twidth = _image_data.width();
382 theight = _image_data.height(); 489 theight = _image_data.height();
383 490
384 /* 491 /*
385 * update the zoomer 492 * update the zoomer
386 */ 493 */
387 check_zoomer(); 494 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:
116 * return the current value of the autoscale flag. 116 * return the current value of the autoscale flag.
117 */ 117 */
118 virtual bool AutoScale()const; 118 virtual bool AutoScale()const;
119 /** 119 /**
120 * return the current value of the show zoomer flag. 120 * return the current value of the show zoomer flag.
121 */ 121 */
122 virtual bool ShowZoomer()const; 122 virtual bool ShowZoomer()const;
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:
125 /** 138 /**
126 * Displays a new image, calculations will made immediately. 139 * Displays a new image, calculations will made immediately.
127 * 140 *
128 * @param aImage the image to display 141 * @param aImage the image to display
129 */ 142 */
130 virtual void setImage(const QImage&aImage); 143 virtual void setImage(const QImage&aImage);
131 /** 144 /**
@@ -152,16 +165,18 @@ signals:
152protected: 165protected:
153 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); 166 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
154 void init(); 167 void init();
155 168
156 Opie::MM::OImageZoomer *_zoomer; 169 Opie::MM::OImageZoomer *_zoomer;
157 QImage _image_data; 170 QImage _image_data;
158 QImage _original_data; 171 QImage _original_data;
159 QPixmap _pdata; 172 QPixmap _pdata;
173 int _intensity;
174 bool _newImage;
160 175
161 int _mouseStartPosX,_mouseStartPosY; 176 int _mouseStartPosX,_mouseStartPosY;
162 177
163 QBitArray m_states; 178 QBitArray m_states;
164 179
165 Rotation m_last_rot; 180 Rotation m_last_rot;
166 QString m_lastName; 181 QString m_lastName;
167 virtual void rescaleImage(int w, int h); 182 virtual void rescaleImage(int w, int h);
@@ -174,16 +189,17 @@ protected:
174 189
175 /* internal bitset manipulation */ 190 /* internal bitset manipulation */
176 virtual bool ImageIsJpeg()const; 191 virtual bool ImageIsJpeg()const;
177 virtual void setImageIsJpeg(bool how); 192 virtual void setImageIsJpeg(bool how);
178 virtual bool ImageScaledLoaded()const; 193 virtual bool ImageScaledLoaded()const;
179 virtual void setImageScaledLoaded(bool how); 194 virtual void setImageScaledLoaded(bool how);
180 virtual bool FirstResizeDone()const; 195 virtual bool FirstResizeDone()const;
181 virtual void setFirstResizeDone(bool how); 196 virtual void setFirstResizeDone(bool how);
197 virtual void apply_gamma(int aValue);
182 198
183protected slots: 199protected slots:
184 virtual void viewportMouseMoveEvent(QMouseEvent* e); 200 virtual void viewportMouseMoveEvent(QMouseEvent* e);
185 virtual void contentsMousePressEvent ( QMouseEvent * e); 201 virtual void contentsMousePressEvent ( QMouseEvent * e);
186 virtual void resizeEvent(QResizeEvent * e); 202 virtual void resizeEvent(QResizeEvent * e);
187 virtual void keyPressEvent(QKeyEvent * e); 203 virtual void keyPressEvent(QKeyEvent * e);
188}; 204};
189 205