MCPcopy Create free account
hub / github.com/carbonengine/trinity / GetThumbnail

Method GetThumbnail

trinity/Resources/Tr2LightProfileRes.cpp:249–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249BlueStdResult Tr2LightProfileRes::GetThumbnail( uint32_t width, uint32_t height, Tr2HostBitmapPtr& bitmap ) const
250{
251 bitmap = nullptr;
252
253 IBlueStreamPtr stream;
254 auto success = BePaths->GetFileContentsWithYield( m_path.c_str(), &stream );
255 if( !BeIsSuccess( success ) )
256 {
257 return BlueStdResult( BLUE_STD_RESULT_IO_ERROR, success.value.c_str() );
258 }
259
260 ImageIO::HostBitmap lightmap;
261
262 if( IsIesExtension( m_path.c_str() ) )
263 {
264 std::string contents;
265 contents.resize( stream->GetSize() );
266 stream->Read( contents.data(), contents.size() );
267
268 if( !ParseIes( contents, lightmap ) )
269 {
270 return BlueStdResult( BLUE_STD_RESULT_RUNTIME_ERROR, "Failed to parse IES file" );
271 }
272 }
273 else
274 {
275 auto result = ImageIO::ReadImage( *stream, ImageIO::LoadParameters( m_path.c_str() ), lightmap );
276 if( !result )
277 {
278 return BlueStdResult( BLUE_STD_RESULT_IO_ERROR, result.GetErrorMessage().c_str() );
279 }
280 if( !IsCompatibleBitmap( lightmap ) )
281 {
282 return BlueStdResult( BLUE_STD_RESULT_VALUE_ERROR, "The input texture has incompatible dimensions/format" );
283 }
284 }
285
286 bitmap.CreateInstance();
287 bitmap->Create( width, height, 1, Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8X8_UNORM );
288 if( !bitmap )
289 {
290 bitmap = nullptr;
291 return BlueStdResult( BLUE_STD_RESULT_MEMORY_ERROR, "Ran out of memory when creating the thumbnail bitmap" );
292 }
293
294 auto PlaneRay = []( const Plane& plane, const Vector3& origin, const Vector3& direction ) {
295 float t = -( plane.d + origin.x * plane.a + origin.y * plane.b + origin.z * plane.c ) / ( direction.x * plane.a + direction.y * plane.b + direction.z * plane.c );
296 return std::make_pair( t, origin + direction * t );
297 };
298
299
300 float aspectRatio = float( width ) / float( height );
301
302 Matrix rotation = RotationMatrix( Vector3( 1, 0, 0 ), 0.3f );
303
304 Vector3 light = Vector3( 0, 0.7f, 0.98f );
305
306 for( uint32_t j = 0; j < height; ++j )

Callers

nothing calls this directly

Calls 10

BeIsSuccessFunction · 0.85
IsIesExtensionFunction · 0.85
IsCompatibleBitmapFunction · 0.85
sizeMethod · 0.80
CreateInstanceMethod · 0.80
Vector3Class · 0.50
GetSizeMethod · 0.45
ReadMethod · 0.45
CreateMethod · 0.45
GetWidthMethod · 0.45

Tested by

no test coverage detected