PageRenderTime 384ms CodeModel.GetById 191ms app.highlight 7ms RepoModel.GetById 184ms app.codeStats 0ms

/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/*
 26 * History:
 27 * ================================================================
 28 * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include "ftk_log.h"
 33#include "ftk_bitmap.h"
 34#include "ftk_allocator.h"
 35
 36typedef struct _PrivInfo
 37{
 38	int w;
 39	int h;
 40	int ref;
 41	int length;
 42	FtkColor* bits;
 43}PrivInfo;
 44
 45FtkBitmap* ftk_bitmap_create(int w, int h, FtkColor color)
 46{
 47	int i = 0;
 48	int length = w * h;
 49	FtkBitmap* thiz = (FtkBitmap*)FTK_ZALLOC(sizeof(FtkBitmap) + sizeof(PrivInfo));
 50
 51	if(thiz != NULL)
 52	{
 53		DECL_PRIV(thiz, priv);
 54
 55		thiz->ref = 1;
 56		priv->w = w;
 57		priv->h = h;
 58		priv->length = length;
 59		
 60		priv->bits = FTK_ALLOC(length * sizeof(FtkColor));
 61		for(i = 0; i < length; i++) 
 62		{
 63			priv->bits[i] = color;
 64		}
 65	}
 66
 67	return thiz;
 68}
 69
 70void* ftk_bitmap_get_native(FtkBitmap* thiz)
 71{
 72	return_val_if_fail(thiz != NULL, NULL);
 73
 74	return thiz;
 75}
 76
 77int ftk_bitmap_width(FtkBitmap* thiz)
 78{
 79	DECL_PRIV(thiz, priv);
 80	return_val_if_fail(priv != NULL, 0);
 81
 82	return priv->w;
 83}
 84
 85int ftk_bitmap_height(FtkBitmap* thiz)
 86{
 87	DECL_PRIV(thiz, priv);
 88	return_val_if_fail(priv != NULL, 0);
 89
 90	return priv->h;
 91}
 92
 93FtkColor* ftk_bitmap_lock(FtkBitmap* thiz)
 94{
 95	DECL_PRIV(thiz, priv);
 96	return_val_if_fail(priv != NULL, NULL);
 97
 98	return priv->bits;
 99}
100
101void    ftk_bitmap_unlock(FtkBitmap* thiz)
102{
103	return;
104}
105
106FtkColor ftk_bitmap_get_pixel(FtkBitmap* thiz, int x, int y)
107{
108	DECL_PRIV(thiz, priv);
109	FtkColor c = {0, 0, 0, 0};
110	return_val_if_fail(thiz != NULL && x < priv->w && y < priv->h, c);
111
112	c = *(priv->bits + y * priv->w + x);
113
114	return c;
115}
116
117void ftk_bitmap_destroy(FtkBitmap* thiz)
118{
119	if(thiz != NULL)
120	{
121		DECL_PRIV(thiz, priv);
122
123		FTK_FREE(priv->bits);
124		FTK_FREE(thiz);
125	}
126
127	return;
128}
129