On 18 Aug, 18:17, MrIncognito <StudioJa...@gmail.comwrote:
Am I using this correctly?
This line of code is supposed to find the number of bytes in one line
of a 16 color bitmap, but it doesn't seem to work most of the time.
long linesize = ceil((double) (header.width / 8)) * 4;
For example, when header.width is 1790, this code returns 892, when it
should be returning 896...
I've had a similar problem. The problem is that, when it divides one
integer type by another, it wipes out any remainder. In your case, the
expression (header.width / 8) is, I presume, one integer type divided
by another, so because of the brackets round this it calculates this
and throws away the remainder *before* it tries to convert the answer
into a double. You need to convert either header.width or the 8 to a
double before the division. Such as:
linesize = ceil(((double) header.width) / 8) * 4;
or
linesize = ceil((double) header.width / 8) * 4;
or
linesize = ceil(header.width / 8.0) * 4;
Hope that helps.
Paul.