Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 1998-11-26
1
531 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

792 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