summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-14 12:39:03 (UTC)
committer alwin <alwin>2004-04-14 12:39:03 (UTC)
commit4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb (patch) (unidiff)
tree24f22c258d4fac1924c0be938dca7a5b52a5a3d4
parent3ed50198400e432b308ca58178f562e2e256de0e (diff)
downloadopie-4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb.zip
opie-4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb.tar.gz
opie-4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb.tar.bz2
jpegs will be loaded scaled if needed for a faster preview loading
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp74
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h3
2 files changed, 77 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
index 2f16d82..d034ee0 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
@@ -1,11 +1,14 @@
1#include "imagescrollview.h" 1#include "imagescrollview.h"
2 2
3#include <opie2/odebug.h> 3#include <opie2/odebug.h>
4#include <opie2/oapplication.h>
5#include <opie2/owait.h>
4 6
5using namespace Opie::Core; 7using namespace Opie::Core;
6 8
7#include <qimage.h> 9#include <qimage.h>
8#include <qlayout.h> 10#include <qlayout.h>
11#include <qpe/qcopenvelope_qws.h>
9 12
10ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) 13ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f )
11 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), 14 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true),
@@ -38,18 +41,76 @@ void ImageScrollView::setImage(const QImage&img)
38 _original_data.convertDepth(QPixmap::defaultDepth()); 41 _original_data.convertDepth(QPixmap::defaultDepth());
39 _original_data.setAlphaBuffer(false); 42 _original_data.setAlphaBuffer(false);
40 m_lastName = ""; 43 m_lastName = "";
44 image_is_jpeg = false;
45 image_scaled_loaded = false;
41 if (first_resize_done) { 46 if (first_resize_done) {
42 generateImage(); 47 generateImage();
43 } 48 }
44} 49}
45 50
51void ImageScrollView::loadJpeg(bool interncall)
52{
53 if (m_lastName.isEmpty()) return;
54 QImageIO iio( m_lastName, 0l );
55 QString param;
56 bool real_load = false;
57 if (scale_to_fit) {
58 if (!interncall) {
59 int wid, hei;
60 wid = QApplication::desktop()->width();
61 hei = QApplication::desktop()->height();
62 if (hei>wid) {
63 wid = hei;
64 } else {
65 hei = wid;
66 }
67 param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei );
68 odebug << "Load jpeg scaled \"" << param << "\"" << oendl;
69 iio.setParameters(param.latin1());
70 image_scaled_loaded = true;
71 real_load = true;
72 }
73 } else {
74 if (image_scaled_loaded||!interncall) {
75 odebug << "Load jpeg unscaled" << oendl;
76 real_load = true;
77 }
78 image_scaled_loaded = false;
79 }
80 if (real_load) {
81 {
82 QCopEnvelope( "QPE/System", "busy()" );
83 }
84 _original_data = iio.read() ? iio.image() : QImage();
85 {
86 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
87 env << "Image loaded";
88 }
89 }
90}
91
46void ImageScrollView::setImage( const QString& path ) { 92void ImageScrollView::setImage( const QString& path ) {
47 odebug << "load new image " << oendl; 93 odebug << "load new image " << oendl;
48 if (m_lastName == path) return; 94 if (m_lastName == path) return;
49 m_lastName = path; 95 m_lastName = path;
96 QString itype = QImage::imageFormat(m_lastName);
97 odebug << "Image type = " << itype << oendl;
98 if (itype == "JPEG") {
99 image_is_jpeg = true;
100 loadJpeg();
101 } else {
102 {
103 QCopEnvelope( "QPE/System", "busy()" );
104 }
105 image_is_jpeg = false;
50 _original_data.load(path); 106 _original_data.load(path);
51 _original_data.convertDepth(QPixmap::defaultDepth()); 107 _original_data.convertDepth(QPixmap::defaultDepth());
52 _original_data.setAlphaBuffer(false); 108 _original_data.setAlphaBuffer(false);
109 {
110 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
111 env << "Image loaded";
112 }
113 }
53 _image_data = QImage(); 114 _image_data = QImage();
54 if (first_resize_done) { 115 if (first_resize_done) {
55 generateImage(); 116 generateImage();
@@ -77,6 +138,8 @@ void ImageScrollView::init()
77 138
78 viewport()->setBackgroundColor(white); 139 viewport()->setBackgroundColor(white);
79 setFocusPolicy(QWidget::StrongFocus); 140 setFocusPolicy(QWidget::StrongFocus);
141 image_scaled_loaded = false;
142 image_is_jpeg = false;
80 if (first_resize_done) { 143 if (first_resize_done) {
81 last_rot = Rotate0; 144 last_rot = Rotate0;
82 generateImage(); 145 generateImage();
@@ -103,6 +166,9 @@ void ImageScrollView::setAutoScale(bool how)
103 rotate_to_fit = false; 166 rotate_to_fit = false;
104 } 167 }
105 _image_data = QImage(); 168 _image_data = QImage();
169 if (image_is_jpeg && how == false && image_scaled_loaded==true) {
170 loadJpeg(true);
171 }
106 generateImage(); 172 generateImage();
107} 173}
108 174
@@ -240,10 +306,14 @@ void ImageScrollView::rotate_into_data(Rotation r)
240void ImageScrollView::generateImage() 306void ImageScrollView::generateImage()
241{ 307{
242 Rotation r = Rotate0; 308 Rotation r = Rotate0;
309 {
310 QCopEnvelope( "QPE/System", "busy()" );
311 }
243 if (width()>height()&&_original_data.width()<_original_data.height() || 312 if (width()>height()&&_original_data.width()<_original_data.height() ||
244 width()<height()&&_original_data.width()>_original_data.height()) { 313 width()<height()&&_original_data.width()>_original_data.height()) {
245 if (rotate_to_fit) r = Rotate90; 314 if (rotate_to_fit) r = Rotate90;
246 } 315 }
316
247 odebug << " r = " << r << oendl; 317 odebug << " r = " << r << oendl;
248 if (scale_to_fit) { 318 if (scale_to_fit) {
249 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 319 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
@@ -285,6 +355,10 @@ void ImageScrollView::generateImage()
285 * invalidate 355 * invalidate
286 */ 356 */
287 _image_data=QImage(); 357 _image_data=QImage();
358 {
359 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
360 env << "Image generated";
361 }
288} 362}
289 363
290void ImageScrollView::resizeEvent(QResizeEvent * e) 364void ImageScrollView::resizeEvent(QResizeEvent * e)
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h
index e209dfb..f6e187d 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.h
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.h
@@ -57,12 +57,15 @@ protected:
57 bool rotate_to_fit; 57 bool rotate_to_fit;
58 bool show_zoomer; 58 bool show_zoomer;
59 bool first_resize_done; 59 bool first_resize_done;
60 bool image_is_jpeg;
61 bool image_scaled_loaded;
60 Rotation last_rot; 62 Rotation last_rot;
61 QString m_lastName; 63 QString m_lastName;
62 virtual void rescaleImage(int w, int h); 64 virtual void rescaleImage(int w, int h);
63 65
64 virtual void rotate_into_data(Rotation r); 66 virtual void rotate_into_data(Rotation r);
65 virtual void generateImage(); 67 virtual void generateImage();
68 virtual void loadJpeg(bool interncall = false);
66 bool image_fit_into(const QSize&s); 69 bool image_fit_into(const QSize&s);
67 void check_zoomer(); 70 void check_zoomer();
68 71