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

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