[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 1998-11-26
1
Medium Priority
?
565 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 100 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

656 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