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

Function PyBgraToRgb

trinity/Tr2HostBitmap_Blue.cpp:402–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400}
401
402static PyObject* PyBgraToRgb( PyObject*, PyObject* args )
403{
404 Py_buffer buffer;
405 if( !PyArg_ParseTuple( args, "s*", &buffer ) )
406 {
407 return nullptr;
408 }
409 ON_BLOCK_EXIT( [&] { PyBuffer_Release( &buffer ); } );
410
411 auto count = buffer.len / 4;
412 if( count < 1 )
413 {
414 PyErr_SetString( PyExc_ValueError, "Buffer is too short" );
415 return nullptr;
416 }
417
418 std::unique_ptr<uint8_t[]> output( new uint8_t[count * 3] );
419 auto src = static_cast<const uint8_t*>( buffer.buf );
420 auto dst = output.get();
421 for( Py_ssize_t i = 0; i < count; ++i )
422 {
423 dst[0] = src[2];
424 dst[1] = src[1];
425 dst[2] = src[0];
426 dst += 3;
427 src += 4;
428 }
429 return PyVerCompat::ToPyBytes( reinterpret_cast<const char*>( output.get() ), count * 3 );
430}
431
432#endif
433

Callers

nothing calls this directly

Calls 2

ToPyBytesFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected