00001 /*========================================================================= 00002 00003 GFX - a small graphics library 00004 00005 Copyright (C) 2004 Rafael de Oliveira Jannone 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact the author: 00022 by e-mail : rafael AT jannone DOT org 00023 homepage : http://jannone.org/gfxlib 00024 ICQ UIN : 10115284 00025 00026 See the License at http://www.gnu.org/copyleft/lesser.txt 00027 00028 =========================================================================*/ 00029 00033 // DEFS.H : shared defines 00034 00035 /* === WARNING == 00036 00037 This is a work-in-progress, meaning that most of this code is unstable 00038 and it's subject to future changes. Also, most of it is very hackish, 00039 not properly cleaned up nor tested. 00040 00041 === WARNING == */ 00042 00043 #ifndef DEFS_H 00044 #define DEFS_H 00045 00046 // trivial stuff 00047 00048 #define u_int unsigned int 00049 #define u_char unsigned char 00050 #define bool char 00051 #define true 1 00052 #define false 0 00053 #ifndef NULL 00054 #define NULL 0 00055 #endif 00056 00057 // screen mapping 00058 00060 #define map_block(x,y) ((((y) & ~(7)) << 5) + ((x) & ~(7))) 00061 00063 #define map_pixel(x,y) (map_block(x,y) + ((y) & 7)) 00064 /* 00065 here is how it works: 00066 00067 // map the row start (by row I mean a block of 8 lines) 00068 addr = (y & ~(7)) << 5; // this is the same as (y / 8) * 256 00069 00070 // then we aim for the column (column = block of 8 pixels) 00071 addr += (x & ~(7)); // this is the same as (x / 8) * 8 00072 00073 // finally, aim for the remaining "sub-row" inside the row block 00074 addr += (y & 7); 00075 */ 00076 00078 #define map_subpixel(x) (128 >> ((x) & 7)) 00079 00080 #define LONG(v) ((long)(v)) 00081 00082 // fixed point arithmetic 00083 00085 #define i2f(v) ((v) << 6) 00086 00088 #define f2i(v) ((v) >> 6) 00089 00091 #define mulfx(x,y) ((LONG(y) * LONG(x)) >> 6) 00092 00094 #define divfx(x,y) ((LONG(x) << 6) / LONG(y)) 00095 00097 #define sqrfx(x) ((LONG(x) * LONG(x)) >> 6) 00098 00100 #define sqrtfx(x) (LONG(sqrt(x)) << 3) 00101 // formula: sqrt(N * 64) = sqrt(N) * sqrt(64) -> must compensate with 64/sqrt(64) = 8 00102 00104 #define wgavgfx(x, y, w) (mulfx(i2f(1) - w, x) + mulfx(w, y)) 00105 00106 // malloc helpers 00107 00109 #define new(x) ((x*)malloc(sizeof(x))) 00110 00112 #define newa(x, c) ((x*)malloc(sizeof(x) * c)) 00113 00114 #endif
1.4.1