root/platform/n_facebook/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. camera_jpeg_count_str
  2. get_flash_params_count
  3. hook_raw_image_addr
  4. hook_alt_raw_image_addr
  5. vid_bitmap_refresh
  6. shutdown
  7. debug_led
  8. camera_set_led
  9. vid_get_bitmap_fb
  10. vid_get_viewport_fb
  11. vid_get_viewport_fb_d
  12. vid_get_viewport_live_fb
  13. vid_get_viewport_yscale
  14. vid_get_viewport_width
  15. vid_get_viewport_height_proper
  16. vid_get_viewport_height
  17. vid_get_viewport_display_xoffset
  18. vid_get_viewport_yoffset
  19. vid_get_palette_type
  20. vid_get_palette_size
  21. vid_get_viewport_display_yoffset_proper
  22. vid_get_viewport_fullscreen_height
  23. vid_get_bitmap_active_palette
  24. vid_get_bitmap_active_buffer
  25. load_chdk_palette

   1 // Powershot N Facebook
   2 
   3 #include "platform.h"
   4 #include "platform_palette.h"
   5 #include "lolevel.h"
   6 
   7 extern  int     active_raw_buffer;
   8 extern  char*   raw_buffers[];
   9 
  10 char *camera_jpeg_count_str()    { return (char*)0x00220be0; }             // Found @0xff2c14cc
  11 int get_flash_params_count(void) { return 0x91; }                          // Found @0xff250098
  12 
  13 char *hook_raw_image_addr()
  14 {
  15     return raw_buffers[active_raw_buffer];
  16 }
  17 
  18 char *hook_alt_raw_image_addr()
  19 {
  20     return raw_buffers[(active_raw_buffer^1)];
  21 }
  22 
  23 void vid_bitmap_refresh()
  24 {
  25     extern int full_screen_refresh;
  26     extern void _ScreenUnlock();
  27     extern void _ScreenLock();
  28 
  29     full_screen_refresh |= 3;
  30     _ScreenLock();
  31     _ScreenUnlock();
  32 }
  33 
  34 void shutdown()
  35 {
  36     extern void _TurnOffE1(void);
  37     _TurnOffE1();
  38     while(1);
  39 }
  40 
  41 // powershot N has only one LED - on the power button
  42 void debug_led(int state)
  43 {
  44     if ( state == 1 ) *(int*)0xc022c30c = ( (*(int*)0xc022c30c) & 0xffffffcf ) | 0x20 ;
  45     else              *(int*)0xc022c30c = ( (*(int*)0xc022c30c) & 0xffffffcf )        ;
  46 }
  47 
  48 // powershot N has one LED - on the power button - and a focus assist / camera lamp on the front of the camera
  49 void camera_set_led(int led, int state, __attribute__ ((unused))int bright)
  50 {
  51     static char led_table[3]={0,6,11};  // 0=green power button LED, 6=focus assist lamp (dim), 11=flash LED (bright)
  52     _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  53 }
  54 
  55 // Bitmap values
  56 void *vid_get_bitmap_fb()   { return (void*)0x406c5000; }        // Found @0xff08d5d8
  57 void *vid_get_viewport_fb() { return (void*)0x4081ab80; }        // Found @0xff4b7678
  58 
  59 void *vid_get_viewport_fb_d()                                    // buffer used in playback mode & fallback if vid_get_viewport_live_fb returns null
  60 {
  61     extern char *viewport_fb_d;
  62     return viewport_fb_d;
  63 }
  64 
  65 void *vid_get_viewport_live_fb()                                 // live buffer used in record mode
  66 {
  67     extern char active_viewport_buffer;
  68     extern void* viewport_buffers[];
  69 
  70     if (camera_info.state.mode_video || is_video_recording() || camera_info.state.mode_shooting == MODE_FISHEYE)
  71         return viewport_buffers[(active_viewport_buffer-1)&3];     // Video and fisheye appear to use 4 buffer
  72 
  73     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  74     // note code previously used -7, but seems unlikely to be correct
  75     return viewport_buffers[(active_viewport_buffer-1)&7];
  76 }
  77 
  78 
  79 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  80 // 240 in FISHEYE mode
  81 int vid_get_viewport_yscale() {
  82     if (camera_info.state.mode_play) {
  83         return 2;
  84     }
  85     if(camera_info.state.mode_shooting == MODE_FISHEYE && !is_video_recording()) {
  86         return 1;
  87     }
  88     return 2;
  89 }
  90 
  91 int vid_get_viewport_width()
  92 {
  93     if (camera_info.state.mode_play)
  94     {
  95         return 360;
  96     }
  97     extern int _GetVRAMHPixelsSize();
  98     return _GetVRAMHPixelsSize() >> 1;
  99 }
 100 
 101 int vid_get_viewport_height_proper()
 102 {
 103   if (camera_info.state.mode_play)
 104   {
 105        return 480;
 106   }
 107   extern int _GetVRAMVPixelsSize();
 108   return _GetVRAMVPixelsSize();
 109 
 110 }
 111 
 112 // define in terms of "proper" so only one needs to call vid_get_viewport_yscale
 113 long vid_get_viewport_height()
 114 {
 115     return vid_get_viewport_height_proper() >> (vid_get_viewport_yscale()-1);
 116 }
 117 // viewport width offset table for each image size
 118 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 119 static long vp_xo[5] = { 0, 0, 0, 44 };                         // should all be even values for edge overlay
 120 
 121 // default
 122 //int vid_get_viewport_xoffset() { return 0; }
 123 
 124 int vid_get_viewport_display_xoffset()
 125 {
 126     if (camera_info.state.mode_play || camera_info.state.mode_video || is_video_recording())
 127     {
 128         return 0;
 129     }
 130     return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 131 }
 132 
 133 // viewport height offset table for each image size
 134 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 135 static long vp_yo[5] = { 0, 30, 13, 0 };
 136 
 137 int vid_get_viewport_yoffset()
 138 {
 139     if (camera_info.state.mode_play)
 140     {
 141         return 0;
 142     }
 143     else if (camera_info.state.mode_video || is_video_recording())
 144     {
 145         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) { // 640x480
 146             return 0;// 4:3 video, no offset
 147         } else {
 148             return 30; // 16:9 video
 149         }
 150     }
 151     else
 152     {
 153         return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 154     }
 155 }
 156 
 157 // default
 158 // int vid_get_viewport_display_yoffset() { return vid_get_viewport_yoffset(); }
 159 
 160 // Functions for PTP Live View system & Custom Palette Colors
 161 
 162 extern int active_palette_buffer;
 163 extern int** palette_buffer_ptr;
 164 extern char palette_control;
 165 
 166 // default
 167 //int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 168 int vid_get_palette_type()                      { return 3; }
 169 int vid_get_palette_size()                      { return 256 * 4; }
 170 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() <<(vid_get_viewport_yscale()-1); }
 171 // physical aspect ratio appears to be 4:3, default
 172 /*int vid_get_aspect_ratio()                      { return 0; }*/
 173 
 174 int vid_get_viewport_fullscreen_height()
 175 {
 176     return 240<<(vid_get_viewport_yscale()-1);
 177 }
 178 
 179 void *vid_get_bitmap_active_palette() {
 180     unsigned char theme;
 181     get_parameter_data(20, &theme, 1);
 182     void *p = palette_buffer_ptr[active_palette_buffer+theme];
 183     if(p) {
 184         p += 4;
 185     }
 186     return p;
 187 }
 188 
 189 void * vid_get_bitmap_active_buffer()
 190 {
 191     return (void*)(*(int*)(0x7510+0x18)); //found Powershot N FB @ loc_ff1be034 (from A1400 example)
 192 }
 193 
 194 #ifdef CAM_LOAD_CUSTOM_COLORS
 195 
 196 // Function to load CHDK custom colors into active Canon palette
 197 
 198 void load_chdk_palette()
 199 {
 200     // active_palette_buffer values
 201     //  0x00:shooting, 0x04:camera modes menu, 0x0C:func menu, 0x10:playback, 0x14:shooting setup menu, 0x18:wifi menu
 202 
 203     if (    (active_palette_buffer == 0x00)
 204          || (active_palette_buffer == 0x10))
 205     {
 206         int *pal = vid_get_bitmap_active_palette();
 207         // check that palette_buffer != null and palette transparent & black colors are correct before overwriting palette)
 208         if (    (pal!=0)
 209              && (pal[CHDK_COLOR_BASE+0] != 0x3F3ADF62)
 210              && (pal[0x00]==0x00FF0000)
 211              && (pal[0xFF]==0x3F000000) )
 212         {
 213             pal[CHDK_COLOR_BASE+0]  = 0x3F3ADF62;  // Red
 214             pal[CHDK_COLOR_BASE+1]  = 0x3F26EA40;  // Dark Red
 215             pal[CHDK_COLOR_BASE+2]  = 0x3F4CD57F;  // Light Red
 216             pal[CHDK_COLOR_BASE+3]  = 0x3F73BFAE;  // Green
 217             pal[CHDK_COLOR_BASE+4]  = 0x3F4BD6CA;  // Dark Green
 218             pal[CHDK_COLOR_BASE+5]  = 0x3F95AB95;  // Light Green
 219             pal[CHDK_COLOR_BASE+6]  = 0x3F4766F0;  // Blue
 220             pal[CHDK_COLOR_BASE+7]  = 0x3F1250F3;  // Dark Blue
 221             pal[CHDK_COLOR_BASE+8]  = 0x3F7F408F;  // Cyan
 222             pal[CHDK_COLOR_BASE+9]  = 0x3F512D5B;  // Magenta
 223             pal[CHDK_COLOR_BASE+10] = 0x3FA9A917;  // Yellow
 224             pal[CHDK_COLOR_BASE+11] = 0x3F819137;  // Dark Yellow
 225             pal[CHDK_COLOR_BASE+12] = 0x3FDED115;  // Light Yellow
 226             pal[CHDK_COLOR_BASE+13] = 0x1F0A0000;  // Transparent dark grey
 227 
 228             vid_bitmap_refresh();
 229         }
 230     }
 231 }
 232 #endif

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