Pictures?
- blobmiester
- Member
- Posts: 45
- Joined: Fri Jul 16, 2010 9:49 am
Re: Pictures?
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.
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.
- Combuster
- 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?
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.
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?
Hi,
Cheers,
Brendan
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: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?
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.
Re: Pictures?
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
Re: Pictures?
Hi,
Cheers,
Brendan
First suggestion: Find out why it doesn't work properly.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?
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.
Re: Pictures?
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!
Root -- With great power comes great responsibility
Re: Pictures?
Well, did you try to put that data on the screen?
Re: Pictures?
Hi,
Cheers,
Brendan
Heh - he may have tried "memcpy(0xB8000, gimp_image.pixel_data, 80*25" in text mode...Nessphoro wrote:Well, did you try to put that data on the screen?
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.
Re: Pictures?
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
Re: Pictures?
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.
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?
Opened up GIMP - use save as C header.
And then for data you pass in the pointer for char array,
Which can look something like this
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; \
}
Which can look something like this
Code: Select all
static char *header_data =
"````````````````````````````````````````````````````````````````"
"````````````````````````````````````````````````````````````````"
"````````````````````````````````````````````````````````````````"
"````````````````````````````````````````````````````````````````"
/*Lots of code*/
"````````````````````````````````````````````````````````````````"
"";
Re: Pictures?
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!
Root -- With great power comes great responsibility
Re: Pictures?
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