Solved

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

Posted on 1998-11-26
1
545 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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