Plain format conversion

hello,

i’d like to use only a small part of sdl to just convert an array of
pixels from one format into an other. so basically i want to do the
following:

Uint8 *pixels;
//store useful RGB data in pixels
SDL_Surface * sf = SDL_CreateRGBSurfaceFrom(pixels, …);
sf = SDL_ConvertSurface(sf, new_format_with_alpha_channel, flags);
SDL_FreeSurface(sf);
//voila, pixels is in RGBA mode now :wink:

so i tried to set up a SDL_PixelFormat struct, create a SDL_Surface from
my data and called SDL_ConvertSurface then. i think i’m basically on the
right track since my new pixels data does not completely contain
garbage :wink:

but i have the following questions:

  • what do i have to enter as values for [RGB]loss in the SDL_PixelFormat
    struct? for example, i’m converting RGBA to RGB, is the correct value 1
    or 8 or 0 or whatever? my naive guess was -8, but its an unsigned char,
    so it can’t be.
  • i create the SDL_Surface using SDL_CreateRGBSurfaceFrom(), passing my
    own pixel data. i assume that my data will not be freed after a call to
    SDL_FreeSurface. correct?
  • when i create a SDL_Surface using SDL_CreateRGBSurfaceFrom i don’t
    have to specify any flags. so what flags do i pass to
    SDL_ConvertSurface() then? is 0 sufficient?

maybe someone has a little hint or even a codesnippet for me that could
help me converting my pixels?

regards
sebastian mecklenburg–
sebastian mecklenburg
sebi at cyte.de
http://sebi.cyte.de

s.mecklenburg at t-online.de (Sebastian Mecklenburg) wrote:

so i tried to set up a SDL_PixelFormat struct, create a SDL_Surface from
my data and called SDL_ConvertSurface then. i think i’m basically on the
right track since my new pixels data does not completely contain
garbage :wink:

You can create an SDL_PixelFormat struct yourself if you know what you
are doing, but I don’t really recommend it. Instead of calling ConvertSurface,
create your new surface with CreateRGBSurface and blit the contents over.
ConvertSurface is somewhat broken by design so it’s rarely useful

@Sebastian_Mecklenbur (Sebastian Mecklenburg) wrote:

so i tried to set up a SDL_PixelFormat struct, create a SDL_Surface
from
my data and called SDL_ConvertSurface then. i think i’m basically on
the
right track since my new pixels data does not completely contain
garbage :wink:

You can create an SDL_PixelFormat struct yourself if you know what you
are doing, but I don’t really recommend it. Instead of calling
ConvertSurface,
create your new surface with CreateRGBSurface and blit the contents
over.
ConvertSurface is somewhat broken by design so it’s rarely useful

thanks a lot.
i just got it to work with 32 and 24 bit images using the way you
described (wheee:-), but if i want to copy indexed images as well, how
do i specify the lookup table? the docs say that a call to
SDL_SetPalette() is ignored if the surface is not palettized surface,
but how can i create a palettized surface from scratch? i didn’t find
anything in the headers or the docs about that except SDL_SetVideoMode()
where i can specify a color depth of 8, but i guess that’s not the
correct one if i only want to use the surface in my private memory, is
it not?

thanks again for your help and regards
sebastian mecklenburgOn Saturday, November 10, 2001, at 10:21 AM, Mattias Engdeg?rd wrote:

“Mattias Engdeg?rd” wrote in message
news:mailman.1005416522.26963.sdl at libsdl.org

s.mecklenburg at t-online.de (Sebastian Mecklenburg) wrote:
You can create an SDL_PixelFormat struct yourself if you know what you
are doing, but I don’t really recommend it.

In practice, the ‘SDL_PixelFormat’ you wnat is almost always accessable as
’someothersurface->format’.

Instead of calling ConvertSurface,
create your new surface with CreateRGBSurface and blit the contents over.
ConvertSurface is somewhat broken by design so it’s rarely useful

While I agree that ‘SDL_ConvertSurface’ is broken, I’m not sure I understand
what you are suggesting here. Are suggesting that surfaces are to be kept
in a non-native format? That would be slow. Are you suggesting that
surfaces be created directly in the native format? That would require a ton
of tedious extra code. Are you suggesting that ‘SDL_BlitSurface’ be used to
convert the surface to the native format? That would be strange, since
’SDL_ConvertSurface’ is already built on top of ‘SDL_BlitSurface’ (and
’SDL_DisplayFormat’ on top of that).–
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

s.mecklenburg at t-online.de (Sebastian Mecklenburg) wrote:

i just got it to work with 32 and 24 bit images using the way you
described (wheee:-), but if i want to copy indexed images as well, how
do i specify the lookup table? the docs say that a call to
SDL_SetPalette() is ignored if the surface is not palettized surface,
but how can i create a palettized surface from scratch?

if you create an 8bpp surface with CreateRGBSurface, it will have a
palette created for it. (It will be all black, so don’t forget to copy
over the colours as well — use SetColors() or SetPalette())

“Rainer Deyke” wrote:

While I agree that ‘SDL_ConvertSurface’ is broken, I’m not sure I understand
what you are suggesting here.

It’s just an API quirk. Since there is no (official) way of creating
an SDL_PixelFormat, SDL_ConvertSurface can only be used to convert to
a format that another surface already has. 9 times out of 10 that
other surface is the screen, and it’s easier to use SDL_DisplayFormat
instead.

But if there is no such surface, you end up creating a dummy surface
just for passing its format into SDL_ConvertSurface. In that case it’s
usually easier to create the destination surface directly and blit the
contents over explicitly

I have been trying to access the site libsdl.org and its down for the last
two days.
Is everyone experiencing the same.

  • Karthick.P

I have been trying to access the site libsdl.org and its down for the last
two days.

???

Is everyone experiencing the same.

no, not me, curious ?

Not sure why my browser does not access the site … Anyways.

I am a beginer to multimedia programming. We have a project which requires
us to record and store audio/vedio. I am trying to see if SDL could help us
out. Can someone help me out.

1. Does SDL support audio recording ?
2. What is the best possible audio compression that i can get if i use the

existing apis like the one in SDL (if available)/Directx etc. We are looking
at recording a one hour session. What would be the other solutions.
3. Is there any code sample using SDL/Directx which could record
continously the activities happening on a desktop screen and the voice
through a mike (Say u are explaining a software and want to record …).

Thanks in advance.
  • Karthick.P> ----- Original Message -----

From: Lloyd Dupont [mailto:lloyd@galador.net]
Sent: Sunday, November 11, 2001 4:33 PM
To: sdl at libsdl.org; @Karthick_Purushotham
Subject: Re: [SDL] libsdl.org down

I have been trying to access the site libsdl.org and its down for the last
two days.

???

Is everyone experiencing the same.

no, not me, curious ?

Karthick Purushothaman wrote:

Not sure why my browser does not access the site … Anyways.

hum, might be a quite stupid sugestion, but du you type the riht URL ?
http://www.libsdl.org ?

I am a beginer to multimedia programming. We have a project which requires
us to record and store audio/vedio. I am trying to see if SDL could help us
out. Can someone help me out.

  1. Does SDL support audio recording ?

i fewly utilise SDL sound/mixer until now, but i do not believe there is
such possibilities…
(and see nothing related to this when i quickly glance at
SDL_mixer/audio header)

you could also try OpenAL, who knows ?
for DirectX, i don’t know…

Well, if you want to have the presentation ready before hand then its
pretty easy. But, if you want to do it real time its going to be quite
complicated!! (in my opnion, specially trying to record it as a video
mpeg or avi is going to be quite a task)

Anyone else have any ideas??

We are trying to record the classroom session in a real time.

The following is the scenario and our ideas of recording. Can someone

comment on whether we are on the right track.

	The instructor uses a powerpoint presentation to display his notes and

talks in the classroom. Whatever is displayed on the desktop ppt/.doc etc
(which in turn is projected on the screen) has to be recorded. Now recording
can happen in two modes “Discrete” and “Continous”.

Assumption: The instructor does not write anything in the classroom.

	In the "discrete mode".. the instructor displays the slide and talks for

