| 393 | | /***************************************************************************** |
|---|
| 394 | | * BinaryLog: computes the base 2 log of a binary value |
|---|
| 395 | | ***************************************************************************** |
|---|
| 396 | | * This functions is used by MaskToShift, to get a bit index from a binary |
|---|
| 397 | | * value. |
|---|
| 398 | | *****************************************************************************/ |
|---|
| 399 | | static int BinaryLog( uint32_t i ) |
|---|
| 400 | | { |
|---|
| 401 | | int i_log = 0; |
|---|
| 402 | | |
|---|
| 403 | | if( i == 0 ) return -31337; |
|---|
| 404 | | |
|---|
| 405 | | if( i & 0xffff0000 ) i_log += 16; |
|---|
| 406 | | if( i & 0xff00ff00 ) i_log += 8; |
|---|
| 407 | | if( i & 0xf0f0f0f0 ) i_log += 4; |
|---|
| 408 | | if( i & 0xcccccccc ) i_log += 2; |
|---|
| 409 | | if( i & 0xaaaaaaaa ) i_log += 1; |
|---|
| 410 | | |
|---|
| 411 | | return i_log; |
|---|
| 412 | | } |
|---|
| 413 | | |
|---|
| 431 | | } |
|---|
| 432 | | |
|---|
| 433 | | /** |
|---|
| 434 | | * It transforms a color mask into right and left shifts |
|---|
| 435 | | * FIXME copied from video_output.c |
|---|
| 436 | | */ |
|---|
| 437 | | static void MaskToShift( int *pi_left, int *pi_right, uint32_t i_mask ) |
|---|
| 438 | | { |
|---|
| 439 | | uint32_t i_low, i_high; /* lower hand higher bits of the mask */ |
|---|
| 440 | | |
|---|
| 441 | | if( !i_mask ) |
|---|
| 442 | | { |
|---|
| 443 | | *pi_left = *pi_right = 0; |
|---|
| 444 | | return; |
|---|
| 445 | | } |
|---|
| 446 | | |
|---|
| 447 | | /* Get bits */ |
|---|
| 448 | | i_low = i_high = i_mask; |
|---|
| 449 | | |
|---|
| 450 | | i_low &= - (int32_t)i_low; /* lower bit of the mask */ |
|---|
| 451 | | i_high += i_low; /* higher bit of the mask */ |
|---|
| 452 | | |
|---|
| 453 | | /* Transform bits into an index. Also deal with i_high overflow, which |
|---|
| 454 | | * is faster than changing the BinaryLog code to handle 64 bit integers. */ |
|---|
| 455 | | i_low = BinaryLog (i_low); |
|---|
| 456 | | i_high = i_high ? BinaryLog (i_high) : 32; |
|---|
| 457 | | |
|---|
| 458 | | /* Update pointers and return */ |
|---|
| 459 | | *pi_left = i_low; |
|---|
| 460 | | *pi_right = (8 - i_high + i_low); |
|---|
| 461 | | } |
|---|
| 462 | | |
|---|
| 463 | | /* FIXME should be moved to src/ */ |
|---|
| 464 | | static void video_format_FixRgb( video_format_t *p_fmt ) |
|---|
| 465 | | { |
|---|
| 466 | | if( p_fmt->i_chroma != FCC_RV15 && |
|---|
| 467 | | p_fmt->i_chroma != FCC_RV16 && |
|---|
| 468 | | p_fmt->i_chroma != FCC_RV24 && |
|---|
| 469 | | p_fmt->i_chroma != FCC_RV32 ) |
|---|
| 470 | | return; |
|---|
| 471 | | |
|---|
| 472 | | /* FIXME find right default mask */ |
|---|
| 473 | | if( !p_fmt->i_rmask || !p_fmt->i_gmask || !p_fmt->i_bmask ) |
|---|
| 474 | | { |
|---|
| 475 | | switch( p_fmt->i_chroma ) |
|---|
| 476 | | { |
|---|
| 477 | | case FCC_RV15: |
|---|
| 478 | | p_fmt->i_rmask = 0x7c00; |
|---|
| 479 | | p_fmt->i_gmask = 0x03e0; |
|---|
| 480 | | p_fmt->i_bmask = 0x001f; |
|---|
| 481 | | break; |
|---|
| 482 | | |
|---|
| 483 | | case FCC_RV16: |
|---|
| 484 | | p_fmt->i_rmask = 0xf800; |
|---|
| 485 | | p_fmt->i_gmask = 0x07e0; |
|---|
| 486 | | p_fmt->i_bmask = 0x001f; |
|---|
| 487 | | break; |
|---|
| 488 | | |
|---|
| 489 | | case FCC_RV24: |
|---|
| 490 | | p_fmt->i_rmask = 0xff0000; |
|---|
| 491 | | p_fmt->i_gmask = 0x00ff00; |
|---|
| 492 | | p_fmt->i_bmask = 0x0000ff; |
|---|
| 493 | | break; |
|---|
| 494 | | case FCC_RV32: |
|---|
| 495 | | p_fmt->i_rmask = 0x00ff0000; |
|---|
| 496 | | p_fmt->i_gmask = 0x0000ff00; |
|---|
| 497 | | p_fmt->i_bmask = 0x000000ff; |
|---|
| 498 | | break; |
|---|
| 499 | | |
|---|
| 500 | | default: |
|---|
| 501 | | assert(0); |
|---|
| 502 | | break; |
|---|
| 503 | | } |
|---|
| 504 | | } |
|---|
| 505 | | |
|---|
| 506 | | MaskToShift( &p_fmt->i_lrshift, &p_fmt->i_rrshift, |
|---|
| 507 | | p_fmt->i_rmask ); |
|---|
| 508 | | MaskToShift( &p_fmt->i_lgshift, &p_fmt->i_rgshift, |
|---|
| 509 | | p_fmt->i_gmask ); |
|---|
| 510 | | MaskToShift( &p_fmt->i_lbshift, &p_fmt->i_rbshift, |
|---|
| 511 | | p_fmt->i_bmask ); |
|---|