/src/test/display_test.c

http://ftk.googlecode.com/ · C · 154 lines · 104 code · 20 blank · 30 comment · 10 complexity · 6d6febc48e64ea004762f9e03deb4ec6 MD5 · raw file

  1. /*
  2. * File: display_fb_test.c
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief:
  5. *
  6. * Copyright (c) 2009 - 2010 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #include "ftk.h"
  31. void red_bitmap(FtkBitmap* bitmap)
  32. {
  33. int x = 0;
  34. int y = 0;
  35. int w = ftk_bitmap_width(bitmap);
  36. int h = ftk_bitmap_height(bitmap);
  37. FtkColor* bits = ftk_bitmap_lock(bitmap);
  38. for(y = 0; y < h; y++)
  39. {
  40. for(x = 0; x < w; x++, bits++)
  41. {
  42. bits->g = 0;
  43. bits->b = 0;
  44. bits->r = 0xff;
  45. }
  46. }
  47. return;
  48. }
  49. void green_bitmap(FtkBitmap* bitmap)
  50. {
  51. int x = 0;
  52. int y = 0;
  53. int w = ftk_bitmap_width(bitmap);
  54. int h = ftk_bitmap_height(bitmap);
  55. FtkColor* bits = ftk_bitmap_lock(bitmap);
  56. for(y = 0; y < h; y++)
  57. {
  58. for(x = 0; x < w; x++, bits++)
  59. {
  60. bits->r = 0;
  61. bits->b = 0;
  62. bits->g = 0xff;
  63. }
  64. }
  65. return;
  66. }
  67. void blue_bitmap(FtkBitmap* bitmap)
  68. {
  69. int x = 0;
  70. int y = 0;
  71. int w = ftk_bitmap_width(bitmap);
  72. int h = ftk_bitmap_height(bitmap);
  73. FtkColor* bits = ftk_bitmap_lock(bitmap);
  74. for(y = 0; y < h; y++)
  75. {
  76. for(x = 0; x < w; x++, bits++)
  77. {
  78. bits->g = 0;
  79. bits->r = 0;
  80. bits->b = 0xff;
  81. }
  82. }
  83. return;
  84. }
  85. void mire_bitmap(FtkBitmap* bitmap)
  86. {
  87. int x = 0;
  88. int y = 0;
  89. int w = ftk_bitmap_width(bitmap);
  90. int h = ftk_bitmap_height(bitmap);
  91. FtkColor* bits = ftk_bitmap_lock(bitmap);
  92. for (y = 0; y < h; y++)
  93. {
  94. for (x=0; x < w; x++, bits++)
  95. {
  96. unsigned int color = ((x-w/2)*(x-w/2) + (y-h/2)*(y-h/2))/64;
  97. bits->r = (color/8) % 256;
  98. bits->g = (color/4) % 256;
  99. bits->b = (color/2) % 256;
  100. // bits->a = (color*2) % 256;
  101. }
  102. }
  103. return;
  104. }
  105. int main(int argc, char* argv[])
  106. {
  107. FtkDisplay* thiz = NULL;
  108. ftk_init(argc, argv);
  109. thiz = ftk_default_display();
  110. if(thiz != NULL)
  111. {
  112. FtkBitmap* bitmap = NULL;
  113. FtkColor color = {.a=0xff};
  114. FtkRect rect = {0};
  115. rect.width = ftk_display_width(thiz);
  116. rect.height = ftk_display_height(thiz);
  117. bitmap = ftk_bitmap_create(rect.width, rect.height, color);
  118. red_bitmap(bitmap);
  119. ftk_display_update(thiz, bitmap, &rect, 0, 0);
  120. sleep(3);
  121. green_bitmap(bitmap);
  122. ftk_display_update(thiz, bitmap, &rect, 0, 0);
  123. sleep(3);
  124. blue_bitmap(bitmap);
  125. ftk_display_update(thiz, bitmap, &rect, 0, 0);
  126. sleep(3);
  127. mire_bitmap(bitmap);
  128. ftk_display_update(thiz, bitmap, &rect, 0, 0);
  129. sleep(3);
  130. ftk_display_destroy(thiz);
  131. ftk_bitmap_unref(bitmap);
  132. }
  133. return 0;
  134. }