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