Hallo, SDL.
How can i create 1 (or n) bit surface.
SDL_CreateRGBSurface() is the function you want. It can create just
about any type of surface. It does make some assumptions that might get
in your way. But, it does appear that you can use it to create a 1 bit
deep surface. I have not tried it, so I am not 100% certain it will
work.
Wouldn’t that have the general issue that a 1 bit or n bit surface isn’t very
usable for drawing?
A 1 bit surface is perfectly usable if what you need is a 1 bit surface.
Not knowing the application we can’t say what would be better.
Eventually it has to be converted into something the
graphic card handles, likely the one that is the current screen mode.
Not necessarily. We don’t know that his output is going to a screen. It
may well be part of a process that builds an image that is going to a
fax machine. Not all computer graphics is about putting images on a
screen.
Certainly it can be done since screens can be viewed as just raw memory of a
certain shape but it’d just mandate a conversion every time that was done.
Since we don’t know the application it is hard to suggest that he do
something different. He may well be working on a system with a 1 bit
display. Such things do exist. Or, perhaps he is building the planes for
a cursor or overlay plane. Or, perhaps he is working with a very large
number of pixels and needs the space to get them all in memory. Maybe he
is doing some sort of super antialiasing and will sample the 1 bit
surface by averaging 16x16 or 32x32 pixel regions into a single pixel in
his final image.
There are many reasons to use a 1 bit surface, I haven’t come close to
listing all the ones I can think of, just off the top of my head.
Bob PendletonOn Tue, 2005-04-26 at 08:41 -0400, bloomp at rpi.edu wrote:
On Tue, 19 Apr 2005 15:10:15 -0500 Bob Pendleton wrote:
On Tue, 2005-04-19 at 21:18 +0400, Alexei Sergeev wrote:
Draw on it
Drawing on it is up to you. That is, you will need to do the arithmetic
and shifts to get and set the proper bits.
(i can draw
on 32 bit surface, but what happened if i’ll draw pixel in
32-bit format in 1 bit surface?
Nothing useful will happen, clearly a 32 bit value can not be stored in
a 1 bit field
actually, it’ll write to 32 pixels together, assuming you do it memory wise.
This can be useful for faster draws where you’re calculating what the image
is displaying and the calculation step takes significantly less time than the
memory write for the pixel. As far as I’m aware, this is also optimal (4
words) for writing to memory in the first place.
How can i avoid problems with
this (I mean, if there is some function to convert pixels?)).
Yes, there are several functions that can convert pixels to RGB values
and vice versa. Check out SDL_MapRGB, SDL_MapRGBA SDL_GetRGB,
SDL_GetRGBA.
In the case of a one bit pixel the only valid pixel values are 0 and 1.
Then I need to draw 1 (n) bit surface on 32-bit surf. Should I
use only SDL_ConverSurface() or something else?
That will work, I’m sure other people will jump in with other ways to do
the job.
It’ll work, but it’d have no advantage over just drawing it in 32 bit to
begin with. If you know a conversion is happening and you know what it’s
being converted to, there’s little point not to do the math ahead of time and
convert it yourself rather than do it in program. Even if you don’t know
what it’s being converted to, why not go with something that’s as close to
your expected case as possible and check if you need to convert instead of
always converting?
Philip
A sleepy programmer
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
–
±-------------------------------------+