| 595 | } |
| 596 | |
| 597 | bool CGraphics_Threaded::CheckImageDivisibility(const char *pContextName, CImageInfo &Image, int DivX, int DivY, bool AllowResize) |
| 598 | { |
| 599 | dbg_assert(DivX != 0 && DivY != 0, "Passing 0 to this function is not allowed."); |
| 600 | bool ImageIsValid = true; |
| 601 | bool WidthBroken = Image.m_Width == 0 || (Image.m_Width % DivX) != 0; |
| 602 | bool HeightBroken = Image.m_Height == 0 || (Image.m_Height % DivY) != 0; |
| 603 | if(WidthBroken || HeightBroken) |
| 604 | { |
| 605 | SWarning NewWarning; |
| 606 | char aContextNameQuoted[128]; |
| 607 | str_format(aContextNameQuoted, sizeof(aContextNameQuoted), "\"%s\"", pContextName); |
| 608 | str_format(NewWarning.m_aWarningMsg, sizeof(NewWarning.m_aWarningMsg), |
| 609 | Localize("The width of texture %s is not divisible by %d, or the height is not divisible by %d, which might cause visual bugs."), aContextNameQuoted, DivX, DivY); |
| 610 | AddWarning(NewWarning); |
| 611 | ImageIsValid = false; |
| 612 | } |
| 613 | |
| 614 | if(AllowResize && !ImageIsValid && Image.m_Width > 0 && Image.m_Height > 0) |
| 615 | { |
| 616 | int NewWidth = DivX; |
| 617 | int NewHeight = DivY; |
| 618 | if(WidthBroken) |
| 619 | { |
| 620 | NewWidth = maximum<int>(HighestBit(Image.m_Width), DivX); |
| 621 | NewHeight = (NewWidth / DivX) * DivY; |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | NewHeight = maximum<int>(HighestBit(Image.m_Height), DivY); |
| 626 | NewWidth = (NewHeight / DivY) * DivX; |
| 627 | } |
| 628 | ResizeImage(Image, NewWidth, NewHeight); |
| 629 | ImageIsValid = true; |
| 630 | } |
| 631 | |
| 632 | return ImageIsValid; |
| 633 | } |
| 634 | |
| 635 | bool CGraphics_Threaded::IsImageFormatRgba(const char *pContextName, const CImageInfo &Image) |
| 636 | { |
no test coverage detected