Uint8 *pixels = (Uint8*)dest_surface->pixels;
Uint8 *oldpixels = (Uint8*)src_surface->pixels;
pixels[CurrentDestX * dest_surface->format->BytesPerPixel + CurrentDestY * dest_surface->pitch] = oldpixels[CurrentDestX * src_surface->format->BytesPerPixel + CurrentDestY * src_surface->pitch];
What's wrong with this code?!
To elaborate: you''re using Uint8 (one byte), but skipping bytes according to the bytes-per-pizel. So if it''s a 32-bit surface, you copy 1 byte, skip 4, copy 1, skip 4, and so on. The simplest way to get around this is to drop the bytes per pixel bit in that expression, and loop so that X goes from zero to width * bytes per pixel. eg. 128 pixels wide, 32-bit surface, X goes from 0 to 512, copying each byte as it goes.
Alternatively, write separate routines using different data types depending on the bytes per pixel, and keep the bytes per pixel multiplier in there. (Warning - gets marginally more complex for 24-bit images.)
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
Alternatively, write separate routines using different data types depending on the bytes per pixel, and keep the bytes per pixel multiplier in there. (Warning - gets marginally more complex for 24-bit images.)
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement