images::ImagePage Class Reference

#include <image_page.h>

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

Public Member Functions

 ImagePage (const std::string &p, const ImagePageAttrs &request)
 ~ImagePage (void)
bool render (void)
 Render image with specified request.
const ImagePageAttrsattributes () const
 Retrieve the attributes of render result.
const std::string & get_path () const
 Retrieve the image path.
size_t operator() (void) const
bool operator== (const ImagePage &right)
bool operator< (const ImagePage &right)
bool operator> (const ImagePage &right)
int length (void)
void update_timestamp (void)
void set_in_use_flag (bool flag)
bool get_in_use_flag (void)

Static Public Member Functions

static int max_zoom_factor ()
static int min_zoom_factor ()
static size_t calc_key (const std::string &anchor, int width, int height, float zoom, int rotation)
static void calc_desired_dimension (ImagePageAttrs &request)
static gint64 estimate_length (const ImagePageAttrs &request)
static PluginRotationDegree check_autorotate (int w, int h, int display_w, int display_h)

Detailed Description

Represent each image. Through this class, caller is able to

Definition at line 108 of file image_page.h.


Constructor & Destructor Documentation

images::ImagePage::ImagePage ( const std::string &  p,
const ImagePageAttrs request 
)

Definition at line 50 of file image_page.cpp.

References images::ImagePageAttrs::desired_color_depth, images::ImagePageAttrs::desired_height, images::ImagePageAttrs::desired_width, images::ImagePageAttrs::final_rotation, LOGPRINTF, images::ImagePageAttrs::original_height, images::ImagePageAttrs::original_width, images::ImagePageAttrs::rotation, and images::ImagePageAttrs::zoom.

00052 : path(p)
00053 , in_use(false)
00054 , timestamp(0)
00055 , loader(0)
00056 , valid(false)
00057 {
00058     LOGPRINTF("%s", p.c_str());
00059     
00060     attrs.original_width      = request.original_width;
00061     attrs.original_height     = request.original_height;
00062     attrs.desired_width       = request.desired_width;
00063     attrs.desired_height      = request.desired_height;
00064     attrs.desired_color_depth = request.desired_color_depth;
00065 
00066     attrs.zoom           = request.zoom;
00067     attrs.rotation       = request.rotation;
00068     attrs.final_rotation = request.final_rotation;
00069 
00070     display_width  = request.desired_width;
00071     display_height = request.desired_height;
00072 }

images::ImagePage::~ImagePage ( void   ) 

Definition at line 74 of file image_page.cpp.

References LOGPRINTF.

00075 {
00076     LOGPRINTF("entry %s", path.c_str());
00077 
00078     destroy();
00079 }


Member Function Documentation

const ImagePageAttrs& images::ImagePage::attributes (  )  const [inline]

Retrieve the attributes of render result.

Definition at line 120 of file image_page.h.

00120 { return attrs; }

void images::ImagePage::calc_desired_dimension ( ImagePageAttrs request  )  [static]

Definition at line 125 of file image_page.cpp.

References check_autorotate(), Clockwise_Degrees_270, Clockwise_Degrees_360, Clockwise_Degrees_90, images::ImagePageAttrs::desired_height, images::ImagePageAttrs::desired_width, images::ImagePageAttrs::final_rotation, images::ImagePageAttrs::original_height, images::ImagePageAttrs::original_width, PLUGIN_ZOOM_TO_CROP_BY_PAGE, PLUGIN_ZOOM_TO_CROP_BY_WIDTH, PLUGIN_ZOOM_TO_PAGE, PLUGIN_ZOOM_TO_WIDTH, images::ImagePageAttrs::rotation, rotation, and images::ImagePageAttrs::zoom.

Referenced by estimate_length().

