Bert Freudenberg bert at freudenbergs.de
Thu Dec 6 13:38:18 UTC 2007

```On Dec 6, 2007, at 14:24 , johnps11 at bigpond.com wrote:

>> On Dec 1, 2007, at 20:34 , Pete wrote:
>>
>>> It's also not clear to me why this array is
>>> size of 120, when we have an rectangular region of
>>> 40x40, and what is the difference of depth 1,2,4 ...
>>
>>
>> Depth is the number of bits per pixel. Depth 2 means 2 bits per
>> pixel, hence 4 colors.
>>
>> The array stores 32 bits per element. So at depth 2 you get 16 pixels
>> per element. You need 3 elements per row for 40 pixels. 40 rows times
>> 3 words per row is 120. Mystery solved.
>>
>> FYI, pixels are stored big-endian by default.
>>
>> And I'm pretty sure Form even has a class comment, as should Bitmap.
>>
>> - Bert -
>
> I have to admit that Bert's explanation has me none the wiser - the
> leap
> from 2 16 bit words per element (16 pixels) meaning that 3 elements
> (96
> bits, 48 pixels) equals 40 pixels, which is 3 words per row seems a
> little
> unclear (as 48 != 40 in most sane algebras).

I wrote "32 bits per element". The array stores 32 bit numbers
(a.k.a. words). For 40 pixels at 2 bits each you need a row of at
least 80 bits. That means you need three 32 bit numbers giving you 96
bits per row of which 16 are unused. This wastes up to 31 bits per
row, but letting each row start on a word boundary is much more
efficient. You can think of a row as being "padded" up to the next
multiple of 32 bits.

- Bert -

```