summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/slave/jpeg_slave.cpp
blob: 0f41359056de2230fe89f719ddb189558434c587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include  "jpeg_slave.h"
#include "thumbnailtool.h"

PHUNK_VIEW_INTERFACE( "JPEG", JpegSlave )

/* OPIE */
#include <opie2/odebug.h>
#include <opie2/opieexif.h>
#include <qpe/timestring.h>
using namespace Opie::Core;
using namespace Opie::MM;

/* QT */
#include <qobject.h>
#include <qimage.h>
static QDateTime parseDateTime( const QString& string )
{
    QDateTime dt;
    if ( string.length() != 19 )
        return dt;

    QString year    = string.left( 4 );
    QString month   = string.mid( 5, 2 );
    QString day     = string.mid( 8, 2 );
    QString hour    = string.mid( 11, 2 );
    QString minute  = string.mid( 14, 2 );
    QString seconds = string.mid( 18, 2 );

    bool ok;
    bool allOk = true;
    int y  = year.toInt( &ok );
    allOk &= ok;

    int mo = month.toInt( &ok );
    allOk &= ok;

    int d  = day.toInt( &ok );
    allOk &= ok;

    int h  = hour.toInt( &ok );
    allOk &= ok;

    int mi = minute.toInt( &ok );
    allOk &= ok;

    int s  = seconds.toInt( &ok );
    allOk &= ok;

    if ( allOk ) {
        dt.setDate( QDate( y, mo, d ) );
        dt.setTime( QTime( h, mi, s ) );
    }

    return dt;
}

JpegSlave::JpegSlave()
    : SlaveInterface(  QStringList::split( " ", "jpeg jpg" ) )
{}

JpegSlave::~JpegSlave() {}

QString JpegSlave::iconViewName( const QString& path) {
    ExifData ImageInfo;
    if ( !ImageInfo.scan( path ) )
        return QString::null;

    QString tag;
    tag  = QObject::tr( "Comment: %1\n" ).arg( ImageInfo.getComment() );
    {
// ODP fixme
        QString timestring = TimeString::dateString( parseDateTime(  ImageInfo.getDateTime() ), FALSE );
        tag += QObject::tr( "Date/Time: %1\n" ).arg( timestring );
    }
    tag += QObject::tr( "Dimensions: %1x%2\n" ).arg(ImageInfo.getWidth())
           .arg(ImageInfo.getHeight() );

    tag += ExifData::color_mode_to_string(  ImageInfo.getIsColor() );

    tag += ExifData::compression_to_string( ImageInfo.getCompressionLevel() );

    return tag;
}


/*
 * messy messy string creation
 */
QString JpegSlave::fullImageInfo( const QString& path) {
    ExifData ImageInfo;
    if ( !ImageInfo.scan( path ) )
        return QString::null;

    QString tag, tmp;
    tag   = QObject::tr( "<qt>Comment: %1\n" ).arg( ImageInfo.getComment() );

    tmp =  ImageInfo.getCameraMake();
    if ( tmp.length() )
        tag  += QObject::tr( "Manufacturer: %1\n" ).arg( tmp );
    tmp = ImageInfo.getCameraModel();
    if ( tmp.length() )
        tag += QObject::tr( "Model: %1\n" ).arg( tmp );
    {
// ODP fixme
        tmp = TimeString::dateString( parseDateTime(  ImageInfo.getDateTime() ), FALSE );
        tag += QObject::tr( "Date/Time: %1\n" ).arg( tmp );
    }
    tag += QObject::tr( "Dimensions: %1x%2\n" ).arg(ImageInfo.getWidth())
           .arg(ImageInfo.getHeight() );

    tag += ExifData::color_mode_to_string(  ImageInfo.getIsColor() );

    tag += ExifData::compression_to_string( ImageInfo.getCompressionLevel() );
    if ( ImageInfo.getOrientation() )
        tag += QObject::tr( "Orientation: %1\n" ).arg(ImageInfo.getOrientation() );


    {
        int flash_used = ImageInfo.getFlashUsed();
        if ( flash_used >= 0 )
            tag += QObject::tr( "Flash used\n" );
    }

    if ( ImageInfo.getFocalLength() ) {
        tag += QObject::tr( "Focal length: %1\n" ).arg(  QString().sprintf( "%4.1f", ImageInfo.getFocalLength() ) );
        if ( ImageInfo.getCCDWidth() )
            tag += QObject::tr( "35mm equivalent: %1\n" ).arg(  (int)(ImageInfo.getFocalLength()/ImageInfo.getCCDWidth()*35 + 0.5) );

    }

    if ( ImageInfo.getCCDWidth() )
        tag += QObject::tr( "CCD width: %1" ).arg( ImageInfo.getCCDWidth() );
    if ( ImageInfo.getExposureTime() ) {
        tmp = QString().sprintf("%4.2f", ImageInfo.getExposureTime() );
        float exposureTime = ImageInfo.getExposureTime();
        if ( exposureTime > 0 && exposureTime <= 0.5 )
            tmp += QString().sprintf(" (1/%d)", (int)(0.5 +1/exposureTime) );
        tag += QObject::tr( "Exposure time: %1\n" ).arg( tmp );
    }

    if ( ImageInfo.getApertureFNumber() )
        tag += QObject::tr( "Aperture: %1\n" ).arg(  QString().sprintf("f/%3.1f", (double)ImageInfo.getApertureFNumber() ) );

    if ( ImageInfo.getDistance() ) {
        if ( ImageInfo.getDistance() < 0 )
            tag += QObject::tr( "Distance: %1\n" ).arg( QObject::tr( "Infinite" ) );
        else
            tag += QObject::tr( "Distance: %1\n" ).arg( QString().sprintf( "%5.2fm", (double)ImageInfo.getDistance() ) );
    }

    if ( ImageInfo.getExposureBias() ) {
        tag += QObject::tr( "Exposure bias: %1\n", QString().sprintf("%4.2f", (double)ImageInfo.getExposureBias() ) );
    }

    if ( ImageInfo.getWhitebalance() != -1 )
        tag += ExifData::white_balance_string( ImageInfo.getWhitebalance() );


    if( ImageInfo.getMeteringMode() != -1 )
        tag += ExifData::metering_mode( ImageInfo.getMeteringMode() );

    if ( ImageInfo.getExposureProgram() )
        tag += ExifData::exposure_program( ImageInfo.getExposureProgram() );
    if ( ImageInfo.getISOequivalent() )
        tag += QObject::tr( "ISO equivalent: %1\n" ).arg( QString().sprintf("%2d", ImageInfo.getISOequivalent() ) );

    tmp = ImageInfo.getUserComment();
    if ( tmp.length() )
        tag += QObject::tr( "EXIF comment: %1" ).arg( tmp );

    tag += QObject::tr( "</qt>" );



    return tag;
}

QPixmap JpegSlave::pixmap( const QString& path, int wid, int hei) {
    ExifData ImageInfo;
    /*
     */
    if ( !ImageInfo.scan( path ) || ImageInfo.isNullThumbnail() ) {
        QImage img;
        QImageIO iio( path, 0l );
        if (wid < ImageInfo.getWidth() || hei<ImageInfo.getHeight()) {
            QString str = QString( "Fast Shrink( 4 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei );
            iio.setParameters( str.latin1() );// will be strdupped anyway
        } else {
        }
        img = iio.read() ? iio.image() : QImage();
        return ThumbNailTool::scaleImage(  img, wid,hei );
    }else{
        QImage img = ImageInfo.getThumbnail();
        return ThumbNailTool::scaleImage(  img, wid,hei );
    }
}