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     char *pal_data = NULL;
  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 defined in port, size will be set to zero
 101         pal_size = vid_get_palette_size();
 102         if (pal_size)
 103         {
 104             // palette data may be NULL or a small offset while switching outputs
 105             // or due to port bugs or other reasons
 106             pal_data = vid_get_bitmap_active_palette();
 107             if(pal_data > (char *)0x1000) {
 108                 lv.lv.palette_type = vid_get_palette_type();
 109                 lv.lv.palette_data_start = total_size;
 110                 total_size += pal_size;
 111             } else {
 112                 pal_data = 0;
 113                 pal_size = 0;
 114             }
 115         }
 116         if (!pal_size) {
 117             lv.lv.palette_data_start = lv.lv.palette_type = 0;
 118         }
 119     }
 120     else
 121     {
 122         lv.lv.palette_data_start = lv.lv.palette_type = 0;
 123     }
 124 #else
 125     lv.lv.palette_data_start = lv.lv.palette_type = 0;
 126 #endif
 127 
 128     int vp_size = 0;
 129     void *vp_fb = vid_get_viewport_active_buffer();
 130     // Add viewport details if requested, and not null
 131     if ( (flags & LV_TFR_VIEWPORT) && vp_fb) // live buffer
 132     {
 133         lv.vp.data_start = total_size;
 134 #ifndef THUMB_FW
 135         vp_size = (lv.vp.buffer_width*lv.vp.visible_height*6)/4;
 136 #else
 137         vp_size = (lv.vp.buffer_width*lv.vp.visible_height*4)/2;
 138 #endif
 139         total_size += vp_size;
 140         // offset to start of actual data
 141         vp_fb += vid_get_viewport_image_offset();
 142     }
 143     else
 144     {
 145         lv.vp.data_start = 0;
 146     }
 147 
 148     int bm_size = 0;
 149     // Add bitmap details if requested
 150     if ( flags & LV_TFR_BITMAP ) // bitmap buffer
 151     {
 152         lv.bm.data_start = total_size;
 153 #ifndef THUMB_FW
 154         bm_size = lv.bm.buffer_width*lv.bm.visible_height;
 155 #else
 156         bm_size = (lv.bm.buffer_width*lv.bm.visible_height*4)/2;
 157 #endif
 158         total_size += bm_size;
 159     }
 160     else
 161     {
 162         lv.bm.data_start = 0;
 163     }
 164 
 165 #ifdef THUMB_FW
 166     int bmo_size = 0;
 167     // Add bitmap opacity if thumb2 and request
 168     if ( flags & LV_TFR_BITMAP_OPACITY ) // bitmap opacity buffer
 169     {
 170         lv.bmo.data_start = total_size;
 171         bmo_size = lv.bmo.buffer_width*lv.bmo.visible_height;
 172         total_size += bmo_size;
 173     }
 174     else
 175     {
 176         lv.bmo.data_start = 0;
 177     }
 178 #endif
 179 
 180     // Send header structure (along with total size to be sent)
 181     data->send_data(data->handle,(char*)&lv,sizeof(lv_hdr),total_size,0,0,0);
 182 
 183 #ifndef THUMB_FW
 184     // Send palette data if requested
 185     if (pal_size)
 186     {
 187         data->send_data(data->handle,pal_data,pal_size,0,0,0,0);
 188     }
 189 #endif
 190 
 191     // Send viewport data if requested
 192     if ( vp_size )
 193     {
 194         data->send_data(data->handle,vp_fb,vp_size,0,0,0,0);
 195     }
 196 
 197     // Send bitmap data if requested
 198     if ( bm_size )
 199     {
 200         data->send_data(data->handle,vid_get_bitmap_active_buffer(),bm_size,0,0,0,0);
 201     }
 202 
 203 #ifdef THUMB_FW
 204     // Send bitmap opacity data if requested
 205     if ( bmo_size )
 206     {
 207         data->send_data(data->handle,vid_get_opacity_active_buffer(),bmo_size,0,0,0,0);
 208     }
 209 #endif
 210 
 211     return total_size;
 212 }

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