Changeset 670 for libcaca/trunk
- Timestamp:
- Mar 22, 2006, 8:54:37 PM (15 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/canvas.c
r668 r670 66 66 * \return The current foreground colour. 67 67 */ 68 enum cucul_color cucul_get_fg_color(cucul_t *qq)68 enum cucul_color cucul_get_fg_color(cucul_t const *qq) 69 69 { 70 70 return qq->fgcolor; … … 78 78 * \return The current background colour. 79 79 */ 80 enum cucul_color cucul_get_bg_color(cucul_t *qq)80 enum cucul_color cucul_get_bg_color(cucul_t const *qq) 81 81 { 82 82 return qq->bgcolor; … … 227 227 * This function fills a byte array with the character values. 228 228 */ 229 void cucul_get_screen(cucul_t *qq, char *buffer)229 void cucul_get_screen(cucul_t const *qq, char *buffer) 230 230 { 231 231 unsigned int x, y; … … 260 260 } 261 261 262 /** \brief Blit a canvas onto another one. 263 * 264 * This function blits a canvas onto another one at the given coordinates. 265 * An optional mask canvas can be used. 266 * 267 * \param dst The destination canvas. 268 * \param x X coordinate. 269 * \param y Y coordinate. 270 * \param src The source canvas. 271 * \param mask The mask canvas. 272 */ 273 void cucul_blit(cucul_t *dst, int x, int y, 274 cucul_t const *src, cucul_t const *mask) 275 { 276 int i, j, starti, startj, endi, endj; 277 278 if(src->width != mask->width || src->height != mask->height) 279 return; 280 281 starti = x < 0 ? -x : 0; 282 startj = y < 0 ? -y : 0; 283 endi = (x + src->width >= dst->width) ? dst->width - x : src->width; 284 endj = (y + src->height >= dst->height) ? dst->height - y : src->height; 285 286 for(j = startj; j < endj; j++) 287 { 288 for(i = starti; i < endi; i++) 289 { 290 if(mask && mask->chars[j * src->width + i] == (uint32_t)' ') 291 continue; 292 293 dst->chars[(j + y) * dst->width + (i + x)] 294 = src->chars[j * src->width + i]; 295 dst->attr[(j + y) * dst->width + (i + x)] 296 = src->attr[j * src->width + i]; 297 } 298 } 299 } 300 -
libcaca/trunk/cucul/cucul.h
r667 r670 129 129 /* @} */ 130 130 131 /** \defgroup char Character printing 132 * 133 * These functions provide low-level character printing routines. 131 /** \defgroup canvas Canvas drawing 132 * 133 * These functions provide low-level character printing routines and 134 * higher level graphics functions. 134 135 * 135 136 * @{ */ 136 137 void cucul_set_color(cucul_t *, enum cucul_color, enum cucul_color); 137 enum cucul_color cucul_get_fg_color(cucul_t *);138 enum cucul_color cucul_get_bg_color(cucul_t *);138 enum cucul_color cucul_get_fg_color(cucul_t const *); 139 enum cucul_color cucul_get_bg_color(cucul_t const *); 139 140 char const *cucul_get_color_name(enum cucul_color); 140 141 void cucul_putchar(cucul_t *, int, int, char); 141 142 void cucul_putstr(cucul_t *, int, int, char const *); 142 143 void cucul_printf(cucul_t *, int, int, char const *, ...); 143 void cucul_get_screen(cucul_t *, char *);144 void cucul_get_screen(cucul_t const *, char *); 144 145 void cucul_clear(cucul_t *); 146 void cucul_blit(cucul_t *, int, int, cucul_t const *, cucul_t const *); 145 147 /* @} */ 146 148 -
libcaca/trunk/test/Makefile.am
r654 r670 24 24 25 25 gamma_SOURCES = gamma.c 26 gamma_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ 26 gamma_LDADD = ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ @MATH_LIBS@ 27 27 gamma_CPPFLAGS = -I$(top_srcdir)/cucul -I$(top_srcdir)/caca 28 28 -
libcaca/trunk/test/gamma.c
r666 r670 22 22 #endif 23 23 24 #if !defined(__KERNEL__) 25 # include <stdio.h> 26 # include <math.h> 27 #endif 28 24 29 #include "cucul.h" 25 30 #include "caca.h" … … 29 34 int main(void) 30 35 { 31 cucul_t *qq ;36 cucul_t *qq, *gg, *mask; 32 37 caca_t *kk; 33 34 38 struct cucul_bitmap *left, *right; 39 float gam = 1.0; 35 40 int x; 36 41 37 42 qq = cucul_init(0, 0); 38 43 kk = caca_attach(qq); 44 45 gg = cucul_init(cucul_get_width(qq), cucul_get_height(qq)); 46 mask = cucul_init(cucul_get_width(qq), cucul_get_height(qq)); 39 47 40 48 for(x = 0; x < 256; x++) … … 52 60 caca_set_delay(kk, 20000); 53 61 54 for(x = 0; ; x = (x + 1) % 256)62 for(x = 0; ; x++) 55 63 { 56 float g = (x > 128) ? (256.0 + 8.0 - x) / 64.0 : (8.0 + x) / 64.0;64 int ev = caca_get_event(kk, CACA_EVENT_KEY_PRESS); 57 65 58 if(caca_get_event(kk, CACA_EVENT_KEY_PRESS)) 66 if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT)) 67 gam /= 1.03; 68 else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT)) 69 gam *= 1.03; 70 else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN)) 71 gam = 1.0; 72 else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE)) 59 73 break; 60 74 61 cucul_draw_bitmap(qq, 0, cucul_get_height(qq) / 2, 75 /* Resize the spare canvas, just in case the main one changed */ 76 cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq)); 77 cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq)); 78 79 /* Draw the regular bitmap on the main canvas */ 80 cucul_draw_bitmap(qq, 0, 0, 62 81 cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, 63 82 left, buffer); 64 83 65 cucul_set_bitmap_gamma(right, g); 66 cucul_draw_bitmap(qq, 0, 0, 67 cucul_get_width(qq) - 1, cucul_get_height(qq) / 2 - 1, 84 /* Draw the gamma-modified bitmap on the spare canvas */ 85 cucul_set_bitmap_gamma(right, gam); 86 cucul_draw_bitmap(gg, 0, 0, 87 cucul_get_width(gg) - 1, cucul_get_height(gg) - 1, 68 88 right, buffer); 69 89 90 /* Draw something on the mask */ 91 cucul_clear(mask); 92 cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE); 93 cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x)) 94 * 0.5 * cucul_get_width(mask), 95 (1.0 + cos(0.05 * (float)x)) 96 * 0.5 * cucul_get_height(mask), 97 cucul_get_width(mask) / 2, 98 cucul_get_height(mask) / 2, '#'); 99 100 /* Blit the spare canvas onto the first one */ 101 cucul_blit(qq, 0, 0, gg, mask); 102 70 103 cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); 71 cucul_printf(qq, 2, 1, "gamma=%g", g); 104 cucul_printf(qq, 2, 1, 105 "gamma=%g - use arrows to change, Esc to quit", gam); 72 106 73 107 caca_display(kk);
Note: See TracChangeset
for help on using the changeset viewer.