 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Brad White Guest
|
Posted: Tue Apr 06, 2004 8:15 pm Post subject: size of bitmap |
|
|
I have a tiff file, compressed.
I am converting it to a bitmap because my
report program doesn't handle tiffs.
All works well, except sometimes the bitmap exceeds
the size of the buffer and fails. So there is something
wrong with my size calculation.
These are black&white images.
BitsPerPixel = 1;
BitsPerByte = 8;
FudgeFactor = 3000;
ImageSize := Round((LeadImage.BitmapWidth *
LeadImage.BitmapHeight * BitsPerPixel) / BitsPerByte) +
FudgeFactor;
LeadImage.SaveBuffer(pBuffer, uImageSize, FILE_BMP, BitsPerPixel, 2,
@FinalBufSize);
I've charted the diff between my calculated size and the final size,
and 50 - 60% differ by the amount of the fudge factor.
Most of the rest differ by between 1500 and 3000.
5 that we have found have a slightly larger FinalBufSize than ImageSize
and fail.
Nothing seems special about the 5. We can view them fine.
Obviously, I've upped the FudgeFactor for a workaround.
But since I don't understand why the calculation is off, I don't have
any confidence that it will be a permanent fix.
Why do I need the fudge factor at all, why the wild variance?
--
Thanks,
Brad White
|
|
| Back to top |
|
 |
Jorrit Jongma Guest
|
Posted: Wed Apr 07, 2004 1:41 pm Post subject: Re: size of bitmap |
|
|
Try upping the width to the next multiple of 2.
I dont know how SaveBuffer works or how the TIFF image works, but it is a
fairly common thing, so it might just hit the spot :-)
HTH
|
|
| Back to top |
|
 |
Ive Guest
|
Posted: Wed Apr 07, 2004 3:25 pm Post subject: Re: size of bitmap |
|
|
try this:
ImageSize := ((LeadImage.BitmapWidth + 7) div * LeadImage.BitmapHeight;
this does adjust the needed bytes/line to byte boundary for b/w images.
(BTW your use of Round does not make any sense)
-Ive
| Quote: | These are black&white images.
BitsPerPixel = 1;
BitsPerByte = 8;
FudgeFactor = 3000;
ImageSize := Round((LeadImage.BitmapWidth *
LeadImage.BitmapHeight * BitsPerPixel) / BitsPerByte) +
FudgeFactor;
|
|
|
| Back to top |
|
 |
Brad White Guest
|
Posted: Wed Apr 07, 2004 3:28 pm Post subject: Re: size of bitmap |
|
|
That sounds like that could fit what we're seeing.
I'll check the data and get back to you.
--
Thanks,
Brad White
"Jorrit Jongma >" <
| Quote: | Try upping the width to the next multiple of 2.
I dont know how SaveBuffer works or how the TIFF image works, but it is a
fairly common thing, so it might just hit the spot :-)
HTH
|
|
|
| Back to top |
|
 |
Nils Haeck Guest
|
Posted: Thu Apr 08, 2004 12:24 am Post subject: Re: size of bitmap |
|
|
I assume that the Lead library saves the file as a BMP file. Obviously,
there's a header to this file, not only the bits.
This header may also contain a palette, which could account for quite some
bytes.
And then another thing: each scanline MUST be a multiple of 8 bits, or in
other words, end on byte boundaries. Your calculation does not take that
into account. So you should use something like:
if BitsPerPixel = 1 then
ImageSize := ((LeadImage.BitmapWidth + 7) div * LeadImage.BitmapHeight;
(and why would you define bitsperbyte? There have ALWAYS been 8 bits in a
byte! Not a thing that will change soon either)
In other BitsPerPixel cases you must also take special care (e.g. 24bpp
would require scanlines aligned on dword boundaries, IIRC).
The real issue here is that you're trying to do something for which Lead
most probably already has a function. It would be worth to study the
documentation and see if there is a function that either gives you the
buffer size required, or a function that locks memory itself which you can
then access and free. I have worked on a blue monday with Lead, and that
latter one was the one I used.
In Windows GDI functions there's also sometimes this approach: by passing 0
in the variable uImageSize you will signal the function to return the
buffersize first (without actually writing the image). Then you can use that
value and call the function again.
Kind regards,
Nils Haeck
www.simdesign.nl
"Brad White" <bwhite at inebraska.com> wrote
| Quote: | I have a tiff file, compressed.
I am converting it to a bitmap because my
report program doesn't handle tiffs.
All works well, except sometimes the bitmap exceeds
the size of the buffer and fails. So there is something
wrong with my size calculation.
These are black&white images.
BitsPerPixel = 1;
BitsPerByte = 8;
FudgeFactor = 3000;
ImageSize := Round((LeadImage.BitmapWidth *
LeadImage.BitmapHeight * BitsPerPixel) / BitsPerByte) +
FudgeFactor;
LeadImage.SaveBuffer(pBuffer, uImageSize, FILE_BMP, BitsPerPixel, 2,
@FinalBufSize);
I've charted the diff between my calculated size and the final size,
and 50 - 60% differ by the amount of the fudge factor.
Most of the rest differ by between 1500 and 3000.
5 that we have found have a slightly larger FinalBufSize than ImageSize
and fail.
Nothing seems special about the 5. We can view them fine.
Obviously, I've upped the FudgeFactor for a workaround.
But since I don't understand why the calculation is off, I don't have
any confidence that it will be a permanent fix.
Why do I need the fudge factor at all, why the wild variance?
--
Thanks,
Brad White
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|