images::ImagesScanner Class Reference

: Scan all the images in the formats supported by gdk_pixbuf under the input directory or the directory which the input filename is located in. It also supports the option of scanning recursively or not. More...

#include <images_scanner.h>

Collaboration diagram for images::ImagesScanner:
Collaboration graph
[legend]

Public Member Functions

 ImagesScanner (void)
 Construct a 'ImagesScanner'.
 ~ImagesScanner (void)
bool is_image (const std::string &filename)
int scan_images (const std::string &filename, bool to_scan_dir, bool recursive_flag, SortType sort_type, bool sort_ascending, Images &results)
 Set the filename or directory to scan.

Static Public Member Functions

static bool get_size (const std::string &filename, int *width, int *height)
static void get_original_rotation (const std::string &filename, PluginRotationDegree &rotation)

Detailed Description

: Scan all the images in the formats supported by gdk_pixbuf under the input directory or the directory which the input filename is located in. It also supports the option of scanning recursively or not.

Definition at line 71 of file images_scanner.h.


Constructor & Destructor Documentation

images::ImagesScanner::ImagesScanner ( void   ) 

Construct a 'ImagesScanner'.

Definition at line 54 of file images_scanner.cpp.

References LOGPRINTF.

00055 :filepath("")
00056 ,recursive(false)
00057 ,isdir(false)
00058 ,dir("")
00059 ,active(-1) 
00060 {
00061     LOGPRINTF("entry");
00062 
00063     get_supported_extnames();
00064 }

images::ImagesScanner::~ImagesScanner ( void   ) 

Definition at line 66 of file images_scanner.cpp.

References LOGPRINTF.

00067 {
00068     LOGPRINTF("entry");
00069 }


Member Function Documentation

void images::ImagesScanner::get_original_rotation ( const std::string &  filename,
PluginRotationDegree rotation 
) [static]

Definition at line 95 of file images_scanner.cpp.

References Clockwise_Degrees_0, Clockwise_Degrees_180, Clockwise_Degrees_270, Clockwise_Degrees_90, and LOGPRINTF.

00097 {
00098     LOGPRINTF("entry");
00099 
00100     // Set the default return value.
00101     rotation = Clockwise_Degrees_0;
00102 #ifndef WIN32
00103     ExifData * ped = exif_data_new_from_file (filename.c_str());
00104     if (ped == 0) { return; }
00105 
00106     ExifEntry * pee = exif_data_get_entry(ped, EXIF_TAG_ORIENTATION);
00107     if (pee == 0) 
00108     {
00109         exif_data_unref(ped);
00110         return; 
00111     }
00112 
00113     // CAUTION: The character set of the returned string is not defined.
00114     // It may be UTF-8, latin1, the native encoding of the
00115     // computer, or the native encoding of the camera.
00116     const unsigned int maxlen = 1024;
00117     char val[maxlen] = {0};
00118 
00119     if (exif_entry_get_value (pee, val, maxlen))
00120     {
00121         // Conversion table for EXIT orientation to rotation degrees.
00122         // See also:
00123         //   http://www.impulseadventure.com/photo/exif-orientation.html
00124         //   http://sylvana.net/jpegcrop/exif_orientation.html
00125         const struct
00126               {
00127                   const char                    *exif_orientation;
00128                   const PluginRotationDegree    rotation;
00129               } exif_conversion_tbl[]
00130               =
00131               {
00132                   { "top - left",     Clockwise_Degrees_0   },
00133                   { "top - right",    Clockwise_Degrees_0   },
00134                   { "bottom - right", Clockwise_Degrees_180 },
00135                   { "bottom - left",  Clockwise_Degrees_180 },
00136                   { "left - top",     Clockwise_Degrees_270 },
00137                   { "right - top",    Clockwise_Degrees_270 },
00138                   { "right - bottom", Clockwise_Degrees_90  },
00139                   { "left - bottom",  Clockwise_Degrees_90  },
00140                   { NULL,             Clockwise_Degrees_0   }
00141               };
00142 
00143         for (int i = 0; exif_conversion_tbl[i].exif_orientation; i++)
00144         {
00145             if ( strcmp(val, exif_conversion_tbl[i].exif_orientation) == 0 )
00146             {
00147                 rotation = exif_conversion_tbl[i].rotation;
00148                 break;
00149             }
00150         }
00151     }
00152     
00153     exif_data_unref(ped);
00154     ped = 0;
00155 #endif
00156     LOGPRINTF("%d", rotation);
00157 }

bool images::ImagesScanner::get_size ( const std::string &  filename,
int *  width,
int *  height 
) [static]

Definition at line 81 of file images_scanner.cpp.

Referenced by images::ImagesDocument::get_original_size().

00083 {
00084     // Set the default values.
00085     if (width) { *width = 0; }
00086     if (height) { *height = 0; }
00087     
00088     if (gdk_pixbuf_get_file_info(filename.c_str(), width, height))
00089     {
00090         return true;
00091     }
00092     return false;
00093 }

Here is the caller graph for this function:

bool images::ImagesScanner::is_image ( const std::string &  filename  ) 

Definition at line 71 of file images_scanner.cpp.

References LOGPRINTF.

Referenced by scan_images().

00072 {
00073     // Only check the extension name to imporve the performance of scanning. 
00074     bool ret = check_extname(filename);
00075 
00076     LOGPRINTF("%s is image? %d", filename.c_str(), ret);
00077 
00078     return ret;
00079 }

Here is the caller graph for this function:

int images::ImagesScanner::scan_images ( const std::string &  filename,
bool  to_scan_dir,
bool  recursive_flag,
SortType  sort_type,
bool  sort_ascending,
Images results 
)

Set the filename or directory to scan.

Parameters:
filename 
to_scan_dir Scan or not scan the directory where the filename is in.
recursive_flag Scan recursively or not.
sort_type Sort by date, size, etc.
sort_ascending Sort by ascending or descending.
Returns:
Get the index of the current active image. The current active image is the input filename. Or if the input filename is directory, the active image is the first image file found.

Definition at line 159 of file images_scanner.cpp.

References Clockwise_Degrees_0, images::Image::height, is_image(), images::Image::is_rotation_calculated, images::Image::path, images::Image::rotation, and images::Image::width.

Referenced by images::ImagesDocument::open_document().

00165 {
00166     set_filename(filename);
00167     recursive = recursive_flag;
00168 
00169     if (!to_scan_dir)
00170     {
00171         if (g_file_test(filename.c_str(), (GFileTest)G_FILE_TEST_IS_REGULAR)
00172                 && is_image(filename))
00173         {
00174             ImagePtr image = new Image;
00175             if (image)
00176             { 
00177                 image->path = filename;
00178                 image->width = -1;
00179                 image->height = -1;
00180                 image->is_rotation_calculated = false;
00181                 image->rotation = Clockwise_Degrees_0;
00182                 results.push_back(image);
00183             }
00184         }
00185     }
00186     else
00187     {
00188         // Do scanning.
00189         scan_dir(dir, results);
00190         // Do sorting.
00191         sort_images(results, sort_type, sort_ascending);
00192     }
00193 
00194     return ((active != -1) ? active : 0);
00195 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208