| 90 | } |
| 91 | |
| 92 | Color Tr2ImageRes::GetPixelColor( int x, int y ) const |
| 93 | { |
| 94 | if( !m_bitmap.IsValid() ) |
| 95 | { |
| 96 | return Color( 0.0f, 0.0f, 0.0f, 0.0f ); |
| 97 | } |
| 98 | |
| 99 | // TODO: Support different formats |
| 100 | Tr2RenderContextEnum::PixelFormat format = m_bitmap.GetFormat(); |
| 101 | if( format != Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8A8_UNORM && |
| 102 | format != Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8X8_UNORM ) |
| 103 | { |
| 104 | CCP_LOGERR( "Tr2ImageRes::GetPixelColor currently only supports PIXEL_FORMAT_B8G8R8A8_UNORM or PIXEL_FORMAT_B8G8R8X8_UNORM" ); |
| 105 | return Color( 0.0f, 0.0f, 0.0f, 0.0f ); |
| 106 | } |
| 107 | |
| 108 | if( !m_bitmap.GetRawData() ) |
| 109 | { |
| 110 | if( format == Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8A8_UNORM ) |
| 111 | { |
| 112 | return Color( 0.0f, 0.0f, 0.0f, 0.0f ); |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | return Color( 0.0f, 0.0f, 0.0f, 1.0f ); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if( ( x < 0 ) || ( y < 0 ) || ( x >= int( m_bitmap.GetWidth() ) ) || ( y >= int( m_bitmap.GetHeight() ) ) ) |
| 121 | { |
| 122 | return Color( 0.0f, 0.0f, 0.0f, 0.0f ); |
| 123 | } |
| 124 | |
| 125 | const unsigned char* p = reinterpret_cast<const unsigned char*>( m_bitmap.GetRawData() ); |
| 126 | |
| 127 | const int bytesPerPixel = 4; // only works for PIXEL_FORMAT_B8G8R8A8_UNORM, etc. |
| 128 | p += y * m_bitmap.GetWidth() * bytesPerPixel + x * bytesPerPixel; |
| 129 | |
| 130 | Color color( *reinterpret_cast<const uint32_t*>( p ) ); |
| 131 | if( format == Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8X8_UNORM ) |
| 132 | { |
| 133 | color.a = 1.0f; |
| 134 | } |
| 135 | return color; |
| 136 | } |
| 137 | |
| 138 | const ImageIO::HostBitmap& Tr2ImageRes::GetBitmap() const |
| 139 | { |