| 697 | } |
| 698 | |
| 699 | Color Image::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const |
| 700 | { |
| 701 | #if NAZARA_UTILITY_SAFE |
| 702 | if (m_sharedImage == &emptyImage) |
| 703 | { |
| 704 | NazaraError("Image must be valid"); |
| 705 | return Color(); |
| 706 | } |
| 707 | |
| 708 | if (PixelFormat::IsCompressed(m_sharedImage->format)) |
| 709 | { |
| 710 | NazaraError("Cannot access pixels from compressed image"); |
| 711 | return Color(); |
| 712 | } |
| 713 | |
| 714 | if (x >= m_sharedImage->width) |
| 715 | { |
| 716 | NazaraError("X value exceeds width (" + String::Number(x) + " >= " + String::Number(m_sharedImage->width) + ')'); |
| 717 | return Color(); |
| 718 | } |
| 719 | |
| 720 | if (y >= m_sharedImage->height) |
| 721 | { |
| 722 | NazaraError("Y value exceeds height (" + String::Number(y) + " >= " + String::Number(m_sharedImage->height) + ')'); |
| 723 | return Color(); |
| 724 | } |
| 725 | |
| 726 | unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth; |
| 727 | if (z >= depth) |
| 728 | { |
| 729 | NazaraError("Z value exceeds depth (" + String::Number(z) + " >= " + String::Number(depth) + ')'); |
| 730 | return Color(); |
| 731 | } |
| 732 | #endif |
| 733 | |
| 734 | const UInt8* pixel = GetPixelPtr(m_sharedImage->levels[0].get(), PixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); |
| 735 | |
| 736 | Color color; |
| 737 | if (!PixelFormat::Convert(m_sharedImage->format, PixelFormatType_RGBA8, pixel, &color.r)) |
| 738 | NazaraError("Failed to convert image's format to RGBA8"); |
| 739 | |
| 740 | return color; |
| 741 | } |
| 742 | |
| 743 | UInt8* Image::GetPixels(unsigned int x, unsigned int y, unsigned int z, UInt8 level) |
| 744 | { |
no test coverage detected