00001 #include "jpeg_slave.h"
00002 #include "thumbnailtool.h"
00003
00004 PHUNK_VIEW_INTERFACE( "JPEG", JpegSlave )
00005
00006
00007 #include <opie2/odebug.h>
00008 #include <opie2/opieexif.h>
00009 #include <qpe/timestring.h>
00010 using namespace Opie::Core;
00011 using namespace Opie::MM;
00012
00013
00014 #include <qobject.h>
00015 #include <qimage.h>
00016 static QDateTime parseDateTime( const QString& string )
00017 {
00018 QDateTime dt;
00019 if ( string.length() != 19 )
00020 return dt;
00021
00022 QString year = string.left( 4 );
00023 QString month = string.mid( 5, 2 );
00024 QString day = string.mid( 8, 2 );
00025 QString hour = string.mid( 11, 2 );
00026 QString minute = string.mid( 14, 2 );
00027 QString seconds = string.mid( 18, 2 );
00028
00029 bool ok;
00030 bool allOk = true;
00031 int y = year.toInt( &ok );
00032 allOk &= ok;
00033
00034 int mo = month.toInt( &ok );
00035 allOk &= ok;
00036
00037 int d = day.toInt( &ok );
00038 allOk &= ok;
00039
00040 int h = hour.toInt( &ok );
00041 allOk &= ok;
00042
00043 int mi = minute.toInt( &ok );
00044 allOk &= ok;
00045
00046 int s = seconds.toInt( &ok );
00047 allOk &= ok;
00048
00049 if ( allOk ) {
00050 dt.setDate( QDate( y, mo, d ) );
00051 dt.setTime( QTime( h, mi, s ) );
00052 }
00053
00054 return dt;
00055 }
00056
00057 JpegSlave::JpegSlave()
00058 : SlaveInterface( QStringList::split( " ", "jpeg jpg" ) )
00059 {}
00060
00061 JpegSlave::~JpegSlave() {}
00062
00063 QString JpegSlave::iconViewName( const QString& path) {
00064 ExifData ImageInfo;
00065 if ( !ImageInfo.scan( path ) )
00066 return QString::null;
00067
00068 QString tag;
00069 tag = QObject::tr( "Comment: %1\n" ).arg( ImageInfo.getComment() );
00070 {
00071
00072 QString timestring = TimeString::dateString( parseDateTime( ImageInfo.getDateTime() ), FALSE );
00073 tag += QObject::tr( "Date/Time: %1\n" ).arg( timestring );
00074 }
00075 tag += QObject::tr( "Dimensions: %1x%2\n" ).arg(ImageInfo.getWidth())
00076 .arg(ImageInfo.getHeight() );
00077
00078 tag += ExifData::color_mode_to_string( ImageInfo.getIsColor() );
00079
00080 tag += ExifData::compression_to_string( ImageInfo.getCompressionLevel() );
00081
00082 return tag;
00083 }
00084
00085
00086
00087
00088
00089 QString JpegSlave::fullImageInfo( const QString& path) {
00090 ExifData ImageInfo;
00091 if ( !ImageInfo.scan( path ) )
00092 return QString::null;
00093
00094 QString tag, tmp;
00095 tag = QObject::tr( "<qt>Comment: %1\n" ).arg( ImageInfo.getComment() );
00096
00097 tmp = ImageInfo.getCameraMake();
00098 if ( tmp.length() )
00099 tag += QObject::tr( "Manufacturer: %1\n" ).arg( tmp );
00100 tmp = ImageInfo.getCameraModel();
00101 if ( tmp.length() )
00102 tag += QObject::tr( "Model: %1\n" ).arg( tmp );
00103 {
00104
00105 tmp = TimeString::dateString( parseDateTime( ImageInfo.getDateTime() ), FALSE );
00106 tag += QObject::tr( "Date/Time: %1\n" ).arg( tmp );
00107 }
00108 tag += QObject::tr( "Dimensions: %1x%2\n" ).arg(ImageInfo.getWidth())
00109 .arg(ImageInfo.getHeight() );
00110
00111 tag += ExifData::color_mode_to_string( ImageInfo.getIsColor() );
00112
00113 tag += ExifData::compression_to_string( ImageInfo.getCompressionLevel() );
00114 if ( ImageInfo.getOrientation() )
00115 tag += QObject::tr( "Orientation: %1\n" ).arg(ImageInfo.getOrientation() );
00116
00117
00118 {
00119 int flash_used = ImageInfo.getFlashUsed();
00120 if ( flash_used >= 0 )
00121 tag += QObject::tr( "Flash used\n" );
00122 }
00123
00124 if ( ImageInfo.getFocalLength() ) {
00125 tag += QObject::tr( "Focal length: %1\n" ).arg( QString().sprintf( "%4.1f", ImageInfo.getFocalLength() ) );
00126 if ( ImageInfo.getCCDWidth() )
00127 tag += QObject::tr( "35mm equivalent: %1\n" ).arg( (int)(ImageInfo.getFocalLength()/ImageInfo.getCCDWidth()*35 + 0.5) );
00128
00129 }
00130
00131 if ( ImageInfo.getCCDWidth() )
00132 tag += QObject::tr( "CCD width: %1" ).arg( ImageInfo.getCCDWidth() );
00133 if ( ImageInfo.getExposureTime() ) {
00134 tmp = QString().sprintf("%4.2f", ImageInfo.getExposureTime() );
00135 float exposureTime = ImageInfo.getExposureTime();
00136 if ( exposureTime > 0 && exposureTime <= 0.5 )
00137 tmp += QString().sprintf(" (1/%d)", (int)(0.5 +1/exposureTime) );
00138 tag += QObject::tr( "Exposure time: %1\n" ).arg( tmp );
00139 }
00140
00141 if ( ImageInfo.getApertureFNumber() )
00142 tag += QObject::tr( "Aperture: %1\n" ).arg( QString().sprintf("f/%3.1f", (double)ImageInfo.getApertureFNumber() ) );
00143
00144 if ( ImageInfo.getDistance() ) {
00145 if ( ImageInfo.getDistance() < 0 )
00146 tag += QObject::tr( "Distance: %1\n" ).arg( QObject::tr( "Infinite" ) );
00147 else
00148 tag += QObject::tr( "Distance: %1\n" ).arg( QString().sprintf( "%5.2fm", (double)ImageInfo.getDistance() ) );
00149 }
00150
00151 if ( ImageInfo.getExposureBias() ) {
00152 tag += QObject::tr( "Exposure bias: %1\n", QString().sprintf("%4.2f", (double)ImageInfo.getExposureBias() ) );
00153 }
00154
00155 if ( ImageInfo.getWhitebalance() != -1 )
00156 tag += ExifData::white_balance_string( ImageInfo.getWhitebalance() );
00157
00158
00159 if( ImageInfo.getMeteringMode() != -1 )
00160 tag += ExifData::metering_mode( ImageInfo.getMeteringMode() );
00161
00162 if ( ImageInfo.getExposureProgram() )
00163 tag += ExifData::exposure_program( ImageInfo.getExposureProgram() );
00164 if ( ImageInfo.getISOequivalent() )
00165 tag += QObject::tr( "ISO equivalent: %1\n" ).arg( QString().sprintf("%2d", ImageInfo.getISOequivalent() ) );
00166
00167 tmp = ImageInfo.getUserComment();
00168 if ( tmp.length() )
00169 tag += QObject::tr( "EXIF comment: %1" ).arg( tmp );
00170
00171 tag += QObject::tr( "</qt>" );
00172
00173
00174
00175 return tag;
00176 }
00177
00178 QPixmap JpegSlave::pixmap( const QString& path, int wid, int hei) {
00179 ExifData ImageInfo;
00180
00181
00182 if ( !ImageInfo.scan( path ) || ImageInfo.isNullThumbnail() ) {
00183 QImage img;
00184 QImageIO iio( path, 0l );
00185 if (wid < ImageInfo.getWidth() || hei<ImageInfo.getHeight()) {
00186 QString str = QString( "Fast Shrink( 4 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei );
00187 iio.setParameters( str.latin1() );
00188 } else {
00189 }
00190 img = iio.read() ? iio.image() : QImage();
00191 return ThumbNailTool::scaleImage( img, wid,hei );
00192 }else{
00193 QImage img = ImageInfo.getThumbnail();
00194 return ThumbNailTool::scaleImage( img, wid,hei );
00195 }
00196 }