SDL_DisplayFormat question

The documentation for SDL_DisplayFormat mentions three
different surfaces:

This function takes a surface and copies it to a new surface of the
pixel format and colors of the video framebuffer, suitable for fast
blitting onto the display surface. It calls SDL_ConvertSurface.

and the prototype:

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

mentions two surfaces. One inny and one outy. Which one
goes where? How does it know about the third?
Thanks for any help.

Frank

“Frank Samuelson” wrote

The documentation for SDL_DisplayFormat mentions three
different surfaces:

This function takes a surface and copies it to a new surface of the
pixel format and colors of the video framebuffer, suitable for fast
blitting onto the display surface. It calls SDL_ConvertSurface.

and the prototype:

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

mentions two surfaces. One inny and one outy. Which one
goes where? How does it know about the third?
Thanks for any help.

it’s easier than you might think ;]
the function only needs one argument, the surface you want
converted to match the screen. it doesn’t need any other
information, since SDL already knows the surface format for
the display. the return surface is a new copy of the input
surface with its format changed to match the display.

one surface goes in, and a slightly changed copy of it
comes out.

Hi Frank,On Tue, 28 Nov 2000, you wrote:

The documentation for SDL_DisplayFormat mentions three
different surfaces:

This function takes a surface and copies it to a new surface of the
pixel format and colors of the video framebuffer, suitable for fast
blitting onto the display surface. It calls SDL_ConvertSurface.

and the prototype:

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

mentions two surfaces. One inny and one outy. Which one
goes where? How does it know about the third?
The argument ‘surface’ is the surface that should be converted.
The return value is the converted copy of that surface (you should free the
first surface after calling SDL_DisplayFormat).
The ‘third’ surface is the display surface. There’s only one display surface,
created when you call SDL_SetVideoMode(). SDL has a (private) pointer to this
surface, that’s why you don’t have to pass it to SDL_DisplayFormat().
This implies that must not call SDL_DisplayFormat() before SDL_SetVideoMode().

If you want a similar surface optimization for blitting to another surface (not
the display surface), look at the sources of SDL how SDL_DisplaySurface() is
implemented.

---- from src/video/SDL_video.c

SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface)
{
Uint32 flags;

    /* Set the flags appropriate for copying to display surface */
    flags  = (SDL_PublicSurface->flags&SDL_HWSURFACE);
    flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA));
    return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));

}


Just replace SDL_PublicSurface with your target surface.


Benjamin Niemann (P!\K)
http://www.odahoda.de
pink at odahoda.de

The documentation for SDL_DisplayFormat mentions three
different surfaces:

and the prototype:

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

mentions two surfaces. One inny and one outy. Which one
goes where? How does it know about the third?
Thanks for any help.

The thing the function sends back is the "outy."
The thing you send TO the function (“surface”) is the “inny.”

The third is your actual window or screen (as opened
with “SDL_SetVideoMode()”).

Make sense? It needs to be explained a little better, it sounds like.

-bill!

Tue, 28 Nov 2000 Pete Shinners wrote:

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

Hey, speaking of SDL_DisplayFormat(); does it support dithering and other
filtering operations? (Didn’t find anything in the man.)

I have some code for 4x4 size pattern based dithering that I’ve used for
24->15/16 bit conversions, if anyone wants to see a simple example of an
implementation. The dithering pattern is controlled by passing a 4x4 pixel
offset mask to the routine.

//David

…- M u C o S -------------------------. .- David Olofson --------.
| A Free/Open Source | | Audio Hacker |
| Plugin and Integration Standard | | Linux Advocate |
| for | | Open Source Advocate |
| Professional and Consumer | | Singer |
| Multimedia | | Songwriter |
-----> http://www.linuxdj.com/mucos -'—> david at linuxdj.com -’

Benjamin Niemann wrote:

Hi Frank,

The documentation for SDL_DisplayFormat mentions three
different surfaces:

This function takes a surface and copies it to a new surface of the
pixel format and colors of the video framebuffer, suitable for fast
blitting onto the display surface. It calls SDL_ConvertSurface.

and the prototype:

SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface);

mentions two surfaces. One inny and one outy. Which one
goes where? How does it know about the third?
The argument ‘surface’ is the surface that should be converted.
The return value is the converted copy of that surface (you should free the
first surface after calling SDL_DisplayFormat).

I’m having a small problem with SDL_DisplayFormat. I have created a small slide
show type viewer and now I’m implementing a few transition effects. To do this,
I’ve had to implement my own SDL_Surface->pixels to SDL_Surface->pixels copy
functions, and need to convert all my image to the display format. So far no
problem. I free the original surface ok, but when I go to free the converted
surface I’m getting segmentation faults and if I don’t free the the converted
surface, well I’m going to need a lot more memory. Any ideas???> On Tue, 28 Nov 2000, you wrote:

The ‘third’ surface is the display surface. There’s only one display surface,
created when you call SDL_SetVideoMode(). SDL has a (private) pointer to this
surface, that’s why you don’t have to pass it to SDL_DisplayFormat().
This implies that must not call SDL_DisplayFormat() before SDL_SetVideoMode().

If you want a similar surface optimization for blitting to another surface (not
the display surface), look at the sources of SDL how SDL_DisplaySurface() is
implemented.

---- from src/video/SDL_video.c

SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface)
{
Uint32 flags;

    /* Set the flags appropriate for copying to display surface */
    flags  = (SDL_PublicSurface->flags&SDL_HWSURFACE);
    flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA));
    return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));

}


Just replace SDL_PublicSurface with your target surface.


Benjamin Niemann (P!\K)
http://www.odahoda.de
pink at odahoda.de