Re: Pack bitmap bytes into native-endian 32bit int
- From: luser- -droog <mijoryx@xxxxxxxxx>
- Date: Fri, 14 Jan 2011 09:29:15 -0800 (PST)
On Jan 14, 11:02 am, Nobody <nob...@xxxxxxxxxxx> wrote:
On Tue, 11 Jan 2011 19:21:54 -0800, luser- -droog wrote:
This should be:
for (k = 0; k < 4; k++) {
Otherwise, you're iterating over the columns twice.
I tried that, but my sample data only has three bytes per row.
So? However much data you have, there are always 4 8-bit bytes in a
32-bit word.
Yebbut...
As I said before:
But you also need to allow for:
1. any padding at the end of each row (i.e. if w < stride*4)....
For 1, either:
a) use e.g. "if (j*4+k < stride)" around the code which reads the bytes,
or
b) iterate over the bytes rather than the words, then push an extra 0-3
zero bytes into the final word at the end of each row.
Either way, you need to "create" 0-3 extra zero bytes at the end of each
row. If you iterate over the words, the innermost level needs a check to
use the created zeros rather than trying to read non-existent source
bytes. If you iterate over the bytes, you need to "complete" the last word
after the loop.
I think I've got that covered.
I zero the word first and then mask and shift the
bytes into it. The padding is alredy there when I
copy the word into word-packed mask.
uint32_t u;
...
for (j = 0; j < stride/4; j++) {
u = 0;
/* each 8bit byte in 32bit int */
for (k = 0; k < w/8; k++) {
uint8_t b;
if (endian == big) b = samp[i*(w/8) + k];
else b = samp[(i+1)*(w/8) - (k+1)];
u <<= 8;
if (endian == big) u |= b;
else u |= invertbits(b);
//printf("%X\n", u);
}
//printf("%08X\n", u);
*((uint32_t *)(data + i*stride + j*4)) = u;
}
}
.
- Follow-Ups:
- Re: Pack bitmap bytes into native-endian 32bit int
- From: Nobody
- Re: Pack bitmap bytes into native-endian 32bit int
- From: luser- -droog
- Re: Pack bitmap bytes into native-endian 32bit int
- References:
- Pack bitmap bytes into native-endian 32bit int
- From: luser- -droog
- Re: Pack bitmap bytes into native-endian 32bit int
- From: Nobody
- Re: Pack bitmap bytes into native-endian 32bit int
- From: luser- -droog
- Re: Pack bitmap bytes into native-endian 32bit int
- From: Nobody
- Pack bitmap bytes into native-endian 32bit int
- Prev by Date: Re: Pack bitmap bytes into native-endian 32bit int
- Next by Date: Re: Pack bitmap bytes into native-endian 32bit int
- Previous by thread: Re: Pack bitmap bytes into native-endian 32bit int
- Next by thread: Re: Pack bitmap bytes into native-endian 32bit int
- Index(es):
Relevant Pages
|