00126 {
00127     int w = request.original_width;
00128     int h = request.original_height;
00129     unsigned int display_w = request.desired_width;
00130     unsigned int display_h = request.desired_height;
00131     
00132     PluginRotationDegree autorotate = check_autorotate(w, h, display_w, display_h);
00133 
00134     // TODO: Correct for autorotation, if needed.
00135     int rotation = static_cast<int>(request.rotation);
00136     rotation = (rotation + autorotate) % Clockwise_Degrees_360;
00137     request.final_rotation = static_cast<PluginRotationDegree>(rotation);
00138     if (   rotation == Clockwise_Degrees_90
00139         || rotation == Clockwise_Degrees_270)
00140     {
00141         w = request.original_height;
00142         h = request.original_width;
00143         request.original_width = w;
00144         request.original_height = h;
00145     }
00146 
00147     // Calculate the desired width and height.
00148     if (request.zoom == PLUGIN_ZOOM_TO_PAGE ||
00149         request.zoom == PLUGIN_ZOOM_TO_CROP_BY_PAGE)
00150     {
00151         float ratio_width = static_cast<float>(request.desired_width) /
00152                              static_cast<float>(w);
00153 
00154         float ratio_height = static_cast<float>(request.desired_height) /
00155                               static_cast<float>(h);
00156 
00157         if (ratio_width > ratio_height)
00158         {
00159             request.desired_width = static_cast<int>(ratio_height * w);
00160         }
00161         else
00162         {
00163             request.desired_height = static_cast<int>(ratio_width * h);
00164         }
00165     }
00166     else if (request.zoom == PLUGIN_ZOOM_TO_WIDTH ||
00167              request.zoom == PLUGIN_ZOOM_TO_CROP_BY_WIDTH)
00168     {
00169         float ratio_width = static_cast<float>(request.desired_width) /
00170                              static_cast<float>(w);
00171         request.desired_height = static_cast<int>(h * ratio_width);
00172     }
00173     else if (request.zoom > 0)
00174     {
00175         request.desired_width = static_cast<int>(
00176             static_cast<float>(request.zoom * w) / static_cast<float>(100));
00177         request.desired_height = static_cast<int>(
00178             static_cast<float>(request.zoom * h) / static_cast<float>(100));
00179     }
00180 }

Here is the call graph for this function:

Here is the caller graph for this function:

size_t images::ImagePage::calc_key ( const std::string &  anchor,
int  width,
int  height,
float  zoom,
int  rotation 
) [static]

Definition at line 460 of file image_page.cpp.

References LOGPRINTF, make_hash_code(), and MAX_PATH_LEN.

Referenced by images::ImagesRenderer::get_page(), and operator()().

00465 {
00466     struct PageKey
00467     {
00468         char   anchor[MAX_PATH_LEN]; 
00469         int    display_width;        // display size
00470         int    display_height;
00471         float  zoom;
00472         int    rotation;
00473     };
00474 
00475     PageKey key;
00476     int len = sizeof(PageKey);
00477     memset(&key, 0, len);
00478     
00479     memcpy(key.anchor, anchor.c_str(), strlen(anchor.c_str()));
00480     key.display_width = width;
00481     key.display_height = height;
00482     key.zoom = zoom;
00483     key.rotation = rotation;
00484 
00485     size_t h = make_hash_code((const char*)&key, len);
00486 
00487     LOGPRINTF("return %d", h);
00488 
00489     return h;
00490 }

Here is the call graph for this function:

Here is the caller graph for this function:

PluginRotationDegree images::ImagePage::check_autorotate ( int  w,
int  h,
int  display_w,
int  display_h 
) [static]

Definition at line 604 of file image_page.cpp.

References Clockwise_Degrees_0, Clockwise_Degrees_270, and Clockwise_Degrees_90.

Referenced by calc_desired_dimension().

00605 {
00606     // Image fits on screen: no autorotation.
00607     if ((w <= display_w) && (h <= display_h))
00608     {
00609         return Clockwise_Degrees_0;
00610     }
00611 
00612     // Portrait image on landscape display: autorotate.
00613     if ((w < h) && (display_w > display_h))
00614     {
00615         return Clockwise_Degrees_270;
00616     }
00617 
00618     // Landscape image on portrait dislay: autorotate.
00619     if ((w > h) && (display_w < display_h))
00620     {
00621         return Clockwise_Degrees_90;
00622     }
00623 
00624     return Clockwise_Degrees_0;
00625 }

Here is the caller graph for this function:

gint64 images::ImagePage::estimate_length ( const ImagePageAttrs request  )  [static]

Definition at line 547 of file image_page.cpp.

References calc_desired_dimension(), images::ImagePageAttrs::desired_color_depth, images::ImagePageAttrs::desired_height, images::ImagePageAttrs::desired_width, images::ImageDither::get_rowstride(), LOGPRINTF, images::ImagePageAttrs::original_height, and images::ImagePageAttrs::original_width.

Referenced by images::ImagesRenderer::can_render().

