root/core/live_view.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. live_view_get_data

   1 #include "camera_info.h"
   2 #include "stdlib.h"
   3 #include "conf.h"
   4 #include "viewport.h"
   5 #include "ptp_chdk.h"
   6 #include "live_view.h"
   7 
   8 /*
   9 send selected data for live view
  10 returns 0 on error, total size on success
  11 should only be called from ptp handler
  12 */
  13 int live_view_get_data(ptp_data *data, int flags) {
  14     int vp_size = 0,bm_size = 0,bmo_size = 0,pal_size = 0;
  15     lv_data_header *lv;
  16     lv_framebuffer_desc *vp;
  17     lv_framebuffer_desc *bm;
  18     lv_framebuffer_desc *bmo;
  19 
  20     // determine if we will send palette so it can go in one send
  21     if ( flags & LV_TFR_PALETTE ) // bitmap palette
  22     {
  23         // if no palette, will be set to zero
  24         pal_size = vid_get_palette_size();
  25     }
  26     
  27     // one contiguous buffer to allow a single send call
  28     int buf_size = sizeof(lv_data_header) + sizeof(lv_framebuffer_desc)*3 + pal_size;
  29     void *buf = malloc(buf_size);
  30     if(!buf) {
  31         return 0;
  32     }
  33     lv = buf;
  34 
  35     lv->vp_desc_start = sizeof(lv_data_header);
  36     lv->bm_desc_start = lv->vp_desc_start+sizeof(lv_framebuffer_desc);
  37     lv->bmo_desc_start = lv->bm_desc_start+sizeof(lv_framebuffer_desc);
  38 
  39     vp = buf + lv->vp_desc_start;
  40     bm = buf + lv->bm_desc_start;
  41     bmo = buf + lv->bmo_desc_start;
  42 
  43     lv->version_major = LIVE_VIEW_VERSION_MAJOR;
  44     lv->version_minor = LIVE_VIEW_VERSION_MINOR;
  45 
  46     lv->lcd_aspect_ratio = vid_get_aspect_ratio();
  47 
  48     lv->palette_type = vid_get_palette_type();
  49     lv->palette_data_start = 0;
  50 
  51     vp->fb_type = vid_get_viewport_type();
  52 
  53     vp->buffer_width = vid_get_viewport_buffer_width_proper();
  54 
  55     vp->visible_width = vid_get_viewport_width_proper();
  56     vp->visible_height = vid_get_viewport_height_proper();
  57 
  58     vp->margin_left = vid_get_viewport_display_xoffset_proper();
  59     vp->margin_top = vid_get_viewport_display_yoffset_proper();
  60 
  61     // TODO returning margins from lib.c might be better
  62     // can end up with negative if size and offset sources don't update at exactly the same time
  63     vp->margin_right = vid_get_viewport_fullscreen_width() - vp->visible_width - vp->margin_left;
  64     vp->margin_bot = vid_get_viewport_fullscreen_height() - vp->visible_height - vp->margin_top;
  65 
  66 // TODO maybe should be function like viewport
  67 #ifndef THUMB_FW
  68     bm->fb_type = LV_FB_PAL8;
  69 #else
  70     bm->fb_type = LV_FB_YUV8B;
  71 #endif
  72     bm->buffer_width = camera_screen.buffer_width;
  73 
  74     bm->margin_left = 0;
  75     bm->margin_top = 0;
  76     bm->margin_right = 0;
  77     bm->margin_bot = 0;
  78 
  79     bm->visible_width = camera_screen.physical_width;
  80     bm->visible_height = camera_screen.height;
  81 
  82 // type is always set to OPACITY8 even if camera doesn't have, we won't have a "none" define.
  83     bmo->fb_type = LV_FB_OPACITY8;
  84 // for pre-d6, all values set to 0
  85 #ifndef THUMB_FW
  86     bmo->buffer_width = 0;
  87 
  88     bmo->margin_left = 0;
  89     bmo->margin_top = 0;
  90     bmo->margin_right = 0;
  91     bmo->margin_bot = 0;
  92 
  93     bmo->visible_width = 0;
  94     bmo->visible_height = 0;
  95 #else
  96 // TODO for now assume opacity buffer is same size as bm
  97     bmo->buffer_width = camera_screen.buffer_width;
  98 
  99     bmo->margin_left = 0;
 100     bmo->margin_top = 0;
 101     bmo->margin_right = 0;
 102     bmo->margin_bot = 0;
 103 
 104     bmo->visible_width = camera_screen.physical_width;
 105     bmo->visible_height = camera_screen.height;
 106 #endif
 107 
 108     vp->data_start = 0;
 109     bm->data_start = 0;
 110     bmo->data_start = 0;
 111 
 112     int total_size = buf_size;
 113 
 114     void *vp_fb = vid_get_viewport_active_buffer();
 115     // Add viewport details if requested, and not null
 116     if ( flags & LV_TFR_VIEWPORT && vp_fb) // live buffer
 117     {
 118         vp->data_start = total_size;
 119 #ifndef THUMB_FW
 120         vp_size = (vp->buffer_width*vp->visible_height*6)/4;
 121 #else
 122         vp_size = (vp->buffer_width*vp->visible_height*4)/2;
 123 #endif
 124         total_size += vp_size;
 125         // offset to start of actual data
 126         vp_fb += vid_get_viewport_image_offset();
 127     }
 128 
 129     // Add bitmap details if requested
 130     if ( flags & LV_TFR_BITMAP ) // bitmap buffer
 131     {
 132         bm->data_start = total_size;
 133 #ifndef THUMB_FW
 134         bm_size = bm->buffer_width*bm->visible_height;
 135 #else
 136         bm_size = (bm->buffer_width*bm->visible_height*4)/2;
 137 #endif
 138         total_size += bm_size;
 139     }
 140  
 141     // Add bitmap opacity if thumb2 and request
 142 #ifdef THUMB_FW
 143     if ( flags & LV_TFR_BITMAP_OPACITY ) // bitmap opacity buffer
 144     {
 145         bmo->data_start = total_size;
 146         bmo_size = bmo->buffer_width*bmo->visible_height;
 147         total_size += bmo_size;
 148     }
 149 #endif
 150 
 151     // Add palette detals if requested and available
 152     if ( pal_size ) // bitmap palette
 153     {
 154         lv->palette_data_start = buf_size - pal_size;
 155         memcpy(buf + lv->palette_data_start,vid_get_bitmap_active_palette(),pal_size);
 156     }
 157 
 158     // Send header structure (along with total size to be sent)
 159     data->send_data(data->handle,(char*)buf,buf_size,total_size,0,0,0);
 160 
 161     // Send viewport data if requested
 162     if ( vp_size )
 163     {
 164         data->send_data(data->handle,vp_fb,vp_size,0,0,0,0);
 165     }
 166 
 167     // Send bitmap data if requested
 168     if ( bm_size )
 169     {
 170         data->send_data(data->handle,vid_get_bitmap_active_buffer(),bm_size,0,0,0,0);
 171     }
 172 
 173     // Send bitmap opacity data if requested
 174 #ifdef THUMB_FW
 175     if ( bmo_size )
 176     {
 177         data->send_data(data->handle,vid_get_opacity_active_buffer(),bmo_size,0,0,0,0);
 178     }
 179 #endif
 180 
 181     free(buf);
 182     return total_size;
 183 }

/* [<][>][^][v][top][bottom][index][help] */