Morning Zbynek,
1) Is there some clever way to multiply alpha value in all pixels with constant (in other words, to apply constant opacity to bitmap, which already has some transparency)? Other than doing it "manually" through ScanLine() method?
These member functions are your friends:
void Bitmap::SetAlpha( uint8 newAlpha );
void Bitmap::SetAlpha( const Rect& rect, uint8 newAlpha );You can operate either on the whole bitmap or on a rectangular region. Unfortunately, arbitrary region selection is still not implemented for bitmaps in the PCL (although this can be implemented easily; let me know if you're interested).
These member functions also may be of your interest:
void Bitmap::ReplaceColor( RGBA replaceThis, RGBA replaceWith )
void Bitmap::ReplaceColor( const Rect& rect, RGBA replaceThis, RGBA replaceWith );They allow you to replace a specific color selectively.
In addition, the full sets of color assignment and bitwise logical operators are also available for the Bitmap class: Copy, Fill, Or, And, Xor, Invert; in several forms that allow you to operate between bitmaps and between bitmaps and constant pixel values. For more information, see the
pcl/Bitmap.h standard header or the
Bitmap class in PCL documentation.
All of these routines have been implemented as fast direct pixel manipulations. They don't use BeginPaint()...EndPaint(), Graphics, etc.
2) Is the length of one bitmap line equal to bitmap width? Can I safely use "RGBA* line = bmp.ScanLine(0); line[y*bmp.Width()+x] = value;"?
Yes. Bitmap is a device-independent image in PixInsight/PCL. You can assume that all pixels in a Bitmap are stored as a contiguous data block. Each pixel is a 32-bit unsigned integer in the AARRGGBB format.
3) Is it safe to modify bitmap pixels via ScanLine between calls to Graphics::BeginPaint() and EndPaint() on the same bitmap? I'm not asking about parallel processing here.
Yes, you can do that. You can also call fast direct pixel manipulation routines such as Fill(), Or(), And(), Invert(), etc.
4) Related to Thread class. If I create new thread using new operator, does it indeed create new thread in the OS? Or does it take thread from some threadpool? In other words, it there a thread creation overhead?
Thread creation overhead is negligible. A thread is not effectively created as such until you call Thread::Start(). On FreeBSD, Linux and Mac OS X, PI uses the standard pthread library. Each call to Thread::Start() will translate into a call to
pthread_create(). On Windows, the Win32 API is used directly so Thread::Start() translates into ::CreateThread().
Before calling Thread::Start() a Thread object is just a managed pcl::UIObject in your module whose server-side counterpart is a very small structure 'waiting' to be 'fired'.
Let me know if you need further info and happy module creation