00549 {
00550     ImagePageAttrs attrs(request);
00551 
00552     calc_desired_dimension(attrs);
00553 
00554     // Memory size needed for bitmap to UDS.
00555     int rowstride = ImageDither::get_rowstride(attrs.desired_width, 
00556                                                attrs.desired_color_depth / 8,
00557                                                4);
00558     gint64 size_for_bitmap = static_cast<gint64>(rowstride) *
00559                              static_cast<gint64>(attrs.desired_height);
00560 
00561     // Memory size needed temporarily while rendering.
00562     gint64 size_for_tmp = size_for_bitmap * 5;
00563 
00564     // Memory size that must be available to render this image.
00565     gint64 size = size_for_bitmap + size_for_tmp;
00566     
00567     LOGPRINTF("original [%d %d] desired [%d %d] memory [%lld %lld %lld]",
00568               attrs.original_width, attrs.original_height,
00569               attrs.desired_width, attrs.desired_height,
00570               size_for_bitmap, size_for_tmp, size);
00571     
00572     return size;
00573 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool images::ImagePage::get_in_use_flag ( void   )  [inline]

Definition at line 161 of file image_page.h.

00161 { return in_use; }

const std::string& images::ImagePage::get_path (  )  const [inline]

Retrieve the image path.

Definition at line 123 of file image_page.h.

00123 { return path; }

int images::ImagePage::length ( void   ) 

Definition at line 538 of file image_page.cpp.

References images::ImagePageAttrs::desired_height, LOGPRINTF, and images::ImagePageAttrs::row_stride.

Referenced by images::PagesCache::add_page(), and main().

00539 {
00540     int size = attrs.row_stride * attrs.desired_height;
00541     
00542     LOGPRINTF("return %d", size);
00543 
00544     return size;
00545 }

Here is the caller graph for this function:

static int images::ImagePage::max_zoom_factor (  )  [inline, static]

Definition at line 125 of file image_page.h.

00125 { return 400; }

static int images::ImagePage::min_zoom_factor (  )  [inline, static]

Definition at line 127 of file image_page.h.

00127 { return 10; }

size_t images::ImagePage::operator() ( void   )  const

Definition at line 454 of file image_page.cpp.

References calc_key(), images::ImagePageAttrs::rotation, and images::ImagePageAttrs::zoom.

00455 {
00456     return calc_key(path, display_width, display_height, 
00457                     attrs.zoom, attrs.rotation);
00458 }

Here is the call graph for this function:

bool images::ImagePage::operator< ( const ImagePage right  ) 

Definition at line 511 of file image_page.cpp.

References LOGPRINTF.

00512 {
00513    if (this->in_use && !right.in_use)
00514    {
00515        return false;
00516    }
00517    else if (!this->in_use && right.in_use)
00518    {
00519        return true;
00520    }
00521    else
00522    {
00523         LOGPRINTF("%ld < %ld ? %d", 
00524                 this->timestamp, right.timestamp, 
00525                 this->timestamp < right.timestamp);
00526 
00527         return (this->timestamp < right.timestamp);
00528    }
00529 }

bool images::ImagePage::operator== ( const ImagePage right  ) 

Definition at line 493 of file image_page.cpp.

References LOGPRINTF, images::ImagePageAttrs::rotation, and images::ImagePageAttrs::zoom.

00494 {
00495     LOGPRINTF("entry");
00496 
00497     // Note: Ignore final_rotation for comparison
00498     if ((path == right.path)
00499         && (this->attrs.zoom == right.attrs.zoom)
00500         && (this->attrs.rotation == right.attrs.rotation)
00501         && (this->display_width == right.display_width)
00502         && (this->display_height == right.display_height))
00503     {
00504         return true;
00505     }
00506 
00507     return false;
00508 }

bool images::ImagePage::operator> ( const ImagePage right  ) 

Definition at line 532 of file image_page.cpp.

00533 {
00534     return !((*this) < right);
00535 }

bool images::ImagePage::render ( void   ) 

Render image with specified request.

Definition at line 98 of file image_page.cpp.

References LOGPRINTF.

Referenced by images::ImageRenderTask::execute().

00099 {
00100     LOGPRINTF("entry: anchor [%s]", anchor.c_str());
00101 
00102     if (!try_to_load_at_scale())
00103     {
00104         return false;
00105     }
00106 
00107     if (!update_attributes())
00108     {
00109         return false;
00110     }
00111 
00112     if (!try_to_dither())
00113     {
00114         return false;
00115     }
00116 
00117     if (!try_to_rotate_grey())
00118     {
00119         return false;
00120     }
00121 
00122     return true;
00123 }

Here is the caller graph for this function:

void images::ImagePage::set_in_use_flag ( bool  flag  )  [inline]

Definition at line 159 of file image_page.h.

Referenced by images::PluginRenderResultImpl::set_page(), and images::PluginRenderResultImpl::~PluginRenderResultImpl().

00159 { in_use = flag; }

Here is the caller graph for this function:

void images::ImagePage::update_timestamp ( void   ) 

Definition at line 575 of file image_page.cpp.

Referenced by images::ImagesRenderer::notify_page_ready().

00576 {
00577 #ifdef WIN32
00578     timestamp = GetTickCount();
00579 #else
00580     struct sysinfo s_info;
00581     sysinfo(&s_info);
00582     timestamp = s_info.uptime;
00583 #endif
00584 }

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