root/platform/ixus140_elph130/lib.c

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

DEFINITIONS

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

   1 #include "platform.h"
   2 #include "platform_palette.h"
   3 #include "lolevel.h"
   4 #include "gui_draw.h"
   5 
   6 void vid_bitmap_refresh()
   7 {
   8     if(draw_is_suspended()) {
   9         return;
  10     }
  11     extern int full_screen_refresh;
  12     extern void _ScreenLock();
  13     extern void _ScreenUnlock();
  14 
  15     full_screen_refresh |= 3;
  16     _ScreenLock();
  17     _ScreenUnlock();
  18 }
  19 
  20 // TODO not really complete, last call from task_Bye
  21 void shutdown()
  22 {
  23     extern void _finish_shutdown(void);
  24     _finish_shutdown();
  25     while(1);
  26 }
  27 
  28 
  29 #define LED_PR 0xC0220094 // Green (only non-AF)
  30 
  31 void debug_led(int state)
  32 {
  33     volatile long *p=(void*)LED_PR;
  34     if (state)
  35         p[0]=0x46;
  36     else
  37         p[0]=0x44;
  38 }
  39 
  40 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  41  static char led_table[]={0,4}; // status, AF
  42  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  43 }
  44 
  45 char *camera_jpeg_count_str()
  46 {
  47     extern char jpeg_count_str[];
  48         return jpeg_count_str;
  49 }
  50 
  51 int get_flash_params_count(void) { return 0x91; }                          // Found @0xff2075ac
  52 
  53 
  54 void *vid_get_bitmap_fb()        { return (void*)0x406b1000; }             // Found @0xff08b550
  55 void *vid_get_viewport_fb()      { return (void*)0x40806b80; }             // Found @0xff412680
  56 void *vid_get_viewport_fb_d()
  57 {
  58     extern char *viewport_fb_d;
  59         return viewport_fb_d;
  60 }
  61 
  62 void *vid_get_viewport_live_fb()
  63 {
  64     extern char active_viewport_buffer;
  65     extern void* viewport_buffers[];
  66 
  67     int i = active_viewport_buffer - 1;
  68     // video appears to only use 3 buffers, no distinct video mode
  69     if (is_video_recording()) {
  70         if(i < 0) {
  71             i = 2;
  72         }
  73     } else if(i < 0) {
  74         i = 3;
  75     }
  76 
  77     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  78     return viewport_buffers[i];
  79 }
  80 
  81 
  82 char *hook_raw_image_addr()
  83 {
  84     return (char*)0x42365c30; //(Found @0xff413f98)
  85 }
  86 
  87 extern int _GetVideoOutType(void);
  88 extern int _GetVRAMHPixelsSize(void);
  89 extern int _GetVRAMVPixelsSize(void);
  90 
  91 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  92 // elph130 is 240 when using video out in rec, or in FISHEYE mode
  93 int vid_get_viewport_yscale() {
  94     if (camera_info.state.mode_play) {
  95         return 2;
  96     }
  97     if(_GetVideoOutType() != 0 || (camera_info.state.mode_shooting == MODE_FISHEYE && !is_video_recording())) {
  98         return 1;
  99     }
 100     return 2;
 101 }
 102 
 103 int vid_get_viewport_width()
 104 {
 105     if (camera_info.state.mode_play)
 106     {
 107         return 360;
 108     }
 109     return _GetVRAMHPixelsSize() >> 1;
 110 }
 111 
 112 long vid_get_viewport_height()
 113 {
 114     int vot = _GetVideoOutType();
 115     if (camera_info.state.mode_play)
 116     {
 117         if(vot == 2) { // PAL
 118             return 288; // 576
 119         }
 120         return 240;
 121     }
 122     return _GetVRAMVPixelsSize() >> (vid_get_viewport_yscale() - 1);
 123 }
 124 
 125 // viewport width offset table for each image size
 126 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 127 static long vp_xo[5] = { 0, 0, 0, 44 };                         // should all be even values for edge overlay
 128 
 129 // elph130 appears to use display offsets exclusively in X
 130 int vid_get_viewport_xoffset()
 131 {
 132     return 0;
 133 }
 134 
 135 int vid_get_viewport_display_xoffset()
 136 {
 137     if (camera_info.state.mode_play || is_video_recording())
 138     {
 139         return 0;
 140     }
 141     else if (camera_info.state.mode_shooting == MODE_STITCH)
 142     {
 143         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 144             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 145                 return 40;
 146             else
 147                 return 140;
 148         else
 149             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 150                 return 140;
 151             else
 152                 return 40;
 153     }
 154     else
 155     {
 156         return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 157     }
 158 }
 159 
 160 // viewport height offset table for each image size
 161 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 162 static long vp_yo[5] = { 0, 30, 13, 0 };
 163 
 164 int vid_get_viewport_yoffset()
 165 {
 166     if (camera_info.state.mode_play)
 167     {
 168         return 0;
 169     }
 170     // no distinct video mode, video uses its own aspect ratio, not still ratio of current mode
 171     else if (/*mode_is_video(m)*/ is_video_recording())
 172     {
 173         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) { // 640x480
 174             return 0;// 4:3 video, no offset
 175         } else {
 176             return 30; // 16:9 video
 177         }
 178     }
 179     else if (camera_info.state.mode_shooting == MODE_STITCH)
 180     {
 181         return 0;
 182     }
 183     else
 184     {
 185         return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 186     }
 187 }
 188 
 189 int vid_get_viewport_display_yoffset()
 190 {
 191     if (camera_info.state.mode_play)
 192     {
 193         return 0;
 194     }
 195     else if (/*mode_is_video(m)*/ is_video_recording())
 196     {
 197         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) { // 640x480
 198             return 0;// 4:3 video, no offset
 199         } else {
 200             return 30;
 201         }
 202     }
 203     else if (camera_info.state.mode_shooting == MODE_STITCH)
 204     {
 205         return 72;
 206     }
 207     else
 208     {
 209         return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 210     }
 211 }
 212 
 213 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * vid_get_viewport_yscale(); }
 214 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * vid_get_viewport_yscale(); }
 215 
 216 int vid_get_viewport_fullscreen_height()
 217 {
 218     if (camera_info.state.mode_play) {
 219         int vot = _GetVideoOutType();
 220         if(vot == 2) {
 221             return 576; // PAL in playback is 576
 222         } else {
 223             return 480; // all other playback is 480
 224         }
 225     } else {
 226         return 240<<(vid_get_viewport_yscale()-1);
 227     }
 228 }
 229 int vid_get_palette_type()                      { return 3; }
 230 int vid_get_palette_size()                      { return 256 * 4; }
 231 
 232 // Defined in stubs_min.S
 233 extern int active_bitmap_buffer;
 234 extern char* bitmap_buffer[];
 235 void *vid_get_bitmap_active_buffer()
 236 {
 237     return bitmap_buffer[active_bitmap_buffer];
 238 }
 239 
 240 void *vid_get_bitmap_active_palette()
 241 {
 242     extern int active_palette_buffer;
 243     extern int** palette_buffer_ptr;
 244     int *p = palette_buffer_ptr[active_palette_buffer];
 245     // active_palette_buffer can point at null when
 246     // func and menu are opened for the first time
 247     if(!p) {
 248         p = palette_buffer_ptr[0]; // rec mode buffer normally initialized
 249         if(!p) { // but may be null on video out switch
 250             return (void *)0;
 251         }
 252     }
 253     return (p+1);
 254 }
 255 
 256 // Function to load CHDK custom colors into active Canon palette
 257 void load_chdk_palette()
 258 {
 259     extern int active_palette_buffer;
 260     // Only load for the standard record and playback palettes
 261     // 0 = rec, 4 = func menu, 5 = playback, 6 = menu (play or rec),
 262     if ((active_palette_buffer == 0) || (active_palette_buffer == 5) || (active_palette_buffer == 4))
 263     {
 264         int *pal = (int*)vid_get_bitmap_active_palette();
 265         if (pal && pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 266         {
 267             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 268             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 269             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 270             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 271             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 272             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 273             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 274             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 275             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 276             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 277             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 278             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 279             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 280 
 281             extern char palette_control;
 282             palette_control = 1; // note appears to be a bitmask, bit 2 is also used
 283             vid_bitmap_refresh();
 284         }
 285     }
 286 }

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