Advertisement
Guest User

Untitled

a guest
Feb 29th, 2012
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c
  2. index b0be687..0d1a0c1 100644
  3. --- a/firmware/drivers/lcd-bitmap-common.c
  4. +++ b/firmware/drivers/lcd-bitmap-common.c
  5. @@ -41,11 +41,46 @@
  6. #endif
  7.  
  8. #if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
  9. -/* Fill a rectangle with a gradient */
  10. -static void lcd_gradient_rect(int x1, int x2, int y, unsigned h,
  11. - int num_lines, int cur_line)
  12. +/* Fill a rectangle with a gradient:
  13. + * x1, x2 - x pixel coordinates to start/stop
  14. + * y - y pixel to start from
  15. + * h - line height
  16. + * num_lines - number of lines to span the gradient over
  17. + * cur_line - current line being draw
  18. + */
  19. +void lcd_gradientfillrect(int x1, int x2, int y1, int y2,
  20. + unsigned start_rgb, unsigned end_rgb)
  21. {
  22. int old_pattern = current_vp->fg_pattern;
  23. + int step_mul, i;
  24. + if (y2 - y1 == 0) return;
  25. +
  26. + step_mul = (1 << 16) / (y2 - y1);
  27. + int h_r = RGB_UNPACK_RED(start_rgb);
  28. + int h_g = RGB_UNPACK_GREEN(start_rgb);
  29. + int h_b = RGB_UNPACK_BLUE(start_rgb);
  30. + int rstep = (h_r - RGB_UNPACK_RED(end_rgb)) * step_mul;
  31. + int gstep = (h_g - RGB_UNPACK_GREEN(end_rgb)) * step_mul;
  32. + int bstep = (h_b - RGB_UNPACK_BLUE(end_rgb)) * step_mul;
  33. + h_r = (h_r << 16) + (1 << 15);
  34. + h_g = (h_g << 16) + (1 << 15);
  35. + h_b = (h_b << 16) + (1 << 15);
  36. +
  37. + for(i = y1; i < y2; i++) {
  38. + current_vp->fg_pattern = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
  39. + lcd_hline(x1, x2, i);
  40. + h_r -= rstep;
  41. + h_g -= gstep;
  42. + h_b -= bstep;
  43. + }
  44. +
  45. + current_vp->fg_pattern = old_pattern;
  46. +}
  47. +
  48. +
  49. +static void lcd_do_gradient_line(int x1, int x2, int y, unsigned h,
  50. + int num_lines, int cur_line)
  51. +{
  52. int step_mul;
  53. if (h == 0) return;
  54.  
  55. @@ -58,6 +93,8 @@ static void lcd_gradient_rect(int x1, int x2, int y, unsigned h,
  56. int rstep = (h_r - RGB_UNPACK_RED(current_vp->lse_pattern)) * step_mul;
  57. int gstep = (h_g - RGB_UNPACK_GREEN(current_vp->lse_pattern)) * step_mul;
  58. int bstep = (h_b - RGB_UNPACK_BLUE(current_vp->lse_pattern)) * step_mul;
  59. + unsigned start_rgb, end_rgb;
  60. + printf("num_lines: %d, h: %d, cur_line: %d\n", num_lines, h, cur_line);
  61. h_r = (h_r << 16) + (1 << 15);
  62. h_g = (h_g << 16) + (1 << 15);
  63. h_b = (h_b << 16) + (1 << 15);
  64. @@ -67,18 +104,17 @@ static void lcd_gradient_rect(int x1, int x2, int y, unsigned h,
  65. h_g -= cur_line * gstep;
  66. h_b -= cur_line * bstep;
  67. }
  68. - unsigned count;
  69. -
  70. - for(count = 0; count < h; count++) {
  71. - current_vp->fg_pattern = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
  72. - lcd_hline(x1, x2, y + count);
  73. - h_r -= rstep;
  74. - h_g -= gstep;
  75. - h_b -= bstep;
  76. - }
  77. -
  78. - current_vp->fg_pattern = old_pattern;
  79. + start_rgb = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
  80. +
  81. + cur_line += h;
  82. + h_r -= cur_line * rstep;
  83. + h_g -= cur_line * gstep;
  84. + h_b -= cur_line * bstep;
  85. + end_rgb = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
  86. + printf("start: %x, end: %x\n", start_rgb, end_rgb);
  87. + lcd_gradientfillrect(x1, x2, y, y + h, start_rgb, end_rgb);
  88. }
  89. +
  90. #endif
  91.  
  92. void LCDFN(set_framebuffer)(FBFN(data) *fb)
  93. @@ -284,7 +320,7 @@ static void LCDFN(putsxyofs_style)(int xpos, int ypos,
  94. current_vp->drawmode ^= DRMODE_INVERSEVID;
  95. if (style & STYLE_GRADIENT) {
  96. current_vp->drawmode = DRMODE_FG;
  97. - lcd_gradient_rect(xpos, current_vp->width, ypos, h,
  98. + lcd_do_gradient_line(xpos, current_vp->width, ypos, h,
  99. NUMLN_UNPACK(style), CURLN_UNPACK(style));
  100. current_vp->fg_pattern = current_vp->lst_pattern;
  101. }
  102. diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
  103. index 7e0e979..8c63baf 100644
  104. --- a/firmware/export/lcd.h
  105. +++ b/firmware/export/lcd.h
  106. @@ -523,6 +523,8 @@ extern void lcd_hline(int x1, int x2, int y);
  107. extern void lcd_vline(int x, int y1, int y2);
  108. extern void lcd_drawrect(int x, int y, int width, int height);
  109. extern void lcd_fillrect(int x, int y, int width, int height);
  110. +extern void lcd_gradientfillrect(int x, int y, int width, int height,
  111. + unsigned start_rgb, unsigned end_rgb);
  112. extern void lcd_draw_border_viewport(void);
  113. extern void lcd_fill_viewport(void);
  114. extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement