Changeset 246 for libcaca/trunk/src
- Timestamp:
- Dec 11, 2003, 5:31:49 PM (19 years ago)
- Location:
- libcaca/trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/bitmap.c
r240 r246 51 51 static void mask2shift(unsigned int, int *, int *); 52 52 53 static void get_rgb_default(struct caca_bitmap *, uint8_t *, int, int, 54 unsigned int *, unsigned int *, unsigned int *); 53 static void get_rgba_default(const struct caca_bitmap *, uint8_t *, int, int, 54 unsigned int *, unsigned int *, unsigned int *, 55 unsigned int *); 55 56 static void rgb2hsv_default(int, int, int, int *, int *, int *); 56 57 … … 128 129 int bpp, palette; 129 130 int w, h, pitch; 130 int rmask, gmask, bmask ;131 int rright, gright, bright ;132 int rleft, gleft, bleft ;131 int rmask, gmask, bmask, amask; 132 int rright, gright, bright, aright; 133 int rleft, gleft, bleft, aleft; 133 134 void (*get_hsv)(struct caca_bitmap *, char *, int, int); 134 int red[256], green[256], blue[256] ;135 int red[256], green[256], blue[256], alpha[256]; 135 136 }; 136 137 … … 161 162 162 163 struct caca_bitmap *caca_create_bitmap(int bpp, int w, int h, int pitch, 163 int rmask, int gmask, int bmask) 164 int rmask, int gmask, int bmask, 165 int amask) 164 166 { 165 167 struct caca_bitmap *bitmap; … … 183 185 bitmap->gmask = gmask; 184 186 bitmap->bmask = bmask; 187 bitmap->amask = amask; 185 188 186 189 /* Load bitmasks */ 187 if(rmask || gmask || bmask )190 if(rmask || gmask || bmask || amask) 188 191 { 189 192 mask2shift(rmask, &bitmap->rright, &bitmap->rleft); 190 193 mask2shift(gmask, &bitmap->gright, &bitmap->gleft); 191 194 mask2shift(bmask, &bitmap->bright, &bitmap->bleft); 195 mask2shift(amask, &bitmap->aright, &bitmap->aleft); 192 196 } 193 197 … … 199 203 for(i = 0; i < 256; i++) 200 204 { 201 bitmap->red[i] = i * 0x10; 202 bitmap->green[i] = i * 0x10; 203 bitmap->blue[i] = i * 0x10; 205 bitmap->red[i] = i * 0xfff / 256; 206 bitmap->green[i] = i * 0xfff / 256; 207 bitmap->blue[i] = i * 0xfff / 256; 208 bitmap->alpha[i] = 0xfff; 204 209 } 205 210 } … … 209 214 210 215 void caca_set_bitmap_palette(struct caca_bitmap *bitmap, 211 int red[], int green[], int blue[]) 216 unsigned int red[], unsigned int green[], 217 unsigned int blue[], unsigned int alpha[]) 212 218 { 213 219 int i; … … 220 226 if(red[i] >= 0 && red[i] < 0x1000 && 221 227 green[i] >= 0 && green[i] < 0x1000 && 222 blue[i] >= 0 && blue[i] < 0x1000) 228 blue[i] >= 0 && blue[i] < 0x1000 && 229 alpha[i] >= 0 && alpha[i] < 0x1000) 223 230 { 224 231 bitmap->red[i] = red[i]; 225 232 bitmap->green[i] = green[i]; 226 233 bitmap->blue[i] = blue[i]; 234 bitmap->alpha[i] = alpha[i]; 227 235 } 228 236 } … … 237 245 } 238 246 239 static void get_rgb _default(struct caca_bitmap *bitmap, uint8_t *pixels,240 int x, int y, unsigned int *r,241 unsigned int *g, unsigned int *b)247 static void get_rgba_default(const struct caca_bitmap *bitmap, uint8_t *pixels, 248 int x, int y, unsigned int *r, unsigned int *g, 249 unsigned int *b, unsigned int *a) 242 250 { 243 251 uint32_t bits; … … 255 263 if(__BYTE_ORDER == __BIG_ENDIAN) 256 264 #else 257 static const uint32_t rmask = 0x12345678; 258 if(*(uint8_t *)&rmask == 0x12) 265 /* This is compile-time optimised with at least -O1 or -Os */ 266 const uint32_t rmask = 0x12345678; 267 if(*(const uint8_t *)&rmask == 0x12) 259 268 #endif 260 269 bits = ((uint32_t)pixels[0] << 16) | … … 281 290 *g = bitmap->green[bits]; 282 291 *b = bitmap->blue[bits]; 292 *a = bitmap->alpha[bits]; 283 293 } 284 294 else … … 287 297 *g = ((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft; 288 298 *b = ((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft; 299 *a = ((bits & bitmap->amask) >> bitmap->aright) << bitmap->aleft; 289 300 } 290 301 } … … 321 332 322 333 void caca_draw_bitmap(int x1, int y1, int x2, int y2, 323 struct caca_bitmap *bitmap, char *pixels)334 const struct caca_bitmap *bitmap, char *pixels) 324 335 { 325 336 #if !NEW_RENDERER … … 359 370 static const char density_chars[] = 360 371 " " 361 " 362 ". `"363 " ,`.'"364 " i:-^"365 " |=+;"366 " ox/\\"367 " <>x%"368 "& $zw"369 "WX KM"370 " #8##"371 "8 @8#"372 " @8@8"372 ". " 373 ".. " 374 "...." 375 "::::" 376 ";=;=" 377 "tftf" 378 "%$%$" 379 "&KSZ" 380 "WXGM" 381 "@@@@" 382 "8888" 383 "####" 373 384 "????"; 374 385 … … 392 403 } 393 404 394 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int) caca_get_height(); y++)405 for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)_caca_height; y++) 395 406 for(x = x1 > 0 ? x1 : 0, _init_dither(y); 396 x <= x2 && x <= (int) caca_get_width();407 x <= x2 && x <= (int)_caca_width; 397 408 x++) 398 409 { 399 410 int ch; 400 unsigned int r, g, b, R, G, B;411 unsigned int r, g, b, a, R, G, B; 401 412 int hue, sat, val; 402 413 int fromx = w * (x - x1) / (x2 - x1 + 1); … … 414 425 /* First get RGB */ 415 426 R = 0, G = 0, B = 0; 416 get_rgb_default(bitmap, pixels, fromx, fromy, &r, &g, &b); 427 get_rgba_default(bitmap, pixels, fromx, fromy, &r, &g, &b, &a); 428 if(a == 0) 429 continue; 417 430 #if 1 418 431 R += r; G += g; B += b; 419 432 #else 420 433 R += r; G += g; B += b; 421 get_rgb _default(bitmap, pixels, fromx - 1, fromy, &r, &g, &b);434 get_rgba_default(bitmap, pixels, fromx - 1, fromy, &r, &g, &b, &a); 422 435 R += r; G += g; B += b; 423 get_rgb _default(bitmap, pixels, fromx, fromy - 1, &r, &g, &b);436 get_rgba_default(bitmap, pixels, fromx, fromy - 1, &r, &g, &b, &a); 424 437 R += r; G += g; B += b; 425 get_rgb _default(bitmap, pixels, fromx + 1, fromy, &r, &g, &b);438 get_rgba_default(bitmap, pixels, fromx + 1, fromy, &r, &g, &b, &a); 426 439 R += r; G += g; B += b; 427 get_rgb _default(bitmap, pixels, fromx, fromy + 1, &r, &g, &b);440 get_rgba_default(bitmap, pixels, fromx, fromy + 1, &r, &g, &b, &a); 428 441 R += r; G += g; B += b; 429 442 R /= 5; G /= 5; B /= 5; … … 444 457 distbg = XRATIO * val * val; 445 458 distbg += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 459 distbg = distbg * 2 / 4; 446 460 outbg = CACA_COLOR_BLACK; 447 461 … … 510 524 + HRATIO * (hue - hue2) * (hue - hue2); 511 525 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 512 dist = dist * 3 / 4;526 // dist = dist * 3 / 4; 513 527 if(dist <= distbg) 514 528 { … … 529 543 + HRATIO * (hue - hue2) * (hue - hue2); 530 544 dist += FUZZINESS * _get_dither() - 0x80 * FUZZINESS; 531 dist = dist / 2; 545 //dist = dist * 3 / 4; 546 //dist = dist / 2; 532 547 if(dist <= distbg) 533 548 { -
libcaca/trunk/src/box.c
r205 r246 59 59 } 60 60 61 xmax = caca_get_width()- 1;62 ymax = caca_get_height()- 1;61 xmax = _caca_width - 1; 62 ymax = _caca_height - 1; 63 63 64 64 if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) … … 112 112 } 113 113 114 xmax = caca_get_width()- 1;115 ymax = caca_get_height()- 1;114 xmax = _caca_width - 1; 115 ymax = _caca_height - 1; 116 116 117 117 if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) -
libcaca/trunk/src/caca.c
r238 r246 39 39 # include <dos.h> 40 40 # include <conio.h> 41 # if defined(SCREENUPDATE_IN_PC_H)42 # include <pc.h>43 # endif44 41 #else 45 42 # error "no graphics library detected" … … 63 60 64 61 #if defined(USE_CONIO) 65 static struct text_info ti;66 62 char *_caca_screen; 67 63 #endif … … 133 129 unsigned int caca_get_width(void) 134 130 { 135 #if defined(USE_SLANG) 136 return SLtt_Screen_Cols; 137 #elif defined(USE_NCURSES) 138 return COLS; 139 #elif defined(USE_CONIO) 140 return ti.screenwidth; 141 #endif 131 return _caca_width; 142 132 } 143 133 144 134 unsigned int caca_get_height(void) 145 135 { 146 #if defined(USE_SLANG) 147 return SLtt_Screen_Rows; 148 #elif defined(USE_NCURSES) 149 return LINES; 150 #else 151 return ti.screenheight; 152 #endif 136 return _caca_height; 153 137 } 154 138 … … 213 197 textcolor((enum COLORS)WHITE); 214 198 textbackground((enum COLORS)BLACK); 215 gotoxy( caca_get_width(), caca_get_height());199 gotoxy(_caca_width, _caca_height); 216 200 cputs("\r\n"); 217 201 _setcursortype(_NORMALCURSOR); -
libcaca/trunk/src/caca.h
r238 r246 201 201 struct caca_sprite; 202 202 struct caca_sprite * caca_load_sprite(const char *); 203 int caca_get_sprite_frames( struct caca_sprite *);204 int caca_get_sprite_width( struct caca_sprite *, int);205 int caca_get_sprite_height( struct caca_sprite *, int);206 int caca_get_sprite_dx( struct caca_sprite *, int);207 int caca_get_sprite_dy( struct caca_sprite *, int);208 void caca_draw_sprite(int, int, struct caca_sprite *, int);203 int caca_get_sprite_frames(const struct caca_sprite *); 204 int caca_get_sprite_width(const struct caca_sprite *, int); 205 int caca_get_sprite_height(const struct caca_sprite *, int); 206 int caca_get_sprite_dx(const struct caca_sprite *, int); 207 int caca_get_sprite_dy(const struct caca_sprite *, int); 208 void caca_draw_sprite(int, int, const struct caca_sprite *, int); 209 209 void caca_free_sprite(struct caca_sprite *); 210 210 … … 213 213 */ 214 214 struct caca_bitmap; 215 struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int); 216 void caca_set_bitmap_palette(struct caca_bitmap *, int[], int[], int[]); 217 void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *); 215 struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int, int); 216 void caca_set_bitmap_palette(struct caca_bitmap *, unsigned int[], 217 unsigned int[], unsigned int[], unsigned int[]); 218 void caca_draw_bitmap(int, int, int, int, const struct caca_bitmap *, char *); 218 219 void caca_free_bitmap(struct caca_bitmap *); 219 220 -
libcaca/trunk/src/caca_internals.h
r227 r246 38 38 39 39 #if defined(USE_CONIO) 40 extern struct text_info _ti; 40 41 extern char *_caca_screen; 41 42 #endif 43 44 extern unsigned int _caca_width; 45 extern unsigned int _caca_height; 42 46 43 47 extern char *_caca_empty_line; -
libcaca/trunk/src/conic.c
r205 r246 192 192 uint8_t b = 0; 193 193 194 if(xo + x >= 0 && xo + x < (int) caca_get_width())194 if(xo + x >= 0 && xo + x < (int)_caca_width) 195 195 b |= 0x1; 196 if(xo - x >= 0 && xo - x < (int) caca_get_width())196 if(xo - x >= 0 && xo - x < (int)_caca_width) 197 197 b |= 0x2; 198 if(yo + y >= 0 && yo + y < (int) caca_get_height())198 if(yo + y >= 0 && yo + y < (int)_caca_height) 199 199 b |= 0x4; 200 if(yo - y >= 0 && yo - y < (int) caca_get_height())200 if(yo - y >= 0 && yo - y < (int)_caca_height) 201 201 b |= 0x8; 202 202 -
libcaca/trunk/src/graphics.c
r231 r246 36 36 #elif defined(USE_CONIO) 37 37 # include <conio.h> 38 # if defined(SCREENUPDATE_IN_PC_H) 39 # include <pc.h> 40 # endif 38 41 #else 39 42 # error "no graphics library detected" … … 55 58 #include "caca_internals.h" 56 59 60 #ifdef USE_CONIO 61 static struct text_info ti; 62 #endif 63 64 unsigned int _caca_width; 65 unsigned int _caca_height; 66 57 67 static unsigned int _caca_delay; 58 68 static unsigned int _caca_rendertime; … … 93 103 char *data; 94 104 #endif 95 if(x < 0 || x >= (int) caca_get_width()||96 y < 0 || y >= (int) caca_get_height())105 if(x < 0 || x >= (int)_caca_width || 106 y < 0 || y >= (int)_caca_height) 97 107 return; 98 108 … … 104 114 addch(c); 105 115 #elif defined(USE_CONIO) 106 data = _caca_screen + 2 * (x + y * caca_get_width());116 data = _caca_screen + 2 * (x + y * _caca_width); 107 117 data[0] = c; 108 118 data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; … … 116 126 unsigned int len; 117 127 118 if(y < 0 || y >= (int) caca_get_height() || x >= (int)caca_get_width())128 if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width) 119 129 return; 120 130 … … 130 140 } 131 141 132 if(x + len >= caca_get_width())133 { 134 memcpy(_caca_scratch_line, s, caca_get_width()- x);135 _caca_scratch_line[ caca_get_width()- x] = '\0';142 if(x + len >= _caca_width) 143 { 144 memcpy(_caca_scratch_line, s, _caca_width - x); 145 _caca_scratch_line[_caca_width - x] = '\0'; 136 146 s = _caca_scratch_line; 137 147 } … … 144 154 addstr(s); 145 155 #elif defined(USE_CONIO) 146 char *buf = _caca_screen + 2 * (x + y * caca_get_width());156 char *buf = _caca_screen + 2 * (x + y * _caca_width); 147 157 while(*s) 148 158 { … … 161 171 va_list args; 162 172 163 if(y < 0 || y >= (int) caca_get_height() || x >= (int)caca_get_width())173 if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width) 164 174 return; 165 175 166 if( caca_get_width()- x + 1 > BUFSIZ)167 buf = malloc( caca_get_width()- x + 1);176 if(_caca_width - x + 1 > BUFSIZ) 177 buf = malloc(_caca_width - x + 1); 168 178 169 179 va_start(args, format); 170 180 #if defined(HAVE_VSNPRINTF) 171 vsnprintf(buf, caca_get_width()- x + 1, format, args);181 vsnprintf(buf, _caca_width - x + 1, format, args); 172 182 #else 173 183 vsprintf(buf, format, args); 174 184 #endif 175 buf[ caca_get_width()- x] = '\0';185 buf[_caca_width - x] = '\0'; 176 186 va_end(args); 177 187 … … 186 196 enum caca_color oldfg = caca_get_fg_color(); 187 197 enum caca_color oldbg = caca_get_bg_color(); 188 int y = caca_get_height();198 int y = _caca_height; 189 199 190 200 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); … … 235 245 SLtt_Has_Alt_Charset = 0; 236 246 247 _caca_width = SLtt_Screen_Cols; 248 _caca_height = SLtt_Screen_Rows; 249 237 250 #elif defined(USE_NCURSES) 238 251 static int curses_colors[] = … … 293 306 } 294 307 308 _caca_width = COLS; 309 _caca_height = LINES; 310 295 311 #elif defined(USE_CONIO) 296 312 gettextinfo(&ti); … … 303 319 /* FIXME */ 304 320 # endif 305 306 #endif 307 _caca_empty_line = malloc(caca_get_width() + 1); 308 memset(_caca_empty_line, ' ', caca_get_width()); 309 _caca_empty_line[caca_get_width()] = '\0'; 310 311 _caca_scratch_line = malloc(caca_get_width() + 1); 321 _caca_width = ti.screenwidth; 322 _caca_height = ti.screenheight; 323 324 #endif 325 _caca_empty_line = malloc(_caca_width + 1); 326 memset(_caca_empty_line, ' ', _caca_width); 327 _caca_empty_line[_caca_width] = '\0'; 328 329 _caca_scratch_line = malloc(_caca_width + 1); 312 330 313 331 _caca_delay = 0; -
libcaca/trunk/src/line.c
r205 r246 172 172 else if(bits1 & (1<<1)) 173 173 { 174 int xmax = caca_get_width()- 1;174 int xmax = _caca_width - 1; 175 175 s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); 176 176 s->x1 = xmax; … … 183 183 else if(bits1 & (1<<3)) 184 184 { 185 int ymax = caca_get_height()- 1;185 int ymax = _caca_height - 1; 186 186 s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); 187 187 s->y1 = ymax; … … 204 204 if(x < 0) 205 205 b |= (1<<0); 206 else if(x >= (int) caca_get_width())206 else if(x >= (int)_caca_width) 207 207 b |= (1<<1); 208 208 209 209 if(y < 0) 210 210 b |= (1<<2); 211 else if(y >= (int) caca_get_height())211 else if(y >= (int)_caca_height) 212 212 b |= (1<<3); 213 213 -
libcaca/trunk/src/sprite.c
r226 r246 166 166 } 167 167 168 int caca_get_sprite_frames( struct caca_sprite *sprite)168 int caca_get_sprite_frames(const struct caca_sprite *sprite) 169 169 { 170 170 if(sprite == NULL) … … 174 174 } 175 175 176 int caca_get_sprite_width( struct caca_sprite *sprite, int f)176 int caca_get_sprite_width(const struct caca_sprite *sprite, int f) 177 177 { 178 178 if(sprite == NULL) … … 185 185 } 186 186 187 int caca_get_sprite_height( struct caca_sprite *sprite, int f)187 int caca_get_sprite_height(const struct caca_sprite *sprite, int f) 188 188 { 189 189 if(sprite == NULL) … … 196 196 } 197 197 198 int caca_get_sprite_dx( struct caca_sprite *sprite, int f)198 int caca_get_sprite_dx(const struct caca_sprite *sprite, int f) 199 199 { 200 200 if(sprite == NULL) … … 207 207 } 208 208 209 int caca_get_sprite_dy( struct caca_sprite *sprite, int f)209 int caca_get_sprite_dy(const struct caca_sprite *sprite, int f) 210 210 { 211 211 if(sprite == NULL) … … 218 218 } 219 219 220 void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f)220 void caca_draw_sprite(int x, int y, const struct caca_sprite *sprite, int f) 221 221 { 222 222 int i, j; -
libcaca/trunk/src/triangle.c
r205 r246 71 71 x3 *= 4; 72 72 73 xmax = caca_get_width()- 1;74 ymax = caca_get_height()- 1;73 xmax = _caca_width - 1; 74 ymax = _caca_height - 1; 75 75 76 76 /* Rasterize our triangle */
Note: See TracChangeset
for help on using the changeset viewer.