author | alwin <alwin> | 2004-04-14 12:39:03 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-14 12:39:03 (UTC) |
commit | 4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb (patch) (side-by-side diff) | |
tree | 24f22c258d4fac1924c0be938dca7a5b52a5a3d4 /noncore | |
parent | 3ed50198400e432b308ca58178f562e2e256de0e (diff) | |
download | opie-4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb.zip opie-4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb.tar.gz opie-4f78995cbb47f78e68eb40d9a86a6a0dcdc576eb.tar.bz2 |
jpegs will be loaded scaled if needed for a faster preview loading
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 86 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 3 |
2 files changed, 83 insertions, 6 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 @@ #include "imagescrollview.h" #include <opie2/odebug.h> +#include <opie2/oapplication.h> +#include <opie2/owait.h> using namespace Opie::Core; #include <qimage.h> #include <qlayout.h> +#include <qpe/qcopenvelope_qws.h> ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), @@ -38,18 +41,76 @@ void ImageScrollView::setImage(const QImage&img) _original_data.convertDepth(QPixmap::defaultDepth()); _original_data.setAlphaBuffer(false); m_lastName = ""; + image_is_jpeg = false; + image_scaled_loaded = false; if (first_resize_done) { generateImage(); } } +void ImageScrollView::loadJpeg(bool interncall) +{ + if (m_lastName.isEmpty()) return; + QImageIO iio( m_lastName, 0l ); + QString param; + bool real_load = false; + if (scale_to_fit) { + if (!interncall) { + int wid, hei; + wid = QApplication::desktop()->width(); + hei = QApplication::desktop()->height(); + if (hei>wid) { + wid = hei; + } else { + hei = wid; + } + param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); + odebug << "Load jpeg scaled \"" << param << "\"" << oendl; + iio.setParameters(param.latin1()); + image_scaled_loaded = true; + real_load = true; + } + } else { + if (image_scaled_loaded||!interncall) { + odebug << "Load jpeg unscaled" << oendl; + real_load = true; + } + image_scaled_loaded = false; + } + if (real_load) { + { + QCopEnvelope( "QPE/System", "busy()" ); + } + _original_data = iio.read() ? iio.image() : QImage(); + { + QCopEnvelope env( "QPE/System", "notBusy(QString)" ); + env << "Image loaded"; + } + } +} + void ImageScrollView::setImage( const QString& path ) { odebug << "load new image " << oendl; if (m_lastName == path) return; m_lastName = path; - _original_data.load(path); - _original_data.convertDepth(QPixmap::defaultDepth()); - _original_data.setAlphaBuffer(false); + QString itype = QImage::imageFormat(m_lastName); + odebug << "Image type = " << itype << oendl; + if (itype == "JPEG") { + image_is_jpeg = true; + loadJpeg(); + } else { + { + QCopEnvelope( "QPE/System", "busy()" ); + } + image_is_jpeg = false; + _original_data.load(path); + _original_data.convertDepth(QPixmap::defaultDepth()); + _original_data.setAlphaBuffer(false); + { + QCopEnvelope env( "QPE/System", "notBusy(QString)" ); + env << "Image loaded"; + } + } _image_data = QImage(); if (first_resize_done) { generateImage(); @@ -77,6 +138,8 @@ void ImageScrollView::init() viewport()->setBackgroundColor(white); setFocusPolicy(QWidget::StrongFocus); + image_scaled_loaded = false; + image_is_jpeg = false; if (first_resize_done) { last_rot = Rotate0; generateImage(); @@ -103,6 +166,9 @@ void ImageScrollView::setAutoScale(bool how) rotate_to_fit = false; } _image_data = QImage(); + if (image_is_jpeg && how == false && image_scaled_loaded==true) { + loadJpeg(true); + } generateImage(); } @@ -240,10 +306,14 @@ void ImageScrollView::rotate_into_data(Rotation r) void ImageScrollView::generateImage() { Rotation r = Rotate0; + { + QCopEnvelope( "QPE/System", "busy()" ); + } if (width()>height()&&_original_data.width()<_original_data.height() || width()<height()&&_original_data.width()>_original_data.height()) { if (rotate_to_fit) r = Rotate90; } + odebug << " r = " << r << oendl; if (scale_to_fit) { if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { @@ -266,12 +336,12 @@ void ImageScrollView::generateImage() resizeContents(_image_data.width(),_image_data.height()); } _pdata.convertFromImage(_image_data); - + /* * update the zoomer */ - check_zoomer(); + check_zoomer(); emit imageSizeChanged( _image_data.size() ); rescaleImage( 128, 128 ); /* @@ -279,12 +349,16 @@ void ImageScrollView::generateImage() */ _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, _image_data.width()/2, _image_data.height()/2 ); - + _zoomer->setImage( _image_data ); /* * invalidate */ _image_data=QImage(); + { + QCopEnvelope env( "QPE/System", "notBusy(QString)" ); + env << "Image generated"; + } } void 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: bool rotate_to_fit; bool show_zoomer; bool first_resize_done; + bool image_is_jpeg; + bool image_scaled_loaded; Rotation last_rot; QString m_lastName; virtual void rescaleImage(int w, int h); virtual void rotate_into_data(Rotation r); virtual void generateImage(); + virtual void loadJpeg(bool interncall = false); bool image_fit_into(const QSize&s); void check_zoomer(); |