[Digikam-devel] extragear/graphics/digikam
Gilles Caulier
caulier.gilles at free.fr
Tue Feb 28 13:43:39 GMT 2006
SVN commit 514442 by cgilles:
digikam from trunk : capability to rotate automaticly thumbnail from RAW (tiff file based) accordinly to tiff orientation tag (NEF file for example). The code is based on Raw KFile plugin.
CCMAIL: digikam-devel at kde.org
M +26 -2 kioslave/digikamthumbnail.cpp
M +17 -1 libs/dcraw/dcraw_parse.cpp
M +6 -1 libs/dcraw/dcraw_parse.h
M +27 -2 utilities/cameragui/umscamera.cpp
--- trunk/extragear/graphics/digikam/kioslave/digikamthumbnail.cpp #514441:514442
@@ -583,15 +583,39 @@
KTempFile thumbFile(QString::null, "rawthumb");
thumbFile.setAutoDelete(true);
Digikam::DcrawParse rawFileParser;
-
+ int orientation = 0;
+
if (thumbFile.status() == 0)
{
if (rawFileParser.getThumbnail(QFile::encodeName(path),
- QFile::encodeName(thumbFile.name())) == 0)
+ QFile::encodeName(thumbFile.name()),
+ &orientation) == 0)
{
image.load(thumbFile.name());
if (!image.isNull())
+ {
+ if(orientation)
+ {
+ QWMatrix M;
+ QWMatrix flip = QWMatrix(-1, 0, 0, 1, 0, 0);
+
+ switch(orientation+1)
+ { // notice intentional fallthroughs
+ case 2: M = flip; break;
+ case 4: M = flip;
+ case 3: M.rotate(180); break;
+ case 5: M = flip;
+ case 6: M.rotate(90); break;
+ case 7: M = flip;
+ case 8: M.rotate(270); break;
+ default: break; // should never happen
+ }
+
+ image = image.xForm(M);
+ }
+
return true;
+ }
}
}
--- trunk/extragear/graphics/digikam/libs/dcraw/dcraw_parse.cpp #514441:514442
@@ -56,6 +56,7 @@
DcrawParse::DcrawParse()
{
order = 0;
+ flip = 0;
}
DcrawParse::~DcrawParse()
@@ -401,6 +402,9 @@
case 0x111: /* StripOffset */
if (!offset || is_dng) offset = val;
break;
+ case 0x112: /* Orientation */
+ flip = flip_map[(val-1) & 7]; // From KFile-Plugins:parse.c to get thumb orientation.
+ break;
case 0x117: /* StripByteCounts */
if (!length || is_dng) length = val;
if (offset > val && !strncmp(make,"KODAK",5) && !is_dng)
@@ -1206,7 +1210,7 @@
Get embedded thumbnail in RAW file. Return nonzero if the file cannot be decoded.
*/
-int DcrawParse::getThumbnail(const char* infile, const char* outfile)
+int DcrawParse::getThumbnail(const char* infile, const char* outfile, int* orientation)
{
char head[32], *thumb, *rgb, *cp;
unsigned hlen, fsize, toff, tlen, lsize, i;
@@ -1314,6 +1318,18 @@
free (thumb);
done:
fclose (tfp);
+
+ // From KFile-Plugins:parse.c to get thumb orientation.
+
+ /* Coffin's code has different meaning for orientation
+ values than TIFF, so we map them to TIFF values */
+ switch ((flip+3600) % 360) {
+ case 270: flip = 5; break;
+ case 180: flip = 3; break;
+ case 90: flip = 6;
+ }
+ if( orientation ) *orientation = flip_map[flip%7];
+
return 0;
}
--- trunk/extragear/graphics/digikam/libs/dcraw/dcraw_parse.h #514441:514442
@@ -28,14 +28,17 @@
namespace Digikam
{
+static const int flip_map[] = { 0,1,3,2,4,7,5,6 };
+
class DIGIKAM_EXPORT DcrawParse
{
+
public:
DcrawParse();
~DcrawParse();
- int getThumbnail(const char* infile, const char* outfile);
+ int getThumbnail(const char* infile, const char* outfile, int* orientation);
int getCameraModel(const char* infile, char* cameraConstructor, char* cameraModel);
private:
@@ -57,6 +60,8 @@
int width, height, offset, length, bps, is_dng;
int thumb_offset, thumb_length, thumb_layers;
+ int flip; // From KFile-Plugins:parse.c to get thumb orientation.
+
private:
ushort sget2 (uchar *s);
--- trunk/extragear/graphics/digikam/utilities/cameragui/umscamera.cpp #514441:514442
@@ -38,6 +38,7 @@
#include <qfile.h>
#include <qstringlist.h>
#include <qdeepcopy.h>
+#include <qwmatrix.h>
// KDE includes.
@@ -201,15 +202,39 @@
KTempFile thumbFile(QString::null, "camerarawthumb");
thumbFile.setAutoDelete(true);
DcrawParse rawFileParser;
-
+ int orientation = 0;
+
if (thumbFile.status() == 0)
{
if (rawFileParser.getThumbnail(QFile::encodeName(folder + "/" + itemName),
- QFile::encodeName(thumbFile.name())) == 0)
+ QFile::encodeName(thumbFile.name()),
+ &orientation) == 0)
{
thumbnail.load(thumbFile.name());
if (!thumbnail.isNull())
+ {
+ if(orientation)
+ {
+ QWMatrix M;
+ QWMatrix flip = QWMatrix(-1, 0, 0, 1, 0, 0);
+
+ switch(orientation+1)
+ { // notice intentional fallthroughs
+ case 2: M = flip; break;
+ case 4: M = flip;
+ case 3: M.rotate(180); break;
+ case 5: M = flip;
+ case 6: M.rotate(90); break;
+ case 7: M = flip;
+ case 8: M.rotate(270); break;
+ default: break; // should never happen
+ }
+
+ thumbnail = thumbnail.xForm(M);
+ }
+
return true;
+ }
}
}
More information about the Digikam-devel
mailing list