WWLCDPanel.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "WWLCDPanelP.h"
  5. /*****************************************************************************/
  6. /* メンバ関数の定義 */
  7. /*****************************************************************************/
  8. int WWLCDPanel_GetWidth( WWLCDPanel p) { return (p->width ); }
  9. int WWLCDPanel_GetHeight(WWLCDPanel p) { return (p->height); }
  10. int WWLCDPanel_SetWidth( WWLCDPanel p, int n) { return (p->width = n); }
  11. int WWLCDPanel_SetHeight(WWLCDPanel p, int n) { return (p->height = n); }
  12. unsigned char * WWLCDPanel_GetPixelMap(WWLCDPanel p) { return (p->pixel); }
  13. /* LCDは1ピクセル16色(4ビット必要) */
  14. int WWLCDPanel_GetPixel(WWLCDPanel lcd_panel, int x, int y)
  15. {
  16. unsigned char pixel;
  17. if ( (x < 0) || (x > WWLCDPanel_GetWidth(lcd_panel) - 1) ||
  18. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  19. return (-1);
  20. pixel = lcd_panel->pixel[y * (WWLCDPanel_GetWidth(lcd_panel) / 2) + x / 2];
  21. if (x % 2) pixel = pixel >> 4;
  22. pixel &= 0x0f;
  23. return ((int)pixel);
  24. }
  25. int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y, int pixel)
  26. {
  27. unsigned char p;
  28. int n;
  29. if ( (x < 0) || (x > WWLCDPanel_GetWidth(lcd_panel) - 1) ||
  30. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  31. return (-1);
  32. p = 0x0f;
  33. if (x % 2) p = p << 4;
  34. n = y * (WWLCDPanel_GetWidth(lcd_panel) / 2) + x / 2;
  35. lcd_panel->pixel[n] &= ~p;
  36. p = ((unsigned char)pixel) & 0x0f;
  37. if (x % 2) p = p << 4;
  38. lcd_panel->pixel[n] |= p;
  39. return (pixel);
  40. }
  41. WWLCDPanel WWLCDPanel_Create(int width, int height)
  42. {
  43. WWLCDPanel lcd_panel;
  44. int x, y;
  45. lcd_panel = (WWLCDPanel)malloc(sizeof(_WWLCDPanel));
  46. if (lcd_panel == NULL) Error("WWLCDPanel_Create", "Cannot allocate memory.");
  47. WWLCDPanel_SetWidth( lcd_panel, width);
  48. WWLCDPanel_SetHeight(lcd_panel, height);
  49. lcd_panel->pixel =
  50. (unsigned char *)malloc(sizeof(unsigned char) *
  51. (WWLCDPanel_GetWidth(lcd_panel) / 2) *
  52. WWLCDPanel_GetHeight(lcd_panel));
  53. for (y = 0; y < lcd_panel->height; y++) {
  54. for (x = 0; x < lcd_panel->width / 2; x++) {
  55. WWLCDPanel_SetPixel(lcd_panel, x, y, 0x00);
  56. }
  57. }
  58. return (lcd_panel);
  59. }
  60. WWLCDPanel WWLCDPanel_Destroy(WWLCDPanel lcd_panel)
  61. {
  62. if (lcd_panel == NULL) return (NULL);
  63. if (lcd_panel->pixel) free(lcd_panel->pixel);
  64. free(lcd_panel);
  65. return (NULL);
  66. }
  67. /*****************************************************************************/
  68. /* ここまで */
  69. /*****************************************************************************/
  70. /*****************************************************************************/
  71. /* End of File. */
  72. /*****************************************************************************/