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 // 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     // Viewport
  47     lv.vp.fb_type = vid_get_viewport_type();
  48 
  49     lv.vp.buffer_width = vid_get_viewport_buffer_width_proper();
  50 
  51     lv.vp.visible_width = vid_get_viewport_width_proper();
  52     lv.vp.visible_height = vid_get_viewport_height_proper();
  53 
  54     lv.vp.margin_left = vid_get_viewport_display_xoffset_proper();
  55     lv.vp.margin_top = vid_get_viewport_display_yoffset_proper();
  56 
  57     // TODO returning margins from lib.c might be better
  58     // can end up with negative if size and offset sources don't update at exactly the same time
  59     lv.vp.margin_right = vid_get_viewport_fullscreen_width() - lv.vp.visible_width - lv.vp.margin_left;
  60     lv.vp.margin_bot = vid_get_viewport_fullscreen_height() - lv.vp.visible_height - lv.vp.margin_top;
  61 
  62     // Bitmap
  63     // TODO maybe should be function like viewport
  64 #ifdef THUMB_FW
  65     lv.bm.fb_type = LV_FB_YUV8B;
  66 #else
  67     lv.bm.fb_type = LV_FB_PAL8;
  68 #endif
  69     lv.bm.buffer_width = camera_screen.buffer_width;
  70 
  71     lv.bm.visible_width = camera_screen.physical_width;
  72     lv.bm.visible_height = camera_screen.height;
  73 
  74     lv.bm.margin_left = lv.bm.margin_right = lv.bm.margin_top = lv.bm.margin_bot = 0;
  75 
  76 #ifdef THUMB_FW
  77     // Bitmap opacity
  78     lv.bmo.fb_type = LV_FB_OPACITY8;
  79     lv.bmo.buffer_width = lv.bm.buffer_width;
  80 
  81     lv.bmo.visible_width = lv.bm.visible_width;
  82     lv.bmo.visible_height = lv.bm.visible_height;
  83 
  84     lv.bmo.margin_left = lv.bmo.margin_right = lv.bmo.margin_top = lv.bmo.margin_bot = 0;
  85 #endif
  86 
  87     // Calc sizes and get buffer pointers
  88     int total_size = sizeof(lv_hdr);
  89 
  90 #ifndef THUMB_FW
  91     int pal_size = 0;
  92     // determine if we will send palette so it can go in one send
  93     if ( flags & LV_TFR_PALETTE ) // bitmap palette
  94     {
  95         // if no palette, will be set to zero
  96         pal_size = vid_get_palette_size();
  97         if (pal_size)
  98         {
  99             lv.lv.palette_type = vid_get_palette_type();
 100             lv.lv.palette_data_start = total_size;
 101             total_size += pal_size;
 102         }
 103     }
 104     else
 105     {
 106         lv.lv.palette_data_start = lv.lv.palette_type = 0;
 107     }
 108 #else
 109     lv.lv.palette_data_start = lv.lv.palette_type = 0;
 110 #endif
 111 
 112     int vp_size = 0;
 113     void *vp_fb = vid_get_viewport_active_buffer();
 114     // Add viewport details if requested, and not null
 115     if ( (flags & LV_TFR_VIEWPORT) && vp_fb) // live buffer
 116     {
 117         lv.vp.data_start = total_size;
 118 #ifndef THUMB_FW
 119         vp_size = (lv.vp.buffer_width*lv.vp.visible_height*6)/4;
 120 #else
 121         vp_size = (lv.vp.buffer_width*lv.vp.visible_height*4)/2;
 122 #endif
 123         total_size += vp_size;
 124         // offset to start of actual data
 125         vp_fb += vid_get_viewport_image_offset();
 126     }
 127     else
 128     {
 129         lv.vp.data_start = 0;
 130     }
 131 
 132     int bm_size = 0;
 133     // Add bitmap details if requested
 134     if ( flags & LV_TFR_BITMAP ) // bitmap buffer
 135     {
 136         lv.bm.data_start = total_size;
 137 #ifndef THUMB_FW
 138         bm_size = lv.bm.buffer_width*lv.bm.visible_height;
 139 #else
 140         bm_size = (lv.bm.buffer_width*lv.bm.visible_height*4)/2;
 141 #endif
 142         total_size += bm_size;
 143     }
 144     else
 145     {
 146         lv.bm.data_start = 0;
 147     }
 148 
 149 #ifdef THUMB_FW
 150     int bmo_size = 0;
 151     // Add bitmap opacity if thumb2 and request
 152     if ( flags & LV_TFR_BITMAP_OPACITY ) // bitmap opacity buffer
 153     {
 154         lv.bmo.data_start = total_size;
 155         bmo_size = lv.bmo.buffer_width*lv.bmo.visible_height;
 156         total_size += bmo_size;
 157     }
 158     else
 159     {
 160         lv.bmo.data_start = 0;
 161     }
 162 #endif
 163 
 164     // Send header structure (along with total size to be sent)
 165     data->send_data(data->handle,(char*)&lv,sizeof(lv_hdr),total_size,0,0,0);
 166 
 167 #ifndef THUMB_FW
 168     // Send palette data if requested
 169     if (pal_size)
 170     {
 171         data->send_data(data->handle,vid_get_bitmap_active_palette(),pal_size,0,0,0,0);
 172     }
 173 #endif
 174 
 175     // Send viewport data if requested
 176     if ( vp_size )
 177     {
 178         data->send_data(data->handle,vp_fb,vp_size,0,0,0,0);
 179     }
 180 
 181     // Send bitmap data if requested
 182     if ( bm_size )
 183     {
 184         data->send_data(data->handle,vid_get_bitmap_active_buffer(),bm_size,0,0,0,0);
 185     }
 186 
 187 #ifdef THUMB_FW
 188     // Send bitmap opacity data if requested
 189     if ( bmo_size )
 190     {
 191         data->send_data(data->handle,vid_get_opacity_active_buffer(),bmo_size,0,0,0,0);
 192     }
 193 #endif
 194 
 195     return total_size;
 196 }

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