Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
33 user(s) are online (26 user(s) are browsing Forums)

Members: 1
Guests: 32

Hypex, more...

Support us!

Headlines

 
  Register To Post  

Patterns
Just can't stay away
Just can't stay away


See User information
What is the fastest or most convenient way to turn a bitwise 01-pattern into an alpha map or colored bitmap?

(sorry for all the lame questions)

Go to top
Re: Patterns
Home away from home
Home away from home


See User information
Quote:

alfkil wrote:
What is the fastest or most convenient way to turn a bitwise 01-pattern into an alpha map or colored bitmap?

(sorry for all the lame questions)


Process it 4 pixels at a time using a 4-bit Look-Up-Table (LUT).

Something like:

uint32 lut[16] = {
        
0x00000000,
        
0x000000FF,
        
0x0000FF00,
        
0x0000FFFF,
        
0x00FF0000,
        
0x00FF00FF,
        
0x00FFFF00,
        
0x00FFFFFF,
        
0xFF000000,
        
0xFF0000FF,
        
0xFF00FF00,
        
0xFF00FFFF,
        
0xFFFF0000,
        
0xFFFF00FF,
        
0xFFFFFF00,
        
0xFFFFFFFF,
    };

uint8src srcBase;
uint32destRow destBase;

for(
0height; ++y)
{
    
uint32dest destRow;

    for(
0width/8; ++x)
    {
        
dest[0] = lut[(*src >> 4)];
        
dest[1] = lut[*src 0xF];

        
dest += 2;
        ++
src;
    }
    
destRow += destDWORDSPerRow;
}


NOTES:
- I made up this code just now, and it has NOT been tested
- I cannot remember in what order the pixels are within each byte of a bitplane; the code above may have to be modified to reverse the order if I got it wrong
- Likewise, this code is byte endian-dependent, and so you'd have to adjust the code again if you moved to a little-endian processor.

Hans


Edited by Hans on 2012/3/26 5:45:33
Edited by Hans on 2012/3/26 5:49:39
Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: Patterns
Home away from home
Home away from home


See User information
@alfkil
Definitely NOT "the fastest", but maybe "most convenient": I would considering using writePixelArray8() for easily writing bitmaps of <=256 colours & p96WritePixelArray() for bitmaps >256 colours (which can have an alpha map). These require that you have a char or long array, with each array item being the value for one pixel.

If your bitwise 01 pattern is an actual 1-bitplane mask, then you can use readPixelArray8() to quickly convert it into an array.

writePixelArray8() is a bit more hassle to use than p96WritePixelArray(), as it requires array width being rounded up, as well as a temporary rasterport bitmap.


I haven't yet got into direct manipulation of bitmaps like Hans seems to be suggesting! No doubt very fast, but probably rather convoluted if you have to handle arbitrary bitmaps.

Author of the PortablE programming language.
Go to top
Re: Patterns
Just can't stay away
Just can't stay away


See User information
@Hans

Looks neat, but how do I get a pointer to the pixel data from a 32-bit BitMap?? I guess I can use p96WritePixelArray to write to the bitmap after converting.

@Chris
My data is just a raw 1 bitplane mask with no BitMap struct or RastPort, so to use ReadPixelArray I need to set up those first. I guess initializing the BitMap structure is possible by making planes[0] point to my data, or??

Go to top
Re: Patterns
Home away from home
Home away from home


See User information
Quote:
My data is just a raw 1 bitplane mask with no BitMap struct or RastPort, so to use ReadPixelArray I need to set up those first. I guess initializing the BitMap structure is possible by making planes[0] point to my data, or??

yeah, planes[0] should point to your data. So you would have SOMETHING like this (untested copied+pasted+modified code):

Quote:
/*some casting or correct typing of variables will be needed for compilation, and my C is a bit rusty (I'm really thinking in E and then converting to C), and yes I didn't bother with OS4 interface stuff */

struct bitmap maskBitmap;
InitBitMap(maskBitmap, 1, width, height);
maskBitmap.planes[0] = AllocRaster(GetBitMapAttr(maskBitmap, BMA_WIDTH), GetBitMapAttr(maskBitmap, BMA_HEIGHT));
/*alternatively:
maskBitmap.planes[0] = malloc(maskBitmap.bytesperrow * maskBitmap.rows);
*/
struct rastport maskRastport;
InitRastPort(maskRastport);
maskRastport.bitmap = maskBitmap;

By using InitBitMap(), we avoid the need to manually work out bytesperrow & any necessary rounding/padding. Your planes[0] data MUST be written using those values.

Quote:
Looks neat, but how do I get a pointer to the pixel data from a 32-bit BitMap?? I guess I can use p96WritePixelArray to write to the bitmap after converting.

You COULD just use p96ReadPixelArray() to read your pixel data from a 32-bit bitmap into a long array, then add the alpha channel, before finally writing it back to the same (or different) bitmap using p96WritePixelArray.

If you have used readPixelArray8() to convert your mask data into a char array, then it is pretty easy to add the alpha channel to your long array of pixel data.


Edited by ChrisH on 2012/3/26 23:29:22
Author of the PortablE programming language.
Go to top
Re: Patterns
Home away from home
Home away from home


See User information
Quote:

alfkil wrote:
@Hans

Looks neat, but how do I get a pointer to the pixel data from a 32-bit BitMap?? I guess I can use p96WritePixelArray to write to the bitmap after converting.


Use p96LockBitMap() to get the pointer, and the bytes-per-row. However, if the bitmap is stored in VRAM, then it will probably be faster to convert it to a temporary buffer, and use p96WritePixelArray(). This will be particularly true when p96WritePixelArray() is DMA accelerated (currently only on the Sam 440 and 460 machines).

Hans

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: Patterns
Just can't stay away
Just can't stay away


See User information
@Hans

Ok, I think I am gonna go with the temporary buffer .

Go to top
Re: Patterns
Quite a regular
Quite a regular


See User information
This DMA accelerated temporary buffer thingy sounds like it could speed up AmiVNC a lot, because scanning the screen is what is by far the slowest thing right now.

Software developer for Amiga OS3 and OS4.
Develops for OnyxSoft and the Amiga using E and C and occasionally C++
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project