root/platform/ixus240_elph320hs/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. hook_raw_image_addr
  2. hook_alt_raw_image_addr
  3. camera_jpeg_count_str
  4. get_flash_params_count
  5. vid_bitmap_refresh
  6. shutdown
  7. debug_led
  8. camera_set_led
  9. vid_get_viewport_yscale
  10. vid_get_viewport_fb
  11. vid_get_viewport_live_fb
  12. vid_get_viewport_fb_d
  13. vid_get_bitmap_fb
  14. vid_get_viewport_width
  15. vid_get_viewport_height
  16. vid_get_viewport_display_xoffset
  17. vid_get_viewport_display_xoffset_proper
  18. vid_get_viewport_height_proper
  19. vid_get_viewport_buffer_width_proper
  20. vid_get_viewport_fullscreen_height
  21. vid_get_palette_type
  22. vid_get_palette_size
  23. vid_get_aspect_ratio
  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 
   5 extern  int     active_raw_buffer;
   6 extern  char*   raw_buffers[];
   7 
   8 char *hook_raw_image_addr()
   9 {
  10     return raw_buffers[active_raw_buffer];
  11 }
  12 
  13 char *hook_alt_raw_image_addr()
  14 {
  15     return raw_buffers[(active_raw_buffer^1)];
  16 }
  17 
  18 
  19 char *camera_jpeg_count_str()
  20 {
  21     extern char jpeg_count_str[];
  22     return jpeg_count_str;
  23 }
  24 
  25 int get_flash_params_count(void)
  26 {
  27     return 0xa6; // Found @0xff24dffc by finsig
  28 }
  29 
  30 void vid_bitmap_refresh()
  31 {
  32     extern int full_screen_refresh;
  33     extern void _ScreenUnlock();
  34     extern void _ScreenLock();
  35 
  36     full_screen_refresh |= 3;
  37     _ScreenLock();
  38     _ScreenUnlock();
  39 }
  40 
  41 //To do: check this!!
  42 void shutdown()
  43 {
  44     volatile long *p = (void*)0xC022001C;
  45 
  46     asm(
  47         "MRS     R1, CPSR\n"
  48         "AND     R0, R1, #0x80\n"
  49         "ORR     R1, R1, #0x80\n"
  50         "MSR     CPSR_cf, R1\n"
  51         :::"r1","r0");
  52 
  53     *p = 0x44;  // power off.
  54 
  55     while(1);
  56 }
  57 
  58 //#define LED_PR 0xC022C30C                       // Power LED (@FF15B178 & @FF15B1CC)
  59 //TO DO:
  60 void debug_led(__attribute__ ((unused))int state) {
  61     // using power LED, which defaults to on
  62     // for debugging turn LED off if state is 1 and on for state = 0
  63     // leaves LED on at end of debugging
  64 //    volatile long *p = (void*)LED_PR;
  65 //    *p = (*p & 0xFFFFFFCF) | ((state) ? 0x00 : 0x20);
  66 }
  67 
  68 //To do:
  69 // IXUS240 has two 'lights' - Power LED, and AF assist lamp
  70 // Power Led = first entry in table (led 0)
  71 // AF Assist Lamp = second entry in table (led 1)
  72 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  73     static char led_table[2]={0,4};
  74     if(state<=1) _LEDDrive(led_table[led%sizeof(led_table)], (!state)&1);
  75 }
  76 
  77 
  78 // Viewport and Bitmap values that shouldn't change across firmware versions.
  79 // Values that may change are in lib.c for each firmware version.
  80 
  81 // Defined in stubs_min.S
  82 extern char active_viewport_buffer;
  83 extern void* viewport_buffers[];
  84 
  85 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  86 // camera appears to use 240 when recording FHD video and Fisheye mode, 480 otherwise
  87 int vid_get_viewport_yscale() {
  88     if (camera_info.state.mode_play) {
  89         return 2;
  90     }
  91     if (is_video_recording()) {
  92         // FHD video
  93         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 5) {
  94             return 1;
  95         }
  96         return 2;
  97     }
  98     if (camera_info.state.mode_shooting == MODE_FISHEYE) {
  99         return 1;
 100     }
 101     return 2;
 102 }
 103 
 104 void *vid_get_viewport_fb()
 105 {
 106     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
 107     return viewport_buffers[0];
 108 }
 109 
 110 void *vid_get_viewport_live_fb()
 111 {
 112     // only 4 buffers used while video recording
 113     if (camera_info.state.mode_video || is_video_recording())
 114         return viewport_buffers[(active_viewport_buffer-1)&3];
 115 
 116     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
 117     // Offset the return value because the viewport is left justified instead of centered on this camera
 118     return viewport_buffers[(active_viewport_buffer-1)&7];
 119 }
 120 
 121 void *vid_get_viewport_fb_d()
 122 {
 123     extern char *viewport_fb_d;
 124     return viewport_fb_d;
 125 }
 126 
 127 // Defined in stubs_min.S
 128 extern int active_bitmap_buffer;
 129 extern char* bitmap_buffer[];
 130 
 131 void *vid_get_bitmap_fb()
 132 {
 133     // Return first bitmap buffer address
 134     return bitmap_buffer[0];
 135 }
 136 
 137 int vid_get_viewport_width()
 138 {
 139     if (camera_info.state.mode_play)
 140     {
 141         return 480;
 142     }
 143     extern int _GetVRAMHPixelsSize();
 144     return _GetVRAMHPixelsSize() >> 1;
 145 }
 146 
 147 
 148 long vid_get_viewport_height()
 149 {
 150     if(camera_info.state.mode_play) {
 151         return 240;
 152     }
 153     extern int _GetVRAMVPixelsSize();
 154     // FHD video is apparently 180 on a 240 display
 155     int h = _GetVRAMVPixelsSize();
 156     if (vid_get_viewport_yscale() == 1) {
 157         return h;
 158     }
 159 
 160     return h>>1;
 161 }
 162 
 163 int vid_get_viewport_display_xoffset()
 164 {
 165     if (camera_info.state.mode_play)
 166     {
 167         return 0;
 168     }
 169     else
 170     {
 171         // viewport width offset table for each image size
 172         // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 173         static long vp_w[5] = { 60, 0, 36, 104 };                // should all be even values for edge overlay
 174         return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 175     }
 176 }
 177 
 178 // Functions for PTP Live View system
 179 
 180 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 181 int vid_get_viewport_height_proper()            { return vid_get_viewport_height()*vid_get_viewport_yscale(); }
 182 int vid_get_viewport_buffer_width_proper()      { return 960; }
 183 int vid_get_viewport_fullscreen_height()        { return 240*vid_get_viewport_yscale(); }
 184 
 185 int vid_get_palette_type()                      { return 3; }
 186 int vid_get_palette_size()                      { return 256 * 4; }
 187 int vid_get_aspect_ratio()                      { return 1; } /* LV_ASPECT_16_9 */
 188 
 189 void *vid_get_bitmap_active_buffer()
 190 {
 191     return bitmap_buffer[active_bitmap_buffer];
 192 }
 193 
 194 void *vid_get_bitmap_active_palette()
 195 {
 196     extern int active_palette_buffer;
 197     extern char* palette_buffer[];
 198     unsigned char color_option;
 199     // on cameras that allow setting UI color scheme,
 200     // actual palette is offset by color scheme value
 201     get_parameter_data(0x1a,&color_option,1); // from 102a sub_ff2ddd74
 202     char *p = palette_buffer[active_palette_buffer + color_option];
 203     // if null, don't add +4
 204     if(p) {
 205         p+=4;
 206     }
 207     return p;
 208 }
 209 
 210 #ifdef CAM_LOAD_CUSTOM_COLORS
 211 // Function to load CHDK custom colors into active Canon palette
 212 void load_chdk_palette()
 213 {
 214     extern int active_palette_buffer;
 215     // Only load for the standard record and playback palettes
 216     // per https://chdk.setepontos.com/index.php?topic=9005.msg145877#msg145877
 217     // rec 0, playback 16, menu 12
 218     if ((active_palette_buffer == 0) || (active_palette_buffer == 16))
 219     {
 220         int *pal = (int*)vid_get_bitmap_active_palette();
 221         if(pal) {
 222             if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 223             {
 224                 pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 225                 pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 226                 pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 227                 pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 228                 pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 229                 pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 230                 pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 231                 pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 232                 pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 233                 pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 234                 pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 235                 pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 236                 pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 237 
 238                 vid_bitmap_refresh();
 239             }
 240         }
 241     }
 242 }
 243 #endif

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