summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/slave/thumbnailtool.cpp
authorzecke <zecke>2004-03-22 23:32:41 (UTC)
committer zecke <zecke>2004-03-22 23:32:41 (UTC)
commit428b687982966dc2efabaf6dbcc55ad0ea30aa10 (patch) (side-by-side diff)
tree86da20abd2e4b97a59dc32e17996bde5ee74cc91 /noncore/graphics/opie-eye/slave/thumbnailtool.cpp
parent7ce623c6351646ce738a81e103632d73c5454ecc (diff)
downloadopie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.zip
opie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.tar.gz
opie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.tar.bz2
Initial Check in of the Eye Of Zilla. This ImageViewer features
Image Infos, EXIF, Jpeg,Png,Gif support. It supports scaled loading of Jpegs. an smart image cache.... GUI needs some work and we need to find a bug in QCOP as well. TODO: Add Image Service for example Mailer Add ImageCanvas/Zoomer/Display
Diffstat (limited to 'noncore/graphics/opie-eye/slave/thumbnailtool.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/slave/thumbnailtool.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/slave/thumbnailtool.cpp b/noncore/graphics/opie-eye/slave/thumbnailtool.cpp
new file mode 100644
index 0000000..a202457
--- a/dev/null
+++ b/noncore/graphics/opie-eye/slave/thumbnailtool.cpp
@@ -0,0 +1,61 @@
+#include "thumbnailtool.h"
+
+#include <qfileinfo.h>
+#include <qdir.h>
+#include <qimage.h>
+#include <qpixmap.h>
+#include <qstring.h>
+
+static bool makeThumbDir( const QFileInfo& inf, bool make = false) {
+ QDir dir( inf.dirPath()+ "/.opie-eye" );
+ if ( !dir.exists() )
+ if ( make )
+ return dir.mkdir(QString::null);
+ else
+ return false;
+ return true;
+}
+
+
+/*
+ * check if the Opie opie-eye dir exists
+ * check if a thumbnail exists
+ * load the thumbnail
+ * /foo/bar/imagefoo.gif
+ * check for a png in /foo/bar/.opie-eye/%dx%d-imagefoo.gif
+ */
+QPixmap ThumbNailTool::getThumb( const QString& path, int width, int height ) {
+ QFileInfo inf( path );
+ qWarning( "Get Thumb" );
+ if ( !makeThumbDir( inf ) ) {
+ QPixmap pix;
+ return pix;
+ }
+ QString str = QString( "/.opie-eye/%1x%2-%3" ).arg( width ).arg( height ).arg( inf.fileName() );
+ qWarning( inf.dirPath()+str );
+ return QPixmap( inf.dirPath()+str,"PNG" );
+
+}
+
+void ThumbNailTool::putThumb( const QString& path, const QPixmap& pix, int width, int height ) {
+ QFileInfo inf( path );
+ makeThumbDir( inf, true );
+ QString str = QString( "/.opie-eye/%1x%2-%3" ).arg( width ).arg( height ).arg( inf.fileName() );
+ qWarning( inf.dirPath()+str );
+ pix.save( inf.dirPath()+str, "PNG" );
+}
+
+
+QPixmap ThumbNailTool::scaleImage( QImage& img, int w, int h ) {
+ double hs = (double)h / (double)img.height() ;
+ double ws = (double)w / (double)img.width() ;
+ double scaleFactor = (hs > ws) ? ws : hs;
+ int smoothW = (int)(scaleFactor * img.width());
+ int smoothH = (int)(scaleFactor * img.height());
+ QPixmap pixmap;
+ if ( img.width() <= w && img.height() <= h )
+ pixmap.convertFromImage( img );
+ else
+ pixmap.convertFromImage( img.smoothScale( smoothW, smoothH) );
+ return pixmap;
+}