Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

12 Experts available now in Live!

Get 1:1 Help Now