Hydra 0.20
hydra.src/hydra/RotateCode.h
00001 
00002 /*
00003  * Copyright (c) 2010 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_HYDRA_ROTATETAG_H__
00009 #define __INCLUDED_HYDRA_ROTATETAG_H__
00010 
00011 #include <QImage>
00012 #include <QPixmap>
00013 
00014 #include <hydra/Records.h>
00015 
00016 namespace hydra
00017 {
00018   /**
00019    * Converts a rotate code to degrees, for display.
00020    *
00021    * @author Aleksander Demko
00022    */ 
00023   inline int rotateCodeToDegrees(int rotateCode) { return rotateCode * 90; }
00024 
00025   /**
00026    * Converts degrees to a rotate code.
00027    * Returns -1 on invalid codes.
00028    *
00029    * @author Aleksander Demko
00030    */
00031   int rotateDegreesToCode(int degrees);
00032 
00033   /**
00034    * Adds the given amount (which can be negative)o to the rotateCode
00035    * and returns the result.
00036    * The returned result is always valid (0..3)
00037    *
00038    * @author Aleksander Demko
00039    */ 
00040   int rotateCodeAdd(int rotateCode, int deltaCode);
00041 
00042   /**
00043    * Detects the auto rotation information in the file, if any.
00044    * -1 error/no exif found.
00045    * 0 do not rotate
00046    * 1 rotate 90 degrees cw
00047    * 2 rotate 180 degrees cw
00048    * 3 rotate 270 degrees cw
00049    *
00050    * If exif detection support is not compiled, this function will always return 0.
00051    *
00052    * @author Aleksander Demko
00053    */ 
00054   short detectTagRotate(const hydra::FileItemRecord::tags_t &tags);
00055 
00056   /**
00057    * Converts the given coordinates to the final coordinates, as if it where rotated by the given exif rotation
00058    * code. Node, the variables can the same (&origW == newW, etc)
00059    *
00060    * @author Aleksander Demko
00061    */ 
00062   void rotateSizeByCode(short rotatecode, unsigned long origW, unsigned long origH, unsigned long &newW, unsigned long &newH);
00063 
00064   /**
00065    * Rotates an image as per the given rotate code.
00066    * 0 do not rotate
00067    * 1 rotate 90 degrees cw
00068    * 2 rotate 180 degrees cw
00069    * 3 rotate 270 degrees cw
00070    * rotatecode must be >=0
00071    *
00072    * @author Aleksander Demko
00073    */
00074   QImage rotateImageByCode(short rotatecode, QImage &img);
00075 
00076   /**
00077    * Rotates an pixmap as per the given rotate code.
00078    * 0 do not rotate
00079    * 1 rotate 90 degrees cw
00080    * 2 rotate 180 degrees cw
00081    * 3 rotate 270 degrees cw
00082    * rotatecode must be >=0
00083    *
00084    * @author Aleksander Demko
00085    */
00086   QPixmap rotatePixmapByCode(short rotatecode, QPixmap &pix);
00087 
00088   /**
00089    * Uses both detectExifRotate and detectTagRotate to come up with a reasonable default.
00090    * Will never return -1 (will return 0 instead).
00091    *
00092    * @author Aleksander Demko
00093    */ 
00094   short detectMultiRotate(const QString &filename, const hydra::FileItemRecord::tags_t &tags);
00095 }
00096 
00097 #endif
00098 
 All Classes Namespaces Functions Variables