Page 1 of 1

Pictures?

Posted: Tue Jul 12, 2011 3:20 pm
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?

Re: Pictures?

Posted: Tue Jul 12, 2011 3:27 pm
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.

Re: Pictures?

Posted: Tue Jul 12, 2011 3:35 pm
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.

Re: Pictures?

Posted: Tue Jul 12, 2011 4:00 pm
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

Re: Pictures?

Posted: Tue Jul 12, 2011 6:22 pm
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?

Re: Pictures?

Posted: Tue Jul 12, 2011 7:19 pm
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

Re: Pictures?

Posted: Wed Jul 13, 2011 3:33 pm
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

Re: Pictures?

Posted: Wed Jul 13, 2011 3:37 pm
by Nessphoro
Well, did you try to put that data on the screen?

Re: Pictures?

Posted: Wed Jul 13, 2011 4:11 pm
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

Re: Pictures?

Posted: Wed Jul 13, 2011 6:09 pm
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. :|

Re: Pictures?

Posted: Wed Jul 13, 2011 7:20 pm
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.

Re: Pictures?

Posted: Wed Jul 13, 2011 7:25 pm
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*/
           "````````````````````````````````````````````````````````````````"
	"";
          

Re: Pictures?

Posted: Wed Jul 13, 2011 7:44 pm
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

Re: Pictures?

Posted: Wed Jul 13, 2011 9:15 pm
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