OT: copy images from video memory

Hi,

I have a question for someone who knows more about maths than I do…

I have a large image, starting at a known address. The image is a grid of icons, 10 icons wide by 10 high, all 72 pixels x 72 pixels square.
I need to copy each icon to a different area of memory. I just don’t know how to do it.
I cannot use SDL for this (if I could, I would).

If anyone can help I would be so very very grateful!

Many Thanks
Ed

Assuming you have a SDL_surface loaded using one of the convenient
SDL_image functions or the BMP reader , it is easy to access the pixel
data.

Each surface includes a pointer to a bunch of bytes organized like this:

[surface] = [row][row]…[row]
[row] = [pixel][pixel]…[pixel][filler]
[pixel] = [1 byte index color] | [2 bytes RGB565] | [3 byte RGB888] | [4
byte RGBA] | maybe more
[filler] = [0 bytes] | [n bytes]

The filler is used to align rows, so one should always iterate by row in
row-width (pitch) steps. A surface also has width and height
information, the pixel depth and the RGB order (it can be ABGR). So you
have all the information you will need to write a function to access
pixel data and create a copy loop to the target location.

To speed things up you could also use the SDL_Blit function to chop your
source image into pieces before starting your copy loop. Pseudo code:

source=SDl_LoadBmp(big_image_file)
while (have_pieces) {
per_piece_source_rect=CalculatePieceRect()
SDL_Blit(source, per_piece_source_rect, piece, null)
CopyPixelsToTargetLoop(piece, target)
}

For some examples and to get started, have - for example - a look at the
source code of SDL_gfx which writes bytes into surfaces to draw graphics
primitives.

Hope that helps.
–Andreas

Edward Byard wrote:

Hi,

I have a question for someone who knows more about maths than I do.

I have a large image, starting at a known address. The image is a grid
of icons, 10 icons wide by 10 high, all 72 pixels x 72 pixels square.
I need to copy each icon to a different area of memory. I just don’t
know how to do it.
I cannot use SDL for this (if I could, I would).

If anyone can help I would be so very very grateful!

Many Thanks
Ed



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: aschiffler.vcf
Type: text/x-vcard
Size: 142 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090114/5343d70b/attachment.vcf

It would help if we knew what you can use, what format your image is in, and what hardware, OS and development tools you’re running on.>________________________________

From: Edward Byard <e_byard at yahoo.co.uk>
Subject: [SDL] OT: copy images from video memory

Hi,

I have a question for someone who knows more about maths than I do.

I have a large image, starting at a known address. The image is a grid of icons, 10
icons wide by 10 high, all 72 pixels x 72 pixels square.
I need to copy each icon to a different area of memory. I just don’t know how to do it.
I cannot use SDL for this (if I could, I would).

If anyone can help I would be so very very grateful!

Many Thanks
Ed

OK, as I said, I am not and cannot use SDL.

I have no OS so speak, it’s an embedded platform and I have total, uncontrolled access to all areas of memory (128mb worth).
I am using C with a gnu compiler for a ColdFire 5475.

I have a standard C system running on the board.

My images are in 16 bpp, converted to a propritery format which takes a 24 bpp BMP, strips the header and reverses the
image data.

Thanks
Ed________________________________
From: masonwheeler@yahoo.com (Mason Wheeler)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, 14 January, 2009 16:56:49
Subject: Re: [SDL] OT: copy images from video memory

It would help if we knew what you can use, what format your image is in, and what hardware, OS and development tools you’re running on.


From: Edward Byard <@Edward_Byard>
Subject: [SDL] OT: copy images from video memory

Hi,

I have a question for someone who knows more about maths than I do.

I have a large image, starting at a known address. The image is a grid of icons, 10
icons wide by 10 high, all 72 pixels x 72 pixels square.
I need to copy each icon to a different area of memory. I just don’t know how to do it.
I cannot use SDL for this (if I could, I would).

If anyone can help I would be so very very grateful!

Many Thanks
Ed


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hello !

OK, as I said, I am not and cannot use SDL.

I have no OS so speak, it’s an embedded platform and I have total,
uncontrolled access to all areas of memory (128mb worth).
I am using C with a gnu compiler for a ColdFire 5475.

I have a standard C system running on the board.

My images are in 16 bpp, converted to a propritery format which
takes a 24 bpp BMP, strips the header and reverses the
image data.

Have you tried to compile SDL on that board ?
You can use the dummy drivers for that purpose.

CU

Torsten

No, but if I can get SDL working on this, I would be so so happy!
All I need is the graphics API, blitting and so on.

Where do I get the “dummy drivers” etc?

Thanks________________________________
From: wizard@syntheticsw.com (Torsten Giebl)
To: sdl at lists.libsdl.org
Sent: Wednesday, 14 January, 2009 17:23:54
Subject: Re: [SDL] OT: copy images from video memory

Hello !

OK, as I said, I am not and cannot use SDL.

