TODO including a scaling algorithm in this formula, or give more resolution to the dither
| 571 | |
| 572 | // TODO including a scaling algorithm in this formula, or give more resolution to the dither |
| 573 | QBitmap |
| 574 | DitherPatternInfo::get_bitmap (int width, int height, int frame_width) const |
| 575 | { |
| 576 | if (height < 0) { |
| 577 | height = 36; |
| 578 | } |
| 579 | if (width < 0) { |
| 580 | width = 34; |
| 581 | } |
| 582 | unsigned int fw = frame_width < 0 ? 1 : frame_width; |
| 583 | |
| 584 | const uint32_t * const *p = pattern (); |
| 585 | unsigned int stride = (width + 7) / 8; |
| 586 | |
| 587 | unsigned char *data = new unsigned char[stride * height]; |
| 588 | memset (data, 0x00, size_t (stride * height)); |
| 589 | |
| 590 | for (unsigned int i = 0; i < (unsigned int) height; ++i) { |
| 591 | uint32_t w = 0xffffffff; |
| 592 | if (i >= fw && i < (unsigned int) height - fw) { |
| 593 | w = *(p [(height - 1 - i) % m_height]); |
| 594 | } |
| 595 | for (unsigned int j = 0; j < (unsigned int) width; ++j) { |
| 596 | if (j < fw || j >= (unsigned int) width - fw || (w & (1 << (j % m_width))) != 0) { |
| 597 | data [stride * i + j / 8] |= (1 << (j % 8)); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | QBitmap bitmap (QBitmap::fromData (QSize (width, height), data, QImage::Format_MonoLSB)); |
| 603 | delete[] data; |
| 604 | |
| 605 | return bitmap; |
| 606 | } |
| 607 | |
| 608 | #endif |
| 609 |