| 601 | } |
| 602 | |
| 603 | bool image_resample(const image &src, image &dst, bool srgb, |
| 604 | const char *pFilter, float filter_scale, |
| 605 | bool wrapping, |
| 606 | uint32_t first_comp, uint32_t num_comps) |
| 607 | { |
| 608 | assert((first_comp + num_comps) <= 4); |
| 609 | |
| 610 | const int cMaxComps = 4; |
| 611 | |
| 612 | const uint32_t src_w = src.get_width(), src_h = src.get_height(); |
| 613 | const uint32_t dst_w = dst.get_width(), dst_h = dst.get_height(); |
| 614 | |
| 615 | if (maximum(src_w, src_h) > BASISU_RESAMPLER_MAX_DIMENSION) |
| 616 | { |
| 617 | printf("Image is too large!\n"); |
| 618 | return false; |
| 619 | } |
| 620 | |
| 621 | if (!src_w || !src_h || !dst_w || !dst_h) |
| 622 | return false; |
| 623 | |
| 624 | if ((num_comps < 1) || (num_comps > cMaxComps)) |
| 625 | return false; |
| 626 | |
| 627 | if ((minimum(dst_w, dst_h) < 1) || (maximum(dst_w, dst_h) > BASISU_RESAMPLER_MAX_DIMENSION)) |
| 628 | { |
| 629 | printf("Image is too large!\n"); |
| 630 | return false; |
| 631 | } |
| 632 | |
| 633 | if ((src_w == dst_w) && (src_h == dst_h)) |
| 634 | { |
| 635 | dst = src; |
| 636 | return true; |
| 637 | } |
| 638 | |
| 639 | float srgb_to_linear_table[256]; |
| 640 | if (srgb) |
| 641 | { |
| 642 | for (int i = 0; i < 256; ++i) |
| 643 | srgb_to_linear_table[i] = srgb_to_linear((float)i * (1.0f/255.0f)); |
| 644 | } |
| 645 | |
| 646 | const int LINEAR_TO_SRGB_TABLE_SIZE = 8192; |
| 647 | uint8_t linear_to_srgb_table[LINEAR_TO_SRGB_TABLE_SIZE]; |
| 648 | |
| 649 | if (srgb) |
| 650 | { |
| 651 | for (int i = 0; i < LINEAR_TO_SRGB_TABLE_SIZE; ++i) |
| 652 | linear_to_srgb_table[i] = (uint8_t)clamp<int>((int)(255.0f * linear_to_srgb((float)i * (1.0f / (LINEAR_TO_SRGB_TABLE_SIZE - 1))) + .5f), 0, 255); |
| 653 | } |
| 654 | |
| 655 | std::vector<float> samples[cMaxComps]; |
| 656 | Resampler *resamplers[cMaxComps]; |
| 657 | |
| 658 | resamplers[0] = new Resampler(src_w, src_h, dst_w, dst_h, |
| 659 | wrapping ? Resampler::BOUNDARY_WRAP : Resampler::BOUNDARY_CLAMP, 0.0f, 1.0f, |
| 660 | pFilter, nullptr, nullptr, filter_scale, filter_scale, 0, 0); |
no test coverage detected