I have no OS so speak, it’s an embedded platform and I have total, uncontrolled access to all areas of memory (128mb worth).
I am using C with a gnu compiler for a ColdFire 5475.

I have a standard C system running on the board.

My images are in 16 bpp, converted to a propritery format which takes a 24 bpp BMP, strips the header and reverses the
image data.

Have you tried to compile SDL on that board ?
You can use the dummy drivers for that purpose.

CU


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I have a large image, starting at a known address. The image is a grid of
icons, 10 icons wide by 10 high, all 72 pixels x 72 pixels square.
I need to copy each icon to a different area of memory. I just don’t know
how to do it.
I cannot use SDL for this (if I could, I would).

A bit strange to say that on the SDL list, but oh well… :slight_smile:

Andreas Schiffler explained the memory layout pretty well. So what you
need to know are the following:

  • memory address of the upper left corner of the source image
  • memory address of the destination image
  • bytes per pixel
  • the pitch of the source image (size of “(width * bytes per pixel) + filler”)
  • the pitch of the destination image

The amount that you want to copy is known, 72x72 pixels, so it’s
pretty trivial to calculate where to start and stop within the image.
This is untested, half-way between pseudo-code and C (and C++ will
find issues with it, I’m sure):

/* The icon_x/icon_y are zero-based, so the third icon of the first
line would be 2, 0. bpp is in BYTES, not in BITS, unlike many cases
where you might see “bpp” (but it’s easy to convert!). /
void CopyIcon(void
src_img, void* dst_img, size_t bpp, size_t
src_pitch, size_t dst_pitch, unsigned int icon_x, unsigned int icon_y)
{
/* skip the right number of rows in the source image */
src_img += icon_y * 72 * src_pitch;

/* shift ourselves so that we point at the first pixel of the icon */
src_img += icon_y * 72 * bpp;

int i = 0;
for (i = 0; i < 72; ++i) {
    /* copy a row of the icon */
    memcpy(dst_img, src_img, 72 * bpp);
    src_img += src_pitch;
    dst_img += dst_pitch;
}

}

If there is no filling/padding in the source image, the src_pitch
would be a constant “bpp * 72 * 10”, but if this is video memory, you
have to find out (it can depend on the video mode). This function
could be written tighter, but I optimized for legibility and
understanbility. :-)On Wed, Jan 14, 2009 at 10:44 AM, Edward Byard <e_byard at yahoo.co.uk> wrote:


http://pphaneuf.livejournal.com/

Hello !

No, but if I can get SDL working on this, I would be so so happy!
All I need is the graphics API, blitting and so on.

Where do I get the “dummy drivers” etc?

They are in SDL already. You have a video and audio dummy driver.
Run ./configure --help under Linux there you can see all the needed
arguments to disable all the unneeded parts in SDL.

Then in your app use the SDL_putenv (“SDL_VIDEODRIVER=dummy”) to
activate it. You can use all the blitting functions you want.

CU

Then in your app use the SDL_putenv (“SDL_VIDEODRIVER=dummy”) to
activate it. You can use all the blitting functions you want.

Ah, yes, using SDL_CreateRGBSurfaceFrom, very clever!On Wed, Jan 14, 2009 at 12:34 PM, Torsten Giebl wrote:


http://pphaneuf.livejournal.com/

Many thanks…only one problem…I don’t use Linux!________________________________
From: wizard@syntheticsw.com (Torsten Giebl)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, 14 January, 2009 17:34:31
Subject: Re: [SDL] OT: copy images from video memory

Hello !

No, but if I can get SDL working on this, I would be so so happy!
All I need is the graphics API, blitting and so on.

Where do I get the “dummy drivers” etc?

They are in SDL already. You have a video and audio dummy driver.
Run ./configure --help under Linux there you can see all the needed
arguments to disable all the unneeded parts in SDL.

Then in your app use the SDL_putenv (“SDL_VIDEODRIVER=dummy”) to
activate it. You can use all the blitting functions you want.

CU


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Then use MinGW and MSYS (http://mingw.sourceforge.net)
With that you can use configure scripts and makefiles under windows.

Greets
Christoph

Edward Byard schrieb:> Many thanks…only one problem…I don’t use Linux!


From: Torsten Giebl
To: A list for developers using the SDL library. (includes
SDL-announce)
Sent: Wednesday, 14 January, 2009 17:34:31
Subject: Re: [SDL] OT: copy images from video memory

Hello !

No, but if I can get SDL working on this, I would be so so happy!
All I need is the graphics API, blitting and so on.

Where do I get the “dummy drivers” etc?

They are in SDL already. You have a video and audio dummy driver.
Run ./configure --help under Linux there you can see all the needed
arguments to disable all the unneeded parts in SDL.

Then in your app use the SDL_putenv (“SDL_VIDEODRIVER=dummy”) to
activate it. You can use all the blitting functions you want.

CU


SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org