/src/canvas/directfb/ftk_bitmap_directfb.c

http://ftk.googlecode.com/ · C · 163 lines · 101 code · 34 blank · 28 comment · 24 complexity · 45a1c80252a21466fea6d3ecc6e6f5eb MD5 · raw file

  1. /*
  2. * File: ftk_bitmap_directfb.c
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: directfb bitmap implemntation.
  5. *
  6. * Copyright (c) 2009 - 2011 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. * 2011-10-03 Li XianJing <xianjimli@hotmail.com> created
  28. */
  29. #include "ftk_bitmap.h"
  30. #include "ftk_globals.h"
  31. #include "directfb_common.h"
  32. FtkBitmap* ftk_bitmap_create(int w, int h, FtkColor color)
  33. {
  34. FtkBitmap* thiz = (FtkBitmap*)FTK_ALLOC(sizeof(FtkBitmap));
  35. if(thiz != NULL)
  36. {
  37. DFBSurfaceDescription desc;
  38. IDirectFBSurface* surface = NULL;
  39. IDirectFB* dfb = directfb_get();
  40. desc.width = w;
  41. desc.height = h;
  42. desc.caps = DSCAPS_NONE;
  43. desc.pixelformat = DSPF_ARGB;
  44. desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT;
  45. dfb->CreateSurface(dfb, &desc, &surface);
  46. surface->Clear(surface, color.r, color.g, color.b, color.a);
  47. thiz->ref = 1;
  48. thiz->data = surface;
  49. }
  50. return thiz;
  51. }
  52. FtkBitmap* ftk_bitmap_create_with_native(void* bitmap)
  53. {
  54. FtkBitmap* thiz = (FtkBitmap*)FTK_ALLOC(sizeof(FtkBitmap));
  55. if(thiz != NULL)
  56. {
  57. thiz->ref = 1;
  58. thiz->data = bitmap;
  59. }
  60. return thiz;
  61. }
  62. void* ftk_bitmap_get_native(FtkBitmap* thiz)
  63. {
  64. return_val_if_fail(thiz != NULL, NULL);
  65. return thiz->data;
  66. }
  67. int ftk_bitmap_width(FtkBitmap* thiz)
  68. {
  69. int w = 0;
  70. int h = 0;
  71. IDirectFBSurface* surface = NULL;
  72. return_val_if_fail(thiz != NULL && thiz->data != NULL, 0);
  73. surface = (IDirectFBSurface*)thiz->data;
  74. surface->GetSize(surface, &w, &h);
  75. return w;
  76. }
  77. int ftk_bitmap_height(FtkBitmap* thiz)
  78. {
  79. int w = 0;
  80. int h = 0;
  81. IDirectFBSurface* surface = NULL;
  82. return_val_if_fail(thiz != NULL && thiz->data != NULL, 0);
  83. surface = (IDirectFBSurface*)thiz->data;
  84. surface->GetSize(surface, &w, &h);
  85. return h;
  86. }
  87. FtkColor* ftk_bitmap_lock(FtkBitmap* thiz)
  88. {
  89. int err = 0;
  90. int bitch = 0;
  91. FtkColor* bits = NULL;
  92. IDirectFBSurface* surface = NULL;
  93. return_val_if_fail(thiz != NULL && thiz->data != NULL, 0);
  94. surface = (IDirectFBSurface*)thiz->data;
  95. DFBCHECK(surface->Lock(surface, DSLF_READ, (void**)&bits, &bitch));
  96. return bits;
  97. }
  98. void ftk_bitmap_unlock(FtkBitmap* thiz)
  99. {
  100. IDirectFBSurface* surface = NULL;
  101. return_if_fail(thiz != NULL && thiz->data != NULL);
  102. surface = (IDirectFBSurface*)thiz->data;
  103. surface->Unlock(surface);
  104. return;
  105. }
  106. FtkColor ftk_bitmap_get_pixel(FtkBitmap* thiz, int x, int y)
  107. {
  108. FtkColor* bits = NULL;
  109. FtkColor c = {0, 0, 0, 0};
  110. return_val_if_fail(thiz != NULL && x < ftk_bitmap_width(thiz) && y < ftk_bitmap_height(thiz), c);
  111. bits = ftk_bitmap_lock(thiz);
  112. if(bits != NULL)
  113. {
  114. c = bits[y * ftk_bitmap_width(thiz) + x];
  115. }
  116. ftk_bitmap_unlock(thiz);
  117. return c;
  118. }
  119. void ftk_bitmap_destroy(FtkBitmap* thiz)
  120. {
  121. if(thiz != NULL)
  122. {
  123. IDirectFBSurface* surface = NULL;
  124. surface = (IDirectFBSurface*)thiz->data;
  125. surface->Release(surface);
  126. FTK_ZFREE(thiz, sizeof(FtkBitmap));
  127. }
  128. return;
  129. }