image_page.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _IMAGE_PAGE_H_
00028 #define _IMAGE_PAGE_H_
00029
00030 #include <string>
00031 #include <gdk-pixbuf/gdk-pixbuf-core.h>
00032
00033 #include "plugin_type.h"
00034
00035 namespace images
00036 {
00037
00038 static const int DEFAULT_COLOR_DEPTH = 8;
00039
00040 static const float DEFAULT_ZOOM_FACTOR = 100.0f;
00041
00042 static const PluginRotationDegree DEFAULT_ROTATION = Clockwise_Degrees_0;
00043
00044
00045 struct ImagePageAttrs
00046 {
00047 int original_width;
00048 int original_height;
00049 int desired_width;
00050 int desired_height;
00051 int row_stride;
00052 int original_color_depth;
00053 int desired_color_depth;
00054 float zoom;
00055
00056
00057
00058
00059 PluginRotationDegree rotation;
00060 PluginRotationDegree final_rotation;
00061 unsigned char *data;
00062
00063
00064 ImagePageAttrs()
00065 : original_width(0)
00066 , original_height(0)
00067 , desired_width(0)
00068 , desired_height(0)
00069 , row_stride(0)
00070 , original_color_depth(0)
00071 , desired_color_depth(DEFAULT_COLOR_DEPTH)
00072 , zoom(DEFAULT_ZOOM_FACTOR)
00073 , rotation(DEFAULT_ROTATION)
00074 , final_rotation(DEFAULT_ROTATION)
00075 , data(0)
00076 {}
00077
00078
00079 inline ImagePageAttrs & operator = (const ImagePageAttrs & right)
00080 {
00081 if (this != &right)
00082 {
00083 original_width = right.original_width;
00084 original_height = right.original_height;
00085 desired_width = right.desired_width;
00086 desired_height = right.desired_height;
00087 row_stride = right.row_stride;
00088 desired_color_depth = right.desired_color_depth;
00089 zoom = right.zoom;
00090 rotation = right.rotation;
00091 final_rotation = right.final_rotation;
00092 data = right.data;
00093 }
00094 return *this;
00095 }
00096 };
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 class ImagePage
00109 {
00110 public:
00111 ImagePage(const std::string & p,
00112 const ImagePageAttrs & request);
00113 ~ImagePage(void);
00114
00115 public:
00116
00117 bool render(void);
00118
00119
00120 const ImagePageAttrs & attributes() const { return attrs; }
00121
00122
00123 const std::string & get_path() const { return path; }
00124
00125 static int max_zoom_factor() { return 400; }
00126
00127 static int min_zoom_factor() { return 10; }
00128
00129 static size_t calc_key(const std::string & anchor,
00130 int width,
00131 int height,
00132 float zoom,
00133 int rotation);
00134
00135
00136 size_t operator()(void) const;
00137
00138
00139 bool operator == (const ImagePage & right);
00140
00141
00142 bool operator < (const ImagePage & right);
00143
00144
00145 bool operator > (const ImagePage & right);
00146
00147
00148 int length(void);
00149
00150
00151 static void calc_desired_dimension(ImagePageAttrs & request);
00152
00153
00154 static gint64 estimate_length(const ImagePageAttrs & request);
00155
00156
00157 void update_timestamp(void);
00158
00159 void set_in_use_flag(bool flag) { in_use = flag; }
00160
00161 bool get_in_use_flag(void) { return in_use; }
00162
00163 static PluginRotationDegree check_autorotate(int w, int h, int display_w, int display_h);
00164
00165 private:
00166
00167 void init_type_system(void);
00168
00169
00170
00171 bool try_to_load_at_scale(void);
00172
00173
00174
00175 bool try_to_rotate_grey(void);
00176
00177
00178
00179 bool try_to_dither(void);
00180
00181
00182 bool update_attributes(void);
00183
00184
00185 void destroy();
00186
00187 private:
00188 std::string path;
00189 ImagePageAttrs attrs;
00190
00191
00192
00193
00194 bool in_use;
00195
00196 int display_width;
00197 int display_height;
00198
00199 long timestamp;
00200
00201 static bool g_type_initialize;
00202 GdkPixbuf *loader;
00203 bool valid;
00204 };
00205
00206 };
00207
00208 #endif
00209
00210