Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 3:07 pm



Post new topic Reply to topic  [ 4 posts ] 
 Displaying Bitmaps 
Author Message

Joined: Sat Jul 25, 2009 6:10 am
Posts: 112
Location: United Kingdom
Post 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 21015 times ]

_________________
Thanks,
Michael Sammels

OS Developing is 10% luck, 20% skill, 15% concentrated power of will. 5% pleasure, 50% pain, and a 100% reason continue the game.


Thu Dec 10, 2009 5:24 pm
Profile

Joined: Mon Oct 26, 2009 2:33 pm
Posts: 38
Location: United Kingdom
Post 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.

_________________
Andy Esser
neogenix Broadcast


Mon Dec 14, 2009 9:52 am
Profile

Joined: Mon Mar 29, 2010 3:55 pm
Posts: 10
Post 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

_________________
2A9B982B-F231-487C-A5FF-B27FEF30BF44


Wed Mar 31, 2010 3:16 pm
Profile

Joined: Wed May 19, 2010 12:14 am
Posts: 10
Post 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


Wed Jun 02, 2010 1:01 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.