Changeset 1816
- Timestamp:
- Sep 29, 2007, 5:15:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/transform.c
r1814 r1816 230 230 * 231 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. I t233 * is illegal to pass a canvas with an odd width to this function.232 * new height. Height is multiplied by two and becomes the new width. If 233 * the original width is an odd number, the division is rounded up. 234 234 * 235 235 * If an error occurs, -1 is returned and \b errno is set accordingly: 236 236 * - \c EBUSY The canvas is in use by a display driver and cannot be rotated. 237 * - \c EINVAL The canvas' width is odd.238 237 * - \c ENOMEM Not enough memory to allocate the new canvas size. If this 239 238 * happens, the previous canvas handle is still valid. … … 245 244 { 246 245 uint32_t *newchars, *newattrs; 247 unsigned int x, y, subwidth, subheight;246 unsigned int x, y, w2, h2; 248 247 249 248 if(cv->refcount) 250 249 { 251 250 seterrno(EBUSY); 252 return -1;253 }254 255 if(cv->width & 1)256 {257 seterrno(EINVAL);258 251 return -1; 259 252 } … … 262 255 _cucul_save_frame_info(cv); 263 256 264 newchars = malloc(cv->width * cv->height * sizeof(uint32_t)); 257 w2 = (cv->width + 1) / 2; 258 h2 = cv->height; 259 260 newchars = malloc(w2 * h2 * 2 * sizeof(uint32_t)); 265 261 if(!newchars) 266 return -1; 267 268 newattrs = malloc(cv->width * cv->height * sizeof(uint32_t)); 262 { 263 seterrno(ENOMEM); 264 return -1; 265 } 266 267 newattrs = malloc(w2 * h2 * 2 * sizeof(uint32_t)); 269 268 if(!newattrs) 270 269 { 271 270 free(newchars); 272 return -1; 273 } 274 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++) 271 seterrno(ENOMEM); 272 return -1; 273 } 274 275 for(y = 0; y < h2; y++) 276 { 277 for(x = 0; x < w2; x++) 281 278 { 282 279 uint32_t pair[2], attr1, attr2; 283 280 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]; 281 pair[0] = cv->chars[cv->width * y + x * 2]; 282 attr1 = cv->attrs[cv->width * y + x * 2]; 283 284 if((cv->width & 1) && x == w2 - 1) 285 { 286 /* Special case: odd column */ 287 pair[1] = ' '; 288 attr2 = attr1; 289 } 290 else 291 { 292 pair[1] = cv->chars[cv->width * y + x * 2 + 1]; 293 attr2 = cv->attrs[cv->width * y + x * 2 + 1]; 294 } 295 288 296 289 297 leftpair(pair); 290 298 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;299 newchars[(h2 * (w2 - 1 - x) + y) * 2] = pair[0]; 300 newattrs[(h2 * (w2 - 1 - x) + y) * 2] = attr1; 301 newchars[(h2 * (w2 - 1 - x) + y) * 2 + 1] = pair[1]; 302 newattrs[(h2 * (w2 - 1 - x) + y) * 2 + 1] = attr2; 295 303 } 296 304 } … … 311 319 312 320 cv->frames[cv->frame].width = cv->height * 2; 313 cv->frames[cv->frame].height = cv->width/ 2;321 cv->frames[cv->frame].height = (cv->width + 1) / 2; 314 322 315 323 cv->frames[cv->frame].chars = newchars; … … 332 340 * 333 341 * Note that the width of the canvas is divided by two and becomes the 334 * new height. Height is multiplied by two and becomes the new width. I t335 * is illegal to pass a canvas with an odd width to this function.342 * new height. Height is multiplied by two and becomes the new width. If 343 * the original width is an odd number, the division is rounded up. 336 344 * 337 345 * If an error occurs, -1 is returned and \b errno is set accordingly: 338 346 * - \c EBUSY The canvas is in use by a display driver and cannot be rotated. 339 * - \c EINVAL The canvas' width is odd.340 347 * - \c ENOMEM Not enough memory to allocate the new canvas size. If this 341 348 * happens, the previous canvas handle is still valid. … … 347 354 { 348 355 uint32_t *newchars, *newattrs; 349 unsigned int x, y, subwidth, subheight;356 unsigned int x, y, w2, h2; 350 357 351 358 if(cv->refcount) 352 359 { 353 360 seterrno(EBUSY); 354 return -1;355 }356 357 if(cv->width & 1)358 {359 seterrno(EINVAL);360 361 return -1; 361 362 } … … 364 365 _cucul_save_frame_info(cv); 365 366 366 newchars = malloc(cv->width * cv->height * sizeof(uint32_t)); 367 w2 = (cv->width + 1) / 2; 368 h2 = cv->height; 369 370 newchars = malloc(w2 * h2 * 2 * sizeof(uint32_t)); 367 371 if(!newchars) 368 return -1; 369 370 newattrs = malloc(cv->width * cv->height * sizeof(uint32_t)); 372 { 373 seterrno(ENOMEM); 374 return -1; 375 } 376 377 newattrs = malloc(w2 * h2 * 2 * sizeof(uint32_t)); 371 378 if(!newattrs) 372 379 { 373 380 free(newchars); 374 return -1; 375 } 376 377 subwidth = cv->width / 2; 378 subheight = cv->height; 379 380 for(y = 0; y < subheight; y++) 381 { 382 for(x = 0; x < subwidth; x++) 381 seterrno(ENOMEM); 382 return -1; 383 } 384 385 for(y = 0; y < h2; y++) 386 { 387 for(x = 0; x < w2; x++) 383 388 { 384 389 uint32_t pair[2], attr1, attr2; 385 390 386 pair[0] = cv->chars[(subwidth * y + x) * 2]; 387 attr1 = cv->attrs[(subwidth * y + x) * 2]; 388 pair[1] = cv->chars[(subwidth * y + x) * 2 + 1]; 389 attr2 = cv->attrs[(subwidth * y + x) * 2 + 1]; 391 pair[0] = cv->chars[cv->width * y + x * 2]; 392 attr1 = cv->attrs[cv->width * y + x * 2]; 393 394 if((cv->width & 1) && x == w2 - 1) 395 { 396 /* Special case: odd column */ 397 pair[1] = ' '; 398 attr2 = attr1; 399 } 400 else 401 { 402 pair[1] = cv->chars[cv->width * y + x * 2 + 1]; 403 attr2 = cv->attrs[cv->width * y + x * 2 + 1]; 404 } 390 405 391 406 rightpair(pair); 392 407 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;408 newchars[(h2 * x + h2 - 1 - y) * 2] = pair[0]; 409 newattrs[(h2 * x + h2 - 1 - y) * 2] = attr1; 410 newchars[(h2 * x + h2 - 1 - y) * 2 + 1] = pair[1]; 411 newattrs[(h2 * x + h2 - 1 - y) * 2 + 1] = attr2; 397 412 } 398 413 } … … 413 428 414 429 cv->frames[cv->frame].width = cv->height * 2; 415 cv->frames[cv->frame].height = cv->width/ 2;430 cv->frames[cv->frame].height = (cv->width + 1) / 2; 416 431 417 432 cv->frames[cv->frame].chars = newchars; … … 459 474 newchars = malloc(cv->width * cv->height * sizeof(uint32_t)); 460 475 if(!newchars) 461 return -1; 476 { 477 seterrno(ENOMEM); 478 return -1; 479 } 462 480 463 481 newattrs = malloc(cv->width * cv->height * sizeof(uint32_t)); … … 465 483 { 466 484 free(newchars); 485 seterrno(ENOMEM); 467 486 return -1; 468 487 } … … 968 987 /* ASCII / Unicode */ 969 988 '-', '-', 0x4e28, CUCUL_MAGIC_FULLWIDTH, /* -- 丨 */ 989 '|', '|', 0x2f06, CUCUL_MAGIC_FULLWIDTH, /* || ⼆ */ 970 990 /* Unicode */ 971 991 0x2584, 0x2580, 0x2580, 0x2584, /* ▄▀ ▀▄ */ … … 988 1008 '\\', ' ', '_', ',', ' ', '\\', 0x00b4, 0x203e, /* \ _, \ ´‾ */ 989 1009 '\\', '_', '_', '/', 0x203e, '\\', '/', 0x203e, /* \_ _/ ‾\ /‾ */ 1010 '_', '\\', 0x203e, '/', '\\', 0x203e, '/', '_', /* _\ ‾/ \‾ /_ */ 990 1011 '|', ' ', '_', '_', ' ', '|', 0x203e, 0x203e, /* | __ | ‾‾ */ 991 1012 '_', '|', 0x203e, '|', '|', 0x203e, '|', '_', /* _| ‾| |‾ |_ */ … … 994 1015 ' ', '_', ' ', 0x2575, 0x203e, ' ', 0x2577, ' ', /* _ ╵ ‾ ╷ */ 995 1016 '.', '_', '.', 0x2575, 0x203e, '\'', 0x2577, '\'', /* ._ .╵ ‾' ╷' */ 1017 '(', '_', 0x203f, '|', 0x203e, ')', '|', 0x2040, /* (_ ‿| ‾) |⁀ */ 1018 '(', 0x203e, '|', 0x203f, '_', ')', 0x2040, '|', /* (‾ |‿ _) ⁀| */ 996 1019 '\\', '/', 0xff1e, CUCUL_MAGIC_FULLWIDTH, 997 1020 '/', '\\', 0xff1c, CUCUL_MAGIC_FULLWIDTH, /* \/ > /\ < */ 1021 ')', ' ', 0xfe35, CUCUL_MAGIC_FULLWIDTH, 1022 ' ', '(', 0xfe36, CUCUL_MAGIC_FULLWIDTH, /* ) ︵ ( ︶ */ 1023 '}', ' ', 0xfe37, CUCUL_MAGIC_FULLWIDTH, 1024 ' ', '{', 0xfe38, CUCUL_MAGIC_FULLWIDTH, /* } ︷ { ︸ */ 998 1025 /* Not perfect, but better than nothing */ 999 1026 '(', ' ', 0x02ce, ',', ' ', ')', 0x00b4, '`', /* ( ˎ, ) ´` */ 1000 ' )', ' ', ',', 0x02ce, ' ', '(', '`', 0x00b4, /* ) ,ˎ ( `´*/1027 ' ', 'v', '>', ' ', 0x028c, ' ', ' ', '<', /* v > ʌ < */ 1001 1028 ' ', 'V', '>', ' ', 0x039b, ' ', ' ', '<', /* V > Λ < */ 1029 'v', ' ', '>', ' ', ' ', 0x028c, ' ', '<', /* v > ʌ < */ 1002 1030 'V', ' ', '>', ' ', ' ', 0x039b, ' ', '<', /* V > Λ < */ 1031 '\\', '|', 0xff1e, CUCUL_MAGIC_FULLWIDTH, 1032 '|', '\\', 0xff1c, CUCUL_MAGIC_FULLWIDTH, /* \| > |\ < */ 1033 '|', '/', 0xff1e, CUCUL_MAGIC_FULLWIDTH, 1034 '/', '|', 0xff1c, CUCUL_MAGIC_FULLWIDTH, /* |/ > /| < */ 1003 1035 /* Unicode */ 1004 1036 0x2584, ' ', ' ', 0x2584, ' ', 0x2580, 0x2580, ' ', /* ▄ ▄ ▀ ▀ */
Note: See TracChangeset
for help on using the changeset viewer.