/src/canvas/default/ftk_bitmap_default.c

http://ftk.googlecode.com/ · C · 129 lines · 76 code · 24 blank · 29 comment · 12 complexity · 9c01f153e2e4363db0cfe427ebd122f7 MD5 · raw file

  1. /*
  2. * File: ftk_bitmap.c
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: Ftk bitmap
  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_log.h"
  31. #include "ftk_bitmap.h"
  32. #include "ftk_allocator.h"
  33. typedef struct _PrivInfo
  34. {
  35. int w;
  36. int h;
  37. int ref;
  38. int length;
  39. FtkColor* bits;
  40. }PrivInfo;
  41. FtkBitmap* ftk_bitmap_create(int w, int h, FtkColor color)
  42. {
  43. int i = 0;
  44. int length = w * h;
  45. FtkBitmap* thiz = (FtkBitmap*)FTK_ZALLOC(sizeof(FtkBitmap) + sizeof(PrivInfo));
  46. if(thiz != NULL)
  47. {
  48. DECL_PRIV(thiz, priv);
  49. thiz->ref = 1;
  50. priv->w = w;
  51. priv->h = h;
  52. priv->length = length;
  53. priv->bits = FTK_ALLOC(length * sizeof(FtkColor));
  54. for(i = 0; i < length; i++)
  55. {
  56. priv->bits[i] = color;
  57. }
  58. }
  59. return thiz;
  60. }
  61. void* ftk_bitmap_get_native(FtkBitmap* thiz)
  62. {
  63. return_val_if_fail(thiz != NULL, NULL);
  64. return thiz;
  65. }
  66. int ftk_bitmap_width(FtkBitmap* thiz)
  67. {
  68. DECL_PRIV(thiz, priv);
  69. return_val_if_fail(priv != NULL, 0);
  70. return priv->w;
  71. }
  72. int ftk_bitmap_height(FtkBitmap* thiz)
  73. {
  74. DECL_PRIV(thiz, priv);
  75. return_val_if_fail(priv != NULL, 0);
  76. return priv->h;
  77. }
  78. FtkColor* ftk_bitmap_lock(FtkBitmap* thiz)
  79. {
  80. DECL_PRIV(thiz, priv);
  81. return_val_if_fail(priv != NULL, NULL);
  82. return priv->bits;
  83. }
  84. void ftk_bitmap_unlock(FtkBitmap* thiz)
  85. {
  86. return;
  87. }
  88. FtkColor ftk_bitmap_get_pixel(FtkBitmap* thiz, int x, int y)
  89. {
  90. DECL_PRIV(thiz, priv);
  91. FtkColor c = {0, 0, 0, 0};
  92. return_val_if_fail(thiz != NULL && x < priv->w && y < priv->h, c);
  93. c = *(priv->bits + y * priv->w + x);
  94. return c;
  95. }
  96. void ftk_bitmap_destroy(FtkBitmap* thiz)
  97. {
  98. if(thiz != NULL)
  99. {
  100. DECL_PRIV(thiz, priv);
  101. FTK_FREE(priv->bits);
  102. FTK_FREE(thiz);
  103. }
  104. return;
  105. }