/src/canvas/directfb/ftk_bitmap_factory_directfb.c

http://ftk.googlecode.com/ · C · 138 lines · 84 code · 19 blank · 35 comment · 7 complexity · 56e1e80acf53258cf4c859b1a327acc3 MD5 · raw file

  1. /*
  2. * File: ftk_bitmap_factory.c
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: bitmap factory.
  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_allocator.h"
  32. #include "directfb_common.h"
  33. #include "ftk_bitmap_factory.h"
  34. struct _FtkBitmapFactory
  35. {
  36. int unused;
  37. };
  38. FtkBitmapFactory* ftk_bitmap_factory_create(void)
  39. {
  40. FtkBitmapFactory* thiz = (FtkBitmapFactory*)FTK_ZALLOC(sizeof(FtkBitmapFactory));
  41. return thiz;
  42. }
  43. static DFBResult directfb_load_image (IDirectFB *dfb,
  44. const char *filename,
  45. IDirectFBSurface **surface)
  46. {
  47. DFBResult ret;
  48. DFBSurfaceDescription dsc;
  49. IDirectFBSurface *image;
  50. IDirectFBImageProvider *provider;
  51. if (!surface)
  52. {
  53. return DFB_INVARG;
  54. }
  55. /* Create an image provider for loading the file */
  56. ret = dfb->CreateImageProvider (dfb, filename, &provider);
  57. if (ret) {
  58. fprintf (stderr,
  59. "load_image: CreateImageProvider for '%s': %s\n",
  60. filename, DirectFBErrorString (ret));
  61. return ret;
  62. }
  63. /* Retrieve a surface description for the image */
  64. ret = provider->GetSurfaceDescription (provider, &dsc);
  65. if (ret) {
  66. fprintf (stderr,
  67. "load_image: GetSurfaceDescription for '%s': %s\n",
  68. filename, DirectFBErrorString (ret));
  69. provider->Release (provider);
  70. return ret;
  71. }
  72. dsc.pixelformat = DSPF_ARGB;
  73. /* Create a surface using the description */
  74. ret = dfb->CreateSurface (dfb, &dsc, &image);
  75. if (ret) {
  76. fprintf (stderr,
  77. "load_image: CreateSurface %dx%d: %s\n",
  78. dsc.width, dsc.height, DirectFBErrorString (ret));
  79. provider->Release (provider);
  80. return ret;
  81. }
  82. /* Render the image to the created surface */
  83. ret = provider->RenderTo (provider, image, NULL);
  84. if (ret) {
  85. fprintf (stderr,
  86. "load_image: RenderTo for '%s': %s\n",
  87. filename, DirectFBErrorString (ret));
  88. image->Release (image);
  89. provider->Release (provider);
  90. return ret;
  91. }
  92. /* Return surface */
  93. *surface = image;
  94. /* Release the provider */
  95. provider->Release (provider);
  96. return DFB_OK;
  97. }
  98. FtkBitmap* ftk_bitmap_factory_load(FtkBitmapFactory* thiz, const char* filename)
  99. {
  100. IDirectFBSurface* surface = NULL;
  101. IDirectFB* dfb = directfb_get();
  102. directfb_load_image(dfb, filename, &surface);
  103. if(surface != NULL)
  104. {
  105. return ftk_bitmap_create_with_native(surface);
  106. }
  107. else
  108. {
  109. return NULL;
  110. }
  111. }
  112. Ret ftk_bitmap_factory_add_decoder(FtkBitmapFactory* thiz, FtkImageDecoder* decoder)
  113. {
  114. return RET_OK;
  115. }
  116. void ftk_bitmap_factory_destroy(FtkBitmapFactory* thiz)
  117. {
  118. return;
  119. }