- Timestamp:
- Nov 16, 2003, 6:41:43 PM (17 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/examples/demo.c
r193 r195 48 48 int bounds = 0; 49 49 int outline = 0; 50 int dithering = 0; 50 51 struct caca_sprite *sprite = NULL; 51 52 … … 77 78 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/pikachu.jpeg", NULL); 78 79 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gradient.png", NULL); 80 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/beastie.png", NULL); 81 pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/stitch.jpg", NULL); 82 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/dranac.jpeg", NULL); 79 83 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/artwork/aboire.png", NULL); 80 84 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/web/sam.zoy.org/artwork/goret.png", NULL); 81 85 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/lilkim02.jpg", NULL); 82 pixbuf = gdk_pixbuf_new_from_file("/home/sam/etw.bmp", NULL);86 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/etw.bmp", NULL); 83 87 if(!pixbuf) return -2; 84 88 pixels = gdk_pixbuf_get_pixels(pixbuf); … … 124 128 display_menu(); 125 129 break; 130 case 'd': 131 case 'D': 132 dithering = (dithering + 1) % 3; 133 caca_set_dithering(dithering == 0 ? CACA_DITHER_NONE : 134 dithering == 1 ? CACA_DITHER_ORDERED : 135 CACA_DITHER_RANDOM); 136 display_menu(); 137 break; 126 138 case 'c': 127 139 demo = demo_color; … … 214 226 caca_printf(4, 19, "'b': drawing boundaries: %s", 215 227 bounds == 0 ? "screen" : "infinite"); 228 caca_printf(4, 20, "'d': %s dithering", 229 dithering == 0 ? "no" : dithering == 1 ? "ordered" : "random"); 216 230 217 231 caca_putstr(4, yo - 2, "'q': quit"); … … 465 479 static void demo_blit(void) 466 480 { 467 caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4, pixels, bufx, bufy); 468 } 469 481 caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4, 482 pixels, bufx, bufy); 483 } 484 -
libcaca/trunk/src/blit.c
r193 r195 35 35 #include "caca_internals.h" 36 36 37 /* Dithering methods */ 38 static void init_no_dither(int); 39 static int get_no_dither(void); 40 static void increment_no_dither(void); 41 42 static void init_ordered_dither(int); 43 static int get_ordered_dither(void); 44 static void increment_ordered_dither(void); 45 46 static void init_random_dither(int); 47 static int get_random_dither(void); 48 static void increment_random_dither(void); 49 50 /* Current dithering method */ 37 51 static enum caca_dithering _caca_dithering = CACA_DITHER_NONE; 38 52 53 static void (*_init_dither) (int) = init_no_dither; 54 static int (*_get_dither) (void) = get_no_dither; 55 static void (*_increment_dither) (void) = increment_no_dither; 56 39 57 void caca_set_dithering(enum caca_dithering dither) 40 58 { 41 if(dither < 0 || dither > 1) 59 switch(dither) 60 { 61 case CACA_DITHER_NONE: 62 _init_dither = init_no_dither; 63 _get_dither = get_no_dither; 64 _increment_dither = increment_no_dither; 65 break; 66 67 case CACA_DITHER_ORDERED: 68 _init_dither = init_ordered_dither; 69 _get_dither = get_ordered_dither; 70 _increment_dither = increment_ordered_dither; 71 break; 72 73 case CACA_DITHER_RANDOM: 74 _init_dither = init_random_dither; 75 _get_dither = get_random_dither; 76 _increment_dither = increment_random_dither; 77 break; 78 79 default: 42 80 return; 81 } 43 82 44 83 _caca_dithering = dither; … … 47 86 void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) 48 87 { 49 char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' }; 88 static int light_colors[] = {CACA_COLOR_LIGHTMAGENTA, CACA_COLOR_LIGHTRED, CACA_COLOR_YELLOW, CACA_COLOR_LIGHTGREEN, CACA_COLOR_LIGHTCYAN, CACA_COLOR_LIGHTBLUE, CACA_COLOR_LIGHTMAGENTA}; 89 static int dark_colors[] = {CACA_COLOR_MAGENTA, CACA_COLOR_RED, CACA_COLOR_BROWN, CACA_COLOR_GREEN, CACA_COLOR_CYAN, CACA_COLOR_BLUE, CACA_COLOR_MAGENTA}; 90 static char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' }; 50 91 int x, y, pitch; 51 92 … … 63 104 64 105 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)caca_get_height(); y++) 106 { 107 /* Initialize dither tables for the current line */ 108 _init_dither(y); 109 110 /* Dither the current line */ 65 111 for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= (int)caca_get_width(); x++) 66 112 { 67 static int light_colors[] = {CACA_COLOR_LIGHTMAGENTA, CACA_COLOR_LIGHTRED, CACA_COLOR_YELLOW, CACA_COLOR_LIGHTGREEN, CACA_COLOR_LIGHTCYAN, CACA_COLOR_LIGHTBLUE, CACA_COLOR_LIGHTMAGENTA};68 static int dark_colors[] = {CACA_COLOR_MAGENTA, CACA_COLOR_RED, CACA_COLOR_BROWN, CACA_COLOR_GREEN, CACA_COLOR_CYAN, CACA_COLOR_BLUE, CACA_COLOR_MAGENTA};69 113 int fromx = w * (x - x1) / (x2 - x1 + 1); 70 114 int fromy = h * (y - y1) / (y2 - y1 + 1); … … 82 126 sat = max ? 256 * delta / max : 0; /* 0 - 255 */ 83 127 84 if(sat > caca_rand(64, 128))128 if(sat > (_get_dither() + 24) * 4) 85 129 { 86 /* XXX: Values are automatically clipped between 0 and 6 87 * because of delta/2 */ 130 /* XXX: Values should be between 1 and 6, but since we 131 * are dithering, there may be overflows, hence our bigger 132 * *_colors[] tables. */ 88 133 if( r == max ) 89 hue = 1 + (float)(g - b + delta / 2 + caca_rand(-40, 40)) / delta;134 hue = 256 + 256 * (g - b) / delta; 90 135 else if( g == max ) 91 hue = 3 + (float)(b - r + delta / 2 + caca_rand(-40, 40)) / delta;136 hue = 768 + 256 * (b - r) / delta; 92 137 else 93 hue = 5 + (float)(r - g + delta / 2 + caca_rand(-40, 40)) / delta; 94 95 if(val > caca_rand(128, 192)) 138 hue = 1280 + 256 * (r - g) / delta; 139 140 hue = (hue + 128 + 8 * _get_dither()) / 256; 141 142 if(val > (_get_dither() + 40) * 4) 96 143 caca_set_color(light_colors[hue]); 97 144 else … … 103 150 } 104 151 105 caca_putchar(x, y, foo[(r + g + b + caca_rand(-10, 10)) / 3 / 25]); 152 caca_putchar(x, y, foo[(r + g + b + 2 * _get_dither()) / 3 / 25]); 153 154 _increment_dither(); 106 155 } 107 } 108 156 } 157 } 158 159 /* 160 * XXX: The following functions are local. 161 */ 162 163 /* 164 * No dithering 165 */ 166 static void init_no_dither(int line) 167 { 168 ; 169 } 170 171 static int get_no_dither(void) 172 { 173 return 0; 174 } 175 176 static void increment_no_dither(void) 177 { 178 return; 179 } 180 181 /* 182 * Ordered dithering 183 */ 184 static int dither4x4[] = {-8, 0, -6, 2, 185 4, -4, 6, -2, 186 -5, 3, -7, 1, 187 7, -1, 5, -3}; 188 static int *dither_table; 189 static int dither_index; 190 191 static void init_ordered_dither(int line) 192 { 193 dither_table = dither4x4 + (line % 4) * 4; 194 dither_index = 0; 195 } 196 197 static int get_ordered_dither(void) 198 { 199 return dither_table[dither_index]; 200 } 201 202 static void increment_ordered_dither(void) 203 { 204 dither_index = (dither_index + 1) % 4; 205 } 206 207 /* 208 * Random dithering 209 */ 210 static void init_random_dither(int line) 211 { 212 ; 213 } 214 215 static int get_random_dither(void) 216 { 217 return caca_rand(-8, 7); 218 } 219 220 static void increment_random_dither(void) 221 { 222 return; 223 } 224 -
libcaca/trunk/src/caca.h
r193 r195 58 58 enum caca_dithering 59 59 { 60 CACA_DITHER_NONE = 0, 61 CACA_DITHER_RANDOM = 1 60 CACA_DITHER_NONE, 61 CACA_DITHER_ORDERED, 62 CACA_DITHER_RANDOM 62 63 }; 63 64
Note: See TracChangeset
for help on using the changeset viewer.