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

Method PopulateMargin

trinity/Tr2HostBitmap.cpp:387–443  ·  view source on GitHub ↗

-------------------------------------------------- Description: Take the pixels in the sub-block (margin, margin)...(width-margin,height-margin) and copy their values into the border pixels to get a clamping effect. --------------------------------------------------

Source from the content-addressed store, hash-verified

385/// values into the border pixels to get a clamping effect.
386/// --------------------------------------------------
387bool Tr2HostBitmap::PopulateMargin( unsigned margin )
388{
389 if( !IsValid() || IsCompressed() || m_mipCount != 1 || 2 * margin >= GetWidth() || 2 * margin >= GetHeight() )
390 {
391 return false;
392 }
393
394 const unsigned bytesPerPixel = GetBytesPerPixel( GetFormat() );
395 const unsigned bytesPerMargin = bytesPerPixel * margin;
396
397
398 const unsigned width = GetWidth() - 2 * margin;
399 const unsigned height = GetHeight() - 2 * margin;
400
401 //top margin
402 const char* src = GetRawData( margin, margin );
403 for( unsigned i = 0; i != margin; ++i )
404 {
405 char* dst = GetRawData( margin, i );
406 memcpy( dst, src, bytesPerPixel * width );
407 }
408
409 //bottom margin
410 src = GetRawData( margin, height + margin - 1 );
411 for( unsigned i = 0; i != margin; ++i )
412 {
413 char* dst = GetRawData( margin, height + margin + i );
414 memcpy( dst, src, bytesPerPixel * width );
415 }
416
417 for( unsigned y = 0; y != height; ++y )
418 {
419 //left margin
420 src = GetRawData( margin, y + margin );
421 char* dst = GetRawData( 0, y + margin );
422 for( unsigned i = 0; i != margin; ++i )
423 {
424 for( unsigned j = 0; j != bytesPerPixel; ++j )
425 {
426 dst[i * bytesPerPixel + j] = src[j];
427 }
428 }
429
430 //right margin
431 src += ( width - 1 ) * bytesPerPixel;
432 dst += width * bytesPerPixel + bytesPerMargin;
433 for( unsigned i = 0; i != margin; ++i )
434 {
435 for( unsigned j = 0; j != bytesPerPixel; ++j )
436 {
437 dst[i * bytesPerPixel + j] = src[j];
438 }
439 }
440 }
441
442 return true;
443}
444

Callers

nothing calls this directly

Calls 1

IsValidFunction · 0.70

Tested by

no test coverage detected