WWLCDPanel.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "WWLCDPanelP.h"
  5. #include "WonX.h"
  6. /*****************************************************************************/
  7. /* メンバ関数の定義 */
  8. /*****************************************************************************/
  9. int WWLCDPanel_GetWidth( WWLCDPanel p) { return (p->width ); }
  10. int WWLCDPanel_GetHeight(WWLCDPanel p) { return (p->height); }
  11. int WWLCDPanel_SetWidth( WWLCDPanel p, int n) { return (p->width = n); }
  12. int WWLCDPanel_SetHeight(WWLCDPanel p, int n) { return (p->height = n); }
  13. int WWLCDPanel_ResetCurrent(WWLCDPanel p)
  14. {
  15. return (p->current = 0);
  16. }
  17. int WWLCDPanel_ReverseCurrent(WWLCDPanel p)
  18. {
  19. return (p->current = 1 - p->current);
  20. }
  21. int WWLCDPanel_ResetAllDraw(WWLCDPanel p) { return (p->all_draw = 0); }
  22. int WWLCDPanel_SetAllDraw(WWLCDPanel p) { return (p->all_draw = 1); }
  23. int WWLCDPanel_IsAllDraw(WWLCDPanel p) { return (p->all_draw); }
  24. unsigned short int * WWLCDPanel_GetPixelMap(WWLCDPanel p)
  25. {
  26. return (p->pixel[p->current]);
  27. }
  28. /* LCDは1ピクセル4096色(12ビット必要) */
  29. static unsigned short int WWLCDPanel_GetPixelByCurrent(WWLCDPanel lcd_panel,
  30. int current,
  31. int x, int y)
  32. {
  33. unsigned short int pixel;
  34. if ( (x < 0) || (x > WWLCDPanel_GetWidth( lcd_panel) - 1) ||
  35. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  36. return (-1);
  37. pixel = lcd_panel->pixel[current][y * WWLCDPanel_GetWidth(lcd_panel) + x];
  38. return ((int)pixel);
  39. }
  40. static unsigned short int WWLCDPanel_GetOldPixel(WWLCDPanel lcd_panel,
  41. int x, int y)
  42. {
  43. return (WWLCDPanel_GetPixelByCurrent(lcd_panel,
  44. 1 - lcd_panel->current, x, y));
  45. }
  46. unsigned short int WWLCDPanel_GetPixel(WWLCDPanel lcd_panel, int x, int y)
  47. {
  48. return (WWLCDPanel_GetPixelByCurrent(lcd_panel, lcd_panel->current, x, y));
  49. }
  50. unsigned short int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y,
  51. unsigned short int pixel)
  52. {
  53. unsigned short int p;
  54. int n;
  55. if ( (x < 0) || (x > WWLCDPanel_GetWidth( lcd_panel) - 1) ||
  56. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  57. return (-1);
  58. p = pixel & 0x0fff;
  59. n = y * WWLCDPanel_GetWidth(lcd_panel) + x;
  60. lcd_panel->pixel[lcd_panel->current][n] = p;
  61. return (p);
  62. }
  63. int WWLCDPanel_IsPixelChanged(WWLCDPanel lcd_panel, int x, int y)
  64. {
  65. unsigned short int old_pixel;
  66. unsigned short int current_pixel;
  67. if (WWLCDPanel_IsAllDraw(lcd_panel)) return (1);
  68. old_pixel = WWLCDPanel_GetOldPixel(lcd_panel, x, y);
  69. current_pixel = WWLCDPanel_GetPixel(lcd_panel, x, y);
  70. return (!(old_pixel == current_pixel));
  71. }
  72. WWLCDPanel WWLCDPanel_Create(int width, int height)
  73. {
  74. WWLCDPanel lcd_panel;
  75. int x, y, i;
  76. unsigned short int * p;
  77. lcd_panel = (WWLCDPanel)malloc(sizeof(_WWLCDPanel));
  78. if (lcd_panel == NULL)
  79. WonX_Error("WWLCDPanel_Create", "Cannot allocate memory.");
  80. WWLCDPanel_SetWidth( lcd_panel, width);
  81. WWLCDPanel_SetHeight(lcd_panel, height);
  82. for (i = 0; i < 2; i++) {
  83. p = (unsigned short int *)malloc(sizeof(unsigned short int) *
  84. WWLCDPanel_GetWidth(lcd_panel) *
  85. WWLCDPanel_GetHeight(lcd_panel));
  86. if (p == NULL) WonX_Error("WWLCDPanel_Create", "Cannot allocate memory.");
  87. lcd_panel->pixel[i] = p;
  88. }
  89. for (y = 0; y < lcd_panel->height; y++) {
  90. for (x = 0; x < lcd_panel->width / 2; x++) {
  91. WWLCDPanel_SetPixel(lcd_panel, x, y, 0);
  92. }
  93. }
  94. WWLCDPanel_ResetCurrent(lcd_panel);
  95. WWLCDPanel_SetAllDraw(lcd_panel); /* 初回は全画面を描画する */
  96. return (lcd_panel);
  97. }
  98. WWLCDPanel WWLCDPanel_Destroy(WWLCDPanel lcd_panel)
  99. {
  100. int i;
  101. if (lcd_panel == NULL)
  102. WonX_Error("WWLCDPanel_Destroy", "Object is not created.");
  103. for (i = 0; i < 2; i++) {
  104. if (lcd_panel->pixel[i]) free(lcd_panel->pixel[i]);
  105. }
  106. free(lcd_panel);
  107. return (NULL);
  108. }
  109. /*****************************************************************************/
  110. /* ここまで */
  111. /*****************************************************************************/
  112. /*****************************************************************************/
  113. /* End of File. */
  114. /*****************************************************************************/