[sane-devel] Minor issue with SANE standard

Ron Hunter-Duvar ronhd at users.sourceforge.net
Tue Dec 20 00:05:45 UTC 2005


This is for the people involved in developing and documenting the SANE 
standard. 

When I was getting familiar with SANE, I read the latest standard (version 
1.03). A very well written standard, IMHO. I just had one little issue (yeah, 
I'm being pedantic, it's a personality flaw 8^), with the formula for c in 
section 4.3.8 (page 29).

First, the formula for c when d = 1 is given as:

	ceiling(B * n / 8)

Technically, this is correct, because the formula is an inequality, setting a 
lower bound on the value of c. But as written, this formula gives a lower 
value for the lower bound than if it were written as:

	B * ceiling(n / 8)

Consider an example with d = 1, n = 3, B = 3. The original formula gives a 
value of ceiling(3 * 3 / 8) = ceiling(9 / 8) = ceiling(1.125) = 2. The new 
formula gives 3 * ceiling(3 / 8) = 3 * ceiling (0.375) = 3 * 1 = 3.

From the description on page 11, when d = 1, the bits for each channel are 
packed into bytes and byte interleaved. So with 3 pixels per line, I read 
this to mean that 3 bytes are required, one byte for the 3 single bit sample 
values for each of 3 channels, with 5 wasted bits per byte. So the new 
formula gives a tighter lower bound.

Unless I'm reading this wrong, and the 9 bits can be crammed together into 2 
bytes. In this case, my new formula would be wrong and the original one 
right.

Assuming the new one is right, it might be better to express it using floor 
instead of ceiling, given how it would likely be implemented, using integer 
arithmetic. The following formula is mathematically equivalent:

	B * floor((n + 7) / 8)

Now, the second part of the formula in the standard, for when d > 1, is 
definitely broken:

	B * n * ceiling((d + 7) / 8)

Let's take B = 3 and n = 3 again (though these values don't really matter to 
my example), and d = 8. Now, when each sample value is 8 bits, it fits in one 
byte. So for 3 channels and 3 pixels per line, 9 bytes are obviously required 
as a minimum for each line. But this formula gives 3 * 3 * ceiling((8 + 7) / 
8) = 9 * ceiling (15 / 8) = 9 * 2 = 18. So it's saying that 18 bytes minimum 
are required to store 9 bytes of information. This formula should either be:

	B * n * ceiling(d / 8)

or:

	B * n * floor ((d + 7) / 8)

Again, these are equivalent. The first is more concise, but the second better 
reflects the likely implementation. It seems obvious that somehow these two 
formulas got mixed together into the incorrect one.

Perhaps someone can see that this gets corrected in the next version of the 
standard.

-- 
Ron
ronhd at users dot sourceforge dot net

Opinions expressed here are all mine.



More information about the sane-devel mailing list