You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is most likely simply a documentation issue. The main issue I ran into is that createRGBSurfaceFrom accepts an IOVector of raw pixel bytes. I naively assumed the bytes would be parsed by SDL in the byte order passed in. However, that is not the case, which is due to the fact SDL actually seems to parse these as 32-bit bytes. What this effectively means is the pixel format is different on little endian & big endian machines.
I think it would help to note this in the documentation of the function, since my brain was initially in haskell land and I assumed giving the function a list of RGBA values it would be parsed as an RGBA format.
If anybody wants a more cross-platform way to do this, I believe this should do the trick (it uses JuicyPixels for the underlying image format but that can be easily changed):
importCodec.PictureimportSDLimportSystem.EndianimportqualifiedData.Vector.StorableasVloadImage::String->IO (ImagePixelRGBA8)
loadImage f =do
r <- readImage f
case r ofLeft e ->error e
Right i ->doreturn (convertRGBA8 i)
createSurfaceFromImage::ImagePixelRGBA8->IOSurface
createSurfaceFromImage i =do
pixels <-V.thaw (imageData i)
let fmt =case getSystemEndianness ofLittleEndian->ABGR8888BigEndian->RGBA8888let (w, h) = (fromIntegral (imageWidth i), fromIntegral (imageHeight i))
createRGBSurfaceFrom pixels (V2 w h) (fromIntegral w*4) fmt
The text was updated successfully, but these errors were encountered:
This is most likely simply a documentation issue. The main issue I ran into is that createRGBSurfaceFrom accepts an IOVector of raw pixel bytes. I naively assumed the bytes would be parsed by SDL in the byte order passed in. However, that is not the case, which is due to the fact SDL actually seems to parse these as 32-bit bytes. What this effectively means is the pixel format is different on little endian & big endian machines.
I think it would help to note this in the documentation of the function, since my brain was initially in haskell land and I assumed giving the function a list of RGBA values it would be parsed as an RGBA format.
If anybody wants a more cross-platform way to do this, I believe this should do the trick (it uses JuicyPixels for the underlying image format but that can be easily changed):
The text was updated successfully, but these errors were encountered: