Changeset 193 for libcaca/trunk/src/blit.c
- Timestamp:
- Nov 16, 2003, 4:20:17 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/blit.c
r192 r193 35 35 #include "caca_internals.h" 36 36 37 #include <stdio.h> 37 static enum caca_dithering _caca_dithering = CACA_DITHER_NONE; 38 39 void caca_set_dithering(enum caca_dithering dither) 40 { 41 if(dither < 0 || dither > 1) 42 return; 43 44 _caca_dithering = dither; 45 } 46 38 47 void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) 39 48 { 40 char foo[] = { ' ', '.', ':', ';', '=', ' $', '%', '@', '#', '8', 'W' };49 char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' }; 41 50 int x, y, pitch; 42 51 … … 56 65 for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= (int)caca_get_width(); x++) 57 66 { 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}; 58 69 int fromx = w * (x - x1) / (x2 - x1 + 1); 59 70 int fromy = h * (y - y1) / (y2 - y1 + 1); … … 61 72 int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy]; 62 73 int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy]; 74 int hue, sat, val; 63 75 64 if(r == g && g == b) 76 int min = r, max = r, delta; 77 if(min > g) min = g; if(max < g) max = g; 78 if(min > b) min = b; if(max < b) max = b; 79 80 delta = max - min; 81 val = max; /* 0 - 255 */ 82 sat = max ? 256 * delta / max : 0; /* 0 - 255 */ 83 84 if(sat > caca_rand(64, 128)) 65 85 { 66 caca_set_color(EE_LIGHTGRAY); 86 /* XXX: Values are automatically clipped between 0 and 6 87 * because of delta/2 */ 88 if( r == max ) 89 hue = 1 + (float)(g - b + delta / 2 + caca_rand(-40, 40)) / delta; 90 else if( g == max ) 91 hue = 3 + (float)(b - r + delta / 2 + caca_rand(-40, 40)) / delta; 92 else 93 hue = 5 + (float)(r - g + delta / 2 + caca_rand(-40, 40)) / delta; 94 95 if(val > caca_rand(128, 192)) 96 caca_set_color(light_colors[hue]); 97 else 98 caca_set_color(dark_colors[hue]); 67 99 } 68 100 else 69 101 { 70 static int foo_colors[6] = {EE_LIGHTRED, EE_YELLOW, EE_LIGHTGREEN, EE_LIGHTCYAN, EE_LIGHTBLUE, EE_LIGHTMAGENTA}; 71 float min = r, max = r, delta, hue, sat; 72 if(min > g) min = g; if(max < g) max = g; 73 if(min > b) min = b; if(max < b) max = b; 74 75 delta = max - min; 76 77 sat = max / delta; 78 79 if(delta > 20) 80 { 81 if( r == max ) 82 hue = (g - b) / delta; // between yellow & magenta 83 else if( g == max ) 84 hue = 2 + (b - r) / delta; // between cyan & yellow 85 else 86 hue = 4 + (r - g) / delta; // between magenta & cyan 87 88 hue *= 60; // degrees 89 if( hue < 0 ) 90 hue += 360; 91 92 caca_set_color(foo_colors[(int)(hue + 30) / 60]); 93 } 94 else 95 { 96 caca_set_color(EE_LIGHTGRAY); 97 } 102 caca_set_color(CACA_COLOR_LIGHTGRAY); 98 103 } 99 104 100 caca_putchar(x, y, foo[(r + g + b ) / 3 / 25]);105 caca_putchar(x, y, foo[(r + g + b + caca_rand(-10, 10)) / 3 / 25]); 101 106 } 102 107 }
Note: See TracChangeset
for help on using the changeset viewer.