PageRenderTime 690ms CodeModel.GetById 256ms app.highlight 11ms RepoModel.GetById 221ms app.codeStats 0ms

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