Solved

How to Show bmp's in Turbo c++ 3.00

Posted on 1998-11-26
1
515 Views
Last Modified: 2006-11-17
How Can we View *.bmp Files in c++ program ? i'm using
turbo c++ 3.00 for dos.
thanx.
0
Comment
Question by:nitin_kumars
1 Comment
 
LVL 2

Accepted Solution

by:
harrys earned 50 total points
ID: 1178662
This sample should give you enough information to do what you want, it could only display uncompressed 256color bitmaps and assumes and videomode with 256colors (eg mode 0x13 or vesa 0x101..) and it doesn't set the palette ...

typedef struct {
            char bfType[2];
            unsigned long int  bfSize;
            unsigned short int reserved1;
            unsigned short int reserved2;
            unsigned long int bfoffbits;
             } bitmapfileheader_t;

typedef struct {
            unsigned long int biSize;
            unsigned long int biWidth;
            unsigned long int biHeight;
            unsigned short int biPlanes;
            unsigned short int biBitCount;
            unsigned long int biCompression;
            unsigned long int biSizeImage;
            unsigned long int biXPelsPerMeter;
            unsigned long int biYPelsPerMeter;
            unsigned long int biClrUsed;
            unsigned long int biClrImportant;
            } bitmapinfoheader_t;

typedef struct {
            bitmapinfoheader_t bmiheader;
            } bitmapinfo_t;

typedef struct {
      unsigned char b, g, r, reserved;
       } rgbquad_t;

void displaybmp(char *name,int x, int y)
{

 bitmapfileheader_t header;
 bitmapinfoheader_t bmi;
 FILE           *hnd;
 rgbquad_t      *palette;
 char           *buffer;
 char             *linebuffer;
 int i,sizex,sizey;

 hnd=fopen(name,"rb");
 if (hnd==NULL) {
     return;
     }

 fread(&header,1,sizeof(header),hnd);
 if (strncmp(header.bfType,"BM",2)!=0) {
    printf("not a bitmap\n");
    fclose(hnd);
    return;
    }


 fread(&bmi,1,sizeof(bmi),hnd);

 if (bmi.biBitCount!=8) {
    printf("unsupported bitmap depth\n");
    fclose(hnd);
    return;
    }


 sizex=bmi.biWidth;
 sizey=bmi.biHeight;

 linebuffer = malloc(sizex+sizeof(short int )*2 +1);
 if (!linebuffer)
     return;

 *((int *)linebuffer)=sizex-1;
 *(((int *)linebuffer)+1)=0;
 buffer = linebuffer+4;

 palette = malloc(sizeof(rgbquad_t)*256+1);
 fread(palette,sizeof(rgbquad_t)*256,1,hnd);

 y = y + sizey-1;
 fseek(hnd,header.bfoffbits,SEEK_SET);
 switch (bmi.biCompression) {
 case 0: // uncompressed
       for (i=0;i<sizey;i++) {
       fread(buffer,1,sizex,hnd);
       if (sizex % 4) {
          fseek(hnd,4 - (sizex % 4),SEEK_CUR);
          }
       putimage(x,y,linebuffer,COPY_PUT);
       y--;
       buffer=linebuffer+4;
       }
       break;
 case 1: // RLE8
       break;
 case 2: // RLE4
       break;
 default:
      printf("compression type %d \n",bmi.biCompression);
      break;
 }

 fclose(hnd);
 return;
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now