say 5 mintues. At the end of the 5th minute when the instructor says “stop
recording” a screen shot of what is displayed is taken. The voice recording
is stopped. The screen shot is stored along with the voice. (Note that we do
not store it as an avi or mpeg here but just an jpg+audio)
In the continous mode both the desktop and the audio is simultaneously
recorded as an avi file when the instructor stops recording.

	The classroom goes on with both the modes used randomly.

At the end of the classroom the "discrete blocks" and "continous blocks"

are stored in a propritery format to be played back later.

Is this the right solution to store a classroom ? What would be the

appropriate file sizes.

  • Karthick.P> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Nishal Thomas G.
Sent: Sunday, November 11, 2001 6:05 PM
To: sdl at libsdl.org
Subject: Re: [SDL] libsdl.org down - beginer looking for answers

Well, if you want to have the presentation ready before hand then its
pretty easy. But, if you want to do it real time its going to be quite
complicated!! (in my opnion, specially trying to record it as a video
mpeg or avi is going to be quite a task)

Anyone else have any ideas??


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

  1. Does SDL support audio recording ?

Nope, it’s planned for the SDL 1.3 rewrite.

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

[…]

  1. Does SDL support audio recording ?

No, not yet. (Planned for 1.3, it seems.)

  1. What is the best possible audio compression that i can get if i use
    the existing apis like the one in SDL (if available)/Directx etc. We
    are looking at recording a one hour session. What would be the other
    solutions.

I don’t think SDL is of much help here - SDL is primarilly meant for
games, so the API is focused on playback when it comes to audio and
video.

Depending on how important portability is, you may look at the Win32
"codec" interface, DirectX etc, or Free/Open Source compression
libraries. There are a few for audio (mp3, ogg and various other
variants, such as simple ADPCM and GSM-like variants), but I don’t know
much about video compression libraries. (I’ve had no need for video
compression so far…)

  1. Is there any code sample using SDL/Directx which could
    record continously the activities happening on a desktop screen and the
    voice through a mike (Say u are explaining a software and want to
    record …).

What are you looking for, actually? It’s two entirely separate things,
and both are pretty trivial - apart from the compression part, that is.

