WWLCDPanel.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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) + x];
  21. pixel &= 0x0f;
  22. return ((int)pixel);
  23. }
  24. int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y, int pixel)
  25. {
  26. unsigned char p;
  27. int n;
  28. if ( (x < 0) || (x > WWLCDPanel_GetWidth(lcd_panel) - 1) ||
  29. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  30. return (-1);
  31. p = ((unsigned char)pixel) & 0x0f;
  32. n = y * WWLCDPanel_GetWidth(lcd_panel) + x;
  33. lcd_panel->pixel[n] = p;
  34. return (pixel);
  35. }
  36. WWLCDPanel WWLCDPanel_Create(int width, int height)
  37. {
  38. WWLCDPanel lcd_panel;
  39. int x, y;
  40. lcd_panel = (WWLCDPanel)malloc(sizeof(_WWLCDPanel));
  41. if (lcd_panel == NULL) Error("WWLCDPanel_Create", "Cannot allocate memory.");
  42. WWLCDPanel_SetWidth( lcd_panel, width);
  43. WWLCDPanel_SetHeight(lcd_panel, height);
  44. lcd_panel->pixel =
  45. (unsigned char *)malloc(sizeof(unsigned char) *
  46. WWLCDPanel_GetWidth(lcd_panel) *
  47. WWLCDPanel_GetHeight(lcd_panel));
  48. for (y = 0; y < lcd_panel->height; y++) {
  49. for (x = 0; x < lcd_panel->width / 2; x++) {
  50. WWLCDPanel_SetPixel(lcd_panel, x, y, 0x00);
  51. }
  52. }
  53. return (lcd_panel);
  54. }
  55. WWLCDPanel WWLCDPanel_Destroy(WWLCDPanel lcd_panel)
  56. {
  57. if (lcd_panel == NULL) return (NULL);
  58. if (lcd_panel->pixel) free(lcd_panel->pixel);
  59. free(lcd_panel);
  60. return (NULL);
  61. }
  62. /*****************************************************************************/
  63. /* ここまで */
  64. /*****************************************************************************/
  65. /*****************************************************************************/
  66. /* End of File. */
  67. /*****************************************************************************/