0
\$\begingroup\$
class Surface 
{
protected:
    Surface();
    virtual ~Surface();

    class IMAGE // create a discreet type to be used to instantiate queue template
    {
    public:
        // single bitmap image width and height
        unsigned short width, height;
        unsigned int size;      // single bitmap image size
        DWORD* buffer;          // buffer to hold a width X height _size_ image
…

class Bitmap : protected Surface
{
public:
    class BMP_32
    {
    public:
        BMPHeader       HeaderSection;
        BMPInfo         InfoSection;
        BMPColorTable       ColorTableSection;

…

void Bitmap::BMP_32::Read(Bitmap::BMP_32& a_bmp32, IMAGE& an_image, SURFACE& a_surface, const char* file_name)
{
…
fread(&a_bmp32.HeaderSection.FileType, sizeof(a_bmp32.HeaderSection.FileType), 1, fp);
…
fread(&a_bmp32.InfoSection.HeaderSize, sizeof(a_bmp32.InfoSection.HeaderSize), 1, fp);
…
fread(&a_bmp32.ColorTableSection.RedIntensity, sizeof(a_bmp32.ColorTableSection.RedIntensity), 1, fp);
…

an_image.buffer = new DWORD[IMAGEBUFFERSIZE];

…
// The following three examples render the same output visually:

// DWORD dwords_read = fread(an_image.buffer, sizeof(DWORD), an_image.size, fp);  // dwords_read = 2,073,600

DWORD dwords_read = fread(an_image.buffer, (SCREEN_WIDTH * SCREEN_HEIGHT), 4, fp);   // dwords_read = 4
// DWORD dwords_read = fread(an_image.buffer, ((SCREEN_WIDTH * SCREEN_HEIGHT) * 2), 2, fp);  // dwords_read = 2

Background Detail: I am building up a class framework to read in 32BPP BMP files, that I am creating on a backsurface, which I then bltfast to the frontsurface and flip to GDI. The 32BPP background BMP that I am reading in is 8294400 in size, but the most I am able to read using “fread()” is 2073600, which is exactly 25% of the original artwork. I am using Visual Studio 2019 Community Edition and fread(&MyBuffer, arg2, arg3, stream) extensively. My application is an MFC application.

I have a need to read in the entire BMP Pixel Data Section into memory, because I am saving this into a queue Abstract Data type. Once I have the BMP in memory the I/O is done to disk and I just make calls to update the backsurface, bltfast and flip to update my scene. I am creating a class library for the BMP code.

Question: Is fread() hitting an upperbound on size limit? If so can someone suggest how I might be able to overcome this problem. If so I am hoping to make a minor substitution for this fread() API call for another C++ call. I cannot do anything too fancy with multiple buffers or doing a lot of I/O, as I have tried that approach already without success.

\$\endgroup\$
  • \$\begingroup\$ What is the value of an_image.size and IMAGEBUFFERSIZE? \$\endgroup\$ – Fuzzy Logic May 30 at 7:45
  • \$\begingroup\$ // some useful constants #define SCREEN_WIDTH 1920 #define SCREEN_HEIGHT 1080 #define BPP 32 // Bits Per Pixel #define IMAGEBUFFERSIZE ( SCREEN_WIDTH * SCREEN_HEIGHT ) * BPP // holds max IMAGE size; an_image.size == 8294400 // size of the raw pixel data from this specific 32 BPP BMP // here is how I obtained it -- fread(&a_bmp32.InfoSection.ImageSize, sizeof(a_bmp32.InfoSection.ImageSize), 1, fp); an_image.size = a_bmp32.InfoSection.ImageSize; I have set the value of IMAGEBUFFERSIZE much higher than I believe it needs to be Thanks for taking a peek \$\endgroup\$ – DHarding May 30 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.