(Use DirectX or the old wave API to record; blit from “window 0” to get
the whole screen, including the desktop.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Sunday 11 November 2001 12:21, Karthick Purushothaman wrote:

We are trying to record the classroom session in a real time.

The “real time” part is probably your biggest problem here…

[…]

At the end of the classroom the “discrete blocks” and “continous
blocks” are stored in a propritery format to be played back later.
^^^^^^^^^^
You mean you have to use a file format that’s fundamentally
cripled and made useless right from the start, rather than a
Free/Open file format? :wink:

Is this the right solution to store a classroom ?

Well, the basic idea is pretty much the only way I can think of… What
other ways are there, apart from adding/removing “special features” like
the discrete/continuous block distinction?

BTW, with a proper “compression” algo, I don’t really see the point in
the discrete mode. Compressing N frames with no changes should result in
the same output as 1 frame with any algo suitable for this kind of
applications.

What would be the appropriate file sizes.

How about “the smallest possible that meets the quality requirements”? :wink:

Seriously, most of the time, you’re just moving the mouse around, popping
up a tiny menu, or switching to the next “page”. So, first off after
grabbing each frame, you should probably do a simple and fast diff test
between the new frame and the last frame. (For example, chop the screen
up into 32x32 tiles, and then test them one by one, adding the ones with
an old/new difference to a linked list, table or whatever.) Only consider
the changed areas for storage. Depending on your input, this alone might
be sufficient!

If not (ie too big areas change too often), keep in mind that you’ll need
a very fast CPU to compress anything near a full screen per frame, if
you want a frame rate high enough not to force the teacher to run a
"slowmotion demo" for video viewers to be able to follow the action.

Simple, non-destructive RLE encoding helps a lot for normal application
GUIs and the like, and relatively fast implementations aren’t too hard to
code. It won’t do much for animations with lots of gradients and stuff,
though - can’t think of any simple algorithms for compressing that kind
of stuff, so you’re probably better off with some tried video compression
algo there.

Finally, think about buffering - done right, it will make things run a
lot smoother. I don’t know what you’ll be recording exactly, but I
suspect that there will be extended periods of time where there’s very
little work for the compressor, while occasionally, almost the whole
screen will change. Setting up sufficient buffering (corresponding to
several full screens, if possible) in between the initial "tile changed"
test and the actual compression (in another thread) might help. Queue up
full screen buffers, or preferably tiles, in a FIFO queue or similar
construct between the threads, so that the grabbing + testing code can
run at full speed all the time, as long as there is free buffer space.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Sunday 11 November 2001 13:44, Karthick Purushothaman wrote:

Thanks for the detailed explanation and the suggestion abt the codecs.
Lookin at them and the windows media platform to find some solutions now.
Lemme see if it can solve the compression problems…> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
David Olofson
Sent: Monday, November 12, 2001 9:39 PM
To: sdl at libsdl.org
Subject: Re: [SDL] libsdl.org down - beginer looking for answers

On Sunday 11 November 2001 13:44, Karthick Purushothaman wrote:

We are trying to record the classroom session in a real time.

The “real time” part is probably your biggest problem here…

[…]

At the end of the classroom the "discrete blocks" and "continous

blocks" are stored in a propritery format to be played back later.
^^^^^^^^^^
You mean you have to use a file format that’s fundamentally
cripled and made useless right from the start, rather than a
Free/Open file format? :wink:

Is this the right solution to store a classroom ?

Well, the basic idea is pretty much the only way I can think of… What
other ways are there, apart from adding/removing “special features” like
the discrete/continuous block distinction?

BTW, with a proper “compression” algo, I don’t really see the point in
the discrete mode. Compressing N frames with no changes should result in
the same output as 1 frame with any algo suitable for this kind of
applications.

What would be the appropriate file sizes.

How about “the smallest possible that meets the quality requirements”? :wink:

Seriously, most of the time, you’re just moving the mouse around, popping
up a tiny menu, or switching to the next “page”. So, first off after
grabbing each frame, you should probably do a simple and fast diff test
between the new frame and the last frame. (For example, chop the screen
up into 32x32 tiles, and then test them one by one, adding the ones with
an old/new difference to a linked list, table or whatever.) Only consider
the changed areas for storage. Depending on your input, this alone might
be sufficient!

If not (ie too big areas change too often), keep in mind that you’ll need
a very fast CPU to compress anything near a full screen per frame, if
you want a frame rate high enough not to force the teacher to run a
"slowmotion demo" for video viewers to be able to follow the action.

Simple, non-destructive RLE encoding helps a lot for normal application
GUIs and the like, and relatively fast implementations aren’t too hard to
code. It won’t do much for animations with lots of gradients and stuff,
though - can’t think of any simple algorithms for compressing that kind
of stuff, so you’re probably better off with some tried video compression
algo there.

Finally, think about buffering - done right, it will make things run a
lot smoother. I don’t know what you’ll be recording exactly, but I
suspect that there will be extended periods of time where there’s very
little work for the compressor, while occasionally, almost the whole
screen will change. Setting up sufficient buffering (corresponding to
several full screens, if possible) in between the initial "tile changed"
test and the actual compression (in another thread) might help. Queue up
full screen buffers, or preferably tiles, in a FIFO queue or similar
construct between the threads, so that the grabbing + testing code can
run at full speed all the time, as long as there is free buffer space.

//David Olofson — Programmer, Reologica Instruments AB

…- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' ...- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -’


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Simple, non-destructive RLE encoding helps a lot for normal application
GUIs and the like, and relatively fast implementations aren’t too hard to
code. It won’t do much for animations with lots of gradients and stuff,
though - can’t think of any simple algorithms for compressing that kind
of stuff, so you’re probably better off with some tried video compression
algo there.

http://www.math.berkeley.edu/~benrg/huffyuv.html

Interesting stuff!

(Although I wasn’t the one looking for it - but I’m interested in pretty
much everything, as you might have noticed… :wink:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 16 November 2001 05:35, Callum Lerwick wrote:

Simple, non-destructive RLE encoding helps a lot for normal
application GUIs and the like, and relatively fast implementations
aren’t too hard to code. It won’t do much for animations with lots of
gradients and stuff, though - can’t think of any simple algorithms
for compressing that kind of stuff, so you’re probably better off
with some tried video compression algo there.

http://www.math.berkeley.edu/~benrg/huffyuv.html