Changeset 1365
- Timestamp:
- 10/15/11 04:22:52 (20 months ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
core/edgeoverlay.c (modified) (4 diffs)
-
core/gui.c (modified) (5 diffs)
-
core/gui_draw.c (modified) (8 diffs)
-
core/gui_draw.h (modified) (1 diff)
-
core/gui_grid.c (modified) (1 diff)
-
core/motion_detector.c (modified) (1 diff)
-
include/camera.h (modified) (3 diffs)
-
platform/ixus310_elph500hs/platform_camera.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/edgeoverlay.c
r1203 r1365 36 36 static void get_viewport_size() 37 37 { 38 // since screen_height is used in the drawing downwards, we should use it39 // here too to calculate the buffer we need...40 41 #if defined(CAM_USES_ASPECT_CORRECTION)42 //nandoide sept-2009 get the viewport dimensions, not the screen dimensions, on sx200is they aren't the same.43 38 viewport_height = vid_get_viewport_height()-EDGE_HMARGIN*2; //don't trace bottom lines 44 39 viewport_width = vid_get_viewport_width(); 45 40 viewport_byte_width = vid_get_viewport_buffer_width() * 3; 46 #else47 viewport_height = screen_height;//vid_get_viewport_height();48 viewport_width = screen_width;49 viewport_byte_width = screen_width * 3;50 #endif51 41 52 42 viewport_xoffset = vid_get_viewport_xoffset(); … … 518 508 // If there is no edge based on the newest data, but there is one painted on the screen 519 509 // from previous calls, delete it from the screen. 520 const int aspect_correct_x_off = ASPECT_VIEWPORT_XCORRECTION(x_off);510 const int aspect_correct_x_off = x_off; 521 511 const int bEdge = bv_get(edgebuf, y_edgebuf + x); 522 512 const int bDraw = bEdge || (draw_get_pixel(aspect_correct_x_off, y_off) == conf.edge_overlay_color); … … 546 536 for (x = x_min_c; x < x_max_c; ++x) 547 537 { 548 const int aspect_correct_x = ASPECT_VIEWPORT_XCORRECTION(x);538 const int aspect_correct_x = x; 549 539 if (draw_get_pixel(aspect_correct_x, y) == cl) // if there is an edge drawn on the screen but there is no edge there based on the newest data, delete it from the screen 550 540 draw_pixel(aspect_correct_x, y, 0 ); … … 564 554 for (x = x_min; x < x_max; ++x) 565 555 { 566 const int aspect_correct_x = ASPECT_VIEWPORT_XCORRECTION(x);556 const int aspect_correct_x = x; 567 557 if (draw_get_pixel(aspect_correct_x, y) == cl) // if there is an edge drawn on the screen but there is no edge there based on the newest data, delete it from the screen 568 558 draw_pixel(aspect_correct_x, y, 0 ); -
trunk/core/gui.c
r1350 r1365 2092 2092 gui_in_redraw = 1; 2093 2093 gui_mode_old = gui_mode; 2094 2095 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-20092096 //the different modes arises because games are designed on a 360x240 basis and are difficult to downscale to 320x2402097 if (gui_mode == GUI_MODE_REVERSI || gui_mode == GUI_MODE_SOKOBAN || gui_mode == GUI_MODE_4WINS || gui_mode == GUI_MODE_MASTERMIND) {2098 draw_set_environment(aspect_xcorrection_games_360, aspect_ycorrection_games_360, GAMES_SCREEN_WIDTH, GAMES_SCREEN_HEIGHT);2099 } else { //default2100 draw_set_environment(NULL, NULL, vid_get_bitmap_screen_width(), vid_get_bitmap_screen_height());2101 }2102 #endif2103 2094 2104 2095 #ifdef CAM_TOUCHSCREEN_UI … … 2627 2618 } 2628 2619 2629 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-20092630 draw_set_environment(aspect_xcorrection_games_360, aspect_ycorrection_games_360, GAMES_SCREEN_WIDTH, GAMES_SCREEN_HEIGHT);2631 #endif2632 2620 gui_set_mode(GUI_MODE_REVERSI); 2633 2621 gui_reversi_init(); … … 2643 2631 return; 2644 2632 } 2645 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-20092646 draw_set_environment(aspect_xcorrection_games_360, aspect_ycorrection_games_360, GAMES_SCREEN_WIDTH, GAMES_SCREEN_HEIGHT);2647 #endif2648 2633 if ( gui_sokoban_init() ) 2649 2634 gui_set_mode(GUI_MODE_SOKOBAN); … … 2658 2643 return; 2659 2644 } 2660 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-20092661 draw_set_environment(aspect_xcorrection_games_360, aspect_ycorrection_games_360, GAMES_SCREEN_WIDTH, GAMES_SCREEN_HEIGHT);2662 #endif2663 2645 if ( gui_4wins_init() ) 2664 2646 gui_set_mode(GUI_MODE_4WINS); … … 2673 2655 return; 2674 2656 } 2675 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-2009 2676 draw_set_environment(aspect_xcorrection_games_360, aspect_ycorrection_games_360, GAMES_SCREEN_WIDTH, GAMES_SCREEN_HEIGHT); 2677 #endif 2678 if ( gui_mastermind_init() ) 2657 if ( gui_mastermind_init() ) 2679 2658 gui_set_mode(GUI_MODE_MASTERMIND); 2680 2659 } -
trunk/core/gui_draw.c
r1355 r1365 23 23 } 24 24 25 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-200926 27 unsigned int (*aspect_xcorrection_proc)(unsigned int x);28 unsigned int (*aspect_ycorrection_proc)(unsigned int y);29 30 //-------------------------------------------------------------------31 unsigned int aspect_xcorrection_std(unsigned int x) {32 return (ASPECT_XCORRECTION(x));33 }34 //-------------------------------------------------------------------35 static unsigned int aspect_ycorrection_std(unsigned int y) {36 return (ASPECT_YCORRECTION(y));37 }38 //-------------------------------------------------------------------39 unsigned int aspect_xcorrection_games_360(unsigned int x) {40 return (ASPECT_GAMES_XCORRECTION(x));41 }42 //-------------------------------------------------------------------43 unsigned int aspect_ycorrection_games_360(unsigned int y) {44 return (ASPECT_GAMES_YCORRECTION(y));45 }46 //-------------------------------------------------------------------47 void draw_set_aspect_xcorrection_proc(unsigned int (*xcorrection_proc)(unsigned int x)) {48 aspect_xcorrection_proc = (xcorrection_proc)?xcorrection_proc:aspect_xcorrection_std;49 }50 //-------------------------------------------------------------------51 void draw_set_aspect_ycorrection_proc(unsigned int (*ycorrection_proc)(unsigned int y)) {52 aspect_ycorrection_proc = (ycorrection_proc)?ycorrection_proc:aspect_ycorrection_std;53 }54 //-------------------------------------------------------------------55 void draw_set_environment(unsigned int (*xcorrection_proc)(unsigned int x),56 unsigned int (*ycorrection_proc)(unsigned int y),57 int screenx, int screeny ) {58 screen_width=screenx;59 screen_height=screeny;60 draw_set_aspect_xcorrection_proc(xcorrection_proc);61 draw_set_aspect_ycorrection_proc(ycorrection_proc);62 }63 64 #endif65 66 25 //------------------------------------------------------------------- 67 26 #ifdef CAM_DETECT_SCREEN_ERASE … … 86 45 { 87 46 if (x >= screen_width || y >= screen_height) return 0; 88 #if CAM_USES_ASPECT_CORRECTION 89 return (frame_buffer[0][y * screen_buffer_width + aspect_xcorrection_proc(x)] == c) && 90 (frame_buffer[1][y * screen_buffer_width + aspect_xcorrection_proc(x)] == c); 91 #else 92 return (frame_buffer[0][y * screen_buffer_width + x] == c) && 93 (frame_buffer[1][y * screen_buffer_width + x] == c); 94 #endif 47 return (frame_buffer[0][y * screen_buffer_width + ASPECT_XCORRECTION(x)] == c) && 48 (frame_buffer[1][y * screen_buffer_width + ASPECT_XCORRECTION(x)] == c); 95 49 } 96 50 … … 110 64 frame_buffer[1] = frame_buffer[0] + screen_buffer_size; 111 65 draw_set_draw_proc(NULL); 112 #if CAM_USES_ASPECT_CORRECTION113 draw_set_aspect_xcorrection_proc(NULL);114 draw_set_aspect_ycorrection_proc(NULL);115 #endif116 66 117 67 #ifdef CAM_DETECT_SCREEN_ERASE … … 120 70 } 121 71 122 #if CAM_USES_ASPECT_CORRECTION123 124 // nandoide: sept-2009: draw_pixel_xarray draws a horizontal line at height y, from xi to xf125 // includes a correction of aspect ratio on x from buffer to screen126 // can be used to optimize computations (offset calculus) in other primitives (rectangles, and so on...) and compensate tne increase in computation time127 // of aspect ratio correction.128 // sx200is:129 // we have a 720x240 efective memory buffer (in a 960x270 physical memory buffer) and a screen of 320x240 (!)130 // the drawing primitives work on screen coordinates (the other approach, less modular it's to paint on buffer coordinates, deforming on x direction, I think it would be harder to live with it131 // and requires a full bunch of changes of the actual software).132 // then we do paint a x coordinate transformed in buffer by a factor 720/320=9/4 and then we do correct (deform) x to x*9/4 previously to save it on buffer133 // other:134 // the default mapping is x=x (NOTE: I think important to check that on every model, and necessary in newer models. it seems to me very strange screen sizes of 360x240 for 4/3 and 480/240 for 16/9 (SX1S).135 136 void draw_pixel_xarray(coord y, coord xi, coord xf, color cl) {137 if (xi >= screen_width || y >= screen_height) return;138 else {139 unsigned int offsetx, offsetxf, offsetxi, offsety;140 offsety=aspect_ycorrection_proc(y) * screen_buffer_width;141 offsetxi = aspect_xcorrection_proc(xi);142 xf++;143 offsetxf= (xf >= screen_width) ? screen_buffer_width - 1 : aspect_xcorrection_proc(xf);144 for (offsetx=offsetxi; offsetx<=offsetxf-1; offsetx++) {145 draw_pixel_proc(offsety+offsetx, cl);146 }147 }148 }149 150 #if CAM_USES_ASPECT_YCORRECTION151 //generalization for cases than we need to correct both coordinates: symetric algorithm152 void draw_pixel_rectanglearray(coord yi, coord yf, coord xi, coord xf, color cl) {153 if (xi >= screen_width || yi >= screen_height) return;154 else {155 unsigned int offsetx, offsetxf, offsetxi, offsety, offsetyf, offsetyi, offset;156 offsetyi = aspect_ycorrection_proc(yi);157 yf++;158 offsetyf= (yf >= screen_height) ? screen_buffer_height - 1 : aspect_ycorrection_proc(yf);159 offsetxi = aspect_xcorrection_proc(xi);160 xf++;161 offsetxf= (xf >= screen_width) ? screen_buffer_width - 1 : aspect_xcorrection_proc(xf);162 for (offsety=offsetyi; offsety<=offsetyf-1; offsety++) {163 offset=offsety*screen_buffer_width;164 for (offsetx=offsetxi; offsetx<=offsetxf-1; offsetx++) {165 draw_pixel_proc(offset+offsetx, cl);166 }167 }168 }169 }170 #endif171 172 // nandoide sept-2009: draw_pixel version that calls draw_pixel_xarray for calculations. It's necessary to paint more than a pixel. In other case we got holes due173 // to the nature of discrete drawing algoritms and the aspect-ratio correction.174 // so, we need paint a horizontal line from the point coordinate to the next point (x to x+1)175 // it's a brute force algorithm and it's possible that we have aliasing problems ...176 // but the display seems OK on sx200is ( good!) , due perhaps to the fact that the system makes a final reverse (bilinear?) resize 720 -> 320, to display the buffer data.177 178 void draw_pixel(coord x, coord y, color cl) {179 #if CAM_USES_ASPECT_YCORRECTION180 draw_pixel_rectanglearray(y, y, x, x, cl);181 #else182 draw_pixel_xarray(y, x, x, cl);183 #endif184 }185 186 color draw_get_pixel(coord x, coord y) {187 if (x >= screen_width || y >= screen_height) return 0;188 return frame_buffer[0][y * screen_buffer_width + aspect_xcorrection_proc(x) ];189 }190 #else191 72 //------------------------------------------------------------------- 192 73 void draw_pixel(coord x, coord y, color cl) { 193 74 if (x >= screen_width || y >= screen_height) return; 194 75 else { 195 register unsigned int offset = y * screen_buffer_width + x; 196 draw_pixel_proc(offset, cl); 76 register unsigned int offset = y * screen_buffer_width + ASPECT_XCORRECTION(x); 77 draw_pixel_proc(offset, cl); 78 #if CAM_USES_ASPECT_CORRECTION 79 draw_pixel_proc(offset+1, cl); // Draw second pixel if screen scaling is needed 80 #endif 197 81 } 198 82 } … … 201 85 color draw_get_pixel(coord x, coord y) { 202 86 if (x >= screen_width || y >= screen_height) return 0; 203 return frame_buffer[0][y * screen_buffer_width + x]; 204 } 205 #endif 87 return frame_buffer[0][y * screen_buffer_width + ASPECT_XCORRECTION(x) ]; 88 } 206 89 207 90 //------------------------------------------------------------------- … … 237 120 void draw_hline(coord x, coord y, int len, color cl) 238 121 { 239 #if CAM_USES_ASPECT_CORRECTION && !CAM_USES_ASPECT_YCORRECTION240 draw_pixel_xarray(y, x, x+len, cl);241 #else242 for (; len>=0; len--, x++) {243 draw_pixel(x, y, cl);244 }245 #endif122 if (x >= screen_width || y >= screen_height) return; 123 if (x < 0) { len += x; x = 0; } 124 if ((x + len) > screen_width) len = screen_width - x; 125 register unsigned int offset = y * screen_buffer_width + ASPECT_XCORRECTION(x); 126 len = ASPECT_XCORRECTION(len); // Scale the line length if needed 127 for (; len>=0; len--, offset++) 128 draw_pixel_proc(offset, cl); 246 129 } 247 130 248 131 void draw_vline(coord x, coord y, int len, color cl) 249 132 { 250 for (; len>=0; len--, y++) { 133 if ((x < 0) || (x >= screen_width) || (y >= screen_height)) return; 134 if (y < 0) { len += y; y = 0; } 135 if ((y + len) > screen_height) len = screen_height - y; 136 for (; len>=0; len--, y++) 251 137 draw_pixel(x, y, cl); 252 }253 138 } 254 139 //------------------------------------------------------------------- … … 276 161 if (yMin>=screen_height) yMin=screen_height-1; 277 162 278 for (y=yMin+(round<<1); y<=yMax-(round<<1); ++y) { 163 for (y=yMin+(round<<1); y<=yMax-(round<<1); ++y) 164 { 279 165 draw_pixel(xMin, y, cl); 280 166 draw_pixel(xMax, y, cl); 281 167 } 282 #if CAM_USES_ASPECT_CORRECTION && !CAM_USES_ASPECT_YCORRECTION 283 draw_pixel_xarray(yMin, xMin+1+round, xMax-1-round, cl); 284 draw_pixel_xarray(yMax, xMin+1+round, xMax-1-round, cl); 285 #else 286 for (x=xMin+1+round; x<=xMax-1-round; ++x) { 287 draw_pixel(x, yMin, cl); 288 draw_pixel(x, yMax, cl); 289 } 290 #endif 168 169 draw_hline(xMin+1+round, yMin, (xMax-1-round) - (xMin+1+round) + 1, cl); 170 draw_hline(xMin+1+round, yMax, (xMax-1-round) - (xMin+1+round) + 1, cl); 291 171 } 292 172 … … 331 211 register unsigned int x, y; 332 212 333 for (y=yMin+1; y<=yMax-1; ++y) { 334 #if CAM_USES_ASPECT_CORRECTION && !CAM_USES_ASPECT_YCORRECTION 335 draw_pixel_xarray(y, xMin+1, xMax-1, cl>>8); 336 #else 337 for (x=xMin+1; x<=xMax-1; ++x) { 338 draw_pixel(x, y, cl>>8); 339 } 340 #endif 213 cl = cl >> 8; 214 for (y=yMin+1; y<=yMax-1; ++y) 215 { 216 draw_hline(xMin+1, y, (xMax-1) - (xMin+1) + 1, cl); 341 217 } 342 218 } -
trunk/core/gui_draw.h
r1355 r1365 733 733 #endif 734 734 735 #if CAM_USES_ASPECT_CORRECTION //nandoide sept-2009736 void draw_set_aspect_xcorrection_proc(unsigned int (*xcorrection_proc)(unsigned int x));737 void draw_set_aspect_ycorrection_proc(unsigned int (*ycorrection_proc)(unsigned int y));738 unsigned int aspect_xcorrection_games_360(unsigned int x);739 unsigned int aspect_ycorrection_games_360(unsigned int y);740 void draw_set_environment(unsigned int (*xcorrection_proc)(unsigned int x),741 unsigned int (*ycorrection_proc)(unsigned int y),742 int screenx, int screeny );743 #endif744 745 735 //------------------------------------------------------------------- 746 736 #endif -
trunk/core/gui_grid.c
r804 r1365 86 86 if (gptr) { 87 87 gptr->type=type; 88 #if CAM_USES_ASPECT_CORRECTION //nandoide sep-2009 89 gptr->x0=ASPECT_GRID_XCORRECTION(nums[0]); gptr->y0=ASPECT_GRID_YCORRECTION(nums[1]); 90 gptr->x1=ASPECT_GRID_XCORRECTION(nums[2]); gptr->y1=ASPECT_GRID_YCORRECTION(nums[3]); 91 #else 92 gptr->x0=nums[0]; gptr->y0=nums[1]; 93 gptr->x1=nums[2]; gptr->y1=nums[3]; 94 #endif 88 gptr->x0=nums[0]; gptr->y0=nums[1]; 89 gptr->x1=nums[2]; gptr->y1=nums[3]; 95 90 gptr->clf=nums[4]; gptr->clb=nums[5]; 96 91 if (!head) head=gptr; -
trunk/core/motion_detector.c
r1088 r1365 559 559 } 560 560 561 xoffset = ASPECT_VIEWPORT_XCORRECTION(vid_get_viewport_xoffset()); // used when image size != viewport size561 xoffset = vid_get_viewport_xoffset(); // used when image size != viewport size 562 562 yoffset = vid_get_viewport_yoffset(); // used when image size != viewport size 563 563 -
trunk/include/camera.h
r1352 r1365 96 96 #define ZEBRA_HMARGIN0 0 97 97 98 // aspect corrections 99 #define CAM_USES_ASPECT_CORRECTION 0 // if true, camera uses a modified graphics primitives to draw with exact display aspect-ratio. 100 // Could slow the graphics output (but not perceived on sx200is), but adds rectangle drawing optimizations to compensate. 101 // To extend to other cameras see sx200is camera.h comments in and comments on core gui_draw.c 102 #define CAM_USES_ASPECT_YCORRECTION 0 103 104 // menu, alt (default) 105 #define ASPECT_XCORRECTION(x) ( ((x)<<1) ) // see comments on 200is 106 #define ASPECT_YCORRECTION(y) ( (y) ) // no correction the same for coordinate y. I think there are no cameras actually needing both corrections. 107 // viewport, defaults used if there is no aspect correction 108 #define ASPECT_VIEWPORT_XCORRECTION(x) ( (x) ) // see comments on 200is 109 #define ASPECT_VIEWPORT_YCORRECTION(y) ( (y) ) // no correction 98 // Older cameras had a screen/bitmap buffer that was 360 pixels wide (or 480 for wide screen models) 99 // CHDK was built around this 360 pixel wide display model 100 // Newer cameras have a 720 pixel wide bitmap (960 for wide screen cameras) 101 // To accomadate this the CHDK co-ordinate system assumes a 360/480 wide buffer and the 102 // pixel drawing routines draw every pixel twice to scale the image up to the actual buffer size 103 // Define CAM_USES_ASPECT_CORRECTION with a value of 1 to enable this scaled display 104 #define CAM_USES_ASPECT_CORRECTION 0 110 105 111 106 #define EDGE_HMARGIN 0 // define sup and inf screen margins on edge overlay without overlay. Necessary to save memory buffer space. sx200is needs values other than 0 … … 153 148 // This reduces the file size by approx 45% 154 149 155 // Games definitions156 #define GAMES_SCREEN_WIDTH 360 // Logical screen width for games157 #define GAMES_SCREEN_HEIGHT 240 // Logical screen height for games158 #define ASPECT_GAMES_XCORRECTION(x) ((x)<<1) // Aspect ratio correction for games. Default for games is 360x240 logical screen. Physical camera screen is159 #define ASPECT_GAMES_YCORRECTION(y) (y) // 720x240 so x*2 needed for X axis correction, no correction for Y.160 161 // Grid definitions162 #define ASPECT_GRID_XCORRECTION(x) (x) // Aspect ratio correction for grids. Grids are designed on a 360x240 logical screen size which matches the163 #define ASPECT_GRID_YCORRECTION(y) (y) // default CHDK logical screen size so no correction needed.164 165 150 #undef PARAM_CAMERA_NAME // parameter number for GetParameterData to get camera name 166 151 … … 200 185 //========================================================== 201 186 187 // For newer cameras where the screen bitmap is double the width we need to scale 188 // the CHDK horizontal (X) co-ordinates 189 #if CAM_USES_ASPECT_CORRECTION 190 #define ASPECT_XCORRECTION(x) ((x)<<1) // See comments for CAM_USES_ASPECT_CORRECTION above 191 #else 192 #define ASPECT_XCORRECTION(x) (x) // See comments for CAM_USES_ASPECT_CORRECTION above 193 #endif 202 194 203 195 // curves only work in 10bpp for now -
trunk/platform/ixus310_elph500hs/platform_camera.h
r1352 r1365 79 79 #undef CAM_USES_ASPECT_CORRECTION 80 80 #define CAM_USES_ASPECT_CORRECTION 1 //camera uses the modified graphics primitives to map screens an viewports to buffers more sized 81 #undef GAMES_SCREEN_WIDTH82 #define GAMES_SCREEN_WIDTH 480 // Logical screen width for games83 81 84 82 #undef EDGE_HMARGIN
Note: See TracChangeset
for help on using the changeset viewer.