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 "conf.h"
   3 #include "modes.h"
   4 #include "viewport.h"
   5 #include "ptp_chdk.h"
   6 #include "live_view.h"
   7 
   8 // Live View implementation for all cameras using YUV or 8bpp palette based bitmap buffer
   9 // Viewport = YUV buffer
  10 // Bitmap = 8bpp buffer or YUV buffer (Digic6)
  11 // Palette = Color table (Non Digic 6)
  12 
  13 typedef struct
  14 {
  15     lv_data_header      lv;
  16     lv_framebuffer_desc vp;
  17     lv_framebuffer_desc bm;
  18 #ifdef THUMB_FW
  19     lv_framebuffer_desc bmo;
  20 #endif
  21 } lv_hdr;
  22 
  23 /*
  24 send selected data for live view
  25 returns 0 on error, total size on success
  26 should only be called from ptp handler
  27 */
  28 int live_view_get_data(ptp_data *data, int flags)
  29 {
  30     lv_hdr lv;
  31 
  32     // Header
  33     lv.lv.version_major = LIVE_VIEW_VERSION_MAJOR;
  34     lv.lv.version_minor = LIVE_VIEW_VERSION_MINOR;
  35 
  36     lv.lv.lcd_aspect_ratio = vid_get_aspect_ratio();
  37 
  38     lv.lv.vp_desc_start = sizeof(lv_data_header);
  39     lv.lv.bm_desc_start = lv.lv.vp_desc_start+sizeof(lv_framebuffer_desc);
  40 #ifdef THUMB_FW
  41     lv.lv.bmo_desc_start = lv.lv.bm_desc_start+sizeof(lv_framebuffer_desc);
  42 #else
  43     lv.lv.bmo_desc_start = 0;
  44 #endif
  45 
  46     // update camera_screen values to increase chance they will be consistent 
  47     // with values obtained directly from fw functions
  48     mode_get();
  49 
  50     // Viewport
  51     lv.vp.fb_type = vid_get_viewport_type();
  52 
  53     lv.vp.buffer_width = vid_get_viewport_buffer_width_proper();
  54 
  55     lv.vp.visible_width = vid_get_viewport_width_proper();
  56     lv.vp.visible_height = vid_get_viewport_height_proper();
  57 
  58     lv.vp.margin_left = vid_get_viewport_display_xoffset_proper();
  59     lv.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     lv.vp.margin_right = vid_get_viewport_fullscreen_width() - lv.vp.visible_width - lv.vp.margin_left;
  64     lv.vp.margin_bot = vid_get_viewport_fullscreen_height() - lv.vp.visible_height - lv.vp.margin_top;
  65 
  66     // Bitmap
  67     // TODO maybe should be function like viewport
  68 #ifdef THUMB_FW
  69     lv.bm.fb_type = LV_FB_YUV8B;
  70 #else
  71     lv.bm.fb_type = LV_FB_PAL8;
  72 #endif
  73     lv.bm.buffer_width = camera_screen.buffer_width;
  74 
  75     lv.bm.visible_width = camera_screen.physical_width;
  76     lv.bm.visible_height = camera_screen.height;
  77 
  78     lv.bm.margin_left = lv.bm.margin_right = lv.bm.margin_top = lv.bm.margin_bot = 0;
  79 
  80 #ifdef THUMB_FW
  81     // Bitmap opacity
  82     lv.bmo.fb_type = LV_FB_OPACITY8;
  83     lv.bmo.buffer_width = lv.bm.buffer_width;
  84 
  85     lv.bmo.visible_width = lv.bm.visible_width;
  86     lv.bmo.visible_height = lv.bm.visible_height;
  87 
  88     lv.bmo.margin_left = lv.bmo.margin_right = lv.bmo.margin_top = lv.bmo.margin_bot = 0;
  89 #endif
  90 
  91     // Calc sizes and get buffer pointers
  92     int total_size = sizeof(lv_hdr);
  93 
  94 #ifndef THUMB_FW
  95     int pal_size = 0;
  96     // determine if we will send palette so it can go in one send
  97     if ( flags & LV_TFR_PALETTE ) // bitmap palette
  98     {
  99         // if no palette, will be set to zero
 100         pal_size = vid_get_palette_size();
 101         if (pal_size)
 102         {
 103             lv.lv.palette_type = vid_get_palette_type();
 104             lv.lv.palette_data_start = total_size;
 105             total_size += pal_size;
 106         }
 107     }
 108     else
 109     {
 110         lv.lv.palette_data_start = lv.lv.palette_type = 0;
 111     }
 112 #else
 113     lv.lv.palette_data_start = lv.lv.palette_type = 0;
 114 #endif
 115 
 116     int vp_size = 0;
 117     void *vp_fb = vid_get_viewport_active_buffer();
 118     // Add viewport details if requested, and not null
 119     if ( (flags & LV_TFR_VIEWPORT) && vp_fb) // live buffer
 120     {
 121         lv.vp.data_start = total_size;
 122 #ifndef THUMB_FW
 123         vp_size = (lv.vp.buffer_width*lv.vp.visible_height*6)/4;
 124 #else
 125         vp_size = (lv.vp.buffer_width*lv.vp.visible_height*4)/2;
 126 #endif
 127         total_size += vp_size;
 128         // offset to start of actual data
 129         vp_fb += vid_get_viewport_image_offset();
 130     }
 131     else
 132     {
 133         lv.vp.data_start = 0;
 134     }
 135 
 136     int bm_size = 0;
 137     // Add bitmap details if requested
 138     if ( flags & LV_TFR_BITMAP ) // bitmap buffer
 139     {
 140         lv.bm.data_start = total_size;
 141 #ifndef THUMB_FW
 142         bm_size = lv.bm.buffer_width*lv.bm.visible_height;
 143 #else
 144         bm_size = (lv.bm.buffer_width*lv.bm.visible_height*4)/2;
 145 #endif
 146         total_size += bm_size;
 147     }
 148     else
 149     {
 150         lv.bm.data_start = 0;
 151     }
 152 
 153 #ifdef THUMB_FW
 154     int bmo_size = 0;
 155     // Add bitmap opacity if thumb2 and request
 156     if ( flags & LV_TFR_BITMAP_OPACITY ) // bitmap opacity buffer
 157     {
 158         lv.bmo.data_start = total_size;
 159         bmo_size = lv.bmo.buffer_width*lv.bmo.visible_height;
 160         total_size += bmo_size;
 161     }
 162     else
 163     {
 164         lv.bmo.data_start = 0;
 165     }
 166 #endif
 167 
 168     // Send header structure (along with total size to be sent)
 169     data->send_data(data->handle,(char*)&lv,sizeof(lv_hdr),total_size,0,0,0);
 170 
 171 #ifndef THUMB_FW
 172     // Send palette data if requested
 173     if (pal_size)
 174     {
 175         data->send_data(data->handle,vid_get_bitmap_active_palette(),pal_size,0,0,0,0);
 176     }
 177 #endif
 178 
 179     // Send viewport data if requested
 180     if ( vp_size )
 181     {
 182         data->send_data(data->handle,vp_fb,vp_size,0,0,0,0);
 183     }
 184 
 185     // Send bitmap data if requested
 186     if ( bm_size )
 187     {
 188         data->send_data(data->handle,vid_get_bitmap_active_buffer(),bm_size,0,0,0,0);
 189     }
 190 
 191 #ifdef THUMB_FW
 192     // Send bitmap opacity data if requested
 193     if ( bmo_size )
 194     {
 195         data->send_data(data->handle,vid_get_opacity_active_buffer(),bmo_size,0,0,0,0);
 196     }
 197 #endif
 198 
 199     return total_size;
 200 }

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