Changeset 1015 for libcaca/trunk/caca
- Timestamp:
- Sep 9, 2006, 6:53:13 PM (15 years ago)
- Location:
- libcaca/trunk/caca
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca0.c
r1013 r1015 21 21 22 22 #if !defined(__KERNEL__) 23 # include <std io.h>23 # include <stdlib.h> 24 24 #endif 25 25 … … 30 30 cucul_canvas_t *__caca0_cv = NULL; 31 31 caca_display_t *__caca0_dp = NULL; 32 unsigned char __caca0_fg ;33 unsigned char __caca0_bg ;32 unsigned char __caca0_fg = CUCUL_COLOR_LIGHTGRAY; 33 unsigned char __caca0_bg = CUCUL_COLOR_BLACK; 34 34 char __caca0_utf8[2] = " "; 35 35 … … 38 38 void __caca0_end(void); 39 39 unsigned int __caca0_get_event(unsigned int, int); 40 unsigned int __caca0_sqrt(unsigned int); 40 41 int __caca0_get_feature(int); 41 42 void __caca0_set_feature(int); 42 43 char const *__caca0_get_feature_name(int); 43 44 cucul_canvas_t *__caca0_load_sprite(char const *); 45 cucul_dither_t *__caca0_create_bitmap(unsigned int, unsigned int, 46 unsigned int, unsigned int, unsigned long int, unsigned long int, 47 unsigned long int, unsigned long int); 48 void __caca0_free_bitmap(cucul_dither_t *); 44 49 45 50 /* Emulation functions */ … … 100 105 } 101 106 102 enum caca_feature 103 { 104 CACA_BACKGROUND = 0x10, 105 CACA_BACKGROUND_BLACK = 0x11, 106 CACA_BACKGROUND_SOLID = 0x12, 107 #define CACA_BACKGROUND_MIN 0x11 108 #define CACA_BACKGROUND_MAX 0x12 109 CACA_ANTIALIASING = 0x20, 110 CACA_ANTIALIASING_NONE = 0x21, 111 CACA_ANTIALIASING_PREFILTER = 0x22, 112 #define CACA_ANTIALIASING_MIN 0x21 113 #define CACA_ANTIALIASING_MAX 0x22 114 CACA_DITHERING = 0x30, 115 CACA_DITHERING_NONE = 0x31, 116 CACA_DITHERING_ORDERED2 = 0x32, 117 CACA_DITHERING_ORDERED4 = 0x33, 118 CACA_DITHERING_ORDERED8 = 0x34, 119 CACA_DITHERING_RANDOM = 0x35, 120 #define CACA_DITHERING_MIN 0x31 121 #define CACA_DITHERING_MAX 0x35 122 CACA_FEATURE_UNKNOWN = 0xffff 107 unsigned int __caca0_sqrt(unsigned int a) 108 { 109 if(a == 0) 110 return 0; 111 112 if(a < 1000000000) 113 { 114 unsigned int x = a < 10 ? 1 115 : a < 1000 ? 10 116 : a < 100000 ? 100 117 : a < 10000000 ? 1000 118 : 10000; 119 120 /* Newton's method. Three iterations would be more than enough. */ 121 x = (x * x + a) / x / 2; 122 x = (x * x + a) / x / 2; 123 x = (x * x + a) / x / 2; 124 x = (x * x + a) / x / 2; 125 126 return x; 127 } 128 129 return 2 * __caca0_sqrt(a / 4); 130 } 131 132 static char const *features[] = 133 { 134 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 135 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 136 137 NULL, "16", "full16", NULL, NULL, NULL, NULL, NULL, 138 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 139 140 NULL, "none", "prefilter", NULL, NULL, NULL, NULL, NULL, 141 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 142 143 NULL, "none", "ordered2", "ordered4", "ordered8", "random" 123 144 }; 124 145 146 static cucul_dither_t **bitmaps = NULL; 147 static unsigned int nbitmaps = 0; 148 149 static int background = 0x12; 150 static int antialiasing = 0x22; 151 static int dithering = 0x33; 152 125 153 int __caca0_get_feature(int feature) 126 154 { 127 return feature; 155 if(feature == 0x10) 156 return background; 157 if(feature == 0x20) 158 return antialiasing; 159 if(feature == 0x30) 160 return dithering; 161 return 0xffff; /* CACA_FEATURE_UNKNOWN */ 128 162 } 129 163 130 164 void __caca0_set_feature(int feature) 131 165 { 166 unsigned int i; 167 132 168 switch(feature) 133 169 { 134 case CACA_BACKGROUND: 135 feature = CACA_BACKGROUND_SOLID; 136 case CACA_BACKGROUND_BLACK: 137 case CACA_BACKGROUND_SOLID: 138 //_caca_background = feature; 139 break; 140 141 case CACA_ANTIALIASING: 142 feature = CACA_ANTIALIASING_PREFILTER; 143 case CACA_ANTIALIASING_NONE: 144 case CACA_ANTIALIASING_PREFILTER: 145 //_caca_antialiasing = feature; 146 break; 147 148 case CACA_DITHERING: 149 feature = CACA_DITHERING_ORDERED4; 150 case CACA_DITHERING_NONE: 151 case CACA_DITHERING_ORDERED2: 152 case CACA_DITHERING_ORDERED4: 153 case CACA_DITHERING_ORDERED8: 154 case CACA_DITHERING_RANDOM: 155 //_caca_dithering = feature; 170 case 0x10: feature = 0x12; /* CACA_BACKGROUND_SOLID */ 171 case 0x11: case 0x12: 172 background = feature; 173 for(i = 0; i < nbitmaps; i++) 174 cucul_set_dither_color(bitmaps[i], features[feature]); 175 break; 176 177 case 0x20: feature = 0x22; /* CACA_ANTIALIASING_PREFILTER */ 178 case 0x21: case 0x22: 179 antialiasing = feature; 180 for(i = 0; i < nbitmaps; i++) 181 cucul_set_dither_antialias(bitmaps[i], features[feature]); 182 break; 183 184 case 0x30: feature = 0x33; /* CACA_DITHERING_ORDERED4 */ 185 case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: 186 dithering = feature; 187 for(i = 0; i < nbitmaps; i++) 188 cucul_set_dither_mode(bitmaps[i], features[feature]); 156 189 break; 157 190 } … … 162 195 switch(feature) 163 196 { 164 case CACA_BACKGROUND_BLACK: return "black background";165 case CACA_BACKGROUND_SOLID: return "solid background";166 167 case CACA_ANTIALIASING_NONE:return "no antialiasing";168 case CACA_ANTIALIASING_PREFILTER: return "prefilter antialiasing";169 170 case CACA_DITHERING_NONE:return "no dithering";171 case CACA_DITHERING_ORDERED2: return "2x2 ordered dithering";172 case CACA_DITHERING_ORDERED4: return "4x4 ordered dithering";173 case CACA_DITHERING_ORDERED8: return "8x8 ordered dithering";174 case CACA_DITHERING_RANDOM:return "random dithering";197 case 0x11: return "black background"; 198 case 0x12: return "solid background"; 199 200 case 0x21: return "no antialiasing"; 201 case 0x22: return "prefilter antialiasing"; 202 203 case 0x31: return "no dithering"; 204 case 0x32: return "2x2 ordered dithering"; 205 case 0x33: return "4x4 ordered dithering"; 206 case 0x34: return "8x8 ordered dithering"; 207 case 0x35: return "random dithering"; 175 208 176 209 default: return "unknown"; … … 194 227 } 195 228 229 cucul_dither_t *__caca0_create_bitmap(unsigned int bpp, unsigned int w, 230 unsigned int h, unsigned int pitch, 231 unsigned long int r, unsigned long int g, 232 unsigned long int b, unsigned long int a) 233 { 234 cucul_dither_t *d; 235 236 d = cucul_create_dither(bpp, w, h, pitch, r, g, b, a); 237 if(!d) 238 return NULL; 239 240 cucul_set_dither_color(d, features[background]); 241 cucul_set_dither_antialias(d, features[antialiasing]); 242 cucul_set_dither_mode(d, features[dithering]); 243 244 /* Store bitmap in our list */ 245 nbitmaps++; 246 bitmaps = realloc(bitmaps, nbitmaps * (sizeof(cucul_dither_t *))); 247 bitmaps[nbitmaps - 1] = d; 248 249 return d; 250 } 251 252 void __caca0_free_bitmap(cucul_dither_t *d) 253 { 254 unsigned int i, found = 0; 255 256 cucul_free_dither(d); 257 258 /* Remove bitmap from our list */ 259 for(i = 0; i + 1 < nbitmaps; i++) 260 { 261 if(bitmaps[i] == d) 262 found = 1; 263 if(found) 264 bitmaps[i] = bitmaps[i + 1]; 265 } 266 267 nbitmaps--; 268 } 269 -
libcaca/trunk/caca/caca0.h
r1013 r1015 31 31 extern void __caca0_end(void); 32 32 extern unsigned int __caca0_get_event(unsigned int, int); 33 extern unsigned int __caca0_sqrt(unsigned int); 33 34 extern int __caca0_get_feature(int); 34 35 extern void __caca0_set_feature(int); 35 36 extern char const *__caca0_get_feature_name(int); 36 37 extern cucul_canvas_t *__caca0_load_sprite(char const *); 38 extern cucul_dither_t *__caca0_create_bitmap(unsigned int, unsigned int, 39 unsigned int, unsigned int, unsigned long int, unsigned long int, 40 unsigned long int, unsigned long int); 41 extern void __caca0_free_bitmap(cucul_dither_t *); 37 42 38 43 /* These variables are needed to emulate old non-thread safe behaviour */ … … 87 92 }; 88 93 94 /* This enum still exists in libcaca 1.x, thus cannot be redefined */ 89 95 #define CACA_EVENT_NONE 0x00000000 90 96 #define CACA_EVENT_KEY_PRESS 0x01000000 … … 124 130 #define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp) 125 131 126 #define caca_set_color(x, y) cucul_set_color(__caca0_cv, x, y) 132 #define caca_set_color(x, y) \ 133 (__caca0_fg = (x), __caca0_bg = (y), cucul_set_color(__caca0_cv, x, y)) 134 #define caca_get_fg_color() __caca0_fg 135 #define caca_get_bg_color() __caca0_bg 127 136 #define caca_get_color_name cucul_get_color_name 128 137 #define caca_putchar(x, y, c) cucul_putchar(__caca0_cv, x, y, c) … … 167 176 168 177 #define caca_rand(a, b) cucul_rand(a, (b)+1) 178 #define caca_sqrt __caca0_sqrt 169 179 170 180 #define caca_sprite cucul_canvas 171 181 #define caca_load_sprite __caca0_load_sprite 172 #define caca_get_sprite_frames(c) 0182 #define caca_get_sprite_frames(c) 1 173 183 #define caca_get_sprite_width(c, f) cucul_get_canvas_width(c) 174 184 #define caca_get_sprite_height(c, f) cucul_get_canvas_height(c) … … 179 189 180 190 #define caca_bitmap cucul_dither 181 #define caca_create_bitmap cucul_create_dither191 #define caca_create_bitmap __caca0_create_bitmap 182 192 #define caca_set_bitmap_palette cucul_set_dither_palette 183 193 #define caca_draw_bitmap(x, y, z, t, b, p) \ 184 194 cucul_dither_bitmap(__caca0_cv, x, y, z, t, b, p) 185 #define caca_free_bitmap cucul_free_dither195 #define caca_free_bitmap __caca0_free_bitmap 186 196 187 197 #ifdef __cplusplus
Note: See TracChangeset
for help on using the changeset viewer.