-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API to get (and maybe set?) individual pixels in a surface #8319
Comments
See also #8320 and particularly #8320 (comment). It would probably be useful to have this as an internal function to be shared by |
See also: #4867 IIRC, there was some pushback to making this function/macro public (as it could be very slow), but we've clearly implemented this incorrectly often enough that having some helper would make sense (even if callers are later optimised to avoid using it). |
... but Standard C says memcpy() is the only valid way to do potentially-unaligned accesses, and a decent compiler will optimize memcpy() into whatever is the best way to do a potentially-unaligned access (on x86, it usually ends up being the same machine code as the pointer cast). I think part of the problem here is that SDL carefully avoids using memcpy() because it doesn't want a C runtime library dependency, and instead uses SDL_memcpy(), but compilers don't know that they can optimize away SDL_memcpy() and turn it into inlined machine code. |
I would rather this not end up in the public API, but we can add it to libSDL_test. |
This is essentially the same as was added in d95d2d7, but with clearer error handling. It's implemented in a private header file so that it can be shared with SDL_shape, which also wants this functionality. Resolves: libsdl-org#8319 Signed-off-by: Simon McVittie <[email protected]>
This is essentially the same as was added in d95d2d7, but with clearer error handling. It's implemented in a private header file so that it can be shared with SDL_shape, which also wants this functionality. Resolves: #8319 Signed-off-by: Simon McVittie <[email protected]>
This is essentially the same as was added in d95d2d7, but with clearer error handling. It's implemented in a private header file so that it can be shared with SDL_shape, which also wants this functionality. Resolves: libsdl-org#8319 Signed-off-by: Simon McVittie <[email protected]>
When writing regression tests or assertions, particularly around image endianness, it's useful to be able to say things like "the pixel at (15,13) should have value rgba(1, 2, 3, 4)".
However, it's not at all obvious how to do this correctly for formats that are not 32 bits per pixel, as evidenced by SDLTest_CompareSurfaces() having been wrong for RGB24 on big-endian platforms ever since it was added (fixed in #8317). As seen in #8317, you have to memcpy the right number of bytes into the low-order bits of a Uint32 (which do not necessarily start at byte 0!), and then pass that to SDL_GetRGBA() to decode it into its colour channels.
I think it might be useful to have something like:
which would do the rowstride arithmetic internally, and let you do something like:
This would have to lock the surface if it's in a non-trivial format, so it could be slow, but that's fine for something testing-oriented. (Because locking is refcounted, interfaces that iterate through an image, like
SDLTest_CompareSurfaces()
, could speed this up considerably by locking before iteration and unlocking afterwards.)For completeness we could also have
but that seems less useful in practice.
The text was updated successfully, but these errors were encountered: