- Timestamp:
- Jul 17, 2007, 10:46:18 PM (16 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/cucul.h
r1805 r1809 123 123 int cucul_rotate_180(cucul_canvas_t *); 124 124 int cucul_rotate_left(cucul_canvas_t *); 125 int cucul_rotate_left_wide(cucul_canvas_t *);126 125 int cucul_rotate_right(cucul_canvas_t *); 127 int cucul_rotate_right_wide(cucul_canvas_t *); 126 int cucul_stretch_left(cucul_canvas_t *); 127 int cucul_stretch_right(cucul_canvas_t *); 128 128 /* @} */ 129 129 -
libcaca/trunk/cucul/transform.c
r1808 r1809 223 223 * 224 224 * Apply a 90-degree transformation to a canvas, choosing characters 225 * that look like the rotated version wherever possible. Some characters 226 * will stay unchanged by the process, some others will be replaced by 227 * close equivalents. Fullwidth characters will be lost. The operation is 225 * that look like the rotated version wherever possible. Characters cells 226 * are rotated two-by-two. Some characters will stay unchanged by the 227 * process, some others will be replaced by close equivalents. Fullwidth 228 * characters at odd horizontal coordinates will be lost. The operation is 228 229 * not guaranteed to be reversible at all. 229 230 * 230 * Note that the width and height of the canvas are swapped. 231 * Note that the width of the canvas is divided by two and becomes the 232 * new height. Height is multiplied by two and becomes the new width. It 233 * is illegal to pass a canvas with an odd width to this function. 231 234 * 232 235 * If an error occurs, -1 is returned and \b errno is set accordingly: 233 236 * - \c EBUSY The canvas is in use by a display driver and cannot be rotated. 237 * - \c EINVAL The canvas' width is odd. 234 238 * - \c ENOMEM Not enough memory to allocate the new canvas size. If this 235 239 * happens, the previous canvas handle is still valid. … … 241 245 { 242 246 uint32_t *newchars, *newattrs; 243 unsigned int x, y ;247 unsigned int x, y, subwidth, subheight; 244 248 245 249 if(cv->refcount) 246 250 { 247 251 seterrno(EBUSY); 252 return -1; 253 } 254 255 if(cv->width & 1) 256 { 257 seterrno(EINVAL); 248 258 return -1; 249 259 } … … 263 273 } 264 274 265 for(y = 0; y < cv->height; y++) 266 { 267 for(x = 0; x < cv->width; x++) 268 { 269 uint32_t ch, attr; 270 271 ch = cv->chars[cv->width * y + x]; 272 attr = cv->attrs[cv->width * y + x]; 273 274 /* FIXME: do something about fullwidth characters */ 275 ch = leftchar(ch); 276 277 newchars[cv->height * (cv->width - 1 - x) + y] = ch; 278 newattrs[cv->height * (cv->width - 1 - x) + y] = attr; 275 subwidth = cv->width / 2; 276 subheight = cv->height; 277 278 for(y = 0; y < subheight; y++) 279 { 280 for(x = 0; x < subwidth; x++) 281 { 282 uint32_t pair[2], attr1, attr2; 283 284 pair[0] = cv->chars[(subwidth * y + x) * 2]; 285 attr1 = cv->attrs[(subwidth * y + x) * 2]; 286 pair[1] = cv->chars[(subwidth * y + x) * 2 + 1]; 287 attr2 = cv->attrs[(subwidth * y + x) * 2 + 1]; 288 289 leftpair(pair); 290 291 newchars[(subheight * (subwidth - 1 - x) + y) * 2] = pair[0]; 292 newattrs[(subheight * (subwidth - 1 - x) + y) * 2] = attr1; 293 newchars[(subheight * (subwidth - 1 - x) + y) * 2 + 1] = pair[1]; 294 newattrs[(subheight * (subwidth - 1 - x) + y) * 2 + 1] = attr2; 279 295 } 280 296 } … … 286 302 x = cv->frames[cv->frame].x; 287 303 y = cv->frames[cv->frame].y; 288 cv->frames[cv->frame].x = y ;289 cv->frames[cv->frame].y = cv->width - 1 - x;304 cv->frames[cv->frame].x = y * 2; 305 cv->frames[cv->frame].y = (cv->width - 1 - x) / 2; 290 306 291 307 x = cv->frames[cv->frame].handlex; 292 308 y = cv->frames[cv->frame].handley; 293 cv->frames[cv->frame].handlex = y ;294 cv->frames[cv->frame].handley = cv->width - 1 - x;295 296 cv->frames[cv->frame].width = cv->height ;297 cv->frames[cv->frame].height = cv->width ;309 cv->frames[cv->frame].handlex = y * 2; 310 cv->frames[cv->frame].handley = (cv->width - 1 - x) / 2; 311 312 cv->frames[cv->frame].width = cv->height * 2; 313 cv->frames[cv->frame].height = cv->width / 2; 298 314 299 315 cv->frames[cv->frame].chars = newchars; … … 306 322 } 307 323 308 /** \brief Rotate a canvas, 90 degrees counterclockwise (widechar version).324 /** \brief Rotate a canvas, 90 degrees counterclockwise. 309 325 * 310 326 * Apply a 90-degree transformation to a canvas, choosing characters … … 325 341 * happens, the previous canvas handle is still valid. 326 342 * 327 * \param cv The canvas to rotate left.343 * \param cv The canvas to rotate right. 328 344 * \return 0 in case of success, -1 if an error occurred. 329 345 */ 330 int cucul_rotate_ left_wide(cucul_canvas_t *cv)346 int cucul_rotate_right(cucul_canvas_t *cv) 331 347 { 332 348 uint32_t *newchars, *newattrs; … … 373 389 attr2 = cv->attrs[(subwidth * y + x) * 2 + 1]; 374 390 375 leftpair(pair);376 377 newchars[(subheight * (subwidth - 1 - x) +y) * 2] = pair[0];378 newattrs[(subheight * (subwidth - 1 - x) +y) * 2] = attr1;379 newchars[(subheight * (subwidth - 1 - x) +y) * 2 + 1] = pair[1];380 newattrs[(subheight * (subwidth - 1 - x) +y) * 2 + 1] = attr2;391 rightpair(pair); 392 393 newchars[(subheight * x + subheight - 1 - y) * 2] = pair[0]; 394 newattrs[(subheight * x + subheight - 1 - y) * 2] = attr1; 395 newchars[(subheight * x + subheight - 1 - y) * 2 + 1] = pair[1]; 396 newattrs[(subheight * x + subheight - 1 - y) * 2 + 1] = attr2; 381 397 } 382 398 } … … 388 404 x = cv->frames[cv->frame].x; 389 405 y = cv->frames[cv->frame].y; 390 cv->frames[cv->frame].x = y* 2;391 cv->frames[cv->frame].y = (cv->width - 1 - x)/ 2;406 cv->frames[cv->frame].x = (cv->height - 1 - y) * 2; 407 cv->frames[cv->frame].y = x / 2; 392 408 393 409 x = cv->frames[cv->frame].handlex; 394 410 y = cv->frames[cv->frame].handley; 395 cv->frames[cv->frame].handlex = y* 2;396 cv->frames[cv->frame].handley = (cv->width - 1 - x)/ 2;411 cv->frames[cv->frame].handlex = (cv->height - 1 - y) * 2; 412 cv->frames[cv->frame].handley = x / 2; 397 413 398 414 cv->frames[cv->frame].width = cv->height * 2; … … 408 424 } 409 425 410 /** \brief Rotate a canvas, 90 degrees clockwise. 426 /** \brief Rotate and stretch a canvas, 90 degrees counterclockwise. 427 * 428 * Apply a 90-degree transformation to a canvas, choosing characters 429 * that look like the rotated version wherever possible. Some characters 430 * will stay unchanged by the process, some others will be replaced by 431 * close equivalents. Fullwidth characters will be lost. The operation is 432 * not guaranteed to be reversible at all. 433 * 434 * Note that the width and height of the canvas are swapped, causing its 435 * aspect ratio to look stretched. 436 * 437 * If an error occurs, -1 is returned and \b errno is set accordingly: 438 * - \c EBUSY The canvas is in use by a display driver and cannot be rotated. 439 * - \c ENOMEM Not enough memory to allocate the new canvas size. If this 440 * happens, the previous canvas handle is still valid. 441 * 442 * \param cv The canvas to rotate left. 443 * \return 0 in case of success, -1 if an error occurred. 444 */ 445 int cucul_stretch_left(cucul_canvas_t *cv) 446 { 447 uint32_t *newchars, *newattrs; 448 unsigned int x, y; 449 450 if(cv->refcount) 451 { 452 seterrno(EBUSY); 453 return -1; 454 } 455 456 /* Save the current frame shortcuts */ 457 _cucul_save_frame_info(cv); 458 459 newchars = malloc(cv->width * cv->height * sizeof(uint32_t)); 460 if(!newchars) 461 return -1; 462 463 newattrs = malloc(cv->width * cv->height * sizeof(uint32_t)); 464 if(!newattrs) 465 { 466 free(newchars); 467 return -1; 468 } 469 470 for(y = 0; y < cv->height; y++) 471 { 472 for(x = 0; x < cv->width; x++) 473 { 474 uint32_t ch, attr; 475 476 ch = cv->chars[cv->width * y + x]; 477 attr = cv->attrs[cv->width * y + x]; 478 479 /* FIXME: do something about fullwidth characters */ 480 ch = leftchar(ch); 481 482 newchars[cv->height * (cv->width - 1 - x) + y] = ch; 483 newattrs[cv->height * (cv->width - 1 - x) + y] = attr; 484 } 485 } 486 487 free(cv->chars); 488 free(cv->attrs); 489 490 /* Swap X and Y information */ 491 x = cv->frames[cv->frame].x; 492 y = cv->frames[cv->frame].y; 493 cv->frames[cv->frame].x = y; 494 cv->frames[cv->frame].y = cv->width - 1 - x; 495 496 x = cv->frames[cv->frame].handlex; 497 y = cv->frames[cv->frame].handley; 498 cv->frames[cv->frame].handlex = y; 499 cv->frames[cv->frame].handley = cv->width - 1 - x; 500 501 cv->frames[cv->frame].width = cv->height; 502 cv->frames[cv->frame].height = cv->width; 503 504 cv->frames[cv->frame].chars = newchars; 505 cv->frames[cv->frame].attrs = newattrs; 506 507 /* Reset the current frame shortcuts */ 508 _cucul_load_frame_info(cv); 509 510 return 0; 511 } 512 513 /** \brief Rotate and stretch a canvas, 90 degrees clockwise. 411 514 * 412 515 * Apply a 270-degree transformation to a canvas, choosing characters … … 416 519 * not guaranteed to be reversible at all. 417 520 * 418 * Note that the width and height of the canvas are swapped. 521 * Note that the width and height of the canvas are swapped, causing its 522 * aspect ratio to look stretched. 419 523 * 420 524 * If an error occurs, -1 is returned and \b errno is set accordingly: … … 426 530 * \return 0 in case of success, -1 if an error occurred. 427 531 */ 428 int cucul_ rotate_right(cucul_canvas_t *cv)532 int cucul_stretch_right(cucul_canvas_t *cv) 429 533 { 430 534 uint32_t *newchars, *newattrs; … … 488 592 cv->frames[cv->frame].width = cv->height; 489 593 cv->frames[cv->frame].height = cv->width; 490 491 cv->frames[cv->frame].chars = newchars;492 cv->frames[cv->frame].attrs = newattrs;493 494 /* Reset the current frame shortcuts */495 _cucul_load_frame_info(cv);496 497 return 0;498 }499 500 /** \brief Rotate a canvas, 90 degrees counterclockwise (widechar version).501 *502 * Apply a 90-degree transformation to a canvas, choosing characters503 * that look like the rotated version wherever possible. Characters cells504 * are rotated two-by-two. Some characters will stay unchanged by the505 * process, some others will be replaced by close equivalents. Fullwidth506 * characters at odd horizontal coordinates will be lost. The operation is507 * not guaranteed to be reversible at all.508 *509 * Note that the width of the canvas is divided by two and becomes the510 * new height. Height is multiplied by two and becomes the new width. It511 * is illegal to pass a canvas with an odd width to this function.512 *513 * If an error occurs, -1 is returned and \b errno is set accordingly:514 * - \c EBUSY The canvas is in use by a display driver and cannot be rotated.515 * - \c EINVAL The canvas' width is odd.516 * - \c ENOMEM Not enough memory to allocate the new canvas size. If this517 * happens, the previous canvas handle is still valid.518 *519 * \param cv The canvas to rotate right.520 * \return 0 in case of success, -1 if an error occurred.521 */522 int cucul_rotate_right_wide(cucul_canvas_t *cv)523 {524 uint32_t *newchars, *newattrs;525 unsigned int x, y, subwidth, subheight;526 527 if(cv->refcount)528 {529 seterrno(EBUSY);530 return -1;531 }532 533 if(cv->width & 1)534 {535 seterrno(EINVAL);536 return -1;537 }538 539 /* Save the current frame shortcuts */540 _cucul_save_frame_info(cv);541 542 newchars = malloc(cv->width * cv->height * sizeof(uint32_t));543 if(!newchars)544 return -1;545 546 newattrs = malloc(cv->width * cv->height * sizeof(uint32_t));547 if(!newattrs)548 {549 free(newchars);550 return -1;551 }552 553 subwidth = cv->width / 2;554 subheight = cv->height;555 556 for(y = 0; y < subheight; y++)557 {558 for(x = 0; x < subwidth; x++)559 {560 uint32_t pair[2], attr1, attr2;561 562 pair[0] = cv->chars[(subwidth * y + x) * 2];563 attr1 = cv->attrs[(subwidth * y + x) * 2];564 pair[1] = cv->chars[(subwidth * y + x) * 2 + 1];565 attr2 = cv->attrs[(subwidth * y + x) * 2 + 1];566 567 rightpair(pair);568 569 newchars[(subheight * x + subheight - 1 - y) * 2] = pair[0];570 newattrs[(subheight * x + subheight - 1 - y) * 2] = attr1;571 newchars[(subheight * x + subheight - 1 - y) * 2 + 1] = pair[1];572 newattrs[(subheight * x + subheight - 1 - y) * 2 + 1] = attr2;573 }574 }575 576 free(cv->chars);577 free(cv->attrs);578 579 /* Swap X and Y information */580 x = cv->frames[cv->frame].x;581 y = cv->frames[cv->frame].y;582 cv->frames[cv->frame].x = (cv->height - 1 - y) * 2;583 cv->frames[cv->frame].y = x / 2;584 585 x = cv->frames[cv->frame].handlex;586 y = cv->frames[cv->frame].handley;587 cv->frames[cv->frame].handlex = (cv->height - 1 - y) * 2;588 cv->frames[cv->frame].handley = x / 2;589 590 cv->frames[cv->frame].width = cv->height * 2;591 cv->frames[cv->frame].height = cv->width / 2;592 594 593 595 cv->frames[cv->frame].chars = newchars; -
libcaca/trunk/test/text.c
r1808 r1809 83 83 free(buffer); 84 84 85 cucul_rotate_left _wide(cv);85 cucul_rotate_left(cv); 86 86 buffer = cucul_export_memory(cv, "utf8", &len); 87 87 fwrite(buffer, len, 1, stdout);
Note: See TracChangeset
for help on using the changeset viewer.