PageRenderTime 486ms CodeModel.GetById 454ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/display_test.c

http://ftk.googlecode.com/
C | 154 lines | 104 code | 20 blank | 30 comment | 10 complexity | 6d6febc48e64ea004762f9e03deb4ec6 MD5 | raw file
  1/*
  2 * File: display_fb_test.c    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   
  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.h"
 33
 34void red_bitmap(FtkBitmap* bitmap)
 35{
 36	int x = 0;
 37	int y = 0;
 38	int w = ftk_bitmap_width(bitmap);
 39	int h = ftk_bitmap_height(bitmap);
 40	FtkColor* bits = ftk_bitmap_lock(bitmap);
 41
 42	for(y = 0; y < h; y++)
 43	{
 44		for(x = 0; x < w; x++, bits++)
 45		{
 46			bits->g = 0;
 47			bits->b = 0;
 48			bits->r = 0xff;
 49		}
 50	}
 51
 52	return;
 53}
 54
 55void green_bitmap(FtkBitmap* bitmap)
 56{
 57	int x = 0;
 58	int y = 0;
 59	int w = ftk_bitmap_width(bitmap);
 60	int h = ftk_bitmap_height(bitmap);
 61	FtkColor* bits = ftk_bitmap_lock(bitmap);
 62
 63	for(y = 0; y < h; y++)
 64	{
 65		for(x = 0; x < w; x++, bits++)
 66		{
 67			bits->r = 0;
 68			bits->b = 0;
 69			bits->g = 0xff;
 70		}
 71	}
 72
 73	return;
 74}
 75
 76void blue_bitmap(FtkBitmap* bitmap)
 77{
 78	int x = 0;
 79	int y = 0;
 80	int w = ftk_bitmap_width(bitmap);
 81	int h = ftk_bitmap_height(bitmap);
 82	FtkColor* bits = ftk_bitmap_lock(bitmap);
 83
 84	for(y = 0; y < h; y++)
 85	{
 86		for(x = 0; x < w; x++, bits++)
 87		{
 88			bits->g = 0;
 89			bits->r = 0;
 90			bits->b = 0xff;
 91		}
 92	}
 93
 94	return;
 95}
 96
 97void mire_bitmap(FtkBitmap* bitmap)
 98{
 99	int x = 0;
100	int y = 0;
101	int w = ftk_bitmap_width(bitmap);
102	int h = ftk_bitmap_height(bitmap);
103	FtkColor* bits = ftk_bitmap_lock(bitmap);
104
105	for (y = 0; y < h; y++)
106	{
107		for (x=0; x < w; x++, bits++)
108		{
109			unsigned int color = ((x-w/2)*(x-w/2) + (y-h/2)*(y-h/2))/64;
110			bits->r = (color/8) % 256;
111			bits->g = (color/4) % 256;
112			bits->b = (color/2) % 256;
113	//		bits->a = (color*2) % 256;
114		}
115	}
116
117	return;
118}
119
120int main(int argc, char* argv[])
121{
122	FtkDisplay* thiz = NULL;
123
124	ftk_init(argc, argv);
125
126	thiz = ftk_default_display();
127	if(thiz != NULL)
128	{
129		FtkBitmap* bitmap = NULL;
130		FtkColor color = {.a=0xff};
131		FtkRect rect = {0};
132		rect.width = ftk_display_width(thiz);
133		rect.height = ftk_display_height(thiz);
134
135		bitmap = ftk_bitmap_create(rect.width, rect.height, color);
136		red_bitmap(bitmap);
137		ftk_display_update(thiz, bitmap, &rect, 0, 0);
138		sleep(3);
139		green_bitmap(bitmap);
140		ftk_display_update(thiz, bitmap, &rect, 0, 0);
141		sleep(3);
142		blue_bitmap(bitmap);
143		ftk_display_update(thiz, bitmap, &rect, 0, 0);
144		sleep(3);
145		mire_bitmap(bitmap);
146		ftk_display_update(thiz, bitmap, &rect, 0, 0);
147		sleep(3);
148
149		ftk_display_destroy(thiz);
150		ftk_bitmap_unref(bitmap);
151	}
152
153	return 0;
154}