Bona Fide OS Development
http://forums.osdever.net/

Displaying Bitmaps
http://forums.osdever.net/viewtopic.php?f=4&t=107
Page 1 of 1

Author:  Michael [ Thu Dec 10, 2009 5:24 pm ]
Post subject:  Displaying Bitmaps

OK, so my OS is coming along. So far I've managed to get some nice boxes up, and it's all in colour! :D

But there's a new idea... I want to display an image. I'm currently using C to do my Operating System. See the attached image to see what I have so far.
Attachment:
Sample.png
Sample.png [ 81.97 KiB | Viewed 20995 times ]

Author:  AndyEsser [ Mon Dec 14, 2009 9:52 am ]
Post subject:  Re: Displaying Bitmaps

Well done mate, least you've got something to show for your work.

At the moment I've had to suspend both tutorial writing and actual work on my bootloader/kernel because of work and some family stuff.

Author:  Wendell890 [ Wed Mar 31, 2010 3:16 pm ]
Post subject:  Re: Displaying Bitmaps

I found this fine tutorial in my search throughout the tutorial section, thought it might help.
http://www.brackeen.com/vga/bitmaps.html

Author:  chibicitiberiu [ Wed Jun 02, 2010 1:01 am ]
Post subject:  Re: Displaying Bitmaps

I have some sample code here. I'm using mode 13h, compiled it with the old Borland C 3.0, and I'm using the standard libraries. It ignores palette data, so you may want to change that. It can display monochrome bitmaps, and 256 color ones. I was too lazy to implement 16colors... :P

I used this code in a game...

Code:
int putimage_BMP_1bit (char filename[], int x, int y, int zero, int one)
{
    // Variables
   dword width, height, offset;
   dword i, j, counter = 0, by = 0;
   byte ch[1];
   byte header[54], array[8];



    // Open image file
   ifstream in (filename, ios::binary);
   if (!in) return -1;


    // Read and process header
   in.read (header, 54);

   if (header[0] != 0x42 || header[1] != 0x4D) return -2;

   offset = todword (header, 10);

   width = todword (header, 18);
   height = todword (header, 22);

   if (header[28] != 0x01 && header[29]!=0x00) return -3;


   in.seekg (offset);
    // Read and display image
   for (i = height; i > 0; i--) {

       for (j = 0; j < width; j++) {

      if (counter % 8 == 0) {
          if (by % 4 == 0) by = 0;
          in.read (ch, 1);
          tobinary (ch[0], array);
          by++;
      }

      if (array[counter%8] == 0 && zero>=0) putpixel (j+x, i+y, zero);
      if (array[counter%8] == 1 && one>=0) putpixel (j+x, i+y, one);

      counter++;

       }

       while (by<4) {
      in.read (ch, 1);
      by++;
      }
            while (counter%8 != 0) counter++;

   }

    // Cleanup*/
   in.close();
   return 0;

}


int putimage_BMP_8bit (char filename[], int x, int y)
{
    // Variables
   dword width, height, offset;
   dword i, j, counter = 0;
   byte ch[4];
   byte header[54], array[2];



    // Open image file
   ifstream in (filename, ios::binary);
   if (!in) return -1;


    // Read and process header
   in.read (header, 54);

   if (header[0] != 0x42 || header[1] != 0x4D) return -2;

   offset = todword (header, 10);

   width = todword (header, 18);
   height = todword (header, 22);

//   if (header[28] != 0x08 && header[29]!=0x00) return -3;


   in.seekg (offset);
    // Read and display image
   for (i = height; i > 0; i--) {

       for (j = 0; j < width; j++) {

      if (counter % 4 == 0) {
          in.read (ch, 4);
      }

      putpixel (j+x, i+y, ch[counter%4]);
      counter++;

       }

       while (counter%8 != 0) counter++;

   }

    // Cleanup*/
   in.close();
   return 0;

}


You can use wikipedia to see how bitmaps look like, I mean the header and the data how it's structured.
http://en.wikipedia.org/wiki/BMP_file_format

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/