Pictures?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
rooper
Posts: 8
Joined: Tue Jul 05, 2011 9:14 pm

Pictures?

Post by rooper »

Does anyone know of a way to display a picture(like a .bmp) into a C based OS? Do you use some kind of array?
Last edited by rooper on Tue Jul 12, 2011 6:52 pm, edited 1 time in total.
Root -- With great power comes great responsibility
User avatar
blobmiester
Member
Member
Posts: 45
Joined: Fri Jul 16, 2010 9:49 am

Re: Pictures?

Post by blobmiester »

Not sure what you mean by "port a picture".

If you mean display a picture, then picture formats have a defined format. Just read the picture file into memory and parse it according to its specification.

If not, please explain what you mean.

EDIT: First google result found this: http://www.fileformat.info/format/bmp/s ... c/view.htm. I'm sure MSDN would have a bit more to say about bitmaps as well.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Pictures?

Post by Combuster »

I'm sorry, but the Required Knowledge rule applies here. Manually loading Windows Bitmaps is in comparison such a simple task that it should be straightforward for anything but the beginner programmer. Your misuse of terminology also points in that direction.

Try loading a bitmap in whatever OS you are using to read this. Use existing code first, then write your own loader for an exercise. If you have any problems with that, a place like http://www.cprogramming.com or http://www.stackoverflow.com are the best places to ask for help.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Pictures?

Post by Brendan »

Hi,
rooper wrote:Does anyone know of a way to port a picture(like a .bmp) into a C based OS? Do you use some kind of array?
If you mean "convert a picture directly into C code", then the format of the data depends on the tool you use to do the conversion. For example, I tried "save as C source" in GIMP and it created a this:

Code: Select all

static const struct {
  guint  	 width;
  guint  	 height;
  guint  	 bytes_per_pixel; /* 3:RGB, 4:RGBA */ 
  guint8 	 pixel_data[124 * 124 * 3 + 1];
} gimp_image = {
  124, 124, 3,
  "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
  /**** I removed lots of lines of data from the middle ****/
  "\0\377\377\0\377",
};

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
rooper
Posts: 8
Joined: Tue Jul 05, 2011 9:14 pm

Re: Pictures?

Post by rooper »

I am new to OS dev, but am an experienced programmer in C. And yes that is what I mean Brendan. Doesn't work properly though any other suggestions?
Root -- With great power comes great responsibility
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Pictures?

Post by Brendan »

Hi,
rooper wrote:I am new to OS dev, but am an experienced programmer in C. And yes that is what I mean Brendan. Doesn't work properly though any other suggestions?
First suggestion: Find out why it doesn't work properly.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
rooper
Posts: 8
Joined: Tue Jul 05, 2011 9:14 pm

Re: Pictures?

Post by rooper »

It appears when you do it your way Brendan it still requires GIMP to display it, but no worry I think I found a different way in my research! :D
Root -- With great power comes great responsibility
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Pictures?

Post by Nessphoro »

Well, did you try to put that data on the screen?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Pictures?

Post by Brendan »

Hi,
Nessphoro wrote:Well, did you try to put that data on the screen?
Heh - he may have tried "memcpy(0xB8000, gimp_image.pixel_data, 80*25" in text mode... ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
rooper
Posts: 8
Joined: Tue Jul 05, 2011 9:14 pm

Re: Pictures?

Post by rooper »

Not to be rude, but if I didn't try put my code on the screen how would I be able to tell you it didn't work? Unless I took your statement wrong. :|
Root -- With great power comes great responsibility
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Pictures?

Post by bluemoon »

IMO It only means your code does not work, but not "Brendan's method not work".

To show something on screen, first you need to know the related interface exposed by the OS.
It can be a set of graphic API, or nothing but allow you to directly write to frame buffer.

On the case of directly write to frame buffer (display memory), you need to convert the data into proper pixel format - for example 32-bit-per-pixel (0888), and put the pixels into the frame buffer. Things will get more complicated if you works on legacy VGA and bank switching.

If the OS provide some graphic API, you'll need to follow its workflow - which is OS-dependent.

And I don't think GIMP is required to show the picture on a custom OS
- it defeats the purpose of such export.
- GIMP may not run on your OS.

However you may re-use the pixel-conversion functions in some case.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Pictures?

Post by Nessphoro »

Opened up GIMP - use save as C header.

Code: Select all

#define HEADER_PIXEL(data,pixel) {\
pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \
pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); \
pixel[2] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); \
data += 4; \
}
And then for data you pass in the pointer for char array,
Which can look something like this

Code: Select all

static char *header_data =
	"````````````````````````````````````````````````````````````````"
	"````````````````````````````````````````````````````````````````"
	"````````````````````````````````````````````````````````````````"
	"````````````````````````````````````````````````````````````````"
           /*Lots of code*/
           "````````````````````````````````````````````````````````````````"
	"";
          
rooper
Posts: 8
Joined: Tue Jul 05, 2011 9:14 pm

Re: Pictures?

Post by rooper »

Thank you very much for your information I was able to figure it out using a header file and additional research. This post has been very insightful. Though it is my second post here on the OS dev. I think Ive got the feel of how things run and how to and what to ask about thanks! :D
Root -- With great power comes great responsibility
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Pictures?

Post by Nessphoro »

Yes, this forum can be a lot of talk if you don't ask the question in the right way, and the answer might not be what you want - if there is one
Post Reply